Skip to content

Commit ad7daf7

Browse files
authoredSep 27, 2017
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
1 parent 50b2185 commit ad7daf7

24 files changed

+295
-284
lines changed
 

Diff for: ‎src/client.cpp

+2-6
Original file line numberDiff line numberDiff line change
@@ -1218,11 +1218,7 @@ void Client::sendPlayerPos()
12181218

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

1221-
u16 our_peer_id;
1222-
{
1223-
//MutexAutoLock lock(m_con_mutex); //bulk comment-out
1224-
our_peer_id = m_con->GetPeerID();
1225-
}
1221+
session_t our_peer_id = m_con->GetPeerID();
12261222

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

1246-
u16 our_peer_id = m_con->GetPeerID();
1242+
session_t our_peer_id = m_con->GetPeerID();
12471243

12481244
// Set peer id if not set already
12491245
if(myplayer->peer_id == PEER_ID_INEXISTENT)

Diff for: ‎src/clientiface.cpp

+13-12
Original file line numberDiff line numberDiff line change
@@ -669,8 +669,8 @@ void ClientInterface::UpdatePlayerList()
669669
}
670670
}
671671

672-
void ClientInterface::send(u16 peer_id, u8 channelnum,
673-
NetworkPacket* pkt, bool reliable)
672+
void ClientInterface::send(session_t peer_id, u8 channelnum,
673+
NetworkPacket *pkt, bool reliable)
674674
{
675675
m_con->Send(peer_id, channelnum, pkt, reliable);
676676
}
@@ -714,7 +714,7 @@ void ClientInterface::sendToAllCompat(NetworkPacket *pkt, NetworkPacket *legacyp
714714
}
715715
}
716716

717-
RemoteClient* ClientInterface::getClientNoEx(u16 peer_id, ClientState state_min)
717+
RemoteClient* ClientInterface::getClientNoEx(session_t peer_id, ClientState state_min)
718718
{
719719
MutexAutoLock clientslock(m_clients_mutex);
720720
RemoteClientMap::const_iterator n = m_clients.find(peer_id);
@@ -729,7 +729,7 @@ RemoteClient* ClientInterface::getClientNoEx(u16 peer_id, ClientState state_min)
729729
return NULL;
730730
}
731731

732-
RemoteClient* ClientInterface::lockedGetClientNoEx(u16 peer_id, ClientState state_min)
732+
RemoteClient* ClientInterface::lockedGetClientNoEx(session_t peer_id, ClientState state_min)
733733
{
734734
RemoteClientMap::const_iterator n = m_clients.find(peer_id);
735735
// The client may not exist; clients are immediately removed if their
@@ -743,7 +743,7 @@ RemoteClient* ClientInterface::lockedGetClientNoEx(u16 peer_id, ClientState stat
743743
return NULL;
744744
}
745745

746-
ClientState ClientInterface::getClientState(u16 peer_id)
746+
ClientState ClientInterface::getClientState(session_t peer_id)
747747
{
748748
MutexAutoLock clientslock(m_clients_mutex);
749749
RemoteClientMap::const_iterator n = m_clients.find(peer_id);
@@ -755,7 +755,7 @@ ClientState ClientInterface::getClientState(u16 peer_id)
755755
return n->second->getState();
756756
}
757757

758-
void ClientInterface::setPlayerName(u16 peer_id,std::string name)
758+
void ClientInterface::setPlayerName(session_t peer_id, const std::string &name)
759759
{
760760
MutexAutoLock clientslock(m_clients_mutex);
761761
RemoteClientMap::iterator n = m_clients.find(peer_id);
@@ -765,7 +765,7 @@ void ClientInterface::setPlayerName(u16 peer_id,std::string name)
765765
n->second->setName(name);
766766
}
767767

768-
void ClientInterface::DeleteClient(u16 peer_id)
768+
void ClientInterface::DeleteClient(session_t peer_id)
769769
{
770770
MutexAutoLock conlock(m_clients_mutex);
771771

@@ -795,7 +795,7 @@ void ClientInterface::DeleteClient(u16 peer_id)
795795
m_clients.erase(peer_id);
796796
}
797797

798-
void ClientInterface::CreateClient(u16 peer_id)
798+
void ClientInterface::CreateClient(session_t peer_id)
799799
{
800800
MutexAutoLock conlock(m_clients_mutex);
801801

@@ -810,7 +810,7 @@ void ClientInterface::CreateClient(u16 peer_id)
810810
m_clients[client->peer_id] = client;
811811
}
812812

813-
void ClientInterface::event(u16 peer_id, ClientStateEvent event)
813+
void ClientInterface::event(session_t peer_id, ClientStateEvent event)
814814
{
815815
{
816816
MutexAutoLock clientlock(m_clients_mutex);
@@ -832,7 +832,7 @@ void ClientInterface::event(u16 peer_id, ClientStateEvent event)
832832
}
833833
}
834834

835-
u16 ClientInterface::getProtocolVersion(u16 peer_id)
835+
u16 ClientInterface::getProtocolVersion(session_t peer_id)
836836
{
837837
MutexAutoLock conlock(m_clients_mutex);
838838

@@ -846,7 +846,8 @@ u16 ClientInterface::getProtocolVersion(u16 peer_id)
846846
return n->second->net_proto_version;
847847
}
848848

849-
void ClientInterface::setClientVersion(u16 peer_id, u8 major, u8 minor, u8 patch, std::string full)
849+
void ClientInterface::setClientVersion(session_t peer_id, u8 major, u8 minor, u8 patch,
850+
const std::string &full)
850851
{
851852
MutexAutoLock conlock(m_clients_mutex);
852853

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

860-
n->second->setVersionInfo(major,minor,patch,full);
861+
n->second->setVersionInfo(major, minor, patch, full);
861862
}

Diff for: ‎src/clientiface.h

+14-13
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ enum ClientStateEvent
205205
*/
206206
struct PrioritySortedBlockTransfer
207207
{
208-
PrioritySortedBlockTransfer(float a_priority, const v3s16 &a_pos, u16 a_peer_id)
208+
PrioritySortedBlockTransfer(float a_priority, const v3s16 &a_pos, session_t a_peer_id)
209209
{
210210
priority = a_priority;
211211
pos = a_pos;
@@ -217,7 +217,7 @@ struct PrioritySortedBlockTransfer
217217
}
218218
float priority;
219219
v3s16 pos;
220-
u16 peer_id;
220+
session_t peer_id;
221221
};
222222

223223
class RemoteClient
@@ -227,7 +227,7 @@ class RemoteClient
227227
// NOTE: If client is made allowed to exist while peer doesn't,
228228
// this has to be set to 0 when there is no peer.
229229
// Also, the client must be moved to some other container.
230-
u16 peer_id = PEER_ID_INEXISTENT;
230+
session_t peer_id = PEER_ID_INEXISTENT;
231231
// The serialization version to use with the client
232232
u8 serialization_version = SER_FMT_VER_INVALID;
233233
//
@@ -431,38 +431,39 @@ class ClientInterface {
431431
const std::vector<std::string> &getPlayerNames() const { return m_clients_names; }
432432

433433
/* send message to client */
434-
void send(u16 peer_id, u8 channelnum, NetworkPacket* pkt, bool reliable);
434+
void send(session_t peer_id, u8 channelnum, NetworkPacket *pkt, bool reliable);
435435

436436
/* send to all clients */
437437
void sendToAll(NetworkPacket *pkt);
438438
void sendToAllCompat(NetworkPacket *pkt, NetworkPacket *legacypkt, u16 min_proto_ver);
439439

440440
/* delete a client */
441-
void DeleteClient(u16 peer_id);
441+
void DeleteClient(session_t peer_id);
442442

443443
/* create client */
444-
void CreateClient(u16 peer_id);
444+
void CreateClient(session_t peer_id);
445445

446446
/* get a client by peer_id */
447-
RemoteClient* getClientNoEx(u16 peer_id, ClientState state_min=CS_Active);
447+
RemoteClient *getClientNoEx(session_t peer_id, ClientState state_min = CS_Active);
448448

449449
/* get client by peer_id (make sure you have list lock before!*/
450-
RemoteClient* lockedGetClientNoEx(u16 peer_id, ClientState state_min=CS_Active);
450+
RemoteClient *lockedGetClientNoEx(session_t peer_id, ClientState state_min = CS_Active);
451451

452452
/* get state of client by id*/
453-
ClientState getClientState(u16 peer_id);
453+
ClientState getClientState(session_t peer_id);
454454

455455
/* set client playername */
456-
void setPlayerName(u16 peer_id,std::string name);
456+
void setPlayerName(session_t peer_id, const std::string &name);
457457

458458
/* get protocol version of client */
459-
u16 getProtocolVersion(u16 peer_id);
459+
u16 getProtocolVersion(session_t peer_id);
460460

461461
/* set client version */
462-
void setClientVersion(u16 peer_id, u8 major, u8 minor, u8 patch, std::string full);
462+
void setClientVersion(session_t peer_id, u8 major, u8 minor, u8 patch,
463+
const std::string &full);
463464

464465
/* event to update client state */
465-
void event(u16 peer_id, ClientStateEvent event);
466+
void event(session_t peer_id, ClientStateEvent event);
466467

467468
/* Set environment. Do not call this function if environment is already set */
468469
void setEnv(ServerEnvironment *env)

Diff for: ‎src/content_sao.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,7 @@ bool LuaEntitySAO::collideWithObjects() const
784784

785785
// No prototype, PlayerSAO does not need to be deserialized
786786

787-
PlayerSAO::PlayerSAO(ServerEnvironment *env_, RemotePlayer *player_, u16 peer_id_,
787+
PlayerSAO::PlayerSAO(ServerEnvironment *env_, RemotePlayer *player_, session_t peer_id_,
788788
bool is_singleplayer):
789789
UnitSAO(env_, v3f(0,0,0)),
790790
m_player(player_),

Diff for: ‎src/content_sao.h

+6-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
1919

2020
#pragma once
2121

22-
#include <util/numeric.h>
22+
#include "network/networkprotocol.h"
23+
#include "util/numeric.h"
2324
#include "serverobject.h"
2425
#include "itemgroup.h"
2526
#include "object_properties.h"
@@ -196,7 +197,8 @@ class RemotePlayer;
196197
class PlayerSAO : public UnitSAO
197198
{
198199
public:
199-
PlayerSAO(ServerEnvironment *env_, RemotePlayer *player_, u16 peer_id_, bool is_singleplayer);
200+
PlayerSAO(ServerEnvironment *env_, RemotePlayer *player_, session_t peer_id_,
201+
bool is_singleplayer);
200202
~PlayerSAO();
201203
ActiveObjectType getType() const
202204
{ return ACTIVEOBJECT_TYPE_PLAYER; }
@@ -311,7 +313,7 @@ class PlayerSAO : public UnitSAO
311313
void disconnected();
312314

313315
RemotePlayer *getPlayer() { return m_player; }
314-
u16 getPeerID() const { return m_peer_id; }
316+
session_t getPeerID() const { return m_peer_id; }
315317

316318
// Cheat prevention
317319

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

374376
RemotePlayer *m_player = nullptr;
375-
u16 m_peer_id = 0;
377+
session_t m_peer_id = 0;
376378
Inventory *m_inventory = nullptr;
377379
s16 m_damage = 0;
378380

Diff for: ‎src/emerge.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ bool EmergeManager::isRunning()
247247

248248

249249
bool EmergeManager::enqueueBlockEmerge(
250-
u16 peer_id,
250+
session_t peer_id,
251251
v3s16 blockpos,
252252
bool allow_generate,
253253
bool ignore_queue_limits)
@@ -264,7 +264,7 @@ bool EmergeManager::enqueueBlockEmerge(
264264

265265
bool EmergeManager::enqueueBlockEmergeEx(
266266
v3s16 blockpos,
267-
u16 peer_id,
267+
session_t peer_id,
268268
u16 flags,
269269
EmergeCompletionCallback callback,
270270
void *callback_param)

Diff for: ‎src/emerge.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2121

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

125126
bool enqueueBlockEmerge(
126-
u16 peer_id,
127+
session_t peer_id,
127128
v3s16 blockpos,
128129
bool allow_generate,
129130
bool ignore_queue_limits=false);
130131

131132
bool enqueueBlockEmergeEx(
132133
v3s16 blockpos,
133-
u16 peer_id,
134+
session_t peer_id,
134135
u16 flags,
135136
EmergeCompletionCallback callback,
136137
void *callback_param);

Diff for: ‎src/modchannels.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2222
#include <cassert>
2323
#include "util/basic_macros.h"
2424

25-
bool ModChannel::registerConsumer(u16 peer_id)
25+
bool ModChannel::registerConsumer(session_t peer_id)
2626
{
2727

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

36-
bool ModChannel::removeConsumer(u16 peer_id)
36+
bool ModChannel::removeConsumer(session_t peer_id)
3737
{
3838
bool found = false;
3939
auto peer_removal_fct = [peer_id, &found](u16 p) {
@@ -112,15 +112,15 @@ bool ModChannelMgr::removeChannel(const std::string &channel)
112112
return true;
113113
}
114114

115-
bool ModChannelMgr::joinChannel(const std::string &channel, u16 peer_id)
115+
bool ModChannelMgr::joinChannel(const std::string &channel, session_t peer_id)
116116
{
117117
if (!channelRegistered(channel))
118118
registerChannel(channel);
119119

120120
return m_registered_channels[channel]->registerConsumer(peer_id);
121121
}
122122

123-
bool ModChannelMgr::leaveChannel(const std::string &channel, u16 peer_id)
123+
bool ModChannelMgr::leaveChannel(const std::string &channel, session_t peer_id)
124124
{
125125
if (!channelRegistered(channel))
126126
return false;
@@ -135,7 +135,7 @@ bool ModChannelMgr::leaveChannel(const std::string &channel, u16 peer_id)
135135
return consumerRemoved;
136136
}
137137

138-
void ModChannelMgr::leaveAllChannels(u16 peer_id)
138+
void ModChannelMgr::leaveAllChannels(session_t peer_id)
139139
{
140140
for (auto &channel_it : m_registered_channels)
141141
channel_it.second->removeConsumer(peer_id);

Diff for: ‎src/modchannels.h

+6-5
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2323
#include <string>
2424
#include <vector>
2525
#include <memory>
26+
#include "network/networkprotocol.h"
2627
#include "irrlichttypes.h"
2728

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

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

7172
void registerChannel(const std::string &channel);
7273
bool setChannelState(const std::string &channel, ModChannelState state);
73-
bool joinChannel(const std::string &channel, u16 peer_id);
74-
bool leaveChannel(const std::string &channel, u16 peer_id);
74+
bool joinChannel(const std::string &channel, session_t peer_id);
75+
bool leaveChannel(const std::string &channel, session_t peer_id);
7576
bool channelRegistered(const std::string &channel) const;
7677
ModChannel *getModChannel(const std::string &channel);
7778
/**
@@ -81,7 +82,7 @@ class ModChannelMgr
8182
* @return true if write is allowed
8283
*/
8384
bool canWriteOnChannel(const std::string &channel) const;
84-
void leaveAllChannels(u16 peer_id);
85+
void leaveAllChannels(session_t peer_id);
8586
const std::vector<u16> &getChannelPeers(const std::string &channel) const;
8687

8788
private:

0 commit comments

Comments
 (0)
Please sign in to comment.