@@ -45,6 +45,7 @@ along with this program. If not, see http://www.gnu.org/licenses/
45
45
#include " linkshell.h"
46
46
#include " map.h"
47
47
#include " mob_spell_list.h"
48
+ #include " packet_guard.h"
48
49
#include " packet_system.h"
49
50
#include " party.h"
50
51
#include " utils/petutils.h"
@@ -251,6 +252,8 @@ int32 do_init(int32 argc, char** argv)
251
252
g_PBuff = new int8[map_config.buffer_size + 20 ];
252
253
PTempBuff = new int8[map_config.buffer_size + 20 ];
253
254
255
+ PacketGuard::Init ();
256
+
254
257
ShowStatus (" The map-server is " CL_GREEN" ready" CL_RESET" to work...\n " );
255
258
ShowMessage (" =======================================================================\n " );
256
259
return 0 ;
@@ -584,18 +587,35 @@ int32 parse(int8* buff, size_t* buffsize, sockaddr_in* from, map_session_data_t*
584
587
585
588
if (PacketSize[SmallPD_Type] == SmallPD_Size || PacketSize[SmallPD_Type] == 0 ) // Tests incoming packets for the correct size prior to processing
586
589
{
587
- // если код текущего пакета меньше либо равен последнему полученному
588
- // или больше глобального то игнорируем пакет
590
+ // Google Translate:
591
+ // if the code of the current package is less than or equal to the last received
592
+ // or more global then ignore the package
589
593
590
594
if ((ref<uint16>(SmallPD_ptr, 2 ) <= map_session_data->client_packet_id ) ||
591
595
(ref<uint16>(SmallPD_ptr, 2 ) > SmallPD_Code))
592
596
{
593
597
continue ;
594
598
}
599
+
595
600
if (SmallPD_Type != 0x15 )
596
601
{
597
602
ShowInfo (" parse: %03hX | %04hX %04hX %02hX from user: %s\n " , SmallPD_Type, ref<uint16>(SmallPD_ptr, 2 ), ref<uint16>(buff, 2 ), SmallPD_Size, PChar->GetName ());
598
603
}
604
+
605
+ if (map_config.packetguard_enabled && PacketGuard::IsRateLimitedPacket (PChar, SmallPD_Type))
606
+ {
607
+ ShowError (CL_RED " Rate-limiting packet: Player: %s - Packet: %03hX\n " CL_RESET, PChar->GetName (), SmallPD_Type);
608
+ continue ; // skip this packet
609
+ }
610
+
611
+ if (map_config.packetguard_enabled && !PacketGuard::PacketIsValidForPlayerState (PChar, SmallPD_Type))
612
+ {
613
+ // TODO: Log exploit
614
+ ShowError (CL_RED " Caught mismatch between player substate and recieved packet: Player: %s - Packet: %03hX\n " CL_RESET, PChar->GetName (), SmallPD_Type);
615
+ // TODO: Plug in optional jailutils usage
616
+ continue ; // skip this packet
617
+ }
618
+
599
619
if (PChar->loc .zone == nullptr && SmallPD_Type != 0x0A )
600
620
{
601
621
ShowWarning (" This packet is unexpected from %s - Received %03hX earlier without matching 0x0A\n " , PChar->GetName (), SmallPD_Type);
@@ -612,8 +632,9 @@ int32 parse(int8* buff, size_t* buffsize, sockaddr_in* from, map_session_data_t*
612
632
}
613
633
map_session_data->client_packet_id = SmallPD_Code;
614
634
615
- // здесь мы проверяем, получил ли клиент предыдущий пакет
616
- // если не получил, то мы не создаем новый, а отправляем предыдущий
635
+ // Google Translate:
636
+ // here we check if the client received the previous package
637
+ // if not received, then we do not create a new one, but send the previous one
617
638
618
639
if (ref<uint16>(buff, 2 ) != map_session_data->server_packet_id )
619
640
{
@@ -627,7 +648,7 @@ int32 parse(int8* buff, size_t* buffsize, sockaddr_in* from, map_session_data_t*
627
648
return -1 ;
628
649
}
629
650
630
- // увеличиваем номер отправленного пакета только в случае отправки новых данных
651
+ // GT: increase the number of the sent packet only if new data is sent
631
652
632
653
map_session_data->server_packet_id += 1 ;
633
654
@@ -1000,6 +1021,7 @@ int32 map_config_default()
1000
1021
map_config.blood_pact_shared_timer = 0 ;
1001
1022
map_config.vanadiel_time_epoch = 0 ;
1002
1023
map_config.lightluggage_block = 4 ;
1024
+ map_config.packetguard_enabled = false ;
1003
1025
map_config.max_time_lastupdate = 60000 ;
1004
1026
map_config.newstyle_skillups = 7 ;
1005
1027
map_config.drop_rate_multiplier = 1 .0f ;
@@ -1101,6 +1123,10 @@ int32 map_config_read(const int8* cfgName)
1101
1123
{
1102
1124
map_config.lightluggage_block = atoi (w2);
1103
1125
}
1126
+ else if (strcmp (w1, " packetguard_enabled" ) == 0 )
1127
+ {
1128
+ map_config.packetguard_enabled = atoi (w2);
1129
+ }
1104
1130
else if (strcmp (w1, " ah_base_fee_single" ) == 0 )
1105
1131
{
1106
1132
map_config.ah_base_fee_single = atoi (w2);
0 commit comments