rrb-common 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rune/common.rb +22 -7
- data/lib/rune/{network → core}/buffer.rb +9 -3
- data/lib/rune/{network → core}/constants.rb +1 -1
- data/lib/rune/core/identifiable.rb +47 -0
- data/lib/rune/{network → core}/isaac.rb +1 -1
- data/lib/rune/core/logging.rb +69 -0
- data/lib/rune/{network/readable.rb → core/readable_buffer.rb} +1 -1
- data/lib/rune/core/unit.rb +28 -0
- data/lib/rune/{network/writeable.rb → core/writeable_buffer.rb} +10 -11
- metadata +65 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c0ce773dfdfb39eebd3eca206e2f583acc855bbbd4a00677d7bc0e4e7f3d228
|
4
|
+
data.tar.gz: e7054853f2f0f99977ecb8a64fa18cfcd6159b07af9cf4815ad08988275d6353
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a8566a6cccb99f6c084c2fb012e38b8d47893173de6305d4c48dd01cf07bbad3404e1e969512728c4358c41cf73fdb8d8e887d20d636e5f2a0a8cebb2546119
|
7
|
+
data.tar.gz: '024422087af5f9646086bda2549af7cbac08facf82eb3cb76df32665136fc0dabcdb8bcf5d983e89dbe374811dcbbbb817a7f9d51fe20f040127e8ab2958f46c'
|
data/lib/rune/common.rb
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
Dir[File.dirname(__FILE__)].each { |file| $LOAD_PATH.unshift(file) if File.directory? file }
|
2
2
|
|
3
|
+
require 'console'
|
4
|
+
require 'dry/configurable'
|
5
|
+
require 'dry/container'
|
6
|
+
require 'securerandom'
|
7
|
+
require 'singleton'
|
8
|
+
|
3
9
|
# A game server written in Ruby targeting the 2006 era (or the 317-377 protocols) of the popular MMORPG, RuneScape.
|
4
10
|
#
|
5
11
|
# @title RuneRb
|
@@ -7,13 +13,16 @@ Dir[File.dirname(__FILE__)].each { |file| $LOAD_PATH.unshift(file) if File.direc
|
|
7
13
|
# @since 0.1.0
|
8
14
|
module RuneRb
|
9
15
|
|
10
|
-
# The
|
11
|
-
module
|
12
|
-
autoload :
|
13
|
-
autoload :
|
14
|
-
autoload :
|
15
|
-
autoload :
|
16
|
-
autoload :
|
16
|
+
# The Core module contains the core classes and modules of the Rune.rb framework.
|
17
|
+
module Core
|
18
|
+
autoload :Identifiable, 'rune/core/identifiable'
|
19
|
+
autoload :Logging, 'rune/core/logging'
|
20
|
+
autoload :Unit, 'rune/core/unit'
|
21
|
+
autoload :Buffer, 'rune/core/buffer'
|
22
|
+
autoload :Constants, 'rune/core/constants'
|
23
|
+
autoload :ISAAC, 'rune/core/isaac'
|
24
|
+
autoload :ReadableBuffer, 'rune/core/readable_buffer'
|
25
|
+
autoload :WriteableBuffer, 'rune/core/writeable_buffer'
|
17
26
|
|
18
27
|
include Constants
|
19
28
|
end
|
@@ -23,4 +32,10 @@ module RuneRb
|
|
23
32
|
autoload :IntegerRefinements, 'rune/patches/integer_refinements'
|
24
33
|
autoload :SetRefinements, 'rune/patches/set_refinements'
|
25
34
|
end
|
35
|
+
|
36
|
+
# The Logger utility for the RuneRb framework.
|
37
|
+
# @return [Console::Logger] the logger instance.
|
38
|
+
def self.logger
|
39
|
+
Console.logger
|
40
|
+
end
|
26
41
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module RuneRb::
|
1
|
+
module RuneRb::Core
|
2
2
|
|
3
3
|
# A Buffer encapsulates raw data in a String instance. Depending on the mode, the buffer can be read from or written to.
|
4
4
|
class Buffer
|
@@ -20,6 +20,12 @@ module RuneRb::Network
|
|
20
20
|
@data.dup
|
21
21
|
end
|
22
22
|
|
23
|
+
# Is the {Buffer#data} empty?
|
24
|
+
# @return [Boolean] true if the {Buffer#data} is empty, false otherwise.
|
25
|
+
def empty?
|
26
|
+
@data.empty?
|
27
|
+
end
|
28
|
+
|
23
29
|
# Returns the limit of the buffer.
|
24
30
|
# @return [Integer] the limit of the buffer.
|
25
31
|
def length
|
@@ -61,14 +67,14 @@ module RuneRb::Network
|
|
61
67
|
|
62
68
|
# Enables read functions on the buffer instance. Bit Access is disabled by default. Sets the bit position to 0.
|
63
69
|
def enable_readable
|
64
|
-
singleton_class.include(RuneRb::
|
70
|
+
singleton_class.include(RuneRb::Core::ReadableBuffer)
|
65
71
|
@bit_access = false
|
66
72
|
@bit_position = 0
|
67
73
|
end
|
68
74
|
|
69
75
|
# Enables write functions on the buffer instance.
|
70
76
|
def enable_writeable
|
71
|
-
singleton_class.include(RuneRb::
|
77
|
+
singleton_class.include(RuneRb::Core::WriteableBuffer)
|
72
78
|
end
|
73
79
|
end
|
74
80
|
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module RuneRb::Core::Identifiable
|
2
|
+
# @!attribute [r] id
|
3
|
+
# @return [String, Integer, Symbol] - The identifier of the object.
|
4
|
+
attr_reader :identifier
|
5
|
+
|
6
|
+
# The identifier of the object.
|
7
|
+
# @return [String, Integer, Symbol] - The identifier of the object.
|
8
|
+
def identifier
|
9
|
+
@identifier ||= SecureRandom.uuid
|
10
|
+
@identifier
|
11
|
+
end
|
12
|
+
|
13
|
+
alias id identifier
|
14
|
+
alias signature identifier
|
15
|
+
end
|
16
|
+
|
17
|
+
############################################################################################################
|
18
|
+
# Copyright (c) 2023, Patrick W. #
|
19
|
+
# All rights reserved. #
|
20
|
+
# #
|
21
|
+
# Redistribution and use in source and binary forms, with or without #
|
22
|
+
# modification, are permitted provided that the following conditions are met: #
|
23
|
+
# #
|
24
|
+
# * Redistributions of source code must retain the above copyright notice, this #
|
25
|
+
# list of conditions and the following disclaimer. #
|
26
|
+
# #
|
27
|
+
# * Redistributions in binary form must reproduce the above copyright notice, #
|
28
|
+
# this list of conditions and the following disclaimer in the documentation #
|
29
|
+
# and/or other materials provided with the distribution. #
|
30
|
+
# #
|
31
|
+
# * Neither the name of the copyright holder nor the names of its #
|
32
|
+
# contributors may be used to endorse or promote products derived from #
|
33
|
+
# this software without specific prior written permission. #
|
34
|
+
# #
|
35
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" #
|
36
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE #
|
37
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE #
|
38
|
+
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE #
|
39
|
+
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL #
|
40
|
+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR #
|
41
|
+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER #
|
42
|
+
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, #
|
43
|
+
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE #
|
44
|
+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #
|
45
|
+
# #
|
46
|
+
############################################################################################################
|
47
|
+
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# A module responsible for setting up logging functions.
|
4
|
+
module RuneRb::Core::Logging
|
5
|
+
|
6
|
+
# Write information to the log.
|
7
|
+
# @param lines [Array, String] the lines to write to the log.
|
8
|
+
def log(*lines)
|
9
|
+
RuneRb.logger.info(self.class.name) { lines.join("\n") }
|
10
|
+
end
|
11
|
+
|
12
|
+
alias info log
|
13
|
+
|
14
|
+
# Write a warning to the log.
|
15
|
+
# @param lines [Array, String] the lines to write to the log.
|
16
|
+
def log!(*lines)
|
17
|
+
RuneRb.logger.warn(self.class.name) { lines.join("\n") }
|
18
|
+
end
|
19
|
+
|
20
|
+
alias warn log!
|
21
|
+
|
22
|
+
# Write an error to the log.
|
23
|
+
# @param lines [Array, String] the lines to write to the log.
|
24
|
+
def err(*lines)
|
25
|
+
RuneRb.logger.error(self.class.name) { lines.join("\n") }
|
26
|
+
end
|
27
|
+
|
28
|
+
alias error err
|
29
|
+
|
30
|
+
# Write a fatal error to the log.
|
31
|
+
# @param lines [Array, String] the lines to write to the log.
|
32
|
+
def err!(*lines)
|
33
|
+
RuneRb.logger.fatal(self.class.name) { lines.join("\n") }
|
34
|
+
end
|
35
|
+
|
36
|
+
alias fatal err!
|
37
|
+
end
|
38
|
+
|
39
|
+
############################################################################################################
|
40
|
+
# Copyright (c) 2023, Patrick W. #
|
41
|
+
# All rights reserved. #
|
42
|
+
# #
|
43
|
+
# Redistribution and use in source and binary forms, with or without #
|
44
|
+
# modification, are permitted provided that the following conditions are met: #
|
45
|
+
# #
|
46
|
+
# * Redistributions of source code must retain the above copyright notice, this #
|
47
|
+
# list of conditions and the following disclaimer. #
|
48
|
+
# #
|
49
|
+
# * Redistributions in binary form must reproduce the above copyright notice, #
|
50
|
+
# this list of conditions and the following disclaimer in the documentation #
|
51
|
+
# and/or other materials provided with the distribution. #
|
52
|
+
# #
|
53
|
+
# * Neither the name of the copyright holder nor the names of its #
|
54
|
+
# contributors may be used to endorse or promote products derived from #
|
55
|
+
# this software without specific prior written permission. #
|
56
|
+
# #
|
57
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" #
|
58
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE #
|
59
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE #
|
60
|
+
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE #
|
61
|
+
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL #
|
62
|
+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR #
|
63
|
+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER #
|
64
|
+
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, #
|
65
|
+
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE #
|
66
|
+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #
|
67
|
+
# #
|
68
|
+
############################################################################################################
|
69
|
+
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module RuneRb::Core
|
2
|
+
# A Unit is a {Dry::Container} that encapsulates specific logic for a given system. Units are used to construct and run certain parts of the game. All {Unit} instances should include the {Singletons}.
|
3
|
+
# @abstract
|
4
|
+
class Unit
|
5
|
+
extend Dry::Configurable
|
6
|
+
include Dry::Container::Mixin
|
7
|
+
include RuneRb::Core::Logging
|
8
|
+
include Singleton
|
9
|
+
|
10
|
+
# Constructs a new instance of {Unit} and sets the name to the class name.
|
11
|
+
def initialize
|
12
|
+
@name = self.class.name.split('::')[-2]
|
13
|
+
super
|
14
|
+
end
|
15
|
+
|
16
|
+
# Prepares the unit for use. Providers are loaded and imported based on the configuration.
|
17
|
+
def prepare
|
18
|
+
info "Preparing #{@name} unit."
|
19
|
+
|
20
|
+
# Determine directory based on the class of the current instance
|
21
|
+
class_directory = File.dirname(self.class.instance_method(:prepare).source_location.first)
|
22
|
+
providers_directory = File.join(class_directory, 'providers', '*.rb')
|
23
|
+
|
24
|
+
# Load providers
|
25
|
+
Dir[providers_directory].sort.each { |provider| require provider }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# The Writeable module contains functions for writing data to a {Buffer} object.
|
2
|
-
module RuneRb::
|
2
|
+
module RuneRb::Core::WriteableBuffer
|
3
3
|
|
4
4
|
# Write data to the payload.
|
5
5
|
# @param value [Integer, String, Message, Array] the value to write.
|
@@ -107,11 +107,11 @@ module RuneRb::Network::Writeable
|
|
107
107
|
def write_long(value, mutation: :STD, signed: false, order: :BIG)
|
108
108
|
case order
|
109
109
|
when :BIG
|
110
|
-
(RuneRb::
|
110
|
+
(RuneRb::Core::BYTE_SIZE * 7).downto(0) { |div| ((div % 8).zero? and div.positive?) ? write_byte(value >> div) : next }
|
111
111
|
write_byte(value, mutation: mutation, signed: signed)
|
112
112
|
when :LITTLE
|
113
113
|
write_byte(value, mutation: mutation, signed: signed)
|
114
|
-
(0).upto(RuneRb::
|
114
|
+
(0).upto(RuneRb::Core::BYTE_SIZE * 7) { |div| ((div % 8).zero? and div.positive?) ? write_byte(value >> div) : next }
|
115
115
|
else raise "Unrecognized byte order: #{order}"
|
116
116
|
end
|
117
117
|
end
|
@@ -141,8 +141,7 @@ module RuneRb::Network::Writeable
|
|
141
141
|
def write_bytes(values)
|
142
142
|
case values
|
143
143
|
when Array then values.each { |byte| write_byte(byte.to_i) }
|
144
|
-
when RuneRb::
|
145
|
-
when RuneRb::Network::Buffer then send(:put, values)
|
144
|
+
when RuneRb::Core::Buffer then send(:put, values)
|
146
145
|
when String then send(:<<, values)
|
147
146
|
end
|
148
147
|
end
|
@@ -173,8 +172,8 @@ module RuneRb::Network::Writeable
|
|
173
172
|
|
174
173
|
while amount > bit_offset
|
175
174
|
@buffer[byte_pos] = [0].pack('c') if @buffer[byte_pos].nil?
|
176
|
-
@buffer[byte_pos] = [(@buffer[byte_pos].unpack1('c') & ~RuneRb::
|
177
|
-
@buffer[byte_pos] = [(@buffer[byte_pos].unpack1('c') | (value >> (amount - bit_offset)) & RuneRb::
|
175
|
+
@buffer[byte_pos] = [(@buffer[byte_pos].unpack1('c') & ~RuneRb::Core::BIT_MASK_OUT[bit_offset])].pack('c')
|
176
|
+
@buffer[byte_pos] = [(@buffer[byte_pos].unpack1('c') | (value >> (amount - bit_offset)) & RuneRb::Core::BIT_MASK_OUT[bit_offset])].pack('c')
|
178
177
|
byte_pos += 1
|
179
178
|
amount -= bit_offset
|
180
179
|
bit_offset = 8
|
@@ -183,11 +182,11 @@ module RuneRb::Network::Writeable
|
|
183
182
|
@buffer[byte_pos] = [0].pack('c') if @buffer[byte_pos].nil?
|
184
183
|
|
185
184
|
if amount == bit_offset
|
186
|
-
@buffer[byte_pos] = [(@buffer[byte_pos].unpack1('c') & ~RuneRb::
|
187
|
-
@buffer[byte_pos] = [(@buffer[byte_pos].unpack1('c') | (value &
|
185
|
+
@buffer[byte_pos] = [(@buffer[byte_pos].unpack1('c') & ~RuneRb::Core::BIT_MASK_OUT[bit_offset])].pack('c')
|
186
|
+
@buffer[byte_pos] = [(@buffer[byte_pos].unpack1('c') | (value & RuneRb::Core::BIT_MASK_OUT[bit_offset]))].pack('c')
|
188
187
|
else
|
189
|
-
@buffer[byte_pos] = [(@buffer[byte_pos].unpack1('c') & ~(RuneRb::
|
190
|
-
@buffer[byte_pos] = [(@buffer[byte_pos].unpack1('c') | ((value & RuneRb::
|
188
|
+
@buffer[byte_pos] = [(@buffer[byte_pos].unpack1('c') & ~(RuneRb::Core::BIT_MASK_OUT[amount] << (bit_offset - amount)))].pack('c')
|
189
|
+
@buffer[byte_pos] = [(@buffer[byte_pos].unpack1('c') | ((value & RuneRb::Core::BIT_MASK_OUT[amount]) << (bit_offset - amount)))].pack('c')
|
191
190
|
end
|
192
191
|
end
|
193
192
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rrb-common
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Patrick W.
|
@@ -24,6 +24,62 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '2.8'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: dry-configurable
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.16'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.16'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: dry-container
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.11'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.11'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: console
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: singleton
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.2'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.2'
|
27
83
|
- !ruby/object:Gem::Dependency
|
28
84
|
name: benchmark
|
29
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -101,11 +157,14 @@ extensions: []
|
|
101
157
|
extra_rdoc_files: []
|
102
158
|
files:
|
103
159
|
- lib/rune/common.rb
|
104
|
-
- lib/rune/
|
105
|
-
- lib/rune/
|
106
|
-
- lib/rune/
|
107
|
-
- lib/rune/
|
108
|
-
- lib/rune/
|
160
|
+
- lib/rune/core/buffer.rb
|
161
|
+
- lib/rune/core/constants.rb
|
162
|
+
- lib/rune/core/identifiable.rb
|
163
|
+
- lib/rune/core/isaac.rb
|
164
|
+
- lib/rune/core/logging.rb
|
165
|
+
- lib/rune/core/readable_buffer.rb
|
166
|
+
- lib/rune/core/unit.rb
|
167
|
+
- lib/rune/core/writeable_buffer.rb
|
109
168
|
- lib/rune/patches/integer_refinements.rb
|
110
169
|
- lib/rune/patches/set_refinements.rb
|
111
170
|
homepage:
|