… | |
… | |
12 | |
12 | |
13 | # See doc/protocol.xml and doc/doc2messages.xsl |
13 | # See doc/protocol.xml and doc/doc2messages.xsl |
14 | |
14 | |
15 | package KGS::Messages; |
15 | package KGS::Messages; |
16 | |
16 | |
|
|
17 | use KGS::Constants; # REPLACE by parsed file, too |
|
|
18 | |
17 | use strict; |
19 | use strict; |
18 | |
20 | |
19 | our %type; |
21 | our %type; |
20 | our %send; |
22 | our %send; |
21 | our %recv; |
23 | our %recv; |
… | |
… | |
99 | sub enc_U64 { |
101 | sub enc_U64 { |
100 | enc_U32 $_[0] & 0xffffffff; |
102 | enc_U32 $_[0] & 0xffffffff; |
101 | enc_U32 +($_[0] >> 32) & 0xffffffff; |
103 | enc_U32 +($_[0] >> 32) & 0xffffffff; |
102 | } |
104 | } |
103 | |
105 | |
|
|
106 | sub enc_I16 { |
|
|
107 | enc_U16 unpack "S", pack "s", $_[0]; |
|
|
108 | } |
|
|
109 | |
104 | sub enc_I32 { |
110 | sub enc_I32 { |
105 | enc_U32 unpack "I", pack "i", $_[0]; |
111 | enc_U32 unpack "I", pack "i", $_[0]; |
106 | } |
112 | } |
107 | |
113 | |
108 | sub enc_DATA { |
114 | sub enc_DATA { |
… | |
… | |
112 | |
118 | |
113 | sub enc_STRING { |
119 | sub enc_STRING { |
114 | # should use encode for speed and clarity ;) |
120 | # should use encode for speed and clarity ;) |
115 | $data .= pack "v*", map ord, split //, $_[0]; |
121 | $data .= pack "v*", map ord, split //, $_[0]; |
116 | } |
122 | } |
|
|
123 | |
|
|
124 | sub enc_password { |
|
|
125 | require Math::BigInt; # I insist on 32-bit-perl.. should use C |
|
|
126 | # $hash must be 64 bit |
|
|
127 | my $hash = new Math::BigInt; |
|
|
128 | $hash = $hash * 1055 + ord for split //, $_[0]; |
|
|
129 | enc_U64 $hash; |
|
|
130 | } |
|
|
131 | |
117 | ]]> |
132 | ]]> |
118 | |
133 | |
119 | ############################################################################# |
134 | ############################################################################# |
120 | # types |
135 | # types |
121 | <xsl:apply-templates select="descendant::type"/> |
136 | <xsl:apply-templates select="descendant::type"/> |
… | |
… | |
182 | |
197 | |
183 | } elsif ($type == 15 || $type == 16) { |
198 | } elsif ($type == 15 || $type == 16) { |
184 | push @r, [set_timer => $type - 15, dec_time, dec_U16]; |
199 | push @r, [set_timer => $type - 15, dec_time, dec_U16]; |
185 | |
200 | |
186 | } elsif ($type == 17 || $type == 18) { |
201 | } elsif ($type == 17 || $type == 18) { |
187 | push @r, [score => $type - 17, dec_score]; |
202 | push @r, [score => $type - 17, dec_score16]; |
188 | |
203 | |
189 | } elsif ($type == 19) { |
204 | } elsif ($type == 19) { |
190 | push @r, [result => dec_result]; |
205 | push @r, [result => dec_result]; # not certain |
191 | |
206 | |
192 | } elsif ($type == 30) { |
207 | } elsif ($type == 30) { |
193 | push @r, [active_player => dec_U8]; |
208 | push @r, [active_player => dec_U8]; |
194 | |
209 | |
195 | } elsif ($type == 0) { # label(?) |
210 | } elsif ($type == 0) { # label(?) |