EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
PyExceptions.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: Bloody.Rabbit
24 */
25 
26 #include "eve-common.h"
27 
29 #include "EVEVersion.h"
30 
31 
32 /* PyException */
33 PyException::PyException( PyRep* except ) : ssException( except != nullptr ? except : PyStatic.NewNone()) {}
34 PyException::PyException( const PyException& oth ) : ssException( nullptr ) { *this = oth; }
36 
38 {
42 
43  return *this;
44 }
45 
47 : PyObjectEx_Type1( new PyToken( "exceptions.GPSTransportClosed" ), _CreateArgs( reason ), _CreateKeywords( reason ) )
48 {
49 }
50 
52 : PyObjectEx_Type1( new PyToken( "exceptions.GPSTransportClosed" ), _CreateArgs( reason.c_str() ), _CreateKeywords( reason.c_str() ) )
53 {
54 
55 }
56 void GPSTransportClosed::AddKeyword( const char* name, PyRep* value )
57 {
58  GetReasonArgs()->SetItemString( name, value );
59 }
60 
62 {
63  PyRep* r = FindKeyword( "reasonArgs" );
64  assert( r );
65 
66  return r->AsDict();
67 }
68 
70 {
71  PyTuple* args = new PyTuple( 1 );
72  args->SetItem( 0, new PyString( reason ) );
73 
74  return args;
75 }
76 
78 {
79  PyDict* keywords = new PyDict;
80  //keywords->SetItemString( "origin", new PyString( "proxy" ) );
81  keywords->SetItemString( "reasonArgs", new PyDict );
82  keywords->SetItemString( "clock", new PyLong( GetFileTimeNow() ) );
83  //keywords->SetItemString( "loggedOnUserCount", );
84  keywords->SetItemString( "region", new PyString( EVEProjectRegion ) );
85  keywords->SetItemString( "reason", new PyString( reason ) );
86  keywords->SetItemString( "version", new PyFloat( EVEVersionNumber ) );
87  keywords->SetItemString( "build", new PyInt( EVEBuildVersion ) );
88  //keywords->SetItemString( "reasonCode", );
89  keywords->SetItemString( "codename", new PyString( EVEProjectCodename ) );
90  keywords->SetItemString( "machoVersion", new PyInt( MachoNetVersion ) );
91 
92  return keywords;
93 }
94 
95 
96 
97 UserError::UserError (const char* exceptionType)
98 : PyException (new PyObjectEx_Type1 (new PyToken (EXCEPTION_NAME), _CreateArgs (exceptionType), _CreateKeywords (exceptionType)))
99 {
100 }
101 
102 UserError& UserError::AddFormatValue (const char* name, PyRep* value)
103 {
104  this->AddKeyword (name, value);
105 
106  return *this;
107 }
108 
110 {
111  PyTuple* param = new PyTuple (value2 == nullptr ? 2 : 3);
112 
113  param->SetItem (0, new PyInt (type));
114  param->SetItem (1, value);
115 
116  if (value2 != nullptr)
117  param->SetItem (2, value2);
118 
119  return this->AddFormatValue (name, param);
120 }
121 
122 UserError& UserError::AddDateTime (const char* name, time_t date)
123 {
124  return this->AddParameterKeyword (name, UserError_Parameter_DateTime, new PyLong (date));
125 }
126 
127 UserError& UserError::AddDate (const char* name, time_t date)
128 {
129  return this->AddParameterKeyword (name, UserError_Parameter_Date, new PyLong (date));
130 }
131 
132 UserError& UserError::AddTime (const char* name, time_t time)
133 {
134  return this->AddParameterKeyword (name, UserError_Parameter_Time, new PyLong (time));
135 }
136 
137 UserError& UserError::AddTimeShort (const char* name, time_t time)
138 {
139  return this->AddParameterKeyword (name, UserError_Parameter_TimeShort, new PyLong (time));
140 }
141 UserError& UserError::AddA (const char* name, const char* value)
142 {
143  return this->AddParameterKeyword (name, UserError_Parameter_A, new PyString (value));
144 }
145 
146 UserError& UserError::AddThe (const char* name, const char* value)
147 {
148  return this->AddParameterKeyword (name, UserError_Parameter_The, new PyString (value));
149 }
150 
151 UserError& UserError::AddUELocalization (const char* name, const char* strKey, PyDict* args)
152 {
153  return this->AddParameterKeyword (name, UserError_Parameter_Localization, new PyString (strKey), args);
154 }
155 
156 UserError& UserError::AddList (const char* name, PyList* listEntries, const char* separator)
157 {
158  if (separator == nullptr)
159  return this->AddParameterKeyword (name, UserError_Parameter_List, listEntries);
160  else
161  return this->AddParameterKeyword (name, UserError_Parameter_List, listEntries, new PyString (separator));
162 }
163 
164 UserError& UserError::AddOwnerName (const char* name, uint32 ownerID)
165 {
166  return this->AddParameterKeyword (name, UserError_Parameter_OwnerName, new PyLong (ownerID));
167 }
168 
169 UserError& UserError::AddOwnerNick (const char* name, uint32 ownerID)
170 {
171  return this->AddParameterKeyword (name, UserError_Parameter_OwnerNick, new PyLong (ownerID));
172 }
173 
174 UserError& UserError::AddLocationName (const char* name, uint32 locationID)
175 {
176  return this->AddParameterKeyword (name, UserError_Parameter_LocationName, new PyLong (locationID));
177 }
178 
179 UserError& UserError::AddTypeName (const char* name, uint32 typeID)
180 {
181  return this->AddParameterKeyword (name, UserError_Parameter_TypeName, new PyInt (typeID));
182 }
183 
184 UserError& UserError::AddTypeDescription (const char* name, uint32 typeID)
185 {
186  return this->AddParameterKeyword (name, UserError_Parameter_TypeDescription, new PyInt (typeID));
187 }
188 
189 UserError& UserError::AddTypeList (const char* name, PyList* typeIDs)
190 {
191  return this->AddParameterKeyword (name, UserError_Parameter_TypeIDList, typeIDs);
192 }
193 
194 UserError& UserError::AddBlueprintTypeName (const char* name, uint32 bpTypeID)
195 {
196  return this->AddParameterKeyword (name, UserError_Parameter_BluePrintTypeName, new PyInt (bpTypeID));
197 }
198 
199 UserError& UserError::AddGroupName (const char* name, uint32 groupID)
200 {
201  return this->AddParameterKeyword (name, UserError_Parameter_GroupName, new PyInt (groupID));
202 }
203 
204 UserError& UserError::AddGroupDescription (const char* name, uint32 groupID)
205 {
206  return this->AddParameterKeyword (name, UserError_Parameter_GroupDescription, new PyInt (groupID));
207 }
208 
209 UserError& UserError::AddCategoryName (const char* name, uint32 categoryID)
210 {
211  return this->AddParameterKeyword (name, UserError_Parameter_CategoryName, new PyInt (categoryID));
212 }
213 
214 UserError& UserError::AddCategoryDescription (const char* name, uint32 categoryID)
215 {
216  return this->AddParameterKeyword (name, UserError_Parameter_CategoryDescription, new PyInt (categoryID));
217 }
218 
219 UserError& UserError::AddAmount (const char* name, int quantity)
220 {
221  return this->AddParameterKeyword (name, UserError_Parameter_Amount, new PyInt (quantity));
222 }
223 
224 UserError& UserError::AddAmount (const char* name, uint quantity)
225 {
226  return this->AddParameterKeyword (name, UserError_Parameter_Amount, new PyInt (quantity));
227 }
228 
229 UserError& UserError::AddAmount (const char* name, double quantity)
230 {
231  return this->AddParameterKeyword (name, UserError_Parameter_Amount, new PyFloat (quantity));
232 }
233 
234 UserError& UserError::AddISK (const char* name, double isk)
235 {
236  return this->AddParameterKeyword (name, UserError_Parameter_ISK, new PyFloat (isk));
237 }
238 
239 UserError& UserError::AddAUR (const char* name, double aur)
240 {
241  return this->AddParameterKeyword (name, UserError_Parameter_AUR, new PyFloat (aur));
242 }
243 
244 UserError& UserError::AddDistance (const char* name, double distance)
245 {
246  return this->AddParameterKeyword (name, UserError_Parameter_Distance, new PyFloat (distance));
247 }
248 
249 UserError& UserError::AddTypeIDAndQuantity (const char* name, uint32 typeID, int quantity)
250 {
251  return this->AddParameterKeyword (name, UserError_Parameter_TypeIDAndQuantity, new PyInt (typeID), new PyInt (quantity));
252 }
253 
254 void UserError::AddKeyword( const char* name, PyRep* value )
255 {
256  // We need 2 refs ... the first one is given to us,
257  // but we must create the second one ...
258  PyIncRef( value );
259 
260  _GetTupleKeywords()->SetItemString( name, value );
261  _GetDictKeywords()->SetItemString( name, value );
262 }
263 
265 {
266  return this->m_args->GetItem (1)->AsDict();
267 }
268 
270 {
271  return this->m_keywords->GetItemString ("dict")->AsDict ();
272 }
273 
274 PyTuple* UserError::_CreateArgs( const char* msg )
275 {
276  this->m_args = new PyTuple (2);
277 
278  this->m_args->SetItem (0, new PyString (msg));
279  this->m_args->SetItem (1, new PyDict);
280 
281  return this->m_args;
282 }
283 
285 {
286  this->m_keywords = new PyDict;
287 
288  this->m_keywords->SetItemString ("msg", new PyString (msg));
289  this->m_keywords->SetItemString ("dict", new PyDict);
290 
291  return this->m_keywords;
292 }
293 
294 CustomError::CustomError(const char *fmt, ...)
295 : UserError (EXCEPTION_NAME)
296 {
297  va_list va;
298  va_start (va, fmt);
299 
300  char* str = nullptr;
301  vasprintf (&str, fmt, va);
302  assert (str);
303 
304  va_end (va);
305 
306  this->AddFormatValue ("error", new PyString (str));
307 
308  SafeFree (str);
309 }
310 
311 const char* CustomError::EXCEPTION_NAME = "CustomError";
312 const char* UserError::EXCEPTION_NAME = "ccp_exceptions.UserError";
Base Python wire object.
Definition: PyRep.h:66
UserError & AddTimeShort(const char *name, time_t time)
Shorthand method for adding the given time as a time string in the message (without minutes) ...
PyRep * GetItem(size_t index) const
Returns Python object.
Definition: PyRep.h:602
Python string.
Definition: PyRep.h:430
static const char *const EVEProjectCodename
Definition: EVEVersion.h:37
PyRep * GetItemString(const char *key) const
Obtains database entry based on given key string.
Definition: PyRep.cpp:702
#define PySafeIncRef(op)
Definition: PyRep.h:60
Python's dictionary.
Definition: PyRep.h:719
UserError & AddThe(const char *name, const char *value)
Shorthand method for adding "the" before the beginning of the value.
UserError & AddCategoryName(const char *name, uint32 categoryID)
Shorthand method for adding a category's name.
UserError & AddTypeIDAndQuantity(const char *name, uint32 typeID, int quantity)
Shorthand method for adding type ID and quantity.
UserError & AddTypeName(const char *name, uint32 typeID)
Shorthand method for adding a type's name.
Python floating point number.
Definition: PyRep.h:292
UserError(const char *exceptionType)
UserError & AddGroupDescription(const char *name, uint32 groupID)
Shorthand method for adding a group's description.
UserError & AddFormatValue(const char *name, PyRep *value)
Fluent version of the protected AddKeyword, allows for adding a keyword to the exception.
UserError & AddDistance(const char *name, double distance)
Shorthand method for adding distance in a easy to read unit.
Python tuple.
Definition: PyRep.h:567
static PyTuple * _CreateArgs(const char *reason)
PyTuple * _CreateArgs(const char *msg)
UserError & AddOwnerNick(const char *name, uint32 ownerID)
Shorthand method for adding an owner's nick (first name without surname)
static const uint16 MachoNetVersion
Definition: EVEVersion.h:33
PyDict * _GetDictKeywords() const
void AddKeyword(const char *name, PyRep *value)
Adds keyword to exception.
UserError & AddISK(const char *name, double isk)
Shorthand method for adding an ISK amount.
CustomError(const char *message,...)
* args
int vasprintf(char **strp, const char *fmt, va_list ap)
Definition: eve-compat.cpp:70
UserError & AddTime(const char *name, time_t time)
Shorthand method for adding the given date time as a time string in the message.
UserError & AddGroupName(const char *name, uint32 groupID)
Shorthand method for adding a group's name.
void SafeFree(T *&p)
Frees and nullifies an array pointer.
Definition: SafeMem.h:111
UserError & AddParameterKeyword(const char *name, UserError_ParameterIDs type, PyRep *value, PyRep *value2=nullptr)
Adds a keyword to exception.
UserError & AddAmount(const char *name, int quantity)
Shorthand method for adding a quantity value.
Base class for exceptions that can be converted to python objects.
Definition: PyExceptions.h:39
GPSTransportClosed(const char *reason)
static const double EVEVersionNumber
Definition: EVEVersion.h:32
UserError_ParameterIDs
Enumeration that indicates what parameters can be sent along with an UserError.
Definition: PyExceptions.h:85
PyDict * GetReasonArgs() const
static const int32 EVEBuildVersion
Definition: EVEVersion.h:34
void SetItem(size_t index, PyRep *object)
Stores Python object.
Definition: PyRep.h:610
UserError & AddTypeDescription(const char *name, uint32 typeID)
Shorthand method for adding a type's description.
UserError & AddOwnerName(const char *name, uint32 ownerID)
Shorthand method for adding an owner's name.
Python integer.
Definition: PyRep.h:231
PyException(PyRep *except)
PyDict * AsDict()
Definition: PyRep.h:142
static PyDict * _CreateKeywords(const char *reason)
UserError & AddAUR(const char *name, double aur)
Shorthand method for adding an AUR amount.
static const char * EXCEPTION_NAME
Definition: PyExceptions.h:463
UserError & AddUELocalization(const char *name, const char *strKey, PyDict *args=nullptr)
Shorthand method for adding a string in the client's translations.
PyTuple * m_args
Definition: PyExceptions.h:443
UserError & AddA(const char *name, const char *value)
Shorthand method for adding "a" before the beginning of the value.
#define PyStatic
Definition: PyRep.h:1209
PyRep * FindKeyword(const char *keyword) const
Definition: PyRep.cpp:853
PyDict * _GetTupleKeywords() const
Python object "ccp_exceptions.UserError".
Definition: PyExceptions.h:121
unsigned __int32 uint32
Definition: eve-compat.h:50
#define PyIncRef(op)
Definition: PyRep.h:56
UserError & AddDateTime(const char *name, time_t date)
Shorthand method for adding the given date-time as a datetime string in the message.
UserError & AddCategoryDescription(const char *name, uint32 categoryID)
Shorthand method for adding a category's description.
UserError & AddList(const char *name, PyList *listEntries, const char *separator=nullptr)
Shorthand method for adding a list of format parameters.
Python token (eg. class name).
Definition: PyRep.h:522
double GetFileTimeNow()
Definition: utils_time.cpp:84
Wrapper class for PyObjectEx of type 1.
Definition: PyRep.h:911
PyDict * _CreateKeywords(const char *msg)
PyDict * m_keywords
Definition: PyExceptions.h:444
PyRep * ssException
Definition: PyExceptions.h:48
UserError & AddTypeList(const char *name, PyList *typeIDs)
Shorthand method for adding a list of types' names.
#define PySafeDecRef(op)
Definition: PyRep.h:61
void AddKeyword(const char *name, PyRep *value)
Adds keyword to exception.
UserError & AddBlueprintTypeName(const char *name, uint32 bpTypeID)
Shorthand method for adding a blueprint's type name.
static const char *const EVEProjectRegion
Definition: EVEVersion.h:35
PyException & operator=(const PyException &oth)
Python list.
Definition: PyRep.h:639
static const char * EXCEPTION_NAME
Definition: PyExceptions.h:413
void SetItemString(const char *key, PyRep *value)
SetItemString adds or sets a database entry.
Definition: PyRep.h:812
Python long integer.
Definition: PyRep.h:261
UserError & AddLocationName(const char *name, uint32 locationID)
Shorthand method for adding a location's name.
UserError & AddDate(const char *name, time_t date)
Shorthand method for adding the given date time as a date string in the message.