wc3_protocol 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/.rspec +2 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/README.md +87 -0
- data/Rakefile +15 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/doc/Warcraft III Game Packet Specs.pdf +0 -0
- data/lib/custom_errors/custom_error.rb +2 -0
- data/lib/wc3_protocol/broadcast.rb +82 -0
- data/lib/wc3_protocol/message.rb +153 -0
- data/lib/wc3_protocol/protocol.rb +29 -0
- data/lib/wc3_protocol/server_info.rb +28 -0
- data/lib/wc3_protocol/version.rb +3 -0
- data/lib/wc3_protocol.rb +6 -0
- data/wc3_protocol.gemspec +37 -0
- metadata +104 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 497152467d10e7a3e76fc722af52711c61be78688223dc49c3d6f964409e8454
|
4
|
+
data.tar.gz: 3a893457a4b10d0f50ecba541842062bad79a4990cc5452ce56e5dab8cb071fa
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fab86e87c0553c716d02fe2c0bc1ffa9655b75099b09355ffba511e782b57c2befa9f114dca338395e49657af1b7be0298d3eb8b22c2a583a5044439069da239
|
7
|
+
data.tar.gz: 3a63d93392bf209b4e084d9704164724a256f5e1d0749e83baa7bf3f05806f79e9c21a809c3c2c1144d34c569a38970c552dee73a7c1dca05ebc5664d72178ac
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at wc3_protocol.gemspec@mail.magynhard.de. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2023 Matthäus J. N. Beyrle
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
# wc3_protocol
|
2
|
+
![Gem](https://img.shields.io/gem/v/wc3_protocol?color=default&style=plastic&logo=ruby&logoColor=red)
|
3
|
+
![Gem](https://img.shields.io/gem/dt/wc3_protocol?color=blue&style=plastic)
|
4
|
+
[![License: MIT](https://img.shields.io/badge/License-MIT-gold.svg?style=plastic&logo=mit)](LICENSE)
|
5
|
+
|
6
|
+
> The ruby gem to find and retrieve information of Warcraft3 games
|
7
|
+
|
8
|
+
# Contents
|
9
|
+
|
10
|
+
* [Usage](#usage)
|
11
|
+
* [Installation](#installation)
|
12
|
+
* [Documentation](#documentation)
|
13
|
+
* [Contributing](#contributing)
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
|
18
|
+
<a name="usage"></a>
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
### Find games in LAN
|
22
|
+
```ruby
|
23
|
+
require 'wc3_protocol'
|
24
|
+
|
25
|
+
# examples with explicit default parameters
|
26
|
+
games = Wc3Protocol::Broadcast.find_games port: 6112, version: '1.27', game_type: 'TFT'
|
27
|
+
# => [Wc3Protocol::ServerInfo, Wc3Protocol::ServerInfo, ...]
|
28
|
+
|
29
|
+
games.each do |g|
|
30
|
+
puts "=================================================="
|
31
|
+
puts "Found game on #{g.remote_address}:#{g.remote_port}"
|
32
|
+
puts
|
33
|
+
puts "Type: #{g.game_type}"
|
34
|
+
puts "Version: #{g.game_version}"
|
35
|
+
puts "Name: #{g.name}"
|
36
|
+
puts "Map: #{g.map_name}"
|
37
|
+
puts "Players: #{g.taken_slots}/#{g.max_slots}"
|
38
|
+
puts
|
39
|
+
# =================================================="
|
40
|
+
# Found game on 192.168.178.20:6112"
|
41
|
+
#
|
42
|
+
# Type: The Frozen Throne
|
43
|
+
# Version: 1.27
|
44
|
+
# Name: Local game (SuperPlayer)
|
45
|
+
# Map: (4)Tanaris.w3x
|
46
|
+
# Players: 3/4"
|
47
|
+
#
|
48
|
+
end
|
49
|
+
|
50
|
+
```
|
51
|
+
|
52
|
+
|
53
|
+
<a name="installation"></a>
|
54
|
+
## Installation
|
55
|
+
|
56
|
+
Add this line to your application's Gemfile:
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
gem 'wc3_protocol'
|
60
|
+
```
|
61
|
+
|
62
|
+
And then execute:
|
63
|
+
|
64
|
+
$ bundle install
|
65
|
+
|
66
|
+
Or install it yourself by:
|
67
|
+
|
68
|
+
$ gem install wc3_protocol
|
69
|
+
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
|
74
|
+
<a name="documentation"></a>
|
75
|
+
## Documentation
|
76
|
+
Check out the doc at RubyDoc
|
77
|
+
<a href="https://www.rubydoc.info/gems/wc3_protocol">https://www.rubydoc.info/gems/wc3_protocol</a>
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
<a name="contributing"></a>
|
84
|
+
## Contributing
|
85
|
+
|
86
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/magynhard/wc3_protocol. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
87
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rspec/core/rake_task"
|
3
|
+
|
4
|
+
#
|
5
|
+
# run default task to see tasks to build and publish gem
|
6
|
+
#
|
7
|
+
task :default do
|
8
|
+
system 'rake --tasks'
|
9
|
+
end
|
10
|
+
|
11
|
+
task :test do
|
12
|
+
system 'rspec'
|
13
|
+
end
|
14
|
+
|
15
|
+
RSpec::Core::RakeTask.new(:spec)
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "lucky_case"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
Binary file
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'socket'
|
2
|
+
require 'stringio'
|
3
|
+
require 'timeout'
|
4
|
+
require 'ostruct'
|
5
|
+
|
6
|
+
require_relative 'protocol'
|
7
|
+
|
8
|
+
module Wc3Protocol
|
9
|
+
|
10
|
+
class Broadcast
|
11
|
+
|
12
|
+
GAME_TYPE = {
|
13
|
+
'TFT' => 'W3XP',
|
14
|
+
'ROC' => 'WAR3'
|
15
|
+
}
|
16
|
+
|
17
|
+
# @param [Integer] port
|
18
|
+
# @param [String] version
|
19
|
+
# @param ['ROC','TFT'] game_type
|
20
|
+
# @return [Array<Wc3Protocol::ServerInfo>] server info of found games
|
21
|
+
def self.find_games port: 6112, version: '1.27', game_type: 'TFT'
|
22
|
+
_broadcast_request port: port, version: version, game_type: game_type
|
23
|
+
# @type [Array<Wc3Protocol::Message>]
|
24
|
+
messages = _broadcast_receive
|
25
|
+
messages.select { |m| Protocol::BYTE_OP_CODE[m.op_code] == :GAME_INFORMATION }.map { |m| Wc3Protocol::ServerInfo.new(m) }
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def self._broadcast_request port:, version:, game_type:
|
31
|
+
# Open socket and listen for broadcast messages
|
32
|
+
@udp_socket = UDPSocket.new
|
33
|
+
@udp_socket.bind('0.0.0.0', port)
|
34
|
+
|
35
|
+
# request for games
|
36
|
+
broadcast_address = '255.255.255.255'
|
37
|
+
broadcast_port = 6112
|
38
|
+
|
39
|
+
# we need only the minor from version for the broadcast
|
40
|
+
version_integer = version.split('.').last.to_i
|
41
|
+
game_type_bytes = GAME_TYPE[game_type].reverse.bytes # needs to be reversed because of little endian order(?)
|
42
|
+
packet_size_byte = 16
|
43
|
+
|
44
|
+
# broadcast to ask for TFT games
|
45
|
+
data_to_send = [
|
46
|
+
"0xf7".to_i(16),
|
47
|
+
"0x2f".to_i(16),
|
48
|
+
*[packet_size_byte, 0],
|
49
|
+
*game_type_bytes,
|
50
|
+
*[version_integer, 0, 0, 0],
|
51
|
+
*[0, 0, 0, 0],
|
52
|
+
]
|
53
|
+
|
54
|
+
data_to_send = data_to_send.pack('C*')
|
55
|
+
|
56
|
+
begin
|
57
|
+
@udp_socket.setsockopt(Socket::SOL_SOCKET, Socket::SO_BROADCAST, true)
|
58
|
+
@udp_socket.send(data_to_send, 0, broadcast_address, broadcast_port)
|
59
|
+
ensure
|
60
|
+
# udp_socket.close if udp_socket
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def self._broadcast_receive
|
65
|
+
raw_messages = []
|
66
|
+
waiting_timeout_seconds = 1
|
67
|
+
begin
|
68
|
+
Timeout.timeout(waiting_timeout_seconds) do
|
69
|
+
loop do
|
70
|
+
# Wait for message
|
71
|
+
message, sender_info = @udp_socket.recvfrom(1024)
|
72
|
+
raw_messages.push(OpenStruct.new message: message, sender_info: sender_info)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
rescue Timeout::Error
|
76
|
+
# messages received until timeout
|
77
|
+
end
|
78
|
+
raw_messages.map { |m| Wc3Protocol::Message.new(raw_msg: m.message, raw_sender_info: m.sender_info) }
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,153 @@
|
|
1
|
+
require_relative 'protocol'
|
2
|
+
|
3
|
+
module Wc3Protocol
|
4
|
+
|
5
|
+
class Message
|
6
|
+
|
7
|
+
attr_reader :sender_address_family
|
8
|
+
attr_reader :sender_port
|
9
|
+
attr_reader :sender_hostname
|
10
|
+
attr_reader :sender_ip_address
|
11
|
+
|
12
|
+
attr_reader :raw_bytes
|
13
|
+
attr_reader :raw_bytes_hex
|
14
|
+
|
15
|
+
attr_reader :magic_byte
|
16
|
+
attr_reader :op_code
|
17
|
+
attr_reader :packet_size
|
18
|
+
attr_reader :game_type
|
19
|
+
attr_reader :game_version
|
20
|
+
attr_reader :game_id
|
21
|
+
attr_reader :tick_counts_ms
|
22
|
+
attr_reader :game_settings
|
23
|
+
attr_reader :game_name
|
24
|
+
# attr_reader :zero_flag
|
25
|
+
attr_reader :game_map_name
|
26
|
+
attr_reader :game_map_width
|
27
|
+
attr_reader :game_map_height
|
28
|
+
attr_reader :game_number_of_slots
|
29
|
+
attr_reader :game_flags
|
30
|
+
attr_reader :game_player_slots
|
31
|
+
attr_reader :game_non_computer_slots
|
32
|
+
attr_reader :game_computer_or_closed_slots
|
33
|
+
attr_reader :game_remaining_slots
|
34
|
+
attr_reader :game_filled_slots
|
35
|
+
# attr_reader :unknown_byte
|
36
|
+
attr_reader :game_port
|
37
|
+
|
38
|
+
def initialize(raw_msg:, raw_sender_info:)
|
39
|
+
_parse_message raw_msg, raw_sender_info
|
40
|
+
end
|
41
|
+
|
42
|
+
def lan?
|
43
|
+
!battle_net?
|
44
|
+
end
|
45
|
+
|
46
|
+
def battle_net?
|
47
|
+
@magic_byte == 'ff'
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def _parse_message(msg, sender_info)
|
53
|
+
@raw_bytes = msg.bytes
|
54
|
+
@raw_hex_bytes = @raw_bytes.map { |p| p.to_s(16) }
|
55
|
+
|
56
|
+
@magic_byte = Wc3Protocol::Protocol::BYTE_MAGIC[@raw_bytes[0].to_s(16)]
|
57
|
+
@op_code = [@raw_bytes[1]].pack('C').unpack('C')[0].to_s(16)
|
58
|
+
@packet_size = @raw_bytes[2..3].pack('C*').unpack('S<')[0]
|
59
|
+
@game_type = Wc3Protocol::Protocol::BYTE_GAME_TYPE[(msg[4..7]).to_s.reverse]
|
60
|
+
@game_version = "1." + @raw_bytes[8..11].pack('C*').unpack('L<')[0].to_s
|
61
|
+
@game_id = @raw_bytes[12..15].pack('C*').unpack('L<')[0]
|
62
|
+
|
63
|
+
@sender_address_family = sender_info[0]
|
64
|
+
@sender_port = sender_info[1]
|
65
|
+
@sender_hostname = sender_info[2]
|
66
|
+
@sender_ip_address = sender_info[3]
|
67
|
+
|
68
|
+
case @op_code
|
69
|
+
when '2f'
|
70
|
+
# do nothing, header only
|
71
|
+
when '30'
|
72
|
+
_parse_op_code_30
|
73
|
+
else
|
74
|
+
puts "WARNING: Unknown, unprocessed OP code #{@op_code}"
|
75
|
+
# raise StandardError.new "Unknown Protocol Code"
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def _parse_op_code_30
|
80
|
+
if op_code == '30'
|
81
|
+
@tick_count_ms = @raw_bytes[16..19].pack('C*').unpack('L<')[0]
|
82
|
+
game_info_bytes = @raw_bytes[20..-23]
|
83
|
+
@game_settings = game_info_bytes[0..3].pack('C*').unpack('L<')[0]
|
84
|
+
zero_flag = game_info_bytes[31]
|
85
|
+
@game_name = _get_string_segment(@raw_bytes[20..-1])
|
86
|
+
encoded_segment_start_index = 22 + _utf8_byte_count(@game_name)
|
87
|
+
decrypted = _decode_string_part(@raw_bytes[encoded_segment_start_index..-1]).bytes
|
88
|
+
@game_settings = decrypted[0..3].pack('C*').unpack('L<')[0]
|
89
|
+
decrypted_string = decrypted.pack('C*')
|
90
|
+
|
91
|
+
# extract map name from 14th byte
|
92
|
+
@game_map_name = decrypted_string[13..-1]
|
93
|
+
|
94
|
+
# Get last segment of map name that is split by '\\'
|
95
|
+
last_map_name_segment = @game_map_name.split('\\').last
|
96
|
+
last_map_name_segment = last_map_name_segment[0..(last_map_name_segment.index('.w3') + 4)]
|
97
|
+
|
98
|
+
# use original map name if no segment is found
|
99
|
+
@game_map_name = last_map_name_segment || @game_map_name
|
100
|
+
|
101
|
+
@game_map_width = decrypted[5..-1].pack('C*').unpack('S<')[0]
|
102
|
+
@game_map_height = decrypted[7..-1].pack('C*').unpack('S<')[0]
|
103
|
+
|
104
|
+
game_info_string = decrypted
|
105
|
+
@game_number_of_slots = @raw_bytes[-22..-19].pack('C*').unpack('L<')[0]
|
106
|
+
@game_flags = @raw_bytes[-18..-15].pack('C*').unpack('L<')[0]
|
107
|
+
@game_player_slots = @raw_bytes[-14..-11].pack('C*').unpack('L<')[0]
|
108
|
+
@game_non_computer_slots = @raw_bytes[-10..-7].pack('C*').unpack('L<')[0]
|
109
|
+
@game_computer_or_closed_slots = @game_number_of_slots - @game_non_computer_slots
|
110
|
+
@game_remaining_slots = @game_number_of_slots - @game_computer_or_closed_slots - @game_player_slots
|
111
|
+
@game_filled_slots = @game_computer_or_closed_slots + @game_player_slots
|
112
|
+
unknown_byte = @raw_bytes[-6..-3].pack('C*').unpack('L<')[0]
|
113
|
+
@game_port = @raw_bytes[-2..-1].pack('C*').unpack('S<')[0]
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def _decode_string_part(data)
|
118
|
+
mask = 0
|
119
|
+
memory_stream = StringIO.new
|
120
|
+
|
121
|
+
first_zero_index = data.index(0)
|
122
|
+
data_cut = first_zero_index.nil? ? data : data[0...first_zero_index]
|
123
|
+
|
124
|
+
data_cut.each_with_index do |b, i|
|
125
|
+
if i % 8 != 0
|
126
|
+
if (mask & (1 << (i % 8))) == 0
|
127
|
+
memory_stream.putc(b - 1)
|
128
|
+
else
|
129
|
+
memory_stream.putc(b)
|
130
|
+
end
|
131
|
+
else
|
132
|
+
mask = b
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
memory_stream.string
|
137
|
+
end
|
138
|
+
|
139
|
+
def _get_string_segment(data)
|
140
|
+
first_zero_index = data.index(0)
|
141
|
+
return '' if first_zero_index.nil?
|
142
|
+
|
143
|
+
string_segment = data[0...first_zero_index]
|
144
|
+
string_segment.pack('C*').force_encoding('UTF-8')
|
145
|
+
end
|
146
|
+
|
147
|
+
def _utf8_byte_count(string)
|
148
|
+
utf8_string = string.encoding.name == 'UTF-8' ? string : string.encode('UTF-8')
|
149
|
+
utf8_string.bytesize
|
150
|
+
end
|
151
|
+
|
152
|
+
end
|
153
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Wc3Protocol
|
2
|
+
module Protocol
|
3
|
+
BYTE_MAGIC = {
|
4
|
+
'f7' => 'LAN',
|
5
|
+
'ff' => 'BATTLE_NET'
|
6
|
+
}
|
7
|
+
BYTE_OP_CODE = {
|
8
|
+
'2f' => :LAN_GAME_QUERY,
|
9
|
+
'30' => :GAME_INFORMATION,
|
10
|
+
'31' => :GAME_CREATED,
|
11
|
+
'32' => :PLAYERS_CHANGED,
|
12
|
+
'33' => :GAME_CANCELLED,
|
13
|
+
'01' => :KEEP_ALIVE,
|
14
|
+
'04' => :JOINED_PLAYER_INFORMATION,
|
15
|
+
'06' => :PLAYER_INFO,
|
16
|
+
'07' => :PLAYER_LEFT_GAME,
|
17
|
+
'08' => :PLAYER_LOADED_GAME,
|
18
|
+
'09' => :SLOTS_CHANGED,
|
19
|
+
'0a' => :HOST_STARTED_GAME,
|
20
|
+
'0b' => :START_LOADING_INFO,
|
21
|
+
'0f' => :CHAT_RECEIVERS,
|
22
|
+
# TODO: more bytes available
|
23
|
+
}
|
24
|
+
BYTE_GAME_TYPE = {
|
25
|
+
'W3XP' => 'The Frozen Throne',
|
26
|
+
'WAR3' => 'Realms of Chaos'
|
27
|
+
}
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Wc3Protocol
|
2
|
+
|
3
|
+
class ServerInfo
|
4
|
+
attr_reader :name
|
5
|
+
attr_reader :taken_slots
|
6
|
+
attr_reader :max_slots
|
7
|
+
attr_reader :map_name
|
8
|
+
|
9
|
+
attr_reader :game_type
|
10
|
+
attr_reader :game_version
|
11
|
+
|
12
|
+
attr_reader :remote_address
|
13
|
+
attr_reader :remote_port
|
14
|
+
|
15
|
+
# @param [Wc3Protocol::Message] message
|
16
|
+
def initialize(message)
|
17
|
+
@name = message.game_name
|
18
|
+
@taken_slots = message.game_number_of_slots - message.game_remaining_slots
|
19
|
+
@max_slots = message.game_number_of_slots
|
20
|
+
@map_name = message.game_map_name
|
21
|
+
@remote_address = message.sender_ip_address
|
22
|
+
@remote_port = message.sender_port
|
23
|
+
@game_version = message.game_version
|
24
|
+
@game_type = message.game_type
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
data/lib/wc3_protocol.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'wc3_protocol/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "wc3_protocol"
|
8
|
+
spec.version = Wc3Protocol::VERSION
|
9
|
+
spec.authors = ["Matthäus J. N. Beyrle"]
|
10
|
+
spec.email = ["wc3_protocol.gemspec@mail.magynhard.de"]
|
11
|
+
|
12
|
+
spec.summary = %q{The ruby gem to find and retrieve information of Warcraft3 games}
|
13
|
+
spec.homepage = "https://github.com/magynhard/wc3_protocol"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
17
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
18
|
+
if spec.respond_to?(:metadata)
|
19
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
20
|
+
else
|
21
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
22
|
+
"public gem pushes."
|
23
|
+
end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
26
|
+
f.match(%r{^(test|spec|features)/})
|
27
|
+
end
|
28
|
+
spec.bindir = 'exe'
|
29
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
30
|
+
spec.require_paths = ['lib']
|
31
|
+
|
32
|
+
spec.required_ruby_version = '>= 2.3'
|
33
|
+
|
34
|
+
spec.add_development_dependency 'bundler', '>= 2.0'
|
35
|
+
spec.add_development_dependency 'rake', '>= 10.0'
|
36
|
+
spec.add_development_dependency 'rspec', '>= 3.0'
|
37
|
+
end
|
metadata
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: wc3_protocol
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matthäus J. N. Beyrle
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-10-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- wc3_protocol.gemspec@mail.magynhard.de
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rspec"
|
64
|
+
- CODE_OF_CONDUCT.md
|
65
|
+
- Gemfile
|
66
|
+
- LICENSE
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- bin/console
|
70
|
+
- bin/setup
|
71
|
+
- doc/Warcraft III Game Packet Specs.pdf
|
72
|
+
- lib/custom_errors/custom_error.rb
|
73
|
+
- lib/wc3_protocol.rb
|
74
|
+
- lib/wc3_protocol/broadcast.rb
|
75
|
+
- lib/wc3_protocol/message.rb
|
76
|
+
- lib/wc3_protocol/protocol.rb
|
77
|
+
- lib/wc3_protocol/server_info.rb
|
78
|
+
- lib/wc3_protocol/version.rb
|
79
|
+
- wc3_protocol.gemspec
|
80
|
+
homepage: https://github.com/magynhard/wc3_protocol
|
81
|
+
licenses:
|
82
|
+
- MIT
|
83
|
+
metadata:
|
84
|
+
allowed_push_host: https://rubygems.org
|
85
|
+
post_install_message:
|
86
|
+
rdoc_options: []
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '2.3'
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
requirements: []
|
100
|
+
rubygems_version: 3.1.4
|
101
|
+
signing_key:
|
102
|
+
specification_version: 4
|
103
|
+
summary: The ruby gem to find and retrieve information of Warcraft3 games
|
104
|
+
test_files: []
|