Skip to content

Commit d3f82e4

Browse files
committed
v1.1.1
1. Changed version to v1.1.1. 2. Fixed bug of messed log format when unidentified protocol incoming.
1 parent ec50878 commit d3f82e4

File tree

6 files changed

+76
-42
lines changed

6 files changed

+76
-42
lines changed

mcrelay.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
A component of Minecraft Relay Server.
44
55
6-
Minecraft Relay Server, version 1.1
6+
Minecraft Relay Server, version 1.1.1
77
Copyright (c) 2020 Bilin Tsui. All right reserved.
88
This is a Free Software, absolutely no warranty.
99
Licensed with GNU General Public License Version 3 (GNU GPL v3).
@@ -16,7 +16,7 @@
1616
#include "mod/network.h"
1717
#include "mod/proto_legacy.h"
1818
#include "mod/proto_modern.h"
19-
const char version_str[]="1.1";
19+
const char version_str[]="1.1.1";
2020
struct conf config;
2121
char configfile[512],cwd[512],config_logfull[BUFSIZ];
2222
unsigned short config_runmode;
@@ -304,6 +304,13 @@ int main(int argc, char ** argv)
304304
close(socket_inbound_client);
305305
return 0;
306306
}
307+
if(ismcproto(inbound,packlen_inbound)==0)
308+
{
309+
mksysmsg(0,config_logfull,config_runmode,config.loglevel,1,"src: %s:%d, status: reject_unidentproto\n",inet_ntoa(addr_inbound_client.sin_addr),ntohs(addr_inbound_client.sin_port));
310+
shutdown(socket_inbound_client,SHUT_RDWR);
311+
close(socket_inbound_client);
312+
return 0;
313+
}
307314
if(inbound[0]==0xFE)
308315
{
309316
int motd_version=legacy_motd_protocol_identify(inbound);
@@ -480,7 +487,7 @@ int main(int argc, char ** argv)
480487
close(socket_inbound_client);
481488
return 0;
482489
}
483-
else
490+
else if((login_version==PVER_L_LEGACY2)||(login_version==PVER_L_LEGACY4))
484491
{
485492
struct p_login_legacy inbound_info=packet_read_legacy_login(inbound,packlen_inbound,login_version);
486493
struct conf_map * proxyinfo=getproxyinfo(&config,inbound_info.address);

mod/basic.h

Lines changed: 62 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
A component of Minecraft Relay Server.
44
55
6-
Minecraft Relay Server, version 1.1
6+
Minecraft Relay Server, version 1.1.1
77
Copyright (c) 2020 Bilin Tsui. All right reserved.
88
This is a Free Software, absolutely no warranty.
99
Licensed with GNU General Public License Version 3 (GNU GPL v3).
@@ -16,13 +16,14 @@
1616
#include <time.h>
1717
#define TYPE_UNIX 1
1818
#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
2627
#define PVER_M_UNIDENT 0
2728
#define PVER_M_LEGACY1 1
2829
#define PVER_M_LEGACY2 2
@@ -184,14 +185,21 @@ int handshake_protocol_identify(unsigned char * source, unsigned int length)
184185
}
185186
break;
186187
default:
187-
switch(source[2])
188+
if((source[source[0]]==1)||(source[source[0]]==2))
188189
{
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;
195203
}
196204
break;
197205
}
@@ -345,3 +353,42 @@ int mksysmsg(unsigned short noprefix, char * logfile, unsigned short runmode, un
345353
return 0;
346354
}
347355
}
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+
}

mod/config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
A component of Minecraft Relay Server.
44
Requires: mod/basic.h, please manually include it in main source code.
55
6-
Minecraft Relay Server, version 1.1
6+
Minecraft Relay Server, version 1.1.1
77
Copyright (c) 2020 Bilin Tsui. All right reserved.
88
This is a Free Software, absolutely no warranty.
99
Licensed with GNU General Public License Version 3 (GNU GPL v3).

mod/network.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
A component of Minecraft Relay Server.
44
Requires: mod/basic.h, please manually include it in main source code. Also require libresolv.so, use option: -lresolv in gcc compile.
55
6-
Minecraft Relay Server, version 1.1
6+
Minecraft Relay Server, version 1.1.1
77
Copyright (c) 2020 Bilin Tsui. All right reserved.
88
This is a Free Software, absolutely no warranty.
99
Licensed with GNU General Public License Version 3 (GNU GPL v3).

mod/proto_legacy.h

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
A component of Minecraft Relay Server.
44
Requires: mod/basic.h, please manually include it in main source code.
55
6-
Minecraft Relay Server, version 1.1
6+
Minecraft Relay Server, version 1.1.1
77
Copyright (c) 2020 Bilin Tsui. All right reserved.
88
This is a Free Software, absolutely no warranty.
99
Licensed with GNU General Public License Version 3 (GNU GPL v3).
@@ -130,26 +130,6 @@ int packet_write_legacy_login(struct p_login_legacy source, unsigned char * targ
130130
}
131131
return size;
132132
}
133-
int legacy_motd_protocol_identify(unsigned char * source)
134-
{
135-
int proto_version=0;
136-
if(source[1]==0)
137-
{
138-
proto_version=PVER_M_LEGACY1;
139-
}
140-
else if(source[1]==1)
141-
{
142-
if(source[2]==0)
143-
{
144-
proto_version=PVER_M_LEGACY2;
145-
}
146-
else if(source[2]==0xFA)
147-
{
148-
proto_version=PVER_M_LEGACY3;
149-
}
150-
}
151-
return proto_version;
152-
}
153133
struct p_motd_legacy packet_read_legacy_motd(unsigned char * sourcepacket, int sourcepacket_length)
154134
{
155135
struct p_motd_legacy result;

mod/proto_modern.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
A component of Minecraft Relay Server.
44
Requires: mod/basic.h, please manually include it in main source code.
55
6-
Minecraft Relay Server, version 1.1
6+
Minecraft Relay Server, version 1.1.1
77
Copyright (c) 2020 Bilin Tsui. All right reserved.
88
This is a Free Software, absolutely no warranty.
99
Licensed with GNU General Public License Version 3 (GNU GPL v3).

0 commit comments

Comments
 (0)