Skip to content
Permalink
Browse files

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
  • Loading branch information...
nerzhul committed Sep 27, 2017
1 parent 50b2185 commit ad7daf7b52348e1b71aa803be10de5b2134cba11
@@ -1218,11 +1218,7 @@ void Client::sendPlayerPos()

//infostream << "Sending Player Position information" << std::endl;

u16 our_peer_id;
{
//MutexAutoLock lock(m_con_mutex); //bulk comment-out
our_peer_id = m_con->GetPeerID();
}
session_t our_peer_id = m_con->GetPeerID();

// Set peer id if not set already
if(myplayer->peer_id == PEER_ID_INEXISTENT)
@@ -1243,7 +1239,7 @@ void Client::sendPlayerItem(u16 item)
if(myplayer == NULL)
return;

u16 our_peer_id = m_con->GetPeerID();
session_t our_peer_id = m_con->GetPeerID();

// Set peer id if not set already
if(myplayer->peer_id == PEER_ID_INEXISTENT)
@@ -669,8 +669,8 @@ void ClientInterface::UpdatePlayerList()
}
}

void ClientInterface::send(u16 peer_id, u8 channelnum,
NetworkPacket* pkt, bool reliable)
void ClientInterface::send(session_t peer_id, u8 channelnum,
NetworkPacket *pkt, bool 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);
RemoteClientMap::const_iterator n = m_clients.find(peer_id);
@@ -729,7 +729,7 @@ RemoteClient* ClientInterface::getClientNoEx(u16 peer_id, ClientState state_min)
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);
// 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;
}

ClientState ClientInterface::getClientState(u16 peer_id)
ClientState ClientInterface::getClientState(session_t peer_id)
{
MutexAutoLock clientslock(m_clients_mutex);
RemoteClientMap::const_iterator n = m_clients.find(peer_id);
@@ -755,7 +755,7 @@ ClientState ClientInterface::getClientState(u16 peer_id)
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);
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);
}

void ClientInterface::DeleteClient(u16 peer_id)
void ClientInterface::DeleteClient(session_t peer_id)
{
MutexAutoLock conlock(m_clients_mutex);

@@ -795,7 +795,7 @@ void ClientInterface::DeleteClient(u16 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);

@@ -810,7 +810,7 @@ void ClientInterface::CreateClient(u16 peer_id)
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);
@@ -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);

@@ -846,7 +846,8 @@ u16 ClientInterface::getProtocolVersion(u16 peer_id)
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);

@@ -857,5 +858,5 @@ void ClientInterface::setClientVersion(u16 peer_id, u8 major, u8 minor, u8 patch
if (n == m_clients.end())
return;

n->second->setVersionInfo(major,minor,patch,full);
n->second->setVersionInfo(major, minor, patch, full);
}
@@ -205,7 +205,7 @@ enum ClientStateEvent
*/
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;
pos = a_pos;
@@ -217,7 +217,7 @@ struct PrioritySortedBlockTransfer
}
float priority;
v3s16 pos;
u16 peer_id;
session_t peer_id;
};

