srcon 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 01ca5a4f817107e44e4504160a4e4cb5ccbda0840effff7b2ca6589a656968f8
4
+ data.tar.gz: 176db79c6bf541bddbb56eb066015932d013329cc4a7d961f0e3d425fe3f4535
5
+ SHA512:
6
+ metadata.gz: 44a89cdf86a588a6cc03258113007fc67f023533f4894a1c8aa445388f3971f9600ec84a1f765904cc130fb616dafd7c93fa0126881b6e2265d09be230425fa7
7
+ data.tar.gz: 2887245f0499c8b7780d3c20b448bf732e5cdfd81c7cdebc06fd2847f7a321b35d02a314fe70809efe0a6b0f2db9b970d012a10910f3eab4ef14d30d008d821e
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+
13
+ .*.swp
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1 @@
1
+ srcon
@@ -0,0 +1 @@
1
+ ruby-2.5.1
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.5.1
5
+ before_install: gem install bundler -v 1.16.1
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in srcon.gemspec
6
+ gemspec
@@ -0,0 +1,41 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ srcon (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ coderay (1.1.2)
10
+ diff-lcs (1.3)
11
+ method_source (0.9.0)
12
+ pry (0.11.3)
13
+ coderay (~> 1.1.0)
14
+ method_source (~> 0.9.0)
15
+ rake (10.5.0)
16
+ rspec (3.7.0)
17
+ rspec-core (~> 3.7.0)
18
+ rspec-expectations (~> 3.7.0)
19
+ rspec-mocks (~> 3.7.0)
20
+ rspec-core (3.7.1)
21
+ rspec-support (~> 3.7.0)
22
+ rspec-expectations (3.7.0)
23
+ diff-lcs (>= 1.2.0, < 2.0)
24
+ rspec-support (~> 3.7.0)
25
+ rspec-mocks (3.7.0)
26
+ diff-lcs (>= 1.2.0, < 2.0)
27
+ rspec-support (~> 3.7.0)
28
+ rspec-support (3.7.1)
29
+
30
+ PLATFORMS
31
+ ruby
32
+
33
+ DEPENDENCIES
34
+ bundler (~> 1.16)
35
+ pry (~> 0.11)
36
+ rake (~> 10.0)
37
+ rspec (~> 3.7)
38
+ srcon!
39
+
40
+ BUNDLED WITH
41
+ 1.16.1
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Brandon
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
13
+ all 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
21
+ THE SOFTWARE.
@@ -0,0 +1,45 @@
1
+ # Srcon
2
+
3
+ Srcon is a Ruby implementation of Valve's [Source RCON Protocol](https://developer.valvesoftware.com/wiki/Source_RCON_Protocol). It is a TCP-based protocol used for communicating with [Source Dedicated Servers](https://developer.valvesoftware.com/wiki/Source_Dedicated_Server) typically accessible via Steam.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'srcon'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install srcon
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ require 'srcon'
25
+
26
+ connection = Srcon::Connection.new('123.45.67.8', 28717, 'some_password')
27
+ connection.send('help')
28
+ connection.receive
29
+ ```
30
+
31
+
32
+ ## Development
33
+
34
+ 1. Fork the repository.
35
+ 2. Create a new branch.
36
+ 3. Make sure tests pass.
37
+ 4. Open a pull request.
38
+
39
+ ## Contributing
40
+
41
+ Bug reports and pull requests are welcome on GitHub at https://github.com/nevern02/srcon.
42
+
43
+ ## License
44
+
45
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,14 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ $LOAD_PATH << File.expand_path('../lib/srcon', __FILE__)
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task :console do
9
+ require 'srcon'
10
+ require 'pry'
11
+ binding.pry
12
+ end
13
+
14
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "srcon"
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__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,7 @@
1
+ require 'srcon/connection'
2
+ require 'srcon/packet'
3
+ require 'srcon/version'
4
+
5
+ module Srcon
6
+ class MaxPacketSize < StandardError; end
7
+ end
@@ -0,0 +1,50 @@
1
+ require 'socket'
2
+
3
+ module Srcon
4
+ class Connection
5
+ class AuthenticationFailure < StandardError; end
6
+
7
+ attr_reader :host, :port, :socket
8
+
9
+ # @param [String] host The host the server is listening on
10
+ # @param [Integer] port The port the server is listening on
11
+ # @param [String] password The password for authentication
12
+ def initialize(host, port, password = nil)
13
+ @host = host
14
+ @port = port
15
+ @id = rand(Process.pid)
16
+
17
+ connect!(password)
18
+ end
19
+
20
+ # @return [Srcon::Packet] The deconstructed packet received from the socket
21
+ def receive
22
+ Srcon::Packet.from_message(*socket.recvmsg)
23
+ end
24
+
25
+ # @param [String] message A message to send to the server
26
+ # @param [Integer] type The type of message
27
+ #
28
+ # @return [Integer] The number of bytes that were sent
29
+ def send(message, type = Srcon::Packet::SERVERDATA_EXECCOMMAND)
30
+ packet = Srcon::Packet.new(message, type, @id)
31
+ @id += 1
32
+ socket&.sendmsg(packet.to_b)
33
+ end
34
+
35
+ private
36
+
37
+ def connect!(password = nil)
38
+ @socket = TCPSocket.new(host, port)
39
+
40
+ return unless password
41
+
42
+ # Authenticate if a password was provided
43
+ send(password, Srcon::Packet::SERVERDATA_AUTH)
44
+
45
+ response = receive
46
+
47
+ raise AuthenticationFailure.new("Failed RCON auth to #{host}:#{port}") unless response.body == 'Authenticated.'
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,47 @@
1
+ module Srcon
2
+ class Packet
3
+ MINIMUM_BYTE_SIZE = 10
4
+ MAXIMUM_BYTE_SIZE = 4096
5
+
6
+ # Packet types
7
+ SERVERDATA_AUTH = 3
8
+ SERVERDATA_AUTH_RESPONSE = 2
9
+ SERVERDATA_EXECCOMMAND = 2
10
+ SERVERDATA_RESPONSE_VALUE = 0
11
+
12
+ attr_reader :id, :body, :type
13
+
14
+ def self.from_message(body, addrinfo, rflags)
15
+ body_unpacked = body.unpack('l<l<l<Z*')
16
+ new(body_unpacked[3], body_unpacked[2], body_unpacked[0])
17
+ end
18
+
19
+ # @param [String] body The message body for the packet
20
+ def initialize(body = '', type = SERVERDATA_EXECCOMMAND, id = 1)
21
+ @body = body
22
+ @type = type
23
+ @id = id
24
+ end
25
+
26
+ def body=(new_body)
27
+ @body = new_body
28
+
29
+ if size > MAXIMUM_BYTE_SIZE
30
+ raise Srcon::MaxPacketSize.new("Maximum packet size is #{MAXIMUM_BYTE_SIZE} bytes")
31
+ end
32
+ end
33
+
34
+ def size
35
+ MINIMUM_BYTE_SIZE + body.bytesize
36
+ end
37
+
38
+ def to_b
39
+ sizeb = [size].pack('l<')
40
+ idb = [id].pack('l<')
41
+ typeb = [type].pack('l<')
42
+ bodyb = [body].pack('Z*')
43
+
44
+ sizeb + idb + typeb + bodyb + "\0"
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,3 @@
1
+ module Srcon
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,28 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "srcon/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "srcon"
8
+ spec.version = Srcon::VERSION
9
+ spec.authors = ["Brandon R."]
10
+ spec.email = ["brandon@blrice.net"]
11
+
12
+ spec.summary = %q{A socket library implementing Valve's RCON protocol.}
13
+ spec.description = %q{A socket library implementing Valve's RCON protocol.}
14
+ spec.homepage = "https://github.com/nevern02/srcon"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.16"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec", "~> 3.7"
27
+ spec.add_development_dependency "pry", "~> 0.11"
28
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: srcon
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Brandon R.
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-06-04 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: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
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.7'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.7'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.11'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.11'
69
+ description: A socket library implementing Valve's RCON protocol.
70
+ email:
71
+ - brandon@blrice.net
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".ruby-gemset"
79
+ - ".ruby-version"
80
+ - ".travis.yml"
81
+ - Gemfile
82
+ - Gemfile.lock
83
+ - LICENSE.txt
84
+ - README.md
85
+ - Rakefile
86
+ - bin/console
87
+ - bin/setup
88
+ - lib/srcon.rb
89
+ - lib/srcon/connection.rb
90
+ - lib/srcon/packet.rb
91
+ - lib/srcon/version.rb
92
+ - srcon.gemspec
93
+ homepage: https://github.com/nevern02/srcon
94
+ licenses:
95
+ - MIT
96
+ metadata: {}
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 2.7.6
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: A socket library implementing Valve's RCON protocol.
117
+ test_files: []