1#include <base/io.h>
2#include <base/time.h>
3
4#include <engine/graphics.h>
5#include <engine/serverbrowser.h>
6#include <engine/shared/config.h>
7#include <engine/storage.h>
8#include <engine/textrender.h>
9
10#include <generated/client_data.h>
11
12#include <game/client/animstate.h>
13#include <game/client/components/motd.h>
14#include <game/client/components/statboard.h>
15#include <game/client/gameclient.h>
16#include <game/localization.h>
17
18CStatboard::CStatboard()
19{
20 m_Active = false;
21 m_ScreenshotTaken = false;
22 m_ScreenshotTime = -1;
23}
24
25void CStatboard::OnReset()
26{
27 for(auto &Stat : GameClient()->m_aStats)
28 Stat.Reset();
29 m_Active = false;
30 m_ScreenshotTaken = false;
31 m_ScreenshotTime = -1;
32}
33
34void CStatboard::OnRelease()
35{
36 m_Active = false;
37}
38
39void CStatboard::ConKeyStats(IConsole::IResult *pResult, void *pUserData)
40{
41 ((CStatboard *)pUserData)->m_Active = pResult->GetInteger(Index: 0) != 0;
42}
43
44void CStatboard::OnConsoleInit()
45{
46 Console()->Register(pName: "+statboard", pParams: "", Flags: CFGFLAG_CLIENT, pfnFunc: ConKeyStats, pUser: this, pHelp: "Show stats");
47}
48
49bool CStatboard::IsActive() const
50{
51 return m_Active;
52}
53
54void CStatboard::OnMessage(int MsgType, void *pRawMsg)
55{
56 if(GameClient()->m_SuppressEvents)
57 return;
58
59 if(MsgType == NETMSGTYPE_SV_KILLMSG)
60 {
61 CNetMsg_Sv_KillMsg *pMsg = (CNetMsg_Sv_KillMsg *)pRawMsg;
62 CGameClient::CClientStats *pStats = GameClient()->m_aStats;
63
64 pStats[pMsg->m_Victim].m_Deaths++;
65 pStats[pMsg->m_Victim].m_CurrentSpree = 0;
66 if(pMsg->m_Weapon >= 0)
67 pStats[pMsg->m_Victim].m_aDeathsFrom[pMsg->m_Weapon]++;
68 if(pMsg->m_Victim != pMsg->m_Killer)
69 {
70 pStats[pMsg->m_Killer].m_Frags++;
71 pStats[pMsg->m_Killer].m_CurrentSpree++;
72
73 if(pStats[pMsg->m_Killer].m_CurrentSpree > pStats[pMsg->m_Killer].m_BestSpree)
74 pStats[pMsg->m_Killer].m_BestSpree = pStats[pMsg->m_Killer].m_CurrentSpree;
75 if(pMsg->m_Weapon >= 0)
76 pStats[pMsg->m_Killer].m_aFragsWith[pMsg->m_Weapon]++;
77 }
78 else
79 pStats[pMsg->m_Victim].m_Suicides++;
80 }
81 else if(MsgType == NETMSGTYPE_SV_KILLMSGTEAM)
82 {
83 CNetMsg_Sv_KillMsgTeam *pMsg = (CNetMsg_Sv_KillMsgTeam *)pRawMsg;
84 CGameClient::CClientStats *pStats = GameClient()->m_aStats;
85
86 for(int i = 0; i < MAX_CLIENTS; i++)
87 {
88 if(GameClient()->m_Teams.Team(ClientId: i) == pMsg->m_Team)
89 {
90 pStats[i].m_Deaths++;
91 pStats[i].m_Suicides++;
92 }
93 }
94 }
95 else if(MsgType == NETMSGTYPE_SV_CHAT)
96 {
97 CNetMsg_Sv_Chat *pMsg = (CNetMsg_Sv_Chat *)pRawMsg;
98 if(pMsg->m_ClientId < 0)
99 {
100 const char *p, *t;
101 const char *pLookFor = "flag was captured by '";
102 if((p = str_find(haystack: pMsg->m_pMessage, needle: pLookFor)))
103 {
104 char aName[MAX_NAME_LENGTH];
105 p += str_length(str: pLookFor);
106 t = str_rchr(haystack: p, needle: '\'');
107
108 if(t <= p)
109 return;
110 str_truncate(dst: aName, dst_size: sizeof(aName), src: p, truncation_len: t - p);
111
112 for(int i = 0; i < MAX_CLIENTS; i++)
113 {
114 if(!GameClient()->m_aStats[i].IsActive())
115 continue;
116
117 if(str_comp(a: GameClient()->m_aClients[i].m_aName, b: aName) == 0)
118 {
119 GameClient()->m_aStats[i].m_FlagCaptures++;
120 break;
121 }
122 }
123 }
124 }
125 }
126}
127
128void CStatboard::OnRender()
129{
130 if(Client()->State() != IClient::STATE_ONLINE && Client()->State() != IClient::STATE_DEMOPLAYBACK)
131 return;
132
133 if((g_Config.m_ClAutoStatboardScreenshot || g_Config.m_ClAutoCSV) && Client()->State() != IClient::STATE_DEMOPLAYBACK)
134 {
135 if(m_ScreenshotTime < 0 && GameClient()->m_Snap.m_pGameInfoObj && GameClient()->m_Snap.m_pGameInfoObj->m_GameStateFlags & GAMESTATEFLAG_GAMEOVER)
136 m_ScreenshotTime = time_get() + time_freq() * 3;
137 if(m_ScreenshotTime > -1 && m_ScreenshotTime < time_get())
138 m_Active = true;
139 if(!m_ScreenshotTaken && m_ScreenshotTime > -1 && m_ScreenshotTime + time_freq() / 5 < time_get())
140 {
141 if(g_Config.m_ClAutoStatboardScreenshot)
142 AutoStatScreenshot();
143 if(g_Config.m_ClAutoCSV)
144 AutoStatCSV();
145 m_ScreenshotTaken = true;
146 }
147 }
148
149 if(IsActive())
150 RenderGlobalStats();
151}
152
153void CStatboard::RenderGlobalStats()
154{
155 const float StatboardWidth = 400 * 3.0f * Graphics()->ScreenAspect();
156 const float StatboardHeight = 400 * 3.0f;
157 float StatboardContentWidth = 260.0f;
158 float StatboardContentHeight = 750.0f;
159
160 const CNetObj_PlayerInfo *apPlayers[MAX_CLIENTS] = {nullptr};
161 int NumPlayers = 0;
162
163 // sort red or dm players by score
164 for(const auto *pInfo : GameClient()->m_Snap.m_apInfoByScore)
165 {
166 if(!pInfo || !GameClient()->m_aStats[pInfo->m_ClientId].IsActive() || GameClient()->m_aClients[pInfo->m_ClientId].m_Team != TEAM_RED)
167 continue;
168 apPlayers[NumPlayers] = pInfo;
169 NumPlayers++;
170 }
171
172 // sort blue players by score after
173 if(GameClient()->IsTeamPlay())
174 {
175 for(const auto *pInfo : GameClient()->m_Snap.m_apInfoByScore)
176 {
177 if(!pInfo || !GameClient()->m_aStats[pInfo->m_ClientId].IsActive() || GameClient()->m_aClients[pInfo->m_ClientId].m_Team != TEAM_BLUE)
178 continue;
179 apPlayers[NumPlayers] = pInfo;
180 NumPlayers++;
181 }
182 }
183
184 // Dirty hack. Do not show scoreboard if there are more than 32 players
185 // remove as soon as support of more than 32 players is required
186 if(NumPlayers > 32)
187 return;
188
189 //clear motd if it is active
190 if(GameClient()->m_Motd.IsActive())
191 GameClient()->m_Motd.Clear();
192
193 bool GameWithFlags = GameClient()->m_Snap.m_pGameInfoObj &&
194 GameClient()->m_Snap.m_pGameInfoObj->m_GameFlags & GAMEFLAG_FLAGS;
195
196 StatboardContentWidth += 7 * 85 + 95; // Suicides 95; other labels 85
197
198 if(GameWithFlags)
199 StatboardContentWidth += 150; // Grabs & Flags
200
201 bool aDisplayWeapon[NUM_WEAPONS] = {false};
202 for(int i = 0; i < NumPlayers; i++)
203 {
204 const CGameClient::CClientStats *pStats = &GameClient()->m_aStats[apPlayers[i]->m_ClientId];
205 for(int j = 0; j < NUM_WEAPONS; j++)
206 aDisplayWeapon[j] = aDisplayWeapon[j] || pStats->m_aFragsWith[j] || pStats->m_aDeathsFrom[j];
207 }
208 for(bool DisplayWeapon : aDisplayWeapon)
209 if(DisplayWeapon)
210 StatboardContentWidth += 80;
211
212 float x = StatboardWidth / 2 - StatboardContentWidth / 2;
213 float y = 200.0f;
214
215 Graphics()->MapScreenToSize(Width: StatboardWidth, Height: StatboardHeight);
216
217 Graphics()->DrawRect(x: x - 10.f, y: y - 10.f, w: StatboardContentWidth, h: StatboardContentHeight, Color: ColorRGBA(0.0f, 0.0f, 0.0f, 0.5f), Corners: IGraphics::CORNER_ALL, Rounding: 17.0f);
218
219 int px = 325;
220
221 TextRender()->Text(x: x + 10, y: y - 5, Size: 22.0f, pText: Localize(pStr: "Name"), LineWidth: -1.0f);
222 const char *apHeaders[] = {
223 Localize(pStr: "Frags"), Localize(pStr: "Deaths"), Localize(pStr: "Suicides"),
224 Localize(pStr: "Ratio"), Localize(pStr: "Net"), Localize(pStr: "FPM"),
225 Localize(pStr: "Spree"), Localize(pStr: "Best"), Localize(pStr: "Grabs")};
226 for(int i = 0; i < 9; i++)
227 {
228 if(i == 2)
229 px += 10.0f; // Suicides
230 if(i == 8 && !GameWithFlags) // Don't draw "Grabs" in game with no flag
231 continue;
232 const float TextWidth = TextRender()->TextWidth(Size: 22.0f, pText: apHeaders[i], StrLength: -1, LineWidth: -1.0f);
233 TextRender()->Text(x: x + px - TextWidth, y: y - 5, Size: 22.0f, pText: apHeaders[i], LineWidth: -1.0f);
234 px += 85;
235 }
236
237 px -= 40;
238 for(int i = 0; i < NUM_WEAPONS; i++)
239 {
240 if(!aDisplayWeapon[i])
241 continue;
242 float ScaleX, ScaleY;
243 Graphics()->GetSpriteScale(pSprite: g_pData->m_Weapons.m_aId[i].m_pSpriteBody, ScaleX, ScaleY);
244 Graphics()->TextureSet(Texture: GameClient()->m_GameSkin.m_aSpriteWeapons[i]);
245 Graphics()->QuadsBegin();
246 if(i == 0)
247 Graphics()->DrawSprite(x: x + px, y: y + 10, ScaledWidth: g_pData->m_Weapons.m_aId[i].m_VisualSize * 0.8f * ScaleX, ScaledHeight: g_pData->m_Weapons.m_aId[i].m_VisualSize * 0.8f * ScaleY);
248 else
249 Graphics()->DrawSprite(x: x + px, y: y + 10, ScaledWidth: g_pData->m_Weapons.m_aId[i].m_VisualSize * ScaleX, ScaledHeight: g_pData->m_Weapons.m_aId[i].m_VisualSize * ScaleY);
250 px += 80;
251 Graphics()->QuadsEnd();
252 }
253
254 if(GameWithFlags)
255 {
256 Graphics()->TextureSet(Texture: GameClient()->m_GameSkin.m_SpriteFlagRed);
257 float ScaleX, ScaleY;
258 Graphics()->GetSpriteScale(Id: SPRITE_FLAG_RED, ScaleX, ScaleY);
259 Graphics()->QuadsBegin();
260 Graphics()->QuadsSetRotation(Angle: 0.78f);
261 Graphics()->DrawSprite(x: x + px, y: y + 15, ScaledWidth: 48 * ScaleX, ScaledHeight: 48 * ScaleY);
262 Graphics()->QuadsEnd();
263 }
264
265 y += 29.0f;
266
267 float FontSize = 24.0f;
268 float LineHeight = 50.0f;
269 float TeeSizemod = 0.8f;
270 float ContentLineOffset = LineHeight * 0.05f;
271
272 if(NumPlayers > 16)
273 {
274 FontSize = 20.0f;
275 LineHeight = 22.0f;
276 TeeSizemod = 0.34f;
277 ContentLineOffset = 0;
278 }
279 else if(NumPlayers > 14)
280 {
281 FontSize = 24.0f;
282 LineHeight = 40.0f;
283 TeeSizemod = 0.7f;
284 }
285
286 for(int j = 0; j < NumPlayers; j++)
287 {
288 const CNetObj_PlayerInfo *pInfo = apPlayers[j];
289 const CGameClient::CClientStats *pStats = &GameClient()->m_aStats[pInfo->m_ClientId];
290
291 if(GameClient()->m_Snap.m_LocalClientId == pInfo->m_ClientId || (GameClient()->m_Snap.m_SpecInfo.m_Active && pInfo->m_ClientId == GameClient()->m_Snap.m_SpecInfo.m_SpectatorId))
292 {
293 // background so it's easy to find the local player
294 Graphics()->DrawRect(x: x - 10, y: y + ContentLineOffset / 2, w: StatboardContentWidth, h: LineHeight - ContentLineOffset, Color: ColorRGBA(1.0f, 1.0f, 1.0f, 0.25f), Corners: IGraphics::CORNER_NONE, Rounding: 0.0f);
295 }
296
297 CTeeRenderInfo Teeinfo = GameClient()->m_aClients[pInfo->m_ClientId].m_RenderInfo;
298 Teeinfo.m_Size *= TeeSizemod;
299
300 RenderTools()->RenderIdleTeeAtCenter(pInfo: &Teeinfo, Center: vec2(x + Teeinfo.m_Size / 2, y + LineHeight / 2.0f));
301
302 char aBuf[128];
303 CTextCursor Cursor;
304 Cursor.SetPosition(vec2(x + 64, y + (LineHeight * 0.95f - FontSize) / 2.f));
305 Cursor.m_FontSize = FontSize;
306 Cursor.m_Flags |= TEXTFLAG_STOP_AT_END;
307 Cursor.m_LineWidth = 220;
308 TextRender()->TextEx(pCursor: &Cursor, pText: GameClient()->m_aClients[pInfo->m_ClientId].m_aName, Length: -1);
309
310 px = 325;
311
312 // FRAGS
313 {
314 str_format(buffer: aBuf, buffer_size: sizeof(aBuf), format: "%d", pStats->m_Frags);
315 const float TextWidth = TextRender()->TextWidth(Size: FontSize, pText: aBuf, StrLength: -1, LineWidth: -1.0f);
316 TextRender()->Text(x: x - TextWidth + px, y: y + (LineHeight * 0.95f - FontSize) / 2.f, Size: FontSize, pText: aBuf, LineWidth: -1.0f);
317 px += 85;
318 }
319 // DEATHS
320 {
321 str_format(buffer: aBuf, buffer_size: sizeof(aBuf), format: "%d", pStats->m_Deaths);
322 const float TextWidth = TextRender()->TextWidth(Size: FontSize, pText: aBuf, StrLength: -1, LineWidth: -1.0f);
323 TextRender()->Text(x: x - TextWidth + px, y: y + (LineHeight * 0.95f - FontSize) / 2.f, Size: FontSize, pText: aBuf, LineWidth: -1.0f);
324 px += 85;
325 }
326 // SUICIDES
327 {
328 px += 10;
329 str_format(buffer: aBuf, buffer_size: sizeof(aBuf), format: "%d", pStats->m_Suicides);
330 const float TextWidth = TextRender()->TextWidth(Size: FontSize, pText: aBuf, StrLength: -1, LineWidth: -1.0f);
331 TextRender()->Text(x: x - TextWidth + px, y: y + (LineHeight * 0.95f - FontSize) / 2.f, Size: FontSize, pText: aBuf, LineWidth: -1.0f);
332 px += 85;
333 }
334 // RATIO
335 {
336 if(pStats->m_Deaths == 0)
337 str_copy(dst&: aBuf, src: "--");
338 else
339 str_format(buffer: aBuf, buffer_size: sizeof(aBuf), format: "%.2f", (float)(pStats->m_Frags) / pStats->m_Deaths);
340 const float TextWidth = TextRender()->TextWidth(Size: FontSize, pText: aBuf, StrLength: -1, LineWidth: -1.0f);
341 TextRender()->Text(x: x - TextWidth + px, y: y + (LineHeight * 0.95f - FontSize) / 2.f, Size: FontSize, pText: aBuf, LineWidth: -1.0f);
342 px += 85;
343 }
344 // NET
345 {
346 str_format(buffer: aBuf, buffer_size: sizeof(aBuf), format: "%+d", pStats->m_Frags - pStats->m_Deaths);
347 const float TextWidth = TextRender()->TextWidth(Size: FontSize, pText: aBuf, StrLength: -1, LineWidth: -1.0f);
348 TextRender()->Text(x: x - TextWidth + px, y: y + (LineHeight * 0.95f - FontSize) / 2.f, Size: FontSize, pText: aBuf, LineWidth: -1.0f);
349 px += 85;
350 }
351 // FPM
352 {
353 float Fpm = pStats->GetFPM(Tick: Client()->GameTick(Conn: g_Config.m_ClDummy), TickSpeed: Client()->GameTickSpeed());
354 str_format(buffer: aBuf, buffer_size: sizeof(aBuf), format: "%.1f", Fpm);
355 const float TextWidth = TextRender()->TextWidth(Size: FontSize, pText: aBuf, StrLength: -1, LineWidth: -1.0f);
356 TextRender()->Text(x: x - TextWidth + px, y: y + (LineHeight * 0.95f - FontSize) / 2.f, Size: FontSize, pText: aBuf, LineWidth: -1.0f);
357 px += 85;
358 }
359 // SPREE
360 {
361 str_format(buffer: aBuf, buffer_size: sizeof(aBuf), format: "%d", pStats->m_CurrentSpree);
362 const float TextWidth = TextRender()->TextWidth(Size: FontSize, pText: aBuf, StrLength: -1, LineWidth: -1.0f);
363 TextRender()->Text(x: x - TextWidth + px, y: y + (LineHeight * 0.95f - FontSize) / 2.f, Size: FontSize, pText: aBuf, LineWidth: -1.0f);
364 px += 85;
365 }
366 // BEST SPREE
367 {
368 str_format(buffer: aBuf, buffer_size: sizeof(aBuf), format: "%d", pStats->m_BestSpree);
369 const float TextWidth = TextRender()->TextWidth(Size: FontSize, pText: aBuf, StrLength: -1, LineWidth: -1.0f);
370 TextRender()->Text(x: x - TextWidth + px, y: y + (LineHeight * 0.95f - FontSize) / 2.f, Size: FontSize, pText: aBuf, LineWidth: -1.0f);
371 px += 85;
372 }
373 // GRABS
374 if(GameWithFlags)
375 {
376 str_format(buffer: aBuf, buffer_size: sizeof(aBuf), format: "%d", pStats->m_FlagGrabs);
377 const float TextWidth = TextRender()->TextWidth(Size: FontSize, pText: aBuf, StrLength: -1, LineWidth: -1.0f);
378 TextRender()->Text(x: x - TextWidth + px, y: y + (LineHeight * 0.95f - FontSize) / 2.f, Size: FontSize, pText: aBuf, LineWidth: -1.0f);
379 px += 85;
380 }
381 // WEAPONS
382 px -= 40;
383 for(int i = 0; i < NUM_WEAPONS; i++)
384 {
385 if(!aDisplayWeapon[i])
386 continue;
387
388 str_format(buffer: aBuf, buffer_size: sizeof(aBuf), format: "%d/%d", pStats->m_aFragsWith[i], pStats->m_aDeathsFrom[i]);
389 const float TextWidth = TextRender()->TextWidth(Size: FontSize, pText: aBuf, StrLength: -1, LineWidth: -1.0f);
390 TextRender()->Text(x: x + px - TextWidth / 2, y: y + (LineHeight * 0.95f - FontSize) / 2.f, Size: FontSize, pText: aBuf, LineWidth: -1.0f);
391 px += 80;
392 }
393 // FLAGS
394 if(GameWithFlags)
395 {
396 str_format(buffer: aBuf, buffer_size: sizeof(aBuf), format: "%d", pStats->m_FlagCaptures);
397 const float TextWidth = TextRender()->TextWidth(Size: FontSize, pText: aBuf, StrLength: -1, LineWidth: -1.0f);
398 TextRender()->Text(x: x - TextWidth + px, y: y + (LineHeight * 0.95f - FontSize) / 2.f, Size: FontSize, pText: aBuf, LineWidth: -1.0f);
399 }
400 y += LineHeight;
401 }
402}
403
404void CStatboard::AutoStatScreenshot()
405{
406 if(Client()->State() != IClient::STATE_DEMOPLAYBACK)
407 Client()->AutoStatScreenshot_Start();
408}
409
410void CStatboard::AutoStatCSV()
411{
412 if(Client()->State() != IClient::STATE_DEMOPLAYBACK)
413 {
414 char aDate[20], aFilename[IO_MAX_PATH_LENGTH];
415 str_timestamp(buffer: aDate, buffer_size: sizeof(aDate));
416 str_format(buffer: aFilename, buffer_size: sizeof(aFilename), format: "screenshots/auto/stats_%s.csv", aDate);
417 IOHANDLE File = Storage()->OpenFile(pFilename: aFilename, Flags: IOFLAG_WRITE, Type: IStorage::TYPE_SAVE);
418
419 if(File)
420 {
421 char aStats[1024 * (VANILLA_MAX_CLIENTS + 1)];
422 FormatStats(pDest: aStats, DestSize: sizeof(aStats));
423 io_write(io: File, buffer: aStats, size: str_length(str: aStats));
424 io_close(io: File);
425 }
426
427 Client()->AutoCSV_Start();
428 }
429}
430
431std::string CStatboard::ReplaceCommata(const char *pStr)
432{
433 if(!str_find(haystack: pStr, needle: ","))
434 return pStr;
435
436 char aOutbuf[256] = "";
437 for(int i = 0, Skip = 0; i < 64; i++)
438 {
439 if(pStr[i] == ',')
440 {
441 aOutbuf[i + Skip++] = '%';
442 aOutbuf[i + Skip++] = '2';
443 aOutbuf[i + Skip] = 'C';
444 }
445 else
446 aOutbuf[i + Skip] = pStr[i];
447 }
448 return aOutbuf;
449}
450
451void CStatboard::FormatStats(char *pDest, size_t DestSize)
452{
453 // server stats
454 const CServerInfo &CurrentServerInfo = Client()->ServerInfo();
455
456 char aServerStats[1024];
457 str_format(buffer: aServerStats, buffer_size: sizeof(aServerStats), format: "Servername,Game-type,Map\n%s,%s,%s", ReplaceCommata(pStr: CurrentServerInfo.m_aName).c_str(), ReplaceCommata(pStr: CurrentServerInfo.m_aGameType).c_str(), ReplaceCommata(pStr: CurrentServerInfo.m_aMap).c_str());
458
459 // player stats
460
461 // sort players
462 const CNetObj_PlayerInfo *apPlayers[MAX_CLIENTS] = {nullptr};
463 int NumPlayers = 0;
464
465 // sort red or dm players by score
466 for(const auto *pInfo : GameClient()->m_Snap.m_apInfoByScore)
467 {
468 if(!pInfo || !GameClient()->m_aStats[pInfo->m_ClientId].IsActive() || GameClient()->m_aClients[pInfo->m_ClientId].m_Team != TEAM_RED)
469 continue;
470 apPlayers[NumPlayers] = pInfo;
471 NumPlayers++;
472 }
473
474 // sort blue players by score after
475 if(GameClient()->IsTeamPlay())
476 {
477 for(const auto *pInfo : GameClient()->m_Snap.m_apInfoByScore)
478 {
479 if(!pInfo || !GameClient()->m_aStats[pInfo->m_ClientId].IsActive() || GameClient()->m_aClients[pInfo->m_ClientId].m_Team != TEAM_BLUE)
480 continue;
481 apPlayers[NumPlayers] = pInfo;
482 NumPlayers++;
483 }
484 }
485
486 char aPlayerStats[1024 * VANILLA_MAX_CLIENTS] = "Local-player,Team,Name,Clan,Score,Frags,Deaths,Suicides,F/D-ratio,Net,FPM,Spree,Best,Hammer-F/D,Gun-F/D,Shotgun-F/D,Grenade-F/D,Laser-F/D,Ninja-F/D,GameWithFlags,Flag-grabs,Flag-captures\n";
487 for(int i = 0; i < NumPlayers; i++)
488 {
489 const CNetObj_PlayerInfo *pInfo = apPlayers[i];
490 const CGameClient::CClientStats *pStats = &GameClient()->m_aStats[pInfo->m_ClientId];
491
492 // Pre-formatting
493
494 // Weapons frags/deaths
495 char aWeaponFD[64 * NUM_WEAPONS];
496 for(int j = 0; j < NUM_WEAPONS; j++)
497 {
498 if(j == 0)
499 str_format(buffer: aWeaponFD, buffer_size: sizeof(aWeaponFD), format: "%d/%d", pStats->m_aFragsWith[j], pStats->m_aDeathsFrom[j]);
500 else
501 str_format(buffer: aWeaponFD, buffer_size: sizeof(aWeaponFD), format: "%s,%d/%d", aWeaponFD, pStats->m_aFragsWith[j], pStats->m_aDeathsFrom[j]);
502 }
503
504 // Frag/Death ratio
505 float KillRatio = 0.0f;
506 if(pStats->m_Deaths != 0)
507 KillRatio = (float)(pStats->m_Frags) / pStats->m_Deaths;
508
509 // Local player
510 bool LocalPlayer = (GameClient()->m_Snap.m_LocalClientId == pInfo->m_ClientId || (GameClient()->m_Snap.m_SpecInfo.m_Active && pInfo->m_ClientId == GameClient()->m_Snap.m_SpecInfo.m_SpectatorId));
511
512 // Game with flags
513 bool GameWithFlags = (GameClient()->m_Snap.m_pGameInfoObj && GameClient()->m_Snap.m_pGameInfoObj->m_GameFlags & GAMEFLAG_FLAGS);
514
515 char aBuf[1024];
516 str_format(buffer: aBuf, buffer_size: sizeof(aBuf), format: "%d,%d,%s,%s,%d,%d,%d,%d,%.2f,%i,%.1f,%d,%d,%s,%d,%d,%d\n",
517 LocalPlayer ? 1 : 0, // Local player
518 GameClient()->m_aClients[pInfo->m_ClientId].m_Team, // Team
519 ReplaceCommata(pStr: GameClient()->m_aClients[pInfo->m_ClientId].m_aName).c_str(), // Name
520 ReplaceCommata(pStr: GameClient()->m_aClients[pInfo->m_ClientId].m_aClan).c_str(), // Clan
521 std::clamp(val: pInfo->m_Score, lo: -999, hi: 999), // Score
522 pStats->m_Frags, // Frags
523 pStats->m_Deaths, // Deaths
524 pStats->m_Suicides, // Suicides
525 KillRatio, // Kill ratio
526 pStats->m_Frags - pStats->m_Deaths, // Net
527 pStats->GetFPM(Tick: Client()->GameTick(Conn: g_Config.m_ClDummy), TickSpeed: Client()->GameTickSpeed()), // FPM
528 pStats->m_CurrentSpree, // CurSpree
529 pStats->m_BestSpree, // BestSpree
530 aWeaponFD, // WeaponFD
531 GameWithFlags ? 1 : 0, // GameWithFlags
532 pStats->m_FlagGrabs, // Flag grabs
533 pStats->m_FlagCaptures); // Flag captures
534
535 str_append(dst&: aPlayerStats, src: aBuf);
536 }
537
538 str_format(buffer: pDest, buffer_size: DestSize, format: "%s\n\n%s", aServerStats, aPlayerStats);
539}
540