aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2011-08-10 21:43:40 +0200
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2011-08-11 15:22:36 +0200
commitecd5c5f9206437c320da029680cf1d053b644761 (patch)
treefd8c439dc142aa2ae9e87ec75dfcf71c8c12f868
parent91d1186cbb0e651de919e17e6808c75c20a0ef6f (diff)
downloadminetest-ecd5c5f9206437c320da029680cf1d053b644761.tar.gz
minetest-ecd5c5f9206437c320da029680cf1d053b644761.tar.bz2
minetest-ecd5c5f9206437c320da029680cf1d053b644761.zip
Clients inform server on wielded item
This is done with the new TOSERVER_PLAYERITEM message, that informs the server on the index of the wielded item.
-rw-r--r--src/client.cpp24
-rw-r--r--src/client.h2
-rw-r--r--src/clientserver.h8
-rw-r--r--src/server.cpp8
4 files changed, 42 insertions, 0 deletions
diff --git a/src/client.cpp b/src/client.cpp
index 2687d01e0..398b2602d 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -1864,6 +1864,28 @@ void Client::sendPlayerPos()
Send(0, data, false);
}
+void Client::sendPlayerItem(u16 item)
+{
+ Player *myplayer = m_env.getLocalPlayer();
+ if(myplayer == NULL)
+ return;
+
+ u16 our_peer_id = m_con.GetPeerID();
+
+ // Set peer id if not set already
+ if(myplayer->peer_id == PEER_ID_INEXISTENT)
+ myplayer->peer_id = our_peer_id;
+ // Check that an existing peer_id is the same as the connection's
+ assert(myplayer->peer_id == our_peer_id);
+
+ SharedBuffer<u8> data(2+2);
+ writeU16(&data[0], TOSERVER_PLAYERITEM);
+ writeU16(&data[2], item);
+
+ // Send as reliable
+ Send(0, data, true);
+}
+
void Client::removeNode(v3s16 p)
{
//JMutexAutoLock envlock(m_env_mutex); //bulk comment-out
@@ -1959,6 +1981,8 @@ void Client::selectPlayerItem(u16 item)
assert(player != NULL);
player->wieldItem(item);
+
+ sendPlayerItem(item);
}
// Returns true if the inventory of the local player has been
diff --git a/src/client.h b/src/client.h
index d21764f75..963eb6702 100644
--- a/src/client.h
+++ b/src/client.h
@@ -318,6 +318,8 @@ private:
void sendPlayerPos();
// This sends the player's current name etc to the server
void sendPlayerInfo();
+ // Send the item number 'item' as player item to the server
+ void sendPlayerItem(u16 item);
float m_packetcounter_timer;
float m_connection_reinit_timer;
diff --git a/src/clientserver.h b/src/clientserver.h
index 4981b7ea8..717e657b7 100644
--- a/src/clientserver.h
+++ b/src/clientserver.h
@@ -301,6 +301,14 @@ enum ToServerCommand
[30] u8[28] new password
*/
+ TOSERVER_PLAYERITEM=0x37,
+ /*
+ Sent to change selected item.
+
+ [0] u16 TOSERVER_PLAYERITEM
+ [2] u16 item
+ */
+
};
inline SharedBuffer<u8> makePacket_TOCLIENT_TIME_OF_DAY(u16 time)
diff --git a/src/server.cpp b/src/server.cpp
index c2fb6097e..e3747775a 100644
--- a/src/server.cpp
+++ b/src/server.cpp
@@ -3381,6 +3381,14 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
<<std::endl;
SendChatMessage(peer_id, L"Password change successful");
}
+ else if (command == TOSERVER_PLAYERITEM)
+ {
+ if (datasize < 2+2)
+ return;
+
+ u16 item = readU16(&data[2]);
+ player->wieldItem(item);
+ }
else
{
derr_server<<"WARNING: Server::ProcessData(): Ignoring "