Skip to content

Commit

Permalink
fix for #524 (#525)
Browse files Browse the repository at this point in the history
* --fix style records/forwards

* --added oldtime var for styles
--added time difference between old and new server style record to printed phrase
--actually fixed issues(?)

* --missing set values for new var

* --missing indexation

* --wrong format
  • Loading branch information
shipyy authored Sep 12, 2022
1 parent 2792595 commit d92c60a
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 48 deletions.
6 changes: 4 additions & 2 deletions addons/sourcemod/scripting/surftimer/buttonpress.sp
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,7 @@ public void CL_OnEndTimerPress(int client)
{
// New fastest time in map
g_bStyleMapSRVRecord[style][client] = true;
g_fOldStyleRecordMapTime[style] = g_fRecordStyleMapTime[style];
g_fRecordStyleMapTime[style] = g_fFinalTime[client];
Format(g_szRecordStylePlayer[style], 128, "%s", szName);
FormatTimeFloat(1, g_fRecordStyleMapTime[style], 3, g_szRecordStyleMapTime[style], 64);
Expand Down Expand Up @@ -516,6 +517,7 @@ public void CL_OnEndTimerPress(int client)

// Has to be the new record, since it is the first completion
g_bStyleMapSRVRecord[style][client] = true;
g_fOldStyleRecordMapTime[style] = g_fFinalTime[client];
g_fRecordStyleMapTime[style] = g_fFinalTime[client];
Format(g_szRecordStylePlayer[style], 128, "%s", szName);
FormatTimeFloat(1, g_fRecordStyleMapTime[style], 3, g_szRecordStyleMapTime[style], 128);
Expand All @@ -532,7 +534,7 @@ public void CL_OnEndTimerPress(int client)
g_bStyleMapFirstRecord[style][client] = true;
g_pr_showmsg[client] = true;

db_selectStyleRecord(client, style);
db_selectPersonalStyleRecord(client, style);
}
else if (diff > 0.0)
{
Expand All @@ -543,7 +545,7 @@ public void CL_OnEndTimerPress(int client)
g_bStyleMapPBRecord[style][client] = true;
g_pr_showmsg[client] = true;

db_selectStyleRecord(client, style);
db_selectPersonalStyleRecord(client, style);
}

if (!g_bStyleMapSRVRecord[style][client] && !g_bStyleMapFirstRecord[style][client] && !g_bStyleMapPBRecord[style][client])
Expand Down
3 changes: 3 additions & 0 deletions addons/sourcemod/scripting/surftimer/globals.sp
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,9 @@ float g_fRecordMapTime;
// Old map record time in seconds
float g_fOldRecordMapTime;

// Old map style record time in seconds
float g_fOldStyleRecordMapTime[MAX_STYLES];

// Record map time in 00:00:00 format
char g_szRecordMapTime[64];

Expand Down
27 changes: 23 additions & 4 deletions addons/sourcemod/scripting/surftimer/misc.sp
Original file line number Diff line number Diff line change
Expand Up @@ -4163,9 +4163,15 @@ stock void StyleFinishedMsgs(int client, int style)

if (g_bStyleMapSRVRecord[style][client])
{
// int r = GetRandomInt(1, 2);
float fRecordDiff;
char szRecordDiff[64] = "";

fRecordDiff = g_fOldStyleRecordMapTime[style] - g_fFinalTime[client];
FormatTimeFloat(client, fRecordDiff, 3, szRecordDiff, sizeof szRecordDiff);
Format(szRecordDiff, sizeof szRecordDiff, "[%c-%s%c]", LIGHTGREEN, szRecordDiff, WHITE);

PlayRecordSound(2);
CPrintToChat(i, "%t", "Misc36", g_szChatPrefix, szName, g_szStyleRecordPrint[style]);
CPrintToChat(i, "%t", "Misc36", g_szChatPrefix, szName, g_szStyleRecordPrint[style], szRecordDiff);
}
}
}
Expand All @@ -4176,9 +4182,15 @@ stock void StyleFinishedMsgs(int client, int style)
{
if (g_bStyleMapSRVRecord[style][client])
{
// int r = GetRandomInt(1, 2);
float fRecordDiff;
char szRecordDiff[64] = "";

fRecordDiff = g_fOldStyleRecordMapTime[style] - g_fFinalTime[client];
FormatTimeFloat(client, fRecordDiff, 3, szRecordDiff, sizeof szRecordDiff);
Format(szRecordDiff, sizeof szRecordDiff, "[%c-%s%c]", LIGHTGREEN, szRecordDiff, WHITE);

PlayRecordSound(2);
CPrintToChat(i, "%t", "Misc36", g_szChatPrefix, szName, g_szStyleRecordPrint[style]);
CPrintToChat(i, "%t", "Misc36", g_szChatPrefix, szName, g_szStyleRecordPrint[style], szRecordDiff);
}
}
}
Expand All @@ -4189,6 +4201,13 @@ stock void StyleFinishedMsgs(int client, int style)

