From 0bac9f0de8a28b5d125689d32839347bfd1c14b4 Mon Sep 17 00:00:00 2001 From: def Date: Fri, 25 Sep 2020 18:11:59 +0200 Subject: [PATCH] Manual preparation for cleaner clang-format Also include what you use explicitly --- .clang-format | 6 +- src/antibot/antibot_data.h | 6 +- src/antibot/antibot_null.cpp | 26 ++--- src/base/system.c | 5 +- src/engine/client/backend_sdl.cpp | 2 +- src/engine/client/client.cpp | 14 +-- src/engine/client/demoedit.h | 2 + src/engine/client/graphics_threaded.cpp | 3 +- src/engine/demo.h | 7 +- src/engine/external/.clang-format | 3 + src/engine/kernel.h | 7 -- src/engine/server/databases/connection.cpp | 86 +++++++------- src/engine/server/register.h | 1 + src/game/client/animstate.h | 2 + src/game/client/components/ghost.h | 1 + src/game/extrainfo.h | 2 + src/game/server/entities/gun.cpp | 6 +- src/game/server/entities/projectile.h | 2 + src/game/server/gamecontext.h | 2 + src/game/server/score.cpp | 126 ++++++++++----------- src/game/server/teehistorian.cpp | 27 +++-- src/test/teehistorian.cpp | 12 +- src/tools/crapnet.cpp | 2 +- 23 files changed, 178 insertions(+), 172 deletions(-) create mode 100644 src/engine/external/.clang-format diff --git a/.clang-format b/.clang-format index 86a3a921d..0e478c288 100644 --- a/.clang-format +++ b/.clang-format @@ -2,12 +2,16 @@ Language: Cpp AccessModifierOffset: -8 AlignAfterOpenBracket: DontAlign +AlignEscapedNewlines: DontAlign AlignTrailingComments: false -AllowShortFunctionsOnASingleLine: Inline +AllowShortBlocksOnASingleLine: Always +AllowShortCaseLabelsOnASingleLine: true +AllowShortFunctionsOnASingleLine: All AlwaysBreakTemplateDeclarations: true BasedOnStyle: LLVM BreakBeforeBraces: Custom BreakBeforeTernaryOperators: false +BreakConstructorInitializers: AfterColon BreakStringLiterals: true BraceWrapping: AfterCaseLabel: true diff --git a/src/antibot/antibot_data.h b/src/antibot/antibot_data.h index 811210502..02d9b3978 100644 --- a/src/antibot/antibot_data.h +++ b/src/antibot/antibot_data.h @@ -30,9 +30,9 @@ struct CAntibotInputData // Defined by the network protocol, unlikely to change. //enum //{ - //TEAM_SPECTATORS=-1, - //TEAM_RED=0, - //TEAM_BLUE=1, +// TEAM_SPECTATORS=-1, +// TEAM_RED=0, +// TEAM_BLUE=1, //}; struct CAntibotCharacterData diff --git a/src/antibot/antibot_null.cpp b/src/antibot/antibot_null.cpp index aa8ffef2c..00d3cde43 100644 --- a/src/antibot/antibot_null.cpp +++ b/src/antibot/antibot_null.cpp @@ -22,18 +22,18 @@ void AntibotDump(void) { g_pData->m_pfnLog("null antibot", g_pData->m_pUser); } -void AntibotOnPlayerInit(int ClientID) { (void)ClientID; } -void AntibotOnPlayerDestroy(int ClientID) { (void)ClientID; } -void AntibotOnSpawn(int ClientID) { (void)ClientID; } -void AntibotOnHammerFireReloading(int ClientID) { (void)ClientID; } -void AntibotOnHammerFire(int ClientID) { (void)ClientID; } -void AntibotOnHammerHit(int ClientID) { (void)ClientID; } -void AntibotOnDirectInput(int ClientID) { (void)ClientID; } -void AntibotOnCharacterTick(int ClientID) { (void)ClientID; } -void AntibotOnHookAttach(int ClientID, bool Player) { (void)ClientID; (void)Player; } -void AntibotOnEngineTick(void) { } -void AntibotOnEngineClientJoin(int ClientID, bool Sixup) { (void)ClientID; (void)Sixup; } -void AntibotOnEngineClientDrop(int ClientID, const char *pReason) { (void)ClientID; (void)pReason; } -void AntibotOnEngineClientMessage(int ClientID, const void *pData, int Size, int Flags) { (void)ClientID; (void)pData; (void)Size; (void)Flags; } +void AntibotOnPlayerInit(int /*ClientID*/) {} +void AntibotOnPlayerDestroy(int /*ClientID*/) {} +void AntibotOnSpawn(int /*ClientID*/) {} +void AntibotOnHammerFireReloading(int /*ClientID*/) {} +void AntibotOnHammerFire(int /*ClientID*/) {} +void AntibotOnHammerHit(int /*ClientID*/) {} +void AntibotOnDirectInput(int /*ClientID*/) {} +void AntibotOnCharacterTick(int /*ClientID*/) {} +void AntibotOnHookAttach(int /*ClientID*/, bool /*Player*/) {} +void AntibotOnEngineTick(void) {} +void AntibotOnEngineClientJoin(int /*ClientID*/, bool /*Sixup*/) {} +void AntibotOnEngineClientDrop(int /*ClientID*/, const char * /*pReason*/) {} +void AntibotOnEngineClientMessage(int /*ClientID*/, const void * /*pData*/, int /*Size*/, int /*Flags*/) {} } diff --git a/src/base/system.c b/src/base/system.c index 48d693c90..b9f9908bb 100644 --- a/src/base/system.c +++ b/src/base/system.c @@ -52,6 +52,7 @@ #include #include #include + #include #include #include @@ -3335,8 +3336,8 @@ int os_is_winxp_or_lower(void) mem_zero(&ver, sizeof(OSVERSIONINFO)); ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); GetVersionEx(&ver); - return ver.dwMajorVersion < WINXP_MAJOR - || (ver.dwMajorVersion == WINXP_MAJOR && ver.dwMinorVersion <= WINXP_MINOR); + return ver.dwMajorVersion < WINXP_MAJOR || + (ver.dwMajorVersion == WINXP_MAJOR && ver.dwMinorVersion <= WINXP_MINOR); #else return 0; #endif diff --git a/src/engine/client/backend_sdl.cpp b/src/engine/client/backend_sdl.cpp index 1f026b474..4ed003d67 100644 --- a/src/engine/client/backend_sdl.cpp +++ b/src/engine/client/backend_sdl.cpp @@ -3651,7 +3651,7 @@ static void ParseVersionString(const GLubyte* pStr, int& VersionMajor, int& Vers char aCurNumberStr[32]; size_t CurNumberStrLen = 0; size_t TotalNumbersPassed = 0; - int aNumbers[3] = { 0, }; + int aNumbers[3] = { 0 }; bool LastWasNumber = false; while(*pStr && TotalNumbersPassed < 3) { diff --git a/src/engine/client/client.cpp b/src/engine/client/client.cpp index 80bf2b907..f39e16f60 100644 --- a/src/engine/client/client.cpp +++ b/src/engine/client/client.cpp @@ -1380,8 +1380,8 @@ void CClient::ProcessServerInfo(int RawType, NETADDR *pFrom, const void *pData, CServerInfo Info = {0}; int SavedType = SavedServerInfoType(RawType); - if((SavedType == SERVERINFO_64_LEGACY || SavedType == SERVERINFO_EXTENDED) - && pEntry && pEntry->m_GotInfo && SavedType == pEntry->m_Info.m_Type) + if((SavedType == SERVERINFO_64_LEGACY || SavedType == SERVERINFO_EXTENDED) && + pEntry && pEntry->m_GotInfo && SavedType == pEntry->m_Info.m_Type) { Info = pEntry->m_Info; } @@ -2527,8 +2527,8 @@ void CClient::PumpNetwork() m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "client", aBuf); } - if(State() != IClient::STATE_OFFLINE && State() < IClient::STATE_QUITING && m_DummyConnected - && m_NetClient[CLIENT_DUMMY].State() == NETSTATE_OFFLINE) + if(State() != IClient::STATE_OFFLINE && State() < IClient::STATE_QUITING && m_DummyConnected && + m_NetClient[CLIENT_DUMMY].State() == NETSTATE_OFFLINE) { DummyDisconnect(0); char aBuf[256]; @@ -3219,9 +3219,9 @@ void CClient::Run() bool IsRenderActive = (g_Config.m_GfxBackgroundRender || m_pGraphics->WindowOpen()); - if(IsRenderActive - && (!g_Config.m_GfxAsyncRenderOld || m_pGraphics->IsIdle()) - && (!g_Config.m_GfxRefreshRate || (time_freq() / (int64)g_Config.m_GfxRefreshRate) <= Now - LastRenderTime)) + if(IsRenderActive && + (!g_Config.m_GfxAsyncRenderOld || m_pGraphics->IsIdle()) && + (!g_Config.m_GfxRefreshRate || (time_freq() / (int64)g_Config.m_GfxRefreshRate) <= Now - LastRenderTime)) { m_RenderFrames++; diff --git a/src/engine/client/demoedit.h b/src/engine/client/demoedit.h index 8838f73c4..9eb91caca 100644 --- a/src/engine/client/demoedit.h +++ b/src/engine/client/demoedit.h @@ -2,6 +2,8 @@ #define ENGINE_CLIENT_DEMOEDIT_H #include +#include +#include #define CONNECTLINK "ddnet:" diff --git a/src/engine/client/graphics_threaded.cpp b/src/engine/client/graphics_threaded.cpp index 60039ae9f..a8478ddcb 100644 --- a/src/engine/client/graphics_threaded.cpp +++ b/src/engine/client/graphics_threaded.cpp @@ -2091,8 +2091,7 @@ int CGraphics_Threaded::Init() 0xff,0x00,0x00,0xff, 0xff,0x00,0x00,0xff, 0x00,0xff,0x00,0xff, 0x00,0xff,0x00,0xff, 0xff,0x00,0x00,0xff, 0xff,0x00,0x00,0xff, 0x00,0xff,0x00,0xff, 0x00,0xff,0x00,0xff, 0x00,0x00,0xff,0xff, 0x00,0x00,0xff,0xff, 0xff,0xff,0x00,0xff, 0xff,0xff,0x00,0xff, - 0x00,0x00,0xff,0xff, 0x00,0x00,0xff,0xff, 0xff,0xff,0x00,0xff, 0xff,0xff,0x00,0xff, - }; + 0x00,0x00,0xff,0xff, 0x00,0x00,0xff,0xff, 0xff,0xff,0x00,0xff, 0xff,0xff,0x00,0xff}; m_InvalidTexture = LoadTextureRaw(4,4,CImageInfo::FORMAT_RGBA,s_aNullTextureData,CImageInfo::FORMAT_RGBA,TEXLOAD_NORESAMPLE); return 0; diff --git a/src/engine/demo.h b/src/engine/demo.h index 721155aeb..015ec6e89 100644 --- a/src/engine/demo.h +++ b/src/engine/demo.h @@ -18,12 +18,11 @@ const double g_aSpeeds[] = {0.1, 0.25, 0.5, 0.75, 1.0, 1.25, 1.5, 2.0, 3.0, 4.0, typedef bool (*DEMOFUNC_FILTER)(const void *pData, int DataSize, void *pUser); // TODO: Properly extend demo format using uuids +// "6be6da4a-cebd-380c-9b5b-1289c842d780" +// "demoitem-sha256@ddnet.tw" static const CUuid SHA256_EXTENSION = {{ - // "6be6da4a-cebd-380c-9b5b-1289c842d780" - // "demoitem-sha256@ddnet.tw" 0x6b, 0xe6, 0xda, 0x4a, 0xce, 0xbd, 0x38, 0x0c, - 0x9b, 0x5b, 0x12, 0x89, 0xc8, 0x42, 0xd7, 0x80 -}}; + 0x9b, 0x5b, 0x12, 0x89, 0xc8, 0x42, 0xd7, 0x80}}; struct CDemoHeader { diff --git a/src/engine/external/.clang-format b/src/engine/external/.clang-format new file mode 100644 index 000000000..259fe7fbe --- /dev/null +++ b/src/engine/external/.clang-format @@ -0,0 +1,3 @@ +DisableFormat: true +# clang-format bug: still sorts includes even if disabled +SortIncludes: false diff --git a/src/engine/kernel.h b/src/engine/kernel.h index 235ccb945..736f27719 100644 --- a/src/engine/kernel.h +++ b/src/engine/kernel.h @@ -18,9 +18,6 @@ protected: public: IInterface() : m_pKernel(0) {} virtual ~IInterface() {} - - //virtual unsigned InterfaceID() = 0; - //virtual const char *InterfaceName() = 0; }; #define MACRO_INTERFACE(Name, ver) \ @@ -28,10 +25,6 @@ public: static const char *InterfaceName() { return Name; } \ private: - //virtual unsigned InterfaceID() { return INTERFACE_ID; } - //virtual const char *InterfaceName() { return name; } - - // This kernel thingie makes the structure very flat and basiclly singletons. // I'm not sure if this is a good idea but it works for now. class IKernel diff --git a/src/engine/server/databases/connection.cpp b/src/engine/server/databases/connection.cpp index e94ec9904..b7a95caf9 100644 --- a/src/engine/server/databases/connection.cpp +++ b/src/engine/server/databases/connection.cpp @@ -6,23 +6,23 @@ void IDbConnection::FormatCreateRace(char *aBuf, unsigned int BufferSize) { str_format(aBuf, BufferSize, "CREATE TABLE IF NOT EXISTS %s_race (" - "Map VARCHAR(128) COLLATE %s NOT NULL, " - "Name VARCHAR(%d) COLLATE %s NOT NULL, " - "Timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, " - "Time FLOAT DEFAULT 0, " - "Server CHAR(4), " - "cp1 FLOAT DEFAULT 0, cp2 FLOAT DEFAULT 0, cp3 FLOAT DEFAULT 0, " - "cp4 FLOAT DEFAULT 0, cp5 FLOAT DEFAULT 0, cp6 FLOAT DEFAULT 0, " - "cp7 FLOAT DEFAULT 0, cp8 FLOAT DEFAULT 0, cp9 FLOAT DEFAULT 0, " - "cp10 FLOAT DEFAULT 0, cp11 FLOAT DEFAULT 0, cp12 FLOAT DEFAULT 0, " - "cp13 FLOAT DEFAULT 0, cp14 FLOAT DEFAULT 0, cp15 FLOAT DEFAULT 0, " - "cp16 FLOAT DEFAULT 0, cp17 FLOAT DEFAULT 0, cp18 FLOAT DEFAULT 0, " - "cp19 FLOAT DEFAULT 0, cp20 FLOAT DEFAULT 0, cp21 FLOAT DEFAULT 0, " - "cp22 FLOAT DEFAULT 0, cp23 FLOAT DEFAULT 0, cp24 FLOAT DEFAULT 0, " - "cp25 FLOAT DEFAULT 0, " - "GameID VARCHAR(64), " - "DDNet7 BOOL DEFAULT FALSE, " - "PRIMARY KEY (Map, Name, Time, Timestamp, Server)" + " Map VARCHAR(128) COLLATE %s NOT NULL, " + " Name VARCHAR(%d) COLLATE %s NOT NULL, " + " Timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, " + " Time FLOAT DEFAULT 0, " + " Server CHAR(4), " + " cp1 FLOAT DEFAULT 0, cp2 FLOAT DEFAULT 0, cp3 FLOAT DEFAULT 0, " + " cp4 FLOAT DEFAULT 0, cp5 FLOAT DEFAULT 0, cp6 FLOAT DEFAULT 0, " + " cp7 FLOAT DEFAULT 0, cp8 FLOAT DEFAULT 0, cp9 FLOAT DEFAULT 0, " + " cp10 FLOAT DEFAULT 0, cp11 FLOAT DEFAULT 0, cp12 FLOAT DEFAULT 0, " + " cp13 FLOAT DEFAULT 0, cp14 FLOAT DEFAULT 0, cp15 FLOAT DEFAULT 0, " + " cp16 FLOAT DEFAULT 0, cp17 FLOAT DEFAULT 0, cp18 FLOAT DEFAULT 0, " + " cp19 FLOAT DEFAULT 0, cp20 FLOAT DEFAULT 0, cp21 FLOAT DEFAULT 0, " + " cp22 FLOAT DEFAULT 0, cp23 FLOAT DEFAULT 0, cp24 FLOAT DEFAULT 0, " + " cp25 FLOAT DEFAULT 0, " + " GameID VARCHAR(64), " + " DDNet7 BOOL DEFAULT FALSE, " + " PRIMARY KEY (Map, Name, Time, Timestamp, Server)" ");", GetPrefix(), BinaryCollate(), MAX_NAME_LENGTH, BinaryCollate()); } @@ -31,14 +31,14 @@ void IDbConnection::FormatCreateTeamrace(char *aBuf, unsigned int BufferSize, co { str_format(aBuf, BufferSize, "CREATE TABLE IF NOT EXISTS %s_teamrace (" - "Map VARCHAR(128) COLLATE %s NOT NULL, " - "Name VARCHAR(%d) COLLATE %s NOT NULL, " - "Timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, " - "Time FLOAT DEFAULT 0, " - "ID %s NOT NULL, " // VARBINARY(16) for MySQL and BLOB for SQLite - "GameID VARCHAR(64), " - "DDNet7 BOOL DEFAULT FALSE, " - "PRIMARY KEY (ID, Name)" + " Map VARCHAR(128) COLLATE %s NOT NULL, " + " Name VARCHAR(%d) COLLATE %s NOT NULL, " + " Timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, " + " Time FLOAT DEFAULT 0, " + " ID %s NOT NULL, " // VARBINARY(16) for MySQL and BLOB for SQLite + " GameID VARCHAR(64), " + " DDNet7 BOOL DEFAULT FALSE, " + " PRIMARY KEY (ID, Name)" ");", GetPrefix(), BinaryCollate(), MAX_NAME_LENGTH, BinaryCollate(), pIdType); } @@ -47,13 +47,13 @@ void IDbConnection::FormatCreateMaps(char *aBuf, unsigned int BufferSize) { str_format(aBuf, BufferSize, "CREATE TABLE IF NOT EXISTS %s_maps (" - "Map VARCHAR(128) COLLATE %s NOT NULL, " - "Server VARCHAR(32) COLLATE %s NOT NULL, " - "Mapper VARCHAR(128) COLLATE %s NOT NULL, " - "Points INT DEFAULT 0, " - "Stars INT DEFAULT 0, " - "Timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP, " - "PRIMARY KEY (Map)" + " Map VARCHAR(128) COLLATE %s NOT NULL, " + " Server VARCHAR(32) COLLATE %s NOT NULL, " + " Mapper VARCHAR(128) COLLATE %s NOT NULL, " + " Points INT DEFAULT 0, " + " Stars INT DEFAULT 0, " + " Timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP, " + " PRIMARY KEY (Map)" ");", GetPrefix(), BinaryCollate(), BinaryCollate(), BinaryCollate()); } @@ -62,14 +62,14 @@ void IDbConnection::FormatCreateSaves(char *aBuf, unsigned int BufferSize) { str_format(aBuf, BufferSize, "CREATE TABLE IF NOT EXISTS %s_saves (" - "Savegame TEXT COLLATE %s NOT NULL, " - "Map VARCHAR(128) COLLATE %s NOT NULL, " - "Code VARCHAR(128) COLLATE %s NOT NULL, " - "Timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, " - "Server CHAR(4), " - "DDNet7 BOOL DEFAULT FALSE, " - "SaveID VARCHAR(36) DEFAULT NULL, " - "PRIMARY KEY (Map, Code)" + " Savegame TEXT COLLATE %s NOT NULL, " + " Map VARCHAR(128) COLLATE %s NOT NULL, " + " Code VARCHAR(128) COLLATE %s NOT NULL, " + " Timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, " + " Server CHAR(4), " + " DDNet7 BOOL DEFAULT FALSE, " + " SaveID VARCHAR(36) DEFAULT NULL, " + " PRIMARY KEY (Map, Code)" ");", GetPrefix(), BinaryCollate(), BinaryCollate(), BinaryCollate()); } @@ -78,9 +78,9 @@ void IDbConnection::FormatCreatePoints(char *aBuf, unsigned int BufferSize) { str_format(aBuf, BufferSize, "CREATE TABLE IF NOT EXISTS %s_points (" - "Name VARCHAR(%d) COLLATE %s NOT NULL, " - "Points INT DEFAULT 0, " - "PRIMARY KEY (Name)" + " Name VARCHAR(%d) COLLATE %s NOT NULL, " + " Points INT DEFAULT 0, " + " PRIMARY KEY (Name)" ");", GetPrefix(), MAX_NAME_LENGTH, BinaryCollate()); } diff --git a/src/engine/server/register.h b/src/engine/server/register.h index a75547ba7..86af0c93c 100644 --- a/src/engine/server/register.h +++ b/src/engine/server/register.h @@ -4,6 +4,7 @@ #define ENGINE_SERVER_REGISTER_H #include +#include class CRegister { diff --git a/src/game/client/animstate.h b/src/game/client/animstate.h index fbc0a2f8e..730fff989 100644 --- a/src/game/client/animstate.h +++ b/src/game/client/animstate.h @@ -3,6 +3,8 @@ #ifndef GAME_CLIENT_ANIMSTATE_H #define GAME_CLIENT_ANIMSTATE_H +#include + class CAnimState { CAnimKeyframe m_Body; diff --git a/src/game/client/components/ghost.h b/src/game/client/components/ghost.h index b1e134c04..617b54f96 100644 --- a/src/game/client/components/ghost.h +++ b/src/game/client/components/ghost.h @@ -4,6 +4,7 @@ #define GAME_CLIENT_COMPONENTS_GHOST_H #include +#include enum { diff --git a/src/game/extrainfo.h b/src/game/extrainfo.h index fd3877011..c89b2ab1d 100644 --- a/src/game/extrainfo.h +++ b/src/game/extrainfo.h @@ -3,6 +3,8 @@ #ifndef GAME_EXTRAINFO_H #define GAME_EXTRAINFO_H +#include + #include bool UseExtraInfo(const CNetObj_Projectile *pProj); diff --git a/src/game/server/entities/gun.cpp b/src/game/server/entities/gun.cpp index c805f3210..ade1c8ea2 100644 --- a/src/game/server/entities/gun.cpp +++ b/src/game/server/entities/gun.cpp @@ -117,9 +117,9 @@ void CGun::Snap(int SnappingClient) CCharacter *Char = GameServer()->GetPlayerChar(SnappingClient); - if(SnappingClient > -1 && (GameServer()->m_apPlayers[SnappingClient]->GetTeam() == -1 - || GameServer()->m_apPlayers[SnappingClient]->IsPaused()) - && GameServer()->m_apPlayers[SnappingClient]->m_SpectatorID != SPEC_FREEVIEW) + if(SnappingClient > -1 && (GameServer()->m_apPlayers[SnappingClient]->GetTeam() == -1 || + GameServer()->m_apPlayers[SnappingClient]->IsPaused()) && + GameServer()->m_apPlayers[SnappingClient]->m_SpectatorID != SPEC_FREEVIEW) Char = GameServer()->GetPlayerChar(GameServer()->m_apPlayers[SnappingClient]->m_SpectatorID); int Tick = (Server()->Tick()%Server()->TickSpeed())%11; diff --git a/src/game/server/entities/projectile.h b/src/game/server/entities/projectile.h index ad9a63200..f1d596339 100644 --- a/src/game/server/entities/projectile.h +++ b/src/game/server/entities/projectile.h @@ -3,6 +3,8 @@ #ifndef GAME_SERVER_ENTITIES_PROJECTILE_H #define GAME_SERVER_ENTITIES_PROJECTILE_H +#include + class CProjectile : public CEntity { public: diff --git a/src/game/server/gamecontext.h b/src/game/server/gamecontext.h index 86c0f515e..a440623d1 100644 --- a/src/game/server/gamecontext.h +++ b/src/game/server/gamecontext.h @@ -21,6 +21,8 @@ #include "player.h" #include "teehistorian.h" +#include + #ifdef _MSC_VER typedef __int32 int32_t; typedef unsigned __int32 uint32_t; diff --git a/src/game/server/score.cpp b/src/game/server/score.cpp index a32887ff1..74fef7934 100644 --- a/src/game/server/score.cpp +++ b/src/game/server/score.cpp @@ -213,8 +213,8 @@ bool CScore::LoadPlayerDataThread(IDbConnection *pSqlServer, const ISqlData *pGa // get best race time str_format(aBuf, sizeof(aBuf), "SELECT Time, cp1, cp2, cp3, cp4, cp5, cp6, cp7, cp8, cp9, cp10, " - "cp11, cp12, cp13, cp14, cp15, cp16, cp17, cp18, cp19, cp20, " - "cp21, cp22, cp23, cp24, cp25 " + " cp11, cp12, cp13, cp14, cp15, cp16, cp17, cp18, cp19, cp20, " + " cp21, cp22, cp23, cp24, cp25 " "FROM %s_race " "WHERE Map = ? AND Name = ? " "ORDER BY Time ASC " @@ -293,9 +293,9 @@ bool CScore::MapVoteThread(IDbConnection *pSqlServer, const ISqlData *pGameData) "FROM %s_maps " "WHERE Map LIKE %s " "ORDER BY " - "CASE WHEN Map = ? THEN 0 ELSE 1 END, " - "CASE WHEN Map LIKE ? THEN 0 ELSE 1 END, " - "LENGTH(Map), Map " + " CASE WHEN Map = ? THEN 0 ELSE 1 END, " + " CASE WHEN Map LIKE ? THEN 0 ELSE 1 END, " + " LENGTH(Map), Map " "LIMIT 1;", pSqlServer->GetPrefix(), pSqlServer->CollateNocase()); pSqlServer->PrepareStatement(aBuf); @@ -354,21 +354,21 @@ bool CScore::MapInfoThread(IDbConnection *pSqlServer, const ISqlData *pGameData) char aBuf[1024]; str_format(aBuf, sizeof(aBuf), "SELECT l.Map, l.Server, Mapper, Points, Stars, " - "(SELECT COUNT(Name) FROM %s_race WHERE Map = l.Map) AS Finishes, " - "(SELECT COUNT(DISTINCT Name) FROM %s_race WHERE Map = l.Map) AS Finishers, " - "(SELECT ROUND(AVG(Time)) FROM %s_race WHERE Map = l.Map) AS Average, " - "%s AS Stamp, " - "%s-%s AS Ago, " - "(SELECT MIN(Time) FROM %s_race WHERE Map = l.Map AND Name = ?) AS OwnTime " + " (SELECT COUNT(Name) FROM %s_race WHERE Map = l.Map) AS Finishes, " + " (SELECT COUNT(DISTINCT Name) FROM %s_race WHERE Map = l.Map) AS Finishers, " + " (SELECT ROUND(AVG(Time)) FROM %s_race WHERE Map = l.Map) AS Average, " + " %s AS Stamp, " + " %s-%s AS Ago, " + " (SELECT MIN(Time) FROM %s_race WHERE Map = l.Map AND Name = ?) AS OwnTime " "FROM (" - "SELECT * FROM %s_maps " - "WHERE Map LIKE %s " - "ORDER BY " - "CASE WHEN Map = ? THEN 0 ELSE 1 END, " - "CASE WHEN Map LIKE ? THEN 0 ELSE 1 END, " - "LENGTH(Map), " - "Map " - "LIMIT 1" + " SELECT * FROM %s_maps " + " WHERE Map LIKE %s " + " ORDER BY " + " CASE WHEN Map = ? THEN 0 ELSE 1 END, " + " CASE WHEN Map LIKE ? THEN 0 ELSE 1 END, " + " LENGTH(Map), " + " Map " + " LIMIT 1" ") as l;", pSqlServer->GetPrefix(), pSqlServer->GetPrefix(), pSqlServer->GetPrefix(), aTimestamp, aCurrentTimestamp, aTimestamp, @@ -579,9 +579,9 @@ bool CScore::SaveTeamScoreThread(IDbConnection *pSqlServer, const ISqlData *pGam str_format(aBuf, sizeof(aBuf), "SELECT l.ID, Name, Time " "FROM (" // preselect teams with first name in team - "SELECT ID " - "FROM %s_teamrace " - "WHERE Map = ? AND Name = ? AND DDNet7 = false" + " SELECT ID " + " FROM %s_teamrace " + " WHERE Map = ? AND Name = ? AND DDNet7 = false" ") as l INNER JOIN %s_teamrace AS r ON l.ID = r.ID " "ORDER BY l.ID, Name COLLATE %s;", pSqlServer->GetPrefix(), pSqlServer->GetPrefix(), pSqlServer->BinaryCollate()); @@ -663,11 +663,11 @@ bool CScore::ShowRankThread(IDbConnection *pSqlServer, const ISqlData *pGameData str_format(aBuf, sizeof(aBuf), "SELECT Rank, Name, Time " "FROM (" - "SELECT RANK() OVER w AS Rank, Name, MIN(Time) AS Time " - "FROM %s_race " - "WHERE Map = ? " - "GROUP BY Name " - "WINDOW w AS (ORDER BY Time)" + " SELECT RANK() OVER w AS Rank, Name, MIN(Time) AS Time " + " FROM %s_race " + " WHERE Map = ? " + " GROUP BY Name " + " WINDOW w AS (ORDER BY Time)" ") as a " "WHERE Name = ?;", pSqlServer->GetPrefix()); @@ -721,17 +721,17 @@ bool CScore::ShowTeamRankThread(IDbConnection *pSqlServer, const ISqlData *pGame str_format(aBuf, sizeof(aBuf), "SELECT l.ID, Name, Time, Rank " "FROM (" // teamrank score board - "SELECT RANK() OVER w AS Rank, ID " - "FROM %s_teamrace " - "WHERE Map = ? " - "GROUP BY ID " - "WINDOW w AS (ORDER BY Time)" + " SELECT RANK() OVER w AS Rank, ID " + " FROM %s_teamrace " + " WHERE Map = ? " + " GROUP BY ID " + " WINDOW w AS (ORDER BY Time)" ") AS TeamRank INNER JOIN (" // select rank with Name in team - "SELECT ID " - "FROM %s_teamrace " - "WHERE Map = ? AND Name = ? " - "ORDER BY Time " - "LIMIT 1" + " SELECT ID " + " FROM %s_teamrace " + " WHERE Map = ? AND Name = ? " + " ORDER BY Time " + " LIMIT 1" ") AS l ON TeamRank.ID = l.ID " "INNER JOIN %s_teamrace AS r ON l.ID = r.ID ", pSqlServer->GetPrefix(), pSqlServer->GetPrefix(), pSqlServer->GetPrefix()); @@ -799,11 +799,11 @@ bool CScore::ShowTop5Thread(IDbConnection *pSqlServer, const ISqlData *pGameData str_format(aBuf, sizeof(aBuf), "SELECT Name, Time, Rank " "FROM (" - "SELECT RANK() OVER w AS Rank, Name, MIN(Time) AS Time " - "FROM %s_race " - "WHERE Map = ? " - "GROUP BY Name " - "WINDOW w AS (ORDER BY Time)" + " SELECT RANK() OVER w AS Rank, Name, MIN(Time) AS Time " + " FROM %s_race " + " WHERE Map = ? " + " GROUP BY Name " + " WINDOW w AS (ORDER BY Time)" ") as a " "ORDER BY Rank %s " "LIMIT %d, 5;", @@ -856,16 +856,16 @@ bool CScore::ShowTeamTop5Thread(IDbConnection *pSqlServer, const ISqlData *pGame str_format(aBuf, sizeof(aBuf), "SELECT Name, Time, Rank, TeamSize " "FROM (" // limit to 5 - "SELECT TeamSize, Rank, ID " - "FROM (" // teamrank score board - "SELECT RANK() OVER w AS Rank, ID, COUNT(*) AS Teamsize " - "FROM %s_teamrace " - "WHERE Map = ? " - "GROUP BY Id " - "WINDOW w AS (ORDER BY Time)" - ") as l1 " - "ORDER BY Rank %s " - "LIMIT %d, 5" + " SELECT TeamSize, Rank, ID " + " FROM (" // teamrank score board + " SELECT RANK() OVER w AS Rank, ID, COUNT(*) AS Teamsize " + " FROM %s_teamrace " + " WHERE Map = ? " + " GROUP BY Id " + " WINDOW w AS (ORDER BY Time)" + " ) as l1 " + " ORDER BY Rank %s " + " LIMIT %d, 5" ") as l2 " "INNER JOIN %s_teamrace as r ON l2.ID = r.ID " "ORDER BY Rank %s, r.ID, Name ASC;", @@ -1045,8 +1045,8 @@ bool CScore::ShowPointsThread(IDbConnection *pSqlServer, const ISqlData *pGameDa char aBuf[512]; str_format(aBuf, sizeof(aBuf), "SELECT (" - "SELECT COUNT(Name) + 1 FROM %s_points WHERE Points > (" - "SELECT points FROM %s_points WHERE Name = ?" + " SELECT COUNT(Name) + 1 FROM %s_points WHERE Points > (" + " SELECT points FROM %s_points WHERE Name = ?" ")) as Rank, Points, Name " "FROM %s_points WHERE Name = ?;", pSqlServer->GetPrefix(), pSqlServer->GetPrefix(), pSqlServer->GetPrefix()); @@ -1094,9 +1094,9 @@ bool CScore::ShowTopPointsThread(IDbConnection *pSqlServer, const ISqlData *pGam str_format(aBuf, sizeof(aBuf), "SELECT Rank, Points, Name " "FROM (" - "SELECT RANK() OVER w AS Rank, Points, Name " - "FROM %s_points " - "WINDOW w as (ORDER BY Points DESC)" + " SELECT RANK() OVER w AS Rank, Points, Name " + " FROM %s_points " + " WINDOW w as (ORDER BY Points DESC)" ") as a " "ORDER BY Rank %s " "LIMIT ?, 5;", @@ -1203,9 +1203,9 @@ bool CScore::RandomUnfinishedMapThread(IDbConnection *pSqlServer, const ISqlData "SELECT Map " "FROM %s_maps " "WHERE Server = ? AND Map != ? AND Stars = ? AND Map NOT IN (" - "SELECT Map " - "FROM %s_race " - "WHERE Name = ?" + " SELECT Map " + " FROM %s_race " + " WHERE Name = ?" ") ORDER BY RAND() " "LIMIT 1;", pSqlServer->GetPrefix(), pSqlServer->GetPrefix()); @@ -1221,9 +1221,9 @@ bool CScore::RandomUnfinishedMapThread(IDbConnection *pSqlServer, const ISqlData "SELECT Map " "FROM %s_maps AS maps " "WHERE Server = ? AND Map != ? AND Map NOT IN (" - "SELECT Map " - "FROM %s_race as race " - "WHERE Name = ?" + " SELECT Map " + " FROM %s_race as race " + " WHERE Name = ?" ") ORDER BY RAND() " "LIMIT 1;", pSqlServer->GetPrefix(), pSqlServer->GetPrefix()); diff --git a/src/game/server/teehistorian.cpp b/src/game/server/teehistorian.cpp index d1c620cc1..6d77d614d 100644 --- a/src/game/server/teehistorian.cpp +++ b/src/game/server/teehistorian.cpp @@ -1,15 +1,15 @@ #include "teehistorian.h" #include -#include #include +#include #include static const char TEEHISTORIAN_NAME[] = "teehistorian@ddnet.tw"; static const CUuid TEEHISTORIAN_UUID = CalculateUuid(TEEHISTORIAN_NAME); static const char TEEHISTORIAN_VERSION[] = "2"; -#define UUID(id, name) static const CUuid UUID_ ## id = CalculateUuid(name); +#define UUID(id, name) static const CUuid UUID_##id = CalculateUuid(name); #include #undef UUID @@ -84,7 +84,7 @@ void CTeeHistorian::WriteHeader(const CGameInfo *pGameInfo) char aJson[2048]; - #define E(buf, str) EscapeJson(buf, sizeof(buf), str) +#define E(buf, str) EscapeJson(buf, sizeof(buf), str) str_format(aJson, sizeof(aJson), "{\"comment\":\"%s\",\"version\":\"%s\",\"game_uuid\":\"%s\",\"server_version\":\"%s\",\"start_time\":\"%s\",\"server_name\":\"%s\",\"server_port\":\"%d\",\"game_type\":\"%s\",\"map_name\":\"%s\",\"map_size\":\"%d\",\"map_sha256\":\"%s\",\"map_crc\":\"%08x\",\"prng_description\":\"%s\",\"config\":{", E(aCommentBuffer, TEEHISTORIAN_NAME), @@ -106,7 +106,7 @@ void CTeeHistorian::WriteHeader(const CGameInfo *pGameInfo) char aBuffer2[1024]; bool First = true; - #define MACRO_CONFIG_INT(Name,ScriptName,Def,Min,Max,Flags,Desc) \ +#define MACRO_CONFIG_INT(Name, ScriptName, Def, Min, Max, Flags, Desc) \ if((Flags)&CFGFLAG_SERVER && !((Flags)&CFGFLAG_NONTEEHISTORIC) && pGameInfo->m_pConfig->m_##Name != (Def)) \ { \ str_format(aJson, sizeof(aJson), "%s\"%s\":\"%d\"", \ @@ -117,9 +117,9 @@ void CTeeHistorian::WriteHeader(const CGameInfo *pGameInfo) First = false; \ } - #define MACRO_CONFIG_COL(Name,ScriptName,Def,Save,Desc) MACRO_CONFIG_INT(Name,ScriptName,Def,0,0,Save,Desc) +#define MACRO_CONFIG_COL(Name, ScriptName, Def, Save, Desc) MACRO_CONFIG_INT(Name, ScriptName, Def, 0, 0, Save, Desc) - #define MACRO_CONFIG_STR(Name,ScriptName,Len,Def,Flags,Desc) \ +#define MACRO_CONFIG_STR(Name, ScriptName, Len, Def, Flags, Desc) \ if((Flags)&CFGFLAG_SERVER && !((Flags)&CFGFLAG_NONTEEHISTORIC) && str_comp(pGameInfo->m_pConfig->m_##Name, (Def)) != 0) \ { \ str_format(aJson, sizeof(aJson), "%s\"%s\":\"%s\"", \ @@ -130,11 +130,11 @@ void CTeeHistorian::WriteHeader(const CGameInfo *pGameInfo) First = false; \ } - #include +#include - #undef MACRO_CONFIG_INT - #undef MACRO_CONFIG_COL - #undef MACRO_CONFIG_STR +#undef MACRO_CONFIG_INT +#undef MACRO_CONFIG_COL +#undef MACRO_CONFIG_STR str_format(aJson, sizeof(aJson), "},\"tuning\":{"); Write(aJson, str_length(aJson)); @@ -142,7 +142,7 @@ void CTeeHistorian::WriteHeader(const CGameInfo *pGameInfo) First = true; static const float TicksPerSecond = 50.0f; - #define MACRO_TUNING_PARAM(Name,ScriptName,Value,Description) \ +#define MACRO_TUNING_PARAM(Name, ScriptName, Value, Description) \ if(pGameInfo->m_pTuning->m_##Name.Get() != (int)((Value)*100)) \ { \ str_format(aJson, sizeof(aJson), "%s\"%s\":\"%d\"", \ @@ -152,8 +152,8 @@ void CTeeHistorian::WriteHeader(const CGameInfo *pGameInfo) Write(aJson, str_length(aJson)); \ First = false; \ } - #include - #undef MACRO_TUNING_PARAM +#include +#undef MACRO_TUNING_PARAM str_format(aJson, sizeof(aJson), "},\"uuids\":["); Write(aJson, str_length(aJson)); @@ -184,7 +184,6 @@ void CTeeHistorian::WriteExtra(CUuid Uuid, const void *pData, int DataSize) Write(pData, DataSize); } - void CTeeHistorian::BeginTick(int Tick) { dbg_assert(m_State == STATE_START || m_State == STATE_BEFORE_TICK, "invalid teehistorian state"); diff --git a/src/test/teehistorian.cpp b/src/test/teehistorian.cpp index 14b464a31..412fdb437 100644 --- a/src/test/teehistorian.cpp +++ b/src/test/teehistorian.cpp @@ -49,8 +49,7 @@ protected: 0x01, 0x23, 0x45, 0x67, 0x89, 0x01, 0x23, 0x45, 0x67, 0x89, 0x01, 0x23, 0x45, 0x67, 0x89, 0x01, 0x23, 0x45, 0x67, 0x89, 0x01, 0x23, 0x45, 0x67, 0x89, 0x01, 0x23, 0x45, 0x67, 0x89, - 0x01, 0x23, - }}; + 0x01, 0x23}}; mem_zero(&m_GameInfo, sizeof(m_GameInfo)); @@ -349,8 +348,7 @@ TEST_F(TeeHistorian, DDNetVersion) }; CUuid ConnectionID = { 0xfb, 0x13, 0xa5, 0x76, 0xd3, 0x5f, 0x48, 0x93, - 0xb8, 0x15, 0xee, 0xdc, 0x6d, 0x98, 0x01, 0x5b, - }; + 0xb8, 0x15, 0xee, 0xdc, 0x6d, 0x98, 0x01, 0x5b}; m_TH.RecordDDNetVersion(0, ConnectionID, 13010, "DDNet 13.1 (3623f5e4cd184556)"); m_TH.RecordDDNetVersionOld(1, 13010); Finish(); @@ -456,8 +454,7 @@ TEST_F(TeeHistorian, SaveSuccess) CUuid SaveID = { 0xfb, 0x13, 0xa5, 0x76, 0xd3, 0x5f, 0x48, 0x93, - 0xb8, 0x15, 0xee, 0xdc, 0x6d, 0x98, 0x01, 0x5b, - }; + 0xb8, 0x15, 0xee, 0xdc, 0x6d, 0x98, 0x01, 0x5b}; const char *pTeamSave = "2\tH.\nll0"; m_TH.RecordTeamSaveSuccess(21, SaveID, pTeamSave); Finish(); @@ -503,8 +500,7 @@ TEST_F(TeeHistorian, LoadSuccess) CUuid SaveID = { 0xfb, 0x13, 0xa5, 0x76, 0xd3, 0x5f, 0x48, 0x93, - 0xb8, 0x15, 0xee, 0xdc, 0x6d, 0x98, 0x01, 0x5b, - }; + 0xb8, 0x15, 0xee, 0xdc, 0x6d, 0x98, 0x01, 0x5b}; const char *pTeamSave = "2\tH.\nll0"; m_TH.RecordTeamLoadSuccess(21, SaveID, pTeamSave); Finish(); diff --git a/src/tools/crapnet.cpp b/src/tools/crapnet.cpp index 97b7efb37..0ad63a4f8 100644 --- a/src/tools/crapnet.cpp +++ b/src/tools/crapnet.cpp @@ -31,7 +31,7 @@ struct CPingConfig }; static CPingConfig m_aConfigPings[] = { -// base flux spike loss delay delayfreq + // base flux spike loss delay delayfreq {0, 0, 0, 0, 0, 0}, {40, 20, 100, 0, 0, 0}, {140, 40, 200, 0, 0, 0},