Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save comet0/a4d842b5acf4957364982c1526a864a9 to your computer and use it in GitHub Desktop.
Save comet0/a4d842b5acf4957364982c1526a864a9 to your computer and use it in GitHub Desktop.
diff --git a/src/eve-server/Client.cpp b/src/eve-server/Client.cpp
index c5098a0..eedb89e 100644
--- a/src/eve-server/Client.cpp
+++ b/src/eve-server/Client.cpp
@@ -767,8 +767,7 @@ void Client::_SendSessionChange()
SessionChangeNotification scn;
scn.changes = new PyDict;
- // TO-DO: This should be a unique value for each login.
- scn.sessionID = GetAccountID();
+ scn.sessionID = GetSessionID();
mSession.EncodeChanges( scn.changes );
if( scn.changes->empty() )
@@ -1723,6 +1722,7 @@ bool Client::_VerifyLogin( CryptoChallengePacket& ccp )
mSession.SetInt( "userType", 20); // That was old, 1 is not defined by the client, 20 is userTypePBC //1 );
mSession.SetInt( "userid", account_info.id );
mSession.SetLong( "role", account_info.role );
+ mSession.SetLong( "sessionID", MakeRandomInt(0, UINT64_MAX-1)); // defined in client in basesession.py:GetNewSid(): return random.getrandbits(63)
return true;
@@ -1743,9 +1743,8 @@ bool Client::_VerifyFuncResult( CryptoHandshakeResult& result )
CryptoHandshakeAck ack;
ack.access_token = new PyNone;
ack.client_hash = new PyNone;
- ack.sessionID = 123456789; // TODO: Generate random sessionID for every client.
- // TO-DO: This should be (incrementingOffset * 10000000000L + nodeID)
- ack.user_clientid = GetAccountID();
+ ack.sessionID = GetSessionID();
+ ack.user_clientid = GetNextClientSessionID();
ack.live_updates = new PyList(0); // No, we will never update the client with this method.
ack.languageID = GetLanguageID();
ack.userid = GetAccountID();
@@ -1884,3 +1883,7 @@ void Client::UpdateSession(const char *sessionType, int value)
mSession.SetInt(sessionType, value);
}
+int64 GetNextClientSessionID()
+{
+ return ++EntityList::clientIDOffset * 10000000000 + PyServiceMgr::GetNodeID();
+}
diff --git a/src/eve-server/Client.h b/src/eve-server/Client.h
index 3caef4c..5a805f9 100644
--- a/src/eve-server/Client.h
+++ b/src/eve-server/Client.h
@@ -101,6 +101,7 @@ public:
uint32 GetAccountType() const { return mSession.GetCurrentInt( "userType" ); }
uint32 GetAccountID() const { return mSession.GetCurrentInt( "userid" ); }
+ uint64 GetSessionID() const { return mSession.GetCurrentLong( "sessionID" ); }
uint64 GetAccountRole() const { return mSession.GetCurrentLong( "role" ); }
uint32 GetCharacterID() const { return mSession.GetCurrentInt( "charid" ); }
@@ -339,4 +340,11 @@ private:
std::list<PyTuple*> mDogmaMessages;
};
+/**
+ * @brief Generates the next user_clientid.
+ *
+ * @return Next user_clientid.
+ */
+int64 GetNextClientSessionID();
+
#endif
diff --git a/src/eve-server/EntityList.cpp b/src/eve-server/EntityList.cpp
index 8e1c63f..13ba2ac 100644
--- a/src/eve-server/EntityList.cpp
+++ b/src/eve-server/EntityList.cpp
@@ -35,6 +35,7 @@ client_list m_clients;
typedef std::map<uint32, SystemManager *> system_list;
system_list m_systems;
Mutex mMutex;
+uint32 EntityList::clientIDOffset = 0;
void EntityList::Add(Client **client)
{
diff --git a/src/eve-server/EntityList.h b/src/eve-server/EntityList.h
index b435ad4..21a4e4b 100644
--- a/src/eve-server/EntityList.h
+++ b/src/eve-server/EntityList.h
@@ -77,6 +77,7 @@ public:
static void Unicast(uint32 charID, const char *notifyType, const char *idType, PyTuple **payload, bool seq = true);
static void GetClients(const character_set &cset, std::vector<Client *> &result);
+ static uint32 clientIDOffset;
};
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment