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

Value keeper for single EVE session. More...

#include "ClientSession.h"

Collaboration diagram for ClientSession:

Public Member Functions

 ClientSession ()
 
 ~ClientSession ()
 
bool isDirty () const
 
void SetInt (const char *name, int32 value)
 
int32 GetLastInt (const char *name) const
 
int32 GetCurrentInt (const char *name) const
 
void SetLong (const char *name, int64 value)
 
int64 GetLastLong (const char *name) const
 
int64 GetCurrentLong (const char *name) const
 
void SetString (const char *name, const char *value)
 
std::string GetLastString (const char *name) const
 
std::string GetCurrentString (const char *name) const
 
void Clear (const char *name)
 
void EncodeChanges (PyDict *into)
 
void EncodeInitialState (PyDict *into)
 
int64 GetSessionID ()
 

Protected Member Functions

PyRep_GetLast (const char *name) const
 
PyRep_GetCurrent (const char *name) const
 
PyTuple_GetValueTuple (const char *name) const
 
void _Set (const char *name, PyRep *value)
 

Protected Attributes

PyDict *const mSession
 

Private Attributes

bool mDirty
 
int64 m_sessionID
 

Detailed Description

Value keeper for single EVE session.

This object keeps track of string-value pairs and encodes their changes as session changes.

Definition at line 37 of file ClientSession.h.

Constructor & Destructor Documentation

ClientSession::ClientSession ( )

Definition at line 46 of file ClientSession.cpp.

References GetTimeUSeconds(), m_sessionID, mSession, new_tuple(), Acct::Role::NEWBIE, Acct::Role::PLAYER, PyStatic, sEntityList, and PyDict::SetItemString().

47 : mSession(new PyDict()),
48 mDirty(false),
49 m_sessionID(0)
50 {
51  /* default session values */
53  mSession->SetItemString("userid", new_tuple(PyStatic.NewNone(), PyStatic.NewZero(), PyStatic.NewFalse()));
54  mSession->SetItemString("address", new_tuple(PyStatic.NewNone(), new PyString("0.0.0.0"), PyStatic.NewFalse()));
55 
56  /* session id is unique to each session.
57  * is not saved or shared between chars
58  */
59  //random.getrandbits(63)
61  sEntityList.RegisterSID(m_sessionID);
62 }
Python string.
Definition: PyRep.h:430
Python's dictionary.
Definition: PyRep.h:719
#define sEntityList
Definition: EntityList.h:208
double GetTimeUSeconds()
Definition: utils_time.cpp:116
PyTuple * new_tuple(int64 arg1)
Definition: PyRep.cpp:1160
#define PyStatic
Definition: PyRep.h:1209
PyDict *const mSession
Definition: ClientSession.h:85
void SetItemString(const char *key, PyRep *value)
SetItemString adds or sets a database entry.
Definition: PyRep.h:812
Python long integer.
Definition: PyRep.h:261

Here is the call graph for this function:

ClientSession::~ClientSession ( )

Definition at line 64 of file ClientSession.cpp.

References m_sessionID, mSession, PyDecRef, and sEntityList.

65 {
66  // do we clear session vars here, or let ~PyDict() do it?
68  sEntityList.RemoveSID(m_sessionID);
69 }
#define sEntityList
Definition: EntityList.h:208
#define PyDecRef(op)
Definition: PyRep.h:57
PyDict *const mSession
Definition: ClientSession.h:85

Member Function Documentation

PyRep * ClientSession::_GetCurrent ( const char *  name) const
protected

Definition at line 180 of file ClientSession.cpp.

References _GetValueTuple(), _log, PyTuple::GetItem(), is_log_enabled, and EvE::traceStack().

Referenced by GetCurrentInt(), GetCurrentLong(), and GetCurrentString().

181 {
182  PyTuple* tuple(_GetValueTuple(name)); // copy c'tor
183  if (tuple == nullptr) {
184  if (is_log_enabled(CLIENT__SESSION_NOTFOUND)) {
185  _log(CLIENT__SESSION_NOTFOUND, "ClientSession::_GetCurrent - value not found with name '%s'", name);
186  EvE::traceStack();
187  }
188  return nullptr;
189  }
190  return tuple->GetItem(1);
191 }
#define _log(type, fmt,...)
Definition: logsys.h:124
PyTuple * _GetValueTuple(const char *name) const
Python tuple.
Definition: PyRep.h:567
#define is_log_enabled(type)
Definition: logsys.h:78
void traceStack(void)
Definition: misc.cpp:169

Here is the call graph for this function:

Here is the caller graph for this function:

PyRep * ClientSession::_GetLast ( const char *  name) const
protected

Definition at line 170 of file ClientSession.cpp.

References _GetValueTuple(), _log, and PyTuple::GetItem().

Referenced by GetLastInt(), GetLastLong(), and GetLastString().

171 {
172  PyTuple* tuple(_GetValueTuple(name)); // copy c'tor
173  if (tuple == nullptr) {
174  _log(CLIENT__SESSION_NOTFOUND, "ClientSession::_GetLast - value not found with name '%s'", name);
175  return nullptr;
176  }
177  return tuple->GetItem(0);
178 }
#define _log(type, fmt,...)
Definition: logsys.h:124
PyTuple * _GetValueTuple(const char *name) const
Python tuple.
Definition: PyRep.h:567

Here is the call graph for this function:

Here is the caller graph for this function:

PyTuple * ClientSession::_GetValueTuple ( const char *  name) const
protected

Definition at line 162 of file ClientSession.cpp.

References PyRep::AsTuple(), PyDict::GetItemString(), and mSession.

Referenced by _GetCurrent(), _GetLast(), and _Set().

163 {
164  PyRep* value(mSession->GetItemString(name));
165  if (value == nullptr)
166  return nullptr;
167  return value->AsTuple();
168 }
Base Python wire object.
Definition: PyRep.h:66
PyTuple * AsTuple()
Definition: PyRep.h:138
PyRep * GetItemString(const char *key) const
Obtains database entry based on given key string.
Definition: PyRep.cpp:702
PyDict *const mSession
Definition: ClientSession.h:85

Here is the call graph for this function:

Here is the caller graph for this function:

void ClientSession::_Set ( const char *  name,
PyRep value 
)
protected

Definition at line 193 of file ClientSession.cpp.

References _GetValueTuple(), PyTuple::GetItem(), PyRep::hash(), mDirty, mSession, new_tuple(), PyDecRef, PyStatic, PyTuple::SetItem(), and PyDict::SetItemString().

Referenced by Clear(), SetInt(), SetLong(), and SetString().

194 {
195  PyTuple* tuple(_GetValueTuple(name)); // copy c'tor
196  if (tuple == nullptr) {
197  tuple = new_tuple(PyStatic.NewNone(), PyStatic.NewNone(), PyStatic.NewFalse());
198  mSession->SetItemString(name, tuple);
199  }
200 
201  PyRep* current(tuple->GetItem(1)); // copy c'tor
202  if (value->hash() != current->hash()) {
203  tuple->SetItem(0, current); /* didn't the session need to store the old value too? */
204  tuple->SetItem(1, value);
205  tuple->SetItem(2, PyStatic.NewTrue());
206  mDirty = true;
207  } else {
208  PyDecRef(value);
209  }
210 }
Base Python wire object.
Definition: PyRep.h:66
PyTuple * _GetValueTuple(const char *name) const
Python tuple.
Definition: PyRep.h:567
PyTuple * new_tuple(int64 arg1)
Definition: PyRep.cpp:1160
#define PyStatic
Definition: PyRep.h:1209
virtual int32 hash() const
virtual function to generate a hash value of a object.
Definition: PyRep.cpp:96
#define PyDecRef(op)
Definition: PyRep.h:57
PyDict *const mSession
Definition: ClientSession.h:85
void SetItemString(const char *key, PyRep *value)
SetItemString adds or sets a database entry.
Definition: PyRep.h:812

Here is the call graph for this function:

Here is the caller graph for this function:

void ClientSession::Clear ( const char *  name)

Definition at line 72 of file ClientSession.cpp.

References _Set(), and PyStatic.

Referenced by Client::InitSession(), and Client::UpdateSession().

73 {
74  _Set(name, PyStatic.NewNone());
75 }
#define PyStatic
Definition: PyRep.h:1209
void _Set(const char *name, PyRep *value)

Here is the call graph for this function:

Here is the caller graph for this function:

void ClientSession::EncodeChanges ( PyDict into)

Buils a PyDictionary with the list of changes the session has gone through Every item is a tuple that includes the old and new value so the client can compare against what it has

Parameters
into

Definition at line 122 of file ClientSession.cpp.

References PyRep::AsBool(), PyRep::AsTuple(), PyTuple::GetItem(), mDirty, mSession, new_tuple(), PyStatic, PyTuple::SetItem(), PyDict::SetItem(), and PyBool::value().

Referenced by Client::SendSessionChange().

123 {
124  if (!mDirty)
125  return;
126 
127  for (auto cur : *mSession)
128  {
129  PyTuple* valueTuple = cur.second->AsTuple ();
130 
131  if (valueTuple->GetItem (2)->AsBool ()->value () == false)
132  continue;
133 
134  // mark the value as not new
135  valueTuple->SetItem (2, PyStatic.NewFalse());
136 
137  // add the value to the list if it should be persisted
138  if (NONPERSISTVARS.find (cur.first->AsString ()->content ()) == NONPERSISTVARS.end ())
139  into->SetItem (cur.first, new_tuple (valueTuple->GetItem (0), valueTuple->GetItem(1)));
140  }
141 
142  mDirty = false;
143 }
PyTuple * AsTuple()
Definition: PyRep.h:138
PyRep * GetItem(size_t index) const
Returns Python object.
Definition: PyRep.h:602
PyBool * AsBool()
Definition: PyRep.h:128
bool value() const
Definition: PyRep.h:340
Python tuple.
Definition: PyRep.h:567
static std::map< std::string, bool > NONPERSISTVARS
PyTuple * new_tuple(int64 arg1)
Definition: PyRep.cpp:1160
void SetItem(size_t index, PyRep *object)
Stores Python object.
Definition: PyRep.h:610
#define PyStatic
Definition: PyRep.h:1209
PyDict *const mSession
Definition: ClientSession.h:85
void SetItem(PyRep *key, PyRep *value)
SetItem adds or sets a database entry.
Definition: PyRep.cpp:713

Here is the call graph for this function:

Here is the caller graph for this function:

void ClientSession::EncodeInitialState ( PyDict into)

Builds a PyDictionary with the current state of the session. Useful for macho.SessionInitialStateNotification The side-effects include overwriting of the old value on the session data with the new one

Parameters
into

Definition at line 145 of file ClientSession.cpp.

References PyRep::AsTuple(), mDirty, mSession, PyStatic, PyTuple::SetItem(), and PyDict::SetItem().

Referenced by Client::SendInitialSessionStatus().

146 {
147  for (auto cur : *mSession)
148  {
149  PyTuple* valueTuple = cur.second->AsTuple ();
150 
151  valueTuple->SetItem(2, PyStatic.NewFalse());
152 
153  // add the value to the initial state only if required
154  if (NONPERSISTVARS.find (cur.first->AsString ()->content ()) == NONPERSISTVARS.end ())
155  into->SetItem (cur.first, cur.second->AsTuple ()->GetItem (1));
156  }
157 
158  // mark the session as not dirty
159  mDirty = false;
160 }
PyTuple * AsTuple()
Definition: PyRep.h:138
Python tuple.
Definition: PyRep.h:567
static std::map< std::string, bool > NONPERSISTVARS
void SetItem(size_t index, PyRep *object)
Stores Python object.
Definition: PyRep.h:610
#define PyStatic
Definition: PyRep.h:1209
PyDict *const mSession
Definition: ClientSession.h:85
void SetItem(PyRep *key, PyRep *value)
SetItem adds or sets a database entry.
Definition: PyRep.cpp:713

Here is the call graph for this function:

Here is the caller graph for this function:

int32 ClientSession::GetCurrentInt ( const char *  name) const

Definition at line 97 of file ClientSession.cpp.

References _GetCurrent(), and PyRep::IntegerValue().

Referenced by Client::GetAccountType(), Client::GetAllianceID(), Client::GetCharacterID(), Client::GetCloneStationID(), Client::GetCorpAccountKey(), Client::GetCorpHQ(), Client::GetCorporationID(), Client::GetFleetRole(), Client::GetStationID(), Client::GetStationID2(), Client::GetUserID(), and Client::GetWarFactionID().

98 {
99  return PyRep::IntegerValue(_GetCurrent(name));
100 }
PyRep * _GetCurrent(const char *name) const
static int64 IntegerValue(PyRep *pRep)
Definition: PyRep.cpp:118

Here is the call graph for this function:

Here is the caller graph for this function:

int64 ClientSession::GetCurrentLong ( const char *  name) const

Definition at line 107 of file ClientSession.cpp.

References _GetCurrent(), and PyRep::IntegerValue().

Referenced by Client::GetAccountRole(), Client::GetClientID(), Client::GetCorpRole(), Client::GetRolesAtAll(), Client::GetRolesAtBase(), Client::GetRolesAtHQ(), and Client::GetRolesAtOther().

108 {
109  return PyRep::IntegerValue(_GetCurrent(name));
110 }
PyRep * _GetCurrent(const char *name) const
static int64 IntegerValue(PyRep *pRep)
Definition: PyRep.cpp:118

Here is the call graph for this function:

Here is the caller graph for this function:

std::string ClientSession::GetCurrentString ( const char *  name) const

Definition at line 117 of file ClientSession.cpp.

References _GetCurrent(), and PyRep::StringContent().

Referenced by Client::GetAddress(), and Client::GetLanguageID().

118 {
119  return PyRep::StringContent(_GetCurrent(name));
120 }
static std::string StringContent(PyRep *pRep)
Definition: PyRep.cpp:103
PyRep * _GetCurrent(const char *name) const

Here is the call graph for this function:

Here is the caller graph for this function:

int32 ClientSession::GetLastInt ( const char *  name) const

Definition at line 92 of file ClientSession.cpp.

References _GetLast(), and PyRep::IntegerValue().

93 {
94  return PyRep::IntegerValue(_GetLast(name));
95 }
PyRep * _GetLast(const char *name) const
static int64 IntegerValue(PyRep *pRep)
Definition: PyRep.cpp:118

Here is the call graph for this function:

int64 ClientSession::GetLastLong ( const char *  name) const

Definition at line 102 of file ClientSession.cpp.

References _GetLast(), and PyRep::IntegerValue().

103 {
104  return PyRep::IntegerValue(_GetLast(name));
105 }
PyRep * _GetLast(const char *name) const
static int64 IntegerValue(PyRep *pRep)
Definition: PyRep.cpp:118

Here is the call graph for this function:

std::string ClientSession::GetLastString ( const char *  name) const

Definition at line 112 of file ClientSession.cpp.

References _GetLast(), and PyRep::StringContent().

113 {
114  return PyRep::StringContent(_GetLast(name));
115 }
static std::string StringContent(PyRep *pRep)
Definition: PyRep.cpp:103
PyRep * _GetLast(const char *name) const

Here is the call graph for this function:

int64 ClientSession::GetSessionID ( )
inline

Definition at line 76 of file ClientSession.h.

References m_sessionID.

Referenced by Command_showsession(), and Client::SendInitialSessionStatus().

76 { return m_sessionID; }

Here is the caller graph for this function:

bool ClientSession::isDirty ( ) const
inline

Definition at line 43 of file ClientSession.h.

References mDirty.

Referenced by Client::SendSessionChange().

43 { return mDirty; }

Here is the caller graph for this function:

void ClientSession::SetInt ( const char *  name,
int32  value 
)

Definition at line 77 of file ClientSession.cpp.

References _Set().

Referenced by Client::_VerifyLogin(), Client::InitSession(), Client::SendSessionChange(), Client::SetShip(), Client::UpdateCorpSession(), Client::UpdateFleetSession(), Client::UpdateSession(), and Client::UpdateSessionInt().

78 {
79  _Set(name, new PyInt(value));
80 }
Python integer.
Definition: PyRep.h:231
void _Set(const char *name, PyRep *value)

Here is the call graph for this function:

Here is the caller graph for this function:

void ClientSession::SetLong ( const char *  name,
int64  value 
)

Definition at line 82 of file ClientSession.cpp.

References _Set().

Referenced by Client::_VerifyLogin(), Client::InitSession(), and Client::UpdateCorpSession().

83 {
84  _Set(name, new PyLong(value));
85 }
void _Set(const char *name, PyRep *value)
Python long integer.
Definition: PyRep.h:261

Here is the call graph for this function:

Here is the caller graph for this function:

void ClientSession::SetString ( const char *  name,
const char *  value 
)

Definition at line 87 of file ClientSession.cpp.

References _Set().

Referenced by Client::_VerifyLogin().

88 {
89  _Set(name, new PyString(value));
90 }
Python string.
Definition: PyRep.h:430
void _Set(const char *name, PyRep *value)

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

int64 ClientSession::m_sessionID
private

Definition at line 90 of file ClientSession.h.

Referenced by ClientSession(), GetSessionID(), and ~ClientSession().

bool ClientSession::mDirty
private

Definition at line 88 of file ClientSession.h.

Referenced by _Set(), EncodeChanges(), EncodeInitialState(), and isDirty().

PyDict* const ClientSession::mSession
protected

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