Skip to content

Commit cd7ac23

Browse files
authored
Improving sm_banip
1.a Get the target name of the user banned via sm_banip (ex : sm_banip Rushaway 240 Cheat) Will print target name instead of 'No nickname present' 1.b You can still use the command like sm_banip 255.255.22.2 240 Cheat (Will be show as 'No nickname present') 2. Kick the target banned via sm_banip if the callback succes 3. Remove extra tabs in AutoAdd part
1 parent a4e2392 commit cd7ac23

File tree

1 file changed

+54
-19
lines changed

1 file changed

+54
-19
lines changed

game/addons/sourcemod/scripting/sbpp_main.sp

Lines changed: 54 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ public Action CommandBanIp(int client, int args)
504504
}
505505

506506
int len, next_len;
507-
char Arguments[256], arg[50], time[20];
507+
char Arguments[256], arg[50], time[20], targetName[MAX_NAME_LENGTH];
508508

509509
GetCmdArgString(Arguments, sizeof(Arguments));
510510
len = BreakString(Arguments, arg, sizeof(arg));
@@ -538,7 +538,10 @@ public Action CommandBanIp(int client, int args)
538538
target = target_list[0];
539539

540540
if (!IsFakeClient(target) && CanUserTarget(client, target))
541+
{
542+
GetClientName(target, targetName, sizeof(targetName));
541543
GetClientIP(target, arg, sizeof(arg));
544+
}
542545
}
543546

544547
char adminIp[24], adminAuth[64];
@@ -566,6 +569,7 @@ public Action CommandBanIp(int client, int args)
566569
dataPack.WriteCell(minutes);
567570
dataPack.WriteString(Arguments[len]);
568571
dataPack.WriteString(arg);
572+
dataPack.WriteString(targetName);
569573
dataPack.WriteString(adminAuth);
570574
dataPack.WriteString(adminIp);
571575

@@ -1220,17 +1224,19 @@ public void VerifyInsert(Database db, DBResultSet results, const char[] error, D
12201224
public void SelectBanIpCallback(Database db, DBResultSet results, const char[] error, DataPack dataPack)
12211225
{
12221226
int admin, minutes;
1223-
char adminAuth[30], adminIp[30], banReason[256], ip[16], Query[512];
1224-
char reason[128];
1227+
char adminAuth[30], adminIp[30], banReason[256], ip[16], reason[128], Query[512];
1228+
char targetName[MAX_NAME_LENGTH], sTEscapedName[MAX_NAME_LENGTH * 2 + 1];
12251229

12261230
dataPack.Reset();
12271231
admin = dataPack.ReadCell();
12281232
minutes = dataPack.ReadCell();
12291233
dataPack.ReadString(reason, sizeof(reason));
12301234
dataPack.ReadString(ip, sizeof(ip));
1235+
dataPack.ReadString(targetName, sizeof(targetName));
12311236
dataPack.ReadString(adminAuth, sizeof(adminAuth));
12321237
dataPack.ReadString(adminIp, sizeof(adminIp));
12331238
DB.Escape(reason, banReason, sizeof(banReason));
1239+
DB.Escape(targetName, sTEscapedName, sizeof(sTEscapedName));
12341240

12351241
if (results == null)
12361242
{
@@ -1254,14 +1260,14 @@ public void SelectBanIpCallback(Database db, DBResultSet results, const char[] e
12541260
if (serverID == -1)
12551261
{
12561262
FormatEx(Query, sizeof(Query), "INSERT INTO %s_bans (type, ip, name, created, ends, length, reason, aid, adminIp, sid, country) VALUES \
1257-
(1, '%s', '', UNIX_TIMESTAMP(), UNIX_TIMESTAMP() + %d, %d, '%s', (SELECT aid FROM %s_admins WHERE authid = '%s' OR authid REGEXP '^STEAM_[0-9]:%s$'), '%s', \
1263+
(1, '%s', '%s', UNIX_TIMESTAMP(), UNIX_TIMESTAMP() + %d, %d, '%s', (SELECT aid FROM %s_admins WHERE authid = '%s' OR authid REGEXP '^STEAM_[0-9]:%s$'), '%s', \
12581264
(SELECT sid FROM %s_servers WHERE ip = '%s' AND port = '%s' LIMIT 0,1), ' ')",
1259-
DatabasePrefix, ip, (minutes * 60), (minutes * 60), banReason, DatabasePrefix, adminAuth, adminAuth[8], adminIp, DatabasePrefix, ServerIp, ServerPort);
1265+
DatabasePrefix, ip, sTEscapedName, (minutes * 60), (minutes * 60), banReason, DatabasePrefix, adminAuth, adminAuth[8], adminIp, DatabasePrefix, ServerIp, ServerPort);
12601266
} else {
12611267
FormatEx(Query, sizeof(Query), "INSERT INTO %s_bans (type, ip, name, created, ends, length, reason, aid, adminIp, sid, country) VALUES \
1262-
(1, '%s', '', UNIX_TIMESTAMP(), UNIX_TIMESTAMP() + %d, %d, '%s', (SELECT aid FROM %s_admins WHERE authid = '%s' OR authid REGEXP '^STEAM_[0-9]:%s$'), '%s', \
1268+
(1, '%s', '%s', UNIX_TIMESTAMP(), UNIX_TIMESTAMP() + %d, %d, '%s', (SELECT aid FROM %s_admins WHERE authid = '%s' OR authid REGEXP '^STEAM_[0-9]:%s$'), '%s', \
12631269
%d, ' ')",
1264-
DatabasePrefix, ip, (minutes * 60), (minutes * 60), banReason, DatabasePrefix, adminAuth, adminAuth[8], adminIp, serverID);
1270+
DatabasePrefix, ip, sTEscapedName, (minutes * 60), (minutes * 60), banReason, DatabasePrefix, adminAuth, adminAuth[8], adminIp, serverID);
12651271
}
12661272

12671273
db.Query(InsertBanIpCallback, Query, dataPack, DBPrio_High);
@@ -1271,16 +1277,45 @@ public void InsertBanIpCallback(Database db, DBResultSet results, const char[] e
12711277
{
12721278
// if the pack is good unpack it and close the handle
12731279
int admin, minutes;
1280+
int target = -1;
12741281
char reason[128];
1275-
char arg[30];
1282+
char targetIP[30];
12761283

12771284
if (dataPack != null)
12781285
{
12791286
dataPack.Reset();
12801287
admin = dataPack.ReadCell();
12811288
minutes = dataPack.ReadCell();
12821289
dataPack.ReadString(reason, sizeof(reason));
1283-
dataPack.ReadString(arg, sizeof(arg));
1290+
dataPack.ReadString(targetIP, sizeof(targetIP));
1291+
1292+
for(int i = 1; i <= MaxClients; i++)
1293+
{
1294+
if(!IsClientInGame(i) || IsFakeClient(i))
1295+
continue;
1296+
1297+
char ip[30];
1298+
GetClientIP(i, ip, sizeof(ip));
1299+
if(StrEqual(targetIP, ip, false))
1300+
{
1301+
target = i;
1302+
break;
1303+
}
1304+
}
1305+
1306+
// Kick player
1307+
if(target != -1)
1308+
{
1309+
char length[32];
1310+
if(minutes == 0)
1311+
FormatEx(length, sizeof(length), "permament");
1312+
else
1313+
FormatEx(length, sizeof(length), "%d %s", minutes, minutes == 1 ? "minute" : "minutes");
1314+
1315+
if (IsClientConnected(target))
1316+
KickClient(target, "%t\n\n%t", "Banned Check Site", WebsiteAddress, "Kick Reason", admin, reason, length);
1317+
}
1318+
12841319
delete dataPack;
12851320
} else {
12861321
// Technically this should not be possible
@@ -1296,12 +1331,12 @@ public void InsertBanIpCallback(Database db, DBResultSet results, const char[] e
12961331
return;
12971332
}
12981333

1299-
LogAction(admin, -1, "%t", "Ban Added", admin, minutes, arg, reason);
1334+
LogAction(admin, -1, "%t", "Ban Added", admin, minutes, targetIP, reason);
13001335

13011336
if (admin && IsClientInGame(admin))
1302-
PrintToChat(admin, "%s%t", Prefix, "Ban Success Name", arg);
1337+
PrintToChat(admin, "%s%t", Prefix, "Ban Success Name", targetIP);
13031338
else
1304-
PrintToServer("%s%t", Prefix, "Ban Success Name", arg);
1339+
PrintToServer("%s%t", Prefix, "Ban Success Name", targetIP);
13051340
}
13061341

13071342
public void SelectUnbanCallback(Database db, DBResultSet results, const char[] error, DataPack dataPack)
@@ -1589,13 +1624,13 @@ public void ServerInfoCallback(Database db, DBResultSet results, const char[] er
15891624

15901625
if (AutoAdd == AUTO_ADD_SERVER_WITH_RCON)
15911626
{
1592-
ConVar cvarRconPassword = FindConVar("rcon_password");
1593-
if (cvarRconPassword != null)
1594-
{
1595-
cvarRconPassword.GetString(rcon, sizeof(rcon));
1596-
}
1597-
}
1598-
1627+
ConVar cvarRconPassword = FindConVar("rcon_password");
1628+
if (cvarRconPassword != null)
1629+
{
1630+
cvarRconPassword.GetString(rcon, sizeof(rcon));
1631+
}
1632+
}
1633+
15991634
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);
16001635
db.Query(ErrorCheckCallback, query);
16011636
}

0 commit comments

Comments
 (0)