EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
EVEClientSession Class Referenceabstract

Client session from server's side. More...

#include "EVESession.h"

Inheritance diagram for EVEClientSession:
Collaboration diagram for EVEClientSession:

Public Types

typedef TCPConnection::state_t state_t
 

Public Member Functions

 EVEClientSession (EVETCPConnection **n)
 
virtual ~EVEClientSession ()
 Destroys contained connection. More...
 
state_t GetState () const
 
std::string GetAddress () const
 
void Reset ()
 Resets session. More...
 
void QueuePacket (PyPacket *packet)
 Queues new packet, retaking ownership. More...
 
PyPacketPopPacket ()
 Pops new packet from queue. More...
 
void CloseClientConnection ()
 Disconnects client from the server. More...
 

Protected Member Functions

virtual void _GetVersion (VersionExchangeServer &version)=0
 Obtains version. More...
 
virtual uint32 _GetQueuePosition ()=0
 
virtual bool _VerifyVersion (VersionExchangeClient &version)=0
 Verifies version. More...
 
virtual bool _VerifyVIPKey (const std::string &vipKey)=0
 Verifies VIP key. More...
 
virtual bool _VerifyCrypto (CryptoRequestPacket &cr)=0
 Verifies crypto. More...
 
virtual bool _VerifyLogin (CryptoChallengePacket &ccp)=0
 Verifies login. More...
 
virtual bool _VerifyFuncResult (CryptoHandshakeResult &result)=0
 Verifies function result. More...
 

Protected Attributes

EVETCPConnection *const mNet
 

Private Member Functions

PyPacket_HandleVersion (PyRep *rep)
 
PyPacket_HandleCommand (PyRep *rep)
 
PyPacket_HandleCrypto (PyRep *rep)
 
PyPacket_HandleAuthentication (PyRep *rep)
 
PyPacket_HandleFuncResult (PyRep *rep)
 
PyPacket_HandlePacket (PyRep *rep)
 

Private Attributes

PyPacket *(EVEClientSession::* mPacketHandler )(PyRep *rep)
 

Detailed Description

Client session from server's side.

Defines what server needs to do when dealing with client; takes care of initial authentication, before actual packets are sent.

Author
Bloody.Rabbit

Definition at line 49 of file EVESession.h.

Member Typedef Documentation

Typedef for readability.

Definition at line 53 of file EVESession.h.

Constructor & Destructor Documentation

EVEClientSession::EVEClientSession ( EVETCPConnection **  n)
Parameters
[in]nConnection of this session.

Definition at line 38 of file EVESession.cpp.

39 : mNet( *n ),
40 mPacketHandler( nullptr )
41 {
42  *n = nullptr;
43 }
PyPacket *(EVEClientSession::* mPacketHandler)(PyRep *rep)
Definition: EVESession.h:159
EVETCPConnection *const mNet
Definition: EVESession.h:155
EVEClientSession::~EVEClientSession ( )
virtual

Destroys contained connection.

Definition at line 45 of file EVESession.cpp.

References mNet.

45  {
46  // Destroy connection we used
47  delete mNet;
48 }
EVETCPConnection *const mNet
Definition: EVESession.h:155

Member Function Documentation

virtual uint32 EVEClientSession::_GetQueuePosition ( )
protectedpure virtual
Returns
Current count of connected users.
Current position in connection queue.

Implemented in Client.

Referenced by _HandleCommand().

Here is the caller graph for this function:

virtual void EVEClientSession::_GetVersion ( VersionExchangeServer &  version)
protectedpure virtual

Obtains version.

Parameters
[in]versionObject to be filled with version information.

Implemented in Client.

Referenced by Reset().

Here is the caller graph for this function:

PyPacket * EVEClientSession::_HandleAuthentication ( PyRep rep)
private

Definition at line 158 of file EVESession.cpp.

References _HandleFuncResult(), _VerifyLogin(), GetAddress(), mPacketHandler, PopPacket(), and sLog.

Referenced by _HandleCrypto().

