mcp 0.0.2

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.

Potentially problematic release.


This version of mcp might be problematic. Click here for more details.

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
data/fail.rb ADDED
@@ -0,0 +1,39 @@
1
+ require 'mcp'
2
+ include MCP
3
+ file = 'listaserwerow'
4
+ map = MCP::Util.mapping
5
+ File.readlines(file).each do |line|
6
+ server,port = line.split(":")
7
+ sock = TCPSocket.new server,port
8
+ msg = Msg.new
9
+ login1 = Msg.new
10
+ login1.msg = "/register werwerdf werwerdf"
11
+ login2 = Msg.new
12
+ login2.msg = "/register werwerdf"
13
+ login3 = Msg.new
14
+ login3.msg = "/login werwerdf"
15
+ msg.msg = "Testujemy"
16
+ login = LoginRequest.new
17
+ login.nick = "testujemyxd1"
18
+ sock << login.with_id
19
+ packet_id = MCUbyte.read(sock).to_i
20
+ klass = map[packet_id]
21
+ if !klass
22
+ puts "nieznany pakiet jedziemy dalej nastepny serwer"
23
+ next
24
+ end
25
+ packet = klass.read(sock)
26
+ if packet.instance_of? Kick
27
+ puts "Fail got kick: #{packet.reason} //jedziemy dalej"
28
+ next
29
+ elsif packet.instance_of? LoginResponse
30
+ puts "OK"
31
+ sock << login1.with_id
32
+ sock << login2.with_id
33
+ sock << login3.with_id
34
+ sock << msg.with_id
35
+ end
36
+
37
+ break
38
+ end
39
+ #p MCP::MCMetadata.read "asd"
@@ -0,0 +1,44 @@
1
+ require 'socket'
2
+ require 'mcp/packets.rb'
3
+
4
+ module MCP
5
+ class Connection
6
+
7
+ def initialize(opts = {}, &block)
8
+ host = opts[:host] || "localhost"
9
+ port = opts[:port] || 25565
10
+ @socket = TCPSocket.new host,port
11
+ login = LoginRequest.new
12
+ login.nick = "testing221"
13
+ @socket << login.with_id
14
+ map = Util.mapping
15
+
16
+ while true
17
+ id = MCUbyte.read(@socket).to_i
18
+ klass = map[id]
19
+ if !klass
20
+ @socket.close
21
+ raise Exception, "Unknown packet: 0x#{id.to_s(16).upcase}"
22
+ return
23
+ end
24
+ p klass
25
+ a = klass.read(@socket)
26
+ p a
27
+ if a.instance_of? LoginResponse
28
+ puts "Polaczono z #{host}:#{port}, entity_id=#{a.entity_id}"
29
+ elsif a.instance_of? Kick
30
+ @socket.close
31
+ raise Exception, "Got kick: #{a.reason}"
32
+ return
33
+ elsif a.instance_of? Keepalive
34
+ k = Keepalive.new
35
+ k.id = a.id
36
+ @socket << k.with_id
37
+ end
38
+ puts "Naste[ny packiet"
39
+
40
+ end
41
+ end
42
+
43
+ end
44
+ end
@@ -0,0 +1,177 @@
1
+ require 'mcp/types.rb'
2
+ require 'mcp/packets_util.rb'
3
+
4
+ module MCP
5
+ class PluginMessage < Packet
6
+ Id = 0xFA
7
+ Type = :to_client
8
+
9
+ mc_string :channel
10
+ mc_byte_array :data
11
+ end
12
+
13
+ class LoginRequest < Packet
14
+ Id = 0x01
15
+ Type = :to_server
16
+
17
+ mc_int :protocol_version, value: 29 # int
18
+
19
+ mc_string :nick
20
+ mc_string :notused
21
+
22
+ mc_int :notused1, value: 0 #int
23
+ mc_int :notused2, value: 0 # int
24
+ mc_byte :notused3, value: 0 # byte
25
+ mc_ubyte :notused4, value: 0 #unsigned byte
26
+ mc_ubyte :notused5, value: 0 # ungsigned byte
27
+ end
28
+
29
+ class LoginResponse < Packet
30
+ Id = 0x01
31
+ Type = :to_client # u can only receive it @_@
32
+
33
+ mc_int :entity_id
34
+
35
+ mc_string :comment
36
+ mc_string :level_type
37
+
38
+
39
+ mc_int :server_mode
40
+ mc_int :dimension
41
+ mc_byte :difficulty
42
+ mc_ubyte :notused
43
+ mc_ubyte :max_players
44
+ end
45
+
46
+ class SpawnPosition < Packet
47
+ Id = 0x06
48
+ Type = :to_client
49
+ mc_int :x
50
+ mc_int :y
51
+ mc_int :z
52
+ end
53
+ class Msg < Packet
54
+ Id = 0x03
55
+ Type = :both
56
+
57
+ mc_string :msg
58
+ end
59
+
60
+ class Kick < Packet
61
+ Id = 0xFF
62
+ Type = :to_client
63
+
64
+ mc_string :reason
65
+ end
66
+
67
+ class PlayerAbilities < Packet
68
+ Id = 0xCA
69
+ Type = :both
70
+
71
+ mc_bool :god
72
+ mc_bool :flying
73
+ mc_bool :can_fly
74
+ mc_bool :instant_destroy
75
+ end
76
+
77
+ class TimeUpdate < Packet
78
+ Id = 0x04
79
+ Type = :to_client
80
+
81
+ mc_long :time
82
+ end
83
+
84
+ class SpawnItem < Packet
85
+ Id = 0x15
86
+ Type = :to_client
87
+
88
+ mc_int :entity_id
89
+ mc_short :item
90
+ mc_byte :item_count
91
+ mc_short :damage
92
+ mc_ab_int :x
93
+ mc_ab_int :y
94
+ mc_ab_int :z
95
+ mc_byte :rotation
96
+ mc_byte :pitch
97
+ mc_byte :roll
98
+ end
99
+
100
+ class EntityVelocity < Packet
101
+ Id = 0x1C
102
+ Type = :to_client
103
+
104
+ mc_int :eid
105
+ mc_short :x
106
+ mc_short :y
107
+ mc_short :z
108
+ end
109
+
110
+ class EntityHeadLook < Packet
111
+ Id = 0x23
112
+ Type = :to_client
113
+ mc_int :eid
114
+ mc_byte :head_yaw
115
+ end
116
+
117
+ class ChunkAllocation < Packet
118
+ Id = 0x32
119
+ Type = :to_client
120
+ mc_int :x
121
+ mc_int :z
122
+ mc_bool :mode
123
+ end
124
+
125
+ class SpawnMob < Packet
126
+ Id = 0x18
127
+ Type = :to_client
128
+
129
+ mc_int :eid
130
+ mc_byte :type
131
+ mc_int :x
132
+ mc_int :y
133
+ mc_int :z
134
+ mc_byte :yaw
135
+ mc_byte :pitch
136
+ mc_byte :head_yaw
137
+ mc_short :velocity_z
138
+ mc_short :velocity_x
139
+ mc_short :velocity_y
140
+ mc_metadata :meta
141
+ end
142
+
143
+ class SetWindowItems < Packet
144
+ Id = 0x68
145
+ Type = :to_client
146
+
147
+ mc_byte :window_id
148
+ mc_short :item_count
149
+ end
150
+
151
+ class SpawnNamedEntity < Packet
152
+ Id = 0x14
153
+ Type = :to_client
154
+
155
+ mc_int :eid
156
+ mc_string :name
157
+ mc_ab_int :x
158
+ mc_ab_int :y
159
+ mc_ab_int :z
160
+ mc_byte :yaw
161
+ mc_byte :pitch
162
+ mc_short :item
163
+ mc_metadata :meta
164
+ end
165
+
166
+ class Keepalive < Packet
167
+ Id = 0x00
168
+ Type = :both
169
+ mc_int :id
170
+ end
171
+ class ChangeGamestate < Packet
172
+ Id = 0x46
173
+ Type = :to_client
174
+ mc_byte :reason
175
+ mc_byte :gm
176
+ end
177
+ end
@@ -0,0 +1,24 @@
1
+ require 'mcp/types.rb'
2
+ module MCP
3
+ class Util
4
+ def self.mapping
5
+ MCP.constants.each_with_object({}) do |constant_name, result|
6
+ klass = MCP.const_get(constant_name)
7
+ next unless klass.is_a?(Class)
8
+ next unless klass < Packet
9
+ next unless (klass::Type || :both) != :to_server
10
+ result[klass::Id] = klass
11
+ end
12
+ end
13
+ end
14
+
15
+ class Packet < BinData::Record
16
+ Id = -1
17
+ Type = :both
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
+ end
data/lib/mcp/types.rb ADDED
@@ -0,0 +1,101 @@
1
+ #packet id to U(!)byte
2
+ #byte => int8
3
+ #short => int16
4
+ #int => int32
5
+ require 'bindata'
6
+ module MCP
7
+ class MCByte < BinData::Primitive
8
+ endian :big
9
+ int8 :data
10
+ def get; return self.data; end
11
+ def set(a); self.data = a; end
12
+ end
13
+
14
+ class MCUbyte < BinData::Primitive
15
+ endian :big
16
+ uint8 :data
17
+ def get; return self.data; end
18
+ def set(a); self.data = a; end
19
+ end
20
+
21
+ class MCShort < BinData::Primitive
22
+ endian :big
23
+ int16 :data
24
+ def get; return self.data; end
25
+ def set(a); self.data = a; end
26
+ end
27
+
28
+ class MCInt < BinData::Primitive
29
+ endian :big
30
+ int32 :data
31
+ def get; return self.data; end
32
+ def set(a); self.data = a; end
33
+ end
34
+
35
+ class MCAbInt < BinData::Primitive
36
+ endian :big
37
+ int32 :data
38
+ def get; return self.data/32; end
39
+ def set(a); self.data = a; end
40
+ end
41
+
42
+ class MCString < BinData::Primitive
43
+ endian :big
44
+ int16 :len, value: lambda { length }
45
+ string :data, read_length: lambda { 2*len}
46
+
47
+ def get; return self.data.force_encoding("utf-16be").encode("utf-8"); end
48
+ def set(a)
49
+ length = a.length
50
+ self.data = a.encode("utf-16be")
51
+ end
52
+ end
53
+
54
+ class MCByteArray < BinData::Primitive
55
+ endian :big
56
+ int16 :len
57
+ array :data, :type => :mc_byte, :initial_length => lambda {len}
58
+
59
+ def get; return self.data; end
60
+ def set(a); self.data = a; end
61
+ end
62
+
63
+ class MCBool < BinData::Primitive
64
+ endian :big
65
+ int8 :data
66
+ def get; return self.data != 0; end
67
+ def set(a); self.data = a; end
68
+ end
69
+
70
+ class MCLong < BinData::BasePrimitive
71
+ BinData::Int.define_methods(self, 64, :big, :signed)
72
+ end
73
+
74
+ class MCMetadata < BinData::Primitive
75
+ endian :big
76
+ # array :data, :type => :mc_byte#, :initial_length => 1
77
+ def get; return self.datax; end
78
+ def set(a); puts "nie ma setania"; end
79
+
80
+ def read(stream)
81
+ self.datax = []
82
+ while (x = MCByte.read(stream)) != 127
83
+ #data.initial_length = data.initial_length+1
84
+ index = x & 0x1F
85
+ ty = x >> 5
86
+
87
+ val = case ty
88
+ when 0 then MCByte.read(stream)
89
+ when 1 then MCShort.read(stream)
90
+ when 2 then MCInt.read(stream)
91
+ when 3 then nil # TODO: MC FLOAT!!!
92
+ when 4 then MCString.read(stream)
93
+ when 5 then {id: MCShort.read(stream), count: MCByte.read(stream), damage: MCShort.read(stream)}
94
+ when 6 then [MCInt.read(stream),MCInt.read(stream),MCInt.read(stream)]
95
+ else nil
96
+ end
97
+ self.datax << val
98
+ end
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,3 @@
1
+ module MCP
2
+ VERSION = "0.0.2"
3
+ end
data/lib/mcp.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "mcp/version"
2
+ require 'mcp/connection.rb'
3
+ module MCP
4
+ # Your code goes here...
5
+ end
data/listaserwerow ADDED
@@ -0,0 +1 @@
1
+ metropolic.pl:25565
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,59 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mcp
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - macer1
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-08-01 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
+ - fail.rb
27
+ - lib/mcp.rb
28
+ - lib/mcp/connection.rb
29
+ - lib/mcp/packets.rb
30
+ - lib/mcp/packets_util.rb
31
+ - lib/mcp/types.rb
32
+ - lib/mcp/version.rb
33
+ - listaserwerow
34
+ - mcp.gemspec
35
+ homepage: ''
36
+ licenses: []
37
+ post_install_message:
38
+ rdoc_options: []
39
+ require_paths:
40
+ - lib
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ none: false
49
+ requirements:
50
+ - - ! '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ requirements: []
54
+ rubyforge_project:
55
+ rubygems_version: 1.8.24
56
+ signing_key:
57
+ specification_version: 3
58
+ summary: Warning, pre-alpha indev
59
+ test_files: []