|
3 | 3 | A component of Minecraft Relay Server. |
4 | 4 | |
5 | 5 | |
6 | | - Minecraft Relay Server, version 1.1 |
| 6 | + Minecraft Relay Server, version 1.1.1 |
7 | 7 | Copyright (c) 2020 Bilin Tsui. All right reserved. |
8 | 8 | This is a Free Software, absolutely no warranty. |
9 | 9 | Licensed with GNU General Public License Version 3 (GNU GPL v3). |
|
16 | 16 | #include <time.h> |
17 | 17 | #define TYPE_UNIX 1 |
18 | 18 | #define TYPE_INET 2 |
19 | | -#define PVER_L_ORIGPRO 0 |
20 | | -#define PVER_L_LEGACY1 1 |
21 | | -#define PVER_L_LEGACY2 2 |
22 | | -#define PVER_L_LEGACY3 3 |
23 | | -#define PVER_L_LEGACY4 4 |
24 | | -#define PVER_L_MODERN1 5 |
25 | | -#define PVER_L_MODERN2 6 |
| 19 | +#define PVER_L_UNIDENT 0 |
| 20 | +#define PVER_L_ORIGPRO 1 |
| 21 | +#define PVER_L_LEGACY1 2 |
| 22 | +#define PVER_L_LEGACY2 3 |
| 23 | +#define PVER_L_LEGACY3 4 |
| 24 | +#define PVER_L_LEGACY4 5 |
| 25 | +#define PVER_L_MODERN1 6 |
| 26 | +#define PVER_L_MODERN2 7 |
26 | 27 | #define PVER_M_UNIDENT 0 |
27 | 28 | #define PVER_M_LEGACY1 1 |
28 | 29 | #define PVER_M_LEGACY2 2 |
@@ -184,14 +185,21 @@ int handshake_protocol_identify(unsigned char * source, unsigned int length) |
184 | 185 | } |
185 | 186 | break; |
186 | 187 | default: |
187 | | - switch(source[2]) |
| 188 | + if((source[source[0]]==1)||(source[source[0]]==2)) |
188 | 189 | { |
189 | | - case 0: |
190 | | - protocol_version=PVER_L_MODERN1; |
191 | | - break; |
192 | | - default: |
193 | | - protocol_version=PVER_L_MODERN2; |
194 | | - break; |
| 190 | + switch(source[2]) |
| 191 | + { |
| 192 | + case 0: |
| 193 | + protocol_version=PVER_L_MODERN1; |
| 194 | + break; |
| 195 | + default: |
| 196 | + protocol_version=PVER_L_MODERN2; |
| 197 | + break; |
| 198 | + } |
| 199 | + } |
| 200 | + else |
| 201 | + { |
| 202 | + protocol_version=PVER_L_UNIDENT; |
195 | 203 | } |
196 | 204 | break; |
197 | 205 | } |
@@ -345,3 +353,42 @@ int mksysmsg(unsigned short noprefix, char * logfile, unsigned short runmode, un |
345 | 353 | return 0; |
346 | 354 | } |
347 | 355 | } |
| 356 | +int legacy_motd_protocol_identify(unsigned char * source) |
| 357 | +{ |
| 358 | + int proto_version=PVER_M_UNIDENT; |
| 359 | + if(source[1]==0) |
| 360 | + { |
| 361 | + proto_version=PVER_M_LEGACY1; |
| 362 | + } |
| 363 | + else if(source[1]==1) |
| 364 | + { |
| 365 | + if(source[2]==0) |
| 366 | + { |
| 367 | + proto_version=PVER_M_LEGACY2; |
| 368 | + } |
| 369 | + else if(source[2]==0xFA) |
| 370 | + { |
| 371 | + proto_version=PVER_M_LEGACY3; |
| 372 | + } |
| 373 | + } |
| 374 | + return proto_version; |
| 375 | +} |
| 376 | +int ismcproto(unsigned char * data_in, unsigned int data_length) |
| 377 | +{ |
| 378 | + int result=0; |
| 379 | + if(data_in[0]==0xFE) |
| 380 | + { |
| 381 | + if(legacy_motd_protocol_identify(data_in)!=PVER_M_UNIDENT) |
| 382 | + { |
| 383 | + result=1; |
| 384 | + } |
| 385 | + } |
| 386 | + else |
| 387 | + { |
| 388 | + if(handshake_protocol_identify(data_in,data_length)!=PVER_L_UNIDENT) |
| 389 | + { |
| 390 | + result=1; |
| 391 | + } |
| 392 | + } |
| 393 | + return result; |
| 394 | +} |
0 commit comments