major rework of many features

This commit is contained in:
Christian 2021-02-25 23:44:03 +01:00
parent 148a6d07d4
commit 2d5edba284

View File

@ -1,7 +1,7 @@
#pragma semicolon 1
#define DEBUG
#define PLUGIN_AUTHOR "jenz"
#define PLUGIN_VERSION "1.5"
#define PLUGIN_VERSION "1.6"
#define g_dLength 256
#define g_dIndex 65
#include <sourcemod>
@ -17,10 +17,8 @@ char g_cMapname[g_dLength];
char g_cSpecialMapStart[g_dLength];
char g_cSpecialMapEnd[g_dLength];
static char g_sConfigzones[PLATFORM_MAX_PATH];
int g_iRoundMinutes;
float g_fRoundSeconds;
int g_iMinutesIndividual[MAXPLAYERS + 1];
float g_fSecondsIndividual[MAXPLAYERS + 1];
float g_fStartTime[MAXPLAYERS + 1];
char g_csTime_record[MAXPLAYERS + 1];
float g_fClientVectors[MAXPLAYERS + 1][3];
int g_iClientFrames[MAXPLAYERS + 1];
int g_iClientSpeedInterval[MAXPLAYERS + 1];
@ -28,12 +26,11 @@ int g_iClientChecking[MAXPLAYERS + 1];
bool g_bDisplaySpecial;
bool g_bHumansAllowedTime[MAXPLAYERS + 1];
bool g_bHideTimer[MAXPLAYERS + 1];
bool g_bDev[MAXPLAYERS + 1];
bool g_bEventBool = false;
Handle g_hClientCookie = INVALID_HANDLE;
Database g_dDatabase;
Handle hText;
float playertime_leaving_zone[MAXPLAYERS + 1];
int player_stage[MAXPLAYERS + 1];
public Plugin myinfo =
@ -44,6 +41,11 @@ public Plugin myinfo =
version = PLUGIN_VERSION,
url = "www.unloze.com"
};
public void OnConfigsExecuted()
{
Database.Connect(SQL_OnDatabaseConnect, "racetimercss");
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
@ -68,8 +70,11 @@ public void OnPluginStart()
continue;
}
OnClientCookiesCached(i);
OnClientPostAdminCheck(i);
}
OnMapStart();
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
@ -80,20 +85,27 @@ public void SQL_OnDatabaseConnect(Database db, const char[] error, any data)
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_dDatabase.Query(SQL_OnConnectFinished, sQuery, _, DBPrio_High);
g_bDisplaySpecial = unloze_gBSpecialMapDisplay();
GetCurrentMap(g_cMapname, sizeof(g_cMapname));
CreateTimer(0.05, Timer_CountdownRace, INVALID_HANDLE, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
startTimer();
//MYSQLCheckMapEntry();
}
public void SQL_OnConnectFinished(Database db, DBResultSet results, const char[] error, any data)
{
if(!db || strlen(error))
{
LogError("Database error: %s", error);
return;
}
for(int i = 1; i <= MaxClients; i++)
if (IsClientConnected(i) && IsClientAuthorized(i))
OnClientPostAdminCheck(i);
}
public void SQL_OnQueryCompleted(Database db, DBResultSet results, const char[] error, any data)
@ -106,46 +118,36 @@ public void SQL_OnQueryCompleted(Database db, DBResultSet results, const char[]
int client;
if ((client = GetClientFromSerial(data)) == 0)
return;
if (results.RowCount && results.FetchRow())
{
playertime_leaving_zone[client] = results.FetchFloat(0);
}
results.FetchString(0, g_csTime_record[client], sizeof(g_csTime_record));
}
public void SQL_OnFetchedTime(Database db, DBResultSet results, const char[] error, any data1)
public void MYSQLCheckMapEntry()
{
if (!db || strlen(error))
{
LogError("Query error: %s", error);
return;
}
DataPack data = view_as<DataPack>(data1);
int client = data.ReadCell();
if (client == 0)
return;
int l_iRaceCount;
int l_iZoneCount = unloze_zoneCount();
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");
}
}
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 || strlen(error))
if (!db)
{
LogError("Query error: %s", error);
return;
@ -158,7 +160,7 @@ public void SQL_OnQueryCompleted1(Database db, DBResultSet results, const char[]
{
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);
Format(sQuery, sizeof(sQuery), "ALTER TABLE `zetimer_table` ADD COLUMN `%s` VARCHAR(256) NOT NULL", g_cMapname);
g_dDatabase.Query(SQL_FinishedQuery, sQuery, _, DBPrio_High);
}
else
@ -169,7 +171,7 @@ public void SQL_OnQueryCompleted1(Database db, DBResultSet results, const char[]
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);
Format(sQuery, sizeof(sQuery), "ALTER TABLE `zetimer_table` ADD COLUMN `%sS%i` VARCHAR(256) NOT NULL", g_cMapname, l_iRaceCount);
g_dDatabase.Query(SQL_FinishedQuery, sQuery, _, DBPrio_High);
}
}
@ -186,9 +188,24 @@ public void SQL_FinishedQuery(Database db, DBResultSet results, const char[] err
}
}
public void SQL_FinishedQuery_mute_error(Database db, DBResultSet results, const char[] error, any data)
{
if (!db)
return;
}
public void OnMapStart()
{
Database.Connect(SQL_OnDatabaseConnect, "racetimercss");
static Handle hHostName;
if((hHostName = FindConVar("hostname")) == INVALID_HANDLE)
{
return;
}
char line[g_dLength];
GetConVarString(hHostName, line, sizeof(line));
if (StrContains(line, "EVENT", false) > -1)
g_bEventBool = true;
AutoExecConfig();
}
//----------------------------------------------------------------------------------------------------
@ -223,29 +240,11 @@ public void startTimer()
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public Action Timer_CountdownRace(Handle timer, any data)
{
float l_milisecond = 0.0000;
while (l_milisecond < 0.1000)
{
l_milisecond += 0.00001;
g_fRoundSeconds += 0.00001;
if (g_fRoundSeconds > 59.9999)
{
g_iRoundMinutes += 1;
g_fRoundSeconds = 0.0000;
}
}
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void Event_RoundStart(Handle event, const char[] name, bool dontBroadcast)
{
g_iRoundMinutes = 0;
g_fRoundSeconds = 0.0;
int l_iZoneCount = unloze_zoneCount();
if (!l_iZoneCount)
return;
for (int i = 1; i <= MaxClients; i++)
if (IsValidClient(i))
{
@ -256,6 +255,7 @@ public void Event_RoundStart(Handle event, const char[] name, bool dontBroadcast
{
mysql_get_player_time(i, 0);
g_bHumansAllowedTime[i] = true;
g_fStartTime[i] = GetEngineTime();
}
}
}
@ -287,20 +287,20 @@ public void OnClientDisconnect(int client)
//----------------------------------------------------------------------------------------------------
public void resetClient(int client)
{
g_fSecondsIndividual[client] = 0.0;
g_iMinutesIndividual[client] = 0;
g_iClientChecking[client] = 0;
g_bHumansAllowedTime[client] = false;
resetClientVectors(client);
g_bDev[client] = false;
player_stage[client] = 0;
playertime_leaving_zone[client] = 0.0;
Format(g_csTime_record[client], sizeof(g_csTime_record[]), "0.000");
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public Action OnPlayerRunCmd(int client, int &buttons, int &impulse, float vel[3], float angles[3], int &weapon, int &subtype, int &cmdnum, int &tickcount, int &seed, int mouse[2])
public void OnPlayerRunCmdPost(int client, int buttons, int impulse, const float vel[3], const float angles[3], int weapon, int subtype, int cmdnum, int tickcount, int seed, const int mouse[2])
{
if (g_bEventBool)
g_bHumansAllowedTime[client] = false;
if (g_bHumansAllowedTime[client] && (GetClientTeam(client) == CS_TEAM_CT) && IsPlayerAlive(client))
{
int frameCap = 11;
@ -309,15 +309,15 @@ public Action OnPlayerRunCmd(int client, int &buttons, int &impulse, float vel[3
g_iClientFrames[client] = 0;
float clientVectors[3];
GetClientAbsOrigin(client, clientVectors);
if (checkClientOrigin(g_fClientVectors[client], clientVectors, client) && !g_bDev[client])
if (checkClientOrigin(g_fClientVectors[client], clientVectors, client))
{
g_bHumansAllowedTime[client] = false;
resetClientVectors(client);
PrintToChat(client, "Disabled timer due to potential teleport abuse");
return Plugin_Continue;
return;
}
int speedCheckerCap = 10;
if (g_iClientSpeedInterval[client] > speedCheckerCap && !g_bDev[client])
if (g_iClientSpeedInterval[client] > speedCheckerCap)
{
g_iClientSpeedInterval[client] = 0;
bool bNoclip = (GetEntityMoveType(client) == MOVETYPE_NOCLIP);
@ -326,7 +326,7 @@ public Action OnPlayerRunCmd(int client, int &buttons, int &impulse, float vel[3
g_bHumansAllowedTime[client] = false;
resetClientVectors(client);
PrintToChat(client, "Disabled timer due to Noclip");
return Plugin_Continue;
return;
}
float speed = GetEntPropFloat(client, Prop_Data, "m_flLaggedMovementValue");
if (speed > 1.0)
@ -336,7 +336,7 @@ public Action OnPlayerRunCmd(int client, int &buttons, int &impulse, float vel[3
g_bHumansAllowedTime[client] = false;
resetClientVectors(client);
PrintToChat(client, "Disabled timer due to modified run speed");
return Plugin_Continue;
return;
}
}
float client_gravity = GetEntityGravity(client);
@ -350,7 +350,7 @@ public Action OnPlayerRunCmd(int client, int &buttons, int &impulse, float vel[3
g_bHumansAllowedTime[client] = false;
resetClientVectors(client);
PrintToChat(client, "Disabled timer due to modified gravity");
return Plugin_Continue;
return;
}
}
g_fClientVectors[client] = clientVectors;
@ -358,44 +358,24 @@ public Action OnPlayerRunCmd(int client, int &buttons, int &impulse, float vel[3
if (hText != INVALID_HANDLE && !g_bHideTimer[client])
{
SetHudTextParams(0.35, 0.85, 0.1, 125, 255, 255, 85);
int l_iCalculateMins = CalculateValuesMinutes(client);
float l_fCalculateSecs = CalculateValues(client);
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 (l_fCalculateSecs < 10.0)
{
if (leftover_seconds < 10.0)
{
ShowSyncHudText(client, hText, "%N Time: 0%i:0%.4f\nRecord: 0%i:0%.4f\nMap: %s\nCourse: %i", client, l_iCalculateMins,
l_fCalculateSecs, minutes, leftover_seconds, g_cMapname, player_stage[client]);
}
else
{
ShowSyncHudText(client, hText, "%N Time: 0%i:0%.4f\nRecord: 0%i:%.4f\nMap: %s\nCourse: %i", client, l_iCalculateMins,
l_fCalculateSecs, minutes, leftover_seconds, g_cMapname, player_stage[client]);
}
}
else
{
if (leftover_seconds < 10.0)
{
ShowSyncHudText(client, hText, "%N Time: 0%i:%.4f\nRecord: 0%i:0%.4f\nMap: %s\nCourse: %i", client, l_iCalculateMins,
l_fCalculateSecs, minutes, leftover_seconds, g_cMapname, player_stage[client]);
} else
{
ShowSyncHudText(client, hText, "%N Time: 0%i:%.4f\nRecord: 0%i:%.4f\nMap: %s\nCourse: %i", client, l_iCalculateMins,
l_fCalculateSecs, minutes, leftover_seconds, g_cMapname, player_stage[client]);
}
}
float total_time = client_current_race_time(client);
char sTime[32];
FormatPlayerTime(total_time, sTime, sizeof(sTime), false, 1);
ShowSyncHudText(client, hText, "%N Time: %s\nRecord: %s\nMap: %s\nCourse: %i", client, sTime, g_csTime_record[client], g_cMapname, player_stage[client]);
}
}
g_iClientSpeedInterval[client]++;
}
g_iClientFrames[client]++;
}
return Plugin_Continue;
return;
}
public float client_current_race_time(int i_client)
{
return GetEngineTime() - g_fStartTime[i_client];
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
@ -446,18 +426,12 @@ public void unloze_zoneEntry(int client, char[] zone)
if (IsClientAuthorized(client))
{
if (l_iZoneCount < 2)
{
player_stage[client] = 0;
}
if (player_stage[client] == (zoneIndex / 2) || l_iZoneCount < 2)
{
FinishedStageRaceZone(client);
}
}
else
{
PrintToChat(client, "You are not authorized with steam!!");
}
g_bHumansAllowedTime[client] = false;
}
}
@ -470,8 +444,7 @@ public void unloze_zoneLeave(int client, char[] zone)
if (((GetClientTeam(client) == CS_TEAM_CT) && StrContains(zone, "ZONE_PREFIX_START") > -1) || StrEqual(zone, g_cSpecialMapStart))
{
resetClientVectors(client);
g_fSecondsIndividual[client] = g_fRoundSeconds;
g_iMinutesIndividual[client] = g_iRoundMinutes;
g_fStartTime[client] = GetEngineTime();
float notRounded = float(RetrieveZoneIndex(zone));
player_stage[client] = RoundToCeil(notRounded / 2);
mysql_get_player_time(client, player_stage[client]);
@ -479,6 +452,38 @@ public void unloze_zoneLeave(int client, char[] zone)
CPrintToChat(client, "Timer started for Course: %i", player_stage[client]);
}
}
stock void FormatPlayerTime(float Time, char[] result, int maxlength, bool showDash, int precision)
{
if(Time <= 0.0 && showDash == true)
{
Format(result, maxlength, "-");
return;
}
int hours = RoundToFloor(Time/3600);
Time -= hours*3600;
int minutes = RoundToFloor(Time/60);
Time -= minutes*60;
float seconds = Time;
char sPrecision[16];
if(precision == 0)
Format(sPrecision, sizeof(sPrecision), (hours > 0 || minutes > 0)?"%04.1f":"%.1f", seconds);
else if(precision == 1)
Format(sPrecision, sizeof(sPrecision), (hours > 0 || minutes > 0)?"%06.3f":"%.3f", seconds);
else if(precision == 2)
Format(sPrecision, sizeof(sPrecision), (hours > 0 || minutes > 0)?"%09.6f":"%.6f", seconds);
if(hours > 0)
Format(result, maxlength, "%d:%02d:%s", hours, minutes, sPrecision);
else if(minutes > 0)
Format(result, maxlength, "%d:%s", minutes, sPrecision);
else
Format(result, maxlength, "%s", sPrecision);
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
@ -525,92 +530,31 @@ public int RetrieveZoneIndex(char[] zone)
public void FinishedStageRaceZone(int client)
{
int l_iZoneCount = unloze_zoneCount();
int l_iCalculateMins;
float l_fCalculateSecs;
float leftover_seconds = playertime_leaving_zone[client] - RoundToFloor(playertime_leaving_zone[client]);
int minutes = RoundToFloor(playertime_leaving_zone[client]);
leftover_seconds = leftover_seconds * 100;
if (g_bDev[client])
PrintToChat(client, "leftover_seconds: %f", leftover_seconds);
if (minutes == 0 && leftover_seconds == 0.0)
CPrintToChat(client, "Your record: None yet \nCommand: !toptime !mytime !stages");
else if (leftover_seconds < 10.0)
CPrintToChat(client, "Your record: 0%i:0%.4f \nCommand: !toptime !mytime !stages", minutes, leftover_seconds);
else
CPrintToChat(client, "Your record: 0%i:%.4f \nCommand: !toptime !mytime !stages", minutes, leftover_seconds);
if (l_iZoneCount < 2)
{
//no start zone, we use round time
CPrintToChat(client, "{green}[UNLOZE] Client: %N Time: 0%i:%.4f", client, g_iRoundMinutes, g_fRoundSeconds);
if (g_iRoundMinutes < minutes)
sendMYSQL(client, g_iRoundMinutes, g_fRoundSeconds, player_stage[client]);
else if (g_iRoundMinutes == minutes && g_fRoundSeconds < leftover_seconds)
sendMYSQL(client, g_iRoundMinutes, g_fRoundSeconds, player_stage[client]);
else if (minutes == 0 && leftover_seconds == 0.0)
sendMYSQL(client, g_iRoundMinutes, g_fRoundSeconds, player_stage[client]);
}
else
{
//uses start zone, we use time when leaving start zone
l_iCalculateMins = CalculateValuesMinutes(client);
l_fCalculateSecs = CalculateValues(client);
//tricking ppl !hehe
CPrintToChat(client, "{green}[UNLOZE] Stage: %i", player_stage[client]);
CPrintToChat(client, "{green}[UNLOZE] Client: %N Time: 0%i:%.4f", client, l_iCalculateMins, l_fCalculateSecs);
if (l_iCalculateMins < minutes)
sendMYSQL(client, l_iCalculateMins, l_fCalculateSecs, player_stage[client]);
else if (l_iCalculateMins == minutes && l_fCalculateSecs < leftover_seconds)
sendMYSQL(client, l_iCalculateMins, l_fCalculateSecs, player_stage[client]);
else if (minutes == 0.0 && leftover_seconds == 0.0)
sendMYSQL(client, l_iCalculateMins, l_fCalculateSecs, player_stage[client]);
}
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public int CalculateValuesMinutes(int client)
{
float l_fRoundSeconds = g_fRoundSeconds;
float l_fRoundSecondsIndividual = g_fSecondsIndividual[client];
int l_iRoundMinutes = g_iRoundMinutes;
int l_iRoundMinutesIndividual = g_iMinutesIndividual[client];
if (l_iRoundMinutesIndividual > l_iRoundMinutes)
return 0;
l_iRoundMinutes = l_iRoundMinutes - l_iRoundMinutesIndividual;
if (l_fRoundSeconds < l_fRoundSecondsIndividual)
l_iRoundMinutes--;
return l_iRoundMinutes;
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public float CalculateValues(int client)
{
// 2:24 enter with roundtime 5:29 = 3:05
// 3:01 enter with roundtime 3:59 = 58 sec
//example roundtime is 5 mins 40 seconds, client entered at 4 mins and 50 seconds, so 50 sec race
float l_fRoundSeconds = g_fRoundSeconds;
float l_fRoundSecondsIndividual = g_fSecondsIndividual[client];
float l_fSecAdd;
if (l_fRoundSeconds < l_fRoundSecondsIndividual)
{
while (l_fRoundSecondsIndividual < 59.9)
{
l_fRoundSecondsIndividual++;
l_fSecAdd++;
}
float returnvalue = l_fSecAdd + l_fRoundSeconds;
//PrintToChat(client, "returnvalue float: %f", returnvalue);
return returnvalue;
}
else
{
float returnvalueminus = l_fRoundSeconds - l_fRoundSecondsIndividual;
//PrintToChat(client, "returnvalueminus float: %f", returnvalueminus);
return returnvalueminus;
}
}
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);
if (old_record == 0.0)
{
CPrintToChat(client, "Your record: None yet\nCommand: !toptime !mytime !stages");
sendMYSQL(client, sTime, player_stage[client]);
return;
}
CPrintToChat(client, "Your record: %s\nCommand: !toptime !mytime !stages", record_client);
if (new_time < old_record)
sendMYSQL(client, sTime, player_stage[client]);
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void mysql_get_player_time(int client, int stage)
{
char query[g_dLength];
@ -623,31 +567,6 @@ public void mysql_get_player_time(int client, int stage)
g_dDatabase.Query(SQL_OnQueryCompleted, query, GetClientSerial(client));
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void MYSQLCheckMapEntry()
{
int l_iRaceCount;
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, _);
}
}
}
//----------------------------------------------------------------------------------------------------
// Purpose: TODO implement if needed
//----------------------------------------------------------------------------------------------------
@ -667,12 +586,10 @@ public int GetTotalRaceZones()
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void sendMYSQL(int client, int minutes, float seconds, int stage)
public void sendMYSQL(int client, char[] sTime, int stage)
{
int l_iZoneCount = unloze_zoneCount();
float l_fPlayerTime = float(minutes);
char sSID[g_dIndex];
char sQuery2[g_dLength];
char sQuery[g_dLength];
char sName[MAX_NAME_LENGTH];
GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID));
@ -687,23 +604,16 @@ public void sendMYSQL(int client, int minutes, float seconds, int stage)
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, sEscapedName, l_fPlayerTime, sEscapedName, g_cMapname, l_fPlayerTime);
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(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, sEscapedName, l_fPlayerTime, sEscapedName, g_cMapname, stage, l_fPlayerTime);
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);
}
DataPack pack = new DataPack();
pack.WriteCell(client);
pack.WriteString(sQuery);
pack.WriteFloat(l_fPlayerTime);
pack.Reset();
g_dDatabase.Query(SQL_OnFetchedTime, sQuery2, pack);
g_dDatabase.Query(SQL_FinishedQuery, sQuery, _, DBPrio_High);
CPrintToChat(client, "Updated timer");
}
//----------------------------------------------------------------------------------------------------
@ -734,9 +644,9 @@ public void CheckTop(int client, int index, int autismstate)
}
//we have index now from menu selection
if (l_iZoneCount < 2)
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);
Format(sQuery, sizeof(sQuery), "SELECT name, `%s` FROM `zetimer_table` WHERE `%s` != 0.000 ORDER BY `%s` * 1 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);
Format(sQuery, sizeof(sQuery), "SELECT name, `%sS%i` FROM `zetimer_table` WHERE `%sS%i` != 0.000 ORDER BY `%sS%i` * 1 ASC LIMIT 10", g_cMapname, index, g_cMapname, index, g_cMapname, index);
g_dDatabase.Query(SQL_Select_Top_Callback, sQuery, GetClientSerial(client));
}
@ -750,10 +660,8 @@ public void SQL_Select_Top_Callback(Database db, DBResultSet results, const char
int iclient;
if ((iclient = GetClientFromSerial(data)) == 0)
return;
int l_iMinutes;
int l_iPosition;
float l_fRecord;
float l_iSeconds;
char sTime[g_dLength];
//Player Name
char[] g_cPlayerName = new char[MAX_NAME_LENGTH];
char g_cContent[g_dLength];
@ -765,10 +673,8 @@ public void SQL_Select_Top_Callback(Database db, DBResultSet results, const char
{
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);
results.FetchString(1, sTime, sizeof(sTime));
Format(g_cContent, sizeof(g_cContent), "#%i: Time: %s - %s", l_iPosition, sTime, g_cPlayerName);
menu.AddItem("-1", g_cContent, ITEMDRAW_DISABLED);
}
if (!l_iPosition)
@ -785,9 +691,7 @@ public void SQL_Select_Top_Callback(Database db, DBResultSet results, const char
public int MenuHandler1(Menu menu, MenuAction action, int param1, int param2)
{
if (action == MenuAction_End)
{
delete menu;
}
}
//----------------------------------------------------------------------------------------------------
// Purpose:
@ -920,15 +824,15 @@ public void deleteClientTime(char[] steam2, int stage)
char l_cQuery[g_dLength];
if (stage > 1)
{
Format(l_cQuery, sizeof(l_cQuery), "UPDATE `zetimer_table` SET `%sS%i` = 0.000 WHERE steam_auth = '%s'", g_cMapname, stage, steam2);
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);
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);
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, l_cQuery, _, DBPrio_High);
g_dDatabase.Query(SQL_FinishedQuery_mute_error, l_cQuery, _, DBPrio_High);
}
//----------------------------------------------------------------------------------------------------
// Purpose:
@ -950,9 +854,7 @@ public void Checkself(int client)
g_dDatabase.Query(SQL_CheckSelf, l_cQuery, GetClientSerial(client));
}
else
{
CheckStagesOnMap(client, 1);
}
}
//----------------------------------------------------------------------------------------------------
// Purpose:
@ -965,6 +867,7 @@ public void CheckStageSelf(int client, int selection)
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));
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
@ -975,9 +878,7 @@ public void SQL_CheckSelf(Database db, DBResultSet results, const char[] error,
LogError("Database error: %s", error);
return;
}
int l_iMinutes;
float l_fRecord;
float l_iSeconds;
char sTime[g_dLength];
char l_cMessageContent[g_dLength];
char[] l_cPlayerName = new char[MAX_NAME_LENGTH];
int iclient;
@ -986,15 +887,13 @@ public void SQL_CheckSelf(Database db, DBResultSet results, const char[] error,
if (results.RowCount && results.FetchRow())
{
results.FetchString(0, l_cPlayerName, MAX_NAME_LENGTH);
l_fRecord = results.FetchFloat(1);
if (l_fRecord == 0.000)
results.FetchString(1, sTime, sizeof(sTime));
if (StrEqual(sTime, "0.000", false))
{
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);
Format(l_cMessageContent, sizeof(l_cMessageContent), "%s - %s", sTime, l_cPlayerName);
CPrintToChat(iclient, "Your best time: 0%s", l_cMessageContent);
}
else
@ -1007,8 +906,6 @@ public void SQL_CheckSelf(Database db, DBResultSet results, const char[] error,
stock bool IsValidClient(int client)
{
if (client > 0 && client <= MaxClients && IsClientConnected(client) && IsClientInGame(client))
{
return true;
}
return false;
}