Shows other player's disconnection/joining a team

This commit is contained in:
yvt 2013-09-02 00:42:45 +09:00
parent 0210c0292f
commit 088474952f
4 changed files with 38 additions and 0 deletions

View File

@ -3797,6 +3797,23 @@ namespace spades {
}
}
void Client::PlayerLeaving(spades::client::Player *p) {
std::string msg;
msg = "Player " + chatWindow->TeamColorMessage(p->GetName(), p->GetTeamId());
msg += " has left";
chatWindow->AddMessage(msg);
}
void Client::PlayerJoinedTeam(spades::client::Player *p) {
std::string msg;
msg = p->GetName();
msg += " joined ";
msg += chatWindow->TeamColorMessage(world->GetTeam(p->GetTeamId()).name,
p->GetTeamId());
msg += " team";
chatWindow->AddMessage(msg);
}
void Client::GrenadeDestroyedBlock(spades::IntVector3 blk){
for(int x = blk.x - 1; x <= blk.x + 1; x++)
for(int y = blk.y - 1; y <= blk.y + 1; y++)

View File

@ -242,6 +242,8 @@ namespace spades {
void PlayerDestroyedBlockWithWeaponOrTool(IntVector3);
void PlayerDiggedBlock(IntVector3);
void GrenadeDestroyedBlock(IntVector3);
void PlayerLeaving(Player *);
void PlayerJoinedTeam(Player *);
virtual void PlayerMadeFootstep(Player *);
virtual void PlayerJumped(Player *);

View File

@ -302,6 +302,10 @@ namespace spades {
savedPlayerPos.resize(32);
savedPlayerFront.resize(32);
savedPlayerTeam.resize(32);
std::fill(savedPlayerTeam.begin(),
savedPlayerTeam.end(), -1);
}
NetClient::~NetClient(){
SPADES_MARK_FUNCTION();
@ -889,6 +893,8 @@ namespace spades {
World::PlayerPersistent& pers = GetWorld()->GetPlayerPersistent(pId);
pers.name = name;
pers.kills = kills;
savedPlayerTeam[pId] = team;
}
break;
case PacketTypeShortPlayerData:
@ -987,7 +993,15 @@ namespace spades {
client->LocalPlayerCreated();
lastPlayerInput = 0xffffffff;
lastWeaponInput = 0xffffffff;
}else{
if(savedPlayerTeam[pId] != team && team < 2){
client->PlayerJoinedTeam(p);
savedPlayerTeam[pId] = team;
}
}
}
break;
case PacketTypeBlockAction:
@ -1243,6 +1257,10 @@ namespace spades {
case PacketTypePlayerLeft:
{
Player *p = GetPlayer(reader.ReadByte());
client->PlayerLeaving(p);
savedPlayerTeam[p->GetId()] = -1;
GetWorld()->SetPlayer(p->GetId(), NULL);
// TODO: message
}

View File

@ -54,6 +54,7 @@ namespace spades {
std::vector<Vector3> savedPlayerPos;
std::vector<Vector3> savedPlayerFront;
std::vector<int> savedPlayerTeam;
std::vector<std::vector<char> > savedPackets;