EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
CachedObjectMgr.h
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 */
25 
26 /*
27  * this code has devolved into quite a mess, but it works for now...
28  *
29 */
30 
31 #ifndef __CACHEDOBJECTMGR_H_INCL__
32 #define __CACHEDOBJECTMGR_H_INCL__
33 
34 #include "python/PyRep.h"
35 #include "python/PyVisitor.h"
36 
37 class PyRep;
38 class PySubStream;
39 class PyDict;
40 class PyCachedObject;
41 class PyCachedCall;
42 class PyObject;
43 class PyBuffer;
45 
46 #pragma pack(1)
48 {
53 };
54 #pragma pack()
55 
56 extern const uint32 CacheFileMagic;
57 
59 public:
61 
62  //internal utility function to keep maps simpler.
63  static std::string OIDToString(const PyRep *objectID);
64 
65  bool HaveCached(const std::string &objectID) const;
66  bool HaveCached(const PyRep *objectID) const;
67 
68  bool IsCacheUpToDate(const PyRep *objectID, uint32 version, int64 timestamp);
69 
70  void InvalidateCache(const PyRep *objectID);
71 
72  //bool IsObjectFresh(const std::string &objectID, uint32 version, int64 timestamp);
73  void UpdateCacheFromSS(const std::string &objectID, PySubStream **in_cached_data);
74  void UpdateCache(const std::string &objectID, PyRep **in_cached_data);
75  void UpdateCache(const PyRep *objectID, PyRep **in_cached_data);
76 
77  PyObject *MakeCacheHint(const PyRep *objectID);
78  PyObject *MakeCacheHint(const std::string &objectID);
79 
80  PyObject *GetCachedObject(const PyRep *objectID);
81  PyObject *GetCachedObject(const std::string &objectID);
82 
83 //OLD CCP FILE BASED ACCESS:
84  //PyRep *_MakeCacheHint(const char *oname);
85  //void AddCacheHint(const char *oname, const char *key, PyDict *into);
86 
87  PySubStream* LoadCachedFile(const char *obj_name);
88  PySubStream* LoadCachedFile(PyRep *key, const char *oname);
89  PySubStream* LoadCachedFile(const char *filename, const char *oname);
90  PyCachedObjectDecoder *LoadCachedObject(const char *filename, const char *oname);
91  PyCachedCall *LoadCachedCall(const char *filename, const char *oname);
92 
93  //Cache file storage routines:
94  bool LoadCachedFromFile(const std::string &cacheDir, const std::string &objectID);
95  bool LoadCachedFromFile(const std::string &cacheDir, const PyRep *objectID);
96  bool SaveCachedToFile(const std::string &cacheDir, const std::string &objectID) const;
97  bool SaveCachedToFile(const std::string &cacheDir, const PyRep *objectID) const;
98 
99 protected:
100  //static bool AddCachedFileContents(const char *filename, const char *oname, PySubStream *into);
101  void GetCacheFileName(PyRep *key, std::string &into);
102 
103  void _UpdateCache(const PyRep *objectID, PyBuffer **buffer);
104 
105  class CacheRecord {
106  public:
107  CacheRecord();
108  ~CacheRecord();
109 
110  PyObject *EncodeHint() const;
111 
112  PyRep *objectID; //we own this
115  PyBuffer *cache; //we own this.
116  };
117  typedef std::map<std::string, CacheRecord *> CachedObjMap;
118  typedef CachedObjMap::iterator CachedObjMapItr;
119  typedef CachedObjMap::const_iterator CachedObjMapConstItr;
120 
121 
122  CachedObjMap m_cachedObjects; //we own these pointers
123 };
124 
126 {
127 public:
128  PyCachedObject();
129  ~PyCachedObject();
130 
131  void Dump(FILE *into, const char *pfx, bool contents_too = false);
132 // bool Decode(PySubStream **ss); //consumes substream
133  PyObject *Encode();
134  PyCachedObject *Clone() const;
135 
136  //object version tuple:
138  /*0*/ uint32 version; //might be swapped with nodeID
139 
140  /*1*/ //unknown None
142  /*3*/bool shared; //not sure
143 
144 // PyRep *raw_cache;
145  /*4*/PyRep *cache;
146 
147  /*5*/bool compressed; //guess
148  /*6*/PyRep *objectID; //generally a string or tuple.
149 };
150 
152 {
153 public:
156 
157  void Dump(FILE *into, const char *pfx, bool contents_too = false);
158  bool Decode(PySubStream **ss); //consumes substream
159  PyObject *EncodeHint();
160 
161  //object version tuple:
163  /*0*/int32 version; //might be swapped with nodeID
164 
165  /*1*/ //unknown None
167  /*3*/bool shared; //not sure
168 
170 
171  /*5*/bool compressed; //guess
172  /*6*/PyRep *objectID; //generally a string or tuple.
173 };
174 
175 
177 {
178 public:
179  PyCachedCall();
180  ~PyCachedCall();
181 
182  void Dump(FILE *into, const char *pfx, bool contents_too = false);
183  bool Decode(PySubStream **ss); //consumes substream
184  //PyRep *Encode();
185  //PyRep *EncodeHint();
186  PyCachedCall *Clone() const;
187 
188  //rret:
189  //objectCaching.CachedMethodCallResult object
190  //with ( dict(versionCheck, sessionInfo),
191  // substream (unknown right now)
192  // tuple(version)
193  // )
194  //used:
195  //win32 time
196  //lret
197  //the call result directly
199  //version:
200  //copy of the version tuple in rret
201 };
202 
203 //run through the rep, concatenating all the strings together and noting if
204 //there are a no non-string types in the rep (lists and tuples are OK)
206 : public PyVisitor
207 {
208 public:
209  std::string result;
210 
211  bool VisitInteger( const PyInt* rep )
212  {
213  if( !result.empty() )
214  result += ".";
215 
216  std::stringstream ss;
217  ss << rep->value();
218  result += ss.str();
219 
220  return true;
221  }
222  bool VisitLong( const PyLong* rep ) { return false; }
223  bool VisitReal( const PyFloat* rep ) { return false; }
224  bool VisitBoolean( const PyBool* rep ) { return false; }
225  bool VisitNone( const PyNone* rep ) { return false; }
226  bool VisitBuffer( const PyBuffer* rep ) { return false; }
227  bool VisitString( const PyString* rep )
228  {
229  if( !result.empty() )
230  result += ".";
231  result += rep->content();
232 
233  return true;
234  }
235  bool VisitWString( const PyWString* rep ) { return false; }
236  bool VisitToken( const PyToken* rep ) { return false; }
237 
238  bool VisitDict( const PyDict* rep ) { return false; }
239 
240  bool VisitObject( const PyObject* rep ) { return false; }
241  bool VisitObjectEx( const PyObjectEx* rep ) { return false; }
242 
243  bool VisitPackedRow( const PyPackedRow* rep ) { return false; }
244 
245  bool VisitSubStruct( const PySubStruct* rep ) { return false; }
246  bool VisitSubStream( const PySubStream* rep ) { return false; }
247  bool VisitChecksumedStream( const PyChecksumedStream* rep ) { return false; }
248 };
249 
250 #endif
bool IsCacheUpToDate(const PyRep *objectID, uint32 version, int64 timestamp)
CachedObjMap::const_iterator CachedObjMapConstItr
Base Python wire object.
Definition: PyRep.h:66
PyCachedCall * LoadCachedCall(const char *filename, const char *oname)
std::map< std::string, CacheRecord * > CachedObjMap
void GetCacheFileName(PyRep *key, std::string &into)
bool VisitObjectEx(const PyObjectEx *rep)
bool HaveCached(const std::string &objectID) const
Python string.
Definition: PyRep.h:430
int32 value() const
Definition: PyRep.h:247
Python's dictionary.
Definition: PyRep.h:719
bool VisitWString(const PyWString *rep)
PyCachedObject * Clone() const
PyObject * MakeCacheHint(const PyRep *objectID)
Python floating point number.
Definition: PyRep.h:292
Python wide string.
Definition: PyRep.h:475
bool VisitBoolean(const PyBool *rep)
bool VisitObject(const PyObject *rep)
Object type visitor.
void UpdateCache(const std::string &objectID, PyRep **in_cached_data)
bool VisitReal(const PyFloat *rep)
signed __int32 int32
Definition: eve-compat.h:49
PyCachedCall * Clone() const
Python boolean.
Definition: PyRep.h:323
Python extended object.
Definition: PyRep.h:861
bool VisitToken(const PyToken *rep)
bool VisitSubStream(const PySubStream *rep)
bool VisitSubStruct(const PySubStruct *rep)
wrapper types Visitor
Python object.
Definition: PyRep.h:826
PySubStream * LoadCachedFile(const char *obj_name)
void Dump(FILE *into, const char *pfx, bool contents_too=false)
Python's "none".
Definition: PyRep.h:352
PyObject * Encode()
bool SaveCachedToFile(const std::string &cacheDir, const std::string &objectID) const
void UpdateCacheFromSS(const std::string &objectID, PySubStream **in_cached_data)
Python integer.
Definition: PyRep.h:231
CachedObjMap m_cachedObjects
CachedObjMap::iterator CachedObjMapItr
void InvalidateCache(const PyRep *objectID)
bool VisitNone(const PyNone *rep)
void Dump(FILE *into, const char *pfx, bool contents_too=false)
bool VisitString(const PyString *rep)
bool VisitDict(const PyDict *rep)
unsigned __int32 uint32
Definition: eve-compat.h:50
Python token (eg. class name).
Definition: PyRep.h:522
static std::string OIDToString(const PyRep *objectID)
signed __int64 int64
Definition: eve-compat.h:51
bool VisitLong(const PyLong *rep)
void _UpdateCache(const PyRep *objectID, PyBuffer **buffer)
bool VisitBuffer(const PyBuffer *rep)
PyObject * EncodeHint() const
bool VisitPackedRow(const PyPackedRow *rep)
PackedRow type visitor.
const std::string & content() const
Get the PyString content.
Definition: PyRep.h:458
void Dump(FILE *into, const char *pfx, bool contents_too=false)
bool Decode(PySubStream **ss)
PyObject * GetCachedObject(const PyRep *objectID)
Python buffer.
Definition: PyRep.h:382
Packed row.
Definition: PyRep.h:961
PyCachedObjectDecoder * LoadCachedObject(const char *filename, const char *oname)
bool VisitInteger(const PyInt *rep)
primitive data visitors
typeID Spawn an NPC with the specified type text Search for items matching the specified query() type() key(value)-Send an OnRemoteMessage" ) COMMAND( setbpattr
const uint32 CacheFileMagic
bool LoadCachedFromFile(const std::string &cacheDir, const std::string &objectID)
bool VisitChecksumedStream(const PyChecksumedStream *rep)
bool Decode(PySubStream **ss)
Python long integer.
Definition: PyRep.h:261