EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
DestinyHandler.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 http://evemu.mmoforge.org
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 */
25 
26 #include "EVECollectDisp.h"
27 #include "../common/logsys.h"
28 #include "../common/PyPacket.h"
29 #include "../common/PyRep.h"
30 #include "../common/PyVisitor.h"
31 #include "../packets/AccountPkts.h"
32 #include "../packets/General.h"
33 #include "../packets/Destiny.h"
34 #include "../common/PyDumpVisitor.h"
35 #include "../common/PyXMLGenerator.h"
36 #include "../common/CachedObjectMgr.h"
37 #include "../common/RowsetReader.h"
38 #include "../common/DestinyBinDump.h"
39 
40 //NOTE: there is also a plural version of thisDoDestinyUpdates, which
41 //carries any number of DoDestinyUpdate bodies in its top level list.
42 void EVECollectDispatcher::Notify_DoDestinyUpdate(const PyPacket *packet, EVENotificationStream **in_notify) {
43  EVENotificationStream *notify = *in_notify;
44  *in_notify = NULL;
45 
46  DoDestinyUpdateMain dumain;
47  DoDestinyUpdateMain_2 dumain2;
48  PyRepList::iterator cur, end;
49 
50  if(notify->args->items.size() == 2) {
51  //no idea why some of them have 2..
52  if(!dumain2.Decode(&notify->args)) {
53  delete notify;
54  codelog(COLLECT__ERROR, "Unable to decode destiny update main (2).");
55  return;
56  }
57  cur = dumain2.updates.begin();
58  end = dumain2.updates.end();
59  } else {
60  if(!dumain.Decode(&notify->args)) {
61  delete notify;
62  codelog(COLLECT__ERROR, "Unable to decode destiny update main.");
63  return;
64  }
65  cur = dumain.updates.begin();
66  end = dumain.updates.end();
67  }
68  delete notify;
69 
70  for(; cur != end; cur++) {
71  PyRep *r = *cur;
72  *cur = NULL;
73 
74  _log(COLLECT__DESTINY_REP, "DoDestinyUpdate Action:");
75  PyLookupDump dumper(&lookResolver, COLLECT__DESTINY_REP);
76  r->visit(&dumper);
77 
78  DoDestinyAction action;
79  if(!action.Decode(&r)) {
80  codelog(COLLECT__ERROR, "Unable to decode destiny update action");
81  return;
82  }
83 
84  //bah..
85  if(!action.update->CheckType(PyRep::Tuple)) {
86  codelog(COLLECT__ERROR, "Expected tuple in DoDestinyAction, got %s", action.update->TypeString());
87  continue;
88  }
89  PyRepTuple *t = (PyRepTuple *) action.update;
90  if(t->items.size() != 2) {
91  codelog(COLLECT__ERROR, "Expected size 2 tuple in DoDestinyAction, got %d", t->items.size());
92  continue;
93  }
94  if(!t->items[0]->CheckType(PyRep::String)) {
95  codelog(COLLECT__ERROR, "Expected string in DoDestinyAction update type, got %s", t->items[0]->TypeString());
96  continue;
97  }
98 
99  PyRepString *updtype = (PyRepString *) t->items[0];
100 
101  _log(COLLECT__NOTIFY_SUMMARY, " Destiny Update: %s", updtype->value.c_str());
102 
103  //try to dispatch it...
104  std::map<std::string, _DestinyDispatch>::const_iterator res;
105  res = m_destinyDisp.find(updtype->value);
106  if(res != m_destinyDisp.end()) {
107  _log(COLLECT__DESTINY, "Dispatching action '%s' with ID %d", updtype->value.c_str(), action.update_id);
108  _DestinyDispatch dsp = res->second;
109  (this->*dsp)(packet, &action);
110  }
111  }
112  dumain.updates.items.clear();
113 }
114 
115 void EVECollectDispatcher::Destiny_AddBalls(const PyPacket *packet, DoDestinyAction *action) {
116  DoDestiny_AddBalls upd;
117  if(!upd.Decode(&action->update)) {
118  codelog(COLLECT__ERROR, "Failed to decode arguments");
119  return;
120  }
121 
122  const byte *data = upd.destiny_binary->GetBuffer();
123  uint32 len = upd.destiny_binary->GetLength();
124 
125  _log(COLLECT__DESTINY_HEX, "AddBalls binary data:");
126  _hex(COLLECT__DESTINY_HEX, data, len);
127 
128  Destiny::DumpUpdate(COLLECT__DESTINY, data, len);
129 }
130 
131 
132 void EVECollectDispatcher::Destiny_SetState(const PyPacket *packet, DoDestinyAction *action) {
133  DoDestiny_SetState upd;
134  if(!upd.Decode(&action->update)) {
135  codelog(COLLECT__ERROR, "Failed to decode arguments");
136  return;
137  }
138 
139  const byte *data = upd.destiny_state->GetBuffer();
140  uint32 len = upd.destiny_state->GetLength();
141 
142  _log(COLLECT__DESTINY_HEX, "SetState binary data: (ego=%u)", upd.ego);
143  _hex(COLLECT__DESTINY_HEX, data, len);
144 
145  Destiny::DumpUpdate(COLLECT__DESTINY, data, len);
146 }
147 
148 
149 
150 
151 
152 
153 
154 
155 
156 
157 
Base Python wire object.
Definition: PyRep.h:66
#define _log(type, fmt,...)
Definition: logsys.h:124
#define _hex(type, data, len)
Definition: logsys.h:133
#define codelog(type, fmt,...)
Definition: logsys.h:128
unsigned __int32 uint32
Definition: eve-compat.h:50
PyLookupResolver lookResolver
void DumpUpdate(LogType into, const uint8 *data, uint32 len)
std::map< std::string, _DestinyDispatch > m_destinyDisp
storage_type items
Definition: PyRep.h:628
void(EVECollectDispatcher::* _DestinyDispatch)(const PyPacket *packet, DoDestinyAction *action)
virtual bool visit(PyVisitor &v) const =0
Visits object.