procon_bypass_man 0.1.10 → 0.1.14

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/CHANGELOG.md +13 -1
  4. data/Gemfile +1 -1
  5. data/Gemfile.lock +15 -12
  6. data/README.md +13 -9
  7. data/bin/console +4 -0
  8. data/bin/{report_receive_server.rb → dev_api_server.rb} +8 -1
  9. data/lib/procon_bypass_man/background/job_performer.rb +16 -0
  10. data/lib/procon_bypass_man/background/job_runner.rb +45 -0
  11. data/lib/procon_bypass_man/background/jobs/base_job.rb +7 -0
  12. data/lib/procon_bypass_man/background/jobs/concerns/has_external_api_setting.rb +5 -0
  13. data/lib/procon_bypass_man/background/jobs/concerns/has_internal_api_setting.rb +5 -0
  14. data/lib/procon_bypass_man/background/jobs/concerns/job_runnable.rb +16 -0
  15. data/lib/procon_bypass_man/background/jobs/fetch_and_run_remote_pbm_action_job.rb +29 -0
  16. data/lib/procon_bypass_man/background/jobs/report_boot_job.rb +12 -0
  17. data/lib/procon_bypass_man/background/jobs/report_error_job.rb +11 -0
  18. data/lib/procon_bypass_man/background/jobs/report_event_base_job.rb +5 -0
  19. data/lib/procon_bypass_man/background/jobs/report_load_config_job.rb +11 -0
  20. data/lib/procon_bypass_man/background/jobs/report_pressed_buttons_job.rb +15 -0
  21. data/lib/procon_bypass_man/background/jobs/report_reload_config_job.rb +11 -0
  22. data/lib/procon_bypass_man/background/jobs/sync_device_stats_job.rb +16 -0
  23. data/lib/procon_bypass_man/background.rb +14 -0
  24. data/lib/procon_bypass_man/boot_message.rb +16 -8
  25. data/lib/procon_bypass_man/{configuration → buttons_setting_configuration}/layer.rb +34 -29
  26. data/lib/procon_bypass_man/{configuration → buttons_setting_configuration}/loader.rb +5 -4
  27. data/lib/procon_bypass_man/{configuration → buttons_setting_configuration}/validator.rb +0 -0
  28. data/lib/procon_bypass_man/buttons_setting_configuration.rb +8 -7
  29. data/lib/procon_bypass_man/bypass/usb_hid_logger.rb +20 -2
  30. data/lib/procon_bypass_man/bypass.rb +15 -15
  31. data/lib/procon_bypass_man/commands/bypass_command.rb +86 -0
  32. data/lib/procon_bypass_man/commands/connect_device_command.rb +16 -0
  33. data/lib/procon_bypass_man/commands/print_boot_message_command.rb +9 -0
  34. data/lib/procon_bypass_man/commands/run_local_shell_command.rb +6 -0
  35. data/lib/procon_bypass_man/commands/run_remote_pbm_action_dispatch_command.rb +19 -0
  36. data/lib/procon_bypass_man/commands/send_error_command.rb +19 -0
  37. data/lib/procon_bypass_man/commands/send_reload_config_event_command.rb +11 -0
  38. data/lib/procon_bypass_man/commands/write_device_id_command.rb +12 -0
  39. data/lib/procon_bypass_man/commands/write_session_id_command.rb +7 -0
  40. data/lib/procon_bypass_man/commands.rb +8 -0
  41. data/lib/procon_bypass_man/configuration.rb +48 -8
  42. data/lib/procon_bypass_man/device_connector.rb +33 -26
  43. data/lib/procon_bypass_man/device_status.rb +44 -0
  44. data/lib/procon_bypass_man/io_monitor.rb +9 -4
  45. data/lib/procon_bypass_man/procon/analog_stick.rb +31 -0
  46. data/lib/procon_bypass_man/procon/analog_stick_cap.rb +9 -32
  47. data/lib/procon_bypass_man/procon/button_collection.rb +1 -0
  48. data/lib/procon_bypass_man/procon/{data.rb → consts.rb} +1 -1
  49. data/lib/procon_bypass_man/procon/layer_changer.rb +40 -0
  50. data/lib/procon_bypass_man/procon/user_operation.rb +11 -17
  51. data/lib/procon_bypass_man/procon.rb +6 -10
  52. data/lib/procon_bypass_man/procon_reader.rb +31 -0
  53. data/lib/procon_bypass_man/remote_pbm_action/base_action.rb +53 -0
  54. data/lib/procon_bypass_man/remote_pbm_action/change_pbm_version_action.rb +21 -0
  55. data/lib/procon_bypass_man/remote_pbm_action/lib/update_remote_pbm_action_status_command.rb +24 -0
  56. data/lib/procon_bypass_man/remote_pbm_action/reboot_os_action.rb +17 -0
  57. data/lib/procon_bypass_man/remote_pbm_action/stop_pbm_action.rb +17 -0
  58. data/lib/procon_bypass_man/remote_pbm_action.rb +31 -0
  59. data/lib/procon_bypass_man/runner.rb +14 -112
  60. data/lib/procon_bypass_man/scheduler.rb +92 -0
  61. data/lib/procon_bypass_man/splatoon2/macro/fast_return.rb +15 -0
  62. data/lib/procon_bypass_man/splatoon2/macro/jump_to_left_key.rb +15 -0
  63. data/lib/procon_bypass_man/splatoon2/macro/jump_to_right_key.rb +15 -0
  64. data/lib/procon_bypass_man/splatoon2/macro/jump_to_up_key.rb +15 -0
  65. data/lib/procon_bypass_man/splatoon2/mode/guruguru.rb +57 -0
  66. data/lib/procon_bypass_man/splatoon2/version.rb +7 -0
  67. data/lib/procon_bypass_man/splatoon2.rb +11 -0
  68. data/lib/procon_bypass_man/{callbacks.rb → support/callbacks.rb} +0 -0
  69. data/lib/procon_bypass_man/support/compress_array.rb +56 -0
  70. data/lib/procon_bypass_man/support/http_client.rb +102 -0
  71. data/lib/procon_bypass_man/{on_memory_cache.rb → support/on_memory_cache.rb} +0 -0
  72. data/lib/procon_bypass_man/support/report_http_client.rb +19 -0
  73. data/lib/procon_bypass_man/{timer.rb → support/safe_timeout.rb} +1 -1
  74. data/lib/procon_bypass_man/support/send_device_stats_http_client.rb +9 -0
  75. data/lib/procon_bypass_man/support/server_pool.rb +42 -0
  76. data/lib/procon_bypass_man/support/signal_handler.rb +11 -0
  77. data/lib/procon_bypass_man/support/update_remote_pbm_action_status_http_client.rb +9 -0
  78. data/lib/procon_bypass_man/support/uptime.rb +25 -0
  79. data/lib/procon_bypass_man/value_objects/remote_pbm_action_object.rb +38 -0
  80. data/lib/procon_bypass_man/version.rb +1 -1
  81. data/lib/procon_bypass_man.rb +57 -20
  82. data/procon_bypass_man.gemspec +3 -3
  83. data/project_template/README.md +18 -11
  84. data/project_template/app.rb +3 -4
  85. data/project_template/web.rb +1 -1
  86. data/sig/{README.rb → README.md} +0 -0
  87. data/sig/main.rbs +12 -13
  88. metadata +82 -26
  89. data/examples/practical/app.rb +0 -21
  90. data/examples/practical/setting.yml +0 -24
  91. data/lib/procon_bypass_man/analog_stick_position.rb +0 -8
  92. data/lib/procon_bypass_man/outbound/base.rb +0 -40
  93. data/lib/procon_bypass_man/outbound/error_reporter.rb +0 -13
  94. data/lib/procon_bypass_man/outbound/reporter.rb +0 -12
  95. data/lib/procon_bypass_man/outbound/usb_hid_data_reporter.rb +0 -13
  96. data/lib/procon_bypass_man/procon/debug_dumper.rb +0 -17
  97. data/lib/procon_bypass_man/procon/layer_changeable.rb +0 -28
  98. data/lib/procon_bypass_man/procon/pressed_button_helper.rb +0 -15
  99. data/lib/procon_bypass_man/uptime.rb +0 -15
