changed Database calls, changed timer accruacy, finally fixed escapednames
This commit is contained in:
parent
99389c2892
commit
b5d48eb5ab
@ -55,7 +55,6 @@ public void OnPluginStart()
|
||||
RegConsoleCmd("sm_stages", cmd_timerCheckStage, "Checking race stages");
|
||||
RegConsoleCmd("sm_hidetimer", cmd_hideTimerHUD, "Hides timer HUD");
|
||||
RegAdminCmd("sm_cleantime", Cmd_timeReset, ADMFLAG_GENERIC);
|
||||
RegAdminCmd("sm_devtime", Cmd_devtest, ADMFLAG_GENERIC);
|
||||
//hooks
|
||||
HookEvent("round_start", Event_RoundStart, EventHookMode_PostNoCopy);
|
||||
//HUD
|
||||
@ -74,15 +73,124 @@ public void OnPluginStart()
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public void OnMapStart()
|
||||
public void SQL_OnDatabaseConnect(Database db, const char[] error, any data)
|
||||
{
|
||||
//mysql placed here just in case somebody wants to reset database without having to reload plugin
|
||||
if(!db || strlen(error))
|
||||
{
|
||||
LogError("Database error: %s", error);
|
||||
return;
|
||||
}
|
||||
|
||||
g_dDatabase = db;
|
||||
|
||||
//create tables
|
||||
char sQuery[g_dLength];
|
||||
Format(sQuery, sizeof(sQuery), "CREATE TABLE IF NOT EXISTS `zetimer_table` (`steam_auth` VARCHAR(254) NOT NULL, `name` VARCHAR(254) NOT NULL, PRIMARY KEY (`steam_auth`))");
|
||||
g_dDatabase.Query(SQL_FinishedQuery, sQuery, _, DBPrio_High);
|
||||
|
||||
g_bDisplaySpecial = unloze_gBSpecialMapDisplay();
|
||||
SQL_StartConnection();
|
||||
GetCurrentMap(g_cMapname, sizeof(g_cMapname));
|
||||
CreateTimer(0.1, Timer_CountdownRace, INVALID_HANDLE, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
|
||||
startTimer();
|
||||
GetCurrentMap(g_cMapname, sizeof(g_cMapname));
|
||||
CreateTimer(0.05, Timer_CountdownRace, INVALID_HANDLE, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
|
||||
startTimer();
|
||||
//MYSQLCheckMapEntry();
|
||||
|
||||
}
|
||||
|
||||
public void SQL_OnQueryCompleted(Database db, DBResultSet results, const char[] error, any data)
|
||||
{
|
||||
if (!db || strlen(error))
|
||||
{
|
||||
LogError("Query error: %s", error);
|
||||
return;
|
||||
}
|
||||
int client;
|
||||
if ((client = GetClientFromSerial(data)) == 0)
|
||||
return;
|
||||
|
||||
if (results.RowCount && results.FetchRow())
|
||||
{
|
||||
playertime_leaving_zone[client] = results.FetchFloat(0);
|
||||
}
|
||||
}
|
||||
|
||||
public void SQL_OnFetchedTime(Database db, DBResultSet results, const char[] error, any data1)
|
||||
{
|
||||
if (!db || strlen(error))
|
||||
{
|
||||
LogError("Query error: %s", error);
|
||||
return;
|
||||
}
|
||||
DataPack data = view_as<DataPack>(data1);
|
||||
int client = data.ReadCell();
|
||||
if (client == 0)
|
||||
return;
|
||||
char sQuery[g_dLength];
|
||||
data.ReadString(sQuery, sizeof(sQuery));
|
||||
float l_fPlayerTime = data.ReadFloat();
|
||||
if (results.RowCount && results.FetchRow())
|
||||
{
|
||||
float oldtime = results.FetchFloat(0);
|
||||
bool update_time = l_fPlayerTime < oldtime ? true : false;
|
||||
if (!update_time)
|
||||
update_time = oldtime == 0.0 ? true : false;
|
||||
if (update_time)
|
||||
{
|
||||
//PrintToChatAll("sQuery: %s", sQuery);
|
||||
g_dDatabase.Query(SQL_FinishedQuery, sQuery, _, DBPrio_High);
|
||||
CPrintToChat(client, "Updated timer");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void SQL_OnQueryCompleted1(Database db, DBResultSet results, const char[] error, any data)
|
||||
{
|
||||
if (!db || strlen(error))
|
||||
{
|
||||
LogError("Query error: %s", error);
|
||||
return;
|
||||
}
|
||||
int l_iRaceCount;
|
||||
int l_iZoneCount = unloze_zoneCount();
|
||||
char sQuery[g_dLength];
|
||||
char l_cZoneIndexName[g_dIndex][g_dLength];
|
||||
if (results == null)
|
||||
{
|
||||
if (l_iZoneCount == 1)
|
||||
{
|
||||
Format(sQuery, sizeof(sQuery), "ALTER TABLE `zetimer_table` ADD COLUMN `%s` DECIMAL(8,7) NOT NULL DEFAULT 0.000000", g_cMapname);
|
||||
g_dDatabase.Query(SQL_FinishedQuery, sQuery, _, DBPrio_High);
|
||||
}
|
||||
else
|
||||
{
|
||||
//this might seem repetitive but one null check adds all required coloumns
|
||||
for (int iterator = 0; iterator <= l_iZoneCount; iterator++)
|
||||
{
|
||||
if (IsCorrectZone(iterator, l_cZoneIndexName[iterator][g_dLength -1], "ZONE_PREFIX_RACE"))
|
||||
{
|
||||
l_iRaceCount++;
|
||||
Format(sQuery, sizeof(sQuery), "ALTER TABLE `zetimer_table` ADD COLUMN `%sS%i` DECIMAL(8,7) NOT NULL DEFAULT 0.000000", g_cMapname, l_iRaceCount);
|
||||
g_dDatabase.Query(SQL_FinishedQuery, sQuery, _, DBPrio_High);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SQL_FinishedQuery(Database db, DBResultSet results, const char[] error, any data)
|
||||
{
|
||||
if (!db || strlen(error))
|
||||
{
|
||||
LogError("Query error: %s", error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnMapStart()
|
||||
{
|
||||
Database.Connect(SQL_OnDatabaseConnect, "racetimercss");
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
@ -120,14 +228,15 @@ public Action Timer_CountdownRace(Handle timer, any data)
|
||||
float l_milisecond = 0.0000;
|
||||
while (l_milisecond < 0.1000)
|
||||
{
|
||||
l_milisecond += 0.0001;
|
||||
g_fRoundSeconds += 0.0001;
|
||||
l_milisecond += 0.00001;
|
||||
g_fRoundSeconds += 0.00001;
|
||||
if (g_fRoundSeconds > 59.9999)
|
||||
{
|
||||
g_iRoundMinutes += 1;
|
||||
g_fRoundSeconds = 0.0000;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
@ -254,11 +363,6 @@ public Action OnPlayerRunCmd(int client, int &buttons, int &impulse, float vel[3
|
||||
float leftover_seconds = playertime_leaving_zone[client] - RoundToFloor(playertime_leaving_zone[client]);
|
||||
leftover_seconds = leftover_seconds * 100;
|
||||
int minutes = RoundToFloor(playertime_leaving_zone[client]);
|
||||
if (g_bDev[client])
|
||||
{
|
||||
//PrintToChat(client, "leftover_seconds: %f", leftover_seconds);
|
||||
//PrintToChat(client, "minutes: %i", minutes);
|
||||
}
|
||||
if (l_fCalculateSecs < 10.0)
|
||||
{
|
||||
if (leftover_seconds < 10.0)
|
||||
@ -311,8 +415,8 @@ public bool checkClientOrigin(float oldVals[3], float newVals[3], int client)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
float teleport_range = 100000.0;
|
||||
int velocityCap = 325;
|
||||
float teleport_range = 9000000.0;
|
||||
int velocityCap = 625;
|
||||
float distance = GetVectorDistance(oldVals, newVals, true);
|
||||
//PrintToChatAll("distance: %f", distance);
|
||||
bool bInAir = (GetEntPropEnt(client, Prop_Send, "m_hGroundEntity") == -1);
|
||||
@ -350,8 +454,11 @@ public void unloze_zoneEntry(int client, char[] zone)
|
||||
FinishedStageRaceZone(client);
|
||||
}
|
||||
}
|
||||
if (!g_bDev[client])
|
||||
g_bHumansAllowedTime[client] = false;
|
||||
else
|
||||
{
|
||||
PrintToChat(client, "You are not authorized with steam!!");
|
||||
}
|
||||
g_bHumansAllowedTime[client] = false;
|
||||
}
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
@ -506,7 +613,6 @@ public float CalculateValues(int client)
|
||||
|
||||
public void mysql_get_player_time(int client, int stage)
|
||||
{
|
||||
DBResultSet rs;
|
||||
char query[g_dLength];
|
||||
char steam_auth[g_dIndex];
|
||||
GetClientAuthId(client, AuthId_Steam2, steam_auth, sizeof(steam_auth));
|
||||
@ -514,20 +620,7 @@ public void mysql_get_player_time(int client, int stage)
|
||||
Format(query, sizeof(query), "SELECT `%s` FROM `zetimer_table` where steam_auth = '%s'", g_cMapname, steam_auth);
|
||||
else
|
||||
Format(query, sizeof(query), "SELECT `%sS%i` FROM `zetimer_table` where steam_auth = '%s'", g_cMapname, stage, steam_auth);
|
||||
if ((rs = SQL_Query(g_dDatabase, query)) == null)
|
||||
{
|
||||
delete rs;
|
||||
return;
|
||||
}
|
||||
rs.FetchRow();
|
||||
if (rs.RowCount > 0)
|
||||
playertime_leaving_zone[client] = rs.FetchFloat(0);
|
||||
if (g_bDev[client])
|
||||
{
|
||||
PrintToChat(client, "query: %s", query);
|
||||
PrintToChat(client, "playertime_leaving_zone[client]: %f", playertime_leaving_zone[client]);
|
||||
}
|
||||
delete rs;
|
||||
g_dDatabase.Query(SQL_OnQueryCompleted, query, GetClientSerial(client));
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
@ -542,7 +635,7 @@ public void MYSQLCheckMapEntry()
|
||||
if (l_iZoneCount < 2)
|
||||
{
|
||||
Format(sQuery, sizeof(sQuery), "SELECT `%s` FROM `zetimer_table` LIMIT 1", g_cMapname);
|
||||
SQL_TQuery(g_dDatabase, TqueryThreadCallback, sQuery);
|
||||
g_dDatabase.Query(SQL_OnQueryCompleted1, sQuery, _);
|
||||
}
|
||||
else
|
||||
for (int iterator = 0; iterator <= l_iZoneCount; iterator++)
|
||||
@ -551,42 +644,11 @@ public void MYSQLCheckMapEntry()
|
||||
{
|
||||
l_iRaceCount++;
|
||||
Format(sQuery, sizeof(sQuery), "SELECT `%sS%i` FROM `zetimer_table` LIMIT 1", g_cMapname, l_iRaceCount);
|
||||
SQL_TQuery(g_dDatabase, TqueryThreadCallback, sQuery);
|
||||
g_dDatabase.Query(SQL_OnQueryCompleted1, sQuery, _);
|
||||
}
|
||||
}
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public void TqueryThreadCallback(Handle owner, Handle rs, const char[] error, any data)
|
||||
{
|
||||
int l_iRaceCount;
|
||||
int l_iZoneCount = unloze_zoneCount();
|
||||
char sQuery[g_dLength];
|
||||
char l_cZoneIndexName[g_dIndex][g_dLength];
|
||||
if (rs == null)
|
||||
{
|
||||
if (l_iZoneCount == 1)
|
||||
{
|
||||
Format(sQuery, sizeof(sQuery), "ALTER TABLE `zetimer_table` ADD COLUMN `%s` DECIMAL(8,7) NOT NULL DEFAULT 0.000000", g_cMapname);
|
||||
SQL_FastQuery(g_dDatabase, sQuery);
|
||||
}
|
||||
else
|
||||
{
|
||||
//this might seem repetitive but one null check adds all required coloumns
|
||||
for (int iterator = 0; iterator <= l_iZoneCount; iterator++)
|
||||
{
|
||||
if (IsCorrectZone(iterator, l_cZoneIndexName[iterator][g_dLength -1], "ZONE_PREFIX_RACE"))
|
||||
{
|
||||
l_iRaceCount++;
|
||||
Format(sQuery, sizeof(sQuery), "ALTER TABLE `zetimer_table` ADD COLUMN `%sS%i` DECIMAL(8,7) NOT NULL DEFAULT 0.000000", g_cMapname, l_iRaceCount);
|
||||
SQL_FastQuery(g_dDatabase, sQuery);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose: TODO implement if needed
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public int GetTotalRaceZones()
|
||||
@ -610,89 +672,40 @@ public void sendMYSQL(int client, int minutes, float seconds, int stage)
|
||||
int l_iZoneCount = unloze_zoneCount();
|
||||
float l_fPlayerTime = float(minutes);
|
||||
char sSID[g_dIndex];
|
||||
char l_cClientName[g_dIndex];
|
||||
char sQuery[g_dLength];
|
||||
char sQuery2[g_dLength];
|
||||
char sQuery[g_dLength];
|
||||
char sName[MAX_NAME_LENGTH];
|
||||
GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID));
|
||||
GetClientName(client, sName, sizeof(sName));
|
||||
int size2 = 2 * strlen(sName) + 1;
|
||||
char[] sEscapedName = new char[size2 + 1];
|
||||
SQL_EscapeString(g_dDatabase, sName, sEscapedName, size2 + 1);
|
||||
Format(l_cClientName, sizeof(l_cClientName), sEscapedName);
|
||||
//STEAM_ID_STOP_IGNORING_RETVALS might be considered exploit?
|
||||
|
||||
g_dDatabase.Escape(sName, sEscapedName, size2 + 1);
|
||||
|
||||
if (StrEqual(sSID, "STEAM_ID_STOP_IGNORING_RETVALS") || StrEqual(sSID, "STEAM_ID_PENDING"))
|
||||
{
|
||||
PrintToChat(client, "Your steam ID is not working, not updating timer");
|
||||
return;
|
||||
}
|
||||
l_fPlayerTime = l_fPlayerTime + (seconds / 100);
|
||||
if (l_iZoneCount < 2)
|
||||
{
|
||||
Format(sQuery2, sizeof(sQuery2), "SELECT %s FROM unloze_racetimer_css.zetimer_table zt where steam_auth = '%s'", g_cMapname, sSID);
|
||||
Format(sQuery, sizeof(sQuery), "INSERT INTO `zetimer_table` (`steam_auth`, `name`, `%s`) VALUES ('%s', '%s', '%f') ON DUPLICATE KEY UPDATE `name` = '%s', `%s` = '%f'", g_cMapname, sSID, l_cClientName, l_fPlayerTime, l_cClientName, g_cMapname, l_fPlayerTime);
|
||||
Format(sQuery, sizeof(sQuery), "INSERT INTO `zetimer_table` (`steam_auth`, `name`, `%s`) VALUES ('%s', '%s', '%f') ON DUPLICATE KEY UPDATE `name` = '%s', `%s` = '%f'", g_cMapname, sSID, sEscapedName, l_fPlayerTime, sEscapedName, g_cMapname, l_fPlayerTime);
|
||||
}
|
||||
else
|
||||
{
|
||||
Format(sQuery2, sizeof(sQuery2), "SELECT %sS%i FROM unloze_racetimer_css.zetimer_table zt where steam_auth = '%s'", g_cMapname, stage, sSID);
|
||||
Format(sQuery, sizeof(sQuery), "INSERT INTO `zetimer_table` (`steam_auth`, `name`, `%sS%i`) VALUES ('%s', '%s', '%f') ON DUPLICATE KEY UPDATE `name` = '%s', `%sS%i` = '%f'", g_cMapname, stage, sSID, l_cClientName, l_fPlayerTime, l_cClientName, g_cMapname, stage, l_fPlayerTime);
|
||||
Format(sQuery, sizeof(sQuery), "INSERT INTO `zetimer_table` (`steam_auth`, `name`, `%sS%i`) VALUES ('%s', '%s', '%f') ON DUPLICATE KEY UPDATE `name` = '%s', `%sS%i` = '%f'", g_cMapname, stage, sSID, sEscapedName, l_fPlayerTime, sEscapedName, g_cMapname, stage, l_fPlayerTime);
|
||||
}
|
||||
DBResultSet rs;
|
||||
if ((rs = SQL_Query(g_dDatabase, sQuery2)) == null)
|
||||
{
|
||||
delete rs;
|
||||
return;
|
||||
}
|
||||
rs.FetchRow();
|
||||
if (!rs.RowCount)
|
||||
{
|
||||
delete rs;
|
||||
return;
|
||||
}
|
||||
float oldtime = rs.FetchFloat(0);
|
||||
bool update_time = l_fPlayerTime < oldtime ? true : false;
|
||||
if (!update_time)
|
||||
update_time = oldtime == 0.0 ? true : false;
|
||||
delete rs;
|
||||
if (g_bDev[client])
|
||||
{
|
||||
PrintToChat(client, "sQuery: %s", sQuery);
|
||||
PrintToChat(client, "sQuery2: %s", sQuery2);
|
||||
PrintToChat(client, "update_time: %i", update_time);
|
||||
PrintToChat(client, "l_fPlayerTime: %f", l_fPlayerTime);
|
||||
PrintToChat(client, "oldtime: %f", oldtime);
|
||||
return;
|
||||
}
|
||||
if (update_time)
|
||||
{
|
||||
SQL_TQuery(g_dDatabase, DummyCallbackSimple, sQuery);
|
||||
CPrintToChat(client, "Updated timer");
|
||||
}
|
||||
//PrintToChatAll("SEND MYSQL sQuery: %s", sQuery);
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public void SQL_StartConnection()
|
||||
{
|
||||
char error[g_dLength];
|
||||
if (SQL_CheckConfig("racetimercss"))
|
||||
g_dDatabase = SQL_Connect("racetimercss", true, error, sizeof(error));
|
||||
if (g_dDatabase == null)
|
||||
{
|
||||
CPrintToChatAll("{green}[UNLOZE] {white}Error! Could not connect to MYSQL-DB!");
|
||||
}
|
||||
//create tables
|
||||
char sQuery[g_dLength];
|
||||
Format(sQuery, sizeof(sQuery), "CREATE TABLE IF NOT EXISTS `zetimer_table` (`steam_auth` VARCHAR(254) NOT NULL, `name` VARCHAR(254) NOT NULL, PRIMARY KEY (`steam_auth`))");
|
||||
SQL_TQuery(g_dDatabase, DummyCallbackSimple, sQuery);
|
||||
MYSQLCheckMapEntry();
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public void DummyCallbackSimple(Handle hOwner, Handle hChild, const char[] err, DataPack pack1)
|
||||
{
|
||||
if (hOwner == null || hChild == null)
|
||||
LogError("Query error. (%s)", err);
|
||||
DataPack pack = new DataPack();
|
||||
pack.WriteCell(client);
|
||||
pack.WriteString(sQuery);
|
||||
pack.WriteFloat(l_fPlayerTime);
|
||||
pack.Reset();
|
||||
g_dDatabase.Query(SQL_OnFetchedTime, sQuery2, pack);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
@ -724,46 +737,47 @@ public void CheckTop(int client, int index, int autismstate)
|
||||
Format(sQuery, sizeof(sQuery), "SELECT name, %s FROM `zetimer_table` WHERE %s > 0.000 ORDER BY %s ASC LIMIT 10", g_cMapname, g_cMapname, g_cMapname);
|
||||
else
|
||||
Format(sQuery, sizeof(sQuery), "SELECT name, `%sS%i` FROM `zetimer_table` WHERE `%sS%i` > 0.000 ORDER BY `%sS%i` ASC LIMIT 10", g_cMapname, index, g_cMapname, index, g_cMapname, index);
|
||||
SQL_TQuery(g_dDatabase, SQL_SelectTop_Callback, sQuery, GetClientUserId(client));
|
||||
g_dDatabase.Query(SQL_Select_Top_Callback, sQuery, GetClientSerial(client));
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public void SQL_SelectTop_Callback(Handle db, Handle results, const char[] error, any data)
|
||||
|
||||
public void SQL_Select_Top_Callback(Database db, DBResultSet results, const char[] error, any data)
|
||||
{
|
||||
int iclient = GetClientOfUserId(data);
|
||||
int l_iMinutes;
|
||||
int l_iPosition;
|
||||
float l_fRecord;
|
||||
float l_iSeconds;
|
||||
//Player Name
|
||||
char[] g_cPlayerName = new char[MAX_NAME_LENGTH];
|
||||
char g_cContent[g_dLength];
|
||||
if (iclient == 0)
|
||||
{
|
||||
if(!db || strlen(error))
|
||||
{
|
||||
LogError("Database error: %s", error);
|
||||
return;
|
||||
}
|
||||
int iclient;
|
||||
if ((iclient = GetClientFromSerial(data)) == 0)
|
||||
return;
|
||||
}
|
||||
Menu menu = new Menu(MenuHandler1);
|
||||
menu.SetTitle("Maptimer: %s", g_cMapname);
|
||||
if (results != INVALID_HANDLE)
|
||||
{
|
||||
while (SQL_GetRowCount(results) > 0 && SQL_FetchRow(results))
|
||||
{
|
||||
l_iPosition++;
|
||||
SQL_FetchString(results, 0, g_cPlayerName, MAX_NAME_LENGTH);
|
||||
l_fRecord = SQL_FetchFloat(results, 1);
|
||||
l_iMinutes = RoundToFloor(l_fRecord);
|
||||
l_iSeconds = (l_fRecord - l_iMinutes) * 100;
|
||||
Format(g_cContent, sizeof(g_cContent), "#%i: Time: 0%i:%.4f - %s", l_iPosition, l_iMinutes, l_iSeconds, g_cPlayerName);
|
||||
menu.AddItem("-1", g_cContent, ITEMDRAW_DISABLED);
|
||||
}
|
||||
int l_iMinutes;
|
||||
int l_iPosition;
|
||||
float l_fRecord;
|
||||
float l_iSeconds;
|
||||
//Player Name
|
||||
char[] g_cPlayerName = new char[MAX_NAME_LENGTH];
|
||||
char g_cContent[g_dLength];
|
||||
Menu menu = new Menu(MenuHandler1);
|
||||
menu.SetTitle("Maptimer: %s", g_cMapname);
|
||||
if (results != INVALID_HANDLE)
|
||||
{
|
||||
while (results.RowCount > 0 && results.FetchRow())
|
||||
{
|
||||
l_iPosition++;
|
||||
results.FetchString(0, g_cPlayerName, MAX_NAME_LENGTH);
|
||||
l_fRecord = results.FetchFloat(1);
|
||||
l_iMinutes = RoundToFloor(l_fRecord);
|
||||
l_iSeconds = (l_fRecord - l_iMinutes) * 100;
|
||||
Format(g_cContent, sizeof(g_cContent), "#%i: Time: 0%i:%.4f - %s", l_iPosition, l_iMinutes, l_iSeconds, g_cPlayerName);
|
||||
menu.AddItem("-1", g_cContent, ITEMDRAW_DISABLED);
|
||||
}
|
||||
if (!l_iPosition)
|
||||
{
|
||||
menu.AddItem("-1", "No results. Commands: !toptime !stages", ITEMDRAW_DISABLED);
|
||||
}
|
||||
menu.ExitButton = true;
|
||||
menu.Display(iclient, 0);
|
||||
}
|
||||
{
|
||||
menu.AddItem("-1", "No results. Commands: !toptime !stages", ITEMDRAW_DISABLED);
|
||||
}
|
||||
menu.ExitButton = true;
|
||||
menu.Display(iclient, 0);
|
||||
}
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
@ -778,17 +792,6 @@ public int MenuHandler1(Menu menu, MenuAction action, int param1, int param2)
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public Action Cmd_devtest(int client, int args)
|
||||
{
|
||||
if (!IsValidClient(client))
|
||||
return Plugin_Handled;
|
||||
g_bDev[client] = !g_bDev[client];
|
||||
PrintToChat(client, "dev mode: %i", g_bDev[client]);
|
||||
return Plugin_Handled;
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public Action Cmd_timeReset(int client, int args)
|
||||
{
|
||||
if (!IsValidClient(client))
|
||||
@ -922,10 +925,10 @@ public void deleteClientTime(char[] steam2, int stage)
|
||||
else
|
||||
{
|
||||
Format(l_cQuery, sizeof(l_cQuery), "UPDATE `zetimer_table` SET `%s` = 0.000 WHERE steam_auth = '%s'", g_cMapname, steam2);
|
||||
SQL_TQuery(g_dDatabase, DummyCallbackSimple, l_cQuery);
|
||||
g_dDatabase.Query(SQL_FinishedQuery, l_cQuery, _, DBPrio_High);
|
||||
Format(l_cQuery, sizeof(l_cQuery), "UPDATE `zetimer_table` SET `%sS1` = 0.000 WHERE steam_auth = '%s'", g_cMapname, steam2);
|
||||
}
|
||||
SQL_TQuery(g_dDatabase, DummyCallbackSimple, l_cQuery);
|
||||
g_dDatabase.Query(SQL_FinishedQuery, l_cQuery, _, DBPrio_High);
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
@ -944,7 +947,7 @@ public void Checkself(int client)
|
||||
if (l_iZoneCount < 2)
|
||||
{
|
||||
Format(l_cQuery, sizeof(l_cQuery), "SELECT name, `%s` FROM `zetimer_table` WHERE steam_auth = '%s'", g_cMapname, l_cSID);
|
||||
SQL_TQuery(g_dDatabase, TqueryCheckSelf, l_cQuery, GetClientUserId(client));
|
||||
g_dDatabase.Query(SQL_CheckSelf, l_cQuery, GetClientSerial(client));
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -960,38 +963,44 @@ public void CheckStageSelf(int client, int selection)
|
||||
char l_cSID[g_dIndex];
|
||||
GetClientAuthId(client, AuthId_Steam2, l_cSID, sizeof(l_cSID));
|
||||
Format(l_cQuery, sizeof(l_cQuery), "SELECT name, `%sS%i` FROM `zetimer_table` WHERE steam_auth = '%s'", g_cMapname, selection, l_cSID);
|
||||
SQL_TQuery(g_dDatabase, TqueryCheckSelf, l_cQuery, GetClientUserId(client));
|
||||
g_dDatabase.Query(SQL_CheckSelf, l_cQuery, GetClientSerial(client));
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public void TqueryCheckSelf(Handle db, Handle rs, const char[] error, any data)
|
||||
public void SQL_CheckSelf(Database db, DBResultSet results, const char[] error, any data)
|
||||
{
|
||||
if(!db || strlen(error))
|
||||
{
|
||||
LogError("Database error: %s", error);
|
||||
return;
|
||||
}
|
||||
int l_iMinutes;
|
||||
float l_fRecord;
|
||||
float l_iSeconds;
|
||||
char l_cMessageContent[g_dLength];
|
||||
char[] l_cPlayerName = new char[MAX_NAME_LENGTH];
|
||||
int iclient;
|
||||
if ((iclient = GetClientOfUserId(data)) == 0)
|
||||
float l_fRecord;
|
||||
float l_iSeconds;
|
||||
char l_cMessageContent[g_dLength];
|
||||
char[] l_cPlayerName = new char[MAX_NAME_LENGTH];
|
||||
int iclient;
|
||||
if ((iclient = GetClientFromSerial(data)) == 0)
|
||||
return;
|
||||
if (SQL_GetRowCount(rs) > 0 && SQL_FetchRow(rs))
|
||||
if (results.RowCount && results.FetchRow())
|
||||
{
|
||||
SQL_FetchString(rs, 0, l_cPlayerName, MAX_NAME_LENGTH);
|
||||
l_fRecord = SQL_FetchFloat(rs, 1);
|
||||
results.FetchString(0, l_cPlayerName, MAX_NAME_LENGTH);
|
||||
l_fRecord = results.FetchFloat(1);
|
||||
if (l_fRecord == 0.000)
|
||||
{
|
||||
CPrintToChat(iclient, "You have no time yet!");
|
||||
return;
|
||||
}
|
||||
l_iMinutes = RoundToFloor(l_fRecord);
|
||||
l_iSeconds = (l_fRecord - l_iMinutes) * 100;
|
||||
Format(l_cMessageContent, sizeof(l_cMessageContent), "%i:%.4f - %s", l_iMinutes, l_iSeconds, l_cPlayerName);
|
||||
CPrintToChat(iclient, "Your best time: 0%s", l_cMessageContent);
|
||||
{
|
||||
CPrintToChat(iclient, "You have no time yet!");
|
||||
return;
|
||||
}
|
||||
l_iMinutes = RoundToFloor(l_fRecord);
|
||||
l_iSeconds = (l_fRecord - l_iMinutes) * 100;
|
||||
Format(l_cMessageContent, sizeof(l_cMessageContent), "%i:%.4f - %s", l_iMinutes, l_iSeconds, l_cPlayerName);
|
||||
CPrintToChat(iclient, "Your best time: 0%s", l_cMessageContent);
|
||||
}
|
||||
else
|
||||
CPrintToChat(iclient, "You have no time yet!");
|
||||
CPrintToChat(iclient, "You have no time yet!");
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
@ -1002,4 +1011,4 @@ stock bool IsValidClient(int client)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user