Skip to content

Commit

Permalink
yoink
Browse files Browse the repository at this point in the history
added telefinder.sp
added delete records by steam id
maybe db creation fix
maybe shuffled some things
  • Loading branch information
qawery-just-sad committed Oct 2, 2020
1 parent c482ee8 commit ad18ac2
Show file tree
Hide file tree
Showing 6 changed files with 294 additions and 23 deletions.
124 changes: 124 additions & 0 deletions addons/sourcemod/scripting/Telefinder.sp
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
#pragma semicolon 1

#include <sourcemod>
#include <sdktools>
#include <cstrike>
#include <surftimer>

Handle g_hEntity;
Handle g_hTMEntity;

public Plugin myinfo =
{
name = "[Surf Timer] Teleport Destination Finder",
author = "marcowmadeira",
description = "Shows a list of info_teleport_destination entities.",
version = "1.0",
url = "http://marcowmadeira.com/"
};

public void OnPluginStart()
{
RegAdminCmd("sm_surftimertele", ShowTeleportDestinations, ADMFLAG_ROOT, "[Surf Timer] Shows a menu with all info_teleport_destination entities");
RegAdminCmd("sm_itd", ShowTeleportDestinations, ADMFLAG_ROOT, "[Surf Timer] Shows a menu with all info_teleport_destination entities");
RegAdminCmd("sm_triggerlocations", ShowTriggersLocations, ADMFLAG_ROOT, "[Surf Timer] Shows a menu with all trigger_multiple locations");
}

public void OnMapStart()
{
int iEnt;
g_hEntity = CreateArray(12);
g_hTMEntity = CreateArray(12);

while ((iEnt = FindEntityByClassname(iEnt, "info_teleport_destination")) != -1)
PushArrayCell(g_hEntity, iEnt);

while ((iEnt = FindEntityByClassname(iEnt, "trigger_multiple")) != -1) {

char target_name[32];
GetEntPropString(iEnt, Prop_Data, "m_iName", target_name, sizeof(target_name));


if (strlen(target_name) > 0 && StrContains(target_name, "sm_ckZone") == -1)
PushArrayCell(g_hTMEntity, iEnt);
}
}

public void OnMapEnd()
{
delete g_hEntity;
delete g_hTMEntity;
}

public Action ShowTeleportDestinations(int client, int args)
{
Menu menu = new Menu(TD_MenuHandler);

menu.SetTitle("Teleport Destinations");

for (int i = 0; i < GetArraySize(g_hEntity); i++)
{

// Get entity
int entity = GetArrayCell(g_hEntity, i);

// Get targetname
char target_name[32];
GetEntPropString(entity, Prop_Data, "m_iName", target_name, sizeof(target_name));

menu.AddItem(target_name, target_name);
}

menu.Display(client, 30);
}

public int TD_MenuHandler(Menu menu, MenuAction action, int param1, int param2)
{
if (action == MenuAction_Select) {

int entity = GetArrayCell(g_hEntity, param2);

float position[3];
GetEntPropVector(entity, Prop_Send, "m_vecOrigin", position);

surftimer_SafeTeleport(param1, position, NULL_VECTOR, NULL_VECTOR, true);
} else if (action == MenuAction_End) {
delete menu;
}
}

public Action ShowTriggersLocations(int client, int args)
{
Menu menu = new Menu(TM_MenuHandler);

menu.SetTitle("trigger_multiple entities");

for (int i = 0; i < GetArraySize(g_hTMEntity); i++)
{
// Get entity
int entity = GetArrayCell(g_hTMEntity, i);

// Get targetname
char target_name[32];
GetEntPropString(entity, Prop_Data, "m_iName", target_name, sizeof(target_name));

menu.AddItem(target_name, target_name);
}

menu.Display(client, 30);
}

public int TM_MenuHandler(Menu menu, MenuAction action, int param1, int param2)
{
if (action == MenuAction_Select) {

int entity = GetArrayCell(g_hTMEntity, param2);

float position[3];
GetEntPropVector(entity, Prop_Send, "m_vecOrigin", position);

surftimer_SafeTeleport(param1, position, NULL_VECTOR, NULL_VECTOR, true);
} else if (action == MenuAction_End) {
delete menu;
}
}
20 changes: 20 additions & 0 deletions addons/sourcemod/scripting/surftimer/admin.sp
Original file line number Diff line number Diff line change
Expand Up @@ -638,3 +638,23 @@ public Action Admin_RefreshProfile(int client, int args)
}
return Plugin_Handled;
}

