Add session_t typedef + remove unused functions (#6470)

* Add session_t typedef + remove unused functions

u16 peer_id is used everywhere, to be more consistent and permit some evolutions on this type in the future (i'm working on a PoC), uniformize u16 peer_id to SessionId peer_id
This commit is contained in:
Loïc Blot 2017-09-27 19:47:36 +02:00 committed by GitHub
parent 50b2185ced
commit ad7daf7b52
24 changed files with 294 additions and 283 deletions

@ -1218,11 +1218,7 @@ void Client::sendPlayerPos()
//infostream << "Sending Player Position information" << std::endl; //infostream << "Sending Player Position information" << std::endl;
u16 our_peer_id; session_t our_peer_id = m_con->GetPeerID();
{
//MutexAutoLock lock(m_con_mutex); //bulk comment-out
our_peer_id = m_con->GetPeerID();
}
// Set peer id if not set already // Set peer id if not set already
if(myplayer->peer_id == PEER_ID_INEXISTENT) if(myplayer->peer_id == PEER_ID_INEXISTENT)
@ -1243,7 +1239,7 @@ void Client::sendPlayerItem(u16 item)
if(myplayer == NULL) if(myplayer == NULL)
return; return;
u16 our_peer_id = m_con->GetPeerID(); session_t our_peer_id = m_con->GetPeerID();
// Set peer id if not set already // Set peer id if not set already
if(myplayer->peer_id == PEER_ID_INEXISTENT) if(myplayer->peer_id == PEER_ID_INEXISTENT)

@ -669,8 +669,8 @@ void ClientInterface::UpdatePlayerList()
} }
} }
void ClientInterface::send(u16 peer_id, u8 channelnum, void ClientInterface::send(session_t peer_id, u8 channelnum,
NetworkPacket* pkt, bool reliable) NetworkPacket *pkt, bool reliable)
{ {
m_con->Send(peer_id, channelnum, pkt, reliable); m_con->Send(peer_id, channelnum, pkt, reliable);
} }
@ -714,7 +714,7 @@ void ClientInterface::sendToAllCompat(NetworkPacket *pkt, NetworkPacket *legacyp
} }
} }
RemoteClient* ClientInterface::getClientNoEx(u16 peer_id, ClientState state_min) RemoteClient* ClientInterface::getClientNoEx(session_t peer_id, ClientState state_min)
{ {
MutexAutoLock clientslock(m_clients_mutex); MutexAutoLock clientslock(m_clients_mutex);
RemoteClientMap::const_iterator n = m_clients.find(peer_id); RemoteClientMap::const_iterator n = m_clients.find(peer_id);
@ -729,7 +729,7 @@ RemoteClient* ClientInterface::getClientNoEx(u16 peer_id, ClientState state_min)
return NULL; return NULL;
} }
RemoteClient* ClientInterface::lockedGetClientNoEx(u16 peer_id, ClientState state_min) RemoteClient* ClientInterface::lockedGetClientNoEx(session_t peer_id, ClientState state_min)
{ {
RemoteClientMap::const_iterator n = m_clients.find(peer_id); RemoteClientMap::const_iterator n = m_clients.find(peer_id);
// The client may not exist; clients are immediately removed if their // The client may not exist; clients are immediately removed if their
@ -743,7 +743,7 @@ RemoteClient* ClientInterface::lockedGetClientNoEx(u16 peer_id, ClientState stat
return NULL; return NULL;
} }
ClientState ClientInterface::getClientState(u16 peer_id) ClientState ClientInterface::getClientState(session_t peer_id)
{ {
MutexAutoLock clientslock(m_clients_mutex); MutexAutoLock clientslock(m_clients_mutex);
RemoteClientMap::const_iterator n = m_clients.find(peer_id); RemoteClientMap::const_iterator n = m_clients.find(peer_id);
@ -755,7 +755,7 @@ ClientState ClientInterface::getClientState(u16 peer_id)
return n->second->getState(); return n->second->getState();
} }
void ClientInterface::setPlayerName(u16 peer_id,std::string name) void ClientInterface::setPlayerName(session_t peer_id, const std::string &name)
{ {
MutexAutoLock clientslock(m_clients_mutex); MutexAutoLock clientslock(m_clients_mutex);
RemoteClientMap::iterator n = m_clients.find(peer_id); RemoteClientMap::iterator n = m_clients.find(peer_id);
@ -765,7 +765,7 @@ void ClientInterface::setPlayerName(u16 peer_id,std::string name)
n->second->setName(name); n->second->setName(name);
} }
void ClientInterface::DeleteClient(u16 peer_id) void ClientInterface::DeleteClient(session_t peer_id)
{ {
MutexAutoLock conlock(m_clients_mutex); MutexAutoLock conlock(m_clients_mutex);
@ -795,7 +795,7 @@ void ClientInterface::DeleteClient(u16 peer_id)
m_clients.erase(peer_id); m_clients.erase(peer_id);
} }
void ClientInterface::CreateClient(u16 peer_id) void ClientInterface::CreateClient(session_t peer_id)
{ {
MutexAutoLock conlock(m_clients_mutex); MutexAutoLock conlock(m_clients_mutex);
@ -810,7 +810,7 @@ void ClientInterface::CreateClient(u16 peer_id)
m_clients[client->peer_id] = client; m_clients[client->peer_id] = client;
} }
void ClientInterface::event(u16 peer_id, ClientStateEvent event) void ClientInterface::event(session_t peer_id, ClientStateEvent event)
{ {
{ {
MutexAutoLock clientlock(m_clients_mutex); MutexAutoLock clientlock(m_clients_mutex);
@ -832,7 +832,7 @@ void ClientInterface::event(u16 peer_id, ClientStateEvent event)
} }
} }
u16 ClientInterface::getProtocolVersion(u16 peer_id) u16 ClientInterface::getProtocolVersion(session_t peer_id)
{ {
MutexAutoLock conlock(m_clients_mutex); MutexAutoLock conlock(m_clients_mutex);
@ -846,7 +846,8 @@ u16 ClientInterface::getProtocolVersion(u16 peer_id)
return n->second->net_proto_version; return n->second->net_proto_version;
} }
void ClientInterface::setClientVersion(u16 peer_id, u8 major, u8 minor, u8 patch, std::string full) void ClientInterface::setClientVersion(session_t peer_id, u8 major, u8 minor, u8 patch,
const std::string &full)
{ {
MutexAutoLock conlock(m_clients_mutex); MutexAutoLock conlock(m_clients_mutex);
@ -857,5 +858,5 @@ void ClientInterface::setClientVersion(u16 peer_id, u8 major, u8 minor, u8 patch
if (n == m_clients.end()) if (n == m_clients.end())
return; return;
n->second->setVersionInfo(major,minor,patch,full); n->second->setVersionInfo(major, minor, patch, full);
} }

@ -205,7 +205,7 @@ enum ClientStateEvent
*/ */
struct PrioritySortedBlockTransfer struct PrioritySortedBlockTransfer
{ {
PrioritySortedBlockTransfer(float a_priority, const v3s16 &a_pos, u16 a_peer_id) PrioritySortedBlockTransfer(float a_priority, const v3s16 &a_pos, session_t a_peer_id)
{ {
priority = a_priority; priority = a_priority;
pos = a_pos; pos = a_pos;
@ -217,7 +217,7 @@ struct PrioritySortedBlockTransfer
} }
float priority; float priority;
v3s16 pos; v3s16 pos;
u16 peer_id; session_t peer_id;
}; };
class RemoteClient class RemoteClient
@ -227,7 +227,7 @@ public:
// NOTE: If client is made allowed to exist while peer doesn't, // NOTE: If client is made allowed to exist while peer doesn't,
// this has to be set to 0 when there is no peer. // this has to be set to 0 when there is no peer.
// Also, the client must be moved to some other container. // Also, the client must be moved to some other container.
u16 peer_id = PEER_ID_INEXISTENT; session_t peer_id = PEER_ID_INEXISTENT;
// The serialization version to use with the client // The serialization version to use with the client
u8 serialization_version = SER_FMT_VER_INVALID; u8 serialization_version = SER_FMT_VER_INVALID;
// //
@ -431,38 +431,39 @@ public:
const std::vector<std::string> &getPlayerNames() const { return m_clients_names; } const std::vector<std::string> &getPlayerNames() const { return m_clients_names; }
/* send message to client */ /* send message to client */
void send(u16 peer_id, u8 channelnum, NetworkPacket* pkt, bool reliable); void send(session_t peer_id, u8 channelnum, NetworkPacket *pkt, bool reliable);
/* send to all clients */ /* send to all clients */
void sendToAll(NetworkPacket *pkt); void sendToAll(NetworkPacket *pkt);
void sendToAllCompat(NetworkPacket *pkt, NetworkPacket *legacypkt, u16 min_proto_ver); void sendToAllCompat(NetworkPacket *pkt, NetworkPacket *legacypkt, u16 min_proto_ver);
/* delete a client */ /* delete a client */
void DeleteClient(u16 peer_id); void DeleteClient(session_t peer_id);
/* create client */ /* create client */
void CreateClient(u16 peer_id); void CreateClient(session_t peer_id);
/* get a client by peer_id */ /* get a client by peer_id */
RemoteClient* getClientNoEx(u16 peer_id, ClientState state_min=CS_Active); RemoteClient *getClientNoEx(session_t peer_id, ClientState state_min = CS_Active);
/* get client by peer_id (make sure you have list lock before!*/ /* get client by peer_id (make sure you have list lock before!*/
RemoteClient* lockedGetClientNoEx(u16 peer_id, ClientState state_min=CS_Active); RemoteClient *lockedGetClientNoEx(session_t peer_id, ClientState state_min = CS_Active);
/* get state of client by id*/ /* get state of client by id*/
ClientState getClientState(u16 peer_id); ClientState getClientState(session_t peer_id);
/* set client playername */ /* set client playername */
void setPlayerName(u16 peer_id,std::string name); void setPlayerName(session_t peer_id, const std::string &name);
/* get protocol version of client */ /* get protocol version of client */
u16 getProtocolVersion(u16 peer_id); u16 getProtocolVersion(session_t peer_id);
/* set client version */ /* set client version */
void setClientVersion(u16 peer_id, u8 major, u8 minor, u8 patch, std::string full); void setClientVersion(session_t peer_id, u8 major, u8 minor, u8 patch,
const std::string &full);
/* event to update client state */ /* event to update client state */
void event(u16 peer_id, ClientStateEvent event); void event(session_t peer_id, ClientStateEvent event);
/* Set environment. Do not call this function if environment is already set */ /* Set environment. Do not call this function if environment is already set */
void setEnv(ServerEnvironment *env) void setEnv(ServerEnvironment *env)

@ -784,7 +784,7 @@ bool LuaEntitySAO::collideWithObjects() const
// No prototype, PlayerSAO does not need to be deserialized // No prototype, PlayerSAO does not need to be deserialized
PlayerSAO::PlayerSAO(ServerEnvironment *env_, RemotePlayer *player_, u16 peer_id_, PlayerSAO::PlayerSAO(ServerEnvironment *env_, RemotePlayer *player_, session_t peer_id_,
bool is_singleplayer): bool is_singleplayer):
UnitSAO(env_, v3f(0,0,0)), UnitSAO(env_, v3f(0,0,0)),
m_player(player_), m_player(player_),

@ -19,7 +19,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#pragma once #pragma once
#include <util/numeric.h> #include "network/networkprotocol.h"
#include "util/numeric.h"
#include "serverobject.h" #include "serverobject.h"
#include "itemgroup.h" #include "itemgroup.h"
#include "object_properties.h" #include "object_properties.h"
@ -196,7 +197,8 @@ class RemotePlayer;
class PlayerSAO : public UnitSAO class PlayerSAO : public UnitSAO
{ {
public: public:
PlayerSAO(ServerEnvironment *env_, RemotePlayer *player_, u16 peer_id_, bool is_singleplayer); PlayerSAO(ServerEnvironment *env_, RemotePlayer *player_, session_t peer_id_,
bool is_singleplayer);
~PlayerSAO(); ~PlayerSAO();
ActiveObjectType getType() const ActiveObjectType getType() const
{ return ACTIVEOBJECT_TYPE_PLAYER; } { return ACTIVEOBJECT_TYPE_PLAYER; }
@ -311,7 +313,7 @@ public:
void disconnected(); void disconnected();
RemotePlayer *getPlayer() { return m_player; } RemotePlayer *getPlayer() { return m_player; }
u16 getPeerID() const { return m_peer_id; } session_t getPeerID() const { return m_peer_id; }
// Cheat prevention // Cheat prevention
@ -372,7 +374,7 @@ private:
void unlinkPlayerSessionAndSave(); void unlinkPlayerSessionAndSave();
RemotePlayer *m_player = nullptr; RemotePlayer *m_player = nullptr;
u16 m_peer_id = 0; session_t m_peer_id = 0;
Inventory *m_inventory = nullptr; Inventory *m_inventory = nullptr;
s16 m_damage = 0; s16 m_damage = 0;

@ -247,7 +247,7 @@ bool EmergeManager::isRunning()
bool EmergeManager::enqueueBlockEmerge( bool EmergeManager::enqueueBlockEmerge(
u16 peer_id, session_t peer_id,
v3s16 blockpos, v3s16 blockpos,
bool allow_generate, bool allow_generate,
bool ignore_queue_limits) bool ignore_queue_limits)
@ -264,7 +264,7 @@ bool EmergeManager::enqueueBlockEmerge(
bool EmergeManager::enqueueBlockEmergeEx( bool EmergeManager::enqueueBlockEmergeEx(
v3s16 blockpos, v3s16 blockpos,
u16 peer_id, session_t peer_id,
u16 flags, u16 flags,
EmergeCompletionCallback callback, EmergeCompletionCallback callback,
void *callback_param) void *callback_param)

@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <map> #include <map>
#include <mutex> #include <mutex>
#include "network/networkprotocol.h"
#include "irr_v3d.h" #include "irr_v3d.h"
#include "util/container.h" #include "util/container.h"
#include "mapgen.h" // for MapgenParams #include "mapgen.h" // for MapgenParams
@ -123,14 +124,14 @@ public:
bool isRunning(); bool isRunning();
bool enqueueBlockEmerge( bool enqueueBlockEmerge(
u16 peer_id, session_t peer_id,
v3s16 blockpos, v3s16 blockpos,
bool allow_generate, bool allow_generate,
bool ignore_queue_limits=false); bool ignore_queue_limits=false);
bool enqueueBlockEmergeEx( bool enqueueBlockEmergeEx(
v3s16 blockpos, v3s16 blockpos,
u16 peer_id, session_t peer_id,
u16 flags, u16 flags,
EmergeCompletionCallback callback, EmergeCompletionCallback callback,
void *callback_param); void *callback_param);

@ -22,7 +22,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <cassert> #include <cassert>
#include "util/basic_macros.h" #include "util/basic_macros.h"
bool ModChannel::registerConsumer(u16 peer_id) bool ModChannel::registerConsumer(session_t peer_id)
{ {
// ignore if peer_id already joined // ignore if peer_id already joined
@ -33,7 +33,7 @@ bool ModChannel::registerConsumer(u16 peer_id)
return true; return true;
} }
bool ModChannel::removeConsumer(u16 peer_id) bool ModChannel::removeConsumer(session_t peer_id)
{ {
bool found = false; bool found = false;
auto peer_removal_fct = [peer_id, &found](u16 p) { auto peer_removal_fct = [peer_id, &found](u16 p) {
@ -112,7 +112,7 @@ bool ModChannelMgr::removeChannel(const std::string &channel)
return true; return true;
} }
bool ModChannelMgr::joinChannel(const std::string &channel, u16 peer_id) bool ModChannelMgr::joinChannel(const std::string &channel, session_t peer_id)
{ {
if (!channelRegistered(channel)) if (!channelRegistered(channel))
registerChannel(channel); registerChannel(channel);
@ -120,7 +120,7 @@ bool ModChannelMgr::joinChannel(const std::string &channel, u16 peer_id)
return m_registered_channels[channel]->registerConsumer(peer_id); return m_registered_channels[channel]->registerConsumer(peer_id);
} }
bool ModChannelMgr::leaveChannel(const std::string &channel, u16 peer_id) bool ModChannelMgr::leaveChannel(const std::string &channel, session_t peer_id)
{ {
if (!channelRegistered(channel)) if (!channelRegistered(channel))
return false; return false;
@ -135,7 +135,7 @@ bool ModChannelMgr::leaveChannel(const std::string &channel, u16 peer_id)
return consumerRemoved; return consumerRemoved;
} }
void ModChannelMgr::leaveAllChannels(u16 peer_id) void ModChannelMgr::leaveAllChannels(session_t peer_id)
{ {
for (auto &channel_it : m_registered_channels) for (auto &channel_it : m_registered_channels)
channel_it.second->removeConsumer(peer_id); channel_it.second->removeConsumer(peer_id);

@ -23,6 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <string> #include <string>
#include <vector> #include <vector>
#include <memory> #include <memory>
#include "network/networkprotocol.h"
#include "irrlichttypes.h" #include "irrlichttypes.h"
enum ModChannelState : u8 enum ModChannelState : u8
@ -40,8 +41,8 @@ public:
~ModChannel() = default; ~ModChannel() = default;
const std::string &getName() const { return m_name; } const std::string &getName() const { return m_name; }
bool registerConsumer(u16 peer_id); bool registerConsumer(session_t peer_id);
bool removeConsumer(u16 peer_id); bool removeConsumer(session_t peer_id);
const std::vector<u16> &getChannelPeers() const { return m_client_consumers; } const std::vector<u16> &getChannelPeers() const { return m_client_consumers; }
bool canWrite() const; bool canWrite() const;
void setState(ModChannelState state); void setState(ModChannelState state);
@ -70,8 +71,8 @@ public:
void registerChannel(const std::string &channel); void registerChannel(const std::string &channel);
bool setChannelState(const std::string &channel, ModChannelState state); bool setChannelState(const std::string &channel, ModChannelState state);
bool joinChannel(const std::string &channel, u16 peer_id); bool joinChannel(const std::string &channel, session_t peer_id);
bool leaveChannel(const std::string &channel, u16 peer_id); bool leaveChannel(const std::string &channel, session_t peer_id);
bool channelRegistered(const std::string &channel) const; bool channelRegistered(const std::string &channel) const;
ModChannel *getModChannel(const std::string &channel); ModChannel *getModChannel(const std::string &channel);
/** /**
@ -81,7 +82,7 @@ public:
* @return true if write is allowed * @return true if write is allowed
*/ */
bool canWriteOnChannel(const std::string &channel) const; bool canWriteOnChannel(const std::string &channel) const;
void leaveAllChannels(u16 peer_id); void leaveAllChannels(session_t peer_id);
const std::vector<u16> &getChannelPeers(const std::string &channel) const; const std::vector<u16> &getChannelPeers(const std::string &channel) const;
private: private:

@ -56,7 +56,7 @@ std::mutex log_message_mutex;
#define PING_TIMEOUT 5.0 #define PING_TIMEOUT 5.0
BufferedPacket makePacket(Address &address, SharedBuffer<u8> data, BufferedPacket makePacket(Address &address, SharedBuffer<u8> data,
u32 protocol_id, u16 sender_peer_id, u8 channel) u32 protocol_id, session_t sender_peer_id, u8 channel)
{ {
u32 packet_size = data.getSize() + BASE_HEADER_SIZE; u32 packet_size = data.getSize() + BASE_HEADER_SIZE;
BufferedPacket p(packet_size); BufferedPacket p(packet_size);
@ -501,7 +501,7 @@ void IncomingSplitBuffer::removeUnreliableTimedOuts(float dtime, float timeout)
ConnectionCommand ConnectionCommand
*/ */
void ConnectionCommand::send(u16 peer_id_, u8 channelnum_, NetworkPacket *pkt, void ConnectionCommand::send(session_t peer_id_, u8 channelnum_, NetworkPacket *pkt,
bool reliable_) bool reliable_)
{ {
type = CONNCMD_SEND; type = CONNCMD_SEND;
@ -1198,10 +1198,10 @@ void Connection::TriggerSend()
m_sendThread->Trigger(); m_sendThread->Trigger();
} }
PeerHelper Connection::getPeerNoEx(u16 peer_id) PeerHelper Connection::getPeerNoEx(session_t peer_id)
{ {
MutexAutoLock peerlock(m_peers_mutex); MutexAutoLock peerlock(m_peers_mutex);
std::map<u16, Peer*>::iterator node = m_peers.find(peer_id); std::map<session_t, Peer *>::iterator node = m_peers.find(peer_id);
if (node == m_peers.end()) { if (node == m_peers.end()) {
return PeerHelper(NULL); return PeerHelper(NULL);
@ -1237,17 +1237,7 @@ u16 Connection::lookupPeer(Address& sender)
return PEER_ID_INEXISTENT; return PEER_ID_INEXISTENT;
} }
std::list<Peer*> Connection::getPeers() bool Connection::deletePeer(session_t peer_id, bool timeout)
{
std::list<Peer*> list;
for (auto &p : m_peers) {
Peer *peer = p.second;
list.push_back(peer);
}
return list;
}
bool Connection::deletePeer(u16 peer_id, bool timeout)
{ {
Peer *peer = 0; Peer *peer = 0;
@ -1316,7 +1306,7 @@ bool Connection::Connected()
if (m_peers.size() != 1) if (m_peers.size() != 1)
return false; return false;
std::map<u16, Peer*>::iterator node = m_peers.find(PEER_ID_SERVER); std::map<session_t, Peer *>::iterator node = m_peers.find(PEER_ID_SERVER);
if (node == m_peers.end()) if (node == m_peers.end())
return false; return false;
@ -1371,8 +1361,8 @@ void Connection::Receive(NetworkPacket* pkt)
throw NoIncomingDataException("No incoming data"); throw NoIncomingDataException("No incoming data");
} }
void Connection::Send(u16 peer_id, u8 channelnum, void Connection::Send(session_t peer_id, u8 channelnum,
NetworkPacket* pkt, bool reliable) NetworkPacket *pkt, bool reliable)
{ {
assert(channelnum < CHANNEL_COUNT); // Pre-condition assert(channelnum < CHANNEL_COUNT); // Pre-condition
@ -1382,7 +1372,7 @@ void Connection::Send(u16 peer_id, u8 channelnum,
putCommand(c); putCommand(c);
} }
Address Connection::GetPeerAddress(u16 peer_id) Address Connection::GetPeerAddress(session_t peer_id)
{ {
PeerHelper peer = getPeerNoEx(peer_id); PeerHelper peer = getPeerNoEx(peer_id);
@ -1393,7 +1383,7 @@ Address Connection::GetPeerAddress(u16 peer_id)
return peer_address; return peer_address;
} }
float Connection::getPeerStat(u16 peer_id, rtt_stat_type type) float Connection::getPeerStat(session_t peer_id, rtt_stat_type type)
{ {
PeerHelper peer = getPeerNoEx(peer_id); PeerHelper peer = getPeerNoEx(peer_id);
if (!peer) return -1; if (!peer) return -1;
@ -1440,7 +1430,7 @@ u16 Connection::createPeer(Address& sender, MTProtocols protocol, int fd)
// Somebody wants to make a new connection // Somebody wants to make a new connection
// Get a unique peer id (2 or higher) // Get a unique peer id (2 or higher)
u16 peer_id_new = m_next_remote_peer_id; session_t peer_id_new = m_next_remote_peer_id;
u16 overflow = MAX_UDP_PEERS; u16 overflow = MAX_UDP_PEERS;
/* /*
@ -1508,14 +1498,14 @@ const std::string Connection::getDesc()
itos(m_udpSocket.GetHandle())+"/"+itos(m_peer_id)+")"; itos(m_udpSocket.GetHandle())+"/"+itos(m_peer_id)+")";
} }
void Connection::DisconnectPeer(u16 peer_id) void Connection::DisconnectPeer(session_t peer_id)
{ {
ConnectionCommand discon; ConnectionCommand discon;
discon.disconnect_peer(peer_id); discon.disconnect_peer(peer_id);
putCommand(discon); putCommand(discon);
} }
void Connection::sendAck(u16 peer_id, u8 channelnum, u16 seqnum) void Connection::sendAck(session_t peer_id, u8 channelnum, u16 seqnum)
{ {
assert(channelnum < CHANNEL_COUNT); // Pre-condition assert(channelnum < CHANNEL_COUNT); // Pre-condition

@ -27,6 +27,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "util/container.h" #include "util/container.h"
#include "util/thread.h" #include "util/thread.h"
#include "util/numeric.h" #include "util/numeric.h"
#include "networkprotocol.h"
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
#include <list> #include <list>
@ -103,7 +104,7 @@ struct BufferedPacket
// This adds the base headers to the data and makes a packet out of it // This adds the base headers to the data and makes a packet out of it
BufferedPacket makePacket(Address &address, SharedBuffer<u8> data, BufferedPacket makePacket(Address &address, SharedBuffer<u8> data,
u32 protocol_id, u16 sender_peer_id, u8 channel); u32 protocol_id, session_t sender_peer_id, u8 channel);
// Depending on size, make a TYPE_ORIGINAL or TYPE_SPLIT packet // Depending on size, make a TYPE_ORIGINAL or TYPE_SPLIT packet
// Increments split_seqnum if a split packet is made // Increments split_seqnum if a split packet is made
@ -139,7 +140,7 @@ A packet is sent through a channel to a peer with a basic header:
TODO: Should we have a receiver_peer_id also? TODO: Should we have a receiver_peer_id also?
Header (7 bytes): Header (7 bytes):
[0] u32 protocol_id [0] u32 protocol_id
[4] u16 sender_peer_id [4] session_t sender_peer_id
[6] u8 channel [6] u8 channel
sender_peer_id: sender_peer_id:
Unique to each peer. Unique to each peer.
@ -164,7 +165,7 @@ controltype and data description:
CONTROLTYPE_ACK CONTROLTYPE_ACK
[2] u16 seqnum [2] u16 seqnum
CONTROLTYPE_SET_PEER_ID CONTROLTYPE_SET_PEER_ID
[2] u16 peer_id_new [2] session_t peer_id_new
CONTROLTYPE_PING CONTROLTYPE_PING
- There is no actual reply, but this can be sent in a reliable - There is no actual reply, but this can be sent in a reliable
packet to get a reply packet to get a reply
@ -289,13 +290,13 @@ private:
struct OutgoingPacket struct OutgoingPacket
{ {
u16 peer_id; session_t peer_id;
u8 channelnum; u8 channelnum;
SharedBuffer<u8> data; SharedBuffer<u8> data;
bool reliable; bool reliable;
bool ack; bool ack;
OutgoingPacket(u16 peer_id_, u8 channelnum_, const SharedBuffer<u8> &data_, OutgoingPacket(session_t peer_id_, u8 channelnum_, const SharedBuffer<u8> &data_,
bool reliable_,bool ack_=false): bool reliable_,bool ack_=false):
peer_id(peer_id_), peer_id(peer_id_),
channelnum(channelnum_), channelnum(channelnum_),
@ -323,7 +324,7 @@ struct ConnectionCommand
{ {
enum ConnectionCommandType type = CONNCMD_NONE; enum ConnectionCommandType type = CONNCMD_NONE;
Address address; Address address;
u16 peer_id = PEER_ID_INEXISTENT; session_t peer_id = PEER_ID_INEXISTENT;
u8 channelnum = 0; u8 channelnum = 0;
Buffer<u8> data; Buffer<u8> data;
bool reliable = false; bool reliable = false;
@ -357,15 +358,15 @@ struct ConnectionCommand
{ {
type = CONNCMD_DISCONNECT; type = CONNCMD_DISCONNECT;
} }
void disconnect_peer(u16 peer_id_) void disconnect_peer(session_t peer_id_)
{ {
type = CONNCMD_DISCONNECT_PEER; type = CONNCMD_DISCONNECT_PEER;
peer_id = peer_id_; peer_id = peer_id_;
} }
void send(u16 peer_id_, u8 channelnum_, NetworkPacket* pkt, bool reliable_); void send(session_t peer_id_, u8 channelnum_, NetworkPacket *pkt, bool reliable_);
void ack(u16 peer_id_, u8 channelnum_, const SharedBuffer<u8> &data_) void ack(session_t peer_id_, u8 channelnum_, const SharedBuffer<u8> &data_)
{ {
type = CONCMD_ACK; type = CONCMD_ACK;
peer_id = peer_id_; peer_id = peer_id_;
@ -374,7 +375,7 @@ struct ConnectionCommand
reliable = false; reliable = false;
} }
void createPeer(u16 peer_id_, const SharedBuffer<u8> &data_) void createPeer(session_t peer_id_, const SharedBuffer<u8> &data_)
{ {
type = CONCMD_CREATE_PEER; type = CONCMD_CREATE_PEER;
peer_id = peer_id_; peer_id = peer_id_;
@ -384,7 +385,7 @@ struct ConnectionCommand
raw = true; raw = true;
} }
void disableLegacy(u16 peer_id_, const SharedBuffer<u8> &data_) void disableLegacy(session_t peer_id_, const SharedBuffer<u8> &data_)
{ {
type = CONCMD_DISABLE_LEGACY; type = CONCMD_DISABLE_LEGACY;
peer_id = peer_id_; peer_id = peer_id_;
@ -716,7 +717,7 @@ enum ConnectionEventType{
struct ConnectionEvent struct ConnectionEvent
{ {
enum ConnectionEventType type = CONNEVENT_NONE; enum ConnectionEventType type = CONNEVENT_NONE;
u16 peer_id = 0; session_t peer_id = 0;
Buffer<u8> data; Buffer<u8> data;
bool timeout = false; bool timeout = false;
Address address; Address address;
@ -740,19 +741,19 @@ struct ConnectionEvent
return "Invalid ConnectionEvent"; return "Invalid ConnectionEvent";
} }
void dataReceived(u16 peer_id_, const SharedBuffer<u8> &data_) void dataReceived(session_t peer_id_, const SharedBuffer<u8> &data_)
{ {
type = CONNEVENT_DATA_RECEIVED; type = CONNEVENT_DATA_RECEIVED;
peer_id = peer_id_; peer_id = peer_id_;
data = data_; data = data_;
} }
void peerAdded(u16 peer_id_, Address address_) void peerAdded(session_t peer_id_, Address address_)
{ {
type = CONNEVENT_PEER_ADDED; type = CONNEVENT_PEER_ADDED;
peer_id = peer_id_; peer_id = peer_id_;
address = address_; address = address_;
} }
void peerRemoved(u16 peer_id_, bool timeout_, Address address_) void peerRemoved(session_t peer_id_, bool timeout_, Address address_)
{ {
type = CONNEVENT_PEER_REMOVED; type = CONNEVENT_PEER_REMOVED;
peer_id = peer_id_; peer_id = peer_id_;
@ -787,30 +788,30 @@ public:
bool Connected(); bool Connected();
void Disconnect(); void Disconnect();
void Receive(NetworkPacket* pkt); void Receive(NetworkPacket* pkt);
void Send(u16 peer_id, u8 channelnum, NetworkPacket* pkt, bool reliable); void Send(session_t peer_id, u8 channelnum, NetworkPacket *pkt, bool reliable);
u16 GetPeerID() { return m_peer_id; } session_t GetPeerID() const { return m_peer_id; }
Address GetPeerAddress(u16 peer_id); Address GetPeerAddress(session_t peer_id);
float getPeerStat(u16 peer_id, rtt_stat_type type); float getPeerStat(session_t peer_id, rtt_stat_type type);
float getLocalStat(rate_stat_type type); float getLocalStat(rate_stat_type type);
const u32 GetProtocolID() const { return m_protocol_id; }; const u32 GetProtocolID() const { return m_protocol_id; };
const std::string getDesc(); const std::string getDesc();
void DisconnectPeer(u16 peer_id); void DisconnectPeer(session_t peer_id);
protected: protected:
PeerHelper getPeerNoEx(u16 peer_id); PeerHelper getPeerNoEx(session_t peer_id);
u16 lookupPeer(Address& sender); u16 lookupPeer(Address& sender);
u16 createPeer(Address& sender, MTProtocols protocol, int fd); u16 createPeer(Address& sender, MTProtocols protocol, int fd);
UDPPeer* createServerPeer(Address& sender); UDPPeer* createServerPeer(Address& sender);
bool deletePeer(u16 peer_id, bool timeout); bool deletePeer(session_t peer_id, bool timeout);
void SetPeerID(u16 id) { m_peer_id = id; } void SetPeerID(session_t id) { m_peer_id = id; }
void sendAck(u16 peer_id, u8 channelnum, u16 seqnum); void sendAck(session_t peer_id, u8 channelnum, u16 seqnum);
void PrintInfo(std::ostream &out); void PrintInfo(std::ostream &out);
std::list<u16> getPeerIDs() std::list<session_t> getPeerIDs()
{ {
MutexAutoLock peerlock(m_peers_mutex); MutexAutoLock peerlock(m_peers_mutex);
return m_peer_ids; return m_peer_ids;
@ -823,15 +824,13 @@ protected:
void TriggerSend(); void TriggerSend();
private: private:
std::list<Peer*> getPeers();
MutexedQueue<ConnectionEvent> m_event_queue; MutexedQueue<ConnectionEvent> m_event_queue;
u16 m_peer_id = 0; session_t m_peer_id = 0;
u32 m_protocol_id; u32 m_protocol_id;
std::map<u16, Peer*> m_peers; std::map<session_t, Peer *> m_peers;
std::list<u16> m_peer_ids; std::list<session_t> m_peer_ids;
std::mutex m_peers_mutex; std::mutex m_peers_mutex;
std::unique_ptr<ConnectionSendThread> m_sendThread; std::unique_ptr<ConnectionSendThread> m_sendThread;
@ -845,7 +844,7 @@ private:
bool m_shutting_down = false; bool m_shutting_down = false;
u16 m_next_remote_peer_id = 2; session_t m_next_remote_peer_id = 2;
}; };
} // namespace } // namespace

@ -53,7 +53,7 @@ std::mutex log_conthread_mutex;
#define WINDOW_SIZE 5 #define WINDOW_SIZE 5
static u16 readPeerId(u8 *packetdata) static session_t readPeerId(u8 *packetdata)
{ {
return readU16(&packetdata[4]); return readU16(&packetdata[4]);
} }
@ -138,12 +138,12 @@ void ConnectionSendThread::Trigger()
bool ConnectionSendThread::packetsQueued() bool ConnectionSendThread::packetsQueued()
{ {
std::list<u16> peerIds = m_connection->getPeerIDs(); std::list<session_t> peerIds = m_connection->getPeerIDs();
if (!m_outgoing_queue.empty() && !peerIds.empty()) if (!m_outgoing_queue.empty() && !peerIds.empty())
return true; return true;
for (u16 peerId : peerIds) { for (session_t peerId : peerIds) {
PeerHelper peer = m_connection->getPeerNoEx(peerId); PeerHelper peer = m_connection->getPeerNoEx(peerId);
if (!peer) if (!peer)
@ -165,10 +165,10 @@ bool ConnectionSendThread::packetsQueued()
void ConnectionSendThread::runTimeouts(float dtime) void ConnectionSendThread::runTimeouts(float dtime)
{ {
std::list<u16> timeouted_peers; std::list<session_t> timeouted_peers;
std::list<u16> peerIds = m_connection->getPeerIDs(); std::list<session_t> peerIds = m_connection->getPeerIDs();
for (u16 &peerId : peerIds) { for (session_t &peerId : peerIds) {
PeerHelper peer = m_connection->getPeerNoEx(peerId); PeerHelper peer = m_connection->getPeerNoEx(peerId);
if (!peer) if (!peer)
@ -231,7 +231,7 @@ void ConnectionSendThread::runTimeouts(float dtime)
for (std::list<BufferedPacket>::iterator k = timed_outs.begin(); for (std::list<BufferedPacket>::iterator k = timed_outs.begin();
k != timed_outs.end(); ++k) { k != timed_outs.end(); ++k) {
u16 peer_id = readPeerId(*(k->data)); session_t peer_id = readPeerId(*(k->data));
u8 channelnum = readChannel(*(k->data)); u8 channelnum = readChannel(*(k->data));
u16 seqnum = readU16(&(k->data[BASE_HEADER_SIZE + 1])); u16 seqnum = readU16(&(k->data[BASE_HEADER_SIZE + 1]));
@ -329,7 +329,7 @@ void ConnectionSendThread::sendAsPacketReliable(BufferedPacket &p, Channel *chan
rawSend(p); rawSend(p);
} }
bool ConnectionSendThread::rawSendAsPacket(u16 peer_id, u8 channelnum, bool ConnectionSendThread::rawSendAsPacket(session_t peer_id, u8 channelnum,
SharedBuffer<u8> data, bool reliable) SharedBuffer<u8> data, bool reliable)
{ {
PeerHelper peer = m_connection->getPeerNoEx(peer_id); PeerHelper peer = m_connection->getPeerNoEx(peer_id);
@ -557,14 +557,14 @@ void ConnectionSendThread::disconnect()
// Send to all // Send to all
std::list<u16> peerids = m_connection->getPeerIDs(); std::list<session_t> peerids = m_connection->getPeerIDs();
for (u16 peerid : peerids) { for (session_t peerid : peerids) {
sendAsPacket(peerid, 0, data, false); sendAsPacket(peerid, 0, data, false);
} }
} }
void ConnectionSendThread::disconnect_peer(u16 peer_id) void ConnectionSendThread::disconnect_peer(session_t peer_id)
{ {
LOG(dout_con << m_connection->getDesc() << " disconnecting peer" << std::endl); LOG(dout_con << m_connection->getDesc() << " disconnecting peer" << std::endl);
@ -586,7 +586,7 @@ void ConnectionSendThread::disconnect_peer(u16 peer_id)
dynamic_cast<UDPPeer *>(&peer)->m_pending_disconnect = true; dynamic_cast<UDPPeer *>(&peer)->m_pending_disconnect = true;
} }
void ConnectionSendThread::send(u16 peer_id, u8 channelnum, void ConnectionSendThread::send(session_t peer_id, u8 channelnum,
SharedBuffer<u8> data) SharedBuffer<u8> data)
{ {
assert(channelnum < CHANNEL_COUNT); // Pre-condition assert(channelnum < CHANNEL_COUNT); // Pre-condition
@ -629,18 +629,18 @@ void ConnectionSendThread::sendReliable(ConnectionCommand &c)
void ConnectionSendThread::sendToAll(u8 channelnum, SharedBuffer<u8> data) void ConnectionSendThread::sendToAll(u8 channelnum, SharedBuffer<u8> data)
{ {
std::list<u16> peerids = m_connection->getPeerIDs(); std::list<session_t> peerids = m_connection->getPeerIDs();
for (u16 peerid : peerids) { for (session_t peerid : peerids) {
send(peerid, channelnum, data); send(peerid, channelnum, data);
} }
} }
void ConnectionSendThread::sendToAllReliable(ConnectionCommand &c) void ConnectionSendThread::sendToAllReliable(ConnectionCommand &c)
{ {
std::list<u16> peerids = m_connection->getPeerIDs(); std::list<session_t> peerids = m_connection->getPeerIDs();
for (u16 peerid : peerids) { for (session_t peerid : peerids) {
PeerHelper peer = m_connection->getPeerNoEx(peerid); PeerHelper peer = m_connection->getPeerNoEx(peerid);
if (!peer) if (!peer)
@ -652,11 +652,11 @@ void ConnectionSendThread::sendToAllReliable(ConnectionCommand &c)
void ConnectionSendThread::sendPackets(float dtime) void ConnectionSendThread::sendPackets(float dtime)
{ {
std::list<u16> peerIds = m_connection->getPeerIDs(); std::list<session_t> peerIds = m_connection->getPeerIDs();
std::list<u16> pendingDisconnect; std::list<session_t> pendingDisconnect;
std::map<u16, bool> pending_unreliable; std::map<session_t, bool> pending_unreliable;
for (u16 peerId : peerIds) { for (session_t peerId : peerIds) {
PeerHelper peer = m_connection->getPeerNoEx(peerId); PeerHelper peer = m_connection->getPeerNoEx(peerId);
//peer may have been removed //peer may have been removed
if (!peer) { if (!peer) {
@ -780,14 +780,14 @@ void ConnectionSendThread::sendPackets(float dtime)
} }
} }
for (u16 peerId : pendingDisconnect) { for (session_t peerId : pendingDisconnect) {
if (!pending_unreliable[peerId]) { if (!pending_unreliable[peerId]) {
m_connection->deletePeer(peerId, false); m_connection->deletePeer(peerId, false);
} }
} }
} }
void ConnectionSendThread::sendAsPacket(u16 peer_id, u8 channelnum, void ConnectionSendThread::sendAsPacket(session_t peer_id, u8 channelnum,
SharedBuffer<u8> data, bool ack) SharedBuffer<u8> data, bool ack)
{ {
OutgoingPacket packet(peer_id, channelnum, data, false, ack); OutgoingPacket packet(peer_id, channelnum, data, false, ack);
@ -835,9 +835,9 @@ void *ConnectionReceiveThread::run()
if (debug_print_timer > 20.0) { if (debug_print_timer > 20.0) {
debug_print_timer -= 20.0; debug_print_timer -= 20.0;
std::list<u16> peerids = m_connection->getPeerIDs(); std::list<session_t> peerids = m_connection->getPeerIDs();
for (std::list<u16>::iterator i = peerids.begin(); for (std::list<session_t>::iterator i = peerids.begin();
i != peerids.end(); i != peerids.end();
i++) i++)
{ {
@ -910,7 +910,7 @@ void ConnectionReceiveThread::receive()
try { try {
if (packet_queued) { if (packet_queued) {
bool data_left = true; bool data_left = true;
u16 peer_id; session_t peer_id;
SharedBuffer<u8> resultdata; SharedBuffer<u8> resultdata;
while (data_left) { while (data_left) {
try { try {
@ -943,7 +943,7 @@ void ConnectionReceiveThread::receive()
continue; continue;
} }
u16 peer_id = readPeerId(*packetdata); session_t peer_id = readPeerId(*packetdata);
u8 channelnum = readChannel(*packetdata); u8 channelnum = readChannel(*packetdata);
if (channelnum > CHANNEL_COUNT - 1) { if (channelnum > CHANNEL_COUNT - 1) {
@ -1044,11 +1044,11 @@ void ConnectionReceiveThread::receive()
} }
} }
bool ConnectionReceiveThread::getFromBuffers(u16 &peer_id, SharedBuffer<u8> &dst) bool ConnectionReceiveThread::getFromBuffers(session_t &peer_id, SharedBuffer<u8> &dst)
{ {
std::list<u16> peerids = m_connection->getPeerIDs(); std::list<session_t> peerids = m_connection->getPeerIDs();
for (u16 peerid : peerids) { for (session_t peerid : peerids) {
PeerHelper peer = m_connection->getPeerNoEx(peerid); PeerHelper peer = m_connection->getPeerNoEx(peerid);
if (!peer) if (!peer)
continue; continue;
@ -1066,7 +1066,7 @@ bool ConnectionReceiveThread::getFromBuffers(u16 &peer_id, SharedBuffer<u8> &dst
} }
bool ConnectionReceiveThread::checkIncomingBuffers(Channel *channel, bool ConnectionReceiveThread::checkIncomingBuffers(Channel *channel,
u16 &peer_id, SharedBuffer<u8> &dst) session_t &peer_id, SharedBuffer<u8> &dst)
{ {
u16 firstseqnum = 0; u16 firstseqnum = 0;
if (channel->incoming_reliables.getFirstSeqnum(firstseqnum)) { if (channel->incoming_reliables.getFirstSeqnum(firstseqnum)) {
@ -1098,7 +1098,7 @@ bool ConnectionReceiveThread::checkIncomingBuffers(Channel *channel,
} }
SharedBuffer<u8> ConnectionReceiveThread::processPacket(Channel *channel, SharedBuffer<u8> ConnectionReceiveThread::processPacket(Channel *channel,
SharedBuffer<u8> packetdata, u16 peer_id, u8 channelnum, bool reliable) SharedBuffer<u8> packetdata, session_t peer_id, u8 channelnum, bool reliable)
{ {
PeerHelper peer = m_connection->getPeerNoEx(peer_id); PeerHelper peer = m_connection->getPeerNoEx(peer_id);
@ -1197,7 +1197,7 @@ SharedBuffer<u8> ConnectionReceiveThread::handlePacketType_Control(Channel *chan
if (packetdata.getSize() < 4) if (packetdata.getSize() < 4)
throw InvalidIncomingDataException throw InvalidIncomingDataException
("packetdata.getSize() < 4 (SET_PEER_ID header size)"); ("packetdata.getSize() < 4 (SET_PEER_ID header size)");
u16 peer_id_new = readU16(&packetdata[2]); session_t peer_id_new = readU16(&packetdata[2]);
LOG(dout_con << m_connection->getDesc() << "Got new peer id: " << peer_id_new LOG(dout_con << m_connection->getDesc() << "Got new peer id: " << peer_id_new
<< "... " << std::endl); << "... " << std::endl);

@ -53,22 +53,22 @@ private:
void runTimeouts(float dtime); void runTimeouts(float dtime);
void rawSend(const BufferedPacket &packet); void rawSend(const BufferedPacket &packet);
bool rawSendAsPacket( bool rawSendAsPacket(
u16 peer_id, u8 channelnum, SharedBuffer<u8> data, bool reliable); session_t peer_id, u8 channelnum, SharedBuffer<u8> data, bool reliable);
void processReliableCommand(ConnectionCommand &c); void processReliableCommand(ConnectionCommand &c);
void processNonReliableCommand(ConnectionCommand &c); void processNonReliableCommand(ConnectionCommand &c);
void serve(Address bind_address); void serve(Address bind_address);
void connect(Address address); void connect(Address address);
void disconnect(); void disconnect();
void disconnect_peer(u16 peer_id); void disconnect_peer(session_t peer_id);
void send(u16 peer_id, u8 channelnum, SharedBuffer<u8> data); void send(session_t peer_id, u8 channelnum, SharedBuffer<u8> data);
void sendReliable(ConnectionCommand &c); void sendReliable(ConnectionCommand &c);
void sendToAll(u8 channelnum, SharedBuffer<u8> data); void sendToAll(u8 channelnum, SharedBuffer<u8> data);
void sendToAllReliable(ConnectionCommand &c); void sendToAllReliable(ConnectionCommand &c);
void sendPackets(float dtime); void sendPackets(float dtime);
void sendAsPacket(u16 peer_id, u8 channelnum, SharedBuffer<u8> data, void sendAsPacket(session_t peer_id, u8 channelnum, SharedBuffer<u8> data,
bool ack = false); bool ack = false);
void sendAsPacketReliable(BufferedPacket &p, Channel *channel); void sendAsPacketReliable(BufferedPacket &p, Channel *channel);
@ -106,9 +106,9 @@ private:
// Returns next data from a buffer if possible // Returns next data from a buffer if possible
// If found, returns true; if not, false. // If found, returns true; if not, false.
// If found, sets peer_id and dst // If found, sets peer_id and dst
bool getFromBuffers(u16 &peer_id, SharedBuffer<u8> &dst); bool getFromBuffers(session_t &peer_id, SharedBuffer<u8> &dst);
bool checkIncomingBuffers(Channel *channel, u16 &peer_id, SharedBuffer<u8> &dst); bool checkIncomingBuffers(Channel *channel, session_t &peer_id, SharedBuffer<u8> &dst);
/* /*
Processes a packet with the basic header stripped out. Processes a packet with the basic header stripped out.
@ -119,7 +119,7 @@ private:
reliable: true if recursing into a reliable packet reliable: true if recursing into a reliable packet
*/ */
SharedBuffer<u8> processPacket(Channel *channel, SharedBuffer<u8> packetdata, SharedBuffer<u8> processPacket(Channel *channel, SharedBuffer<u8> packetdata,
u16 peer_id, u8 channelnum, bool reliable); session_t peer_id, u8 channelnum, bool reliable);
SharedBuffer<u8> handlePacketType_Control(Channel *channel, SharedBuffer<u8> handlePacketType_Control(Channel *channel,
SharedBuffer<u8> packetdata, Peer *peer, u8 channelnum, SharedBuffer<u8> packetdata, Peer *peer, u8 channelnum,

@ -21,8 +21,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <sstream> #include <sstream>
#include "networkexceptions.h" #include "networkexceptions.h"
#include "util/serialize.h" #include "util/serialize.h"
#include "networkprotocol.h"
NetworkPacket::NetworkPacket(u16 command, u32 datasize, u16 peer_id): NetworkPacket::NetworkPacket(u16 command, u32 datasize, session_t peer_id):
m_datasize(datasize), m_command(command), m_peer_id(peer_id) m_datasize(datasize), m_command(command), m_peer_id(peer_id)
{ {
m_data.resize(m_datasize); m_data.resize(m_datasize);
@ -49,7 +50,7 @@ void NetworkPacket::checkReadOffset(u32 from_offset, u32 field_size)
} }
} }
void NetworkPacket::putRawPacket(u8 *data, u32 datasize, u16 peer_id) void NetworkPacket::putRawPacket(u8 *data, u32 datasize, session_t peer_id)
{ {
// If a m_command is already set, we are rewriting on same packet // If a m_command is already set, we are rewriting on same packet
// This is not permitted // This is not permitted

@ -22,23 +22,24 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <ctime> #include <ctime>
#include "util/pointer.h" #include "util/pointer.h"
#include "util/numeric.h" #include "util/numeric.h"
#include "networkprotocol.h"
#include <SColor.h> #include <SColor.h>
class NetworkPacket class NetworkPacket
{ {
public: public:
NetworkPacket(u16 command, u32 datasize, u16 peer_id); NetworkPacket(u16 command, u32 datasize, session_t peer_id);
NetworkPacket(u16 command, u32 datasize); NetworkPacket(u16 command, u32 datasize);
NetworkPacket() = default; NetworkPacket() = default;
~NetworkPacket(); ~NetworkPacket();
void putRawPacket(u8 *data, u32 datasize, u16 peer_id); void putRawPacket(u8 *data, u32 datasize, session_t peer_id);
// Getters // Getters
u32 getSize() { return m_datasize; } u32 getSize() const { return m_datasize; }
u16 getPeerId() { return m_peer_id; } session_t getPeerId() const { return m_peer_id; }
u16 getCommand() { return m_command; } u16 getCommand() { return m_command; }
const u32 getRemainingBytes() const { return m_datasize - m_read_offset; } const u32 getRemainingBytes() const { return m_datasize - m_read_offset; }
const char *getRemainingString() { return getString(m_read_offset); } const char *getRemainingString() { return getString(m_read_offset); }
@ -135,5 +136,5 @@ private:
u32 m_datasize = 0; u32 m_datasize = 0;
u32 m_read_offset = 0; u32 m_read_offset = 0;
u16 m_command = 0; u16 m_command = 0;
u16 m_peer_id = 0; session_t m_peer_id = 0;
}; };

@ -206,6 +206,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#define TEXTURENAME_ALLOWED_CHARS "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_.-" #define TEXTURENAME_ALLOWED_CHARS "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_.-"
typedef u16 session_t;
enum ToClientCommand enum ToClientCommand
{ {
TOCLIENT_HELLO = 0x02, TOCLIENT_HELLO = 0x02,

@ -19,6 +19,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#pragma once #pragma once
#include "networkprotocol.h"
namespace con namespace con
{ {
@ -53,21 +55,22 @@ public:
virtual void deletingPeer(Peer *peer, bool timeout) = 0; virtual void deletingPeer(Peer *peer, bool timeout) = 0;
}; };
enum PeerChangeType enum PeerChangeType : u8
{ {
PEER_ADDED, PEER_ADDED,
PEER_REMOVED PEER_REMOVED
}; };
struct PeerChange struct PeerChange
{ {
PeerChange(PeerChangeType t, u16 _peer_id, bool _timeout) PeerChange(PeerChangeType t, session_t _peer_id, bool _timeout)
: type(t), peer_id(_peer_id), timeout(_timeout) : type(t), peer_id(_peer_id), timeout(_timeout)
{ {
} }
PeerChange() = delete; PeerChange() = delete;
PeerChangeType type; PeerChangeType type;
u16 peer_id; session_t peer_id;
bool timeout; bool timeout;
}; };
} }

@ -356,7 +356,7 @@ void Server::handleCommand_RequestMedia(NetworkPacket* pkt)
void Server::handleCommand_ClientReady(NetworkPacket* pkt) void Server::handleCommand_ClientReady(NetworkPacket* pkt)
{ {
u16 peer_id = pkt->getPeerId(); session_t peer_id = pkt->getPeerId();
PlayerSAO* playersao = StageTwoClientInit(peer_id); PlayerSAO* playersao = StageTwoClientInit(peer_id);

@ -22,6 +22,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "irrlichttypes_bloated.h" #include "irrlichttypes_bloated.h"
#include "inventory.h" #include "inventory.h"
#include "constants.h" #include "constants.h"
#include "network/networkprotocol.h"
#include "util/basic_macros.h" #include "util/basic_macros.h"
#include <list> #include <list>
#include <mutex> #include <mutex>
@ -146,7 +147,7 @@ public:
v2s32 local_animations[4]; v2s32 local_animations[4];
float local_animation_speed; float local_animation_speed;
u16 peer_id = PEER_ID_INEXISTENT; session_t peer_id = PEER_ID_INEXISTENT;
std::string inventory_formspec; std::string inventory_formspec;

@ -974,7 +974,7 @@ void Server::AsyncRunStep(bool initial_step)
void Server::Receive() void Server::Receive()
{ {
u16 peer_id; session_t peer_id;
try { try {
NetworkPacket pkt; NetworkPacket pkt;
m_con->Receive(&pkt); m_con->Receive(&pkt);
@ -995,7 +995,7 @@ void Server::Receive()
} }
} }
PlayerSAO* Server::StageTwoClientInit(u16 peer_id) PlayerSAO* Server::StageTwoClientInit(session_t peer_id)
{ {
std::string playername; std::string playername;
PlayerSAO *playersao = NULL; PlayerSAO *playersao = NULL;
@ -1297,14 +1297,14 @@ void Server::deletingPeer(con::Peer *peer, bool timeout)
m_peer_change_queue.push(con::PeerChange(con::PEER_REMOVED, peer->id, timeout)); m_peer_change_queue.push(con::PeerChange(con::PEER_REMOVED, peer->id, timeout));
} }
bool Server::getClientConInfo(u16 peer_id, con::rtt_stat_type type, float* retval) bool Server::getClientConInfo(session_t peer_id, con::rtt_stat_type type, float* retval)
{ {
*retval = m_con->getPeerStat(peer_id,type); *retval = m_con->getPeerStat(peer_id,type);
return *retval != -1; return *retval != -1;
} }
bool Server::getClientInfo( bool Server::getClientInfo(
u16 peer_id, session_t peer_id,
ClientState* state, ClientState* state,
u32* uptime, u32* uptime,
u8* ser_vers, u8* ser_vers,
@ -1381,7 +1381,7 @@ void Server::Send(NetworkPacket *pkt)
Send(pkt->getPeerId(), pkt); Send(pkt->getPeerId(), pkt);
} }
void Server::Send(u16 peer_id, NetworkPacket *pkt) void Server::Send(session_t peer_id, NetworkPacket *pkt)
{ {
m_clients.send(peer_id, m_clients.send(peer_id,
clientCommandFactoryTable[pkt->getCommand()].channel, clientCommandFactoryTable[pkt->getCommand()].channel,
@ -1389,7 +1389,7 @@ void Server::Send(u16 peer_id, NetworkPacket *pkt)
clientCommandFactoryTable[pkt->getCommand()].reliable); clientCommandFactoryTable[pkt->getCommand()].reliable);
} }
void Server::SendMovement(u16 peer_id) void Server::SendMovement(session_t peer_id)
{ {
std::ostringstream os(std::ios_base::binary); std::ostringstream os(std::ios_base::binary);
@ -1416,7 +1416,7 @@ void Server::SendPlayerHPOrDie(PlayerSAO *playersao)
if (!g_settings->getBool("enable_damage")) if (!g_settings->getBool("enable_damage"))
return; return;
u16 peer_id = playersao->getPeerID(); session_t peer_id = playersao->getPeerID();
bool is_alive = playersao->getHP() > 0; bool is_alive = playersao->getHP() > 0;
if (is_alive) if (is_alive)
@ -1425,21 +1425,21 @@ void Server::SendPlayerHPOrDie(PlayerSAO *playersao)
DiePlayer(peer_id); DiePlayer(peer_id);
} }
void Server::SendHP(u16 peer_id, u16 hp) void Server::SendHP(session_t peer_id, u16 hp)
{ {
NetworkPacket pkt(TOCLIENT_HP, 1, peer_id); NetworkPacket pkt(TOCLIENT_HP, 1, peer_id);
pkt << hp; pkt << hp;
Send(&pkt); Send(&pkt);
} }
void Server::SendBreath(u16 peer_id, u16 breath) void Server::SendBreath(session_t peer_id, u16 breath)
{ {
NetworkPacket pkt(TOCLIENT_BREATH, 2, peer_id); NetworkPacket pkt(TOCLIENT_BREATH, 2, peer_id);
pkt << (u16) breath; pkt << (u16) breath;
Send(&pkt); Send(&pkt);
} }
void Server::SendAccessDenied(u16 peer_id, AccessDeniedCode reason, void Server::SendAccessDenied(session_t peer_id, AccessDeniedCode reason,
const std::string &custom_reason, bool reconnect) const std::string &custom_reason, bool reconnect)
{ {
assert(reason < SERVER_ACCESSDENIED_MAX); assert(reason < SERVER_ACCESSDENIED_MAX);
@ -1454,14 +1454,14 @@ void Server::SendAccessDenied(u16 peer_id, AccessDeniedCode reason,
Send(&pkt); Send(&pkt);
} }
void Server::SendAccessDenied_Legacy(u16 peer_id,const std::wstring &reason) void Server::SendAccessDenied_Legacy(session_t peer_id,const std::wstring &reason)
{ {
NetworkPacket pkt(TOCLIENT_ACCESS_DENIED_LEGACY, 0, peer_id); NetworkPacket pkt(TOCLIENT_ACCESS_DENIED_LEGACY, 0, peer_id);
pkt << reason; pkt << reason;
Send(&pkt); Send(&pkt);
} }
void Server::SendDeathscreen(u16 peer_id,bool set_camera_point_target, void Server::SendDeathscreen(session_t peer_id, bool set_camera_point_target,
v3f camera_point_target) v3f camera_point_target)
{ {
NetworkPacket pkt(TOCLIENT_DEATHSCREEN, 1 + sizeof(v3f), peer_id); NetworkPacket pkt(TOCLIENT_DEATHSCREEN, 1 + sizeof(v3f), peer_id);
@ -1469,7 +1469,7 @@ void Server::SendDeathscreen(u16 peer_id,bool set_camera_point_target,
Send(&pkt); Send(&pkt);
} }
void Server::SendItemDef(u16 peer_id, void Server::SendItemDef(session_t peer_id,
IItemDefManager *itemdef, u16 protocol_version) IItemDefManager *itemdef, u16 protocol_version)
{ {
NetworkPacket pkt(TOCLIENT_ITEMDEF, 0, peer_id); NetworkPacket pkt(TOCLIENT_ITEMDEF, 0, peer_id);
@ -1492,7 +1492,7 @@ void Server::SendItemDef(u16 peer_id,
Send(&pkt); Send(&pkt);
} }
void Server::SendNodeDef(u16 peer_id, void Server::SendNodeDef(session_t peer_id,
INodeDefManager *nodedef, u16 protocol_version) INodeDefManager *nodedef, u16 protocol_version)
{ {
NetworkPacket pkt(TOCLIENT_NODEDEF, 0, peer_id); NetworkPacket pkt(TOCLIENT_NODEDEF, 0, peer_id);
@ -1539,7 +1539,7 @@ void Server::SendInventory(PlayerSAO* playerSAO)
Send(&pkt); Send(&pkt);
} }
void Server::SendChatMessage(u16 peer_id, const ChatMessage &message) void Server::SendChatMessage(session_t peer_id, const ChatMessage &message)
{ {
NetworkPacket pkt(TOCLIENT_CHAT_MESSAGE, 0, peer_id); NetworkPacket pkt(TOCLIENT_CHAT_MESSAGE, 0, peer_id);
u8 version = 1; u8 version = 1;
@ -1557,7 +1557,7 @@ void Server::SendChatMessage(u16 peer_id, const ChatMessage &message)
} }
} }
void Server::SendShowFormspecMessage(u16 peer_id, const std::string &formspec, void Server::SendShowFormspecMessage(session_t peer_id, const std::string &formspec,
const std::string &formname) const std::string &formname)
{ {
NetworkPacket pkt(TOCLIENT_SHOW_FORMSPEC, 0 , peer_id); NetworkPacket pkt(TOCLIENT_SHOW_FORMSPEC, 0 , peer_id);
@ -1573,7 +1573,7 @@ void Server::SendShowFormspecMessage(u16 peer_id, const std::string &formspec,
} }
// Spawns a particle on peer with peer_id // Spawns a particle on peer with peer_id
void Server::SendSpawnParticle(u16 peer_id, u16 protocol_version, void Server::SendSpawnParticle(session_t peer_id, u16 protocol_version,
v3f pos, v3f velocity, v3f acceleration, v3f pos, v3f velocity, v3f acceleration,
float expirationtime, float size, bool collisiondetection, float expirationtime, float size, bool collisiondetection,
bool collision_removal, bool collision_removal,
@ -1624,7 +1624,7 @@ void Server::SendSpawnParticle(u16 peer_id, u16 protocol_version,
} }
// Adds a ParticleSpawner on peer with peer_id // Adds a ParticleSpawner on peer with peer_id
void Server::SendAddParticleSpawner(u16 peer_id, u16 protocol_version, void Server::SendAddParticleSpawner(session_t peer_id, u16 protocol_version,
u16 amount, float spawntime, v3f minpos, v3f maxpos, u16 amount, float spawntime, v3f minpos, v3f maxpos,
v3f minvel, v3f maxvel, v3f minacc, v3f maxacc, float minexptime, float maxexptime, v3f minvel, v3f maxvel, v3f minacc, v3f maxacc, float minexptime, float maxexptime,
float minsize, float maxsize, bool collisiondetection, bool collision_removal, float minsize, float maxsize, bool collisiondetection, bool collision_removal,
@ -1667,7 +1667,7 @@ void Server::SendAddParticleSpawner(u16 peer_id, u16 protocol_version,
Send(&pkt); Send(&pkt);
} }
void Server::SendDeleteParticleSpawner(u16 peer_id, u32 id) void Server::SendDeleteParticleSpawner(session_t peer_id, u32 id)
{ {
NetworkPacket pkt(TOCLIENT_DELETE_PARTICLESPAWNER, 4, peer_id); NetworkPacket pkt(TOCLIENT_DELETE_PARTICLESPAWNER, 4, peer_id);
@ -1681,7 +1681,7 @@ void Server::SendDeleteParticleSpawner(u16 peer_id, u32 id)
} }
void Server::SendHUDAdd(u16 peer_id, u32 id, HudElement *form) void Server::SendHUDAdd(session_t peer_id, u32 id, HudElement *form)
{ {
NetworkPacket pkt(TOCLIENT_HUDADD, 0 , peer_id); NetworkPacket pkt(TOCLIENT_HUDADD, 0 , peer_id);
@ -1692,14 +1692,14 @@ void Server::SendHUDAdd(u16 peer_id, u32 id, HudElement *form)
Send(&pkt); Send(&pkt);
} }
void Server::SendHUDRemove(u16 peer_id, u32 id) void Server::SendHUDRemove(session_t peer_id, u32 id)
{ {
NetworkPacket pkt(TOCLIENT_HUDRM, 4, peer_id); NetworkPacket pkt(TOCLIENT_HUDRM, 4, peer_id);
pkt << id; pkt << id;
Send(&pkt); Send(&pkt);
} }
void Server::SendHUDChange(u16 peer_id, u32 id, HudElementStat stat, void *value) void Server::SendHUDChange(session_t peer_id, u32 id, HudElementStat stat, void *value)
{ {
NetworkPacket pkt(TOCLIENT_HUDCHANGE, 0, peer_id); NetworkPacket pkt(TOCLIENT_HUDCHANGE, 0, peer_id);
pkt << id << (u8) stat; pkt << id << (u8) stat;
@ -1732,7 +1732,7 @@ void Server::SendHUDChange(u16 peer_id, u32 id, HudElementStat stat, void *value
Send(&pkt); Send(&pkt);
} }
void Server::SendHUDSetFlags(u16 peer_id, u32 flags, u32 mask) void Server::SendHUDSetFlags(session_t peer_id, u32 flags, u32 mask)
{ {
NetworkPacket pkt(TOCLIENT_HUD_SET_FLAGS, 4 + 4, peer_id); NetworkPacket pkt(TOCLIENT_HUD_SET_FLAGS, 4 + 4, peer_id);
@ -1743,14 +1743,14 @@ void Server::SendHUDSetFlags(u16 peer_id, u32 flags, u32 mask)
Send(&pkt); Send(&pkt);
} }
void Server::SendHUDSetParam(u16 peer_id, u16 param, const std::string &value) void Server::SendHUDSetParam(session_t peer_id, u16 param, const std::string &value)
{ {
NetworkPacket pkt(TOCLIENT_HUD_SET_PARAM, 0, peer_id); NetworkPacket pkt(TOCLIENT_HUD_SET_PARAM, 0, peer_id);
pkt << param << value; pkt << param << value;
Send(&pkt); Send(&pkt);
} }
void Server::SendSetSky(u16 peer_id, const video::SColor &bgcolor, void Server::SendSetSky(session_t peer_id, const video::SColor &bgcolor,
const std::string &type, const std::vector<std::string> &params, const std::string &type, const std::vector<std::string> &params,
bool &clouds) bool &clouds)
{ {
@ -1765,7 +1765,7 @@ void Server::SendSetSky(u16 peer_id, const video::SColor &bgcolor,
Send(&pkt); Send(&pkt);
} }
void Server::SendCloudParams(u16 peer_id, float density, void Server::SendCloudParams(session_t peer_id, float density,
const video::SColor &color_bright, const video::SColor &color_bright,
const video::SColor &color_ambient, const video::SColor &color_ambient,
float height, float height,
@ -1779,7 +1779,7 @@ void Server::SendCloudParams(u16 peer_id, float density,
Send(&pkt); Send(&pkt);
} }
void Server::SendOverrideDayNightRatio(u16 peer_id, bool do_override, void Server::SendOverrideDayNightRatio(session_t peer_id, bool do_override,
float ratio) float ratio)
{ {
NetworkPacket pkt(TOCLIENT_OVERRIDE_DAY_NIGHT_RATIO, NetworkPacket pkt(TOCLIENT_OVERRIDE_DAY_NIGHT_RATIO,
@ -1790,7 +1790,7 @@ void Server::SendOverrideDayNightRatio(u16 peer_id, bool do_override,
Send(&pkt); Send(&pkt);
} }
void Server::SendTimeOfDay(u16 peer_id, u16 time, f32 time_speed) void Server::SendTimeOfDay(session_t peer_id, u16 time, f32 time_speed)
{ {
NetworkPacket pkt(TOCLIENT_TIME_OF_DAY, 0, peer_id); NetworkPacket pkt(TOCLIENT_TIME_OF_DAY, 0, peer_id);
pkt << time << time_speed; pkt << time << time_speed;
@ -1803,7 +1803,7 @@ void Server::SendTimeOfDay(u16 peer_id, u16 time, f32 time_speed)
} }
} }
void Server::SendPlayerHP(u16 peer_id) void Server::SendPlayerHP(session_t peer_id)
{ {
PlayerSAO *playersao = getPlayerSAO(peer_id); PlayerSAO *playersao = getPlayerSAO(peer_id);
// In some rare case if the player is disconnected // In some rare case if the player is disconnected
@ -1828,7 +1828,7 @@ void Server::SendPlayerBreath(PlayerSAO *sao)
SendBreath(sao->getPeerID(), sao->getBreath()); SendBreath(sao->getPeerID(), sao->getBreath());
} }
void Server::SendMovePlayer(u16 peer_id) void Server::SendMovePlayer(session_t peer_id)
{ {
RemotePlayer *player = m_env->getPlayer(peer_id); RemotePlayer *player = m_env->getPlayer(peer_id);
assert(player); assert(player);
@ -1850,7 +1850,8 @@ void Server::SendMovePlayer(u16 peer_id)
Send(&pkt); Send(&pkt);
} }
void Server::SendLocalPlayerAnimations(u16 peer_id, v2s32 animation_frames[4], f32 animation_speed) void Server::SendLocalPlayerAnimations(session_t peer_id, v2s32 animation_frames[4],
f32 animation_speed)
{ {
NetworkPacket pkt(TOCLIENT_LOCAL_PLAYER_ANIMATIONS, 0, NetworkPacket pkt(TOCLIENT_LOCAL_PLAYER_ANIMATIONS, 0,
peer_id); peer_id);
@ -1861,13 +1862,14 @@ void Server::SendLocalPlayerAnimations(u16 peer_id, v2s32 animation_frames[4], f
Send(&pkt); Send(&pkt);
} }
void Server::SendEyeOffset(u16 peer_id, v3f first, v3f third) void Server::SendEyeOffset(session_t peer_id, v3f first, v3f third)
{ {
NetworkPacket pkt(TOCLIENT_EYE_OFFSET, 0, peer_id); NetworkPacket pkt(TOCLIENT_EYE_OFFSET, 0, peer_id);
pkt << first << third; pkt << first << third;
Send(&pkt); Send(&pkt);
} }
void Server::SendPlayerPrivileges(u16 peer_id)
void Server::SendPlayerPrivileges(session_t peer_id)
{ {
RemotePlayer *player = m_env->getPlayer(peer_id); RemotePlayer *player = m_env->getPlayer(peer_id);
assert(player); assert(player);
@ -1887,7 +1889,7 @@ void Server::SendPlayerPrivileges(u16 peer_id)
Send(&pkt); Send(&pkt);
} }
void Server::SendPlayerInventoryFormspec(u16 peer_id) void Server::SendPlayerInventoryFormspec(session_t peer_id)
{ {
RemotePlayer *player = m_env->getPlayer(peer_id); RemotePlayer *player = m_env->getPlayer(peer_id);
assert(player); assert(player);
@ -1899,7 +1901,7 @@ void Server::SendPlayerInventoryFormspec(u16 peer_id)
Send(&pkt); Send(&pkt);
} }
u32 Server::SendActiveObjectRemoveAdd(u16 peer_id, const std::string &datas) u32 Server::SendActiveObjectRemoveAdd(session_t peer_id, const std::string &datas)
{ {
NetworkPacket pkt(TOCLIENT_ACTIVE_OBJECT_REMOVE_ADD, datas.size(), peer_id); NetworkPacket pkt(TOCLIENT_ACTIVE_OBJECT_REMOVE_ADD, datas.size(), peer_id);
pkt.putRawString(datas.c_str(), datas.size()); pkt.putRawString(datas.c_str(), datas.size());
@ -1907,7 +1909,8 @@ u32 Server::SendActiveObjectRemoveAdd(u16 peer_id, const std::string &datas)
return pkt.getSize(); return pkt.getSize();
} }
void Server::SendActiveObjectMessages(u16 peer_id, const std::string &datas, bool reliable) void Server::SendActiveObjectMessages(session_t peer_id, const std::string &datas,
bool reliable)
{ {
NetworkPacket pkt(TOCLIENT_ACTIVE_OBJECT_MESSAGES, NetworkPacket pkt(TOCLIENT_ACTIVE_OBJECT_MESSAGES,
datas.size(), peer_id); datas.size(), peer_id);
@ -1919,7 +1922,7 @@ void Server::SendActiveObjectMessages(u16 peer_id, const std::string &datas, boo
&pkt, reliable); &pkt, reliable);
} }
void Server::SendCSMFlavourLimits(u16 peer_id) void Server::SendCSMFlavourLimits(session_t peer_id)
{ {
NetworkPacket pkt(TOCLIENT_CSM_FLAVOUR_LIMITS, NetworkPacket pkt(TOCLIENT_CSM_FLAVOUR_LIMITS,
sizeof(m_csm_flavour_limits) + sizeof(m_csm_noderange_limit), peer_id); sizeof(m_csm_flavour_limits) + sizeof(m_csm_noderange_limit), peer_id);
@ -2151,7 +2154,8 @@ void Server::setBlockNotSent(v3s16 p)
m_clients.unlock(); m_clients.unlock();
} }
void Server::SendBlockNoLock(u16 peer_id, MapBlock *block, u8 ver, u16 net_proto_version) void Server::SendBlockNoLock(session_t peer_id, MapBlock *block, u8 ver,
u16 net_proto_version)
{ {
v3s16 p = block->getPos(); v3s16 p = block->getPos();
@ -2332,7 +2336,7 @@ void Server::fillMediaCache()
} }
} }
void Server::sendMediaAnnouncement(u16 peer_id, const std::string &lang_code) void Server::sendMediaAnnouncement(session_t peer_id, const std::string &lang_code)
{ {
verbosestream << "Server: Announcing files to id(" << peer_id << ")" verbosestream << "Server: Announcing files to id(" << peer_id << ")"
<< std::endl; << std::endl;
@ -2375,7 +2379,7 @@ struct SendableMedia
{} {}
}; };
void Server::sendRequestedMedia(u16 peer_id, void Server::sendRequestedMedia(session_t peer_id,
const std::vector<std::string> &tosend) const std::vector<std::string> &tosend)
{ {
verbosestream<<"Server::sendRequestedMedia(): " verbosestream<<"Server::sendRequestedMedia(): "
@ -2474,7 +2478,7 @@ void Server::sendRequestedMedia(u16 peer_id,
} }
} }
void Server::sendDetachedInventory(const std::string &name, u16 peer_id) void Server::sendDetachedInventory(const std::string &name, session_t peer_id)
{ {
if(m_detached_inventories.count(name) == 0) { if(m_detached_inventories.count(name) == 0) {
errorstream<<FUNCTION_NAME<<": \""<<name<<"\" not found"<<std::endl; errorstream<<FUNCTION_NAME<<": \""<<name<<"\" not found"<<std::endl;
@ -2505,7 +2509,7 @@ void Server::sendDetachedInventory(const std::string &name, u16 peer_id)
} }
} }
void Server::sendDetachedInventories(u16 peer_id) void Server::sendDetachedInventories(session_t peer_id)
{ {
for (const auto &detached_inventory : m_detached_inventories) { for (const auto &detached_inventory : m_detached_inventories) {
const std::string &name = detached_inventory.first; const std::string &name = detached_inventory.first;
@ -2518,7 +2522,7 @@ void Server::sendDetachedInventories(u16 peer_id)
Something random Something random
*/ */
void Server::DiePlayer(u16 peer_id) void Server::DiePlayer(session_t peer_id)
{ {
PlayerSAO *playersao = getPlayerSAO(peer_id); PlayerSAO *playersao = getPlayerSAO(peer_id);
// In some rare cases this can be NULL -- if the player is disconnected // In some rare cases this can be NULL -- if the player is disconnected
@ -2539,7 +2543,7 @@ void Server::DiePlayer(u16 peer_id)
SendDeathscreen(peer_id, false, v3f(0,0,0)); SendDeathscreen(peer_id, false, v3f(0,0,0));
} }
void Server::RespawnPlayer(u16 peer_id) void Server::RespawnPlayer(session_t peer_id)
{ {
PlayerSAO *playersao = getPlayerSAO(peer_id); PlayerSAO *playersao = getPlayerSAO(peer_id);
assert(playersao); assert(playersao);
@ -2561,14 +2565,14 @@ void Server::RespawnPlayer(u16 peer_id)
} }
void Server::DenySudoAccess(u16 peer_id) void Server::DenySudoAccess(session_t peer_id)
{ {
NetworkPacket pkt(TOCLIENT_DENY_SUDO_MODE, 0, peer_id); NetworkPacket pkt(TOCLIENT_DENY_SUDO_MODE, 0, peer_id);
Send(&pkt); Send(&pkt);
} }
void Server::DenyAccessVerCompliant(u16 peer_id, u16 proto_ver, AccessDeniedCode reason, void Server::DenyAccessVerCompliant(session_t peer_id, u16 proto_ver, AccessDeniedCode reason,
const std::string &str_reason, bool reconnect) const std::string &str_reason, bool reconnect)
{ {
SendAccessDenied(peer_id, reason, str_reason, reconnect); SendAccessDenied(peer_id, reason, str_reason, reconnect);
@ -2578,7 +2582,8 @@ void Server::DenyAccessVerCompliant(u16 peer_id, u16 proto_ver, AccessDeniedCode
} }
void Server::DenyAccess(u16 peer_id, AccessDeniedCode reason, const std::string &custom_reason) void Server::DenyAccess(session_t peer_id, AccessDeniedCode reason,
const std::string &custom_reason)
{ {
SendAccessDenied(peer_id, reason, custom_reason); SendAccessDenied(peer_id, reason, custom_reason);
m_clients.event(peer_id, CSE_SetDenied); m_clients.event(peer_id, CSE_SetDenied);
@ -2587,20 +2592,20 @@ void Server::DenyAccess(u16 peer_id, AccessDeniedCode reason, const std::string
// 13/03/15: remove this function when protocol version 25 will become // 13/03/15: remove this function when protocol version 25 will become
// the minimum version for MT users, maybe in 1 year // the minimum version for MT users, maybe in 1 year
void Server::DenyAccess_Legacy(u16 peer_id, const std::wstring &reason) void Server::DenyAccess_Legacy(session_t peer_id, const std::wstring &reason)
{ {
SendAccessDenied_Legacy(peer_id, reason); SendAccessDenied_Legacy(peer_id, reason);
m_clients.event(peer_id, CSE_SetDenied); m_clients.event(peer_id, CSE_SetDenied);
DisconnectPeer(peer_id); DisconnectPeer(peer_id);
} }
void Server::DisconnectPeer(u16 peer_id) void Server::DisconnectPeer(session_t peer_id)
{ {
m_modchannel_mgr->leaveAllChannels(peer_id); m_modchannel_mgr->leaveAllChannels(peer_id);
m_con->DisconnectPeer(peer_id); m_con->DisconnectPeer(peer_id);
} }
void Server::acceptAuth(u16 peer_id, bool forSudoMode) void Server::acceptAuth(session_t peer_id, bool forSudoMode)
{ {
if (!forSudoMode) { if (!forSudoMode) {
RemoteClient* client = getClient(peer_id, CS_Invalid); RemoteClient* client = getClient(peer_id, CS_Invalid);
@ -2629,7 +2634,7 @@ void Server::acceptAuth(u16 peer_id, bool forSudoMode)
} }
} }
void Server::DeleteClient(u16 peer_id, ClientDeletionReason reason) void Server::DeleteClient(session_t peer_id, ClientDeletionReason reason)
{ {
std::wstring message; std::wstring message;
{ {
@ -2814,7 +2819,7 @@ std::wstring Server::handleChat(const std::string &name, const std::wstring &wna
if they are using protocol version >= 29 if they are using protocol version >= 29
*/ */
u16 peer_id_to_avoid_sending = (player ? player->peer_id : PEER_ID_INEXISTENT); session_t peer_id_to_avoid_sending = (player ? player->peer_id : PEER_ID_INEXISTENT);
if (player && player->protocol_version >= 29) if (player && player->protocol_version >= 29)
peer_id_to_avoid_sending = PEER_ID_INEXISTENT; peer_id_to_avoid_sending = PEER_ID_INEXISTENT;
@ -2839,7 +2844,7 @@ void Server::handleAdminChat(const ChatEventChat *evt)
} }
} }
RemoteClient* Server::getClient(u16 peer_id, ClientState state_min) RemoteClient *Server::getClient(session_t peer_id, ClientState state_min)
{ {
RemoteClient *client = getClientNoEx(peer_id,state_min); RemoteClient *client = getClientNoEx(peer_id,state_min);
if(!client) if(!client)
@ -2847,12 +2852,12 @@ RemoteClient* Server::getClient(u16 peer_id, ClientState state_min)
return client; return client;
} }
RemoteClient* Server::getClientNoEx(u16 peer_id, ClientState state_min) RemoteClient *Server::getClientNoEx(session_t peer_id, ClientState state_min)
{ {
return m_clients.getClientNoEx(peer_id, state_min); return m_clients.getClientNoEx(peer_id, state_min);
} }
std::string Server::getPlayerName(u16 peer_id) std::string Server::getPlayerName(session_t peer_id)
{ {
RemotePlayer *player = m_env->getPlayer(peer_id); RemotePlayer *player = m_env->getPlayer(peer_id);
if (!player) if (!player)
@ -2860,7 +2865,7 @@ std::string Server::getPlayerName(u16 peer_id)
return player->getName(); return player->getName();
} }
PlayerSAO* Server::getPlayerSAO(u16 peer_id) PlayerSAO *Server::getPlayerSAO(session_t peer_id)
{ {
RemotePlayer *player = m_env->getPlayer(peer_id); RemotePlayer *player = m_env->getPlayer(peer_id);
if (!player) if (!player)
@ -3104,7 +3109,7 @@ const std::string& Server::hudGetHotbarSelectedImage(RemotePlayer *player) const
return player->getHotbarSelectedImage(); return player->getHotbarSelectedImage();
} }
Address Server::getPeerAddress(u16 peer_id) Address Server::getPeerAddress(session_t peer_id)
{ {
return m_con->GetPeerAddress(peer_id); return m_con->GetPeerAddress(peer_id);
} }
@ -3186,7 +3191,8 @@ void Server::spawnParticle(const std::string &playername, v3f pos,
if (!m_env) if (!m_env)
return; return;
u16 peer_id = PEER_ID_INEXISTENT, proto_ver = 0; session_t peer_id = PEER_ID_INEXISTENT;
u16 proto_ver = 0;
if (!playername.empty()) { if (!playername.empty()) {
RemotePlayer *player = m_env->getPlayer(playername.c_str()); RemotePlayer *player = m_env->getPlayer(playername.c_str());
if (!player) if (!player)
@ -3212,7 +3218,8 @@ u32 Server::addParticleSpawner(u16 amount, float spawntime,
if (!m_env) if (!m_env)
return -1; return -1;
u16 peer_id = PEER_ID_INEXISTENT, proto_ver = 0; session_t peer_id = PEER_ID_INEXISTENT;
u16 proto_ver = 0;
if (!playername.empty()) { if (!playername.empty()) {
RemotePlayer *player = m_env->getPlayer(playername.c_str()); RemotePlayer *player = m_env->getPlayer(playername.c_str());
if (!player) if (!player)
@ -3244,7 +3251,7 @@ void Server::deleteParticleSpawner(const std::string &playername, u32 id)
if (!m_env) if (!m_env)
throw ServerError("Can't delete particle spawners during initialisation!"); throw ServerError("Can't delete particle spawners during initialisation!");
u16 peer_id = PEER_ID_INEXISTENT; session_t peer_id = PEER_ID_INEXISTENT;
if (!playername.empty()) { if (!playername.empty()) {
RemotePlayer *player = m_env->getPlayer(playername.c_str()); RemotePlayer *player = m_env->getPlayer(playername.c_str());
if (!player) if (!player)
@ -3475,7 +3482,7 @@ void Server::requestShutdown(const std::string &msg, bool reconnect, float delay
} }
} }
PlayerSAO* Server::emergePlayer(const char *name, u16 peer_id, u16 proto_version) PlayerSAO* Server::emergePlayer(const char *name, session_t peer_id, u16 proto_version)
{ {
/* /*
Try to get an existing player Try to get an existing player
@ -3636,7 +3643,7 @@ void Server::broadcastModChannelMessage(const std::string &channel,
NetworkPacket resp_pkt(TOCLIENT_MODCHANNEL_MSG, NetworkPacket resp_pkt(TOCLIENT_MODCHANNEL_MSG,
2 + channel.size() + 2 + sender.size() + 2 + message.size()); 2 + channel.size() + 2 + sender.size() + 2 + message.size());
resp_pkt << channel << sender << message; resp_pkt << channel << sender << message;
for (u16 peer_id : peers) { for (session_t peer_id : peers) {
// Ignore sender // Ignore sender
if (peer_id == from_peer) if (peer_id == from_peer)
continue; continue;

@ -103,7 +103,7 @@ struct ServerPlayingSound
{ {
ServerSoundParams params; ServerSoundParams params;
SimpleSoundSpec spec; SimpleSoundSpec spec;
std::unordered_set<u16> clients; // peer ids std::unordered_set<session_t> clients; // peer ids
}; };
class Server : public con::PeerHandler, public MapEventReceiver, class Server : public con::PeerHandler, public MapEventReceiver,
@ -133,7 +133,7 @@ public:
// This is run by ServerThread and does the actual processing // This is run by ServerThread and does the actual processing
void AsyncRunStep(bool initial_step=false); void AsyncRunStep(bool initial_step=false);
void Receive(); void Receive();
PlayerSAO* StageTwoClientInit(u16 peer_id); PlayerSAO* StageTwoClientInit(session_t peer_id);
/* /*
* Command Handlers * Command Handlers
@ -170,7 +170,7 @@ public:
void ProcessData(NetworkPacket *pkt); void ProcessData(NetworkPacket *pkt);
void Send(NetworkPacket *pkt); void Send(NetworkPacket *pkt);
void Send(u16 peer_id, NetworkPacket *pkt); void Send(session_t peer_id, NetworkPacket *pkt);
// Helper for handleCommand_PlayerPos and handleCommand_Interact // Helper for handleCommand_PlayerPos and handleCommand_Interact
void process_PlayerPos(RemotePlayer *player, PlayerSAO *playersao, void process_PlayerPos(RemotePlayer *player, PlayerSAO *playersao,
@ -296,7 +296,7 @@ public:
void hudSetHotbarSelectedImage(RemotePlayer *player, std::string name); void hudSetHotbarSelectedImage(RemotePlayer *player, std::string name);
const std::string &hudGetHotbarSelectedImage(RemotePlayer *player) const; const std::string &hudGetHotbarSelectedImage(RemotePlayer *player) const;
Address getPeerAddress(u16 peer_id); Address getPeerAddress(session_t peer_id);
bool setLocalPlayerAnimations(RemotePlayer *player, v2s32 animation_frames[4], bool setLocalPlayerAnimations(RemotePlayer *player, v2s32 animation_frames[4],
f32 frame_speed); f32 frame_speed);
@ -318,15 +318,16 @@ public:
void peerAdded(con::Peer *peer); void peerAdded(con::Peer *peer);
void deletingPeer(con::Peer *peer, bool timeout); void deletingPeer(con::Peer *peer, bool timeout);
void DenySudoAccess(u16 peer_id); void DenySudoAccess(session_t peer_id);
void DenyAccessVerCompliant(u16 peer_id, u16 proto_ver, AccessDeniedCode reason, void DenyAccessVerCompliant(session_t peer_id, u16 proto_ver, AccessDeniedCode reason,
const std::string &str_reason = "", bool reconnect = false); const std::string &str_reason = "", bool reconnect = false);
void DenyAccess(u16 peer_id, AccessDeniedCode reason, const std::string &custom_reason=""); void DenyAccess(session_t peer_id, AccessDeniedCode reason,
void acceptAuth(u16 peer_id, bool forSudoMode); const std::string &custom_reason = "");
void DenyAccess_Legacy(u16 peer_id, const std::wstring &reason); void acceptAuth(session_t peer_id, bool forSudoMode);
void DisconnectPeer(u16 peer_id); void DenyAccess_Legacy(session_t peer_id, const std::wstring &reason);
bool getClientConInfo(u16 peer_id, con::rtt_stat_type type, float* retval); void DisconnectPeer(session_t peer_id);
bool getClientInfo(u16 peer_id,ClientState* state, u32* uptime, bool getClientConInfo(session_t peer_id, con::rtt_stat_type type, float *retval);
bool getClientInfo(session_t peer_id, ClientState *state, u32 *uptime,
u8* ser_vers, u16* prot_vers, u8* major, u8* minor, u8* patch, u8* ser_vers, u16* prot_vers, u8* major, u8* minor, u8* patch,
std::string* vers_string); std::string* vers_string);
@ -335,7 +336,7 @@ public:
void SendPlayerHPOrDie(PlayerSAO *player); void SendPlayerHPOrDie(PlayerSAO *player);
void SendPlayerBreath(PlayerSAO *sao); void SendPlayerBreath(PlayerSAO *sao);
void SendInventory(PlayerSAO* playerSAO); void SendInventory(PlayerSAO* playerSAO);
void SendMovePlayer(u16 peer_id); void SendMovePlayer(session_t peer_id);
virtual bool registerModStorage(ModMetadata *storage); virtual bool registerModStorage(ModMetadata *storage);
virtual void unregisterModStorage(const std::string &name); virtual void unregisterModStorage(const std::string &name);
@ -356,46 +357,49 @@ private:
friend class EmergeThread; friend class EmergeThread;
friend class RemoteClient; friend class RemoteClient;
void SendMovement(u16 peer_id); void SendMovement(session_t peer_id);
void SendHP(u16 peer_id, u16 hp); void SendHP(session_t peer_id, u16 hp);
void SendBreath(u16 peer_id, u16 breath); void SendBreath(session_t peer_id, u16 breath);
void SendAccessDenied(u16 peer_id, AccessDeniedCode reason, void SendAccessDenied(session_t peer_id, AccessDeniedCode reason,
const std::string &custom_reason, bool reconnect = false); const std::string &custom_reason, bool reconnect = false);
void SendAccessDenied_Legacy(u16 peer_id, const std::wstring &reason); void SendAccessDenied_Legacy(session_t peer_id, const std::wstring &reason);
void SendDeathscreen(u16 peer_id,bool set_camera_point_target, v3f camera_point_target); void SendDeathscreen(session_t peer_id, bool set_camera_point_target,
void SendItemDef(u16 peer_id,IItemDefManager *itemdef, u16 protocol_version); v3f camera_point_target);
void SendNodeDef(u16 peer_id,INodeDefManager *nodedef, u16 protocol_version); void SendItemDef(session_t peer_id, IItemDefManager *itemdef, u16 protocol_version);
void SendNodeDef(session_t peer_id, INodeDefManager *nodedef, u16 protocol_version);
/* mark blocks not sent for all clients */ /* mark blocks not sent for all clients */
void SetBlocksNotSent(std::map<v3s16, MapBlock *>& block); void SetBlocksNotSent(std::map<v3s16, MapBlock *>& block);
void SendChatMessage(u16 peer_id, const ChatMessage &message); void SendChatMessage(session_t peer_id, const ChatMessage &message);
void SendTimeOfDay(u16 peer_id, u16 time, f32 time_speed); void SendTimeOfDay(session_t peer_id, u16 time, f32 time_speed);
void SendPlayerHP(u16 peer_id); void SendPlayerHP(session_t peer_id);
void SendLocalPlayerAnimations(u16 peer_id, v2s32 animation_frames[4], f32 animation_speed); void SendLocalPlayerAnimations(session_t peer_id, v2s32 animation_frames[4],
void SendEyeOffset(u16 peer_id, v3f first, v3f third); f32 animation_speed);
void SendPlayerPrivileges(u16 peer_id); void SendEyeOffset(session_t peer_id, v3f first, v3f third);
void SendPlayerInventoryFormspec(u16 peer_id); void SendPlayerPrivileges(session_t peer_id);
void SendShowFormspecMessage(u16 peer_id, const std::string &formspec, const std::string &formname); void SendPlayerInventoryFormspec(session_t peer_id);
void SendHUDAdd(u16 peer_id, u32 id, HudElement *form); void SendShowFormspecMessage(session_t peer_id, const std::string &formspec,
void SendHUDRemove(u16 peer_id, u32 id); const std::string &formname);
void SendHUDChange(u16 peer_id, u32 id, HudElementStat stat, void *value); void SendHUDAdd(session_t peer_id, u32 id, HudElement *form);
void SendHUDSetFlags(u16 peer_id, u32 flags, u32 mask); void SendHUDRemove(session_t peer_id, u32 id);
void SendHUDSetParam(u16 peer_id, u16 param, const std::string &value); void SendHUDChange(session_t peer_id, u32 id, HudElementStat stat, void *value);
void SendSetSky(u16 peer_id, const video::SColor &bgcolor, void SendHUDSetFlags(session_t peer_id, u32 flags, u32 mask);
void SendHUDSetParam(session_t peer_id, u16 param, const std::string &value);
void SendSetSky(session_t peer_id, const video::SColor &bgcolor,
const std::string &type, const std::vector<std::string> &params, const std::string &type, const std::vector<std::string> &params,
bool &clouds); bool &clouds);
void SendCloudParams(u16 peer_id, float density, void SendCloudParams(session_t peer_id, float density,
const video::SColor &color_bright, const video::SColor &color_bright,
const video::SColor &color_ambient, const video::SColor &color_ambient,
float height, float height,
float thickness, float thickness,
const v2f &speed); const v2f &speed);
void SendOverrideDayNightRatio(u16 peer_id, bool do_override, float ratio); void SendOverrideDayNightRatio(session_t peer_id, bool do_override, float ratio);
void broadcastModChannelMessage(const std::string &channel, void broadcastModChannelMessage(const std::string &channel,
const std::string &message, u16 from_peer); const std::string &message, session_t from_peer);
/* /*
Send a node removal/addition event to all clients except ignore_id. Send a node removal/addition event to all clients except ignore_id.
@ -411,21 +415,21 @@ private:
void setBlockNotSent(v3s16 p); void setBlockNotSent(v3s16 p);
// Environment and Connection must be locked when called // Environment and Connection must be locked when called
void SendBlockNoLock(u16 peer_id, MapBlock *block, u8 ver, u16 net_proto_version); void SendBlockNoLock(session_t peer_id, MapBlock *block, u8 ver, u16 net_proto_version);
// Sends blocks to clients (locks env and con on its own) // Sends blocks to clients (locks env and con on its own)
void SendBlocks(float dtime); void SendBlocks(float dtime);
void fillMediaCache(); void fillMediaCache();
void sendMediaAnnouncement(u16 peer_id, const std::string &lang_code); void sendMediaAnnouncement(session_t peer_id, const std::string &lang_code);
void sendRequestedMedia(u16 peer_id, void sendRequestedMedia(session_t peer_id,
const std::vector<std::string> &tosend); const std::vector<std::string> &tosend);
void sendDetachedInventory(const std::string &name, u16 peer_id); void sendDetachedInventory(const std::string &name, session_t peer_id);
void sendDetachedInventories(u16 peer_id); void sendDetachedInventories(session_t peer_id);
// Adds a ParticleSpawner on peer with peer_id (PEER_ID_INEXISTENT == all) // Adds a ParticleSpawner on peer with peer_id (PEER_ID_INEXISTENT == all)
void SendAddParticleSpawner(u16 peer_id, u16 protocol_version, void SendAddParticleSpawner(session_t peer_id, u16 protocol_version,
u16 amount, float spawntime, u16 amount, float spawntime,
v3f minpos, v3f maxpos, v3f minpos, v3f maxpos,
v3f minvel, v3f maxvel, v3f minvel, v3f maxvel,
@ -437,27 +441,28 @@ private:
bool vertical, const std::string &texture, u32 id, bool vertical, const std::string &texture, u32 id,
const struct TileAnimationParams &animation, u8 glow); const struct TileAnimationParams &animation, u8 glow);
void SendDeleteParticleSpawner(u16 peer_id, u32 id); void SendDeleteParticleSpawner(session_t peer_id, u32 id);
// Spawns particle on peer with peer_id (PEER_ID_INEXISTENT == all) // Spawns particle on peer with peer_id (PEER_ID_INEXISTENT == all)
void SendSpawnParticle(u16 peer_id, u16 protocol_version, void SendSpawnParticle(session_t peer_id, u16 protocol_version,
v3f pos, v3f velocity, v3f acceleration, v3f pos, v3f velocity, v3f acceleration,
float expirationtime, float size, float expirationtime, float size,
bool collisiondetection, bool collision_removal, bool collisiondetection, bool collision_removal,
bool vertical, const std::string &texture, bool vertical, const std::string &texture,
const struct TileAnimationParams &animation, u8 glow); const struct TileAnimationParams &animation, u8 glow);
u32 SendActiveObjectRemoveAdd(u16 peer_id, const std::string &datas); u32 SendActiveObjectRemoveAdd(session_t peer_id, const std::string &datas);
void SendActiveObjectMessages(u16 peer_id, const std::string &datas, bool reliable = true); void SendActiveObjectMessages(session_t peer_id, const std::string &datas,
void SendCSMFlavourLimits(u16 peer_id); bool reliable = true);
void SendCSMFlavourLimits(session_t peer_id);
/* /*
Something random Something random
*/ */
void DiePlayer(u16 peer_id); void DiePlayer(session_t peer_id);
void RespawnPlayer(u16 peer_id); void RespawnPlayer(session_t peer_id);
void DeleteClient(u16 peer_id, ClientDeletionReason reason); void DeleteClient(session_t peer_id, ClientDeletionReason reason);
void UpdateCrafting(RemotePlayer *player); void UpdateCrafting(RemotePlayer *player);
void handleChatInterfaceEvent(ChatEvent *evt); void handleChatInterfaceEvent(ChatEvent *evt);
@ -470,12 +475,12 @@ private:
void handleAdminChat(const ChatEventChat *evt); void handleAdminChat(const ChatEventChat *evt);
// When called, connection mutex should be locked // When called, connection mutex should be locked
RemoteClient* getClient(u16 peer_id,ClientState state_min=CS_Active); RemoteClient* getClient(session_t peer_id, ClientState state_min = CS_Active);
RemoteClient* getClientNoEx(u16 peer_id,ClientState state_min=CS_Active); RemoteClient* getClientNoEx(session_t peer_id, ClientState state_min = CS_Active);
// When called, environment mutex should be locked // When called, environment mutex should be locked
std::string getPlayerName(u16 peer_id); std::string getPlayerName(session_t peer_id);
PlayerSAO* getPlayerSAO(u16 peer_id); PlayerSAO *getPlayerSAO(session_t peer_id);
/* /*
Get a player from memory or creates one. Get a player from memory or creates one.
@ -484,7 +489,7 @@ private:
Call with env and con locked. Call with env and con locked.
*/ */
PlayerSAO *emergePlayer(const char *name, u16 peer_id, u16 proto_version); PlayerSAO *emergePlayer(const char *name, session_t peer_id, u16 proto_version);
void handlePeerChanges(); void handlePeerChanges();
@ -628,7 +633,7 @@ private:
this peed id as the disabled recipient this peed id as the disabled recipient
This is behind m_env_mutex This is behind m_env_mutex
*/ */
u16 m_ignore_map_edit_events_peer_id = 0; session_t m_ignore_map_edit_events_peer_id = 0;
// media files known to server // media files known to server
std::unordered_map<std::string, MediaInfo> m_media; std::unordered_map<std::string, MediaInfo> m_media;

@ -405,7 +405,7 @@ ServerMap & ServerEnvironment::getServerMap()
return *m_map; return *m_map;
} }
RemotePlayer *ServerEnvironment::getPlayer(const u16 peer_id) RemotePlayer *ServerEnvironment::getPlayer(const session_t peer_id)
{ {
for (RemotePlayer *player : m_players) { for (RemotePlayer *player : m_players) {
if (player->peer_id == peer_id) if (player->peer_id == peer_id)
@ -523,7 +523,7 @@ void ServerEnvironment::savePlayer(RemotePlayer *player)
} }
PlayerSAO *ServerEnvironment::loadPlayer(RemotePlayer *player, bool *new_player, PlayerSAO *ServerEnvironment::loadPlayer(RemotePlayer *player, bool *new_player,
u16 peer_id, bool is_singleplayer) session_t peer_id, bool is_singleplayer)
{ {
PlayerSAO *playersao = new PlayerSAO(this, player, peer_id, is_singleplayer); PlayerSAO *playersao = new PlayerSAO(this, player, peer_id, is_singleplayer);
// Create player if it doesn't exist // Create player if it doesn't exist

@ -219,7 +219,7 @@ public:
// Save players // Save players
void saveLoadedPlayers(); void saveLoadedPlayers();
void savePlayer(RemotePlayer *player); void savePlayer(RemotePlayer *player);
PlayerSAO *loadPlayer(RemotePlayer *player, bool *new_player, u16 peer_id, PlayerSAO *loadPlayer(RemotePlayer *player, bool *new_player, session_t peer_id,
bool is_singleplayer); bool is_singleplayer);
void addPlayer(RemotePlayer *player); void addPlayer(RemotePlayer *player);
void removePlayer(RemotePlayer *player); void removePlayer(RemotePlayer *player);
@ -341,7 +341,7 @@ public:
void setStaticForActiveObjectsInBlock(v3s16 blockpos, void setStaticForActiveObjectsInBlock(v3s16 blockpos,
bool static_exists, v3s16 static_block=v3s16(0,0,0)); bool static_exists, v3s16 static_block=v3s16(0,0,0));
RemotePlayer *getPlayer(const u16 peer_id); RemotePlayer *getPlayer(const session_t peer_id);
RemotePlayer *getPlayer(const char* name); RemotePlayer *getPlayer(const char* name);
u32 getPlayerCount() const { return m_players.size(); } u32 getPlayerCount() const { return m_players.size(); }

@ -81,7 +81,7 @@ void TestConnection::testHelpers()
{ {
// Some constants for testing // Some constants for testing
u32 proto_id = 0x12345678; u32 proto_id = 0x12345678;
u16 peer_id = 123; session_t peer_id = 123;
u8 channel = 2; u8 channel = 2;
SharedBuffer<u8> data1(1); SharedBuffer<u8> data1(1);
data1[0] = 100; data1[0] = 100;
@ -94,7 +94,7 @@ void TestConnection::testHelpers()
We should now have a packet with this data: We should now have a packet with this data:
Header: Header:
[0] u32 protocol_id [0] u32 protocol_id
[4] u16 sender_peer_id [4] session_t sender_peer_id
[6] u8 channel [6] u8 channel
Data: Data:
[7] u8 data1[0] [7] u8 data1[0]
@ -264,7 +264,7 @@ void TestConnection::testConnectSendReceive()
UASSERT(memcmp(*sentdata, *recvdata, recvdata.getSize()) == 0); UASSERT(memcmp(*sentdata, *recvdata, recvdata.getSize()) == 0);
} }
u16 peer_id_client = 2; session_t peer_id_client = 2;
/* /*
Send a large packet Send a large packet
*/ */
@ -296,7 +296,7 @@ void TestConnection::testConnectSendReceive()
SharedBuffer<u8> recvdata; SharedBuffer<u8> recvdata;
infostream << "** running client.Receive()" << std::endl; infostream << "** running client.Receive()" << std::endl;
u16 peer_id = 132; session_t peer_id = 132;
u16 size = 0; u16 size = 0;
bool received = false; bool received = false;
u64 timems0 = porting::getTimeMs(); u64 timems0 = porting::getTimeMs();