snprintf(pName, PLAYERNAME_SIZE, "%s", myplayer->getName());
snprintf(pPassword, PASSWORD_SIZE, "%s", m_password.c_str());
- NetworkPacket* pkt = new NetworkPacket(TOSERVER_INIT_LEGACY,
+ NetworkPacket pkt(TOSERVER_INIT_LEGACY,
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;
+ 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);
+ Send(&pkt);
}
// Not connected, return
[3+6] v3s16 pos_1
...
*/
- NetworkPacket* pkt = new NetworkPacket(TOSERVER_DELETEDBLOCKS, 1 + sizeof(v3s16) * sendlist.size());
+ NetworkPacket pkt(TOSERVER_DELETEDBLOCKS, 1 + sizeof(v3s16) * sendlist.size());
- *pkt << (u8) sendlist.size();
+ pkt << (u8) sendlist.size();
u32 k = 0;
for(std::vector<v3s16>::iterator
j = sendlist.begin();
j != sendlist.end(); ++j) {
- *pkt << *j;
+ pkt << *j;
k++;
}
- Send(pkt);
+ Send(&pkt);
if(i == deleted_blocks.end())
break;
[0] u8 count
[1] v3s16 pos_0
*/
- NetworkPacket* pkt = new NetworkPacket(TOSERVER_GOTBLOCKS, 1 + 6);
- *pkt << (u8) 1 << r.p;
- Send(pkt);
+ NetworkPacket pkt(TOSERVER_GOTBLOCKS, 1 + 6);
+ pkt << (u8) 1 << r.p;
+ Send(&pkt);
}
}
size_t server_ids = removed_server_ids.size();
assert(server_ids <= 0xFFFF);
- NetworkPacket* pkt = new NetworkPacket(TOSERVER_REMOVED_SOUNDS, 2 + server_ids * 4);
+ NetworkPacket pkt(TOSERVER_REMOVED_SOUNDS, 2 + server_ids * 4);
- *pkt << (u16) (server_ids & 0xFFFF);
+ pkt << (u16) (server_ids & 0xFFFF);
for(std::set<s32>::iterator i = removed_server_ids.begin();
i != removed_server_ids.end(); i++)
- *pkt << *i;
+ pkt << *i;
- Send(pkt);
+ Send(&pkt);
}
}
FATAL_ERROR_IF(file_requests_size > 0xFFFF, "Unsupported number of file requests");
// Packet dynamicly resized
- NetworkPacket* pkt = new NetworkPacket(TOSERVER_REQUEST_MEDIA, 2 + 0);
+ NetworkPacket pkt(TOSERVER_REQUEST_MEDIA, 2 + 0);
- *pkt << (u16) (file_requests_size & 0xFFFF);
+ pkt << (u16) (file_requests_size & 0xFFFF);
for(std::vector<std::string>::const_iterator i = file_requests.begin();
i != file_requests.end(); ++i) {
- *pkt << (*i);
+ pkt << (*i);
}
- Send(pkt);
+ Send(&pkt);
- infostream<<"Client: Sending media request list to server ("
- <<file_requests.size()<<" files. packet size)"<<std::endl;
+ infostream << "Client: Sending media request list to server ("
+ << file_requests.size() << " files. packet size)" << std::endl;
}
void Client::received_media()
{
- NetworkPacket* pkt = new NetworkPacket(TOSERVER_RECEIVED_MEDIA, 0);
- Send(pkt);
- infostream<<"Client: Notifying server that we received all media"
- <<std::endl;
+ NetworkPacket pkt(TOSERVER_RECEIVED_MEDIA, 0);
+ Send(&pkt);
+ infostream << "Client: Notifying server that we received all media"
+ << std::endl;
}
void Client::initLocalMapSaving(const Address &address,
return;
}
- NetworkPacket* pkt = new NetworkPacket(data, datasize, sender_peer_id);
+ NetworkPacket pkt(data, datasize, sender_peer_id);
- ToClientCommand command = (ToClientCommand) pkt->getCommand();
+ ToClientCommand command = (ToClientCommand) pkt.getCommand();
//infostream<<"Client: received command="<<command<<std::endl;
m_packetcounter.add((u16)command);
infostream << "Client::ProcessData(): Discarding data not "
"coming from server: peer_id=" << sender_peer_id
<< std::endl;
- delete pkt;
return;
}
* as a byte mask
*/
if(toClientCommandTable[command].state == TOCLIENT_STATE_NOT_CONNECTED) {
- handleCommand(pkt);
- delete pkt;
+ handleCommand(&pkt);
return;
}
infostream << "Client: Server serialization"
" format invalid or not initialized."
" Skipping incoming command=" << command << std::endl;
- delete pkt;
return;
}
Handle runtime commands
*/
- handleCommand(pkt);
- delete pkt;
+ handleCommand(&pkt);
}
void Client::Send(NetworkPacket* pkt)
serverCommandFactoryTable[pkt->getCommand()].channel,
pkt,
serverCommandFactoryTable[pkt->getCommand()].reliable);
- delete pkt;
}
void Client::interact(u8 action, const PointedThing& pointed)
4: use item
*/
- NetworkPacket* pkt = new NetworkPacket(TOSERVER_INTERACT, 1 + 2 + 0);
+ NetworkPacket pkt(TOSERVER_INTERACT, 1 + 2 + 0);
- *pkt << action;
- *pkt << (u16)getPlayerItem();
+ pkt << action;
+ pkt << (u16)getPlayerItem();
std::ostringstream tmp_os(std::ios::binary);
pointed.serialize(tmp_os);
- pkt->putLongString(tmp_os.str());
+ pkt.putLongString(tmp_os.str());
- Send(pkt);
+ Send(&pkt);
}
void Client::sendNodemetaFields(v3s16 p, const std::string &formname,
FATAL_ERROR_IF(fields_size > 0xFFFF, "Unsupported number of nodemeta fields");
- NetworkPacket* pkt = new NetworkPacket(TOSERVER_NODEMETA_FIELDS, 0);
+ NetworkPacket pkt(TOSERVER_NODEMETA_FIELDS, 0);
- *pkt << p << formname << (u16) (fields_size & 0xFFFF);
+ pkt << p << formname << (u16) (fields_size & 0xFFFF);
for(std::map<std::string, std::string>::const_iterator
i = fields.begin(); i != fields.end(); i++) {
const std::string &name = i->first;
const std::string &value = i->second;
- *pkt << name;
- pkt->putLongString(value);
+ pkt << name;
+ pkt.putLongString(value);
}
- Send(pkt);
+ Send(&pkt);
}
void Client::sendInventoryFields(const std::string &formname,
size_t fields_size = fields.size();
FATAL_ERROR_IF(fields_size > 0xFFFF, "Unsupported number of inventory fields");
- NetworkPacket* pkt = new NetworkPacket(TOSERVER_INVENTORY_FIELDS, 0);
- *pkt << formname << (u16) (fields_size & 0xFFFF);
+ NetworkPacket pkt(TOSERVER_INVENTORY_FIELDS, 0);
+ pkt << formname << (u16) (fields_size & 0xFFFF);
for(std::map<std::string, std::string>::const_iterator
i = fields.begin(); i != fields.end(); i++) {
const std::string &name = i->first;
const std::string &value = i->second;
- *pkt << name;
- pkt->putLongString(value);
+ pkt << name;
+ pkt.putLongString(value);
}
- Send(pkt);
+ Send(&pkt);
}
void Client::sendInventoryAction(InventoryAction *a)
// Make data buffer
std::string s = os.str();
- NetworkPacket* pkt = new NetworkPacket(TOSERVER_INVENTORY_ACTION, s.size());
- pkt->putRawString(s.c_str(),s.size());
+ NetworkPacket pkt(TOSERVER_INVENTORY_ACTION, s.size());
+ pkt.putRawString(s.c_str(),s.size());
- Send(pkt);
+ Send(&pkt);
}
void Client::sendChatMessage(const std::wstring &message)
{
- NetworkPacket* pkt = new NetworkPacket(TOSERVER_CHAT_MESSAGE, 2 + message.size() * sizeof(u16));
+ NetworkPacket pkt(TOSERVER_CHAT_MESSAGE, 2 + message.size() * sizeof(u16));
- *pkt << message;
+ pkt << message;
- Send(pkt);
+ Send(&pkt);
}
void Client::sendChangePassword(const std::wstring &oldpassword,
std::string oldpwd = translatePassword(playername, oldpassword);
std::string newpwd = translatePassword(playername, newpassword);
- NetworkPacket* pkt = new NetworkPacket(TOSERVER_PASSWORD_LEGACY, 2 * PASSWORD_SIZE);
+ NetworkPacket pkt(TOSERVER_PASSWORD_LEGACY, 2 * PASSWORD_SIZE);
for(u8 i = 0; i < PASSWORD_SIZE; i++) {
- *pkt << (u8) (i < oldpwd.length() ? oldpwd[i] : 0);
+ pkt << (u8) (i < oldpwd.length() ? oldpwd[i] : 0);
}
for(u8 i = 0; i < PASSWORD_SIZE; i++) {
- *pkt << (u8) (i < newpwd.length() ? newpwd[i] : 0);
+ pkt << (u8) (i < newpwd.length() ? newpwd[i] : 0);
}
- Send(pkt);
+ Send(&pkt);
}
{
DSTACK(__FUNCTION_NAME);
- NetworkPacket* pkt = new NetworkPacket(TOSERVER_DAMAGE, sizeof(u8));
- *pkt << damage;
- Send(pkt);
+ NetworkPacket pkt(TOSERVER_DAMAGE, sizeof(u8));
+ pkt << damage;
+ Send(&pkt);
}
void Client::sendBreath(u16 breath)
{
DSTACK(__FUNCTION_NAME);
- NetworkPacket* pkt = new NetworkPacket(TOSERVER_BREATH, sizeof(u16));
- *pkt << breath;
- Send(pkt);
+ NetworkPacket pkt(TOSERVER_BREATH, sizeof(u16));
+ pkt << breath;
+ Send(&pkt);
}
void Client::sendRespawn()
{
DSTACK(__FUNCTION_NAME);
- NetworkPacket* pkt = new NetworkPacket(TOSERVER_RESPAWN, 0);
- Send(pkt);
+ NetworkPacket pkt(TOSERVER_RESPAWN, 0);
+ Send(&pkt);
}
void Client::sendReady()
{
DSTACK(__FUNCTION_NAME);
- NetworkPacket* pkt = new NetworkPacket(TOSERVER_CLIENT_READY,
+ NetworkPacket pkt(TOSERVER_CLIENT_READY,
1 + 1 + 1 + 1 + 2 + sizeof(char) * strlen(minetest_version_hash));
- *pkt << (u8) VERSION_MAJOR << (u8) VERSION_MINOR << (u8) VERSION_PATCH_ORIG
+ pkt << (u8) VERSION_MAJOR << (u8) VERSION_MINOR << (u8) VERSION_PATCH_ORIG
<< (u8) 0 << (u16) strlen(minetest_version_hash);
- pkt->putRawString(minetest_version_hash, (u16) strlen(minetest_version_hash));
- Send(pkt);
+ pkt.putRawString(minetest_version_hash, (u16) strlen(minetest_version_hash));
+ Send(&pkt);
}
void Client::sendPlayerPos()
[12+12+4+4] u32 keyPressed
*/
- NetworkPacket* pkt = new NetworkPacket(TOSERVER_PLAYERPOS, 12 + 12 + 4 + 4 + 4);
+ NetworkPacket pkt(TOSERVER_PLAYERPOS, 12 + 12 + 4 + 4 + 4);
- *pkt << position << speed << pitch << yaw << keyPressed;
+ pkt << position << speed << pitch << yaw << keyPressed;
- Send(pkt);
+ Send(&pkt);
}
void Client::sendPlayerItem(u16 item)
myplayer->peer_id = our_peer_id;
assert(myplayer->peer_id == our_peer_id);
- NetworkPacket* pkt = new NetworkPacket(TOSERVER_PLAYERITEM, 2);
+ NetworkPacket pkt(TOSERVER_PLAYERITEM, 2);
- *pkt << item;
+ pkt << item;
- Send(pkt);
+ Send(&pkt);
}
void Client::removeNode(v3s16 p)
obj->m_known_by_count++;
}
- NetworkPacket* pkt = new NetworkPacket(TOCLIENT_ACTIVE_OBJECT_REMOVE_ADD, 0, client->peer_id);
- pkt->putRawString(data_buffer.c_str(), data_buffer.size());
+ NetworkPacket pkt(TOCLIENT_ACTIVE_OBJECT_REMOVE_ADD, 0, client->peer_id);
+ pkt.putRawString(data_buffer.c_str(), data_buffer.size());
verbosestream << "Server: Sent object remove/add: "
<< removed_objects.size() << " removed, "
<< added_objects.size() << " added, "
- << "packet size is " << pkt->getSize() << std::endl;
+ << "packet size is " << pkt.getSize() << std::endl;
- Send(pkt);
+ Send(&pkt);
}
m_clients.Unlock();
}
Send them.
*/
if(reliable_data.size() > 0) {
- NetworkPacket* pkt = new NetworkPacket(TOCLIENT_ACTIVE_OBJECT_MESSAGES,
+ NetworkPacket pkt(TOCLIENT_ACTIVE_OBJECT_MESSAGES,
0, client->peer_id);
- pkt->putRawString(reliable_data.c_str(), reliable_data.size());
- Send(pkt);
+ pkt.putRawString(reliable_data.c_str(), reliable_data.size());
+ Send(&pkt);
}
if(unreliable_data.size() > 0) {
- NetworkPacket* pkt = new NetworkPacket(TOCLIENT_ACTIVE_OBJECT_MESSAGES,
+ NetworkPacket pkt(TOCLIENT_ACTIVE_OBJECT_MESSAGES,
0, client->peer_id);
- pkt->putRawString(unreliable_data.c_str(), unreliable_data.size());
- Send(pkt);
+ pkt.putRawString(unreliable_data.c_str(), unreliable_data.size());
+ Send(&pkt);
}
}
m_clients.Unlock();
if(datasize < 2)
return;
- NetworkPacket* pkt = new NetworkPacket(data, datasize, peer_id);
+ NetworkPacket pkt(data, datasize, peer_id);
- ToServerCommand command = (ToServerCommand) pkt->getCommand();
+ ToServerCommand command = (ToServerCommand) pkt.getCommand();
// Command must be handled into ToServerCommandHandler
if (command >= TOSERVER_NUM_MSG_TYPES) {
}
if (toServerCommandTable[command].state == TOSERVER_STATE_NOT_CONNECTED) {
- handleCommand(pkt);
- delete pkt;
+ handleCommand(&pkt);
return;
}
errorstream << "Server::ProcessData(): Cancelling: Peer"
" serialization format invalid or not initialized."
" Skipping incoming command=" << command << std::endl;
-
- delete pkt;
return;
}
/* Handle commands related to client startup */
if (toServerCommandTable[command].state == TOSERVER_STATE_STARTUP) {
- handleCommand(pkt);
- delete pkt;
+ handleCommand(&pkt);
return;
}
errorstream << "Got packet command: " << command << " for peer id "
<< peer_id << " but client isn't active yet. Dropping packet "
<< std::endl;
-
- delete pkt;
return;
}
- handleCommand(pkt);
- delete pkt;
-
+ handleCommand(&pkt);
}
catch(SendFailedException &e) {
errorstream << "Server::ProcessData(): SendFailedException: "
DSTACK(__FUNCTION_NAME);
std::ostringstream os(std::ios_base::binary);
- NetworkPacket* pkt = new NetworkPacket(TOCLIENT_MOVEMENT, 12 * sizeof(float), peer_id);
+ NetworkPacket pkt(TOCLIENT_MOVEMENT, 12 * sizeof(float), peer_id);
+
+ pkt << g_settings->getFloat("movement_acceleration_default");
+ pkt << g_settings->getFloat("movement_acceleration_air");
+ pkt << g_settings->getFloat("movement_acceleration_fast");
+ pkt << g_settings->getFloat("movement_speed_walk");
+ pkt << g_settings->getFloat("movement_speed_crouch");
+ pkt << g_settings->getFloat("movement_speed_fast");
+ pkt << g_settings->getFloat("movement_speed_climb");
+ pkt << g_settings->getFloat("movement_speed_jump");
+ pkt << g_settings->getFloat("movement_liquid_fluidity");
+ pkt << g_settings->getFloat("movement_liquid_fluidity_smooth");
+ pkt << g_settings->getFloat("movement_liquid_sink");
+ pkt << g_settings->getFloat("movement_gravity");
- *pkt << g_settings->getFloat("movement_acceleration_default");
- *pkt << g_settings->getFloat("movement_acceleration_air");
- *pkt << g_settings->getFloat("movement_acceleration_fast");
- *pkt << g_settings->getFloat("movement_speed_walk");
- *pkt << g_settings->getFloat("movement_speed_crouch");
- *pkt << g_settings->getFloat("movement_speed_fast");
- *pkt << g_settings->getFloat("movement_speed_climb");
- *pkt << g_settings->getFloat("movement_speed_jump");
- *pkt << g_settings->getFloat("movement_liquid_fluidity");
- *pkt << g_settings->getFloat("movement_liquid_fluidity_smooth");
- *pkt << g_settings->getFloat("movement_liquid_sink");
- *pkt << g_settings->getFloat("movement_gravity");
-
- Send(pkt);
+ Send(&pkt);
}
void Server::SendHP(u16 peer_id, u8 hp)
{
DSTACK(__FUNCTION_NAME);
- NetworkPacket* pkt = new NetworkPacket(TOCLIENT_HP, 1, peer_id);
- *pkt << hp;
- Send(pkt);
+ NetworkPacket pkt(TOCLIENT_HP, 1, peer_id);
+ pkt << hp;
+ Send(&pkt);
}
void Server::SendBreath(u16 peer_id, u16 breath)
{
DSTACK(__FUNCTION_NAME);
- NetworkPacket* pkt = new NetworkPacket(TOCLIENT_BREATH, 2, peer_id);
- *pkt << (u16) breath;
- Send(pkt);
+ NetworkPacket pkt(TOCLIENT_BREATH, 2, peer_id);
+ pkt << (u16) breath;
+ Send(&pkt);
}
void Server::SendAccessDenied(u16 peer_id, AccessDeniedCode reason, const std::wstring &custom_reason)
{
DSTACK(__FUNCTION_NAME);
- NetworkPacket* pkt = new NetworkPacket(TOCLIENT_ACCESS_DENIED_LEGACY, 0, peer_id);
- *pkt << reason;
- Send(pkt);
+ NetworkPacket pkt(TOCLIENT_ACCESS_DENIED_LEGACY, 0, peer_id);
+ pkt << reason;
+ Send(&pkt);
}
void Server::SendDeathscreen(u16 peer_id,bool set_camera_point_target,
{
DSTACK(__FUNCTION_NAME);
- NetworkPacket* pkt = new NetworkPacket(TOCLIENT_DEATHSCREEN, 1 + sizeof(v3f), peer_id);
- *pkt << set_camera_point_target << camera_point_target;
- Send(pkt);
+ NetworkPacket pkt(TOCLIENT_DEATHSCREEN, 1 + sizeof(v3f), peer_id);
+ pkt << set_camera_point_target << camera_point_target;
+ Send(&pkt);
}
void Server::SendItemDef(u16 peer_id,
{
DSTACK(__FUNCTION_NAME);
- NetworkPacket* pkt = new NetworkPacket(TOCLIENT_ITEMDEF, 0, peer_id);
+ NetworkPacket pkt(TOCLIENT_ITEMDEF, 0, peer_id);
/*
u16 command
itemdef->serialize(tmp_os, protocol_version);
std::ostringstream tmp_os2(std::ios::binary);
compressZlib(tmp_os.str(), tmp_os2);
- pkt->putLongString(tmp_os2.str());
+ pkt.putLongString(tmp_os2.str());
// Make data buffer
verbosestream << "Server: Sending item definitions to id(" << peer_id
- << "): size=" << pkt->getSize() << std::endl;
+ << "): size=" << pkt.getSize() << std::endl;
- Send(pkt);
+ Send(&pkt);
}
void Server::SendNodeDef(u16 peer_id,
{
DSTACK(__FUNCTION_NAME);
- NetworkPacket* pkt = new NetworkPacket(TOCLIENT_NODEDEF, 0, peer_id);
+ NetworkPacket pkt(TOCLIENT_NODEDEF, 0, peer_id);
/*
u16 command
std::ostringstream tmp_os2(std::ios::binary);
compressZlib(tmp_os.str(), tmp_os2);
- pkt->putLongString(tmp_os2.str());
+ pkt.putLongString(tmp_os2.str());
// Make data buffer
verbosestream << "Server: Sending node definitions to id(" << peer_id
- << "): size=" << pkt->getSize() << std::endl;
+ << "): size=" << pkt.getSize() << std::endl;
- Send(pkt);
+ Send(&pkt);
}
/*
Serialize it
*/
- NetworkPacket* pkt = new NetworkPacket(TOCLIENT_INVENTORY, 0,
- playerSAO->getPeerID());
+ NetworkPacket pkt(TOCLIENT_INVENTORY, 0, playerSAO->getPeerID());
std::ostringstream os;
playerSAO->getInventory()->serialize(os);
std::string s = os.str();
- pkt->putRawString(s.c_str(), s.size());
- Send(pkt);
+ pkt.putRawString(s.c_str(), s.size());
+ Send(&pkt);
}
void Server::SendChatMessage(u16 peer_id, const std::wstring &message)
{
DSTACK(__FUNCTION_NAME);
- NetworkPacket* pkt = new NetworkPacket(TOCLIENT_CHAT_MESSAGE, 0, peer_id);
- *pkt << message;
+ NetworkPacket pkt(TOCLIENT_CHAT_MESSAGE, 0, peer_id);
+ pkt << message;
if (peer_id != PEER_ID_INEXISTENT) {
- Send(pkt);
+ Send(&pkt);
}
else {
- m_clients.sendToAll(0,pkt,true);
+ m_clients.sendToAll(0, &pkt, true);
}
}
{
DSTACK(__FUNCTION_NAME);
- NetworkPacket* pkt = new NetworkPacket(TOCLIENT_SHOW_FORMSPEC, 0 , peer_id);
+ NetworkPacket pkt(TOCLIENT_SHOW_FORMSPEC, 0 , peer_id);
- pkt->putLongString(FORMSPEC_VERSION_STRING + formspec);
- *pkt << formname;
+ pkt.putLongString(FORMSPEC_VERSION_STRING + formspec);
+ pkt << formname;
- Send(pkt);
+ Send(&pkt);
}
// Spawns a particle on peer with peer_id
{
DSTACK(__FUNCTION_NAME);
- NetworkPacket* pkt = new NetworkPacket(TOCLIENT_SPAWN_PARTICLE, 0, peer_id);
+ NetworkPacket pkt(TOCLIENT_SPAWN_PARTICLE, 0, peer_id);
- *pkt << pos << velocity << acceleration << expirationtime
+ pkt << pos << velocity << acceleration << expirationtime
<< size << collisiondetection;
- pkt->putLongString(texture);
- *pkt << vertical;
+ pkt.putLongString(texture);
+ pkt << vertical;
if (peer_id != PEER_ID_INEXISTENT) {
- Send(pkt);
+ Send(&pkt);
}
else {
- m_clients.sendToAll(0,pkt,true);
+ m_clients.sendToAll(0, &pkt, true);
}
}
{
DSTACK(__FUNCTION_NAME);
- NetworkPacket* pkt = new NetworkPacket(TOCLIENT_ADD_PARTICLESPAWNER, 0, peer_id);
+ NetworkPacket pkt(TOCLIENT_ADD_PARTICLESPAWNER, 0, peer_id);
- *pkt << amount << spawntime << minpos << maxpos << minvel << maxvel
+ pkt << amount << spawntime << minpos << maxpos << minvel << maxvel
<< minacc << maxacc << minexptime << maxexptime << minsize
<< maxsize << collisiondetection;
- pkt->putLongString(texture);
+ pkt.putLongString(texture);
- *pkt << id << vertical;
+ pkt << id << vertical;
if (peer_id != PEER_ID_INEXISTENT) {
- Send(pkt);
+ Send(&pkt);
}
else {
- m_clients.sendToAll(0, pkt, true);
+ m_clients.sendToAll(0, &pkt, true);
}
}
{
DSTACK(__FUNCTION_NAME);
- NetworkPacket* pkt = new NetworkPacket(TOCLIENT_DELETE_PARTICLESPAWNER_LEGACY, 2, peer_id);
+ NetworkPacket pkt(TOCLIENT_DELETE_PARTICLESPAWNER_LEGACY, 2, peer_id);
// Ugly error in this packet
- *pkt << (u16) id;
+ pkt << (u16) id;
if (peer_id != PEER_ID_INEXISTENT) {
- Send(pkt);
+ Send(&pkt);
}
else {
- m_clients.sendToAll(0, pkt, true);
+ m_clients.sendToAll(0, &pkt, true);
}
}
void Server::SendHUDAdd(u16 peer_id, u32 id, HudElement *form)
{
- NetworkPacket* pkt = new NetworkPacket(TOCLIENT_HUDADD, 0 , peer_id);
+ NetworkPacket pkt(TOCLIENT_HUDADD, 0 , peer_id);
- *pkt << id << (u8) form->type << form->pos << form->name << form->scale
+ pkt << id << (u8) form->type << form->pos << form->name << form->scale
<< form->text << form->number << form->item << form->dir
<< form->align << form->offset << form->world_pos << form->size;
- Send(pkt);
+ Send(&pkt);
}
void Server::SendHUDRemove(u16 peer_id, u32 id)
{
- NetworkPacket* pkt = new NetworkPacket(TOCLIENT_HUDRM, 4, peer_id);
- *pkt << id;
- Send(pkt);
+ NetworkPacket pkt(TOCLIENT_HUDRM, 4, peer_id);
+ pkt << id;
+ Send(&pkt);
}
void Server::SendHUDChange(u16 peer_id, u32 id, HudElementStat stat, void *value)
{
- NetworkPacket* pkt = new NetworkPacket(TOCLIENT_HUDCHANGE, 0, peer_id);
- *pkt << id << (u8) stat;
+ NetworkPacket pkt(TOCLIENT_HUDCHANGE, 0, peer_id);
+ pkt << id << (u8) stat;
switch (stat) {
case HUD_STAT_POS:
case HUD_STAT_SCALE:
case HUD_STAT_ALIGN:
case HUD_STAT_OFFSET:
- *pkt << *(v2f *) value;
+ pkt << *(v2f *) value;
break;
case HUD_STAT_NAME:
case HUD_STAT_TEXT:
- *pkt << *(std::string *) value;
+ pkt << *(std::string *) value;
break;
case HUD_STAT_WORLD_POS:
- *pkt << *(v3f *) value;
+ pkt << *(v3f *) value;
break;
case HUD_STAT_SIZE:
- *pkt << *(v2s32 *) value;
+ pkt << *(v2s32 *) value;
break;
case HUD_STAT_NUMBER:
case HUD_STAT_ITEM:
case HUD_STAT_DIR:
default:
- *pkt << *(u32 *) value;
+ pkt << *(u32 *) value;
break;
}
- Send(pkt);
+ Send(&pkt);
}
void Server::SendHUDSetFlags(u16 peer_id, u32 flags, u32 mask)
{
- NetworkPacket* pkt = new NetworkPacket(TOCLIENT_HUD_SET_FLAGS, 4 + 4, peer_id);
+ NetworkPacket pkt(TOCLIENT_HUD_SET_FLAGS, 4 + 4, peer_id);
flags &= ~(HUD_FLAG_HEALTHBAR_VISIBLE | HUD_FLAG_BREATHBAR_VISIBLE);
- *pkt << flags << mask;
+ pkt << flags << mask;
- Send(pkt);
+ Send(&pkt);
}
void Server::SendHUDSetParam(u16 peer_id, u16 param, const std::string &value)
{
- NetworkPacket* pkt = new NetworkPacket(TOCLIENT_HUD_SET_PARAM, 0, peer_id);
- *pkt << param << value;
- Send(pkt);
+ NetworkPacket pkt(TOCLIENT_HUD_SET_PARAM, 0, peer_id);
+ pkt << param << value;
+ Send(&pkt);
}
void Server::SendSetSky(u16 peer_id, const video::SColor &bgcolor,
const std::string &type, const std::vector<std::string> ¶ms)
{
- NetworkPacket* pkt = new NetworkPacket(TOCLIENT_SET_SKY, 0, peer_id);
- *pkt << bgcolor << type << (u16) params.size();
+ NetworkPacket pkt(TOCLIENT_SET_SKY, 0, peer_id);
+ pkt << bgcolor << type << (u16) params.size();
for(size_t i=0; i<params.size(); i++)
- *pkt << params[i];
+ pkt << params[i];
- Send(pkt);
+ Send(&pkt);
}
void Server::SendOverrideDayNightRatio(u16 peer_id, bool do_override,
float ratio)
{
- NetworkPacket* pkt = new NetworkPacket(TOCLIENT_OVERRIDE_DAY_NIGHT_RATIO,
+ NetworkPacket pkt(TOCLIENT_OVERRIDE_DAY_NIGHT_RATIO,
1 + 2, peer_id);
- *pkt << do_override << (u16) (ratio * 65535);
+ pkt << do_override << (u16) (ratio * 65535);
- Send (pkt);
+ Send(&pkt);
}
void Server::SendTimeOfDay(u16 peer_id, u16 time, f32 time_speed)
{
DSTACK(__FUNCTION_NAME);
- NetworkPacket* pkt = new NetworkPacket(TOCLIENT_TIME_OF_DAY, 0, peer_id);
- *pkt << time << time_speed;
+ NetworkPacket pkt(TOCLIENT_TIME_OF_DAY, 0, peer_id);
+ pkt << time << time_speed;
if (peer_id == PEER_ID_INEXISTENT) {
- m_clients.sendToAll(0, pkt, true);
+ m_clients.sendToAll(0, &pkt, true);
}
else {
- Send(pkt);
+ Send(&pkt);
}
}
Player *player = m_env->getPlayer(peer_id);
assert(player);
- NetworkPacket* pkt = new NetworkPacket(TOCLIENT_MOVE_PLAYER, 0, peer_id);
- *pkt << player->getPosition() << player->getPitch() << player->getYaw();
+ NetworkPacket pkt(TOCLIENT_MOVE_PLAYER, sizeof(v3f) + sizeof(f32) * 2, peer_id);
+ pkt << player->getPosition() << player->getPitch() << player->getYaw();
{
v3f pos = player->getPosition();
f32 pitch = player->getPitch();
f32 yaw = player->getYaw();
- verbosestream<<"Server: Sending TOCLIENT_MOVE_PLAYER"
- <<" pos=("<<pos.X<<","<<pos.Y<<","<<pos.Z<<")"
- <<" pitch="<<pitch
- <<" yaw="<<yaw
- <<std::endl;
+ verbosestream << "Server: Sending TOCLIENT_MOVE_PLAYER"
+ << " pos=(" << pos.X << "," << pos.Y << "," << pos.Z << ")"
+ << " pitch=" << pitch
+ << " yaw=" << yaw
+ << std::endl;
}
- Send(pkt);
+ Send(&pkt);
}
void Server::SendLocalPlayerAnimations(u16 peer_id, v2s32 animation_frames[4], f32 animation_speed)
{
- NetworkPacket* pkt = new NetworkPacket(TOCLIENT_LOCAL_PLAYER_ANIMATIONS, 0,
+ NetworkPacket pkt(TOCLIENT_LOCAL_PLAYER_ANIMATIONS, 0,
peer_id);
- *pkt << animation_frames[0] << animation_frames[1] << animation_frames[2]
+ pkt << animation_frames[0] << animation_frames[1] << animation_frames[2]
<< animation_frames[3] << animation_speed;
- Send(pkt);
+ Send(&pkt);
}
void Server::SendEyeOffset(u16 peer_id, v3f first, v3f third)
{
- NetworkPacket* pkt = new NetworkPacket(TOCLIENT_EYE_OFFSET, 0, peer_id);
- *pkt << first << third;
- Send(pkt);
+ NetworkPacket pkt(TOCLIENT_EYE_OFFSET, 0, peer_id);
+ pkt << first << third;
+ Send(&pkt);
}
void Server::SendPlayerPrivileges(u16 peer_id)
{
std::set<std::string> privs;
m_script->getAuth(player->getName(), NULL, &privs);
- NetworkPacket* pkt = new NetworkPacket(TOCLIENT_PRIVILEGES, 0, peer_id);
- *pkt << (u16) privs.size();
+ NetworkPacket pkt(TOCLIENT_PRIVILEGES, 0, peer_id);
+ pkt << (u16) privs.size();
for(std::set<std::string>::const_iterator i = privs.begin();
i != privs.end(); i++) {
- *pkt << (*i);
+ pkt << (*i);
}
- Send(pkt);
+ Send(&pkt);
}
void Server::SendPlayerInventoryFormspec(u16 peer_id)
if(player->peer_id == PEER_ID_INEXISTENT)
return;
- NetworkPacket* pkt = new NetworkPacket(TOCLIENT_INVENTORY_FORMSPEC, 0, peer_id);
- pkt->putLongString(FORMSPEC_VERSION_STRING + player->inventory_formspec);
- Send(pkt);
+ NetworkPacket pkt(TOCLIENT_INVENTORY_FORMSPEC, 0, peer_id);
+ pkt.putLongString(FORMSPEC_VERSION_STRING + player->inventory_formspec);
+ Send(&pkt);
}
s32 Server::playSound(const SimpleSoundSpec &spec,
ServerPlayingSound &psound = m_playing_sounds[id];
psound.params = params;
- NetworkPacket* pkt = new NetworkPacket(TOCLIENT_PLAY_SOUND, 0);
- *pkt << id << spec.name << (float) (spec.gain * params.gain)
+ NetworkPacket pkt(TOCLIENT_PLAY_SOUND, 0);
+ pkt << id << spec.name << (float) (spec.gain * params.gain)
<< (u8) params.type << pos << params.object << params.loop;
for(std::vector<u16>::iterator i = dst_clients.begin();
i != dst_clients.end(); i++) {
psound.clients.insert(*i);
- m_clients.send(*i, 0, pkt, true, false);
+ m_clients.send(*i, 0, &pkt, true);
}
- delete pkt;
return id;
}
void Server::stopSound(s32 handle)
return;
ServerPlayingSound &psound = i->second;
- NetworkPacket* pkt = new NetworkPacket(TOCLIENT_STOP_SOUND, 4);
- *pkt << handle;
+ NetworkPacket pkt(TOCLIENT_STOP_SOUND, 4);
+ pkt << handle;
for(std::set<u16>::iterator i = psound.clients.begin();
i != psound.clients.end(); i++) {
// Send as reliable
- m_clients.send(*i, 0, pkt, true, false);
+ m_clients.send(*i, 0, &pkt, true);
}
- delete pkt;
// Remove sound reference
m_playing_sounds.erase(i);
}
float maxd = far_d_nodes*BS;
v3f p_f = intToFloat(p, BS);
- NetworkPacket* pkt = new NetworkPacket(TOCLIENT_REMOVENODE, 6);
- *pkt << p;
+ NetworkPacket pkt(TOCLIENT_REMOVENODE, 6);
+ pkt << p;
std::vector<u16> clients = m_clients.getClientIDs();
for(std::vector<u16>::iterator i = clients.begin();
}
// Send as reliable
- m_clients.send(*i, 0, pkt, true, false);
+ m_clients.send(*i, 0, &pkt, true);
}
- // This loop needs the deletion of the packet here
- delete pkt;
}
void Server::sendAddNode(v3s16 p, MapNode n, u16 ignore_id,
}
}
- NetworkPacket* pkt = new NetworkPacket(TOCLIENT_ADDNODE, 6 + 2 + 1 + 1 + 1);
+ NetworkPacket pkt(TOCLIENT_ADDNODE, 6 + 2 + 1 + 1 + 1);
m_clients.Lock();
RemoteClient* client = m_clients.lockedGetClientNoEx(*i);
if (client != 0) {
- *pkt << p << n.param0 << n.param1 << n.param2
+ pkt << p << n.param0 << n.param1 << n.param2
<< (u8) (remove_metadata ? 0 : 1);
if (!remove_metadata) {
m_clients.Unlock();
// Send as reliable
- if (pkt->getSize() > 0)
- m_clients.send(*i, 0, pkt, true);
+ if (pkt.getSize() > 0)
+ m_clients.send(*i, 0, &pkt, true);
}
}
block->serializeNetworkSpecific(os, net_proto_version);
std::string s = os.str();
- NetworkPacket* pkt = new NetworkPacket(TOCLIENT_BLOCKDATA,
- 2 + 2 + 2 + 2 + s.size(), peer_id);
+ NetworkPacket pkt(TOCLIENT_BLOCKDATA, 2 + 2 + 2 + 2 + s.size(), peer_id);
- *pkt << p;
- pkt->putRawString(s.c_str(), s.size());
- Send(pkt);
+ pkt << p;
+ pkt.putRawString(s.c_str(), s.size());
+ Send(&pkt);
}
void Server::SendBlocks(float dtime)
// Make packet
std::ostringstream os(std::ios_base::binary);
- /*
- u32 number of files
- for each texture {
- u16 length of name
- string name
- u16 length of sha1_digest
- string sha1_digest
- }
- */
-
- NetworkPacket* pkt = new NetworkPacket(TOCLIENT_ANNOUNCE_MEDIA, 0, peer_id);
- *pkt << (u16) file_announcements.size();
+ NetworkPacket pkt(TOCLIENT_ANNOUNCE_MEDIA, 0, peer_id);
+ pkt << (u16) file_announcements.size();
for (std::vector<SendableMediaAnnouncement>::iterator
j = file_announcements.begin();
j != file_announcements.end(); ++j) {
- *pkt << j->name << j->sha1_digest;
+ pkt << j->name << j->sha1_digest;
}
- *pkt << g_settings->get("remote_media");
- Send(pkt);
+ pkt << g_settings->get("remote_media");
+ Send(&pkt);
}
struct SendableMedia
}
*/
- NetworkPacket* pkt = new NetworkPacket(TOCLIENT_MEDIA, 0, peer_id);
- *pkt << num_bunches << i << (u32) file_bunches[i].size();
+ NetworkPacket pkt(TOCLIENT_MEDIA, 4 + 0, peer_id);
+ pkt << num_bunches << i << (u32) file_bunches[i].size();
for(std::vector<SendableMedia>::iterator
j = file_bunches[i].begin();
j != file_bunches[i].end(); ++j) {
- *pkt << j->name;
- pkt->putLongString(j->data);
+ pkt << j->name;
+ pkt.putLongString(j->data);
}
verbosestream << "Server::sendRequestedMedia(): bunch "
<< i << "/" << num_bunches
<< " files=" << file_bunches[i].size()
- << " size=" << pkt->getSize() << std::endl;
- Send(pkt);
+ << " size=" << pkt.getSize() << std::endl;
+ Send(&pkt);
}
}
// Make data buffer
std::string s = os.str();
- NetworkPacket* pkt = new NetworkPacket(TOCLIENT_DETACHED_INVENTORY, 0, peer_id);
- pkt->putRawString(s.c_str(), s.size());
+ NetworkPacket pkt(TOCLIENT_DETACHED_INVENTORY, 0, peer_id);
+ pkt.putRawString(s.c_str(), s.size());
if (peer_id != PEER_ID_INEXISTENT) {
- Send(pkt);
+ Send(&pkt);
}
else {
- m_clients.sendToAll(0, pkt, true);
+ m_clients.sendToAll(0, &pkt, true);
}
}