EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
PyLookupDump.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 */
25 
26 #include "eve-common.h"
27 
28 #include "python/PyRep.h"
29 #include "python/PyVisitor.h"
30 #include "python/PyLookupDump.h"
31 #include "utils/EVEUtils.h"
32 
33 static const uint32 MIN_RESOLVABLE_INT = 100;
34 
35 PyLookupDumpVisitor::PyLookupDumpVisitor( PyLookupResolver* _resolver, LogType log_type, LogType log_hex_type, const char* pfx, bool full_nested, bool full_hex )
36 : PyLogDumpVisitor( log_type, log_hex_type, pfx, full_nested, full_hex ),
37  mResolver( _resolver )
38 {
39 }
40 
42 {
43  if( !PyLogDumpVisitor::VisitInteger( rep ) )
44  return false;
45 
46  const char* look = resolver()->LookupInt( rep->value() );
47  if( look != NULL )
48  _print( "%s %s", _pfx(), look );
49 
50  return true;
51 }
52 
54 {
55  if( !PyLogDumpVisitor::VisitString( rep ) )
56  return false;
57 
58  const char* look = resolver()->LookupString( rep->content().c_str() );
59  if( look != NULL )
60  _print( "%s %s", _pfx(), look );
61 
62  return true;
63 }
64 
65 bool PyLookupResolver::LoadIntFile(const char *file) {
66  FILE *f = fopen(file, "r");
67  if(f == NULL)
68  return false;
69  char *buf = new char[10240];
70  while(fgets(buf, 10240, f)) {
71  //kill empty lines
72  if(*buf == '\n' || *buf == '\r' || *buf == '\0' || *buf == '|')
73  continue;
74  //find the first delimiter
75  char *p = buf;
76  while(*p != '|' && *p != '\0' && *p != '\n' && *p != '\r') {
77  p++;
78  }
79  if(*p == '\0' || *p == '\n' || *p == '\r')
80  continue; //didnt find it
81  *p = '\0';
82  p++;
83  if(*p == '\n' || *p == '\r' || *p == '\0')
84  continue; //skip empty values
85  //strip newline
86  char *e = p;
87  while(*e != '\0' && *e != '\n' && *e != '\r') {
88  e++;
89  }
90  *e = '\0';
91  uint32 v = strtoul(buf, NULL, 10);
92  if(v < MIN_RESOLVABLE_INT)
93  continue;
94  m_intRecords[v] = p;
95  }
96  delete[] buf;
97  fclose(f);
98  return true;
99 }
100 
101 bool PyLookupResolver::LoadStringFile(const char *file) {
102  FILE *f = fopen(file, "r");
103  if(f == NULL)
104  return false;
105  char *buf = new char[10240];
106  while(fgets(buf, 10240, f)) {
107  //kill empty lines
108  if(*buf == '\n' || *buf == '\r' || *buf == '\0' || *buf == '|')
109  continue;
110  //find the first delimiter
111  char *p = buf;
112  while(*p != '|' && *p != '\0' && *p != '\n' && *p != '\r') {
113  p++;
114  }
115  if(*p == '\0' || *p == '\n' || *p == '\r')
116  continue; //didnt find it
117  *p = '\0';
118  p++;
119  if(*p == '\n' || *p == '\r' || *p == '\0')
120  continue; //skip empty values
121  //strip newline
122  char *e = p;
123  while(*e != '\0' && *e != '\n' && *e != '\r') {
124  e++;
125  }
126  *e = '\0';
127 
128  m_strRecords[buf] = p;
129  }
130  delete[] buf;
131  fclose(f);
132  return true;
133 }
134 
135 const char *PyLookupResolver::LookupInt(int64 value) const {
136  //hackish check for win32 time looking things...
137  if(value > 127900000000000000LL && value < 130000000000000000LL) {
138  //this is not thread safe or reentrant..
140  return(m_dateBuffer.c_str());
141  }
142 
143  if(value > 0xFFFFFFFFLL || value < MIN_RESOLVABLE_INT)
144  return NULL;
145  std::map<uint32, std::string>::const_iterator res;
146  res = m_intRecords.find(uint32(value));
147  if(res == m_intRecords.end())
148  return NULL;
149  return(res->second.c_str());
150 }
151 
152 const char *PyLookupResolver::LookupString(const char *value) const {
153  if(*value == '\0')
154  return NULL;
155  std::map<std::string, std::string>::const_iterator res;
156  res = m_strRecords.find(value);
157  if(res == m_strRecords.end())
158  return NULL;
159  return(res->second.c_str());
160 }
161 
162 
163 
164 
165 
166 
167 
168 
169 
170 
171 
172 
173 
174 
175 
176 
177 
178 
179 
180 
181 
182 
183 
184 
185 
186 
187 
188 
189 
190 
191 
192 
193 
194 
195 
196 
197 
198 
199 
200 
201 
202 
bool VisitString(const PyString *rep)
Python string.
Definition: PyRep.h:430
int32 value() const
Definition: PyRep.h:247
std::map< std::string, std::string > m_strRecords
Definition: PyLookupDump.h:42
std::map< uint32, std::string > m_intRecords
Definition: PyLookupDump.h:41
bool VisitInteger(const PyInt *rep)
primitive data visitors
void _print(const char *fmt,...)
PyLookupResolver * resolver() const
Definition: PyLookupDump.h:51
static const uint32 MIN_RESOLVABLE_INT
Python integer.
Definition: PyRep.h:231
unsigned __int32 uint32
Definition: eve-compat.h:50
const char * LookupString(const char *value) const
signed __int64 int64
Definition: eve-compat.h:51
LogType
Definition: logsys.h:59
bool VisitInteger(const PyInt *rep)
primitive data visitors
const std::string & content() const
Get the PyString content.
Definition: PyRep.h:458
const char * LookupInt(int64 value) const
bool VisitString(const PyString *rep)
bool LoadIntFile(const char *file)
std::string Win32TimeToString(int64 win32t)
Definition: utils_time.cpp:59
std::string m_dateBuffer
Definition: PyLookupDump.h:43
bool LoadStringFile(const char *file)
const char * _pfx() const
Definition: PyVisitor.h:89
PyLookupDumpVisitor(PyLookupResolver *_resolver, LogType log_type, LogType log_hex_type, const char *pfx="", bool full_nested=false, bool full_hex=false)