From ceaebd00d88fe70516c7b4ef1fa84d2f5f10d736 Mon Sep 17 00:00:00 2001 From: x12xx12x <44411062+12xx12@users.noreply.github.com> Date: Mon, 27 Mar 2023 00:25:54 +0200 Subject: Small Team Creation Fixes (#5479) - Add additional explanation for team creation - error message if team creation fails because team already exists fixes #5466 --- Server/Plugins/APIDump/APIDesc.lua | 2 +- src/Scoreboard.cpp | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Server/Plugins/APIDump/APIDesc.lua b/Server/Plugins/APIDump/APIDesc.lua index 955978670..89e9955a9 100644 --- a/Server/Plugins/APIDump/APIDesc.lua +++ b/Server/Plugins/APIDump/APIDesc.lua @@ -12292,7 +12292,7 @@ end Type = "cTeam", }, }, - Notes = "Registers a new team. Returns the {{cTeam}} instance, nil on error.", + Notes = "Registers a new team. Returns the {{cTeam}} instance, nil on error. For example if the team already exists.", }, RemoveObjective = { diff --git a/src/Scoreboard.cpp b/src/Scoreboard.cpp index 7a6ed8867..fad78210e 100644 --- a/src/Scoreboard.cpp +++ b/src/Scoreboard.cpp @@ -361,11 +361,15 @@ cTeam * cScoreboard::RegisterTeam( const AString & a_Prefix, const AString & a_Suffix ) { - cTeam Team(a_Name, a_DisplayName, a_Prefix, a_Suffix); + auto [TeamIterator, TeamExists] = m_Teams.try_emplace(a_Name, a_Name, a_DisplayName, a_Prefix, a_Suffix); - std::pair Status = m_Teams.insert(cNamedTeam(a_Name, Team)); + if (!TeamExists && GetTeam(a_Name)) + { + LOGWARNING("Tried to register a team that already exists: %s", a_Name.c_str()); + return nullptr; + } - return Status.second ? &Status.first->second : nullptr; + return &TeamIterator->second; } -- cgit v1.2.3