27 #include <boost/algorithm/string.hpp>
100 sLog.Log(
"AccountService::Handle_GetDefaultContactCost()",
"size=%u", call.
tuple->
size());
101 call.
Dump(ACCOUNT__CALL_DUMP);
118 sLog.Log(
"AccountService::Handle_SetContactCost()",
"size=%u", call.
tuple->
size());
119 call.
Dump(ACCOUNT__CALL_DUMP);
129 sLog.Log(
"AccountService::Handle_GetCashBalance()",
"size=%u", call.
tuple->
size());
130 call.
Dump(ACCOUNT__CALL_DUMP);
138 if (call.
byname.find(
"accountKey") != call.
byname.end())
159 sLog.Log(
"AccountService::Handle_GetJournal()",
"size=%u", call.
tuple->
size());
160 call.
Dump(ACCOUNT__CALL_DUMP);
162 Call_GetJournal
args;
163 if (!args.Decode(&call.
tuple)) {
164 codelog(SERVICE__ERROR,
"%s: Failed to decode arguments.",
GetName());
169 if (args.corpAccount)
172 PyRep* res =
m_db.
GetJournal(ownerID, args.entryTypeID, args.accountKey, args.fromDate, args.rev);
174 res->
Dump(ACCOUNT__RSP_DUMP,
" ");
183 sLog.Log(
"AccountService::Handle_GetJournalForAccounts()",
"size=%u", call.
tuple->
size());
184 call.
Dump(ACCOUNT__CALL_DUMP);
186 Call_GetJournals
args;
187 if (!args.Decode(&call.
tuple)) {
188 codelog(SERVICE__ERROR,
"%s: Failed to decode arguments.",
GetName());
193 if (args.corpAccount)
200 res->
Dump(ACCOUNT__RSP_DUMP,
" ");
207 sLog.Log(
"AccountService::Handle_GiveCash()",
"size=%u", call.
tuple->
size());
208 call.
Dump(ACCOUNT__CALL_DUMP);
211 if (!args.Decode(&call.
tuple)) {
212 codelog(SERVICE__ERROR,
"%s: Failed to decode arguments.",
GetName());
216 std::string reason =
"DESC: ";
217 if (args.reason.size() < 1) {
218 reason +=
"No Reason Given";
223 throw CustomError (
"Description contains invalid characters");
224 reason += args.reason;
234 sLog.Log(
"AccountService::Handle_GiveCashFromCorpAccount()",
"size=%u", call.
tuple->
size());
235 call.
Dump(ACCOUNT__CALL_DUMP);
237 Call_GiveCorpCash
args;
238 if (!args.Decode(&call.
tuple)) {
239 codelog(SERVICE__ERROR,
"%s: Failed to decode arguments.",
GetName());
244 if (call.
byname.find(
"toAccountKey") != call.
byname.end())
247 std::string reason=
"DESC: ";
252 if (content.size () < 1) {
253 reason +=
"No Reason Given by ";
257 for (
const auto cur: badChars)
259 throw CustomError(
"Reason contains invalid characters");
264 reason +=
"No Reason Given by ";
269 call.client->GetCharacterID(), args.fromAcctKey, toAcctKey, call.
client);
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);
281 if (
IsAUR(fromKey)) {
287 double newBalanceFrom(0), newBalanceTo(0);
288 Client* pClientFrom(
nullptr);
290 pClientFrom =
sEntityList.FindClientByCharID(fromID);
291 if (pClientFrom ==
nullptr) {
296 pClientFrom->
AddBalance(-amount, fromCurrency);
297 newBalanceFrom = pClientFrom->
GetBalance(fromCurrency);
299 AccountDB::AddJournalEntry(fromID, entryTypeID, fromID, toID, fromCurrency, fromKey, -amount, newBalanceFrom, reason, referenceID);
302 if (pClient !=
nullptr)
304 HandleCorpTransaction(fromID, entryTypeID, userID?userID:fromID, toID, fromCurrency, fromKey, -amount, reason, referenceID);
314 Client* pClientTo(
nullptr);
317 if (pClientTo ==
nullptr) {
325 newBalanceTo = pClientTo->
GetBalance(toCurrency);
330 if (pClient !=
nullptr)
332 HandleCorpTransaction(toID, entryTypeID, fromID, userID?userID:toID, toCurrency, toKey, amount, reason, referenceID);
335 _log(ACCOUNT__TRACE,
"TranserFunds() - toID: %s(%u) is neither player nor player corp. Not sending update.", \
336 sDataMgr.GetCorpName(toID).c_str(), toID);
352 if (
sConfig.server.BountyPayoutDelayed)
353 if (amount <
sConfig.rates.TaxedAmount)
357 if (pClientTo !=
nullptr) {
370 if (tax <
sConfig.rates.TaxAmount)
373 reason =
"DESC: Corporation Tax on pirate bounty";
374 switch (entryTypeID) {
390 uint16 accountKey,
double amount, std::string description, \
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);
399 if (-amount > balance) {
400 std::map<std::string, PyRep *>
args;
402 args[
"amount"] =
new PyFloat(-amount);
403 args[
"balance"] =
new PyFloat(balance);
407 .
AddISK (
"amount", -amount)
408 .
AddISK (
"balance", balance)
418 switch (accountKey) {
426 default: oac.accountKey =
"cash";
break;
428 oac.balance = balance;
429 oac.ownerid = corpID;
430 sEntityList.CorpNotify(corpID, 126 ,
"OnAccountChange",
"*corpid&corpAccountKey", oac.Encode());
431 AccountDB::AddJournalEntry(corpID, entryTypeID, fromID, toID, currency, accountKey, amount, balance, description, referenceID);
#define sConfig
A macro for easier access to the singleton.
Dispatcher *const m_dispatch
static std::string StringContent(PyRep *pRep)
static float GetCorpTaxRate(uint32 charID)
#define _log(type, fmt,...)
PyRep * GetItem(size_t index) const
Returns Python object.
bool AddBalance(float amount, uint8 type=Account::CreditType::ISK)
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)
std::map< std::string, PyRep * > byname
static const std::array< std::string, 18 > badChars
Python floating point number.
PyCallable_Make_InnerDispatcher(AccountService) AccountService
int32 GetCharacterID() const
int32 GetCorporationID() const
static uint32 IntegerValueU32(PyRep *pRep)
UserError & AddFormatValue(const char *name, PyRep *value)
Fluent version of the protected AddKeyword, allows for adding a keyword to the exception.
const char * GetName() const
Advanced version of UserError that allows to send a full custom message.
void Dump(FILE *into, const char *pfx) const
Dumps object to file.
UserError & AddISK(const char *name, double isk)
Shorthand method for adding an ISK amount.
#define is_log_enabled(type)
#define sLog
Evaluates to a NewLog instance.
#define codelog(type, fmt,...)
UserError & AddOwnerName(const char *name, uint32 ownerID)
Shorthand method for adding an owner's name.
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 std::string GetDivisionName(uint32 corpID, uint16 acctKey)
PyRep * GetWalletDivisionsInfo(uint32 corpID)
Dispatcher *const m_dispatch
static uint32 GetCorpID(uint32 charID)
#define IsPlayerCorp(itemID)
#define IsCharacterID(itemID)
Python object "ccp_exceptions.UserError".
#define PyCallable_REG_CALL(c, m)
std::string GetCharName()
float GetBalance(uint8 type=Account::CreditType::ISK)
static void HandleCorpTransaction(uint32 corpID, int8 entryTypeID, uint32 fromID, uint32 toID, int8 currency, uint16 accountKey, double amount, std::string description, uint32 referenceID=0)
static void UpdateCorpBalance(uint32 corpID, uint16 accountKey, double amount)
int32 GetCorpAccountKey() const
void Dump(LogType type) const
static int64 IntegerValue(PyRep *pRep)
static double GetCorpBalance(uint32 corpID, uint16 accountKey)
static double OfflineFundXfer(uint32 charID, double amount, uint8 type=Account::CreditType::ISK)
static std::string GetCorpName(uint32 corpID)
PyRep * GetJournal(uint32 ownerID, int8 entryTypeID, uint16 accountKey, int64 fromDate, bool reverse=false)
bool icontains(std::string data, std::string toSearch, size_t pos=0)