EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
EVEPktDispatch.cpp
Go to the documentation of this file.
1 /*
2  ------------------------------------------------------------------------------------
3  LICENSE:
4  ------------------------------------------------------------------------------------
5  This file is part of EVEmu: EVE Online Server Emulator
6  Copyright 2006 - 2021 The EVEmu Team
7  For the latest information visit https://evemu.dev
8  ------------------------------------------------------------------------------------
9  This program is free software; you can redistribute it and/or modify it under
10  the terms of the GNU Lesser General Public License as published by the Free Software
11  Foundation; either version 2 of the License, or (at your option) any later
12  version.
13 
14  This program is distributed in the hope that it will be useful, but WITHOUT
15  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General Public License along with
19  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
20  Place - Suite 330, Boston, MA 02111-1307, USA, or go to
21  http://www.gnu.org/copyleft/lesser.txt.
22  ------------------------------------------------------------------------------------
23  Author: Zhur
24  Rewrite: Allan
25 */
26 
27 #include "eve-common.h"
28 
29 #include "network/EVEPktDispatch.h"
30 #include "packets/AccountPkts.h"
31 #include "packets/General.h"
32 #include "python/PyPacket.h"
33 #include "python/PyVisitor.h"
34 #include "python/PyRep.h"
35 
37 {
38  switch(packet->type) {
39  case AUTHENTICATION_REQ: {
40  //check the string part, just for good measure
41  if (packet->type_string != "macho.AuthenticationReq") {
42  sLog.Error("EVEPacketDispatcher","Received AUTHENTICATION_RSP with invalid type string '%s'", packet->type_string.c_str());
43  return false;
44  }
45 
46  AuthenticationReq req;
47  if (!req.Decode(packet->payload)) {
48  sLog.Error("EVEPacketDispatcher","Failed to decode AuthenticationReq");
49  return false;
50  }
51 
52  return Handle_AuthenticationReq(packet, req);
53  }
54  case AUTHENTICATION_RSP: {
55  //check the string part, just for good measure
56  if (packet->type_string != "macho.AuthenticationRsp") {
57  sLog.Error("EVEPacketDispatcher","Received AUTHENTICATION_RSP with invalid type string '%s'", packet->type_string.c_str());
58  return false;
59  }
60 
61  AuthenticationRsp rsp;
62  if (!rsp.Decode(packet->payload)) {
63  sLog.Error("EVEPacketDispatcher","Failed to decode AuthenticationRsp");
64  return false;
65  }
66 
67  return Handle_AuthenticationRsp(packet, rsp);
68  }
69  case CALL_REQ: {
70  //check the string part, just for good measure
71  if (packet->type_string != "macho.CallReq") {
72  sLog.Error("EVEPacketDispatcher","Received CALL_REQ with invalid type string '%s'", packet->type_string.c_str());
73  return false;
74  }
75 
76  PyCallStream call;
77  if (!call.Decode(packet->type_string, packet->payload)) {
78  sLog.Error("EVEPacketDispatcher","Failed to convert packet into a call stream");
79  return false;
80  }
81 
82  return Handle_CallReq(packet, call);
83  }
84  case CALL_RSP: {
85  //check the string part, just for good measure
86  if (packet->type_string != "macho.CallRsp") {
87  sLog.Error("EVEPacketDispatcher","Received CALL_RSP with invalid type string '%s'", packet->type_string.c_str());
88  return false;
89  }
90 
91  //TODO: decode substream in tuple
92 
93  return Handle_CallRsp(packet);
94  }
95  case NOTIFICATION: {
96  //check the string part, just for good measure
97  if (packet->type_string != "macho.Notification") {
98  sLog.Error("EVEPacketDispatcher","Received NOTIFICATION with invalid type string '%s'", packet->type_string.c_str());
99  return false;
100  }
101 
102  return Handle_Notify(packet);
103  }
104  case ERRORRESPONSE: {
105  //check the string part, just for good measure
106  if (packet->type_string != "macho.ErrorResponse") {
107  sLog.Error("EVEPacketDispatcher","Received ERRORRESPONSE with invalid type string '%s'", packet->type_string.c_str());
108  return false;
109  }
110 
111  ErrorResponse error;
112  if (!error.Decode(packet->payload)) {
113  sLog.Error("EVEPacketDispatcher","Failed to decode Error Response");
114  return false;
115  }
116 
117  return Handle_ErrorResponse(packet, error);
118  }
120  //check the string part, just for good measure
121  if (packet->type_string != "macho.SessionChangeNotification") {
122  sLog.Error("EVEPacketDispatcher","Received SESSIONCHANGENOTIFICATION with invalid type string '%s'", packet->type_string.c_str());
123  return false;
124  }
125 
126  SessionChangeNotification sessionChange;
127  if (!sessionChange.Decode(packet->payload)) {
128  sLog.Error("EVEPacketDispatcher","Failed to decode session change notification");
129  return false;
130  }
131 
132  return Handle_SessionChange(packet, sessionChange);
133  }
134  case PING_REQ: {
135  //check the string part, just for good measure
136  if (packet->type_string != "macho.PingReq") {
137  sLog.Error("EVEPacketDispatcher","Received PING_REQ with invalid type string '%s'", packet->type_string.c_str());
138  return false;
139  }
140 
141  return Handle_PingReq(packet);
142  }
143  case PING_RSP: {
144  //check the string part, just for good measure
145  if (packet->type_string != "macho.PingRsp") {
146  sLog.Error("EVEPacketDispatcher","Received PING_RSP with invalid type string '%s'", packet->type_string.c_str());
147  return false;
148  }
149 
150  return Handle_PingRsp(packet);
151  }
152  default:
153  return Handle_Other(packet);
154  }
155 }
156 
157 /* default handlers do nothing but print */
158 bool EVEPacketDispatcher::Handle_AuthenticationReq(PyPacket* packet, AuthenticationReq& req)
159 {
160  sLog.Error("EVEPacketDispatcher","Unhandled Authentication Request");
161  return false;
162 }
163 bool EVEPacketDispatcher::Handle_AuthenticationRsp(PyPacket* packet, AuthenticationRsp& rsp)
164 {
165  sLog.Error("EVEPacketDispatcher","Unhandled Authentication Response");
166  return false;
167 }
168 
170 {
171  sLog.Error("EVEPacketDispatcher","Unhandled Call Request");
172  return false;
173 }
175 {
176  sLog.Error("EVEPacketDispatcher","Unhandled Call Response");
177  return false;
178 }
179 bool EVEPacketDispatcher::Handle_ErrorResponse(PyPacket* packet, ErrorResponse& body)
180 {
181  sLog.Error("EVEPacketDispatcher","Unhandled Error Response");
182  return false;
183 }
184 
186 {
187  sLog.Error("EVEPacketDispatcher","Unhandled Notification");
188  return false;
189 }
190 bool EVEPacketDispatcher::Handle_SessionChange(PyPacket* packet, SessionChangeNotification& notify)
191 {
192  sLog.Error("EVEPacketDispatcher","Unhandled SessionChange");
193  return false;
194 }
195 
197 {
198  sLog.Error("EVEPacketDispatcher","Unhandled Ping Request.");
199  return false;
200 }
202 {
203  sLog.Error("EVEPacketDispatcher","Unhandled Ping Response.");
204  return false;
205 }
206 
208 {
209  sLog.Error("EVEPacketDispatcher","Unhandled Packet of type %s (%i)", MACHONETMSG_TYPE_NAMES[ packet->type ], (int)packet->type);
210  return false;
211 }
virtual bool Handle_AuthenticationReq(PyPacket *packet, AuthenticationReq &req)
virtual bool Handle_SessionChange(PyPacket *packet, SessionChangeNotification &sessionChange)
virtual bool Handle_ErrorResponse(PyPacket *packet, ErrorResponse &error)
PyTuple * payload
Definition: PyPacket.h:119
#define sLog
Evaluates to a NewLog instance.
Definition: LogNew.h:250
MACHONETMSG_TYPE type
Definition: PyPacket.h:115
virtual bool Handle_AuthenticationRsp(PyPacket *packet, AuthenticationRsp &rsp)
const char * MACHONETMSG_TYPE_NAMES[MACHONETMSG_TYPE_COUNT]
Definition: PyPacket.cpp:36
virtual bool Handle_PingRsp(PyPacket *packet)
virtual bool Handle_Other(PyPacket *packet)
virtual bool Handle_CallRsp(PyPacket *packet)
bool Decode(const std::string &type, PyTuple *&payload)
Definition: PyPacket.cpp:598
virtual bool Handle_PingReq(PyPacket *packet)
virtual bool Handle_Notify(PyPacket *packet)
bool DispatchPacket(PyPacket *packet)
std::string type_string
Definition: PyPacket.h:112
virtual bool Handle_CallReq(PyPacket *packet, PyCallStream &req)