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

#include "AccountService.h"

Inheritance diagram for AccountService:
Collaboration diagram for AccountService:

Public Member Functions

 AccountService (PyServiceMgr *mgr)
 
 ~AccountService ()
 
- Public Member Functions inherited from PyService
 PyService (PyServiceMgr *mgr, const char *serviceName)
 
virtual ~PyService ()
 
virtual PyResult Call (const std::string &method, PyCallArgs &args)
 
const char * GetName () const
 
- Public Member Functions inherited from PyCallable
 PyCallable ()
 
virtual ~PyCallable ()
 

Static Public Member Functions

static void TranserFunds (uint32 fromID, uint32 toID, double amount, std::string reason="", uint8 entryTypeID=Journal::EntryType::Undefined, uint32 referenceID=0, uint16 fromKey=Account::KeyType::Cash, uint16 toKey=Account::KeyType::Cash, Client *pClient=nullptr)
 
static void HandleCorpTransaction (uint32 corpID, int8 entryTypeID, uint32 fromID, uint32 toID, int8 currency, uint16 accountKey, double amount, std::string description, uint32 referenceID=0)
 

Protected Member Functions

 PyCallable_DECL_CALL (GetCashBalance)
 
 PyCallable_DECL_CALL (GetEntryTypes)
 
 PyCallable_DECL_CALL (GetKeyMap)
 
 PyCallable_DECL_CALL (GiveCash)
 
 PyCallable_DECL_CALL (GiveCashFromCorpAccount)
 
 PyCallable_DECL_CALL (GetJournal)
 
 PyCallable_DECL_CALL (GetJournalForAccounts)
 
 PyCallable_DECL_CALL (GetWalletDivisionsInfo)
 
 PyCallable_DECL_CALL (GetDefaultContactCost)
 
 PyCallable_DECL_CALL (SetContactCost)
 
- Protected Member Functions inherited from PyService
PyObject_BuildCachedReturn (PySubStream **result, const char *sessionInfo, CacheCheckTime check)
 
virtual PyBoundObjectCreateBoundObject (Client *pClient, const PyRep *bind_args)
 
virtual PyResult Handle_MachoResolveObject (PyCallArgs &call)
 
virtual PyResult Handle_MachoBindObject (PyCallArgs &call)
 
- Protected Member Functions inherited from PyCallable
void _SetCallDispatcher (CallDispatcher *d)
 

Protected Attributes

Dispatcher *const m_dispatch
 
AccountDB m_db
 
- Protected Attributes inherited from PyService
PyServiceMgr *const m_manager
 

Additional Inherited Members

- Protected Types inherited from PyService
enum  CacheCheckTime {
  check_Always = 0, check_Never, check_in_year, check_in_6_months,
  check_in_3_months, check_in_1_month, check_in_1_week, check_in_1_day,
  check_in_12_hours, check_in_6_hours, check_in_3_hours, check_in_2_hours,
  check_in_1_hour, check_in_30_minutes, check_in_15_minutes, check_in_5_minutes,
  check_in_1_minute, check_in_30_seconds, check_in_15_seconds, check_in_5_seconds,
  check_in_1_second, _checkCount
}
 
- Static Protected Attributes inherited from PyService
static const char *const s_checkTimeStrings [_checkCount]
 

Detailed Description

Definition at line 35 of file AccountService.h.

Constructor & Destructor Documentation

AccountService::AccountService ( PyServiceMgr mgr)
AccountService::~AccountService ( )

Definition at line 72 of file AccountService.cpp.

References m_dispatch.

72  {
73  delete m_dispatch;
74 }
Dispatcher *const m_dispatch

Member Function Documentation

void AccountService::HandleCorpTransaction ( uint32  corpID,
int8  entryTypeID,
uint32  fromID,
uint32  toID,
int8  currency,
uint16  accountKey,
double  amount,
std::string  description,
uint32  referenceID = 0 
)
static

Definition at line 389 of file AccountService.cpp.

References _log, UserError::AddFormatValue(), UserError::AddISK(), AccountDB::AddJournalEntry(), UserError::AddOwnerName(), args, Account::KeyType::Cash, Account::KeyType::Cash2, Account::KeyType::Cash3, Account::KeyType::Cash4, Account::KeyType::Cash5, Account::KeyType::Cash6, Account::KeyType::Cash7, AccountDB::GetCorpBalance(), CorporationDB::GetCorpName(), CorporationDB::GetDivisionName(), is_log_enabled, sEntityList, and AccountDB::UpdateCorpBalance().

Referenced by TranserFunds().

