From e252ed04e96906f5ecda9c02568835c34f88bcd4 Mon Sep 17 00:00:00 2001
From: scatterflower <marisaposs@gameboyprinter.moe>
Date: Mon, 19 Apr 2021 02:09:24 -0500
Subject: [PATCH] make it configurable

---
 bin/config_sample/config.ini | 1 +
 include/server.h             | 5 +++++
 src/packets.cpp              | 4 +---
 src/server.cpp               | 8 +++++---
 4 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/bin/config_sample/config.ini b/bin/config_sample/config.ini
index 34e14e4..bd43618 100644
--- a/bin/config_sample/config.ini
+++ b/bin/config_sample/config.ini
@@ -17,6 +17,7 @@ modpass=changeme
 logbuffer=500
 logging=modcall
 maximum_statements=10
+multiclient_limit=15
 
 [Dice]
 max_value=100
diff --git a/include/server.h b/include/server.h
index 0d44b0e..f96fd79 100644
--- a/include/server.h
+++ b/include/server.h
@@ -281,6 +281,11 @@ class Server : public QObject {
      */
     QStringList gimp_list;
 
+    /**
+     * @brief Integer representing the maximum number of clients allowed to connect from the same IP
+     */
+    int multiclient_limit;
+
   public slots:
     /**
      * @brief Handles a new connection.
diff --git a/src/packets.cpp b/src/packets.cpp
index 2595576..98e25af 100644
--- a/src/packets.cpp
+++ b/src/packets.cpp
@@ -308,12 +308,10 @@ void AOClient::pktWebSocketIp(AreaData* area, int argc, QStringList argv, AOPack
                 multiclient_count++;
         }
 
-        if (multiclient_count > 5) {
+        if (multiclient_count > server->multiclient_limit) {
             socket->close();
             return;
         }
-
-        qDebug() << "MULTICLIENT COUNT WS: " << multiclient_count;
     }
 }
 
diff --git a/src/server.cpp b/src/server.cpp
index 9ecdb31..30dea51 100644
--- a/src/server.cpp
+++ b/src/server.cpp
@@ -123,9 +123,7 @@ void Server::clientConnected()
             multiclient_count++;
     }
 
-    qDebug() << "MULTICLIENT COUNT: " << multiclient_count;
-
-    if (multiclient_count > 5 && !client->remote_ip.isLoopback()) // TODO: make this configurable
+    if (multiclient_count > multiclient_limit && !client->remote_ip.isLoopback()) // TODO: make this configurable
         is_at_multiclient_limit = true;
 
     if (is_banned) {
@@ -281,6 +279,10 @@ void Server::loadServerConfig()
     afk_timeout = config.value("afk_timeout", "300").toInt(&afk_timeout_conversion_success);
     if (!afk_timeout_conversion_success)
         afk_timeout = 300;
+    bool multiclient_limit_conversion_success;
+    multiclient_limit = config.value("multiclient_limit", "15").toInt(&multiclient_limit_conversion_success);
+    if (!multiclient_limit_conversion_success)
+        multiclient_limit = 15;
     config.endGroup();
 
     //Load dice values