@@ -0,0 +1,24 @@
1
+ module ProconBypassMan
2
+ class UpdateRemotePbmActionStatusCommand
3
+ # @param [String] pbm_job_uuid
4
+ def initialize(pbm_job_uuid: )
5
+ @pbm_job_uuid = pbm_job_uuid
6
+ end
7
+
8
+ # @param [String] to_status
9
+ # @return [void]
10
+ def execute(to_status: )
11
+ ProconBypassMan::UpdateRemotePbmActionStatusHttpClient.new(
12
+ path: path,
13
+ server_pool: ProconBypassMan.config.server_pool,
14
+ ).put(to_status: to_status)
15
+ end
16
+
17
+ private
18
+
19
+ # @return [String]
20
+ def path
21
+ "/api/devices/#{ProconBypassMan.device_id}/pbm_jobs/#{@pbm_job_uuid}"
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,17 @@
1
+ module ProconBypassMan
2
+ module RemotePbmAction
3
+ class RebootOsAction < BaseAction
4
+
5
+ def action_content(_args)
6
+ ProconBypassMan.logger.info "execute RebootOsAction!"
7
+ `reboot`
8
+ end
9
+
10
+ private
11
+
12
+ def before_action_callback
13
+ be_processed
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module ProconBypassMan
2
+ module RemotePbmAction
3
+ class StopPbmAction < BaseAction
4
+
5
+ def action_content(_args)
6
+ ProconBypassMan.logger.info "execute StopPbmAction!"
7
+ Process.kill("TERM", ProconBypassMan.pid)
8
+ end
9
+
10
+ private
11
+
12
+ def before_action_callback
13
+ be_processed
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,31 @@
1
+ module ProconBypassMan
2
+ module RemotePbmAction
3
+ require "procon_bypass_man/remote_pbm_action/base_action"
4
+ require "procon_bypass_man/remote_pbm_action/change_pbm_version_action"
5
+ require "procon_bypass_man/remote_pbm_action/reboot_os_action"
6
+ require "procon_bypass_man/remote_pbm_action/stop_pbm_action"
7
+ require "procon_bypass_man/remote_pbm_action/lib/update_remote_pbm_action_status_command"
8
+
9
+ ACTION_CHANGE_PBM_VERSION = "change_pbm_version"
10
+ ACTION_REBOOT_OS = "reboot_os"
11
+ ACTION_STOP_PBM = "stop_pbm"
12
+ ACTION_RESTORE_SETTING = "restore_setting" # TODO
13
+
14
+ ACTIONS = [
15
+ ACTION_CHANGE_PBM_VERSION,
16
+ ACTION_REBOOT_OS,
17
+ ACTION_STOP_PBM,
18
+ ACTION_RESTORE_SETTING,
19
+ ]
20
+
21
+ STATUS_FAILED = :failed
22
+ STATUS_IN_PROGRESS = :in_progress
23
+ STATUS_PROCESSED = :processed
24
+
25
+ ACTION_STATUSES = [
26
+ STATUS_FAILED,
27
+ STATUS_IN_PROGRESS,
28
+ STATUS_PROCESSED,
29
+ ]
30
+ end
31
+ end
@@ -1,14 +1,19 @@
1
1
  require_relative "io_monitor"
2
- require_relative "uptime"
3
2
  require_relative "boot_message"
4
3
 
5
4
  class ProconBypassMan::Runner
6
5
  class InterruptForRestart < StandardError; end
7
6
 
8
- def run
9
- first_negotiation
10
- print_booted_message
7
+ include ProconBypassMan::SignalHandler
8
+
9
+ def initialize(gadget: , procon: )
10
+ @gadget = gadget
11
+ @procon = procon
12
+
13
+ ProconBypassMan::PrintBootMessageCommand.execute
14
+ end
11
15
 
16
+ def run
12
17
  self_read, self_write = IO.pipe
13
18
  %w(TERM INT USR1 USR2).each do |sig|
14
19
  begin
@@ -16,13 +21,14 @@ class ProconBypassMan::Runner
16
21
  self_write.puts(sig)
17
22
  end
18
23
  rescue ArgumentError
19
- ProconBypassMan.logger.error("Signal #{sig} not supported")
24
+ ProconBypassMan::SendErrorCommand.execute(error: "Signal #{sig} not supported")
20
25
  end
21
26
  end
22
27
 
23
28
  loop do
24
29
  $will_terminate_token = false
25
- main_loop_pid = fork { main_loop }
30
+ # TODO forkしないでThreadでいいのでは?
31
+ main_loop_pid = Kernel.fork { ProconBypassMan::BypassCommand.new(gadget: @gadget, procon: @procon).execute }
26
32
 
27
33
  begin
28
34
  while(readable_io = IO.select([self_read]))
@@ -36,9 +42,9 @@ class ProconBypassMan::Runner
36
42
  ProconBypassMan.logger.info("Reloading config file")
37
43
  begin
38
44
  ProconBypassMan::ButtonsSettingConfiguration::Loader.reload_setting
39
- puts "設定ファイルの再読み込みができました"
45
+ ProconBypassMan::SendReloadConfigEventCommand.execute
40
46
  rescue ProconBypassMan::CouldNotLoadConfigError
41
- ProconBypassMan.logger.error "設定ファイルが不正です。再読み込みができませんでした"
47
+ ProconBypassMan::SendErrorCommand.execute(error: "設定ファイルが不正です。再読み込みができませんでした")
42
48
  end
43
49
  ProconBypassMan.logger.info("バイパス処理を再開します")
44
50
  rescue Interrupt
@@ -53,108 +59,4 @@ class ProconBypassMan::Runner
53
59
  end
54
60
  end
55
61
  end
56
-
57
- private
58
-
59
- def main_loop
60
- ProconBypassMan::IOMonitor.start!
61
- # gadget => procon
62
- # 遅くていい
63
- monitor1 = ProconBypassMan::IOMonitor.new(label: "switch -> procon")
64
- monitor2 = ProconBypassMan::IOMonitor.new(label: "procon -> switch")
65
- ProconBypassMan.logger.info "Thread1を起動します"
66
- t1 = Thread.new do
67
- timer = ProconBypassMan::Timer.new(timeout: Time.now + 10)
68
- bypass = ProconBypassMan::Bypass.new(gadget: @gadget, procon: @procon, monitor: monitor1)
69
- loop do
70
- break if $will_terminate_token
71
- timer.throw_if_timeout!
72
- bypass.send_gadget_to_procon!
73
- sleep(0.005)
74
- rescue ProconBypassMan::Timer::Timeout
75
- ProconBypassMan.logger.info "10秒経過したのでThread1を終了します"
76
- puts "10秒経過したのでThread1を終了します"
77
- break
78
- rescue Errno::EIO, Errno::ENODEV, Errno::EPROTO, IOError => e
79
- ProconBypassMan.logger.error "Proconが切断されました.終了処理を開始します"
80
- Process.kill "TERM", Process.ppid
81
- rescue Errno::ETIMEDOUT => e
82
- # TODO まれにこれが発生する. 再接続したい
83
- ProconBypassMan::ErrorReporter.report(body: e)
84
- ProconBypassMan.logger.error "Switchとの切断されました.終了処理を開始します"
85
- Process.kill "TERM", Process.ppid
86
- end
87
- ProconBypassMan.logger.info "Thread1を終了します"
88
- end
89
-
90
- # procon => gadget
91
- # シビア
92
- ProconBypassMan.logger.info "Thread2を起動します"
93
- t2 = Thread.new do
94
- bypass = ProconBypassMan::Bypass.new(gadget: @gadget, procon: @procon, monitor: monitor2)
95
- loop do
96
- break if $will_terminate_token
97
- bypass.send_procon_to_gadget!
98
- rescue EOFError => e
99
- ProconBypassMan.logger.error "Proconと通信ができませんでした.終了処理を開始します"
100
- Process.kill "TERM", Process.ppid
101
- rescue Errno::EIO, Errno::ENODEV, Errno::EPROTO, IOError => e
102
- ProconBypassMan.logger.error "Proconが切断されました。終了処理を開始します"
103
- Process.kill "TERM", Process.ppid
104
- end
105
- ProconBypassMan.logger.info "Thread2を終了します"
106
- end
107
-
108
- self_read, self_write = IO.pipe
109
- %w(TERM INT).each do |sig|
110
- begin
111
- trap sig do
112
- self_write.puts(sig)
113
- end
114
- rescue ArgumentError
115
- puts "プロセスでSignal #{sig} not supported"
116
- end
117
- end
118
-
119
- ProconBypassMan.logger.info "子プロセスでgraceful shutdownの準備ができました"
120
- begin
121
- while(readable_io = IO.select([self_read]))
122
- signal = readable_io.first[0].gets.strip
123
- handle_signal(signal)
124
- end
125
- rescue Interrupt
126
- $will_terminate_token = true
127
- [t1, t2].each(&:join)
128
- @gadget&.close
129
- @procon&.close
130
- exit 1
131
- end
132
- end
133
-
134
- def first_negotiation
135
- @gadget, @procon = ProconBypassMan::DeviceConnector.connect
136
- rescue ProconBypassMan::Timer::Timeout
137
- ::ProconBypassMan.logger.error "デバイスとの通信でタイムアウトが起きて接続ができませんでした。"
138
- @gadget&.close
139
- @procon&.close
140
- raise ::ProconBypassMan::EternalConnectionError
141
- end
142
-
143
- def handle_signal(sig)
144
- ProconBypassMan.logger.info "#{$$}で#{sig}を受け取りました"
145
- case sig
146
- when 'USR2'
147
- raise InterruptForRestart
148
- when 'INT', 'TERM'
149
- raise Interrupt
150
- end
151
- end
152
-
153
- # @return [void]
154
- def print_booted_message
155
- message = ProconBypassMan::BootMessage.new
156
- ProconBypassMan.logger.info(message.to_s)
157
- Thread.new { ProconBypassMan::Reporter.report(body: message.to_hash) }
158
- puts message.to_s
159
- end
160
62
  end
@@ -0,0 +1,92 @@
1
+ module ProconBypassMan
2
+ class Scheduler
3
+ class Schedule
4
+ attr_accessor :klass, :args, :interval, :next_enqueue_at
5
+
6
+ # @param [any] klass
7
+ # @param [Array] args
8
+ # @param [Integer] interval
9
+ def initialize(klass: , args: , interval: )
10
+ self.klass = klass
11
+ self.args = args
12
+ self.interval = interval
13
+ self.next_enqueue_at = Time.now
14
+ end
15
+
16
+ # @return [void]
17
+ def enqueue
18
+ klass.perform_async(*unwrap_args(args))
19
+ set_next_enqueue_at!
20
+ end
21
+
22
+ # @return [boolean]
23
+ def past_interval?
24
+ next_enqueue_at < Time.now
25
+ end
26
+
27
+ private
28
+
29
+ # @return [void]
30
+ def set_next_enqueue_at!
31
+ self.next_enqueue_at = Time.now + interval
32
+ end
33
+
34
+ # @param [Array] args
35
+ # @return [void]
36
+ def unwrap_args(args)
37
+ args.map do |arg|
38
+ case arg
39
+ when Proc
40
+ arg.call
41
+ else
42
+ arg
43
+ end
44
+ end
45
+ end
46
+ end
47
+
48
+ # @return [Hash]
49
+ def self.schedules
50
+ @@schedules
51
+ end
52
+
53
+ @@schedules = {}
54
+
55
+ def self.start!
56
+ register_schedules
57
+
58
+ @@thread = Thread.start do
59
+ loop do
60
+ schedules.each do |_key, schedule|
61
+ if schedule.past_interval?
62
+ schedule.enqueue
63
+ end
64
+ end
65
+ sleep 10
66
+ end
67
+ end
68
+ end
69
+
70
+ def self.register_schedules
71
+ register(
72
+ schedule: Schedule.new(
73
+ klass: ProconBypassMan::FetchAndRunRemotePbmActionJob,
74
+ args: [],
75
+ interval: 3,
76
+ )
77
+ )
78
+ register(
79
+ schedule: Schedule.new(
80
+ klass: ProconBypassMan::SyncDeviceStatsJob,
81
+ args: [->{ ProconBypassMan::DeviceStatus.current }],
82
+ interval: 60,
83
+ )
84
+ )
85
+ end
86
+
87
+ # @param [Schedule] schedule
88
+ def self.register(schedule: )
89
+ schedules[schedule.klass] = schedule
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,15 @@
1
+ module ProconBypassMan
2
+ module Splatoon2
3
+ module Macro
4
+ module FastReturn
5
+ def self.name
6
+ :fast_return
7
+ end
8
+
9
+ def self.steps
10
+ [:x, :down, :a, :a].freeze
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ module ProconBypassMan
2
+ module Splatoon2
3
+ module Macro
4
+ module JumpToLeftKey
5
+ def self.name
6
+ :jump_to_left_key
7
+ end
8
+
9
+ def self.steps
10
+ [:x, :left, :a, :a].freeze
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ module ProconBypassMan
2
+ module Splatoon2
3
+ module Macro
4
+ module JumpToRightKey
5
+ def self.name
6
+ :jump_to_right_key
7
+ end
8
+
9
+ def self.steps
10
+ [:x, :right, :a, :a].freeze
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ module ProconBypassMan
2
+ module Splatoon2
3
+ module Macro
4
+ module JumpToUpKey
5
+ def self.name
6
+ :jump_to_up_key
7
+ end
8
+
9
+ def self.steps
10
+ [:x, :up, :a, :a].freeze
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,57 @@
1
+ module ProconBypassMan
2
+ module Splatoon2
3
+ module Mode
4
+ module Guruguru
5
+ def self.binaries
6
+ [ "309481408000362d684658750968f71cfe2c0e51000001480053f71ffedf0d4b000a013d00caf6ecfd4c0d480003011c00000000000000000000000000000000",
7
+ "30978140800037dd6748687509fdf6adfded0d6d0081005d00eef68dfdef0d6d00830059001bf791fd140e720090005400000000000000000000000000000000",
8
+ "309a8140800038cd67495875099af821fe120e40006400880042f8fcfdfd0d470067008900d4f7e0fdf20d4e006a008c00000000000000000000000000000000",
9
+ "309c8140800036ed67466875099bf878fe4a0e35005b004c00c1f875fe400e35005d004c00c4f856fe2d0e390063006c00000000000000000000000000000000",
10
+ "30a081408000371d6847587509b9f71bfee70d22002c002300e3f73afe150e2b003500280014f854fe300e2d0038002900000000000000000000000000000000",
11
+ "30a38140800039fd6743587509def70ffea10d1a0031001f00d1f70ffeb10d19002c002200c5f711feb80d18002c002500000000000000000000000000000000",
12
+ "30a58140800037dd6746687509d8f70bfe980d270035001200ddf70dfe980d240038001900dff70ffe9b0d1f0035001a00000000000000000000000000000000",
13
+ "30a98140800037ed67484875099cf7edfdb00d310020000d009ef7eefda30d310022000c00adf7f2fd980d300028000a00000000000000000000000000000000",
14
+ "30ac8140800036ed67484875099cf709fed40d3a002400160097f7fafdd30d39002200150096f7f0fdc80d380022001400000000000000000000000000000000",
15
+ "30ae8140800038fd674558750987f72efed40d360021001c0089f729fed50d39002400180092f715fed10d390022001800000000000000000000000000000000",
16
+ "30b18140800037dd6747487509b8f705fea90d19001d002000c5f70dfeb00d210019002200bff71efec20d280018002400000000000000000000000000000000",
17
+ "30b48140800038fd684868750980f7e9fdd40d0200080024007df7f1fdba0d060011001e0084f7f8fdaa0d12001a001a00000000000000000000000000000000",
18
+ "30b7814080003fdd694958750918f6a9fd510f0d00d1ff370024f7b0fda90e0100ecff30006cf7d1fd210efffff5ff2c00000000000000000000000000000000",
19
+ "30ba81408080482d744768750963f71ffe190f5e00d9fea100ccf62dfe650f510009ff980015f702fe580f4b002eff8400000000000000000000000000000000",
20
+ "30bd814080802f7d864758750974f70efe4c0f5e00c0fea000d1f726fe1c0f5d00c5fea30028f859fe0e0f5c00cafea800000000000000000000000000000000",
21
+ "30bf8140808057cc984758750961f73afe630f99009dfeae0050f738fe710f7500adfea40050f721fe720f6e00b2fea300000000000000000000000000000000",
22
+ "30c281408080f479bd483875092ef8b6feab0f0a0180feba00f1f798fe900f000181febd00c2f77dfe7c0fdb008efebd00000000000000000000000000000000",
23
+ "30c581408080ad87d846487509e1f80000a6107e0178fea2004ef88dff54106c0185fea70063f826ffe60f520182feae00000000000000000000000000000000",
24
+ "30c8810080800797d84868750995f8e1fe4b0f7a0161fe88000df96dffd00f700149fe990035f9cdff361088016afea000000000000000000000000000000000",
25
+ "30cb810080804586d848487509cef672fe8a0f6d0217ff42002df63cfe280f1d0219ff410059f61cfe070fed01f5fe4a00000000000000000000000000000000",
26
+ "30d08100808002c5d745687509d8f5aaff830f5e03e6fe3e01fbf55bffc30f3f03e4fe100158f600ff3e102903e5fee700000000000000000000000000000000",
27
+ "30d3810080807b94d14838750991f6cd00690f9903f0fff10147f6e200560f7e038fffc60101f6c900560f71033bffa901000000000000000000000000000000",
28
+ "30d681008080b743ca475875095af7f2009c0fca03a400320242f7ca00950fb503820028020af7b000820fa4034e001a02000000000000000000000000000000",
29
+ "30d9810080805be3c047587509e7f77a03c70f0e04bb00410258f79801940f0004b800410251f74401910fd803b3003602000000000000000000000000000000",
30
+ "30dc810080808a02b245587509c0fbd5086a10710475020a03b0fb8d085d106c042102e8027efb660876106a04bc01af02000000000000000000000000000000",
31
+ "30de8100808036d2a14568750970fbbf09ad103704af038003a9fb600989105c0459036103c2fb2a097210690412034603000000000000000000000000000000",
32
+ "30e281008000cbb18d4738750989f8b40b2812380341044c0429f99e0bef11510340043704f2f93c0b7911b0033704f003000000000000000000000000000000",
33
+ "30e581008000c9c18945587509a5f7ca0a2e13e400c6024c0547f7fd0a941264011703270578f74a0b6012e40168030205000000000000000000000000000000",
34
+ "30e781008000c6618948687509acf86909e813d0fe2801a1057cf8cf09ed130fff6301990516f8710aaa13ccff13028205000000000000000000000000000000",
35
+ "30ea81008000c77189475875093af93b0762136efbaeff19060cf90107b113a9fb99ff0906e1f85b07b113bafc9fffcd05000000000000000000000000000000",
36
+ "30ed81008000c791894568750950f9ce047c1432f900026007a5f9a6051f146ef9bb013707bff99206a813fef9ce00c606000000000000000000000000000000",
37
+ "30ef81008000c6d1894558750944f8ad0358143ef81c02f10780f8b403841484f84102d107ccf801049314bcf84202ad07000000000000000000000000000000",
38
+ "30f381008000c761884868750914f72105e4134cf6d001c00743f71a05f11391f6bf01e407a0f7c904fa13faf6b3011008000000000000000000000000000000",
39
+ "30f681008000c7718344587509eaf54a04c812a6f40002500627f66d041313f2f40d02940682f6a60468133ef51a02d806000000000000000000000000000000",
40
+ "30f881008000c4e1814668750b5cf5f803b51125f3b5000d0560f50f04e8118cf33c015d057df525042c1210f4b101cc05000000000000000000000000000000",
41
+ "30fb81008000c5e1814458750b19f65a02a410acf29effb804e2f5db02df10b7f2c0ffbf04a9f55c032011dcf22400d804000000000000000000000000000000",
42
+ "30fe8100800035e2814858750b81f65c00f80f8df231fe940471f6e6001f1088f2a6fe92044ef6b1015a1092f21fffa004000000000000000000000000000000",
43
+ "3001810080004b03814868750b69f6e6fdad0ffef20efdd40479f678feb40fd9f249fdc40484f6f4fec00fb0f29ffdad04000000000000000000000000000000",
44
+ "30048100800079e47d4858750b17f64cfb5f0f46f46afb430529f6c4fb710ff1f3d4fb300538f64bfc830fbbf315fc1d05000000000000000000000000000000",
45
+ "300781008000a7057e4668750bb1f5d3f9fb0e8ef5ccf96405cdf5fcf90c0f44f52dfa6505e1f52dfa210f29f550fa6305000000000000000000000000000000",
46
+ "30098100800041f67d4668750bcdf4b0f9ab0e21f602f955057ef5adf9d00ee1f559f95f05b1f5d3f9fb0e8ef5ccf96405000000000000000000000000000000",
47
+ "300d810080003d877c4838750b84f458f7dd0c89f6d0f8fc0436f4e2f7620d83f614f8430526f4c0f8a00e71f666f85c05000000000000000000000000000000",
48
+ "30108100800058e77a4668750bf7f2c3f57c0c9cf6abfa0a0470f30ef6790c89f65dfa420414f476f67e0c80f6d0f98a04000000000000000000000000000000",
49
+ "30128100800059f77a4658750b7ef249f5580cd9f69bfaa40389f269f56c0cd1f6a9fab503a3f286f5760cacf6c9faeb03000000000000000000000000000000",
50
+ "3016810080005b177b4868750ba9f298f4450b2cf774fa3102b8f2a5f47a0b24f765fa6e02b8f2b8f4b10b1df755faac02000000000000000000000000000000",
51
+ "30198100800057777a4558750b39f258f4480a80f73efaf40016f26af4940a5ef76bfa37014ef275f4d40a46f780fa8401000000000000000000000000000000",
52
+ ].map(&:freeze).freeze
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ProconBypassMan
4
+ module Splatoon2
5
+ VERSION = "0.1.1"
6
+ end
7
+ end
@@ -0,0 +1,11 @@
1
+ require_relative "splatoon2/version"
2
+ require_relative "splatoon2/macro/fast_return"
3
+ require_relative "splatoon2/macro/jump_to_right_key"
4
+ require_relative "splatoon2/macro/jump_to_up_key"
5
+ require_relative "splatoon2/macro/jump_to_left_key"
6
+ require_relative "splatoon2/mode/guruguru"
7
+
8
+ module ProconBypassMan
9
+ module Splatoon2
10
+ end
11
+ end
@@ -0,0 +1,56 @@
1
+ module ProconBypassMan
2
+ class CompressArray
3
+ class CompressibleValue
4
+ # @params [String] prev
5
+ # @params [String] current
6
+ def initialize(prev, current)
7
+ @prev = prev
8
+ @current = current
9
+ end
10
+
11
+ # @return [Boolean]
12
+ def compress?
13
+ @prev.include?(@current)
14
+ end
15
+
16
+ # @return [String]
17
+ def to_s_with_mark
18
+ if /^(.+) \* (\d+)/ =~ @prev
19
+ value = $1
20
+ count = $2
21
+ return "#{value} * #{count.to_i + 1}"
22
+ end
23
+ if /^(.+)/ =~ @prev
24
+ value = $1
25
+ return "#{value} * 1"
26
+ end
27
+ end
28
+ end
29
+
30
+ def initialize(array)
31
+ @array = array
32
+ end
33
+
34
+ # @return [Array<String>]
35
+ def compress
36
+ previous_value = nil
37
+ @array.reduce([]) do |acc, item|
38
+ if previous_value.nil?
39
+ acc << item
40
+ previous_value = item
41
+ next acc
42
+ end
43
+
44
+ if CompressibleValue.new(previous_value, item).compress?
45
+ registered_value = acc.pop
46
+ acc << CompressibleValue.new(registered_value, item).to_s_with_mark
47
+ else
48
+ acc << item
49
+ end
50
+
51
+ previous_value = item
52
+ next acc
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,102 @@
1
+ module ProconBypassMan
2
+ class HttpClient
3
+ class HttpRequest
4
+ class Get
5
+ def self.request!(uri: )
6
+ http = Net::HTTP.new(uri.host, uri.port)
7
+ http.use_ssl = uri.scheme === "https"
8
+ http.get(uri.path, { "Content-Type" => "application/json" })
9
+ end
10
+ end
11
+
12
+ class Post
13
+ def self.request!(uri: , request_body: {})
14
+ http = Net::HTTP.new(uri.host, uri.port)
15
+ http.use_ssl = uri.scheme === "https"
16
+ http.post(uri.path, request_body.to_json, { "Content-Type" => "application/json" })
17
+ end
18
+ end
19
+
20
+ class Put
21
+ def self.request!(uri: , request_body: {})
22
+ http = Net::HTTP.new(uri.host, uri.port)
23
+ http.use_ssl = uri.scheme === "https"
24
+ http.put(uri.path, request_body.to_json, { "Content-Type" => "application/json" })
25
+ end
26
+ end
27
+ end
28
+
29
+ def initialize(path: , server_pool: , retry_on_connection_error: false)
30
+ @server_pool = server_pool
31
+ @uri = URI.parse("#{server_pool.server}#{path}")
32
+ @retry_on_connection_error = retry_on_connection_error
33
+ end
34
+
35
+ def get
36
+ handle_request do
37
+ response = HttpRequest::Get.request!(
38
+ uri: @uri,
39
+ )
40
+ break process_response(response)
41
+ end
42
+ end
43
+
44
+ def post(request_body: )
45
+ handle_request do
46
+ body = {}.merge!(request_body)
47
+ response = HttpRequest::Post.request!(
48
+ uri: @uri,
49
+ request_body: body,
50
+ )
51
+ break process_response(response)
52
+ end
53
+ end
54
+
55
+ def put(request_body: )
56
+ handle_request do
57
+ body = {
58
+ hostname: `hostname`.chomp,
59
+ }.merge!(request_body)
60
+ response = HttpRequest::Put.request!(
61
+ uri: @uri,
62
+ request_body: body,
63
+ )
64
+ break process_response(response)
65
+ end
66
+ end
67
+
68
+ private
69
+
70
+ def process_response(response)
71
+ case response.code
72
+ when /^200/
73
+ begin
74
+ return JSON.parse(response.body)
75
+ rescue JSON::ParserError
76
+ return response.body
77
+ end
78
+ else
79
+ @server_pool.next!
80
+ ProconBypassMan.logger.error("#{@uri}から200以外(#{response.code})が帰ってきました. #{response.body}")
81
+ end
82
+ end
83
+
84
+ def handle_request
85
+ raise "need block" unless block_given?
86
+ if @server_pool.server.nil?
87
+ ProconBypassMan.logger.info('送信先が未設定なのでスキップしました')
88
+ return
89
+ end
90
+ return yield
91
+ rescue SocketError => e
92
+ ProconBypassMan.logger.error(e)
93
+ if @retry_on_connection_error
94
+ sleep(10)
95
+ retry
96
+ end
97
+ rescue => e
98
+ puts e
99
+ ProconBypassMan.logger.error(e)
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,19 @@
1
+ module ProconBypassMan
2
+ class ReportHttpClient < HttpClient
3
+ def post(body: , event_type: )
4
+ if body.is_a?(String)
5
+ b = { text: body }
6
+ else
7
+ b = body
8
+ end
9
+
10
+ super(request_body: {
11
+ session_id: ProconBypassMan.session_id,
12
+ device_id: ProconBypassMan.device_id,
13
+ hostname: `hostname`.chomp,
14
+ event_type: event_type,
15
+ body: b,
16
+ })
17
+ end
18
+ end
19
+ end
@@ -1,5 +1,5 @@
1
1
  module ProconBypassMan
2
- class Timer
2
+ class SafeTimeout
3
3
  class Timeout < StandardError; end
4
4
 
5
5
  # 5秒後がタイムアウト