public Action Admin_ResetRecords(int client, int args)
{
if (args < 1)
{
ReplyToCommand(client, "%s Usage: sm_wipeplayer <steamid>", g_szChatPrefix);
return Plugin_Handled;
}
else
{
char szArg[32];
GetCmdArgString(szArg, sizeof(szArg));

StripQuotes(szArg);
TrimString(szArg);
PrintToChat(client, "Output test: %s", szArg);
db_WipePlayer(client, szArg);
}
return Plugin_Handled;
}
1 change: 1 addition & 0 deletions addons/sourcemod/scripting/surftimer/commands.sp
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ void CreateCommands()
// Delete records
RegAdminCmd("sm_deleterecords", Command_DeleteRecords, g_ZonerFlag, "[surftimer] [zoner] Delete records");
RegAdminCmd("sm_dr", Command_DeleteRecords, g_ZonerFlag, "[surftimer] [zoner] Delete records");
RegAdminCmd("sm_wipeplayer", Admin_ResetRecords, ADMFLAG_ROOT, "[surfTimer] Removes all database entries of the specific steamid - requires z flag");

// Setting Commands
RegConsoleCmd("sm_pre", Command_Prestrafe, "[surftimer] [settings] Toggles prestrafe messages for player");
Expand Down
5 changes: 5 additions & 0 deletions addons/sourcemod/scripting/surftimer/db/queries.sp
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,8 @@ char sql_setZoneNames[] = "UPDATE ck_zones SET zonename = '%s' WHERE mapname = '

char sql_MainEditQuery[] = "SELECT steamid, name, %s FROM %s where mapname='%s' and style='%i' %sORDER BY %s ASC LIMIT 50";
char sql_MainDeleteQeury[] = "DELETE From %s where mapname='%s' and style='%i' and steamid='%s' %s";

