Skip to content

Commit 32713b2

Browse files
authored
Merge pull request #838 from stickz/auto-add-servers
Feature: Automatically add servers with rcon password
2 parents 103511b + ee77cbd commit 32713b2

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

game/addons/sourcemod/configs/sourcebans/sourcebans.cfg

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@
3030
// How often should we process the failed ban queue in minutes
3131
"ProcessQueueTime" "5"
3232

33-
// Should the plugin automaticaly add the server to sourcebans
33+
// Should the plugin automatically add the server to sourcebans
3434
// (servers without -ip being set on startup need this set to 0)
35+
// (2 = YES ADD WITH RCON, 1 = YES ADD WITHOUT RCON, 0 = DO NOT ADD SERVER)
3536
"AutoAddServer" "0"
3637

3738
// Enable backing up config files after getting admins from database (1 = enabled, 0 = disabled)
@@ -102,4 +103,4 @@
102103
// "43200" "1 Month"
103104
// "525600" "1 Year"
104105
}
105-
}
106+
}

game/addons/sourcemod/scripting/sbpp_main.sp

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@
4747

4848
#define FLAG_LETTERS_SIZE 26
4949

50+
#define AUTO_ADD_SERVER_DISABLED 0
51+
#define AUTO_ADD_SERVER_WITH_RCON 2
52+
5053
//#define DEBUG
5154

5255
enum State/* ConfigState */
@@ -94,7 +97,6 @@ bool
9497
, loadGroups
9598
, loadOverrides
9699
, LateLoaded
97-
, AutoAdd
98100
, g_bConnecting = false
99101
, requireSiteLogin = false /* Require a lastvisited from SB site */
100102
, backupConfig = true
@@ -104,6 +106,7 @@ bool
104106
int
105107
g_BanTarget[MAXPLAYERS + 1] = { -1, ... }
106108
, g_BanTime[MAXPLAYERS + 1] = { -1, ... }
109+
, AutoAdd = 0
107110
, curLoading
108111
, serverID = -1
109112
, ProcessQueueTime = 5
@@ -1580,9 +1583,20 @@ public void ServerInfoCallback(Database db, DBResultSet results, const char[] er
15801583
if (!results.RowCount)
15811584
{
15821585
// get the game folder name used to determine the mod
1583-
char desc[64], query[200];
1586+
char desc[64], query[200], rcon[128];
15841587
GetGameFolderName(desc, sizeof(desc));
1585-
FormatEx(query, sizeof(query), "INSERT INTO %s_servers (ip, port, rcon, modid) VALUES ('%s', '%s', '', (SELECT mid FROM %s_mods WHERE modfolder = '%s'))", DatabasePrefix, ServerIp, ServerPort, DatabasePrefix, desc);
1588+
Format(rcon, sizeof(rcon), "");
1589+
1590+
if (AutoAdd == AUTO_ADD_SERVER_WITH_RCON)
1591+
{
1592+
ConVar cvarRconPassword = FindConVar("rcon_password");
1593+
if (cvarRconPassword != null)
1594+
{
1595+
cvarRconPassword.GetString(rcon, sizeof(rcon));
1596+
}
1597+
}
1598+
1599+
FormatEx(query, sizeof(query), "INSERT INTO %s_servers (ip, port, rcon, modid) VALUES ('%s', '%s', '%s', (SELECT mid FROM %s_mods WHERE modfolder = '%s'))", DatabasePrefix, ServerIp, ServerPort, rcon, DatabasePrefix, desc);
15861600
db.Query(ErrorCheckCallback, query);
15871601
}
15881602
}
@@ -2236,7 +2250,8 @@ public SMCResult ReadConfig_KeyValue(SMCParser smc, const char[] key, const char
22362250
}
22372251
else if (strcmp("AutoAddServer", key, false) == 0)
22382252
{
2239-
AutoAdd = StringToInt(value) == 1;
2253+
int sAutoAdd = StringToInt(value);
2254+
AutoAdd = (sAutoAdd < 0 || sAutoAdd > 2) ? 0 : sAutoAdd;
22402255
}
22412256
else if (strcmp("Unban", key, false) == 0)
22422257
{
@@ -2645,7 +2660,7 @@ stock void InsertServerInfo()
26452660
FormatEx(ServerIp, sizeof(ServerIp), "%d.%d.%d.%d", pieces[0], pieces[1], pieces[2], pieces[3]);
26462661
CvarPort.GetString(ServerPort, sizeof(ServerPort));
26472662

2648-
if (AutoAdd != false) {
2663+
if (AutoAdd != AUTO_ADD_SERVER_DISABLED) {
26492664
FormatEx(query, sizeof(query), "SELECT sid FROM %s_servers WHERE ip = '%s' AND port = '%s'", DatabasePrefix, ServerIp, ServerPort);
26502665
DB.Query(ServerInfoCallback, query);
26512666
}

0 commit comments

Comments
 (0)