if (g_bStyleMapSRVRecord[style][client])
{
float fRecordDiff = g_fOldStyleRecordMapTime[style] - g_fFinalTime[client];
char szRecordDiff[64];
FormatTimeFloat(client, fRecordDiff, 3, szRecordDiff, sizeof szRecordDiff);
Format(szRecordDiff, sizeof szRecordDiff, "-%s", szRecordDiff);

SendNewRecordForward(client, szRecordDiff);

SetNewRecordPrestrafe(client, 0, style, true, false, false);
}

Expand Down
69 changes: 29 additions & 40 deletions addons/sourcemod/scripting/surftimer/sql.sp
Original file line number Diff line number Diff line change
Expand Up @@ -7699,7 +7699,7 @@ public void sql_viewTotalStageRecordsCallback(Handle owner, Handle hndl, const c
}

// Styles for maps
public void db_selectStyleRecord(int client, int style)
public void db_selectPersonalStyleRecord(int client, int style)
{
if (!IsValidClient(client))
return;
Expand All @@ -7709,15 +7709,15 @@ public void db_selectStyleRecord(int client, int style)
WritePackCell(stylepack, style);

char szQuery[255];
Format(szQuery, 255, "SELECT runtimepro FROM ck_playertimes WHERE mapname = '%s' AND style = %i ORDER BY runtimepro LIMIT 1;", g_szMapName, style);
SQL_TQuery(g_hDb, sql_selectStyleRecordCallback, szQuery, stylepack, DBPrio_Low);
Format(szQuery, 255, "SELECT runtimepro FROM `ck_playertimes` WHERE `steamid` = '%s' AND `mapname` = '%s' AND `style` = %i AND `runtimepro` > -1.0", g_szSteamID[client], g_szMapName, style);
SQL_TQuery(g_hDb, sql_selectPersonalStyleRecordCallback, szQuery, stylepack, DBPrio_Low);
}