// ck_newmaps
char sql_createNewestMaps[] = "CREATE TABLE IF NOT EXISTS ck_newmaps (mapname VARCHAR(32), date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY(mapname)) DEFAULT CHARSET=utf8mb4;";
char sql_insertNewestMaps[] = "INSERT INTO ck_newmaps (mapname) VALUES('%s');";
char sql_selectNewestMaps[] = "SELECT mapname, date FROM ck_newmaps ORDER BY date DESC LIMIT 50";
4 changes: 0 additions & 4 deletions addons/sourcemod/scripting/surftimer/newmaps.sp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public int NewMapMenuHandler(Menu menu, MenuAction action, int param1, int param

public void db_ViewNewestMaps(int client)
{
char sql_selectNewestMaps[] = "SELECT mapname, date FROM ck_newmaps ORDER BY date DESC LIMIT 50";
SQL_TQuery(g_hDb, sql_selectNewestMapsCallback, sql_selectNewestMaps, client, DBPrio_Low);
}

Expand Down Expand Up @@ -72,7 +71,6 @@ public void sql_selectNewestMapsCallback(Handle owner, Handle hndl, const char[]

public void db_InsertNewestMaps()
{
char sql_insertNewestMaps[] = "INSERT INTO ck_newmaps (mapname) VALUES('%s');";
char szQuery[512];
Format(szQuery, 512, sql_insertNewestMaps, g_szMapName);
SQL_TQuery(g_hDb, SQL_CheckCallback, szQuery, DBPrio_Low);
Expand All @@ -92,8 +90,6 @@ public void db_present()

public void db_upgradeDbNewMap()
{
char sql_createNewestMaps[] = "CREATE TABLE IF NOT EXISTS ck_newmaps (mapname VARCHAR(32), date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY(mapname)) DEFAULT CHARSET=utf8mb4;";

Transaction createTableTnx = SQL_CreateTransaction();

SQL_AddQuery(createTableTnx, sql_createNewestMaps);
Expand Down
163 changes: 144 additions & 19 deletions addons/sourcemod/scripting/surftimer/sql.sp
Original file line number Diff line number Diff line change
Expand Up @@ -76,36 +76,76 @@ public void db_setupDatabase()

public void db_createTables()
{
Transaction createTableTnx = SQL_CreateTransaction();
Transaction tTransaction = new Transaction();

SQL_AddQuery(createTableTnx, sql_createPlayertmp);
SQL_AddQuery(createTableTnx, sql_createPlayertimes);
SQL_AddQuery(createTableTnx, sql_createPlayertimesIndex);
SQL_AddQuery(createTableTnx, sql_createPlayerRank);
SQL_AddQuery(createTableTnx, sql_createPlayerOptions);
SQL_AddQuery(createTableTnx, sql_createLatestRecords);
SQL_AddQuery(createTableTnx, sql_createBonus);
SQL_AddQuery(createTableTnx, sql_createBonusIndex);
SQL_AddQuery(createTableTnx, sql_createCheckpoints);
SQL_AddQuery(createTableTnx, sql_createZones);
SQL_AddQuery(createTableTnx, sql_createMapTier);
SQL_AddQuery(createTableTnx, sql_createSpawnLocations);
SQL_AddQuery(createTableTnx, sql_createAnnouncements);
SQL_AddQuery(createTableTnx, sql_createVipAdmins);
SQL_AddQuery(createTableTnx, sql_createWrcps);
tTransaction.AddQuery(sql_createPlayertmp, 1);
tTransaction.AddQuery(sql_createPlayertimes, 2);
tTransaction.AddQuery("SELECT COUNT(1) FROM INFORMATION_SCHEMA.STATISTICS WHERE table_schema=DATABASE() AND table_name='ck_playertimes' AND index_name='maprank';", 3);
tTransaction.AddQuery(sql_createPlayerRank, 4);
tTransaction.AddQuery(sql_createPlayerOptions, 5);
tTransaction.AddQuery(sql_createLatestRecords, 6);
tTransaction.AddQuery(sql_createBonus, 7);
tTransaction.AddQuery("SELECT COUNT(1) FROM INFORMATION_SCHEMA.STATISTICS WHERE table_schema=DATABASE() AND table_name='ck_bonus' AND index_name='bonusrank';", 8);
tTransaction.AddQuery(sql_createCheckpoints, 9);
tTransaction.AddQuery(sql_createZones, 10);
tTransaction.AddQuery(sql_createMapTier, 11);
tTransaction.AddQuery(sql_createSpawnLocations, 12);
tTransaction.AddQuery(sql_createAnnouncements, 13);
tTransaction.AddQuery(sql_createVipAdmins, 14);
tTransaction.AddQuery(sql_createWrcps, 15);
tTransaction.AddQuery(sql_createNewestMaps, 16);

SQL_ExecuteTransaction(g_hDb, createTableTnx, SQLTxn_CreateDatabaseSuccess, SQLTxn_CreateDatabaseFailed);
SQL_ExecuteTransaction(g_hDb, tTransaction, SQLTxn_CreateDatabaseSuccess, SQLTxn_CreateDatabaseFailed, DBPrio_High);

}

public void SQLTxn_CreateDatabaseSuccess(Handle db, any data, int numQueries, Handle[] results, any[] queryData)
public void SQLTxn_CreateDatabaseSuccess(Handle db, any data, int numQueries, DBResultSet[] results, any[] queryData)
{
PrintToServer("[SurfTimer] Database tables succesfully created!");

for (int i = 0; i < numQueries; i++)
{
if (queryData[i] == 3 || queryData[i] == 8)
{
if (results[i].HasResults && results[i].FetchRow())
{
if (results[i].FetchInt(0) == 0)
{
if (queryData[i] == 3)
{
SQL_TQuery(g_hDb, sqlcreatePlayertimesIndex, sql_createPlayertimesIndex, _, DBPrio_High);
}
else
{
SQL_TQuery(g_hDb, sqlcreateBonusIndex, sql_createBonusIndex, _, DBPrio_High);
}
}
}
}
}
}

public void sqlcreatePlayertimesIndex(Database db, DBResultSet results, const char[] error, any data)
{
if (db == null || (strlen(error) && StrContains(error, "Duplicate", false) == -1))
{
SetFailState("[SurfTimer] (sqlcreatePlayertimesIndex) Can't add playertimes index. Error: %s", error);
return;
}
}

public void sqlcreateBonusIndex(Database db, DBResultSet results, const char[] error, any data)
{
if (db == null || (strlen(error) && StrContains(error, "Duplicate", false) == -1))
{
SetFailState("[SurfTimer] (sqlcreateBonusIndex) Can't add bonus index. Error: %s", error);
return;
}
}

public void SQLTxn_CreateDatabaseFailed(Handle db, any data, int numQueries, const char[] error, int failIndex, any[] queryData)
{
SetFailState("[SurfTimer] Database tables could not be created! Error: %s", error);
SetFailState("[SurfTimer] Database tables could not be created! Error (Query: %d): %s", queryData[failIndex], error);
}

public void db_upgradeDatabase(int ver)
Expand Down Expand Up @@ -343,6 +383,91 @@ public int callback_Confirm(Menu menu, MenuAction action, int client, int key)
delete menu;
}

public void db_WipePlayer(int client, char szSteamID[32])
{
Transaction tTransaction = new Transaction();
char szQuery[256];

Format(szQuery, sizeof(szQuery), "DELETE FROM ck_playertimes WHERE steamid = \"%s\";", szSteamID);
tTransaction.AddQuery(szQuery, 1);
Format(szQuery, sizeof(szQuery), "DELETE FROM ck_bonus WHERE steamid = \"%s\";", szSteamID);
tTransaction.AddQuery(szQuery, 2);
Format(szQuery, sizeof(szQuery), "DELETE FROM ck_checkpoints WHERE steamid = \"%s\";", szSteamID);
tTransaction.AddQuery(szQuery, 3);
Format(szQuery, sizeof(szQuery), "DELETE FROM ck_playerrank WHERE steamid = \"%s\";", szSteamID);
tTransaction.AddQuery(szQuery, 4);
Format(szQuery, sizeof(szQuery), "DELETE FROM ck_wrcps WHERE steamid = \"%s\";", szSteamID);
tTransaction.AddQuery(szQuery, 5);
Format(szQuery, sizeof(szQuery), "DELETE FROM ck_playeroptions2 WHERE steamid = \"%s\";", szSteamID);
tTransaction.AddQuery(szQuery, 6);
Format(szQuery, sizeof(szQuery), "DELETE FROM ck_latestrecords WHERE steamid = \"%s\";", szSteamID);
tTransaction.AddQuery(szQuery, 7);
Format(szQuery, sizeof(szQuery), "DELETE FROM ck_playertemp WHERE steamid = \"%s\";", szSteamID);
tTransaction.AddQuery(szQuery, 8);

DataPack pack = new DataPack();
pack.WriteCell(GetClientUserId(client));
pack.WriteString(szSteamID);
SQL_ExecuteTransaction(g_hDb ,tTransaction, SQLTxn_WipePlayerSuccess, SQLTxn_WipePlayerFailed, pack, DBPrio_High);
}

public void SQLTxn_WipePlayerSuccess(Handle db, DataPack pack, int numQueries, Handle[] results, any[] queryData)
{
pack.Reset();

int client = GetClientOfUserId(pack.ReadCell());

char szSteamID[32];
pack.ReadString(szSteamID, sizeof(szSteamID));

delete pack;


if (IsValidClient(client))
{
PrintToChat(client, "Player %s has been wiped!", szSteamID);
PrintToConsole(client, "Player %s has been wiped!", szSteamID);
}

char sBuffer[32];

for(int i = 1; i <= MaxClients; i++)
{
if (!IsClientInGame(i))
continue;

GetClientAuthId(i, AuthId_Steam2, sBuffer, sizeof(sBuffer));
if (StrEqual(sBuffer, szSteamID, false))
{
g_bSettingsLoaded[client] = false;
g_bLoadingSettings[client] = true;
g_iSettingToLoad[client] = 0;
LoadClientSetting(client, g_iSettingToLoad[client]);
break;
}
}
}

public void SQLTxn_WipePlayerFailed(Handle db, DataPack pack, int numQueries, const char[] error, int failIndex, any[] queryData)
{
pack.Reset();

int client = GetClientOfUserId(pack.ReadCell());

char szSteamID[32];
pack.ReadString(szSteamID, sizeof(szSteamID));

delete pack;


LogError("[SurfTimer] Wipe of player %s failed! Error (Query: %d): %s", szSteamID, queryData[failIndex], error);

if (IsValidClient(client))
{
PrintToChat(client, "[SurfTimer] Wipe of player %s failed! Error (Query: %d): %s", szSteamID, queryData[failIndex], error);
PrintToConsole(client, "[SurfTimer] Wipe of player %s failed! Error (Query: %d): %s", szSteamID, queryData[failIndex], error);
}
}

/*==================================
= SPAWN LOCATION =
Expand Down

0 comments on commit ad18ac2

Please sign in to comment.