392 {
393  if (is_log_enabled(ACCOUNT__TRACE))
394  _log(ACCOUNT__TRACE, "HandleCorpTransaction() - corp: %u, from: %u, to: %u, entry: %u, refID: %u, amount: %.2f, key: %u, currency: %u", \
395  corpID, fromID, toID, entryTypeID, referenceID, amount, accountKey, currency);
396  double balance = AccountDB::GetCorpBalance(corpID, accountKey);
397  // verify funds available for withdraw first
398  if (amount < 0) {
399  if (-amount > balance) {
400  std::map<std::string, PyRep *> args;
401  args["owner"] = new PyString(CorporationDB::GetCorpName(corpID));
402  args["amount"] = new PyFloat(-amount);
403  args["balance"] = new PyFloat(balance);
404  args["division"] = new PyString(CorporationDB::GetDivisionName(corpID, accountKey));
405  throw UserError ("NotEnoughMoneyCorp")
406  .AddOwnerName ("owner", corpID)
407  .AddISK ("amount", -amount)
408  .AddISK ("balance", balance)
409  .AddFormatValue ("division", new PyString (CorporationDB::GetDivisionName (corpID, accountKey)));
410  }
411  }
412  // get new corp balance
413  balance += amount;
414  // update corp balance
415  AccountDB::UpdateCorpBalance(corpID, accountKey, balance);
416 
417  OnAccountChange oac;
418  switch (accountKey) {
419  case Account::KeyType::Cash2: oac.accountKey = "cash2"; break;
420  case Account::KeyType::Cash3: oac.accountKey = "cash3"; break;
421  case Account::KeyType::Cash4: oac.accountKey = "cash4"; break;
422  case Account::KeyType::Cash5: oac.accountKey = "cash5"; break;
423  case Account::KeyType::Cash6: oac.accountKey = "cash6"; break;
424  case Account::KeyType::Cash7: oac.accountKey = "cash7"; break;
426  default: oac.accountKey = "cash"; break;
427  }
428  oac.balance = balance;
429  oac.ownerid = corpID;
430  sEntityList.CorpNotify(corpID, 126 /*WalletChange*/, "OnAccountChange", "*corpid&corpAccountKey", oac.Encode());
431  AccountDB::AddJournalEntry(corpID, entryTypeID, fromID, toID, currency, accountKey, amount, balance, description, referenceID);
432 }
#define _log(type, fmt,...)
Definition: logsys.h:124
Python string.
Definition: PyRep.h:430
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)
Definition: AccountDB.cpp:166
Python floating point number.
Definition: PyRep.h:292
#define sEntityList
Definition: EntityList.h:208
UserError & AddFormatValue(const char *name, PyRep *value)
Fluent version of the protected AddKeyword, allows for adding a keyword to the exception.
UserError & AddISK(const char *name, double isk)
Shorthand method for adding an ISK amount.
* args
#define is_log_enabled(type)
Definition: logsys.h:78
UserError & AddOwnerName(const char *name, uint32 ownerID)
Shorthand method for adding an owner's name.
static std::string GetDivisionName(uint32 corpID, uint16 acctKey)
Python object "ccp_exceptions.UserError".
Definition: PyExceptions.h:121
static void UpdateCorpBalance(uint32 corpID, uint16 accountKey, double amount)
Definition: AccountDB.cpp:92
static double GetCorpBalance(uint32 corpID, uint16 accountKey)
Definition: AccountDB.cpp:69
static std::string GetCorpName(uint32 corpID)

Here is the call graph for this function:

Here is the caller graph for this function:

AccountService::PyCallable_DECL_CALL ( GetCashBalance  )
protected
AccountService::PyCallable_DECL_CALL ( GetEntryTypes  )
protected
AccountService::PyCallable_DECL_CALL ( GetKeyMap  )
protected
AccountService::PyCallable_DECL_CALL ( GiveCash  )
protected
AccountService::PyCallable_DECL_CALL ( GiveCashFromCorpAccount  )
protected
AccountService::PyCallable_DECL_CALL ( GetJournal  )
protected
AccountService::PyCallable_DECL_CALL ( GetJournalForAccounts  )
protected
AccountService::PyCallable_DECL_CALL ( GetWalletDivisionsInfo  )
protected
AccountService::PyCallable_DECL_CALL ( GetDefaultContactCost  )
protected
AccountService::PyCallable_DECL_CALL ( SetContactCost  )
protected
void AccountService::TranserFunds ( uint32  fromID,
uint32  toID,
double  amount,
std::string  reason = "",
uint8  entryTypeID = Journal::EntryType::Undefined,
uint32  referenceID = 0,
uint16  fromKey = Account::KeyType::Cash,
uint16  toKey = Account::KeyType::Cash,
Client pClient = nullptr 
)
static
Todo:
if this DOES fail, return funds to origin. this needs a try/catch block

