Skip to content

Commit 6f0cd1d

Browse files
committed
Fixed kicks for unused server messages
New ban entries would be created for too many wasted server messages, even ban entries for that IP were already present. Now existing ban entries' disconnect count is properly incremented. Also removed some disabled debug code from yonder.
1 parent 9eecae6 commit 6f0cd1d

File tree

2 files changed

+13
-21
lines changed

2 files changed

+13
-21
lines changed

POSIXMain.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -506,8 +506,12 @@ void OnServerMessage(lacewing::relayserver &server, std::shared_ptr<lacewing::re
506506
++(**cd).totalNumMessagesIn;
507507

508508
if ((**cd).wastedServerMessages++ > 5) {
509-
banIPList.push_back(BanEntry(addr, 1, "Sending too many messages the server is not meant to handle.",
510-
time(NULL) + 60 * 60));
509+
auto banEntry = std::find_if(banIPList.begin(), banIPList.end(), [&](const BanEntry& b) { return b.ip == addr; });
510+
if (banEntry == banIPList.end())
511+
banIPList.push_back(BanEntry(addr, 1, "Sending too many messages the server is not meant to handle.",
512+
time(NULL) + 60 * 60));
513+
else
514+
++banEntry->disconnects;
511515
senderclient->send(1, "You have been banned for sending too many server messages that the server is not designed to receive.\r\nContact Phi on Clickteam Discord."sv);
512516
senderclient->disconnect();
513517
}

WindowsMain.cpp

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -569,23 +569,6 @@ void OnError(lacewing::relayserver &server, lacewing::error error)
569569
void OnServerMessage(lacewing::relayserver &server, std::shared_ptr<lacewing::relayserver::client> senderclient,
570570
bool blasted, lw_ui8 subchannel, std::string_view data, lw_ui8 variant)
571571
{
572-
senderclient->send(3, data, 2);
573-
#if 0
574-
char data3[] = "\x41" "\x85\xFF" "\x70\x2F\xFC\xFF";
575-
//"\x1\x1\x1\x1" "ABC\xCF\x95\xCF\x95";
576-
std::string_view data2((const char*)&data3, sizeof(data3));
577-
578-
senderclient->blast(12, data2, 2);
579-
senderclient->send(3, data2, 2);
580-
{
581-
auto rl = senderclient->lock.createReadLock();
582-
auto ch = senderclient->getchannels();
583-
auto ch2 = ch[0];
584-
rl.lw_unlock();
585-
ch2->send(103, data2, 2);
586-
ch2->blast(255, data2, 2);
587-
}
588-
#endif
589572
++numMessagesIn;
590573
bytesIn += data.size();
591574
if constexpr (false)
@@ -614,8 +597,13 @@ void OnServerMessage(lacewing::relayserver &server, std::shared_ptr<lacewing::re
614597
++(**cd).totalNumMessagesIn;
615598

616599
if ((**cd).wastedServerMessages++ > 5) {
617-
banIPList.push_back(BanEntry(addr, 1, "Sending too many messages the server is not meant to handle.",
618-
_time64(NULL) + 60LL * 60LL));
600+
601+
auto banEntry = std::find_if(banIPList.begin(), banIPList.end(), [&](const BanEntry& b) { return b.ip == addr; });
602+
if (banEntry == banIPList.end())
603+
banIPList.push_back(BanEntry(addr, 1, "Sending too many messages the server is not meant to handle.",
604+
_time64(NULL) + 60LL * 60LL));
605+
else
606+
++banEntry->disconnects;
619607
senderclient->send(1, "You have been banned for sending too many server messages that the server is not designed to receive.\r\nContact Phi on Clickteam Discord."sv);
620608
senderclient->disconnect();
621609
}

0 commit comments

Comments
 (0)