make next client network compatible with stable server, make next server semi-compatible with stable client
This commit is contained in:
parent
587b3a8f98
commit
90896119fe
|
@ -884,6 +884,75 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
|
|||
setServerSettings(damage,suffocation,hunger);
|
||||
}
|
||||
else if(command == TOCLIENT_PLAYERINFO)
|
||||
{
|
||||
u16 our_peer_id = m_con.GetPeerID();
|
||||
// Cancel if we don't have a peer id
|
||||
if (our_peer_id == PEER_ID_INEXISTENT) {
|
||||
infostream<<"TOCLIENT_PLAYERINFO cancelled: we have no peer id"<<std::endl;
|
||||
return;
|
||||
}
|
||||
{
|
||||
u32 item_size = 2+PLAYERNAME_SIZE;
|
||||
u32 player_count = (datasize-2) / item_size;
|
||||
u32 start = 2;
|
||||
// peer_ids
|
||||
core::list<u16> players_alive;
|
||||
for (u32 i=0; i<player_count; i++) {
|
||||
// Make sure the name ends in '\0'
|
||||
data[start+2+20-1] = 0;
|
||||
u16 peer_id = readU16(&data[start]);
|
||||
players_alive.push_back(peer_id);
|
||||
// Don't update the info of the local player
|
||||
if (peer_id == our_peer_id) {
|
||||
start += item_size;
|
||||
continue;
|
||||
}
|
||||
Player *player = m_env.getPlayer(peer_id);
|
||||
// Create a player if it doesn't exist
|
||||
if (player == NULL) {
|
||||
player = new RemotePlayer(
|
||||
m_device->getSceneManager()->getRootSceneNode(),
|
||||
m_device,
|
||||
-1
|
||||
);
|
||||
player->peer_id = peer_id;
|
||||
m_env.addPlayer(player);
|
||||
infostream<<"Client: Adding new player "<<peer_id<<std::endl;
|
||||
}
|
||||
player->updateName((char*)&data[start+2]);
|
||||
std::string p_name((char*)&data[start+2]);
|
||||
m_httpclient->pushRequest(HTTPREQUEST_SKIN_HASH,p_name);
|
||||
start += item_size;
|
||||
}
|
||||
/*
|
||||
Remove those players from the environment that
|
||||
weren't listed by the server.
|
||||
*/
|
||||
core::list<Player*> players = m_env.getPlayers();
|
||||
core::list<Player*>::Iterator ip;
|
||||
for (ip=players.begin(); ip!=players.end(); ip++) {
|
||||
// Ignore local player
|
||||
if ((*ip)->isLocal())
|
||||
continue;
|
||||
// Warn about a special case
|
||||
if ((*ip)->peer_id == 0)
|
||||
infostream<<"Client: Removing dead player with id=0"<<std::endl;
|
||||
bool is_alive = false;
|
||||
core::list<u16>::Iterator i;
|
||||
for (i=players_alive.begin(); i!=players_alive.end(); i++) {
|
||||
if ((*ip)->peer_id == *i) {
|
||||
is_alive = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (is_alive)
|
||||
continue;
|
||||
infostream<<"Removing dead player "<<(*ip)->peer_id<<std::endl;
|
||||
m_env.removePlayer((*ip)->peer_id);
|
||||
}
|
||||
} //envlock
|
||||
}
|
||||
else if(command == TOCLIENT_PLAYERDATA)
|
||||
{
|
||||
u16 our_peer_id = m_con.GetPeerID();
|
||||
|
||||
|
|
|
@ -69,15 +69,12 @@ enum ToClientCommand
|
|||
u8 enable_hunger
|
||||
*/
|
||||
|
||||
TOCLIENT_PLAYERINFO = 0x24,
|
||||
TOCLIENT_PLAYERINFO = 0x24, // deprecated, see TOCLIENT_PLAYERDATA
|
||||
/*
|
||||
[0] u16 command
|
||||
[2] u16 player count
|
||||
for each player:
|
||||
u16 peer_id
|
||||
char[20] name
|
||||
u16 length of serialized chardef
|
||||
string serialized character definition
|
||||
*/
|
||||
|
||||
TOCLIENT_PLAYER_ANIMATION = 0x25,
|
||||
|
@ -219,6 +216,18 @@ enum ToClientCommand
|
|||
u16 boots
|
||||
}
|
||||
*/
|
||||
|
||||
TOCLIENT_PLAYERDATA = 0x40,
|
||||
/*
|
||||
[0] u16 command
|
||||
[2] u16 player count
|
||||
[4] u16 field count
|
||||
for each player:
|
||||
u16 peer_id
|
||||
char[20] name
|
||||
u16 length of serialized chardef
|
||||
string serialized character definition
|
||||
*/
|
||||
};
|
||||
|
||||
enum ToServerCommand
|
||||
|
|
|
@ -2017,11 +2017,14 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
|
|||
|
||||
|
||||
getClient(peer_id)->serialization_version = getClient(peer_id)->pending_serialization_version;
|
||||
std::string chardef = PLAYER_DEFAULT_CHARDEF;
|
||||
|
||||
std::string datastring((char*)&data[2], datasize-2);
|
||||
std::istringstream is(datastring, std::ios_base::binary);
|
||||
// Read character definition
|
||||
std::string chardef = deSerializeString(is);
|
||||
if (datasize > 2) {
|
||||
std::string datastring((char*)&data[2], datasize-2);
|
||||
std::istringstream is(datastring, std::ios_base::binary);
|
||||
// Read character definition
|
||||
chardef = deSerializeString(is);
|
||||
}
|
||||
|
||||
Player *player = m_env.getPlayer(peer_id);
|
||||
// set the player's character definition
|
||||
|
@ -5000,9 +5003,9 @@ void Server::SendPlayerInfos()
|
|||
core::list<Player*> players = m_env.getPlayers(true);
|
||||
|
||||
std::ostringstream os(std::ios_base::binary);
|
||||
writeU16(os, TOCLIENT_PLAYERINFO);
|
||||
writeU16(os, TOCLIENT_PLAYERDATA);
|
||||
writeU16(os,(u16)players.size());
|
||||
// this is the number of serialized string sent below
|
||||
// this is the number of serialized strings sent below
|
||||
writeU16(os,1);
|
||||
char name[PLAYERNAME_SIZE];
|
||||
|
||||
|
@ -5014,7 +5017,7 @@ void Server::SendPlayerInfos()
|
|||
snprintf(name, PLAYERNAME_SIZE, "%s", player->getName());
|
||||
os.write(name,PLAYERNAME_SIZE);
|
||||
os<<serializeString(player->getCharDef());
|
||||
// space seperated serialized strings can be added here
|
||||
// serialized strings can be added here
|
||||
}
|
||||
|
||||
std::string s = os.str();
|
||||
|
|
Loading…
Reference in New Issue