Skip to content

Commit

Permalink
fix #5468
Browse files Browse the repository at this point in the history
  • Loading branch information
rtri committed Feb 11, 2017
1 parent 9d81d7c commit 5e84a72
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 17 deletions.
41 changes: 26 additions & 15 deletions rts/Net/GameServer.cpp
Expand Up @@ -27,7 +27,6 @@
#include "Game/Players/PlayerHandler.h"

#include "Net/Protocol/BaseNetProtocol.h"
#include "Sim/Misc/GlobalConstants.h"

// This undef is needed, as somewhere there is a type interface specified,
// which we need not!
Expand Down Expand Up @@ -222,6 +221,9 @@ void CGameServer::Initialize()

// initialize players, teams & ais
{
clientDrawFilter.fill({spring_notime, 0});
clientMuteFilter.fill({false, false});

const std::vector<PlayerBase>& playerStartData = myGameSetup->GetPlayerStartingDataCont();
const std::vector<TeamBase>& teamStartData = myGameSetup->GetTeamStartingDataCont();
const std::vector<SkirmishAIData>& aiStartData = myGameSetup->GetAIStartingDataCont();
Expand Down Expand Up @@ -1051,10 +1053,10 @@ void CGameServer::ProcessPacket(const unsigned playerNum, std::shared_ptr<const
Message(spring::format(WrongPlayer, msgCode, a, (unsigned)msg.fromPlayer));
break;
}
if (a < mutedPlayersChat.size() && mutedPlayersChat[a] ) {
//this player is muted, drop his messages quietly
// if this player is chat-muted, drop his messages quietly
if (clientMuteFilter[a].first)
break;
}

GotChatMessage(msg);
} catch (const netcode::UnpackPacketException& ex) {
Message(spring::format("Player %s sent invalid ChatMessage: %s", players[a].name.c_str(), ex.what()));
Expand Down Expand Up @@ -1285,14 +1287,28 @@ void CGameServer::ProcessPacket(const unsigned playerNum, std::shared_ptr<const
netcode::UnpackPacket pckt(packet, 2);
unsigned char playerNum;
pckt >> playerNum;

if (playerNum != a) {
Message(spring::format(WrongPlayer, msgCode, a, (unsigned)playerNum));
break;
}
if (a < mutedPlayersDraw.size() && mutedPlayersDraw[a] ) {
//this player is muted, drop his messages quietly
// if this player is draw-muted, drop his messages quietly
if (clientMuteFilter[a].second)
break;
}


// also drop player commands if we received 25 or more and
// each followed the previous by less than 50 milliseconds
// this is impossible to reach manually, but (very) easily
// through Lua and would allow clients to be DOS'ed
clientDrawFilter[a].second += (spring_diffmsecs(spring_now(), clientDrawFilter[a].first) < 50);
clientDrawFilter[a].second *= (spring_diffmsecs(spring_now(), clientDrawFilter[a].first) < 50);
clientDrawFilter[a].first = spring_now();

if (clientDrawFilter[a].second > 25)
break;


if (!players[playerNum].spectator || allowSpecDraw)
Broadcast(packet); //forward data
} catch (const netcode::UnpackPacketException& ex) {
Expand Down Expand Up @@ -2481,14 +2497,9 @@ void CGameServer::MutePlayer(const int playerNum, bool muteChat, bool muteDraw)
LOG_L(L_WARNING, "MutePlayer: invalid playerNum");
return;
}
if ( playerNum >= mutedPlayersChat.size() ) {
mutedPlayersChat.resize(playerNum+1);
}
if ( playerNum >= mutedPlayersDraw.size() ) {
mutedPlayersDraw.resize(playerNum+1);
}
mutedPlayersChat[playerNum] = muteChat;
mutedPlayersDraw[playerNum] = muteDraw;

clientMuteFilter[playerNum].first = muteChat;
clientMuteFilter[playerNum].second = muteDraw;
}


Expand Down
5 changes: 3 additions & 2 deletions rts/Net/GameServer.h
Expand Up @@ -14,6 +14,7 @@
#include <list>

#include "Game/GameData.h"
#include "Sim/Misc/GlobalConstants.h"
#include "Sim/Misc/TeamBase.h"
#include "System/float3.h"
#include "System/GlobalRNG.h"
Expand Down Expand Up @@ -212,8 +213,8 @@ class CGameServer
std::vector<GameTeam> teams;
std::vector<unsigned char> winningAllyTeams;

std::vector<bool> mutedPlayersChat;
std::vector<bool> mutedPlayersDraw;
std::array< std::pair<spring_time, uint32_t>, MAX_PLAYERS> clientDrawFilter;
std::array< std::pair< bool, bool>, MAX_PLAYERS> clientMuteFilter;

float medianCpu;
int medianPing;
Expand Down

0 comments on commit 5e84a72

Please sign in to comment.