EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
AccountDB Class Reference

#include "AccountDB.h"

Public Member Functions

PyRepGetWalletDivisionsInfo (uint32 corpID)
 
PyRepGetJournal (uint32 ownerID, int8 entryTypeID, uint16 accountKey, int64 fromDate, bool reverse=false)
 

Static Public Member Functions

static double OfflineFundXfer (uint32 charID, double amount, uint8 type=Account::CreditType::ISK)
 
static double GetCorpBalance (uint32 corpID, uint16 accountKey)
 
static void UpdateCorpBalance (uint32 corpID, uint16 accountKey, double amount)
 
static void AddJournalEntry (uint32 ownerID, int8 entryTypeID, uint32 ownerFromID, uint32 ownerToID, int8 currency, uint16 accountKey, double amount, double newBalance, std::string description, uint32 referenceID=0)
 

Detailed Description

Definition at line 32 of file AccountDB.h.

Member Function Documentation

void AccountDB::AddJournalEntry ( uint32  ownerID,
int8  entryTypeID,
uint32  ownerFromID,
uint32  ownerToID,
int8  currency,
uint16  accountKey,
double  amount,
double  newBalance,
std::string  description,
uint32  referenceID = 0 
)
static

Definition at line 166 of file AccountDB.cpp.

References DBerror::c_str(), Account::KeyType::Cash, GetFileTimeNow(), IsCorp, sDatabase, and Journal::EntryType::SkipLog.

Referenced by AccountService::HandleCorpTransaction(), and AccountService::TranserFunds().

168 {
169  if (entryTypeID == Journal::EntryType::SkipLog)
170  return;
171  // account key 0 is usually sent by the client, it should be the main cash account
172  if (accountKey == 0)
173  accountKey = Account::KeyType::Cash;
174 
175  std::string eDesc;
176  sDatabase.DoEscapeString(eDesc, description);
177 
178  std::string tblName = "jnlCharacters";
179  if (IsCorp(ownerID))
180  tblName = "jnlCorporations";
181 
182  // dont care if this fails...
183  DBerror err;
184  sDatabase.RunQuery(err,
185  "INSERT INTO %s (ownerID, entryTypeID, accountKey, transactionDate, ownerID1, ownerID2, referenceID, currency, amount, balance, description)"
186  " VALUES (%u,%u,%u,%f,%u,%u,%u,%i,%.2f,%.2f,'%s')",
187  tblName.c_str(), ownerID, entryTypeID, accountKey, GetFileTimeNow(), ownerFromID, ownerToID, referenceID, currency, amount, newBalance, eDesc.c_str());
188 }
#define sDatabase
Definition: dbcore.h:199
const char * c_str() const
Definition: dbcore.h:48
#define IsCorp(itemID)
Definition: EVE_Defines.h:234
double GetFileTimeNow()
Definition: utils_time.cpp:84
Definition: dbcore.h:39

Here is the call graph for this function:

Here is the caller graph for this function:

double AccountDB::GetCorpBalance ( uint32  corpID,
uint16  accountKey 
)
static

Definition at line 69 of file AccountDB.cpp.

References DBerror::c_str(), Account::KeyType::Cash, Account::KeyType::Cash2, Account::KeyType::Cash3, Account::KeyType::Cash4, Account::KeyType::Cash5, Account::KeyType::Cash6, Account::KeyType::Cash7, codelog, DBQueryResult::error, DBResultRow::GetDouble(), DBQueryResult::GetRow(), and sDatabase.

Referenced by AccountService::HandleCorpTransaction().

