summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/enums/net/packettype.h10
-rw-r--r--src/net/packetlimiter.cpp189
-rw-r--r--src/net/packetlimiter.h6
3 files changed, 129 insertions, 76 deletions
diff --git a/src/enums/net/packettype.h b/src/enums/net/packettype.h
index 9298a9a8e..ed425aa7a 100644
--- a/src/enums/net/packettype.h
+++ b/src/enums/net/packettype.h
@@ -21,10 +21,10 @@
#ifndef ENUMS_NET_PACKETTYPE_H
#define ENUMS_NET_PACKETTYPE_H
-namespace PacketType
+#include "enums/simpletypes/enumdefines.h"
+
+enumStart(PacketType)
{
- enum T
- {
PACKET_CHAT = 0,
PACKET_PICKUP = 1,
PACKET_DROP = 2,
@@ -39,9 +39,7 @@ namespace PacketType
PACKET_ONLINELIST = 11,
PACKET_WHISPER = 12,
PACKET_SIZE
- };
}
-
-typedef PacketType::T PacketTypeT;
+enumEnd(PacketType);
#endif // ENUMS_NET_PACKETTYPE_H
diff --git a/src/net/packetlimiter.cpp b/src/net/packetlimiter.cpp
index 8652690d9..7f899757e 100644
--- a/src/net/packetlimiter.cpp
+++ b/src/net/packetlimiter.cpp
@@ -23,8 +23,6 @@
#include "configuration.h"
#include "settings.h"
-#include "enums/net/packettype.h"
-
#include "utils/timer.h"
#include <fstream>
@@ -41,85 +39,137 @@ struct PacketLimit final
int cntLimit;
};
-PacketLimit mPacketLimits[PacketType::PACKET_SIZE + 1];
+PacketLimit mPacketLimits[static_cast<size_t>(PacketType::PACKET_SIZE) + 1];
void PacketLimiter::initPacketLimiter()
{
// here i setting packet limits. but current server is broken,
// and this limits may not help.
- mPacketLimits[PacketType::PACKET_CHAT].timeLimit = 10 + 5;
- mPacketLimits[PacketType::PACKET_CHAT].lastTime = 0;
- mPacketLimits[PacketType::PACKET_CHAT].cntLimit = 1;
- mPacketLimits[PacketType::PACKET_CHAT].cnt = 0;
+ mPacketLimits[static_cast<size_t>(
+ PacketType::PACKET_CHAT)].timeLimit = 10 + 5;
+ mPacketLimits[static_cast<size_t>(
+ PacketType::PACKET_CHAT)].lastTime = 0;
+ mPacketLimits[static_cast<size_t>(
+ PacketType::PACKET_CHAT)].cntLimit = 1;
+ mPacketLimits[static_cast<size_t>(
+ PacketType::PACKET_CHAT)].cnt = 0;
// 10
- mPacketLimits[PacketType::PACKET_PICKUP].timeLimit = 10 + 5;
- mPacketLimits[PacketType::PACKET_PICKUP].lastTime = 0;
- mPacketLimits[PacketType::PACKET_PICKUP].cntLimit = 1;
- mPacketLimits[PacketType::PACKET_PICKUP].cnt = 0;
+ mPacketLimits[static_cast<size_t>(
+ PacketType::PACKET_PICKUP)].timeLimit = 10 + 5;
+ mPacketLimits[static_cast<size_t>(
+ PacketType::PACKET_PICKUP)].lastTime = 0;
+ mPacketLimits[static_cast<size_t>(
+ PacketType::PACKET_PICKUP)].cntLimit = 1;
+ mPacketLimits[static_cast<size_t>(
+ PacketType::PACKET_PICKUP)].cnt = 0;
// 10 5
- mPacketLimits[PacketType::PACKET_DROP].timeLimit = 5;
- mPacketLimits[PacketType::PACKET_DROP].lastTime = 0;
- mPacketLimits[PacketType::PACKET_DROP].cntLimit = 1;
- mPacketLimits[PacketType::PACKET_DROP].cnt = 0;
+ mPacketLimits[static_cast<size_t>(
+ PacketType::PACKET_DROP)].timeLimit = 5;
+ mPacketLimits[static_cast<size_t>(
+ PacketType::PACKET_DROP)].lastTime = 0;
+ mPacketLimits[static_cast<size_t>(
+ PacketType::PACKET_DROP)].cntLimit = 1;
+ mPacketLimits[static_cast<size_t>(
+ PacketType::PACKET_DROP)].cnt = 0;
// 100
- mPacketLimits[PacketType::PACKET_NPC_NEXT].timeLimit = 0;
- mPacketLimits[PacketType::PACKET_NPC_NEXT].lastTime = 0;
- mPacketLimits[PacketType::PACKET_NPC_NEXT].cntLimit = 1;
- mPacketLimits[PacketType::PACKET_NPC_NEXT].cnt = 0;
-
- mPacketLimits[PacketType::PACKET_NPC_INPUT].timeLimit = 100;
- mPacketLimits[PacketType::PACKET_NPC_INPUT].lastTime = 0;
- mPacketLimits[PacketType::PACKET_NPC_INPUT].cntLimit = 1;
- mPacketLimits[PacketType::PACKET_NPC_INPUT].cnt = 0;
+ mPacketLimits[static_cast<size_t>(
+ PacketType::PACKET_NPC_NEXT)].timeLimit = 0;
+ mPacketLimits[static_cast<size_t>(
+ PacketType::PACKET_NPC_NEXT)].lastTime = 0;
+ mPacketLimits[static_cast<size_t>(
+ PacketType::PACKET_NPC_NEXT)].cntLimit = 1;
+ mPacketLimits[static_cast<size_t>(
+ PacketType::PACKET_NPC_NEXT)].cnt = 0;
+
+ mPacketLimits[static_cast<size_t>(
+ PacketType::PACKET_NPC_INPUT)].timeLimit = 100;
+ mPacketLimits[static_cast<size_t>(
+ PacketType::PACKET_NPC_INPUT)].lastTime = 0;
+ mPacketLimits[static_cast<size_t>(
+ PacketType::PACKET_NPC_INPUT)].cntLimit = 1;
+ mPacketLimits[static_cast<size_t>(
+ PacketType::PACKET_NPC_INPUT)].cnt = 0;
// 50
- mPacketLimits[PacketType::PACKET_NPC_TALK].timeLimit = 60;
- mPacketLimits[PacketType::PACKET_NPC_TALK].lastTime = 0;
- mPacketLimits[PacketType::PACKET_NPC_TALK].cntLimit = 1;
- mPacketLimits[PacketType::PACKET_NPC_TALK].cnt = 0;
+ mPacketLimits[static_cast<size_t>(
+ PacketType::PACKET_NPC_TALK)].timeLimit = 60;
+ mPacketLimits[static_cast<size_t>(
+ PacketType::PACKET_NPC_TALK)].lastTime = 0;
+ mPacketLimits[static_cast<size_t>(
+ PacketType::PACKET_NPC_TALK)].cntLimit = 1;
+ mPacketLimits[static_cast<size_t>(
+ PacketType::PACKET_NPC_TALK)].cnt = 0;
// 10
- mPacketLimits[PacketType::PACKET_EMOTE].timeLimit = 10 + 5;
- mPacketLimits[PacketType::PACKET_EMOTE].lastTime = 0;
- mPacketLimits[PacketType::PACKET_EMOTE].cntLimit = 1;
- mPacketLimits[PacketType::PACKET_EMOTE].cnt = 0;
+ mPacketLimits[static_cast<size_t>(
+ PacketType::PACKET_EMOTE)].timeLimit = 10 + 5;
+ mPacketLimits[static_cast<size_t>(
+ PacketType::PACKET_EMOTE)].lastTime = 0;
+ mPacketLimits[static_cast<size_t>(
+ PacketType::PACKET_EMOTE)].cntLimit = 1;
+ mPacketLimits[static_cast<size_t>(
+ PacketType::PACKET_EMOTE)].cnt = 0;
// 100
- mPacketLimits[PacketType::PACKET_SIT].timeLimit = 100;
- mPacketLimits[PacketType::PACKET_SIT].lastTime = 0;
- mPacketLimits[PacketType::PACKET_SIT].cntLimit = 1;
- mPacketLimits[PacketType::PACKET_SIT].cnt = 0;
-
- mPacketLimits[PacketType::PACKET_DIRECTION].timeLimit = 50;
- mPacketLimits[PacketType::PACKET_DIRECTION].lastTime = 0;
- mPacketLimits[PacketType::PACKET_DIRECTION].cntLimit = 1;
- mPacketLimits[PacketType::PACKET_DIRECTION].cnt = 0;
+ mPacketLimits[static_cast<size_t>(
+ PacketType::PACKET_SIT)].timeLimit = 100;
+ mPacketLimits[static_cast<size_t>(
+ PacketType::PACKET_SIT)].lastTime = 0;
+ mPacketLimits[static_cast<size_t>(
+ PacketType::PACKET_SIT)].cntLimit = 1;
+ mPacketLimits[static_cast<size_t>(
+ PacketType::PACKET_SIT)].cnt = 0;
+
+ mPacketLimits[static_cast<size_t>(
+ PacketType::PACKET_DIRECTION)].timeLimit = 50;
+ mPacketLimits[static_cast<size_t>(
+ PacketType::PACKET_DIRECTION)].lastTime = 0;
+ mPacketLimits[static_cast<size_t>(
+ PacketType::PACKET_DIRECTION)].cntLimit = 1;
+ mPacketLimits[static_cast<size_t>(
+ PacketType::PACKET_DIRECTION)].cnt = 0;
// 2+
- mPacketLimits[PacketType::PACKET_ATTACK].timeLimit = 2 + 10;
- mPacketLimits[PacketType::PACKET_ATTACK].lastTime = 0;
- mPacketLimits[PacketType::PACKET_ATTACK].cntLimit = 1;
- mPacketLimits[PacketType::PACKET_ATTACK].cnt = 0;
-
- mPacketLimits[PacketType::PACKET_STOPATTACK].timeLimit = 2 + 10;
- mPacketLimits[PacketType::PACKET_STOPATTACK].lastTime = 0;
- mPacketLimits[PacketType::PACKET_STOPATTACK].cntLimit = 1;
- mPacketLimits[PacketType::PACKET_STOPATTACK].cnt = 0;
-
- mPacketLimits[PacketType::PACKET_ONLINELIST].timeLimit = 1800;
- mPacketLimits[PacketType::PACKET_ONLINELIST].lastTime = 0;
- mPacketLimits[PacketType::PACKET_ONLINELIST].cntLimit = 1;
- mPacketLimits[PacketType::PACKET_ONLINELIST].cnt = 0;
+ mPacketLimits[static_cast<size_t>(
+ PacketType::PACKET_ATTACK)].timeLimit = 2 + 10;
+ mPacketLimits[static_cast<size_t>(
+ PacketType::PACKET_ATTACK)].lastTime = 0;
+ mPacketLimits[static_cast<size_t>(
+ PacketType::PACKET_ATTACK)].cntLimit = 1;
+ mPacketLimits[static_cast<size_t>(
+ PacketType::PACKET_ATTACK)].cnt = 0;
+
+ mPacketLimits[static_cast<size_t>(
+ PacketType::PACKET_STOPATTACK)].timeLimit = 2 + 10;
+ mPacketLimits[static_cast<size_t>(
+ PacketType::PACKET_STOPATTACK)].lastTime = 0;
+ mPacketLimits[static_cast<size_t>(
+ PacketType::PACKET_STOPATTACK)].cntLimit = 1;
+ mPacketLimits[static_cast<size_t>(
+ PacketType::PACKET_STOPATTACK)].cnt = 0;
+
+ mPacketLimits[static_cast<size_t>(
+ PacketType::PACKET_ONLINELIST)].timeLimit = 1800;
+ mPacketLimits[static_cast<size_t>(
+ PacketType::PACKET_ONLINELIST)].lastTime = 0;
+ mPacketLimits[static_cast<size_t>(
+ PacketType::PACKET_ONLINELIST)].cntLimit = 1;
+ mPacketLimits[static_cast<size_t>(
+ PacketType::PACKET_ONLINELIST)].cnt = 0;
// 300ms + 50 fix
- mPacketLimits[PacketType::PACKET_WHISPER].timeLimit = 30 + 5;
- mPacketLimits[PacketType::PACKET_WHISPER].lastTime = 0;
- mPacketLimits[PacketType::PACKET_WHISPER].cntLimit = 1;
- mPacketLimits[PacketType::PACKET_WHISPER].cnt = 0;
+ mPacketLimits[static_cast<size_t>(
+ PacketType::PACKET_WHISPER)].timeLimit = 30 + 5;
+ mPacketLimits[static_cast<size_t>(
+ PacketType::PACKET_WHISPER)].lastTime = 0;
+ mPacketLimits[static_cast<size_t>(
+ PacketType::PACKET_WHISPER)].cntLimit = 1;
+ mPacketLimits[static_cast<size_t>(
+ PacketType::PACKET_WHISPER)].cnt = 0;
if (!settings.serverConfigDir.empty())
{
@@ -148,14 +198,17 @@ void PacketLimiter::initPacketLimiter()
const int ver = atoi(line);
- for (int f = 0; f < PacketType::PACKET_SIZE; f ++)
+ for (int f = 0;
+ f < static_cast<int>(PacketType::PACKET_SIZE);
+ f ++)
{
if (!inPacketFile.getline(line, 100))
break;
if (!(ver == 1 &&
- (f == PacketType::PACKET_DROP ||
- f == PacketType::PACKET_NPC_NEXT)))
+ (static_cast<PacketTypeT>(f) == PacketType::PACKET_DROP ||
+ static_cast<PacketTypeT>(f)
+ == PacketType::PACKET_NPC_NEXT)))
{
mPacketLimits[f].timeLimit = atoi(line);
}
@@ -177,7 +230,7 @@ void PacketLimiter::writePacketLimits(const std::string &packetLimitsName)
return;
}
outPacketFile << "4" << std::endl;
- for (int f = 0; f < PacketType::PACKET_SIZE; f ++)
+ for (int f = 0; f < static_cast<int>(PacketType::PACKET_SIZE); f ++)
{
outPacketFile << toString(mPacketLimits[f].timeLimit)
<< std::endl;
@@ -186,7 +239,7 @@ void PacketLimiter::writePacketLimits(const std::string &packetLimitsName)
outPacketFile.close();
}
-bool PacketLimiter::checkPackets(const int type)
+bool PacketLimiter::checkPackets(const PacketTypeT type)
{
if (type > PacketType::PACKET_SIZE)
return false;
@@ -194,7 +247,7 @@ bool PacketLimiter::checkPackets(const int type)
if (!serverConfig.getValueBool("enableBuggyServers", true))
return true;
- const PacketLimit &limit = mPacketLimits[type];
+ const PacketLimit &limit = mPacketLimits[static_cast<size_t>(type)];
const int timeLimit = limit.timeLimit;
if (!timeLimit)
@@ -229,15 +282,15 @@ bool PacketLimiter::checkPackets(const int type)
return true;
}
-bool PacketLimiter::limitPackets(const int type)
+bool PacketLimiter::limitPackets(const PacketTypeT type)
{
- if (type < 0 || type > PacketType::PACKET_SIZE)
+ if (static_cast<int>(type) < 0 || type > PacketType::PACKET_SIZE)
return false;
if (!serverConfig.getValueBool("enableBuggyServers", true))
return true;
- PacketLimit &pack = mPacketLimits[type];
+ PacketLimit &pack = mPacketLimits[static_cast<size_t>(type)];
const int timeLimit = pack.timeLimit;
if (!timeLimit)
diff --git a/src/net/packetlimiter.h b/src/net/packetlimiter.h
index f0d8a78df..d8d7d4ea6 100644
--- a/src/net/packetlimiter.h
+++ b/src/net/packetlimiter.h
@@ -21,6 +21,8 @@
#ifndef NET_PACKETLIMITER_H
#define NET_PACKETLIMITER_H
+#include "enums/net/packettype.h"
+
#include <string>
#include "localconsts.h"
@@ -31,9 +33,9 @@ namespace PacketLimiter
void writePacketLimits(const std::string &packetLimitsName);
- bool limitPackets(const int type) A_WARN_UNUSED;
+ bool limitPackets(const PacketTypeT type) A_WARN_UNUSED;
- bool checkPackets(const int type) A_WARN_UNUSED;
+ bool checkPackets(const PacketTypeT type) A_WARN_UNUSED;
}
#endif // NET_PACKETLIMITER_H