Skip to content

Commit 774e9ad

Browse files
authored
Update sbpp_comms.sp (#764)
1 parent 63637f0 commit 774e9ad

File tree

1 file changed

+33
-52
lines changed

1 file changed

+33
-52
lines changed

Diff for: game/addons/sourcemod/scripting/sbpp_comms.sp

+33-52
Original file line numberDiff line numberDiff line change
@@ -1334,10 +1334,11 @@ public void Query_UnBlockSelect(Database db, DBResultSet results, const char[] e
13341334
dataPack.Reset();
13351335
int adminUserID = dataPack.ReadCell();
13361336
int targetUserID = dataPack.ReadCell();
1337-
int type = dataPack.ReadCell(); // not in use unless DEBUG
1337+
int type = dataPack.ReadCell();
13381338
dataPack.ReadString(adminAuth, sizeof(adminAuth));
13391339
dataPack.ReadString(targetAuth, sizeof(targetAuth));
13401340
dataPack.ReadString(reason, sizeof(reason));
1341+
delete dataPack;
13411342

13421343
int admin = GetClientOfUserId(adminUserID);
13431344
int target = GetClientOfUserId(targetUserID);
@@ -1355,7 +1356,8 @@ public void Query_UnBlockSelect(Database db, DBResultSet results, const char[] e
13551356
if (DB_Conn_Lost(results) || error[0] != '\0')
13561357
{
13571358
LogError("Query_UnBlockSelect failed: %s", error);
1358-
if (admin && IsClientInGame(admin))
1359+
1360+
if (admin)
13591361
{
13601362
PrintToChat(admin, "%s%T", PREFIX, "Unblock Select Failed", admin, targetAuth);
13611363
PrintToConsole(admin, "%s%T", PREFIX, "Unblock Select Failed", admin, targetAuth);
@@ -1364,13 +1366,13 @@ public void Query_UnBlockSelect(Database db, DBResultSet results, const char[] e
13641366
{
13651367
PrintToServer("%s%T", PREFIX, "Unblock Select Failed", LANG_SERVER, targetAuth);
13661368
}
1369+
13671370
hasErrors = true;
13681371
}
1369-
1370-
// If there was no results then a ban does not exist for that id
1371-
if (!DB_Conn_Lost(results) && !results.RowCount)
1372+
// If there were no results then a ban does not exist for that id
1373+
else if (!results.RowCount)
13721374
{
1373-
if (admin && IsClientInGame(admin))
1375+
if (admin)
13741376
{
13751377
PrintToChat(admin, "%s%t", PREFIX, "No blocks found", targetAuth);
13761378
PrintToConsole(admin, "%s%t", PREFIX, "No blocks found", targetAuth);
@@ -1379,6 +1381,7 @@ public void Query_UnBlockSelect(Database db, DBResultSet results, const char[] e
13791381
{
13801382
PrintToServer("%s%T", PREFIX, "No blocks found", LANG_SERVER, targetAuth);
13811383
}
1384+
13821385
hasErrors = true;
13831386
}
13841387

@@ -1388,8 +1391,10 @@ public void Query_UnBlockSelect(Database db, DBResultSet results, const char[] e
13881391
PrintToServer("Calling TempUnBlock from Query_UnBlockSelect");
13891392
#endif
13901393

1391-
TempUnBlock(dataPack); // Datapack closed inside.
1392-
return;
1394+
if (target)
1395+
{
1396+
TempUnBlock(admin, target, type, adminAuth, targetAuth, reason);
1397+
}
13931398
}
13941399
else
13951400
{
@@ -1422,12 +1427,13 @@ public void Query_UnBlockSelect(Database db, DBResultSet results, const char[] e
14221427
#endif
14231428

14241429
// Checking - has we access to unblock?
1425-
if (iAID == cAID || (!admin && StrEqual(adminAuth, "STEAM_ID_SERVER")) || AdmHasFlag(admin) || (DisUBImCheck == 0 && (GetAdmImmunity(admin) > cImmunity)))
1430+
if (iAID == cAID || !adminUserID || AdmHasFlag(admin) || (DisUBImCheck == 0 && (GetAdmImmunity(admin) > cImmunity)))
14261431
{
14271432
// Ok! we have rights to unblock
14281433
b_success = true;
1434+
14291435
// UnMute/UnGag, Show & log activity
1430-
if (target && IsClientInGame(target))
1436+
if (target)
14311437
{
14321438
switch (cType)
14331439
{
@@ -1499,7 +1505,7 @@ public void Query_UnBlockSelect(Database db, DBResultSet results, const char[] e
14991505
}
15001506
}
15011507

1502-
if (b_success && target && IsClientInGame(target))
1508+
if (b_success && target)
15031509
{
15041510
#if defined DEBUG
15051511
PrintToServer("Showing activity to server in Query_UnBlockSelect");
@@ -1509,25 +1515,17 @@ public void Query_UnBlockSelect(Database db, DBResultSet results, const char[] e
15091515
if (type == TYPE_UNSILENCE)
15101516
{
15111517
// check result for possible combination with temp and time punishments (temp was skipped in code above)
1512-
1513-
dataPack.Position = view_as<DataPackPos>(16);
1514-
15151518
if (g_MuteType[target] > bNot)
15161519
{
1517-
dataPack.WriteCell(TYPE_UNMUTE);
1518-
TempUnBlock(dataPack);
1520+
TempUnBlock(admin, target, TYPE_UNMUTE, adminAuth, targetAuth, reason);
15191521
}
15201522
else if (g_GagType[target] > bNot)
15211523
{
1522-
dataPack.WriteCell(TYPE_UNGAG);
1523-
TempUnBlock(dataPack);
1524+
TempUnBlock(admin, target, TYPE_UNGAG, adminAuth, targetAuth, reason);
15241525
}
15251526
}
15261527
}
15271528
}
1528-
1529-
if (dataPack != null)
1530-
delete dataPack;
15311529
}
15321530

15331531
public void Query_UnBlockUpdate(Database db, DBResultSet results, const char[] error, DataPack dataPack)
@@ -2467,18 +2465,18 @@ stock void ProcessUnBlock(int client, int targetId = 0, int type, char[] sReason
24672465
}
24682466
}
24692467

2470-
// Pack everything into a data pack so we can retain it
2471-
DataPack dataPack = new DataPack();
2472-
dataPack.WriteCell(GetClientUserId2(client));
2473-
dataPack.WriteCell(GetClientUserId(target));
2474-
dataPack.WriteCell(type);
2475-
dataPack.WriteString(adminAuth);
2476-
dataPack.WriteString(targetAuth);
2477-
dataPack.WriteString(reason);
2478-
2479-
// Check current player status. If player has temporary punishment - don't get info from DB
2468+
// Check current player status. If player has temporary punishment - don't get info from DB.
24802469
if (DB_Connect())
24812470
{
2471+
// Pack everything into a data pack so we can retain it
2472+
DataPack dataPack = new DataPack();
2473+
dataPack.WriteCell(GetClientUserId2(client));
2474+
dataPack.WriteCell(GetClientUserId(target));
2475+
dataPack.WriteCell(type);
2476+
dataPack.WriteString(adminAuth);
2477+
dataPack.WriteString(targetAuth);
2478+
dataPack.WriteString(reason);
2479+
24822480
char sAdminAuthEscaped[sizeof(adminAuth) * 2 + 1];
24832481
char sAdminAuthYZEscaped[sizeof(adminAuth) * 2 + 1];
24842482
char sTargetAuthEscaped[sizeof(targetAuth) * 2 + 1];
@@ -2517,35 +2515,18 @@ stock void ProcessUnBlock(int client, int targetId = 0, int type, char[] sReason
25172515
PrintToServer("Calling TempUnBlock from ProcessUnBlock");
25182516
#endif
25192517

2520-
if (TempUnBlock(dataPack))
2518+
if (TempUnBlock(client, target, type, adminAuth, targetAuth, reason))
25212519
ShowActivityToServer(client, type + TYPE_TEMP_SHIFT, _, _, g_sName[target], _);
25222520
}
25232521
}
25242522
}
25252523

2526-
stock bool TempUnBlock(DataPack dataPack)
2524+
stock bool TempUnBlock(const int admin, const int target, const int type, const char[] adminAuth, const char[] targetAuth, const char[] reason)
25272525
{
2528-
char adminAuth[30], targetAuth[30];
2529-
char reason[256];
2530-
2531-
dataPack.Reset();
2532-
int adminUserID = dataPack.ReadCell();
2533-
int targetUserID = dataPack.ReadCell();
2534-
int type = dataPack.ReadCell();
2535-
dataPack.ReadString(adminAuth, sizeof(adminAuth));
2536-
dataPack.ReadString(targetAuth, sizeof(targetAuth));
2537-
dataPack.ReadString(reason, sizeof(reason));
2538-
delete dataPack; // Need to close datapack
2539-
25402526
#if defined DEBUG
2541-
PrintToServer("TempUnBlock(adminUID: %d, targetUID: %d, type: %d, adminAuth: %s, targetAuth: %s, reason: %s)", adminUserID, targetUserID, type, adminAuth, targetAuth, reason);
2527+
PrintToServer("TempUnBlock(admin: %u, target: %u, type: %d, adminAuth: %s, targetAuth: %s, reason: %s)", admin, target, type, adminAuth, targetAuth, reason);
25422528
#endif
25432529

2544-
int admin = GetClientOfUserId(adminUserID);
2545-
int target = GetClientOfUserId(targetUserID);
2546-
if (!target)
2547-
return false; // target has gone away
2548-
25492530
int AdmImmunity = GetAdmImmunity(admin);
25502531
bool AdmImCheck = (DisUBImCheck == 0
25512532
&& ((type == TYPE_UNMUTE && AdmImmunity >= g_iMuteLevel[target])
@@ -2564,7 +2545,7 @@ stock bool TempUnBlock(DataPack dataPack)
25642545
#endif
25652546

25662547
// Check access for unblock without db changes (temporary unblock)
2567-
bool bHasPermission = (!admin && StrEqual(adminAuth, "STEAM_ID_SERVER")) || AdmHasFlag(admin) || AdmImCheck;
2548+
bool bHasPermission = !admin || AdmHasFlag(admin) || AdmImCheck;
25682549
// can, if we are console or have special flag. else - deep checking by issuer authid
25692550
if (!bHasPermission) {
25702551
switch (type)

0 commit comments

Comments
 (0)