Trying to send reason why the player leaves the game.

This commit is contained in:
lotodore
2008-11-25 23:19:34 +00:00
parent b236fa9d62
commit c57ea0985b
15 changed files with 65 additions and 24 deletions
+1 -1
View File
@@ -53,7 +53,7 @@ public:
virtual void SignalNetClientSelfJoined(unsigned playerId, const std::string &playerName, PlayerRights rights) = 0;
virtual void SignalNetClientPlayerJoined(unsigned playerId, const std::string &playerName, PlayerRights rights) = 0;
virtual void SignalNetClientPlayerChanged(unsigned playerId, const std::string &newPlayerName) = 0;
virtual void SignalNetClientPlayerLeft(unsigned playerId, const std::string &playerName) = 0;
virtual void SignalNetClientPlayerLeft(unsigned playerId, const std::string &playerName, int removeReason) = 0;
virtual void SignalNetClientNewGameAdmin(unsigned playerId, const std::string &playerName) = 0;
virtual void SignalNetClientChatMsg(const std::string &playerName, const std::string &msg) = 0;
+1 -1
View File
@@ -132,7 +132,7 @@ protected:
QtToolsInterface &GetQtToolsInterface();
void AddPlayerData(boost::shared_ptr<PlayerData> playerData);
void RemovePlayerData(unsigned playerId);
void RemovePlayerData(unsigned playerId, int removeReason);
void ClearPlayerDataList();
void MapPlayerDataList();
const PlayerDataList &GetPlayerDataList() const;
+1 -1
View File
@@ -702,7 +702,7 @@ AbstractClientStateReceiving::Process(ClientThread &client)
tmpPacket->ToNetPacketPlayerLeft()->GetData(playerLeftData);
// Signal to GUI and remove from data list.
client.RemovePlayerData(playerLeftData.playerId);
client.RemovePlayerData(playerLeftData.playerId, playerLeftData.removeReason);
}
else if (tmpPacket->ToNetPacketGameAdminChanged())
{
+2 -2
View File
@@ -765,7 +765,7 @@ ClientThread::AddPlayerData(boost::shared_ptr<PlayerData> playerData)
}
void
ClientThread::RemovePlayerData(unsigned playerId)
ClientThread::RemovePlayerData(unsigned playerId, int removeReason)
{
boost::shared_ptr<PlayerData> tmpData;
@@ -785,7 +785,7 @@ ClientThread::RemovePlayerData(unsigned playerId)
if (tmpData.get())
{
// Remove player from gui.
GetCallback().SignalNetClientPlayerLeft(tmpData->GetUniqueId(), tmpData->GetName());
GetCallback().SignalNetClientPlayerLeft(tmpData->GetUniqueId(), tmpData->GetName(), removeReason);
}
}
+38 -2
View File
@@ -113,6 +113,12 @@ using namespace std;
#define NET_REMOVED_START_FAILED 0x0005
#define NET_REMOVED_OTHER_REASON 0xFFFF
// Reasons why player left a game.
#define NET_LEFT_ON_REQUEST 0x0000
#define NET_LEFT_KICKED 0x0001
#define NET_LEFT_ERROR 0x0002
#define NET_LEFT_OTHER_REASON 0xFFFF
// Reasons why ask kick was denied.
#define NET_ASK_KICK_DENIED_TEMPORARY 0x0000
#define NET_ASK_KICK_DENIED_OTHER_IN_PROGRESS 0x0001
@@ -3083,7 +3089,24 @@ NetPacketPlayerLeft::SetData(const NetPacketPlayerLeft::Data &inData)
NetPacketPlayerLeftData *tmpData = (NetPacketPlayerLeftData *)GetRawData();
// Set the data.
tmpData->playerId = htonl(inData.playerId);
tmpData->playerId = htonl(inData.playerId);
tmpData->leaveReason = htons(inData.removeReason);
switch(inData.removeReason)
{
case NTF_NET_REMOVED_ON_REQUEST :
tmpData->leaveReason = htons(NET_LEFT_ON_REQUEST);
break;
case NTF_NET_REMOVED_KICKED :
tmpData->leaveReason = htons(NET_LEFT_KICKED);
break;
case NTF_NET_INTERNAL :
tmpData->leaveReason = htons(NET_LEFT_ERROR);
break;
default :
tmpData->leaveReason = htons(NET_LEFT_OTHER_REASON);
break;
}
// Check the packet - just in case.
Check(GetRawData());
@@ -3095,7 +3118,20 @@ NetPacketPlayerLeft::GetData(NetPacketPlayerLeft::Data &outData) const
// We assume that the data is valid. Validity has already been checked.
NetPacketPlayerLeftData *tmpData = (NetPacketPlayerLeftData *)GetRawData();
outData.playerId = ntohl(tmpData->playerId);
outData.playerId = ntohl(tmpData->playerId);
switch(ntohs(tmpData->leaveReason))
{
case NET_LEFT_ON_REQUEST :
outData.removeReason = ntohs(NTF_NET_REMOVED_ON_REQUEST);
break;
case NET_LEFT_KICKED :
outData.removeReason = ntohs(NTF_NET_REMOVED_KICKED);
break;
default :
outData.removeReason = ntohs(NTF_NET_INTERNAL);
break;
}
}
const NetPacketPlayerLeft *
+7 -6
View File
@@ -375,7 +375,7 @@ ServerGameThread::ResetComputerPlayerList()
while (i != end)
{
GetLobbyThread().RemoveComputerPlayer(*i);
RemovePlayerData(*i);
RemovePlayerData(*i, NTF_NET_REMOVED_ON_REQUEST);
++i;
}
@@ -383,7 +383,7 @@ ServerGameThread::ResetComputerPlayerList()
}
void
ServerGameThread::GracefulRemoveSession(SessionWrapper session)
ServerGameThread::GracefulRemoveSession(SessionWrapper session, int reason)
{
if (!session.sessionData.get())
throw ServerException(__FILE__, __LINE__, ERR_NET_INVALID_SESSION, 0);
@@ -392,12 +392,12 @@ ServerGameThread::GracefulRemoveSession(SessionWrapper session)
boost::shared_ptr<PlayerData> tmpPlayerData = session.playerData;
if (tmpPlayerData.get() && !tmpPlayerData->GetName().empty())
{
RemovePlayerData(tmpPlayerData);
RemovePlayerData(tmpPlayerData, reason);
}
}
void
ServerGameThread::RemovePlayerData(boost::shared_ptr<PlayerData> player)
ServerGameThread::RemovePlayerData(boost::shared_ptr<PlayerData> player, int reason)
{
if (player->GetRights() == PLAYER_RIGHTS_ADMIN)
{
@@ -427,6 +427,7 @@ ServerGameThread::RemovePlayerData(boost::shared_ptr<PlayerData> player)
boost::shared_ptr<NetPacket> thisPlayerLeft(new NetPacketPlayerLeft);
NetPacketPlayerLeft::Data thisPlayerLeftData;
thisPlayerLeftData.playerId = player->GetUniqueId();
thisPlayerLeftData.removeReason = reason;
static_cast<NetPacketPlayerLeft *>(thisPlayerLeft.get())->SetData(thisPlayerLeftData);
GetSessionManager().SendToAllSessions(GetSender(), thisPlayerLeft, SessionData::Game);
@@ -437,7 +438,7 @@ void
ServerGameThread::ErrorRemoveSession(SessionWrapper session)
{
GetLobbyThread().RemoveSessionFromGame(session);
GracefulRemoveSession(session);
GracefulRemoveSession(session, NTF_NET_INTERNAL);
}
void
@@ -452,7 +453,7 @@ ServerGameThread::SessionError(SessionWrapper session, int errorCode)
void
ServerGameThread::MoveSessionToLobby(SessionWrapper session, int reason)
{
GracefulRemoveSession(session);
GracefulRemoveSession(session, reason);
// Reset ready flag - just in case it is set, player may leave at any time.
session.sessionData->ResetReadyFlag();
GetLobbyThread().ReAddSession(session, reason);
+1
View File
@@ -720,6 +720,7 @@ public:
struct Data
{
u_int32_t playerId;
u_int16_t removeReason;
};
NetPacketPlayerLeft();
+2 -2
View File
@@ -95,8 +95,8 @@ protected:
void AddComputerPlayer(boost::shared_ptr<PlayerData> player);
void ResetComputerPlayerList();
void GracefulRemoveSession(SessionWrapper session);
void RemovePlayerData(boost::shared_ptr<PlayerData> player);
void GracefulRemoveSession(SessionWrapper session, int reason);
void RemovePlayerData(boost::shared_ptr<PlayerData> player, int reason);
void ErrorRemoveSession(SessionWrapper session);
void SessionError(SessionWrapper session, int errorCode);
void MoveSessionToLobby(SessionWrapper session, int reason);