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

#include "PyPacket.h"

Collaboration diagram for PyPacket:

Public Member Functions

 PyPacket ()
 
 ~PyPacket ()
 
void Dump (LogType type, PyVisitor &dumper)
 
bool Decode (PyRep **packet)
 
PyRepEncode ()
 
PyPacketClone () const
 

Public Attributes

std::string type_string
 
MACHONETMSG_TYPE type
 
PyAddress source
 
PyAddress dest
 
uint32 userid
 
PyTuplepayload
 
PyDictnamed_payload
 
PyRepcontextKey
 

Detailed Description

Definition at line 101 of file PyPacket.h.

Constructor & Destructor Documentation

PyPacket::PyPacket ( )

Definition at line 62 of file PyPacket.cpp.

Referenced by Clone().

63 : type_string("none"),
65 userid(0),
66 payload(nullptr),
67 named_payload(nullptr),
68 contextKey(nullptr)
69 {
70 
71 }
PyTuple * payload
Definition: PyPacket.h:119
MACHONETMSG_TYPE type
Definition: PyPacket.h:115
PyRep * contextKey
Definition: PyPacket.h:121
uint32 userid
Definition: PyPacket.h:118
PyDict * named_payload
Definition: PyPacket.h:120
std::string type_string
Definition: PyPacket.h:112

Here is the caller graph for this function:

PyPacket::~PyPacket ( )

Definition at line 73 of file PyPacket.cpp.

References named_payload, payload, and PySafeDecRef.

74 {
77 }
PyTuple * payload
Definition: PyPacket.h:119
PyDict * named_payload
Definition: PyPacket.h:120
#define PySafeDecRef(op)
Definition: PyRep.h:61

Member Function Documentation

PyPacket * PyPacket::Clone ( ) const

Definition at line 79 of file PyPacket.cpp.

References PyRep::AsDict(), PyRep::AsTuple(), PyTuple::Clone(), PyDict::Clone(), dest, named_payload, payload, PyPacket(), source, type, type_string, and userid.

80 {
81  PyPacket *res = new PyPacket();
82  res->type_string = type_string;
83  res->type = type;
84  res->source = source;
85  res->dest = dest;
86  res->userid = userid;
87  res->payload = payload->Clone()->AsTuple();
88  if (named_payload == nullptr)
89  res->named_payload = nullptr;
90  else
92  return res;
93 }
PyTuple * AsTuple()
Definition: PyRep.h:138
PyPacket()
Definition: PyPacket.cpp:62
PyAddress dest
Definition: PyPacket.h:117
PyTuple * payload
Definition: PyPacket.h:119
MACHONETMSG_TYPE type
Definition: PyPacket.h:115
PyRep * Clone() const
Clones object.
Definition: PyRep.cpp:548
PyDict * AsDict()
Definition: PyRep.h:142
PyRep * Clone() const
Clones object.
Definition: PyRep.cpp:670
uint32 userid
Definition: PyPacket.h:118
PyDict * named_payload
Definition: PyPacket.h:120
PyAddress source
Definition: PyPacket.h:116
std::string type_string
Definition: PyPacket.h:112

Here is the call graph for this function:

bool PyPacket::Decode ( PyRep **  packet)

Definition at line 115 of file PyPacket.cpp.

References PyObject::arguments(), PyRep::AsChecksumedStream(), PyRep::AsObject(), PyRep::AsSubStream(), PyRep::AsTuple(), AUTHENTICATION_REQ, AUTHENTICATION_RSP, CALL_REQ, CALL_RSP, codelog, PyString::content(), PyAddress::Decode(), PySubStream::decoded(), PySubStream::DecodeData(), dest, ERRORRESPONSE, IDENTIFICATION_REQ, IDENTIFICATION_RSP, PyRep::IntegerValue(), PyRep::IsChecksumedStream(), PyRep::IsObject(), PyRep::IsSubStream(), PyRep::IsTuple(), PyTuple::items, named_payload, NOTIFICATION, payload, PING_REQ, PING_RSP, PyDecRef, PySafeDecRef, RESOLVE_REQ, RESOLVE_RSP, SESSIONCHANGENOTIFICATION, SESSIONINITIALSTATENOTIFICATION, source, PyChecksumedStream::stream(), TRANSPORTCLOSED, type, PyObject::type(), type_string, PyRep::TypeString(), and userid.

Referenced by EVEClientSession::_HandlePacket(), and tcp_callback().

116 {
117  PyRep *packet = *in_packet; //assign
118  *in_packet = nullptr; //consume
119 
122  payload = nullptr;
123  named_payload = nullptr;
124 
125  if (packet == nullptr) {
126  codelog(NET__PACKET_ERROR, "PyPacket::Decode() - packet is null.");
127  return false;
128  }
129 
130  if (packet->IsChecksumedStream()) {
131  //TODO: check cs->checksum
132  packet = packet->AsChecksumedStream()->stream();
133  }
134  //Dragon nuance... it gets wrapped again
135  if (packet->IsSubStream()) {
136  PySubStream* ss = packet->AsSubStream();
137  ss->DecodeData();
138  if (ss->decoded() == nullptr) {
139  codelog(NET__PACKET_ERROR, "PyPacket::Decode() - unable to decode initial packet substream.");
140  PyDecRef(packet);
141  return false;
142  }
143 
144  packet = ss->decoded();
145  }
146 
147  if (!packet->IsObject()) {
148  codelog(NET__PACKET_ERROR, "PyPacket::Decode() - packet body is not PyObject: %s", packet->TypeString());
149  PyDecRef(packet);
150  return false;
151  }
152 
153  type_string = packet->AsObject()->type()->content();
154  if (!packet->AsObject()->arguments()->IsTuple()) {
155  codelog(NET__PACKET_ERROR, "PyPacket::Decode() - packet body does not contain a tuple");
156  return false;
157  }
158 
159  PyTuple *tuple = packet->AsObject()->arguments()->AsTuple();
160  if (tuple == nullptr) {
161  codelog(NET__PACKET_ERROR, "PyPacket::Decode() - tuple is null.");
162  return false;
163  }
164 
165  if (tuple->items.size() != 7) {
166  codelog(NET__PACKET_ERROR, "PyPacket::Decode() - packet body does not contain a tuple of length 7 (is %u)", tuple->items.size());
167  PyDecRef(packet);
168  return false;
169  }
170 
171  if (!tuple->items[0]->IsInt()) {
172  codelog(NET__PACKET_ERROR, "PyPacket::Decode() - First main tuple element is not an integer");
173  PyDecRef(packet);
174  return false;
175  }
176 
177  switch(PyRep::IntegerValue(tuple->items[0])) {
178  case AUTHENTICATION_REQ:
179  case AUTHENTICATION_RSP:
180  case IDENTIFICATION_REQ:
181  case IDENTIFICATION_RSP:
182  case CALL_REQ:
183  case CALL_RSP:
184  case TRANSPORTCLOSED:
185  case RESOLVE_REQ:
186  case RESOLVE_RSP:
187  case NOTIFICATION:
188  case ERRORRESPONSE:
191  case PING_REQ:
192  case PING_RSP: {
194  } break;
195  default: {
196  codelog(NET__PACKET_ERROR, "PyPacket::Decode() - Unknown message type %i", PyRep::IntegerValue(tuple->items[0]));
197  PyDecRef(packet);
198  return false;
199  } break;
200  }
201 
202  //source address
203  if (!source.Decode(tuple->items[1])) {
204  //error printed in decoder
205  PyDecRef(packet);
206  return false;
207  }
208  //dest address
209  if (!dest.Decode(tuple->items[2])) {
210  //error printed in decoder
211  PyDecRef(packet);
212  return false;
213  }
214 
215  userid = PyRep::IntegerValue(tuple->items[3]);
216 
217  //payload
218  if (!tuple->items[4]->IsTuple()) {
219  codelog(NET__PACKET_ERROR, "PyPacket::Decode() - Fifth main tuple element is not a tuple");
220  PyDecRef(packet);
221  return false;
222  }
223  payload = tuple->items[4]->AsTuple();
224 
225  //options dict
226  if (tuple->items[5]->IsNone()) {
227  named_payload = nullptr;
228  } else if (tuple->items[5]->IsDict()) {
229  named_payload = tuple->items[5]->AsDict();
230  } else {
231  codelog(NET__PACKET_ERROR, "PyPacket::Decode() - Sixth main tuple element is neither dict or none.");
232  PyDecRef(packet);
233  return false;
234  }
235 
236  PyDecRef(packet);
237  return true;
238 }
Base Python wire object.
Definition: PyRep.h:66
PyTuple * AsTuple()
Definition: PyRep.h:138
bool IsChecksumedStream() const
Definition: PyRep.h:114
bool IsTuple() const
Definition: PyRep.h:108
PyAddress dest
Definition: PyPacket.h:117
PyObject * AsObject()
Definition: PyRep.h:152
MACHONETMSG_TYPE
Definition: packet_types.h:70
bool IsObject() const
Definition: PyRep.h:115
Python tuple.
Definition: PyRep.h:567
PyRep * arguments() const
Definition: PyRep.h:845
PyTuple * payload
Definition: PyPacket.h:119
PyRep * decoded() const
Definition: PyRep.h:1048
MACHONETMSG_TYPE type
Definition: PyPacket.h:115
PySubStream * AsSubStream()
Definition: PyRep.h:148
PyChecksumedStream * AsChecksumedStream()
Definition: PyRep.h:150
void DecodeData() const
Definition: PyRep.cpp:1125
#define codelog(type, fmt,...)
Definition: logsys.h:128
#define PyDecRef(op)
Definition: PyRep.h:57
bool Decode(PyRep *&object)
Definition: PyPacket.cpp:332
PyString * type() const
Definition: PyRep.h:844
uint32 userid
Definition: PyPacket.h:118
const std::string & content() const
Get the PyString content.
Definition: PyRep.h:458
PyDict * named_payload
Definition: PyPacket.h:120
#define PySafeDecRef(op)
Definition: PyRep.h:61
bool IsSubStream() const
Definition: PyRep.h:113
storage_type items
Definition: PyRep.h:628
static int64 IntegerValue(PyRep *pRep)
Definition: PyRep.cpp:118
PyAddress source
Definition: PyPacket.h:116
std::string type_string
Definition: PyPacket.h:112
const char * TypeString() const
Definition: PyRep.cpp:76
PyRep * stream() const
Definition: PyRep.h:1081

Here is the call graph for this function:

Here is the caller graph for this function:

void PyPacket::Dump ( LogType  type,
PyVisitor dumper 
)

Definition at line 95 of file PyPacket.cpp.

References _log, dest, PyAddress::Dump(), MACHONETMSG_TYPE_NAMES, named_payload, payload, source, type, type_string, userid, PyTuple::visit(), and PyDict::visit().

Referenced by Client::_SendCallReturn(), EVECollectDispatcher::Handle_Other(), Client::SendInitialSessionStatus(), Client::SendNotification(), Client::SendSessionChange(), and tcp_callback().

96 {
97  _log(ltype, "Packet:");
98  _log(ltype, " Type: %s", type_string.c_str());
99  _log(ltype, " Command: %s (%d)", MACHONETMSG_TYPE_NAMES[type], type);
100  _log(ltype, " Source:");
101  source.Dump(ltype, " ");
102  _log(ltype, " Dest:");
103  dest.Dump(ltype, " ");
104  _log(ltype, " User ID: %u", userid);
105  _log(ltype, " Payload:");
106  payload->visit( dumper );
107  if (named_payload == nullptr) {
108  _log(ltype, " Named Payload: None (null)");
109  } else {
110  _log(ltype, " Named Payload:");
111  named_payload->visit( dumper );
112  }
113 }
const char * MACHONETMSG_TYPE_NAMES[MACHONETMSG_TYPE_COUNT]
Definition: PyPacket.cpp:36
#define _log(type, fmt,...)
Definition: logsys.h:124
PyAddress dest
Definition: PyPacket.h:117
bool visit(PyVisitor &v) const
Visits object.
Definition: PyRep.cpp:675
PyTuple * payload
Definition: PyPacket.h:119
void Dump(FILE *into, const char *pfx) const
Definition: PyPacket.cpp:284
MACHONETMSG_TYPE type
Definition: PyPacket.h:115
uint32 userid
Definition: PyPacket.h:118
bool visit(PyVisitor &v) const
Visits object.
Definition: PyRep.cpp:553
PyDict * named_payload
Definition: PyPacket.h:120
PyAddress source
Definition: PyPacket.h:116
std::string type_string
Definition: PyPacket.h:112

Here is the call graph for this function:

Here is the caller graph for this function:

PyRep * PyPacket::Encode ( )

Definition at line 240 of file PyPacket.cpp.

References contextKey, dest, PyAddress::Encode(), PyTuple::items, named_payload, payload, PyStatic, source, type, type_string, and userid.

Referenced by EVEClientSession::QueuePacket().

240  {
241  PyTuple *arg_tuple = new PyTuple(7);
242  //command
243  arg_tuple->items[0] = new PyInt(type);
244  //source
245  arg_tuple->items[1] = source.Encode();
246  //dest
247  arg_tuple->items[2] = dest.Encode();
248  //userid
249  if (userid == 0)
250  arg_tuple->items[3] = PyStatic.NewNone();
251  else
252  arg_tuple->items[3] = new PyInt(userid);
253 
254  //payload
255  arg_tuple->items[4] = payload; // dont clone here. set actual rep in item, and it will be cleaned up by d'tor later
256 
257  //named arguments (OID+ or sn)
258  if (named_payload == nullptr) {
259  arg_tuple->items[5] = PyStatic.NewNone();
260  } else {
261  arg_tuple->items[5] = named_payload; // dont clone here. set actual rep in item, and it will be cleaned up by d'tor later
262  }
263 
264  // contextKey, gives the client extra information on what exactly is going on
265  // this is PyNone almost 100% of the time and seems to be used in the node<->proxy communication
266  if (contextKey == nullptr) {
267  arg_tuple->items[6] = PyStatic.NewNone();
268  } else {
269  arg_tuple->items[6] = contextKey;
270  }
271 
272  return new PyObject( type_string.c_str(), arg_tuple );
273 }
PyAddress dest
Definition: PyPacket.h:117
PyRep * Encode()
Definition: PyPacket.cpp:467
Python tuple.
Definition: PyRep.h:567
PyTuple * payload
Definition: PyPacket.h:119
MACHONETMSG_TYPE type
Definition: PyPacket.h:115
PyRep * contextKey
Definition: PyPacket.h:121
Python object.
Definition: PyRep.h:826
Python integer.
Definition: PyRep.h:231
#define PyStatic
Definition: PyRep.h:1209
uint32 userid
Definition: PyPacket.h:118
PyDict * named_payload
Definition: PyPacket.h:120
storage_type items
Definition: PyRep.h:628
PyAddress source
Definition: PyPacket.h:116
std::string type_string
Definition: PyPacket.h:112

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

PyRep* PyPacket::contextKey

Definition at line 121 of file PyPacket.h.

Referenced by Encode().


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