70 {
71  std::string acctKey = "";
72  switch (accountKey) {
73  case Account::KeyType::Cash: acctKey = "balance1"; break;
74  case Account::KeyType::Cash2: acctKey = "balance2"; break;
75  case Account::KeyType::Cash3: acctKey = "balance3"; break;
76  case Account::KeyType::Cash4: acctKey = "balance4"; break;
77  case Account::KeyType::Cash5: acctKey = "balance5"; break;
78  case Account::KeyType::Cash6: acctKey = "balance6"; break;
79  case Account::KeyType::Cash7: acctKey = "balance7"; break;
80  }
81  DBQueryResult res;
82  if (!sDatabase.RunQuery(res, "SELECT %s FROM crpWalletDivisons WHERE corporationID = %u ", acctKey.c_str(), corpID)) {
83  codelog(DATABASE__ERROR, "Error in query: %s", res.error.c_str());
84  return 0;
85  }
86  DBResultRow row;
87  if (!res.GetRow(row))
88  return 0;
89  return row.GetDouble(0);
90 }
#define sDatabase
Definition: dbcore.h:199
double GetDouble(uint32 index) const
Definition: dbcore.cpp:693
bool GetRow(DBResultRow &into)
Definition: dbcore.cpp:552
const char * c_str() const
Definition: dbcore.h:48
#define codelog(type, fmt,...)
Definition: logsys.h:128
DBerror error
Definition: dbcore.h:69

Here is the call graph for this function:

Here is the caller graph for this function:

PyRep * AccountDB::GetJournal ( uint32  ownerID,
int8  entryTypeID,
uint16  accountKey,
int64  fromDate,
bool  reverse = false 
)

Definition at line 135 of file AccountDB.cpp.

References DBerror::c_str(), codelog, DBResultToCRowset(), DBQueryResult::error, IsCorp, and sDatabase.

136 {
137  std::string tblName = "jnlCharacters";
138  if (IsCorp(ownerID))
139  tblName = "jnlCorporations";
140 
141  std::string entryType = "";
142  if (entryTypeID) {
143  entryType = " AND entryTypeID = ";
144  entryType += std::to_string(entryTypeID);
145  }
146 
147  std::string sort = "";
148  if (reverse)
149  sort = "";
150 
151  DBQueryResult res;
152  if (!sDatabase.RunQuery(res,
153  "SELECT transactionID, transactionDate, referenceID, entryTypeID, ownerID1, ownerID2, accountKey, amount,"
154  " balance, description, currency, 1 AS sortValue"
155  " FROM %s"
156  " WHERE transactionDate > %li AND accountKey = %u %s AND ownerID = %u %s",
157  tblName.c_str(), fromDate, accountKey, entryType.c_str(), ownerID, sort.c_str()))
158  {
159  codelog(DATABASE__ERROR, "Error in query: %s", res.error.c_str());
160  return nullptr;
161  }
162 
163  return DBResultToCRowset(res);
164 }
#define sDatabase
Definition: dbcore.h:199
PyObjectEx * DBResultToCRowset(DBQueryResult &result)
Definition: EVEDBUtils.cpp:402
const char * c_str() const
Definition: dbcore.h:48
#define codelog(type, fmt,...)
Definition: logsys.h:128
#define IsCorp(itemID)
Definition: EVE_Defines.h:234
DBerror error
Definition: dbcore.h:69

Here is the call graph for this function:

PyRep * AccountDB::GetWalletDivisionsInfo ( uint32  corpID)

Definition at line 109 of file AccountDB.cpp.

References PyList::AddItem(), DBerror::c_str(), codelog, PyRep::Dump(), DBQueryResult::error, DBResultRow::GetDouble(), DBQueryResult::GetRow(), is_log_enabled, sDatabase, and PyDict::SetItemString().

109  {
110  DBQueryResult res;
111  if (!sDatabase.RunQuery(res,
112  "SELECT balance1, balance2, balance3, balance4, balance5, balance6, balance7"
113  " FROM crpWalletDivisons"
114  " WHERE corporationID = %u", corpID))
115  {
116  codelog(DATABASE__ERROR, "Error in query: %s", res.error.c_str());
117  return nullptr;
118  }
119 
120  DBResultRow row;
121  PyList *list = new PyList();
122  if (res.GetRow(row))
123  for (int8 i = 0; i < 7; ++i) {
124  PyDict *dict = new PyDict();
125  dict->SetItemString("key", new PyInt(1000 + i));
126  dict->SetItemString("balance", new PyFloat(row.GetDouble(i)));
127  list->AddItem(new PyObject("util.KeyVal", dict));
128  }
129 
130  if (is_log_enabled(ACCOUNT__RSP_DUMP))
131  list->Dump(ACCOUNT__RSP_DUMP, " ");
132  return list;
133 }
#define sDatabase
Definition: dbcore.h:199
Python's dictionary.
Definition: PyRep.h:719
double GetDouble(uint32 index) const
Definition: dbcore.cpp:693
Python floating point number.
Definition: PyRep.h:292
void Dump(FILE *into, const char *pfx) const
Dumps object to file.
Definition: PyRep.cpp:84
signed __int8 int8
Definition: eve-compat.h:45
void AddItem(PyRep *i)
Definition: PyRep.h:701
bool GetRow(DBResultRow &into)
Definition: dbcore.cpp:552
#define is_log_enabled(type)
Definition: logsys.h:78
const char * c_str() const
Definition: dbcore.h:48
Python object.
Definition: PyRep.h:826
#define codelog(type, fmt,...)
Definition: logsys.h:128
Python integer.
Definition: PyRep.h:231
DBerror error
Definition: dbcore.h:69
Python list.
Definition: PyRep.h:639
void SetItemString(const char *key, PyRep *value)
SetItemString adds or sets a database entry.
Definition: PyRep.h:812

