mcp 0.0.1

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.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in mcp.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 macer1
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # Mcp
2
+
3
+ Impl. of Minecraft Protocol
4
+ TODO: Write a gem description
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'mcp'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install mcp
19
+
20
+ ## Usage
21
+
22
+ TODO: Write usage instructions here
23
+ blablabla whatever
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,27 @@
1
+ require 'mcp/protocol/types'
2
+ module MCP
3
+ module Protocol
4
+ module Packets
5
+
6
+ def mapping
7
+ constants.each_with_object({}) do |constant_name, result|
8
+ klass = const_get(constant_name)
9
+ next unless klass.is_a?(Class)
10
+ next unless klass < Packet
11
+ next unless klass::Type != :to_server
12
+ result[klass::Id] = klass
13
+ end
14
+ end
15
+
16
+ private
17
+ class Packet < BinData::Record
18
+ def with_id
19
+ packet = self.class
20
+ id = packet::Id rescue 0
21
+ MCUbyte.new(id).to_binary_s + to_binary_s
22
+ end
23
+ end
24
+
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,70 @@
1
+ #packet id to U(!)byte
2
+ #byte => int8
3
+ #short => int16
4
+ #int => int32
5
+ require 'bindata'
6
+ module MCP
7
+ module Protocol
8
+ module Types
9
+ class MCByte < BinData::Primitive
10
+ endian :big
11
+ int8 :data
12
+ def get; return self.data; end
13
+ def set(a); self.data = a; end
14
+ end
15
+
16
+ class MCUbyte < BinData::Primitive
17
+ endian :big
18
+ uint8 :data
19
+ def get; return self.data; end
20
+ def set(a); self.data = a; end
21
+ end
22
+
23
+ class MCShort < BinData::Primitive
24
+ endian :big
25
+ int16 :data
26
+ def get; return self.data; end
27
+ def set(a); self.data = a; end
28
+ end
29
+
30
+ class MCInt < BinData::Primitive
31
+ endian :big
32
+ int32 :data
33
+ def get; return self.data; end
34
+ def set(a); self.data = a; end
35
+ end
36
+
37
+ class MCString < BinData::Primitive
38
+ endian :big
39
+ int16 :len, value: lambda { length }
40
+ string :data, read_length: lambda { 2*len}
41
+
42
+ def get; return self.data.force_encoding("utf-16be").encode("utf-8"); end
43
+ def set(a)
44
+ length = a.length
45
+ self.data = a.encode("utf-16be")
46
+ end
47
+ end
48
+
49
+ class MCByteArray < BinData::Primitive
50
+ endian :big
51
+ int16 :len
52
+ array :data, :type => :mc_byte, :initial_length => lambda {len}
53
+
54
+ def get; return self.data; end
55
+ def set(a); self.data = a; end
56
+ end
57
+
58
+ class MCBool < BinData::Primitive
59
+ endian :big
60
+ int8 :data
61
+ def get; return self.data != 0; end
62
+ def set(a); self.data = a; end
63
+ end
64
+
65
+ class MCLong < BinData::BasePrimitive
66
+ BinData::Int.define_methods(self, 64, :big, :signed)
67
+ end
68
+ end
69
+ end
70
+
@@ -0,0 +1,87 @@
1
+ require 'mcp/protocol/packets'
2
+ require 'mcp/protocol/types'
3
+ module MCP
4
+ module Protocol29
5
+ module Packets
6
+ include Protocol
7
+ class Plugin < Packet
8
+ Id = 0xFA
9
+ Type = :to_client
10
+
11
+ mc_string :channel
12
+ mc_byte_array :data#, read_length: lambda {data_length}
13
+ end
14
+
15
+ class LoginRequest < Packet
16
+ Id = 0x01
17
+ Type = :to_server
18
+
19
+ mc_int :protocol_version, value: 29 # int
20
+
21
+ mc_string :nick
22
+ mc_string :notused
23
+
24
+ mc_int :notused1, value: 0 #int
25
+ mc_int :notused2, value: 0 # int
26
+ mc_byte :notused3, value: 0 # byte
27
+ mc_ubyte :notused4, value: 0 #unsigned byte
28
+ mc_ubyte :notused5, value: 0 # ungsigned byte
29
+ end
30
+
31
+ class LoginResponse < Packet
32
+ Id = 0x01
33
+ Type = :to_client # u can only receive it @_@
34
+
35
+ mc_int :entity_id
36
+
37
+ mc_string :comment
38
+ mc_string :level_type
39
+
40
+
41
+ mc_int :server_mode
42
+ mc_int :dimension
43
+ mc_byte :difficulty
44
+ mc_ubyte :notused
45
+ mc_ubyte :max_players
46
+ end
47
+
48
+ class SpawnPosition < Packet
49
+ Id = 6
50
+ Type = :to_client
51
+ mc_int :x
52
+ mc_int :y
53
+ mc_int :z
54
+ end
55
+ class Msg < Packet
56
+ Id = 3
57
+ Type = :both
58
+
59
+ mc_string :msg
60
+ end
61
+
62
+ class Kick < Packet
63
+ Id = 0xFF
64
+ Type = :to_client
65
+
66
+ mc_string :reason
67
+ end
68
+
69
+ class PlayerAbilities < Packet
70
+ Id = 0xCA
71
+ Type = :both
72
+
73
+ mc_bool :god
74
+ mc_bool :flying
75
+ mc_bool :can_fly
76
+ mc_bool :instant_destroy
77
+ end
78
+
79
+ class TimeUpdate < Packet
80
+ Id = 0x04
81
+ Type = :to_client
82
+
83
+ mc_long :time
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,3 @@
1
+ module Mcp
2
+ VERSION = "0.0.1"
3
+ end
data/lib/mcp.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "mcp/version"
2
+
3
+ module Mcp
4
+ # Your code goes here...
5
+ end
data/mcp.gemspec ADDED
@@ -0,0 +1,17 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/mcp/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["macer1"]
6
+ gem.email = ["linuksowiec1+github@gmail.com"]
7
+ gem.description = %q{Minecraft Protocol implementation}
8
+ gem.summary = %q{Warning, pre-alpha indev}
9
+ gem.homepage = ""
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "mcp"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Mcp::VERSION
17
+ end
metadata ADDED
@@ -0,0 +1,56 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mcp
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - macer1
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-07-31 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Minecraft Protocol implementation
15
+ email:
16
+ - linuksowiec1+github@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - LICENSE
24
+ - README.md
25
+ - Rakefile
26
+ - lib/mcp.rb
27
+ - lib/mcp/protocol/packets.rb
28
+ - lib/mcp/protocol/types.rb
29
+ - lib/mcp/protocol29/packets.rb
30
+ - lib/mcp/version.rb
31
+ - mcp.gemspec
32
+ homepage: ''
33
+ licenses: []
34
+ post_install_message:
35
+ rdoc_options: []
36
+ require_paths:
37
+ - lib
38
+ required_ruby_version: !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ! '>='
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ requirements: []
51
+ rubyforge_project:
52
+ rubygems_version: 1.8.24
53
+ signing_key:
54
+ specification_version: 3
55
+ summary: Warning, pre-alpha indev
56
+ test_files: []