aboutsummaryrefslogtreecommitdiff
path: root/src/network/clientpackethandler.cpp
diff options
context:
space:
mode:
authorred-001 <red-001@outlook.ie>2018-01-20 13:09:58 +0000
committerLoïc Blot <nerzhul@users.noreply.github.com>2018-01-20 14:09:58 +0100
commit9649e4721467dab348011633c814a63a184bd018 (patch)
treeb5c381d8b597406aa21889a1c40c2689adaa39a9 /src/network/clientpackethandler.cpp
parentd45e5da8ca808e552123bcd94e76b0b435a6ea79 (diff)
downloadminetest-9649e4721467dab348011633c814a63a184bd018.tar.gz
minetest-9649e4721467dab348011633c814a63a184bd018.tar.bz2
minetest-9649e4721467dab348011633c814a63a184bd018.zip
[CSM] Add basic HUD manipulation. (#6067)
* [CSM] Add basic HUD manipulation. Workaround for on_connect not working right now.
Diffstat (limited to 'src/network/clientpackethandler.cpp')
-rw-r--r--src/network/clientpackethandler.cpp53
1 files changed, 32 insertions, 21 deletions
diff --git a/src/network/clientpackethandler.cpp b/src/network/clientpackethandler.cpp
index 14aa7b6e6..bd0cd6a08 100644
--- a/src/network/clientpackethandler.cpp
+++ b/src/network/clientpackethandler.cpp
@@ -1028,7 +1028,7 @@ void Client::handleCommand_HudAdd(NetworkPacket* pkt)
std::string datastring(pkt->getString(0), pkt->getSize());
std::istringstream is(datastring, std::ios_base::binary);
- u32 id;
+ u32 server_id;
u8 type;
v2f pos;
std::string name;
@@ -1042,7 +1042,7 @@ void Client::handleCommand_HudAdd(NetworkPacket* pkt)
v3f world_pos;
v2s32 size;
- *pkt >> id >> type >> pos >> name >> scale >> text >> number >> item
+ *pkt >> server_id >> type >> pos >> name >> scale >> text >> number >> item
>> dir >> align >> offset;
try {
*pkt >> world_pos;
@@ -1052,10 +1052,12 @@ void Client::handleCommand_HudAdd(NetworkPacket* pkt)
try {
*pkt >> size;
} catch(SerializationError &e) {};
+ u32 client_id = getEnv().getLocalPlayer()->getFreeHudID();
+ m_hud_server_to_client[server_id] = client_id;
ClientEvent *event = new ClientEvent();
event->type = CE_HUDADD;
- event->hudadd.id = id;
+ event->hudadd.id = client_id;
event->hudadd.type = type;
event->hudadd.pos = new v2f(pos);
event->hudadd.name = new std::string(name);
@@ -1073,14 +1075,20 @@ void Client::handleCommand_HudAdd(NetworkPacket* pkt)
void Client::handleCommand_HudRemove(NetworkPacket* pkt)
{
- u32 id;
+ u32 server_id;
- *pkt >> id;
+ *pkt >> server_id;
- ClientEvent *event = new ClientEvent();
- event->type = CE_HUDRM;
- event->hudrm.id = id;
- m_client_event_queue.push(event);
+ std::unordered_map<u32, u32>::const_iterator i = m_hud_server_to_client.find(server_id);
+ if (i != m_hud_server_to_client.end()) {
+ int client_id = i->second;
+ m_hud_server_to_client.erase(i);
+
+ ClientEvent *event = new ClientEvent();
+ event->type = CE_HUDRM;
+ event->hudrm.id = client_id;
+ m_client_event_queue.push(event);
+ }
}
void Client::handleCommand_HudChange(NetworkPacket* pkt)
@@ -1090,10 +1098,10 @@ void Client::handleCommand_HudChange(NetworkPacket* pkt)
v3f v3fdata;
u32 intdata = 0;
v2s32 v2s32data;
- u32 id;
+ u32 server_id;
u8 stat;
- *pkt >> id >> stat;
+ *pkt >> server_id >> stat;
if (stat == HUD_STAT_POS || stat == HUD_STAT_SCALE ||
stat == HUD_STAT_ALIGN || stat == HUD_STAT_OFFSET)
@@ -1107,16 +1115,19 @@ void Client::handleCommand_HudChange(NetworkPacket* pkt)
else
*pkt >> intdata;
- ClientEvent *event = new ClientEvent();
- event->type = CE_HUDCHANGE;
- event->hudchange.id = id;
- event->hudchange.stat = (HudElementStat)stat;
- event->hudchange.v2fdata = new v2f(v2fdata);
- event->hudchange.v3fdata = new v3f(v3fdata);
- event->hudchange.sdata = new std::string(sdata);
- event->hudchange.data = intdata;
- event->hudchange.v2s32data = new v2s32(v2s32data);
- m_client_event_queue.push(event);
+ std::unordered_map<u32, u32>::const_iterator i = m_hud_server_to_client.find(server_id);
+ if (i != m_hud_server_to_client.end()) {
+ ClientEvent *event = new ClientEvent();
+ event->type = CE_HUDCHANGE;
+ event->hudchange.id = i->second;
+ event->hudchange.stat = (HudElementStat)stat;
+ event->hudchange.v2fdata = new v2f(v2fdata);
+ event->hudchange.v3fdata = new v3f(v3fdata);
+ event->hudchange.sdata = new std::string(sdata);
+ event->hudchange.data = intdata;
+ event->hudchange.v2s32data = new v2s32(v2s32data);
+ m_client_event_queue.push(event);
+ }
}
void Client::handleCommand_HudSetFlags(NetworkPacket* pkt)