Definition at line 273 of file AccountService.cpp.

References _log, Client::AddBalance(), AccountDB::AddJournalEntry(), Journal::EntryType::AgentMissionReward, Journal::EntryType::AgentMissionTimeBonusReward, Account::CreditType::AURUM, Journal::EntryType::BountyPrize, Journal::EntryType::BountyPrizes, Journal::EntryType::CorporationTaxAgentBonusRewards, Journal::EntryType::CorporationTaxAgentRewards, Journal::EntryType::CorporationTaxNpcBounties, Client::GetBalance(), Client::GetCharacterID(), CharacterDB::GetCorpID(), Client::GetCorporationID(), Client::GetCorpTaxRate(), CharacterDB::GetCorpTaxRate(), HandleCorpTransaction(), is_log_enabled, IsAUR, IsCharacterID, Client::IsCharCreation(), IsCorp, IsDustKey, Account::CreditType::ISK, IsPlayerCorp, Account::CreditType::MPLEX, AccountDB::OfflineFundXfer(), sConfig, sDataMgr, and sEntityList.

Referenced by DynamicSystemEntity::AwardBounty(), PlanetMgr::CreatePin(), TradeBound::ExchangeItems(), MarketMgr::ExecuteBuyOrder(), MarketMgr::ExecuteSellOrder(), Colony::LaunchCommodities(), SystemManager::PayBounties(), Character::PayBounty(), ShipSE::PayInsurance(), Colony::PlanetXfer(), and PlanetMgr::UpgradeCommandCenter().

276 {
277  if (is_log_enabled(ACCOUNT__TRACE))
278  _log(ACCOUNT__TRACE, "TranserFunds() - from: %u, to: %u, entry: %u, refID: %u, amount: %.2f, fKey: %u, tKey: %u", \
279  fromID, toID, entryTypeID, referenceID, amount, fromKey, toKey);
280  uint8 fromCurrency = Account::CreditType::ISK;
281  if (IsAUR(fromKey)) {
282  fromCurrency = Account::CreditType::AURUM;
283  } else if (IsDustKey(fromKey)) {
284  fromCurrency = Account::CreditType::MPLEX;
285  }
286 
287  double newBalanceFrom(0), newBalanceTo(0);
288  Client* pClientFrom(nullptr);
289  if (IsCharacterID(fromID)) {
290  pClientFrom = sEntityList.FindClientByCharID(fromID);
291  if (pClientFrom == nullptr) {
292  // sender is offline. xfer funds thru db.
293  newBalanceFrom = AccountDB::OfflineFundXfer(fromID, -amount, fromCurrency);
294  } else {
295  // this will throw if it fails
296  pClientFrom->AddBalance(-amount, fromCurrency);
297  newBalanceFrom = pClientFrom->GetBalance(fromCurrency);
298  }
299  AccountDB::AddJournalEntry(fromID, entryTypeID, fromID, toID, fromCurrency, fromKey, -amount, newBalanceFrom, reason, referenceID);
300  } else if (IsPlayerCorp(fromID)) {
301  uint32 userID(0);
302  if (pClient != nullptr)
303  userID = pClient->GetCharacterID();
304  HandleCorpTransaction(fromID, entryTypeID, userID?userID:fromID, toID, fromCurrency, fromKey, -amount, reason, referenceID);
305  } // fromID could be npc or _System. nothing to do on this side.
306 
307  uint8 toCurrency = Account::CreditType::ISK;
308  if (IsAUR(toKey)) {
309  toCurrency = Account::CreditType::AURUM;
310  } else if (IsDustKey(toKey)) {
311  toCurrency = Account::CreditType::MPLEX;
312  }
313 
314  Client* pClientTo(nullptr);
315  if (IsCharacterID(toID)) {
316  pClientTo = sEntityList.FindClientByCharID(toID);
317  if (pClientTo == nullptr) {
318  // receipient is offline. xfer funds thru db
319  newBalanceTo = AccountDB::OfflineFundXfer(toID, amount, toCurrency);
320  } else {
321  // this will throw if it fails
322  pClientTo->AddBalance(amount, toCurrency);
324  //TranserFunds(corpSCC, fromID, amount, reason, Journal::EntryType::Undefined, referenceID, fromKey, fromKey);
325  newBalanceTo = pClientTo->GetBalance(toCurrency);
326  }
327  AccountDB::AddJournalEntry(toID, entryTypeID, fromID, toID, toCurrency, toKey, amount, newBalanceTo, reason, referenceID);
328  } else if (IsPlayerCorp(toID)) {
329  uint32 userID(0);
330  if (pClient != nullptr)
331  userID = pClient->GetCharacterID();
332  HandleCorpTransaction(toID, entryTypeID, fromID, userID?userID:toID, toCurrency, toKey, amount, reason, referenceID);
333  return;
334  } else {
335  _log(ACCOUNT__TRACE, "TranserFunds() - toID: %s(%u) is neither player nor player corp. Not sending update.", \
336  sDataMgr.GetCorpName(toID).c_str(), toID);
337  return;
338  }
339 
340  if ((pClientTo != nullptr) and pClientTo->IsCharCreation())
341  return;
342 
343  /* corp taxes...
344  * bounty prizes and mission rewards are taxed by the players corp based on corp tax rate.
345  * there is a possibility the char receiving these payments could be offline (for whatever reason)
346  * these payments are only taxed if they are above amount set in server config.
347  */
348 
349  // are bounty payments grouped on timer?
350  if ((entryTypeID == Journal::EntryType::BountyPrize)
351  or (entryTypeID == Journal::EntryType::BountyPrizes))
352  if (sConfig.server.BountyPayoutDelayed)
353  if (amount < sConfig.rates.TaxedAmount) // is amount worth taxing? default is 75k
354  return;
355  float tax = 0;
356  uint32 corpID = 0;
357  if (pClientTo != nullptr) {
358  tax = pClientTo->GetCorpTaxRate() * amount;
359  corpID = pClientTo->GetCorporationID();
360  } else {
361  // recipient is offline...try to get needed data from db
362  tax = CharacterDB::GetCorpTaxRate(toID) * amount;
363  corpID = CharacterDB::GetCorpID(toID);
364  }
365 
366  // just in case something went wrong.....
367  if (!IsCorp(corpID))
368  return;
369  // is tax worth the accounting hassle? (from corp pov) default is 5k
370  if (tax < sConfig.rates.TaxAmount)
371  return;
372 
373  reason = "DESC: Corporation Tax on pirate bounty";
374  switch (entryTypeID) {
375  // Corp Taxed payment types
378  TranserFunds(toID, corpID, tax, reason.c_str(), Journal::EntryType::CorporationTaxNpcBounties, referenceID);
379  } break;
381  TranserFunds(toID, corpID, tax, reason.c_str(), Journal::EntryType::CorporationTaxAgentRewards, referenceID);
382  } break;
384  TranserFunds(toID, corpID, tax, reason.c_str(), Journal::EntryType::CorporationTaxAgentBonusRewards, referenceID);
385  } break;
386  }
387 }
#define sConfig
A macro for easier access to the singleton.
unsigned __int8 uint8
Definition: eve-compat.h:46
static float GetCorpTaxRate(uint32 charID)
#define _log(type, fmt,...)
Definition: logsys.h:124
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)
Definition: AccountDB.cpp:166
#define IsAUR(key)
Definition: EVE_Defines.h:377
int32 GetCharacterID() const
Definition: Client.h:113
#define sEntityList
Definition: EntityList.h:208
#define is_log_enabled(type)
Definition: logsys.h:78
static void TranserFunds(uint32 fromID, uint32 toID, double amount, std::string reason="", uint8 entryTypeID=Journal::EntryType::Undefined, uint32 referenceID=0, uint16 fromKey=Account::KeyType::Cash, uint16 toKey=Account::KeyType::Cash, Client *pClient=nullptr)
static uint32 GetCorpID(uint32 charID)
#define IsPlayerCorp(itemID)
Definition: EVE_Defines.h:241
#define IsCharacterID(itemID)
Definition: EVE_Defines.h:206
Definition: Client.h:66
unsigned __int32 uint32
Definition: eve-compat.h:50
#define IsCorp(itemID)
Definition: EVE_Defines.h:234
static void HandleCorpTransaction(uint32 corpID, int8 entryTypeID, uint32 fromID, uint32 toID, int8 currency, uint16 accountKey, double amount, std::string description, uint32 referenceID=0)
static double OfflineFundXfer(uint32 charID, double amount, uint8 type=Account::CreditType::ISK)
Definition: AccountDB.cpp:46
#define sDataMgr
#define IsDustKey(key)
Definition: EVE_Defines.h:380

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

AccountDB AccountService::m_db
protected

Definition at line 56 of file AccountService.h.

Dispatcher* const AccountService::m_dispatch
protected

Definition at line 53 of file AccountService.h.

Referenced by ~AccountService().


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