mirror of
https://github.com/minetest/minetest.git
synced 2024-11-27 10:03:45 +01:00
Move client packet generators to dedicated functions for:
* TOSERVER_INIT_LEGACY * TOSERVER_DELETEDBLOCKS * TOSERVER_GOTBLOCKS * TOSERVER_REMOVED_SOUNDS Also use a std::vector instead of std::set for TOSERVER_REMOVED_SOUNDS
This commit is contained in:
parent
e7736ffdd6
commit
d63df4ecb1
@ -407,15 +407,7 @@ void Client::step(float dtime)
|
|||||||
snprintf(pName, PLAYERNAME_SIZE, "%s", myplayer->getName());
|
snprintf(pName, PLAYERNAME_SIZE, "%s", myplayer->getName());
|
||||||
snprintf(pPassword, PASSWORD_SIZE, "%s", m_password.c_str());
|
snprintf(pPassword, PASSWORD_SIZE, "%s", m_password.c_str());
|
||||||
|
|
||||||
NetworkPacket pkt(TOSERVER_INIT_LEGACY,
|
sendLegacyInit(pName, pPassword);
|
||||||
1 + PLAYERNAME_SIZE + PASSWORD_SIZE + 2 + 2);
|
|
||||||
|
|
||||||
pkt << (u8) SER_FMT_VER_HIGHEST_READ;
|
|
||||||
pkt.putRawString(pName,PLAYERNAME_SIZE);
|
|
||||||
pkt.putRawString(pPassword, PASSWORD_SIZE);
|
|
||||||
pkt << (u16) CLIENT_PROTOCOL_VERSION_MIN << (u16) CLIENT_PROTOCOL_VERSION_MAX;
|
|
||||||
|
|
||||||
Send(&pkt);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Not connected, return
|
// Not connected, return
|
||||||
@ -455,19 +447,8 @@ void Client::step(float dtime)
|
|||||||
[3+6] v3s16 pos_1
|
[3+6] v3s16 pos_1
|
||||||
...
|
...
|
||||||
*/
|
*/
|
||||||
NetworkPacket pkt(TOSERVER_DELETEDBLOCKS, 1 + sizeof(v3s16) * sendlist.size());
|
|
||||||
|
|
||||||
pkt << (u8) sendlist.size();
|
sendDeletedBlocks(sendlist);
|
||||||
|
|
||||||
u32 k = 0;
|
|
||||||
for(std::vector<v3s16>::iterator
|
|
||||||
j = sendlist.begin();
|
|
||||||
j != sendlist.end(); ++j) {
|
|
||||||
pkt << *j;
|
|
||||||
k++;
|
|
||||||
}
|
|
||||||
|
|
||||||
Send(&pkt);
|
|
||||||
|
|
||||||
if(i == deleted_blocks.end())
|
if(i == deleted_blocks.end())
|
||||||
break;
|
break;
|
||||||
@ -575,9 +556,7 @@ void Client::step(float dtime)
|
|||||||
[0] u8 count
|
[0] u8 count
|
||||||
[1] v3s16 pos_0
|
[1] v3s16 pos_0
|
||||||
*/
|
*/
|
||||||
NetworkPacket pkt(TOSERVER_GOTBLOCKS, 1 + 6);
|
sendGotBlocks(r.p);
|
||||||
pkt << (u8) 1 << r.p;
|
|
||||||
Send(&pkt);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -646,7 +625,7 @@ void Client::step(float dtime)
|
|||||||
if(m_removed_sounds_check_timer >= 2.32) {
|
if(m_removed_sounds_check_timer >= 2.32) {
|
||||||
m_removed_sounds_check_timer = 0;
|
m_removed_sounds_check_timer = 0;
|
||||||
// Find removed sounds and clear references to them
|
// Find removed sounds and clear references to them
|
||||||
std::set<s32> removed_server_ids;
|
std::vector<s32> removed_server_ids;
|
||||||
for(std::map<s32, int>::iterator
|
for(std::map<s32, int>::iterator
|
||||||
i = m_sounds_server_to_client.begin();
|
i = m_sounds_server_to_client.begin();
|
||||||
i != m_sounds_server_to_client.end();) {
|
i != m_sounds_server_to_client.end();) {
|
||||||
@ -657,24 +636,13 @@ void Client::step(float dtime)
|
|||||||
m_sounds_server_to_client.erase(server_id);
|
m_sounds_server_to_client.erase(server_id);
|
||||||
m_sounds_client_to_server.erase(client_id);
|
m_sounds_client_to_server.erase(client_id);
|
||||||
m_sounds_to_objects.erase(client_id);
|
m_sounds_to_objects.erase(client_id);
|
||||||
removed_server_ids.insert(server_id);
|
removed_server_ids.push_back(server_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sync to server
|
// Sync to server
|
||||||
if(!removed_server_ids.empty()) {
|
if(!removed_server_ids.empty()) {
|
||||||
size_t server_ids = removed_server_ids.size();
|
sendRemovedSounds(removed_server_ids);
|
||||||
assert(server_ids <= 0xFFFF);
|
|
||||||
|
|
||||||
NetworkPacket pkt(TOSERVER_REMOVED_SOUNDS, 2 + server_ids * 4);
|
|
||||||
|
|
||||||
pkt << (u16) (server_ids & 0xFFFF);
|
|
||||||
|
|
||||||
for(std::set<s32>::iterator i = removed_server_ids.begin();
|
|
||||||
i != removed_server_ids.end(); i++)
|
|
||||||
pkt << *i;
|
|
||||||
|
|
||||||
Send(&pkt);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -983,6 +951,59 @@ void Client::interact(u8 action, const PointedThing& pointed)
|
|||||||
Send(&pkt);
|
Send(&pkt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Client::sendLegacyInit(const char* playerName, const char* playerPassword)
|
||||||
|
{
|
||||||
|
NetworkPacket pkt(TOSERVER_INIT_LEGACY,
|
||||||
|
1 + PLAYERNAME_SIZE + PASSWORD_SIZE + 2 + 2);
|
||||||
|
|
||||||
|
pkt << (u8) SER_FMT_VER_HIGHEST_READ;
|
||||||
|
pkt.putRawString(playerName,PLAYERNAME_SIZE);
|
||||||
|
pkt.putRawString(playerPassword, PASSWORD_SIZE);
|
||||||
|
pkt << (u16) CLIENT_PROTOCOL_VERSION_MIN << (u16) CLIENT_PROTOCOL_VERSION_MAX;
|
||||||
|
|
||||||
|
Send(&pkt);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Client::sendDeletedBlocks(std::vector<v3s16> &blocks)
|
||||||
|
{
|
||||||
|
NetworkPacket pkt(TOSERVER_DELETEDBLOCKS, 1 + sizeof(v3s16) * blocks.size());
|
||||||
|
|
||||||
|
pkt << (u8) blocks.size();
|
||||||
|
|
||||||
|
u32 k = 0;
|
||||||
|
for(std::vector<v3s16>::iterator
|
||||||
|
j = blocks.begin();
|
||||||
|
j != blocks.end(); ++j) {
|
||||||
|
pkt << *j;
|
||||||
|
k++;
|
||||||
|
}
|
||||||
|
|
||||||
|
Send(&pkt);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Client::sendGotBlocks(v3s16 block)
|
||||||
|
{
|
||||||
|
NetworkPacket pkt(TOSERVER_GOTBLOCKS, 1 + 6);
|
||||||
|
pkt << (u8) 1 << block;
|
||||||
|
Send(&pkt);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Client::sendRemovedSounds(std::vector<s32> &soundList)
|
||||||
|
{
|
||||||
|
size_t server_ids = soundList.size();
|
||||||
|
assert(server_ids <= 0xFFFF);
|
||||||
|
|
||||||
|
NetworkPacket pkt(TOSERVER_REMOVED_SOUNDS, 2 + server_ids * 4);
|
||||||
|
|
||||||
|
pkt << (u16) (server_ids & 0xFFFF);
|
||||||
|
|
||||||
|
for(std::vector<s32>::iterator i = soundList.begin();
|
||||||
|
i != soundList.end(); i++)
|
||||||
|
pkt << *i;
|
||||||
|
|
||||||
|
Send(&pkt);
|
||||||
|
}
|
||||||
|
|
||||||
void Client::sendNodemetaFields(v3s16 p, const std::string &formname,
|
void Client::sendNodemetaFields(v3s16 p, const std::string &formname,
|
||||||
const std::map<std::string, std::string> &fields)
|
const std::map<std::string, std::string> &fields)
|
||||||
{
|
{
|
||||||
|
@ -542,6 +542,11 @@ private:
|
|||||||
// Send the item number 'item' as player item to the server
|
// Send the item number 'item' as player item to the server
|
||||||
void sendPlayerItem(u16 item);
|
void sendPlayerItem(u16 item);
|
||||||
|
|
||||||
|
void sendLegacyInit(const char* playerName, const char* playerPassword);
|
||||||
|
void sendDeletedBlocks(std::vector<v3s16> &blocks);
|
||||||
|
void sendGotBlocks(v3s16 block);
|
||||||
|
void sendRemovedSounds(std::vector<s32> &soundList);
|
||||||
|
|
||||||
float m_packetcounter_timer;
|
float m_packetcounter_timer;
|
||||||
float m_connection_reinit_timer;
|
float m_connection_reinit_timer;
|
||||||
float m_avg_rtt_timer;
|
float m_avg_rtt_timer;
|
||||||
|
Loading…
Reference in New Issue
Block a user