added squery logs, removed methods, changed alter table, fixed some qoutes probably, changed some checking with mysql
This commit is contained in:
parent
a3f69e7719
commit
63fa29c720
@ -42,10 +42,6 @@ public Plugin myinfo =
|
||||
url = "www.unloze.com"
|
||||
};
|
||||
|
||||
public void OnConfigsExecuted()
|
||||
{
|
||||
Database.Connect(SQL_OnDatabaseConnect, "racetimercss");
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
@ -107,15 +103,20 @@ public void SQL_OnConnectFinished(Database db, DBResultSet results, const char[]
|
||||
OnClientPostAdminCheck(i);
|
||||
}
|
||||
|
||||
public void SQL_OnQueryCompleted(Database db, DBResultSet results, const char[] error, any data)
|
||||
public void SQL_OnQueryCompleted(Database db, DBResultSet results, const char[] error, DataPack data)
|
||||
{
|
||||
ResetPack(data);
|
||||
int client_serial = data.ReadCell();
|
||||
if (!db || strlen(error))
|
||||
{
|
||||
LogError("Query error: %s", error);
|
||||
{
|
||||
char sQuery[g_dLength];
|
||||
data.ReadString(sQuery, sizeof(sQuery));
|
||||
LogError("Query error 1: %s", error);
|
||||
LogError("actual query: %s", sQuery);
|
||||
return;
|
||||
}
|
||||
}
|
||||
int client;
|
||||
if ((client = GetClientFromSerial(data)) == 0)
|
||||
if ((client = GetClientFromSerial(client_serial)) == 0)
|
||||
return;
|
||||
if (results.RowCount && results.FetchRow())
|
||||
results.FetchString(0, g_csTime_record[client], sizeof(g_csTime_record));
|
||||
@ -127,70 +128,39 @@ public void MYSQLCheckMapEntry()
|
||||
int l_iZoneCount = unloze_zoneCount();
|
||||
char sQuery[g_dLength];
|
||||
char l_cZoneIndexName[g_dIndex][g_dLength];
|
||||
if (l_iZoneCount < 2)
|
||||
{
|
||||
Format(sQuery, sizeof(sQuery), "SELECT `%s` FROM `zetimer_table` LIMIT 1", g_cMapname);
|
||||
g_dDatabase.Query(SQL_OnQueryCompleted1, sQuery, _);
|
||||
}
|
||||
else
|
||||
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), "SELECT `%sS%i` FROM `zetimer_table` LIMIT 1", g_cMapname, l_iRaceCount);
|
||||
g_dDatabase.Query(SQL_OnQueryCompleted1, sQuery, _);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SQL_OnQueryCompleted1(Database db, DBResultSet results, const char[] error, any data)
|
||||
{
|
||||
if (!db)
|
||||
{
|
||||
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` VARCHAR(256) DEFAULT '0.000' NOT NULL", g_cMapname);
|
||||
g_dDatabase.Query(SQL_FinishedQuery_mute_error, 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` VARCHAR(256) DEFAULT '0.000' NOT NULL", g_cMapname, l_iRaceCount);
|
||||
g_dDatabase.Query(SQL_FinishedQuery_mute_error, sQuery, _, DBPrio_High);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SQL_FinishedQuery(Database db, DBResultSet results, const char[] error, any data)
|
||||
{
|
||||
if (!db || strlen(error))
|
||||
if (l_iZoneCount == 1)
|
||||
{
|
||||
LogError("Query error: %s", error);
|
||||
return;
|
||||
Format(sQuery, sizeof(sQuery), "ALTER TABLE `zetimer_table` ADD COLUMN IF NOT EXISTS `%s` VARCHAR(256) DEFAULT '0.000' NOT NULL", g_cMapname);
|
||||
DataPack hDataPack = new DataPack();
|
||||
hDataPack.WriteString(sQuery);
|
||||
g_dDatabase.Query(SQL_FinishedQuery, sQuery, hDataPack, DBPrio_High);
|
||||
}
|
||||
else
|
||||
{
|
||||
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 IF NOT EXISTS `%sS%i` VARCHAR(256) DEFAULT '0.000' NOT NULL", g_cMapname, l_iRaceCount);
|
||||
DataPack hDataPack = new DataPack();
|
||||
hDataPack.WriteString(sQuery);
|
||||
g_dDatabase.Query(SQL_FinishedQuery, sQuery, hDataPack, DBPrio_High);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SQL_FinishedQuery_mute_error(Database db, DBResultSet results, const char[] error, any data)
|
||||
public void SQL_FinishedQuery(Database db, DBResultSet results, const char[] error, DataPack data)
|
||||
{
|
||||
if (!db)
|
||||
return;
|
||||
if (!db || strlen(error))
|
||||
{
|
||||
char sQuery[g_dLength];
|
||||
ResetPack(data);
|
||||
data.ReadString(sQuery, sizeof(sQuery));
|
||||
LogError("Query error 3: %s", error);
|
||||
LogError("actual query: %s", sQuery);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnMapStart()
|
||||
@ -204,7 +174,7 @@ public void OnMapStart()
|
||||
GetConVarString(hHostName, line, sizeof(line));
|
||||
if (StrContains(line, "EVENT", false) > -1)
|
||||
g_bEventBool = true;
|
||||
AutoExecConfig();
|
||||
Database.Connect(SQL_OnDatabaseConnect, "racetimercss");
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
@ -264,6 +234,7 @@ public void Event_RoundStart(Handle event, const char[] name, bool dontBroadcast
|
||||
public void OnClientPostAdminCheck(int client)
|
||||
{
|
||||
resetClient(client);
|
||||
insertPlayerMYSQL(client);
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
@ -307,7 +278,6 @@ public void OnPlayerRunCmdPost(int client, int buttons, int impulse, const float
|
||||
g_bHumansAllowedTime[client] = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (g_bHumansAllowedTime[client] && (GetClientTeam(client) == CS_TEAM_CT) && IsPlayerAlive(client))
|
||||
{
|
||||
int frameCap = 11;
|
||||
@ -539,28 +509,50 @@ public int RetrieveZoneIndex(char[] zone)
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public void FinishedStageRaceZone(int client)
|
||||
{
|
||||
char sSID[g_dIndex];
|
||||
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];
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
int l_iZoneCount = unloze_zoneCount();
|
||||
char record_client[32];
|
||||
Format(record_client, sizeof(record_client), g_csTime_record[client]);
|
||||
float client_time = client_current_race_time(client);
|
||||
char sTime[32];
|
||||
FormatPlayerTime(client_time, sTime, sizeof(sTime), false, 1);
|
||||
float old_record = StringToFloat(record_client);
|
||||
float new_time = StringToFloat(sTime);
|
||||
|
||||
if (l_iZoneCount > 1)
|
||||
CPrintToChat(client, "{green}[UNLOZE] Stage: %i", player_stage[client]);
|
||||
CPrintToChat(client, "{green}[UNLOZE] Client: %N Time: %s", client, sTime);
|
||||
int stage = player_stage[client];
|
||||
char sQuery[g_dLength];
|
||||
if (l_iZoneCount < 2)
|
||||
Format(sQuery, sizeof(sQuery), "UPDATE `zetimer_table` SET `%s` = %s, name = '%s' WHERE steam_auth = '%s' and LENGTH(`%s`) >= LENGTH(%s) and STRCMP(`%s`, %s) > 0", g_cMapname, sTime, sEscapedName, sSID, g_cMapname, sTime, g_cMapname, sTime);
|
||||
else
|
||||
Format(sQuery, sizeof(sQuery), "UPDATE `zetimer_table` SET `%sS%i` = %s, name = '%s' WHERE steam_auth = '%s' and LENGTH(`%sS%i`) >= LENGTH(%s) and STRCMP(`%sS%i`, %s) > 0", g_cMapname, stage, sTime, sEscapedName, sSID, g_cMapname, stage, sTime, g_cMapname, stage, sTime);
|
||||
|
||||
if (old_record == 0.0)
|
||||
if (StrEqual(record_client, "0.000"))
|
||||
{
|
||||
CPrintToChat(client, "Your record: None yet\nCommand: !toptime !mytime !stages");
|
||||
sendMYSQL(client, sTime, player_stage[client]);
|
||||
return;
|
||||
if (l_iZoneCount < 2)
|
||||
Format(sQuery, sizeof(sQuery), "UPDATE `zetimer_table` SET `%s` = %s, name = '%s' WHERE steam_auth = '%s'", g_cMapname, sTime, sEscapedName, sSID);
|
||||
else
|
||||
Format(sQuery, sizeof(sQuery), "UPDATE `zetimer_table` SET `%sS%i` = %s, name = '%s' WHERE steam_auth = '%s'", g_cMapname, stage, sTime, sEscapedName, sSID);
|
||||
}
|
||||
CPrintToChat(client, "Your record: %s\nCommand: !toptime !mytime !stages", record_client);
|
||||
if (new_time < old_record)
|
||||
sendMYSQL(client, sTime, player_stage[client]);
|
||||
else
|
||||
CPrintToChat(client, "Your record: %s\nCommand: !toptime !mytime !stages", record_client);
|
||||
DataPack hDataPack = new DataPack();
|
||||
hDataPack.WriteString(sQuery);
|
||||
g_dDatabase.Query(SQL_FinishedQuery, sQuery, hDataPack, DBPrio_High);
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
@ -574,7 +566,10 @@ 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);
|
||||
g_dDatabase.Query(SQL_OnQueryCompleted, query, GetClientSerial(client));
|
||||
DataPack hDataPack = new DataPack();
|
||||
hDataPack.WriteCell(GetClientSerial(client));
|
||||
hDataPack.WriteString(query);
|
||||
g_dDatabase.Query(SQL_OnQueryCompleted, query, hDataPack);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
@ -596,34 +591,27 @@ public int GetTotalRaceZones()
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public void sendMYSQL(int client, char[] sTime, int stage)
|
||||
public void insertPlayerMYSQL(int client)
|
||||
{
|
||||
int l_iZoneCount = unloze_zoneCount();
|
||||
char sSID[g_dIndex];
|
||||
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];
|
||||
|
||||
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");
|
||||
if (!IsValidClient(client))
|
||||
return;
|
||||
}
|
||||
if (l_iZoneCount < 2)
|
||||
{
|
||||
Format(sQuery, sizeof(sQuery), "INSERT INTO `zetimer_table` (`steam_auth`, `name`, `%s`) VALUES ('%s', '%s', '%s') ON DUPLICATE KEY UPDATE `name` = '%s', `%s` = '%s'", g_cMapname, sSID, sEscapedName, sTime, sEscapedName, g_cMapname, sTime);
|
||||
}
|
||||
else
|
||||
{
|
||||
Format(sQuery, sizeof(sQuery), "INSERT INTO `zetimer_table` (`steam_auth`, `name`, `%sS%i`) VALUES ('%s', '%s', '%s') ON DUPLICATE KEY UPDATE `name` = '%s', `%sS%i` = '%s'", g_cMapname, stage, sSID, sEscapedName, sTime, sEscapedName, g_cMapname, stage, sTime);
|
||||
}
|
||||
g_dDatabase.Query(SQL_FinishedQuery, sQuery, _, DBPrio_High);
|
||||
CPrintToChat(client, "Updated timer");
|
||||
char sSID[g_dIndex];
|
||||
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];
|
||||
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;
|
||||
}
|
||||
Format(sQuery, sizeof(sQuery), "INSERT INTO `zetimer_table` (`steam_auth`, `name`) VALUES ('%s', '%s') ON DUPLICATE KEY UPDATE `name` = '%s'", sSID, sEscapedName, sEscapedName);
|
||||
DataPack hDataPack = new DataPack();
|
||||
hDataPack.WriteString(sQuery);
|
||||
g_dDatabase.Query(SQL_FinishedQuery, sQuery, hDataPack, DBPrio_High);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
@ -657,18 +645,27 @@ 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 LENGTH(`%s`) ASC, `%s` ASC LIMIT 10", g_cMapname, 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 LENGTH(`%sS%i`) ASC, `%sS%i` ASC LIMIT 10", g_cMapname, index, g_cMapname, index, g_cMapname, index, g_cMapname, index);
|
||||
g_dDatabase.Query(SQL_Select_Top_Callback, sQuery, GetClientSerial(client));
|
||||
DataPack hDataPack = new DataPack();
|
||||
hDataPack.WriteCell(GetClientSerial(client));
|
||||
hDataPack.WriteString(sQuery);
|
||||
g_dDatabase.Query(SQL_Select_Top_Callback, sQuery, hDataPack);
|
||||
}
|
||||
|
||||
public void SQL_Select_Top_Callback(Database db, DBResultSet results, const char[] error, any data)
|
||||
public void SQL_Select_Top_Callback(Database db, DBResultSet results, const char[] error, DataPack data)
|
||||
{
|
||||
if(!db || strlen(error))
|
||||
ResetPack(data);
|
||||
int client_serial = data.ReadCell();
|
||||
if (!db || strlen(error))
|
||||
{
|
||||
LogError("Database error: %s", error);
|
||||
return;
|
||||
char sQuery[g_dLength];
|
||||
data.ReadString(sQuery, sizeof(sQuery));
|
||||
LogError("Query error 2: %s", error);
|
||||
LogError("actual query: %s", sQuery);
|
||||
return;
|
||||
}
|
||||
|
||||
int iclient;
|
||||
if ((iclient = GetClientFromSerial(data)) == 0)
|
||||
if ((iclient = GetClientFromSerial(client_serial)) == 0)
|
||||
return;
|
||||
int l_iPosition;
|
||||
char sTime[g_dLength];
|
||||
@ -832,17 +829,14 @@ public Action cmd_timerCheckSelf(int client, int args)
|
||||
public void deleteClientTime(char[] steam2, int stage)
|
||||
{
|
||||
char l_cQuery[g_dLength];
|
||||
if (stage > 1)
|
||||
{
|
||||
int l_iZoneCount = unloze_zoneCount();
|
||||
if (l_iZoneCount > 1)
|
||||
Format(l_cQuery, sizeof(l_cQuery), "UPDATE `zetimer_table` SET `%sS%i` = '0.000' WHERE steam_auth = '%s'", g_cMapname, stage, steam2);
|
||||
}
|
||||
else
|
||||
{
|
||||
Format(l_cQuery, sizeof(l_cQuery), "UPDATE `zetimer_table` SET `%s` = '0.000' WHERE steam_auth = '%s'", g_cMapname, steam2);
|
||||
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);
|
||||
}
|
||||
g_dDatabase.Query(SQL_FinishedQuery_mute_error, l_cQuery, _, DBPrio_High);
|
||||
DataPack hDataPack = new DataPack();
|
||||
hDataPack.WriteString(l_cQuery);
|
||||
g_dDatabase.Query(SQL_FinishedQuery, l_cQuery, hDataPack, DBPrio_High);
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
@ -861,7 +855,10 @@ 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);
|
||||
g_dDatabase.Query(SQL_CheckSelf, l_cQuery, GetClientSerial(client));
|
||||
DataPack hDataPack = new DataPack();
|
||||
hDataPack.WriteCell(GetClientSerial(client));
|
||||
hDataPack.WriteString(l_cQuery);
|
||||
g_dDatabase.Query(SQL_CheckSelf, l_cQuery, hDataPack);
|
||||
}
|
||||
else
|
||||
CheckStagesOnMap(client, 1);
|
||||
@ -875,24 +872,32 @@ 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);
|
||||
g_dDatabase.Query(SQL_CheckSelf, l_cQuery, GetClientSerial(client));
|
||||
DataPack hDataPack = new DataPack();
|
||||
hDataPack.WriteCell(GetClientSerial(client));
|
||||
hDataPack.WriteString(l_cQuery);
|
||||
g_dDatabase.Query(SQL_CheckSelf, l_cQuery, hDataPack);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public void SQL_CheckSelf(Database db, DBResultSet results, const char[] error, any data)
|
||||
public void SQL_CheckSelf(Database db, DBResultSet results, const char[] error, DataPack data)
|
||||
{
|
||||
if(!db || strlen(error))
|
||||
ResetPack(data);
|
||||
int client_serial = data.ReadCell();
|
||||
if (!db || strlen(error))
|
||||
{
|
||||
LogError("Database error: %s", error);
|
||||
char sQuery[g_dLength];
|
||||
data.ReadString(sQuery, sizeof(sQuery));
|
||||
LogError("Query error 4: %s", error);
|
||||
LogError("actual query: %s", sQuery);
|
||||
return;
|
||||
}
|
||||
char sTime[g_dLength];
|
||||
char l_cMessageContent[g_dLength];
|
||||
char[] l_cPlayerName = new char[MAX_NAME_LENGTH];
|
||||
int iclient;
|
||||
if ((iclient = GetClientFromSerial(data)) == 0)
|
||||
if ((iclient = GetClientFromSerial(client_serial)) == 0)
|
||||
return;
|
||||
if (results.RowCount && results.FetchRow())
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user