Only allow the first connected client to control the server.
This commit is contained in:
parent
ee320588d5
commit
cebf395939
@ -499,6 +499,7 @@ void ServerLobbyRoomProtocol::connectionRequested(Event* event)
|
||||
m_setup->addPlayer(profile);
|
||||
peer->setPlayerProfile(profile);
|
||||
peer->setClientServerToken(token);
|
||||
peer->setHostId(new_host_id);
|
||||
|
||||
Log::verbose("ServerLobbyRoomProtocol", "New player.");
|
||||
|
||||
|
@ -494,6 +494,8 @@ int STKHost::mustStopListening()
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
/** Returns true if this instance is allowed to control the server.
|
||||
* Only the first connected client (i.e. the one with host id 1) is
|
||||
* allowed to control the server. Only called from a client.
|
||||
*/
|
||||
bool STKHost::isAuthorisedToControl() const
|
||||
{
|
||||
@ -501,15 +503,13 @@ bool STKHost::isAuthorisedToControl() const
|
||||
// stk logic), no peer is authorised.
|
||||
if(m_peers.size()==0)
|
||||
return false;
|
||||
Server *server = ServersManager::get()->getJoinedServer();
|
||||
return NetworkConfig::get()->getMyAddress().getIP() ==
|
||||
server->getAddress().getIP();
|
||||
|
||||
return m_host_id == 1;
|
||||
} // isAuthorisedToControl
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Server-side check if the client sending a command is really authorised
|
||||
* to do so.
|
||||
* to do so. Only the first connected client (i.e. host id = 1) is allowed
|
||||
* to control the server.
|
||||
* \param peer Peer sending the command.
|
||||
*/
|
||||
bool STKHost::isAuthorisedToControl(const STKPeer *peer) const
|
||||
@ -518,9 +518,7 @@ bool STKHost::isAuthorisedToControl(const STKPeer *peer) const
|
||||
// stk logic), no peer is authorised.
|
||||
if(m_peers.size()==0)
|
||||
return false;
|
||||
// FIXME peer has ip 0
|
||||
return true;
|
||||
return peer->getAddress()==NetworkConfig::get()->getMyAddress().getIP();
|
||||
return peer->getHostId()==1;
|
||||
} // isAuthorisedToControl
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
@ -32,6 +32,7 @@ STKPeer::STKPeer(ENetPeer *enet_peer)
|
||||
m_enet_peer = enet_peer;
|
||||
m_player_profile = NULL;
|
||||
m_client_server_token = 0;
|
||||
m_host_id = 0;
|
||||
m_token_set = false;
|
||||
} // STKPeer
|
||||
|
||||
|
@ -50,6 +50,8 @@ protected:
|
||||
/** True if the token for this peer has been set. */
|
||||
bool m_token_set;
|
||||
|
||||
/** Host id of this peer. */
|
||||
int m_host_id;
|
||||
public:
|
||||
STKPeer(ENetPeer *enet_peer);
|
||||
virtual ~STKPeer();
|
||||
@ -89,7 +91,12 @@ public:
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns if the token for this client is known. */
|
||||
bool isClientServerTokenSet() const { return m_token_set; }
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
/** Sets the host if of this peer. */
|
||||
void setHostId(int host_id) { m_host_id = host_id; }
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the host id of this peer. */
|
||||
int getHostId() const { return m_host_id; }
|
||||
}; // STKPeer
|
||||
|
||||
#endif // STK_PEER_HPP
|
||||
|
Loading…
x
Reference in New Issue
Block a user