public void sql_selectStyleRecordCallback(Handle owner, Handle hndl, const char[] error, any stylepack)
public void sql_selectPersonalStyleRecordCallback(Handle owner, Handle hndl, const char[] error, any stylepack)
{
if (hndl == null)
{
LogError("[SurfTimer] SQL Error (sql_selectStyleRecordCallback): %s", error);
LogError("[SurfTimer] SQL Error (sql_selectPersonalStyleRecordCallback): %s", error);
return;
}

Expand All @@ -7731,51 +7731,40 @@ public void sql_selectStyleRecordCallback(Handle owner, Handle hndl, const char[


char szQuery[512];
char szRecordDiff[54];
float RecordDiff;
// Found old time from database
if (SQL_HasResultSet(hndl) && SQL_FetchRow(hndl))
{
float time = SQL_FetchFloat(hndl, 0);

// If old time was slower than the new time, update record
// If old time was slower than the new time, update personal record
if ((g_fFinalTime[data] <= time || time <= 0.0))
{
RecordDiff = time - g_fFinalTime[data];
FormatTimeFloat(data, RecordDiff, 3, szRecordDiff, 54);
Format(szRecordDiff, 54, "-%s", szRecordDiff);
SendNewRecordForward(data, szRecordDiff);
db_updateStyleRecord(data, style);
db_updatePersonalStyleRecord(data, style);
}
}
// No PERSONAL record found from database - Let's insert
else
{ // No record found from database - Let's insert

// Anounce the record
FormatTimeFloat(data, 0.0, 3, szRecordDiff, 54);
Format(szRecordDiff, 54, "-%s", szRecordDiff);
SendNewRecordForward(data, szRecordDiff);

// Escape name for SQL injection protection
char szName[MAX_NAME_LENGTH * 2 + 1], szUName[MAX_NAME_LENGTH];
GetClientName(data, szUName, MAX_NAME_LENGTH);
SQL_EscapeString(g_hDb, szUName, szName, MAX_NAME_LENGTH);
{
// Escape name for SQL injection protection
char szName[MAX_NAME_LENGTH * 2 + 1], szUName[MAX_NAME_LENGTH];
GetClientName(data, szUName, MAX_NAME_LENGTH);
SQL_EscapeString(g_hDb, szUName, szName, MAX_NAME_LENGTH);

// Move required information in datapack
Handle pack = CreateDataPack();
WritePackFloat(pack, g_fFinalTime[data]);
WritePackCell(pack, data);
WritePackCell(pack, style);
// Move required information in datapack
Handle pack = CreateDataPack();
WritePackFloat(pack, g_fFinalTime[data]);
WritePackCell(pack, data);
WritePackCell(pack, style);

g_StyleMapTimesCount[style]++;
g_StyleMapTimesCount[style]++;

Format(szQuery, 512, "INSERT INTO ck_playertimes (steamid, mapname, name, runtimepro, style, velStartXY, velStartXYZ, velStartZ) VALUES ('%s', '%s', '%s', '%f', %i, %i, %i, %i)", g_szSteamID[data], g_szMapName, szName, g_fFinalTime[data], style, g_iPreStrafe[0][0][style], g_iPreStrafe[1][0][style], g_iPreStrafe[2][0][style]);
SQL_TQuery(g_hDb, SQL_UpdateStyleRecordCallback, szQuery, pack, DBPrio_Low);
}
Format(szQuery, 512, "INSERT INTO ck_playertimes (steamid, mapname, name, runtimepro, style, velStartXY, velStartXYZ, velStartZ) VALUES ('%s', '%s', '%s', '%f', %i, %i, %i, %i)", g_szSteamID[data], g_szMapName, szName, g_fFinalTime[data], style, g_iPreStrafe[0][0][style], g_iPreStrafe[1][0][style], g_iPreStrafe[2][0][style]);
SQL_TQuery(g_hDb, SQL_UpdatePersonalStyleRecordCallback, szQuery, pack, DBPrio_Low);
}
}

// If latest record was faster than old - Update time
public void db_updateStyleRecord(int client, int style)
public void db_updatePersonalStyleRecord(int client, int style)
{
char szUName[MAX_NAME_LENGTH];

Expand All @@ -7797,14 +7786,14 @@ public void db_updateStyleRecord(int client, int style)
char szQuery[1024];
// "UPDATE ck_playertimes SET name = '%s', runtimepro = '%f' WHERE steamid = '%s' AND mapname = '%s';";
Format(szQuery, 1024, "UPDATE `ck_playertimes` SET `name` = '%s', runtimepro = '%f', `velStartXY` = %i, `velStartXYZ` = %i, `velStartZ` = %i WHERE `steamid` = '%s' AND `mapname` = '%s' AND `style` = %i;", szName, g_fFinalTime[client], g_iPreStrafe[0][0][style], g_iPreStrafe[1][0][style], g_iPreStrafe[2][0][style], g_szSteamID[client], g_szMapName, style);
SQL_TQuery(g_hDb, SQL_UpdateStyleRecordCallback, szQuery, pack, DBPrio_Low);
SQL_TQuery(g_hDb, SQL_UpdatePersonalStyleRecordCallback, szQuery, pack, DBPrio_Low);
}

public void SQL_UpdateStyleRecordCallback(Handle owner, Handle hndl, const char[] error, any pack)
public void SQL_UpdatePersonalStyleRecordCallback(Handle owner, Handle hndl, const char[] error, any pack)
{
if (hndl == null)
{
LogError("[SurfTimer] SQL Error (SQL_UpdateStyleRecordCallback): %s", error);
LogError("[SurfTimer] SQL Error (SQL_UpdatePersonalStyleRecordCallback): %s", error);
return;
}

Expand All @@ -7821,14 +7810,14 @@ public void SQL_UpdateStyleRecordCallback(Handle owner, Handle hndl, const char[
// Find out how many times are are faster than the players time
char szQuery[512];
Format(szQuery, 512, "SELECT count(runtimepro) FROM `ck_playertimes` WHERE `mapname` = '%s' AND `style` = %i AND `runtimepro` < %f;", g_szMapName, style, time);
SQL_TQuery(g_hDb, SQL_UpdateStyleRecordCallback2, szQuery, data, DBPrio_Low);
SQL_TQuery(g_hDb, SQL_UpdatePersonalStyleRecordCallback2, szQuery, data, DBPrio_Low);
}

public void SQL_UpdateStyleRecordCallback2(Handle owner, Handle hndl, const char[] error, any pack)
public void SQL_UpdatePersonalStyleRecordCallback2(Handle owner, Handle hndl, const char[] error, any pack)
{
if (hndl == null)
{
LogError("[SurfTimer] SQL Error (SQL_UpdateStyleRecordProCallback2): %s", error);
LogError("[SurfTimer] SQL Error (SQL_UpdatePersonalStyleRecordCallback2): %s", error);
return;
}
// Get players rank, 9999999 = error
Expand Down
4 changes: 2 additions & 2 deletions addons/sourcemod/translations/surftimer.phrases.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1366,8 +1366,8 @@
}
"Misc36"
{
"#format" "{1:s},{2:s},{3:s}"
"en" "{1} {yellow}{2}{default} beat the {red}{3} {default}map record!"
"#format" "{1:s},{2:s},{3:s},{4:s}"
"en" "{1} {yellow}{2}{default} beat the {red}{3} {default}map record! {4}"
}
"Misc37"
{
Expand Down

0 comments on commit d92c60a

Please sign in to comment.