2923: Don't str_copy into string itself r=Learath2 a=def-

when reconnecting after server was full:

[2020-09-25 15:39:34][client]: offline error='This server is full'
Source and destination overlap in strncpy(0xd3328e2, 0xd3328e2, 255)
   at 0x483DFDC: strncpy (vg_replace_strmem.c:550)
   by 0x249180: str_copy (system.c:2328)
   by 0x27E1F5: CClient::Connect(char const*, char const*) (client.cpp:707)
   by 0x287864: CClient::Update() (client.cpp:2914)
   by 0x28891B: CClient::Run() (client.cpp:3216)
   by 0x28EDEC: main (client.cpp:4309)

2924: Fix Score/Time alignment r=def- a=Learath2

![screenshot_2020-09-25_16-52-30](https://user-images.githubusercontent.com/490500/94275676-e81dfc80-ff4f-11ea-9f21-dbf5d1cf73a9.png)

Also adds hours to the time

Co-authored-by: def <dennis@felsin9.de>
Co-authored-by: Learath <learath2@gmail.com>
This commit is contained in:
bors[bot] 2020-09-25 14:55:51 +00:00 committed by GitHub
commit 5f6ba345b8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 20 deletions

View file

@ -704,7 +704,8 @@ void CClient::Connect(const char *pAddress, const char *pPassword)
Disconnect();
m_ConnectionID = RandomUuid();
str_copy(m_aServerAddressStr, pAddress, sizeof(m_aServerAddressStr));
if(pAddress != m_aServerAddressStr)
str_copy(m_aServerAddressStr, pAddress, sizeof(m_aServerAddressStr));
str_format(aBuf, sizeof(aBuf), "connecting to '%s'", m_aServerAddressStr);
m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "client", aBuf);

View file

@ -285,20 +285,25 @@ void CScoreboard::RenderScoreboard(float x, float y, float w, int Team, const ch
RoundRadius = 15.0f;
}
float ScoreOffset = x+10.0f, ScoreLength = TextRender()->TextWidth(0, 22.0f/*HeadlineFontsize*/, "00:00:0", -1, -1.0f);
float TeeOffset = ScoreOffset+ScoreLength, TeeLength = 60*TeeSizeMod;
float NameOffset = TeeOffset+TeeLength, NameLength = 300.0f-TeeLength;
float PingOffset = x+610.0f, PingLength = 65.0f;
float CountryOffset = PingOffset-(LineHeight-Spacing-TeeSizeMod*5.0f)*2.0f, CountryLength = (LineHeight-Spacing-TeeSizeMod*5.0f)*2.0f;
float ClanOffset = x+360.0f, ClanLength = 240.0f-CountryLength;
float FontSize = 24.0f;
if(m_pClient->m_Snap.m_aTeamSize[Team] > 48)
FontSize = 16.0f;
else if(m_pClient->m_Snap.m_aTeamSize[Team] > 32)
FontSize = 20.0f;
float ScoreOffset = x + 10.0f, ScoreLength = TextRender()->TextWidth(0, FontSize, "00:00:00", -1, -1.0f);
float TeeOffset = ScoreOffset + ScoreLength + 15.0f, TeeLength = 60 * TeeSizeMod;
float NameOffset = TeeOffset + TeeLength, NameLength = 300.0f - TeeLength;
float PingOffset = x + 610.0f, PingLength = 65.0f;
float CountryOffset = PingOffset - (LineHeight - Spacing - TeeSizeMod * 5.0f) * 2.0f, CountryLength = (LineHeight - Spacing - TeeSizeMod * 5.0f) * 2.0f;
float ClanOffset = x + 360.0f, ClanLength = 240.0f - CountryLength;
// render headlines
y += 50.0f;
float HeadlineFontsize = 22.0f;
const char *pScore = (m_pClient->m_GameInfo.m_TimeScore && g_Config.m_ClDDRaceScoreBoard) ? Localize("Time") : Localize("Score");
float ScoreWidth = TextRender()->TextWidth(0, HeadlineFontsize, pScore, -1, -1.0f);
tw = ScoreLength > ScoreWidth ? ScoreLength : ScoreWidth;
TextRender()->Text(0, ScoreOffset+ScoreLength-tw, y + (HeadlineFontsize * 2.f - HeadlineFontsize) / 2.f, HeadlineFontsize, pScore, -1.0f);
tw = TextRender()->TextWidth(0, HeadlineFontsize, pScore, -1, -1.0f);
TextRender()->Text(0, ScoreOffset + ScoreLength - tw, y + (HeadlineFontsize * 2.f - HeadlineFontsize) / 2.f, HeadlineFontsize, pScore, -1.0f);
TextRender()->Text(0, NameOffset, y + (HeadlineFontsize * 2.f - HeadlineFontsize) / 2.f, HeadlineFontsize, Localize("Name"), -1.0f);
@ -309,12 +314,7 @@ void CScoreboard::RenderScoreboard(float x, float y, float w, int Team, const ch
TextRender()->Text(0, PingOffset+PingLength-tw, y + (HeadlineFontsize * 2.f - HeadlineFontsize) / 2.f, HeadlineFontsize, Localize("Ping"), -1.0f);
// render player entries
y += HeadlineFontsize*2.0f;
float FontSize = 24.0f;
if(m_pClient->m_Snap.m_aTeamSize[Team] > 48)
FontSize = 16.0f;
else if(m_pClient->m_Snap.m_aTeamSize[Team] > 32)
FontSize = 20.0f;
y += HeadlineFontsize * 2.0f;
CTextCursor Cursor;
int rendered = 0;
@ -422,7 +422,10 @@ void CScoreboard::RenderScoreboard(float x, float y, float w, int Team, const ch
else
{
int Time = abs(pInfo->m_Score);
str_format(aBuf, sizeof(aBuf), "%02d:%02d", Time/60, Time%60);
if(Time / 3600)
str_format(aBuf, sizeof(aBuf), "%02d:%02d:%02d", Time / 3600, (Time / 60) % 60, Time % 60);
else
str_format(aBuf, sizeof(aBuf), "%02d:%02d", Time / 60, Time % 60);
}
}
else
@ -464,9 +467,8 @@ void CScoreboard::RenderScoreboard(float x, float y, float w, int Team, const ch
if(g_Config.m_ClShowIDs)
{
char aId[64] = "";
str_format(aId, sizeof(aId),"%2d: ", pInfo->m_ClientID);
str_append(aId, m_pClient->m_aClients[pInfo->m_ClientID].m_aName,sizeof(aId));
Cursor.m_LineWidth = NameLength+8;
str_format(aId, sizeof(aId), "%2d: %s", pInfo->m_ClientID, m_pClient->m_aClients[pInfo->m_ClientID].m_aName);
Cursor.m_LineWidth = NameLength;
TextRender()->TextEx(&Cursor, aId, -1);
}
else