158  {
159  //just to be sure
160  CryptoChallengePacket ccp;
161  if ( !ccp.Decode( &rep ) )
162  sLog.Error("_HandleAuthentication", "%s: Received invalid crypto challenge!", GetAddress().c_str());
163  else if ( _VerifyLogin( ccp ) )
165 
166  return PopPacket();
167 }
virtual bool _VerifyLogin(CryptoChallengePacket &ccp)=0
Verifies login.
PyPacket *(EVEClientSession::* mPacketHandler)(PyRep *rep)
Definition: EVESession.h:159
PyPacket * _HandleFuncResult(PyRep *rep)
Definition: EVESession.cpp:169
std::string GetAddress() const
Definition: EVESession.h:67
#define sLog
Evaluates to a NewLog instance.
Definition: LogNew.h:250
PyPacket * PopPacket()
Pops new packet from queue.
Definition: EVESession.cpp:80

Here is the call graph for this function:

Here is the caller graph for this function:

PyPacket * EVEClientSession::_HandleCommand ( PyRep rep)
private

Definition at line 106 of file EVESession.cpp.

References _GetQueuePosition(), _HandleCrypto(), _log, _VerifyVIPKey(), PyRep::AsTuple(), PyRep::Dump(), GetAddress(), is_log_enabled, PyRep::IsTuple(), mNet, mPacketHandler, PopPacket(), EVETCPConnection::QueueRep(), Reset(), PyTuple::size(), and sLog.

Referenced by _HandleVersion().

106  {
107  //check if it actually is tuple
108  if ( !rep->IsTuple() )
109  sLog.Error("_HandleCommand", "%s: Invalid packet during waiting for command (tuple expected).", GetAddress().c_str());
110  else if ( rep->AsTuple()->size() == 2 ) { // decode
111  //QC = Queue Check
112  NetCommand_QC cmd;
113  if ( !cmd.Decode( &rep ) )
114  sLog.Error("_HandleCommand", "%s: Failed to decode 2-arg command.", GetAddress().c_str());
115  else {
116  sLog.Debug("_HandleCommand", "%s: Got Queue Check command.", GetAddress().c_str());
117 
118  //they return position in queue
119  PyRep* rsp = new PyInt( _GetQueuePosition() );
120  mNet->QueueRep( rsp );
121 
122  //now reset connection
123  Reset();
124  }
125  } else if ( rep->AsTuple()->size() == 3 ) {
126  //this is sent when client is logging in
127  NetCommand_VK cmd;
128  if ( !cmd.Decode( &rep ) ) {
129  sLog.Error("_HandleCommand", "%s: Failed to decode 3-arg command.", GetAddress().c_str());
130  } else {
131  sLog.Debug("_HandleCommand", "%s: Got VK command, vipKey=%s.", GetAddress().c_str(), cmd.vipKey.c_str());
132 
133  if ( _VerifyVIPKey( cmd.vipKey ) )
135  }
136  } else {
137  if (is_log_enabled(NET__PRES_ERROR)) {
138  _log(NET__PRES_ERROR, "%s: Received invalid command packet:", GetAddress().c_str());
139  rep->Dump(NET__PRES_ERROR, " ");
140  }
141  }
142 
143  // recurse
144  return PopPacket();
145 }
Base Python wire object.
Definition: PyRep.h:66
PyTuple * AsTuple()
Definition: PyRep.h:138
void Reset()
Resets session.
Definition: EVESession.cpp:50
#define _log(type, fmt,...)
Definition: logsys.h:124
PyPacket *(EVEClientSession::* mPacketHandler)(PyRep *rep)
Definition: EVESession.h:159
size_t size() const
Definition: PyRep.h:591
bool IsTuple() const
Definition: PyRep.h:108
std::string GetAddress() const
Definition: EVESession.h:67
void QueueRep(const PyRep *rep, bool compress=true)
Queues given PyRep into send queue.
void Dump(FILE *into, const char *pfx) const
Dumps object to file.
Definition: PyRep.cpp:84
PyPacket * _HandleCrypto(PyRep *rep)
Definition: EVESession.cpp:147
#define is_log_enabled(type)
Definition: logsys.h:78
#define sLog
Evaluates to a NewLog instance.
Definition: LogNew.h:250
virtual bool _VerifyVIPKey(const std::string &vipKey)=0
Verifies VIP key.
Python integer.
Definition: PyRep.h:231
EVETCPConnection *const mNet
Definition: EVESession.h:155
PyPacket * PopPacket()
Pops new packet from queue.
Definition: EVESession.cpp:80
virtual uint32 _GetQueuePosition()=0

Here is the call graph for this function:

Here is the caller graph for this function:

PyPacket * EVEClientSession::_HandleCrypto ( PyRep rep)
private

Definition at line 147 of file EVESession.cpp.

References _HandleAuthentication(), _VerifyCrypto(), GetAddress(), mPacketHandler, PopPacket(), and sLog.

Referenced by _HandleCommand().

147  {
148  CryptoRequestPacket cr;
149  if ( !cr.Decode( &rep ) )
150  sLog.Error("_HandleCrypto", "%s: Received invalid crypto request!", GetAddress().c_str());
151  else if ( _VerifyCrypto( cr ) )
153 
154  // recurse
155  return PopPacket();
156 }
PyPacket * _HandleAuthentication(PyRep *rep)
Definition: EVESession.cpp:158
PyPacket *(EVEClientSession::* mPacketHandler)(PyRep *rep)
Definition: EVESession.h:159
std::string GetAddress() const
Definition: EVESession.h:67
#define sLog
Evaluates to a NewLog instance.
Definition: LogNew.h:250
virtual bool _VerifyCrypto(CryptoRequestPacket &cr)=0
Verifies crypto.
PyPacket * PopPacket()
Pops new packet from queue.
Definition: EVESession.cpp:80

Here is the call graph for this function:

Here is the caller graph for this function:

PyPacket * EVEClientSession::_HandleFuncResult ( PyRep rep)
private

Definition at line 169 of file EVESession.cpp.

References _HandlePacket(), _VerifyFuncResult(), GetAddress(), mPacketHandler, PopPacket(), and sLog.

Referenced by _HandleAuthentication().

169  {
170  CryptoHandshakeResult hr;
171  if ( !hr.Decode( &rep ) )
172  sLog.Error("_HandleFuncResult", "%s: Received invalid crypto handshake result!", GetAddress().c_str());
173  else if ( _VerifyFuncResult( hr ) )
175 
176  return PopPacket();
177 }
PyPacket * _HandlePacket(PyRep *rep)
Definition: EVESession.cpp:179
PyPacket *(EVEClientSession::* mPacketHandler)(PyRep *rep)
Definition: EVESession.h:159
std::string GetAddress() const
Definition: EVESession.h:67
virtual bool _VerifyFuncResult(CryptoHandshakeResult &result)=0
Verifies function result.
#define sLog
Evaluates to a NewLog instance.
Definition: LogNew.h:250
PyPacket * PopPacket()
Pops new packet from queue.
Definition: EVESession.cpp:80

Here is the call graph for this function:

Here is the caller graph for this function:

PyPacket * EVEClientSession::_HandlePacket ( PyRep rep)
private

Definition at line 179 of file EVESession.cpp.

References PyPacket::Decode(), GetAddress(), PopPacket(), PySafeDecRef, SafeDelete(), and sLog.

Referenced by _HandleFuncResult().

179  {
180  //take the PyRep and turn it into a PyPacket
181  PyPacket* p = new PyPacket();
182  if ( !p->Decode( &rep ) ) { //rep is consumed here
183  sLog.Error("_HandlePacket", "%s: Failed to decode packet rep", GetAddress().c_str());
184  SafeDelete( p );
185  PySafeDecRef(rep);
186  return PopPacket();
187  }
188 
189  return p;
190 }
std::string GetAddress() const
Definition: EVESession.h:67
void SafeDelete(T *&p)
Deletes and nullifies a pointer.
Definition: SafeMem.h:83
#define sLog
Evaluates to a NewLog instance.
Definition: LogNew.h:250
bool Decode(PyRep **packet)
Definition: PyPacket.cpp:115
PyPacket * PopPacket()
Pops new packet from queue.
Definition: EVESession.cpp:80
#define PySafeDecRef(op)
Definition: PyRep.h:61

Here is the call graph for this function:

Here is the caller graph for this function:

PyPacket * EVEClientSession::_HandleVersion ( PyRep rep)
private

Definition at line 94 of file EVESession.cpp.

References _HandleCommand(), _VerifyVersion(), GetAddress(), mPacketHandler, PopPacket(), and sLog.

Referenced by Reset().

94  {
95  //we are waiting for their version information...
96  VersionExchangeClient ve;
97  if ( !ve.Decode( &rep ) )
98  sLog.Error("_HandleVersion", "%s: Received invalid version exchange!", GetAddress().c_str());
99  else if ( _VerifyVersion( ve ) )
101 
102  // recurse
103  return PopPacket();
104 }
PyPacket *(EVEClientSession::* mPacketHandler)(PyRep *rep)
Definition: EVESession.h:159
std::string GetAddress() const
Definition: EVESession.h:67
#define sLog
Evaluates to a NewLog instance.
Definition: LogNew.h:250
virtual bool _VerifyVersion(VersionExchangeClient &version)=0
Verifies version.
PyPacket * _HandleCommand(PyRep *rep)
Definition: EVESession.cpp:106
PyPacket * PopPacket()
Pops new packet from queue.
Definition: EVESession.cpp:80

Here is the call graph for this function:

Here is the caller graph for this function:

virtual bool EVEClientSession::_VerifyCrypto ( CryptoRequestPacket &  cr)
protectedpure virtual

Verifies crypto.

Parameters
[in]crCrypto sent by client.
Return values
trueVerification succeeded; proceeds to next state.
falseVerification failed; stays in current state.

Implemented in Client.

Referenced by _HandleCrypto().

Here is the caller graph for this function:

virtual bool EVEClientSession::_VerifyFuncResult ( CryptoHandshakeResult &  result)
protectedpure virtual

Verifies function result.

Parameters
[in]resultFunction result sent by client.
Return values
trueVerification succeeded; proceeds to next state.
falseVerification failed; stays in current state.

Implemented in Client.

Referenced by _HandleFuncResult().

Here is the caller graph for this function:

virtual bool EVEClientSession::_VerifyLogin ( CryptoChallengePacket &  ccp)
protectedpure virtual

Verifies login.

Parameters
[in]ccpLogin data sent by client.
Return values
trueVerification succeeded; proceeds to next state.
falseVerification failed; stays in current state.

Implemented in Client.

Referenced by _HandleAuthentication().

Here is the caller graph for this function:

virtual bool EVEClientSession::_VerifyVersion ( VersionExchangeClient &  version)
protectedpure virtual

Verifies version.

Parameters
[in]versionVersion sent by client.
Return values
trueVerification succeeded; proceeds to next state.
falseVerification failed; stays in current state.

Implemented in Client.

Referenced by _HandleVersion().

Here is the caller graph for this function:

virtual bool EVEClientSession::_VerifyVIPKey ( const std::string &  vipKey)
protectedpure virtual

Verifies VIP key.

Parameters
[in]vipKeyVIP key sent by client.
Return values
trueVerification succeeded; proceeds to next state.
falseVerification failed; stays in current state.

Implemented in Client.

Referenced by _HandleCommand().

Here is the caller graph for this function:

void EVEClientSession::CloseClientConnection ( )
inline

Disconnects client from the server.

Definition at line 93 of file EVESession.h.

References TCPConnection::Disconnect(), and mNet.

Referenced by Client::DisconnectClient(), and Client::SelectCharacter().

93 { mNet->Disconnect(); }
EVETCPConnection *const mNet
Definition: EVESession.h:155
void Disconnect()
Schedules disconnect of current connection.

Here is the call graph for this function:

Here is the caller graph for this function:

std::string EVEClientSession::GetAddress ( ) const
inline

Wrapper of TCPConnection::GetAddress().

Definition at line 67 of file EVESession.h.

References TCPConnection::GetAddress(), and mNet.

Referenced by _HandleAuthentication(), _HandleCommand(), _HandleCrypto(), _HandleFuncResult(), _HandlePacket(), _HandleVersion(), Client::_VerifyLogin(), PopPacket(), and QueuePacket().

67 { return mNet->GetAddress(); }
std::string GetAddress()
EVETCPConnection *const mNet
Definition: EVESession.h:155

Here is the call graph for this function:

Here is the caller graph for this function:

state_t EVEClientSession::GetState ( ) const
inline

Wrapper of TCPConnection::GetState().

Definition at line 65 of file EVESession.h.

References TCPConnection::GetState(), and mNet.

Referenced by Client::ProcessNet(), and Reset().

65 { return mNet->GetState(); }
EVETCPConnection *const mNet
Definition: EVESession.h:155
state_t GetState() const
Definition: TCPConnection.h:77

Here is the call graph for this function:

