Skip to content

Commit e7736ff

Browse files
committedMar 16, 2015
Move TOCLIENT_ACTIVE_OBJECT_REMOVE_ADD and TOCLIENT_ACTIVE_OBJECT_MESSAGES to private functions
1 parent b560294 commit e7736ff

File tree

2 files changed

+23
-17
lines changed

2 files changed

+23
-17
lines changed
 

‎src/server.cpp

+21-17
Original file line numberDiff line numberDiff line change
@@ -758,16 +758,11 @@ void Server::AsyncRunStep(bool initial_step)
758758
obj->m_known_by_count++;
759759
}
760760

761-
NetworkPacket pkt(TOCLIENT_ACTIVE_OBJECT_REMOVE_ADD, 0, client->peer_id);
762-
pkt.putRawString(data_buffer.c_str(), data_buffer.size());
763-
764-
761+
u32 pktSize = SendActiveObjectRemoveAdd(client->peer_id, data_buffer);
765762
verbosestream << "Server: Sent object remove/add: "
766763
<< removed_objects.size() << " removed, "
767764
<< added_objects.size() << " added, "
768-
<< "packet size is " << pkt.getSize() << std::endl;
769-
770-
Send(&pkt);
765+
<< "packet size is " << pktSize << std::endl;
771766
}
772767
m_clients.Unlock();
773768
}
@@ -846,19 +841,11 @@ void Server::AsyncRunStep(bool initial_step)
846841
Send them.
847842
*/
848843
if(reliable_data.size() > 0) {
849-
NetworkPacket pkt(TOCLIENT_ACTIVE_OBJECT_MESSAGES,
850-
0, client->peer_id);
851-
852-
pkt.putRawString(reliable_data.c_str(), reliable_data.size());
853-
Send(&pkt);
844+
SendActiveObjectMessages(client->peer_id, reliable_data);
854845
}
855846

856847
if(unreliable_data.size() > 0) {
857-
NetworkPacket pkt(TOCLIENT_ACTIVE_OBJECT_MESSAGES,
858-
0, client->peer_id);
859-
860-
pkt.putRawString(unreliable_data.c_str(), unreliable_data.size());
861-
Send(&pkt);
848+
SendActiveObjectMessages(client->peer_id, unreliable_data);
862849
}
863850
}
864851
m_clients.Unlock();
@@ -1898,6 +1885,23 @@ void Server::SendPlayerInventoryFormspec(u16 peer_id)
18981885
Send(&pkt);
18991886
}
19001887

1888+
u32 Server::SendActiveObjectRemoveAdd(u16 peer_id, const std::string &datas)
1889+
{
1890+
NetworkPacket pkt(TOCLIENT_ACTIVE_OBJECT_REMOVE_ADD, 0, peer_id);
1891+
pkt.putRawString(datas.c_str(), datas.size());
1892+
Send(&pkt);
1893+
return pkt.getSize();
1894+
}
1895+
1896+
void Server::SendActiveObjectMessages(u16 peer_id, const std::string &datas)
1897+
{
1898+
NetworkPacket pkt(TOCLIENT_ACTIVE_OBJECT_MESSAGES,
1899+
0, peer_id);
1900+
1901+
pkt.putRawString(datas.c_str(), datas.size());
1902+
Send(&pkt);
1903+
}
1904+
19011905
s32 Server::playSound(const SimpleSoundSpec &spec,
19021906
const ServerSoundParams &params)
19031907
{

‎src/server.h

+2
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,8 @@ class Server : public con::PeerHandler, public MapEventReceiver,
463463
float expirationtime, float size,
464464
bool collisiondetection, bool vertical, std::string texture);
465465

466+
u32 SendActiveObjectRemoveAdd(u16 peer_id, const std::string &datas);
467+
void SendActiveObjectMessages(u16 peer_id, const std::string &datas);
466468
/*
467469
Something random
468470
*/

0 commit comments

Comments
 (0)
Please sign in to comment.