16 changes: 11 additions & 5 deletions src/game/server/score/file_score.cpp
Expand Up @@ -70,7 +70,11 @@ void CFileScore::SaveScoreThread(void *pUser)
lock_wait(gs_ScoreLock);
std::fstream f;
f.open(SaveFile().c_str(), std::ios::out);
if (!f.fail())
if(f.fail())
{
dbg_msg("filescore", "opening '%s' for writing failed", SaveFile().c_str());
}
else
{
int t = 0;
for (sorted_array<CPlayerScore>::range r = pSelf->m_Top.all();
Expand Down Expand Up @@ -109,6 +113,10 @@ void CFileScore::Init()
std::fstream f;
f.open(SaveFile().c_str(), std::ios::in);

if(f.fail())
{
dbg_msg("filescore", "opening '%s' for reading failed", SaveFile().c_str());
}
while (!f.eof() && !f.fail())
{
std::string TmpName, TmpScore, TmpCpLine;
Expand Down Expand Up @@ -239,6 +247,7 @@ void CFileScore::ShowTop5(IConsole::IResult *pResult, int ClientID,
{
CGameContext *pSelf = (CGameContext *) pUserData;
char aBuf[512];
Debut = max(1, Debut < 0 ? m_Top.size() + Debut - 3 : Debut);
pSelf->SendChatTarget(ClientID, "----------- Top 5 -----------");
for (int i = 0; i < 5; i++)
{
Expand Down Expand Up @@ -268,9 +277,6 @@ void CFileScore::ShowRank(int ClientID, const char* pName, bool Search)
if (pScore && Pos > -1)
{
float Time = pScore->m_Score;
char aClientName[128];
str_format(aClientName, sizeof(aClientName), " (%s)",
Server()->ClientName(ClientID));
if (g_Config.m_SvHideScore)
str_format(aBuf, sizeof(aBuf),
"Your time: %d minute(s) %5.2f second(s)", (int)Time / 60,
Expand All @@ -279,7 +285,7 @@ void CFileScore::ShowRank(int ClientID, const char* pName, bool Search)
str_format(aBuf, sizeof(aBuf),
"%d. %s Time: %d minute(s) %5.2f second(s), requested by (%s)", Pos,
pScore->m_aName, (int)Time / 60,
Time - ((int)Time / 60 * 60), aClientName);
Time - ((int)Time / 60 * 60), Server()->ClientName(ClientID));
if (!Search)
GameServer()->SendChat(-1, CGameContext::CHAT_ALL, aBuf, ClientID);
else
Expand Down
32 changes: 16 additions & 16 deletions src/game/server/score/sql_score.cpp
Expand Up @@ -184,7 +184,7 @@ bool CSqlScore::CheckBirthdayThread(CSqlServer* pSqlServer, const CSqlData *pGam

if(pSqlServer->GetResults()->next())
{
int yearsAgo = (int)pSqlServer->GetResults()->getInt("YearsAgo");
int yearsAgo = pSqlServer->GetResults()->getInt("YearsAgo");
str_format(aBuf, sizeof(aBuf), "Happy DDNet birthday to %s for finishing their first map %d year%s ago!", pData->m_Name.Str(), yearsAgo, yearsAgo > 1 ? "s" : "");
pData->GameServer()->SendChat(-1, CGameContext::CHAT_ALL, aBuf, pData->m_ClientID);

Expand Down Expand Up @@ -400,19 +400,19 @@ bool CSqlScore::MapInfoThread(CSqlServer* pSqlServer, const CSqlData *pGameData,
else
{
pSqlServer->GetResults()->next();
int points = (int)pSqlServer->GetResults()->getInt("Points");
int stars = (int)pSqlServer->GetResults()->getInt("Stars");
int finishes = (int)pSqlServer->GetResults()->getInt("Finishes");
int finishers = (int)pSqlServer->GetResults()->getInt("Finishers");
int average = (int)pSqlServer->GetResults()->getInt("Average");
int points = pSqlServer->GetResults()->getInt("Points");
int stars = pSqlServer->GetResults()->getInt("Stars");
int finishes = pSqlServer->GetResults()->getInt("Finishes");
int finishers = pSqlServer->GetResults()->getInt("Finishers");
int average = pSqlServer->GetResults()->getInt("Average");
char aMap[128];
strcpy(aMap, pSqlServer->GetResults()->getString("Map").c_str());
char aServer[32];
strcpy(aServer, pSqlServer->GetResults()->getString("Server").c_str());
char aMapper[128];
strcpy(aMapper, pSqlServer->GetResults()->getString("Mapper").c_str());
int stamp = (int)pSqlServer->GetResults()->getInt("Stamp");
int ago = (int)pSqlServer->GetResults()->getInt("Ago");
int stamp = pSqlServer->GetResults()->getInt("Stamp");
int ago = pSqlServer->GetResults()->getInt("Ago");
float ownTime = (float)pSqlServer->GetResults()->getDouble("OwnTime");

char pAgoString[40] = "\0";
Expand Down Expand Up @@ -533,7 +533,7 @@ bool CSqlScore::SaveScoreThread(CSqlServer* pSqlServer, const CSqlData *pGameDat
if(pSqlServer->GetResults()->rowsCount() == 1)
{
pSqlServer->GetResults()->next();
int points = (int)pSqlServer->GetResults()->getInt("Points");
int points = pSqlServer->GetResults()->getInt("Points");
if (points == 1)
str_format(aBuf, sizeof(aBuf), "You earned %d point for finishing this map!", points);
else
Expand Down Expand Up @@ -764,7 +764,7 @@ bool CSqlScore::ShowRankThread(CSqlServer* pSqlServer, const CSqlData *pGameData
pSqlServer->GetResults()->next();

float Time = (float)pSqlServer->GetResults()->getDouble("Time");
int Rank = (int)pSqlServer->GetResults()->getInt("Rank");
int Rank = pSqlServer->GetResults()->getInt("Rank");
if(g_Config.m_SvHideScore)
{
str_format(aBuf, sizeof(aBuf), "Your time: %02d:%05.2f", (int)(Time/60), Time-((int)Time/60*60));
Expand Down Expand Up @@ -837,7 +837,7 @@ bool CSqlScore::ShowTeamRankThread(CSqlServer* pSqlServer, const CSqlData *pGame
pSqlServer->GetResults()->first();

float Time = (float)pSqlServer->GetResults()->getDouble("Time");
int Rank = (int)pSqlServer->GetResults()->getInt("Rank");
int Rank = pSqlServer->GetResults()->getInt("Rank");

for(int Row = 0; Row < Rows; Row++)
{
Expand Down Expand Up @@ -1105,8 +1105,8 @@ bool CSqlScore::ShowTimesThread(CSqlServer* pSqlServer, const CSqlData *pGameDat
while(pSqlServer->GetResults()->next())
{
char pAgoString[40] = "\0";
pSince = (int)pSqlServer->GetResults()->getInt("Ago");
pStamp = (int)pSqlServer->GetResults()->getInt("Stamp");
pSince = pSqlServer->GetResults()->getInt("Ago");
pStamp = pSqlServer->GetResults()->getInt("Stamp");
pTime = (float)pSqlServer->GetResults()->getDouble("Time");

sqlstr::AgoTimeToString(pSince,pAgoString);
Expand Down Expand Up @@ -1181,8 +1181,8 @@ bool CSqlScore::ShowPointsThread(CSqlServer* pSqlServer, const CSqlData *pGameDa
else
{
pSqlServer->GetResults()->next();
int count = (int)pSqlServer->GetResults()->getInt("Points");
int rank = (int)pSqlServer->GetResults()->getInt("Rank");
int count = pSqlServer->GetResults()->getInt("Points");
int rank = pSqlServer->GetResults()->getInt("Rank");
str_format(aBuf, sizeof(aBuf), "%d. %s Points: %d, requested by %s", rank, pSqlServer->GetResults()->getString("Name").c_str(), count, pData->m_aRequestingPlayer);
pData->GameServer()->SendChat(-1, CGameContext::CHAT_ALL, aBuf, pData->m_ClientID);
}
Expand Down Expand Up @@ -1554,7 +1554,7 @@ bool CSqlScore::LoadTeamThread(CSqlServer* pSqlServer, const CSqlData *pGameData
}

pSqlServer->GetResults()->getInt("Ago");
int since = (int)pSqlServer->GetResults()->getInt("Ago");
int since = pSqlServer->GetResults()->getInt("Ago");

if(since < g_Config.m_SvSaveGamesDelay)
{
Expand Down
1 change: 0 additions & 1 deletion src/game/teamscore.h
Expand Up @@ -36,7 +36,6 @@ class CTeamsCore
{
return m_IsSolo[ClientID];
}
;
};

#endif
5 changes: 0 additions & 5 deletions src/game/variables.h
Expand Up @@ -22,13 +22,8 @@ MACRO_CONFIG_INT(ClTextEntities, cl_text_entities, 1, 0, 1, CFGFLAG_CLIENT|CFGFL
MACRO_CONFIG_INT(ClAuthedPlayerColor, cl_authed_player_color, 5898183, 0, 0xFFFFFF, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Color of name of authenticated player in scoreboard")
MACRO_CONFIG_INT(ClSameClanColor, cl_same_clan_color, 5898183, 0, 0xFFFFFF, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Clan color of players with the same clan as you in scoreboard.")
MACRO_CONFIG_INT(ClEnablePingColor, cl_enable_ping_color, 1, 0, 1, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Whether ping is colored in scoreboard.")
#if defined(__ANDROID__)
MACRO_CONFIG_INT(ClAutoswitchWeapons, cl_autoswitch_weapons, 1, 0, 1, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Auto switch weapon on pickup")
MACRO_CONFIG_INT(ClAutoswitchWeaponsOutOfAmmo, cl_autoswitch_weapons_out_of_ammo, 1, 0, 1, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Auto switch weapon when out of ammo")
#else
MACRO_CONFIG_INT(ClAutoswitchWeapons, cl_autoswitch_weapons, 0, 0, 1, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Auto switch weapon on pickup")
MACRO_CONFIG_INT(ClAutoswitchWeaponsOutOfAmmo, cl_autoswitch_weapons_out_of_ammo, 0, 0, 1, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Auto switch weapon when out of ammo")
#endif

MACRO_CONFIG_INT(ClShowhud, cl_showhud, 1, 0, 1, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Show ingame HUD")
MACRO_CONFIG_INT(ClShowhudHealthAmmo, cl_showhud_healthammo, 1, 0, 1, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Show ingame HUD (Health + Ammo)")
Expand Down
6 changes: 3 additions & 3 deletions src/game/version.h
Expand Up @@ -2,9 +2,9 @@
/* If you are missing that file, acquire a complete release at teeworlds.com. */
#ifndef GAME_VERSION_H
#define GAME_VERSION_H
#define GAME_VERSION "0.6.4, 12.1"
#define GAME_VERSION "0.6.4, 12.2"
#define GAME_NETVERSION "0.6 626fce9a778df4d4"
#define GAME_RELEASE_VERSION "12.1"
#define CLIENT_VERSIONNR 12010
#define GAME_RELEASE_VERSION "12.2"
#define CLIENT_VERSIONNR 12020
extern const char *GIT_SHORTREV_HASH;
#endif
14 changes: 14 additions & 0 deletions src/test/str.cpp
Expand Up @@ -179,3 +179,17 @@ TEST(Str, StrFormat)
EXPECT_EQ(str_format(aBuf, 4, "%d: ", 99), 3);
EXPECT_STREQ(aBuf, "99:");
}

TEST(Str, StrCopyNum)
{
const char *foo = "Foobar";
char aBuf[64];
str_truncate(aBuf, 3, foo, 1);
EXPECT_STREQ(aBuf, "F");
str_truncate(aBuf, 3, foo, 2);
EXPECT_STREQ(aBuf, "Fo");
str_truncate(aBuf, 3, foo, 3);
EXPECT_STREQ(aBuf, "Fo");
str_truncate(aBuf, sizeof(aBuf), foo, 6);
EXPECT_STREQ(aBuf, "Foobar");
}