class RemoteClient
@@ -227,7 +227,7 @@ class RemoteClient
// NOTE: If client is made allowed to exist while peer doesn't,
// this has to be set to 0 when there is no peer.
// 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
u8 serialization_version = SER_FMT_VER_INVALID;
//
@@ -431,38 +431,39 @@ class ClientInterface {
const std::vector<std::string> &getPlayerNames() const { return m_clients_names; }

/* 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 */
void sendToAll(NetworkPacket *pkt);
void sendToAllCompat(NetworkPacket *pkt, NetworkPacket *legacypkt, u16 min_proto_ver);

/* delete a client */
void DeleteClient(u16 peer_id);
void DeleteClient(session_t peer_id);

/* create client */
void CreateClient(u16 peer_id);
void CreateClient(session_t 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!*/
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*/
ClientState getClientState(u16 peer_id);
ClientState getClientState(session_t peer_id);

/* 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 */
u16 getProtocolVersion(u16 peer_id);
u16 getProtocolVersion(session_t peer_id);

/* 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 */
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 */
void setEnv(ServerEnvironment *env)
@@ -784,7 +784,7 @@ bool LuaEntitySAO::collideWithObjects() const

// 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):
UnitSAO(env_, v3f(0,0,0)),
m_player(player_),
@@ -19,7 +19,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,

#pragma once

#include <util/numeric.h>
#include "network/networkprotocol.h"
#include "util/numeric.h"
#include "serverobject.h"
#include "itemgroup.h"
#include "object_properties.h"
@@ -196,7 +197,8 @@ class RemotePlayer;
class PlayerSAO : public UnitSAO
{
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();
ActiveObjectType getType() const
{ return ACTIVEOBJECT_TYPE_PLAYER; }
@@ -311,7 +313,7 @@ class PlayerSAO : public UnitSAO
void disconnected();

RemotePlayer *getPlayer() { return m_player; }
u16 getPeerID() const { return m_peer_id; }
session_t getPeerID() const { return m_peer_id; }

// Cheat prevention

@@ -372,7 +374,7 @@ class PlayerSAO : public UnitSAO
void unlinkPlayerSessionAndSave();

RemotePlayer *m_player = nullptr;
u16 m_peer_id = 0;
session_t m_peer_id = 0;
Inventory *m_inventory = nullptr;
s16 m_damage = 0;

@@ -247,7 +247,7 @@ bool EmergeManager::isRunning()


bool EmergeManager::enqueueBlockEmerge(
u16 peer_id,
session_t peer_id,
v3s16 blockpos,
bool allow_generate,
bool ignore_queue_limits)
@@ -264,7 +264,7 @@ bool EmergeManager::enqueueBlockEmerge(

bool EmergeManager::enqueueBlockEmergeEx(
v3s16 blockpos,
u16 peer_id,
session_t peer_id,
u16 flags,
EmergeCompletionCallback callback,
void *callback_param)
@@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,

#include <map>
#include <mutex>
#include "network/networkprotocol.h"
#include "irr_v3d.h"
#include "util/container.h"
#include "mapgen.h" // for MapgenParams
@@ -123,14 +124,14 @@ class EmergeManager {
bool isRunning();

bool enqueueBlockEmerge(
u16 peer_id,
session_t peer_id,
v3s16 blockpos,
bool allow_generate,
bool ignore_queue_limits=false);

bool enqueueBlockEmergeEx(
v3s16 blockpos,
u16 peer_id,
session_t peer_id,
u16 flags,
EmergeCompletionCallback callback,
void *callback_param);
@@ -22,7 +22,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <cassert>
#include "util/basic_macros.h"

bool ModChannel::registerConsumer(u16 peer_id)
bool ModChannel::registerConsumer(session_t peer_id)
{

// ignore if peer_id already joined
@@ -33,7 +33,7 @@ bool ModChannel::registerConsumer(u16 peer_id)
return true;
}

bool ModChannel::removeConsumer(u16 peer_id)
bool ModChannel::removeConsumer(session_t peer_id)
{
bool found = false;
auto peer_removal_fct = [peer_id, &found](u16 p) {
@@ -112,15 +112,15 @@ bool ModChannelMgr::removeChannel(const std::string &channel)
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))
registerChannel(channel);

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))
return false;
@@ -135,7 +135,7 @@ bool ModChannelMgr::leaveChannel(const std::string &channel, u16 peer_id)
return consumerRemoved;
}

void ModChannelMgr::leaveAllChannels(u16 peer_id)
void ModChannelMgr::leaveAllChannels(session_t peer_id)
{
for (auto &channel_it : m_registered_channels)
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 <vector>
#include <memory>
#include "network/networkprotocol.h"
#include "irrlichttypes.h"

enum ModChannelState : u8
@@ -40,8 +41,8 @@ class ModChannel
~ModChannel() = default;

const std::string &getName() const { return m_name; }
bool registerConsumer(u16 peer_id);
bool removeConsumer(u16 peer_id);
bool registerConsumer(session_t peer_id);
bool removeConsumer(session_t peer_id);
const std::vector<u16> &getChannelPeers() const { return m_client_consumers; }
bool canWrite() const;
void setState(ModChannelState state);
@@ -70,8 +71,8 @@ class ModChannelMgr

void registerChannel(const std::string &channel);
bool setChannelState(const std::string &channel, ModChannelState state);
bool joinChannel(const std::string &channel, u16 peer_id);
bool leaveChannel(const std::string &channel, u16 peer_id);
bool joinChannel(const std::string &channel, session_t peer_id);
bool leaveChannel(const std::string &channel, session_t peer_id);
bool channelRegistered(const std::string &channel) const;
ModChannel *getModChannel(const std::string &channel);
/**
@@ -81,7 +82,7 @@ class ModChannelMgr
* @return true if write is allowed
*/
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;

private:
Oops, something went wrong.

0 comments on commit ad7daf7

Please sign in to comment.
You can’t perform that action at this time.