Here is the caller graph for this function:

PyPacket * EVEClientSession::PopPacket ( )

Pops new packet from queue.

Returns
Popped packet.

Definition at line 80 of file EVESession.cpp.

References _log, GetAddress(), is_log_enabled, mNet, mPacketHandler, and EVETCPConnection::PopRep().

Referenced by _HandleAuthentication(), _HandleCommand(), _HandleCrypto(), _HandleFuncResult(), _HandlePacket(), _HandleVersion(), and Client::ProcessNet().

80  {
81  PyRep* rep(mNet->PopRep());
82  if (rep == nullptr)
83  return nullptr;
84 
85  if (is_log_enabled(NET__PRES_REP)) {
86  _log(NET__PRES_REP, "%s: Raw Rep Dump:", GetAddress().c_str());
87  rep->Dump(NET__PRES_REP, " ");
88  }
89 
90  assert( mPacketHandler );
91  return ( this->*mPacketHandler )( rep );
92 }
Base Python wire object.
Definition: PyRep.h:66
#define _log(type, fmt,...)
Definition: logsys.h:124
PyPacket *(EVEClientSession::* mPacketHandler)(PyRep *rep)
Definition: EVESession.h:159
std::string GetAddress() const
Definition: EVESession.h:67
PyRep * PopRep()
Pops PyRep from receive queue.
#define is_log_enabled(type)
Definition: logsys.h:78
EVETCPConnection *const mNet
Definition: EVESession.h:155

Here is the call graph for this function:

Here is the caller graph for this function:

void EVEClientSession::QueuePacket ( PyPacket packet)

Queues new packet, retaking ownership.

Parameters
[in]pPacked to be queued.

Definition at line 66 of file EVESession.cpp.

References PyPacket::Encode(), GetAddress(), mNet, EVETCPConnection::QueueRep(), and sLog.

Referenced by Client::_SendCallReturn(), Client::_SendException(), Client::_SendPingRequest(), Client::_SendPingResponse(), Client::SendInitialSessionStatus(), Client::SendNotification(), and Client::SendSessionChange().

66  {
67  if (packet == nullptr)
68  return;
69 
70  PyRep* res(packet->Encode());
71 
72  if (res == nullptr) {
73  sLog.Error("QueuePacket", "%s: Failed to encode a packet.", GetAddress().c_str());
74  return;
75  }
76 
77  mNet->QueueRep( res );
78 }
Base Python wire object.
Definition: PyRep.h:66
std::string GetAddress() const
Definition: EVESession.h:67
void QueueRep(const PyRep *rep, bool compress=true)
Queues given PyRep into send queue.
#define sLog
Evaluates to a NewLog instance.
Definition: LogNew.h:250
EVETCPConnection *const mNet
Definition: EVESession.h:155
PyRep * Encode()
Definition: PyPacket.cpp:240

Here is the call graph for this function:

Here is the caller graph for this function:

void EVEClientSession::Reset ( )

Resets session.

Reset session so we act like client just connected.

Definition at line 50 of file EVESession.cpp.

References _GetVersion(), _HandleVersion(), GetState(), mNet, mPacketHandler, EVETCPConnection::QueueRep(), and TCPConnection::STATE_CONNECTED.

Referenced by _HandleCommand(), and Client::Client().

50  {
51  mPacketHandler = nullptr;
52 
54  // Connection has been lost, there's no point in reset
55  return;
56 
57  VersionExchangeServer version;
58  _GetVersion( version );
59 
60  PyRep* res(version.Encode());
61  mNet->QueueRep(res);
62 
64 }
Base Python wire object.
Definition: PyRep.h:66
PyPacket *(EVEClientSession::* mPacketHandler)(PyRep *rep)
Definition: EVESession.h:159
void QueueRep(const PyRep *rep, bool compress=true)
Queues given PyRep into send queue.
PyPacket * _HandleVersion(PyRep *rep)
Definition: EVESession.cpp:94
EVETCPConnection *const mNet
Definition: EVESession.h:155
virtual void _GetVersion(VersionExchangeServer &version)=0
Obtains version.
state_t GetState() const
Definition: EVESession.h:65

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

PyPacket*( EVEClientSession::* EVEClientSession::mPacketHandler)(PyRep *rep)
private

The documentation for this class was generated from the following files: