Skip to content

Commit

Permalink
fix #3515
Browse files Browse the repository at this point in the history
  • Loading branch information
rt committed Jul 4, 2017
1 parent 0d6b7fe commit 64bf6d4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
6 changes: 4 additions & 2 deletions rts/Game/UnsyncedGameCommands.cpp
Expand Up @@ -907,11 +907,13 @@ class TeamActionExecutor : public IUnsyncedActionExecutor {

bool Execute(const UnsyncedAction& action) const {
const int teamId = atoi(action.GetArgs().c_str());

if (teamHandler->IsValidTeam(teamId)) {
clientNet->Send(CBaseNetProtocol::Get().SendJoinTeam(gu->myPlayerNum, teamId));
} else {
LOG_L(L_WARNING, "/Team: wrong syntax (which is '/Team %%teamid')");
LOG_L(L_WARNING, "[%s] team %d does not exist", __func__, teamId);
}

return true;
}
};
Expand All @@ -921,7 +923,7 @@ class TeamActionExecutor : public IUnsyncedActionExecutor {
class SpectatorActionExecutor : public IUnsyncedActionExecutor {
public:
SpectatorActionExecutor() : IUnsyncedActionExecutor("Spectator",
"Lets the local user give up controll over a team, and start spectating") {}
"Lets the local user give up control over a team, and start spectating") {}

bool Execute(const UnsyncedAction& action) const {
if (gu->spectating)
Expand Down
23 changes: 12 additions & 11 deletions rts/Net/GameServer.cpp
Expand Up @@ -1512,24 +1512,25 @@ void CGameServer::ProcessPacket(const unsigned playerNum, std::shared_ptr<const
break;
}
case TEAMMSG_JOIN_TEAM: {
const unsigned newTeam = inbuf[3];
const bool isNewTeamValid = (newTeam < teams.size());
const unsigned newTeamID = inbuf[3];

const bool isNewTeamValid = (newTeamID < teams.size());
const bool isSinglePlayer = (players.size() <= 1);

if (isNewTeamValid && (isSinglePlayer || cheating)) {
// joining the team is ok
} else {
Message(spring::format(NoTeamChange, players[player].name.c_str(), player));
if (!isNewTeamValid || (!isSinglePlayer && !cheating)) {
Message(spring::format(NoTeamChange, players[player].name.c_str(), player, newTeamID));
break;
}
Broadcast(CBaseNetProtocol::Get().SendJoinTeam(player, newTeam));

players[player].team = newTeam;
// player can join this team
Broadcast(CBaseNetProtocol::Get().SendJoinTeam(player, newTeamID));

players[player].team = newTeamID;
players[player].spectator = false;

if (!teams[newTeam].HasLeader()) {
teams[newTeam].SetLeader(player);
}
if (!teams[newTeamID].HasLeader())
teams[newTeamID].SetLeader(player);

break;
}
case TEAMMSG_TEAM_DIED: {
Expand Down
2 changes: 1 addition & 1 deletion rts/System/MsgStrings.h
Expand Up @@ -28,7 +28,7 @@ const std::string PlayerResigned = "Player %s resigned from the game: %s";

const std::string NoStartposChange = "%s tried to change his startposition illegally";
const std::string NoHelperAI = "%s (%d) is using a helper AI illegally";
const std::string NoTeamChange = "%s (%d) tried to change his team illegally";
const std::string NoTeamChange = "%s (%d) tried to change to non-existent team %d";
const std::string NoAICreated = "%s (%d) tried to control team %i with an AI illegally";
const std::string NoAIChangeState = "%s (%d) tried to change the state of an AI (%i) controlling team %i to state %i illegally";

Expand Down

0 comments on commit 64bf6d4

Please sign in to comment.