aboutsummaryrefslogtreecommitdiff
path: root/src/network
diff options
context:
space:
mode:
authorred-001 <red-001@outlook.ie>2017-06-08 14:30:09 +0100
committerLoïc Blot <nerzhul@users.noreply.github.com>2017-06-08 15:30:09 +0200
commit4221c1b4412f2bf889bd603a26424003f5367f6a (patch)
tree622775e473bf073ed704afded90b050b51d63266 /src/network
parent5bd33a158688f5fb950613278eefb95b0594a765 (diff)
downloadminetest-4221c1b4412f2bf889bd603a26424003f5367f6a.tar.gz
minetest-4221c1b4412f2bf889bd603a26424003f5367f6a.tar.bz2
minetest-4221c1b4412f2bf889bd603a26424003f5367f6a.zip
Have the server send the player list to the client (#5924)
* Have the server send the player list to the client Currently the client generates the player list based on the Client active object list, the issue with this is that we can't be sure all player active objects will be sent to the client, so this could result in players showing up when someone run `/status` but auto complete not working with their nick and CSM not being aware of the player
Diffstat (limited to 'src/network')
-rw-r--r--src/network/clientopcodes.cpp2
-rw-r--r--src/network/clientpackethandler.cpp22
-rw-r--r--src/network/networkprotocol.h22
-rw-r--r--src/network/serveropcodes.cpp2
-rw-r--r--src/network/serverpackethandler.cpp13
5 files changed, 58 insertions, 3 deletions
diff --git a/src/network/clientopcodes.cpp b/src/network/clientopcodes.cpp
index bdcb1dfce..cb504b373 100644
--- a/src/network/clientopcodes.cpp
+++ b/src/network/clientopcodes.cpp
@@ -110,7 +110,7 @@ const ToClientCommandHandler toClientCommandTable[TOCLIENT_NUM_MSG_TYPES] =
{ "TOCLIENT_DELETE_PARTICLESPAWNER", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_DeleteParticleSpawner }, // 0x53
{ "TOCLIENT_CLOUD_PARAMS", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_CloudParams }, // 0x54
{ "TOCLIENT_FADE_SOUND", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_FadeSound }, // 0x55
- null_command_handler,
+ { "TOCLIENT_UPDATE_PLAYER_LIST", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_UpdatePlayerList }, // 0x56
null_command_handler,
null_command_handler,
null_command_handler,
diff --git a/src/network/clientpackethandler.cpp b/src/network/clientpackethandler.cpp
index d002ae10d..9eb6d8dca 100644
--- a/src/network/clientpackethandler.cpp
+++ b/src/network/clientpackethandler.cpp
@@ -1270,6 +1270,28 @@ void Client::handleCommand_EyeOffset(NetworkPacket* pkt)
*pkt >> player->eye_offset_first >> player->eye_offset_third;
}
+void Client::handleCommand_UpdatePlayerList(NetworkPacket* pkt)
+{
+ u8 type;
+ u16 num_players;
+ *pkt >> type >> num_players;
+ PlayerListModifer notice_type = (PlayerListModifer) type;
+
+ for (u16 i = 0; i < num_players; i++) {
+ std::string name;
+ *pkt >> name;
+ switch (notice_type) {
+ case PLAYER_LIST_INIT:
+ case PLAYER_LIST_ADD:
+ m_env.addPlayerName(name);
+ continue;
+ case PLAYER_LIST_REMOVE:
+ m_env.removePlayerName(name);
+ continue;
+ }
+ }
+}
+
void Client::handleCommand_SrpBytesSandB(NetworkPacket* pkt)
{
if ((m_chosen_auth_mech != AUTH_MECHANISM_LEGACY_PASSWORD)
diff --git a/src/network/networkprotocol.h b/src/network/networkprotocol.h
index 7126c237b..f003cf26a 100644
--- a/src/network/networkprotocol.h
+++ b/src/network/networkprotocol.h
@@ -155,9 +155,13 @@ with this program; if not, write to the Free Software Foundation, Inc.,
Stop sending TOSERVER_CLIENT_READY
PROTOCOL VERSION 32:
Add fading sounds
+ PROTOCOL VERSION 33:
+ Add TOCLIENT_UPDATE_PLAYER_LIST and send the player list to the client,
+ instead of guessing based on the active object list.
+
*/
-#define LATEST_PROTOCOL_VERSION 32
+#define LATEST_PROTOCOL_VERSION 33
// Server's supported network protocol range
#define SERVER_PROTOCOL_VERSION_MIN 24
@@ -629,6 +633,14 @@ enum ToClientCommand
float step
float gain
*/
+ TOCLIENT_UPDATE_PLAYER_LIST = 0x56,
+ /*
+ u8 type
+ u16 number of players
+ for each player
+ u16 len
+ u8[len] player name
+ */
TOCLIENT_SRP_BYTES_S_B = 0x60,
/*
@@ -965,4 +977,12 @@ const static std::string accessDeniedStrings[SERVER_ACCESSDENIED_MAX] = {
"This server has experienced an internal error. You will now be disconnected."
};
+enum PlayerListModifer: u8
+{
+ PLAYER_LIST_INIT,
+ PLAYER_LIST_ADD,
+ PLAYER_LIST_REMOVE,
+};
+
+
#endif
diff --git a/src/network/serveropcodes.cpp b/src/network/serveropcodes.cpp
index 19978a2b6..3f9706d6a 100644
--- a/src/network/serveropcodes.cpp
+++ b/src/network/serveropcodes.cpp
@@ -199,7 +199,7 @@ const ClientCommandFactory clientCommandFactoryTable[TOCLIENT_NUM_MSG_TYPES] =
{ "TOCLIENT_DELETE_PARTICLESPAWNER", 0, true }, // 0x53
{ "TOCLIENT_CLOUD_PARAMS", 0, true }, // 0x54
{ "TOCLIENT_FADE_SOUND", 0, true }, // 0x55
- null_command_factory,
+ { "TOCLIENT_UPDATE_PLAYER_LIST", 0, true }, // 0x56
null_command_factory,
null_command_factory,
null_command_factory,
diff --git a/src/network/serverpackethandler.cpp b/src/network/serverpackethandler.cpp
index 90b747e46..f33b1a523 100644
--- a/src/network/serverpackethandler.cpp
+++ b/src/network/serverpackethandler.cpp
@@ -705,6 +705,19 @@ void Server::handleCommand_ClientReady(NetworkPacket* pkt)
peer_id, major_ver, minor_ver, patch_ver,
full_ver);
+ const std::vector<std::string> &players = m_clients.getPlayerNames();
+ NetworkPacket list_pkt(TOCLIENT_UPDATE_PLAYER_LIST, 0, peer_id);
+ list_pkt << (u8) PLAYER_LIST_INIT << (u16) players.size();
+ for (const std::string &player: players) {
+ list_pkt << player;
+ }
+ m_clients.send(peer_id, 0, &list_pkt, true);
+
+ NetworkPacket notice_pkt(TOCLIENT_UPDATE_PLAYER_LIST, 0, PEER_ID_INEXISTENT);
+ // (u16) 1 + std::string represents a pseudo vector serialization representation
+ notice_pkt << (u8) PLAYER_LIST_ADD << (u16) 1 << std::string(playersao->getPlayer()->getName());
+ m_clients.sendToAll(&notice_pkt);
+
m_clients.event(peer_id, CSE_SetClientReady);
m_script->on_joinplayer(playersao);
// Send shutdown timer if shutdown has been scheduled