Here is the call graph for this function:

double AccountDB::OfflineFundXfer ( uint32  charID,
double  amount,
uint8  type = Account::CreditType::ISK 
)
static

Definition at line 46 of file AccountDB.cpp.

References Account::CreditType::AURUM, DBerror::c_str(), DBResultRow::GetDouble(), DBQueryResult::GetRow(), Account::CreditType::ISK, Account::CreditType::MPLEX, and sDatabase.

Referenced by AccountService::TranserFunds().

47 {
48  std::string from = "";
49  switch (type) {
50  case Account::CreditType::ISK: from = "balance"; break;
51  case Account::CreditType::AURUM: from = "aurBalance"; break;
52  case Account::CreditType::MPLEX: return 0; //make error..this isnt used yet
53  }
54 
55  double balance = 0;
56  DBQueryResult res;
57  sDatabase.RunQuery(res, "SELECT %s FROM chrCharacters WHERE characterID = %u", from.c_str(), charID);
58  DBResultRow row;
59  if (res.GetRow(row))
60  balance = row.GetDouble(0);
61 
62  balance += amount;
63  DBerror err;
64  sDatabase.RunQuery(err, "UPDATE chrCharacters SET %s = %f WHERE characterID = %u", from.c_str(), balance, charID);
65  return balance;
66 }
#define sDatabase
Definition: dbcore.h:199
double GetDouble(uint32 index) const
Definition: dbcore.cpp:693
bool GetRow(DBResultRow &into)
Definition: dbcore.cpp:552
const char * c_str() const
Definition: dbcore.h:48
Definition: dbcore.h:39

Here is the call graph for this function:

Here is the caller graph for this function:

void AccountDB::UpdateCorpBalance ( uint32  corpID,
uint16  accountKey,
double  amount 
)
static

Definition at line 92 of file AccountDB.cpp.

References DBerror::c_str(), Account::KeyType::Cash, Account::KeyType::Cash2, Account::KeyType::Cash3, Account::KeyType::Cash4, Account::KeyType::Cash5, Account::KeyType::Cash6, Account::KeyType::Cash7, and sDatabase.

Referenced by AccountService::HandleCorpTransaction().

93 {
94  std::string acctKey = "";
95  switch (accountKey) {
96  case Account::KeyType::Cash: acctKey = "balance1"; break;
97  case Account::KeyType::Cash2: acctKey = "balance2"; break;
98  case Account::KeyType::Cash3: acctKey = "balance3"; break;
99  case Account::KeyType::Cash4: acctKey = "balance4"; break;
100  case Account::KeyType::Cash5: acctKey = "balance5"; break;
101  case Account::KeyType::Cash6: acctKey = "balance6"; break;
102  case Account::KeyType::Cash7: acctKey = "balance7"; break;
103  }
104  DBerror err;
105  sDatabase.RunQuery(err, "UPDATE crpWalletDivisons SET %s = %.2f WHERE corporationID = %u ", acctKey.c_str(), amount, corpID);
106 }
#define sDatabase
Definition: dbcore.h:199
const char * c_str() const
Definition: dbcore.h:48
Definition: dbcore.h:39

Here is the call graph for this function:

Here is the caller graph for this function:


The documentation for this class was generated from the following files: