From 4a12262ad3981fb2ae686a3d66bce65ebae10e2a Mon Sep 17 00:00:00 2001 From: ChillerDragon Date: Wed, 16 Nov 2022 09:37:47 +0100 Subject: [PATCH] Move all network payload classes to messages/ --- lib/game_client.rb | 4 ++-- lib/game_server.rb | 12 ++++++------ lib/message.rb | 11 ----------- lib/{models => messages}/cl_emoticon.rb | 0 lib/{models => messages}/cl_say.rb | 0 lib/{models => messages}/client_info.rb | 0 lib/{models => messages}/game_info.rb | 0 lib/{models => messages}/input_timing.rb | 0 lib/{models => messages}/server_info.rb | 2 +- lib/{models => messages}/server_settings.rb | 0 lib/{models => messages}/start_info.rb | 0 lib/{models => messages}/sv_client_drop.rb | 0 lib/net_base.rb | 10 ++++++++++ lib/teeworlds_client.rb | 3 +-- lib/teeworlds_server.rb | 1 - scripts/bin/twnet | 2 +- spec/06_server_info_spec.rb | 2 +- spec/07_game_info_spec.rb | 2 +- 18 files changed, 23 insertions(+), 26 deletions(-) delete mode 100644 lib/message.rb rename lib/{models => messages}/cl_emoticon.rb (100%) rename lib/{models => messages}/cl_say.rb (100%) rename lib/{models => messages}/client_info.rb (100%) rename lib/{models => messages}/game_info.rb (100%) rename lib/{models => messages}/input_timing.rb (100%) rename lib/{models => messages}/server_info.rb (97%) rename lib/{models => messages}/server_settings.rb (100%) rename lib/{models => messages}/start_info.rb (100%) rename lib/{models => messages}/sv_client_drop.rb (100%) diff --git a/lib/game_client.rb b/lib/game_client.rb index 1fcf5b7..ba4b44f 100644 --- a/lib/game_client.rb +++ b/lib/game_client.rb @@ -2,8 +2,8 @@ require_relative 'models/player' require_relative 'models/chat_message' -require_relative 'models/input_timing' -require_relative 'models/sv_client_drop' +require_relative 'messages/input_timing' +require_relative 'messages/sv_client_drop' require_relative 'packer' require_relative 'context' diff --git a/lib/game_server.rb b/lib/game_server.rb index 06df2a3..0edcb75 100644 --- a/lib/game_server.rb +++ b/lib/game_server.rb @@ -1,13 +1,13 @@ # frozen_string_literal: true require_relative 'models/map' -require_relative 'models/server_info' -require_relative 'models/server_settings' -require_relative 'models/game_info' -require_relative 'models/start_info' -require_relative 'models/cl_say' require_relative 'models/chat_message' -require_relative 'models/cl_emoticon' +require_relative 'messages/game_info' +require_relative 'messages/server_info' +require_relative 'messages/server_settings' +require_relative 'messages/start_info' +require_relative 'messages/cl_say' +require_relative 'messages/cl_emoticon' class GameServer attr_accessor :pred_game_tick, :ack_game_tick, :map diff --git a/lib/message.rb b/lib/message.rb deleted file mode 100644 index da088e0..0000000 --- a/lib/message.rb +++ /dev/null @@ -1,11 +0,0 @@ -# frozen_string_literal: true - -## -# Turns int into network byte -# -# Takes a NETMSGTYPE_CL_* integer -# and returns a byte that can be send over -# the network -def pack_msg_id(msg_id, options = { system: false }) - (msg_id << 1) | (options[:system] ? 1 : 0) -end diff --git a/lib/models/cl_emoticon.rb b/lib/messages/cl_emoticon.rb similarity index 100% rename from lib/models/cl_emoticon.rb rename to lib/messages/cl_emoticon.rb diff --git a/lib/models/cl_say.rb b/lib/messages/cl_say.rb similarity index 100% rename from lib/models/cl_say.rb rename to lib/messages/cl_say.rb diff --git a/lib/models/client_info.rb b/lib/messages/client_info.rb similarity index 100% rename from lib/models/client_info.rb rename to lib/messages/client_info.rb diff --git a/lib/models/game_info.rb b/lib/messages/game_info.rb similarity index 100% rename from lib/models/game_info.rb rename to lib/messages/game_info.rb diff --git a/lib/models/input_timing.rb b/lib/messages/input_timing.rb similarity index 100% rename from lib/models/input_timing.rb rename to lib/messages/input_timing.rb diff --git a/lib/models/server_info.rb b/lib/messages/server_info.rb similarity index 97% rename from lib/models/server_info.rb rename to lib/messages/server_info.rb index 1fcece5..ebdd09f 100644 --- a/lib/models/server_info.rb +++ b/lib/messages/server_info.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true require_relative '../network' -require_relative 'player' +require_relative '../models/player' require_relative '../packer' class ServerInfo diff --git a/lib/models/server_settings.rb b/lib/messages/server_settings.rb similarity index 100% rename from lib/models/server_settings.rb rename to lib/messages/server_settings.rb diff --git a/lib/models/start_info.rb b/lib/messages/start_info.rb similarity index 100% rename from lib/models/start_info.rb rename to lib/messages/start_info.rb diff --git a/lib/models/sv_client_drop.rb b/lib/messages/sv_client_drop.rb similarity index 100% rename from lib/models/sv_client_drop.rb rename to lib/messages/sv_client_drop.rb diff --git a/lib/net_base.rb b/lib/net_base.rb index e341a8f..9aef0c5 100644 --- a/lib/net_base.rb +++ b/lib/net_base.rb @@ -2,6 +2,16 @@ require_relative 'models/token' +## +# Turns int into network byte +# +# Takes a NETMSGTYPE_CL_* integer +# and returns a byte that can be send over +# the network +def pack_msg_id(msg_id, options = { system: false }) + (msg_id << 1) | (options[:system] ? 1 : 0) +end + ## # NetBase # diff --git a/lib/teeworlds_client.rb b/lib/teeworlds_client.rb index 633e7ad..aadeb6b 100644 --- a/lib/teeworlds_client.rb +++ b/lib/teeworlds_client.rb @@ -8,12 +8,11 @@ require_relative 'bytes' require_relative 'network' require_relative 'packet' require_relative 'chunk' -require_relative 'models/server_info' +require_relative 'messages/server_info' require_relative 'net_base' require_relative 'packer' require_relative 'models/player' require_relative 'game_client' -require_relative 'message' class TeeworldsClient attr_reader :state, :hooks, :game_client diff --git a/lib/teeworlds_server.rb b/lib/teeworlds_server.rb index afa4015..aa4fab6 100644 --- a/lib/teeworlds_server.rb +++ b/lib/teeworlds_server.rb @@ -12,7 +12,6 @@ require_relative 'net_base' require_relative 'models/net_addr' require_relative 'packer' require_relative 'game_server' -require_relative 'message' require_relative 'models/token' class Client diff --git a/scripts/bin/twnet b/scripts/bin/twnet index 0f15955..5b8ba39 100755 --- a/scripts/bin/twnet +++ b/scripts/bin/twnet @@ -427,7 +427,7 @@ function action_generate() { fi local destfile - destfile="lib/models/$(basename "$tmpfile")" + destfile="lib/messages/$(basename "$tmpfile")" if [ -f "$destfile" ] then echo "Error: file already exists '$destfile'" diff --git a/spec/06_server_info_spec.rb b/spec/06_server_info_spec.rb index e728123..10c0a69 100644 --- a/spec/06_server_info_spec.rb +++ b/spec/06_server_info_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require_relative '../lib/models/server_info' +require_relative '../lib/messages/server_info' describe 'ServerInfo', :server_info do context 'Pack to network' do diff --git a/spec/07_game_info_spec.rb b/spec/07_game_info_spec.rb index 3f9928a..99e2080 100644 --- a/spec/07_game_info_spec.rb +++ b/spec/07_game_info_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require_relative '../lib/models/game_info' +require_relative '../lib/messages/game_info' describe 'GameInfo', :game_info do context 'Pack to network' do