Skip to content

Commit b302a3b

Browse files
Improvements and fixes for market transactions; code quality improvements (#291)
* show proper clients in wallet transactions view; implement more npc trader features; rename TranserFunds to TransferFunds; code legibility improvements * adjust debug logging
1 parent 4e45b36 commit b302a3b

25 files changed

+926
-457
lines changed

doc/code_and_design_notes/Alasiya_TODO

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,8 @@ customInfo is actually used in client
192192
- there are many logConst and event** msgs not implemented/researched (LP, FacWar, StandingTransactions, more)
193193

194194
20:41:06 [Bound] InsuranceBound::InsureShip()
195-
20:41:06 [AcctTrace] TranserFunds() - from: 90000000, to: 1000132, entry: 19, refID: 0, amount: 0.33, fKey: 1000, tKey: 1000
196-
20:41:06 [AcctTrace] TranserFunds() - toID: 1000132 is neither player nor player corp.
195+
20:41:06 [AcctTrace] TransferFunds() - from: 90000000, to: 1000132, entry: 19, refID: 0, amount: 0.33, fKey: 1000, tKey: 1000
196+
20:41:06 [AcctTrace] TransferFunds() - toID: 1000132 is neither player nor player corp.
197197
20:41:06 [SvcMsg] New messageID: 1
198198
20:41:06 [SvcMsg] Delivered message from 1000132 to recipient 90000000
199199
- ins mail working. need contractID, expiry date, and few other things...

src/eve-common/EVE_Defines.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@
396396
(itemID == npcTraderJoe)
397397

398398
#define IsTrader(itemID) \
399-
(((itemID >= minTrader) && (itemID <= maxTrader))
399+
((itemID >= minTrader) && (itemID <= maxTrader))
400400

401401

402402
/*

src/eve-server/account/AccountService.cpp

Lines changed: 167 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,7 @@ PyResult AccountService::GiveCash(PyCallArgs& call, PyInt* toID, PyFloat* amount
215215
return GiveCash(call, toID, amount, reason.has_value()?reason.value()->content():std::string());
216216
}
217217

218-
PyResult AccountService::GiveCash(PyCallArgs &call, PyInt* toID, PyFloat* amount, std::string reason)
219-
{
218+
PyResult AccountService::GiveCash(PyCallArgs &call, PyInt* toID, PyFloat* amount, std::string reason) {
220219
if (is_log_enabled(ACCOUNT__CALL_DUMP)) {
221220
sLog.Log( "AccountService::Handle_GiveCash()", "size=%lu", call.tuple->size());
222221
call.Dump(ACCOUNT__CALL_DUMP);
@@ -233,7 +232,15 @@ PyResult AccountService::GiveCash(PyCallArgs &call, PyInt* toID, PyFloat* amount
233232
reasonStr += reason;
234233
}
235234

236-
TranserFunds(call.client->GetCharacterID(), toID->value(), amount->value(), reasonStr.c_str(), Journal::EntryType::PlayerDonation, call.client->GetCharacterID());
235+
TransferFunds(
236+
call.client->GetCharacterID(),
237+
toID->value(),
238+
amount->value(),
239+
reasonStr.c_str(),
240+
Journal::EntryType::PlayerDonation,
241+
call.client->GetCharacterID()
242+
);
243+
237244
return nullptr;
238245
}
239246

@@ -273,43 +280,97 @@ PyResult AccountService::GiveCashFromCorpAccount(PyCallArgs &call, PyInt* toID,
273280
reason += call.client->GetCharName();
274281
}
275282

276-
TranserFunds(call.client->GetCorporationID(), toID->value(), amount->value(), reason.c_str(), Journal::EntryType::CorporationAccountWithdrawal, \
277-
call.client->GetCharacterID(), fromAcctKey->value(), toAcctKey, call.client);
283+
TransferFunds(
284+
call.client->GetCorporationID(),
285+
toID->value(),
286+
amount->value(),
287+
reason.c_str(),
288+
Journal::EntryType::CorporationAccountWithdrawal,
289+
call.client->GetCharacterID(),
290+
fromAcctKey->value(),
291+
toAcctKey,
292+
call.client
293+
);
294+
278295
return nullptr;
279296
}
280297

281-
void AccountService::TranserFunds(uint32 fromID, uint32 toID, double amount, std::string reason /*""*/, uint8 entryTypeID /*Journal::EntryType::Undefined*/, \
282-
uint32 referenceID/*0*/, uint16 fromKey/*Account::KeyType::Cash*/, uint16 toKey/*Account::KeyType::Cash*/,
283-
Client* pClient/*nullptr*/)
284-
{
285-
if (is_log_enabled(ACCOUNT__TRACE))
286-
_log(ACCOUNT__TRACE, "TranserFunds() - from: %u, to: %u, entry: %u, refID: %u, amount: %.2f, fKey: %u, tKey: %u", \
287-
fromID, toID, entryTypeID, referenceID, amount, fromKey, toKey);
298+
void AccountService::TransferFunds(
299+
uint32 fromID,
300+
uint32 toID,
301+
double amount,
302+
std::string reason /*""*/,
303+
uint8 entryTypeID /*Journal::EntryType::Undefined*/,
304+
uint32 referenceID /*0*/,
305+
uint16 fromKey /*Account::KeyType::Cash*/,
306+
uint16 toKey /*Account::KeyType::Cash*/,
307+
Client* pClient /*nullptr*/
308+
) {
309+
if (is_log_enabled(ACCOUNT__TRACE)) {
310+
_log(ACCOUNT__TRACE,
311+
"TransferFunds() - from: %u, to: %u, entry: %u, refID: %u, amount: %.2f, fKey: %u, tKey: %u",
312+
fromID,
313+
toID,
314+
entryTypeID,
315+
referenceID,
316+
amount,
317+
fromKey,
318+
toKey
319+
);
320+
}
321+
288322
uint8 fromCurrency = Account::CreditType::ISK;
323+
289324
if (IsAUR(fromKey)) {
290325
fromCurrency = Account::CreditType::AURUM;
291326
} else if (IsDustKey(fromKey)) {
292327
fromCurrency = Account::CreditType::MPLEX;
293328
}
294329

295330
double newBalanceFrom(0), newBalanceTo(0);
331+
296332
Client* pClientFrom(nullptr);
333+
297334
if (IsCharacterID(fromID)) {
298335
pClientFrom = sEntityList.FindClientByCharID(fromID);
299336
if (pClientFrom == nullptr) {
300-
// sender is offline. xfer funds thru db.
337+
// sender is offline. transfer funds through the database instead
301338
newBalanceFrom = AccountDB::OfflineFundXfer(fromID, -amount, fromCurrency);
302339
} else {
303340
// this will throw if it fails
304341
pClientFrom->AddBalance(-amount, fromCurrency);
305342
newBalanceFrom = pClientFrom->GetBalance(fromCurrency);
306343
}
307-
AccountDB::AddJournalEntry(fromID, entryTypeID, fromID, toID, fromCurrency, fromKey, -amount, newBalanceFrom, reason, referenceID);
344+
345+
AccountDB::AddJournalEntry(
346+
fromID,
347+
entryTypeID,
348+
fromID,
349+
toID,
350+
fromCurrency,
351+
fromKey,
352+
-amount,
353+
newBalanceFrom,
354+
reason,
355+
referenceID
356+
);
308357
} else if (IsPlayerCorp(fromID)) {
309358
uint32 userID(0);
310-
if (pClient != nullptr)
359+
if (pClient != nullptr) {
311360
userID = pClient->GetCharacterID();
312-
HandleCorpTransaction(fromID, entryTypeID, userID?userID:fromID, toID, fromCurrency, fromKey, -amount, reason, referenceID);
361+
}
362+
363+
HandleCorpTransaction(
364+
fromID,
365+
entryTypeID,
366+
userID ? userID : fromID,
367+
toID,
368+
fromCurrency,
369+
fromKey,
370+
-amount,
371+
reason,
372+
referenceID
373+
);
313374
} // fromID could be npc or _System. nothing to do on this side.
314375

315376
uint8 toCurrency = Account::CreditType::ISK;
@@ -320,6 +381,7 @@ void AccountService::TranserFunds(uint32 fromID, uint32 toID, double amount, std
320381
}
321382

322383
Client* pClientTo(nullptr);
384+
323385
if (IsCharacterID(toID)) {
324386
pClientTo = sEntityList.FindClientByCharID(toID);
325387
if (pClientTo == nullptr) {
@@ -329,24 +391,67 @@ void AccountService::TranserFunds(uint32 fromID, uint32 toID, double amount, std
329391
// this will throw if it fails
330392
pClientTo->AddBalance(amount, toCurrency);
331393
/** @todo if this DOES fail, return funds to origin. this needs a try/catch block */
332-
//TranserFunds(corpSCC, fromID, amount, reason, Journal::EntryType::Undefined, referenceID, fromKey, fromKey);
394+
//TransferFunds(corpSCC, fromID, amount, reason, Journal::EntryType::Undefined, referenceID, fromKey, fromKey);
333395
newBalanceTo = pClientTo->GetBalance(toCurrency);
334396
}
335-
AccountDB::AddJournalEntry(toID, entryTypeID, fromID, toID, toCurrency, toKey, amount, newBalanceTo, reason, referenceID);
397+
398+
AccountDB::AddJournalEntry(
399+
toID,
400+
entryTypeID,
401+
fromID,
402+
toID,
403+
toCurrency,
404+
toKey,
405+
amount,
406+
newBalanceTo,
407+
reason,
408+
referenceID
409+
);
336410
} else if (IsPlayerCorp(toID)) {
337411
uint32 userID(0);
338-
if (pClient != nullptr)
412+
413+
if (pClient != nullptr) {
339414
userID = pClient->GetCharacterID();
340-
HandleCorpTransaction(toID, entryTypeID, fromID, userID?userID:toID, toCurrency, toKey, amount, reason, referenceID);
415+
}
416+
417+
HandleCorpTransaction(
418+
toID,
419+
entryTypeID,
420+
fromID,
421+
userID?userID:toID,
422+
toCurrency,
423+
toKey,
424+
amount,
425+
reason,
426+
referenceID
427+
);
341428
return;
342429
} else {
343-
_log(ACCOUNT__TRACE, "TranserFunds() - toID: %s(%u) is neither player nor player corp. Not sending update.", \
344-
sDataMgr.GetCorpName(toID).c_str(), toID);
430+
AccountDB::AddJournalEntry(
431+
toID,
432+
entryTypeID,
433+
fromID,
434+
toID,
435+
toCurrency,
436+
toKey,
437+
amount,
438+
newBalanceTo,
439+
reason,
440+
referenceID
441+
);
442+
443+
_log(ACCOUNT__TRACE,
444+
"TransferFunds() - toID: %s(%u) is neither player nor player corp. Not sending update.",
445+
sDataMgr.GetCorpName(toID).c_str(),
446+
toID
447+
);
448+
345449
return;
346450
}
347451

348-
if ((pClientTo != nullptr) and pClientTo->IsCharCreation())
452+
if ((pClientTo != nullptr) and pClientTo->IsCharCreation()) {
349453
return;
454+
}
350455

351456
/* corp taxes...
352457
* bounty prizes and mission rewards are taxed by the players corp based on corp tax rate.
@@ -355,13 +460,18 @@ void AccountService::TranserFunds(uint32 fromID, uint32 toID, double amount, std
355460
*/
356461

357462
// are bounty payments grouped on timer?
358-
if ((entryTypeID == Journal::EntryType::BountyPrize)
359-
or (entryTypeID == Journal::EntryType::BountyPrizes))
360-
if (sConfig.server.BountyPayoutDelayed)
361-
if (amount < sConfig.rates.TaxedAmount) // is amount worth taxing? default is 75k
463+
if ((entryTypeID == Journal::EntryType::BountyPrize) || (entryTypeID == Journal::EntryType::BountyPrizes)) {
464+
if (sConfig.server.BountyPayoutDelayed) {
465+
// is amount worth taxing? default is 75k
466+
if (amount < sConfig.rates.TaxedAmount) {
362467
return;
468+
}
469+
}
470+
}
471+
363472
float tax = 0;
364473
uint32 corpID = 0;
474+
365475
if (pClientTo != nullptr) {
366476
tax = pClientTo->GetCorpTaxRate() * amount;
367477
corpID = pClientTo->GetCorporationID();
@@ -372,24 +482,48 @@ void AccountService::TranserFunds(uint32 fromID, uint32 toID, double amount, std
372482
}
373483

374484
// just in case something went wrong.....
375-
if (!IsCorp(corpID))
485+
if (!IsCorp(corpID)) {
376486
return;
377-
// is tax worth the accounting hassle? (from corp pov) default is 5k
378-
if (tax < sConfig.rates.TaxAmount)
487+
}
488+
489+
// is tax worth the accounting hassle? (from corp pov) default is 5k
490+
if (tax < sConfig.rates.TaxAmount) {
379491
return;
492+
}
380493

381494
reason = "DESC: Corporation Tax on pirate bounty";
382495
switch (entryTypeID) {
383496
// Corp Taxed payment types
384497
case Journal::EntryType::BountyPrize:
385498
case Journal::EntryType::BountyPrizes: {
386-
TranserFunds(toID, corpID, tax, reason.c_str(), Journal::EntryType::CorporationTaxNpcBounties, referenceID);
499+
TransferFunds(
500+
toID,
501+
corpID,
502+
tax,
503+
reason.c_str(),
504+
Journal::EntryType::CorporationTaxNpcBounties,
505+
referenceID
506+
);
387507
} break;
388508
case Journal::EntryType::AgentMissionReward: {
389-
TranserFunds(toID, corpID, tax, reason.c_str(), Journal::EntryType::CorporationTaxAgentRewards, referenceID);
509+
TransferFunds(
510+
toID,
511+
corpID,
512+
tax,
513+
reason.c_str(),
514+
Journal::EntryType::CorporationTaxAgentRewards,
515+
referenceID
516+
);
390517
} break;
391518
case Journal::EntryType::AgentMissionTimeBonusReward: {
392-
TranserFunds(toID, corpID, tax, reason.c_str(), Journal::EntryType::CorporationTaxAgentBonusRewards, referenceID);
519+
TransferFunds(
520+
toID,
521+
corpID,
522+
tax,
523+
reason.c_str(),
524+
Journal::EntryType::CorporationTaxAgentBonusRewards,
525+
referenceID
526+
);
393527
} break;
394528
}
395529
}

src/eve-server/account/AccountService.h

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,31 @@ class AccountService : public Service <AccountService> {
3636
AccountService();
3737

3838
// this moves currency, adds journal entries, and sends blink event. handles applicable corp taxes internally.
39-
// will throw if fails
40-
static void TranserFunds(uint32 fromID, uint32 toID, double amount, std::string reason = "", \
41-
uint8 entryTypeID = Journal::EntryType::Undefined, uint32 referenceID = 0, \
42-
uint16 fromKey = Account::KeyType::Cash, uint16 toKey = Account::KeyType::Cash, \
43-
Client* pClient=nullptr);
39+
// will throw if fails
40+
static void TransferFunds(
41+
uint32 fromID,
42+
uint32 toID,
43+
double amount,
44+
std::string reason = "",
45+
uint8 entryTypeID = Journal::EntryType::Undefined,
46+
uint32 referenceID = 0,
47+
uint16 fromKey = Account::KeyType::Cash,
48+
uint16 toKey = Account::KeyType::Cash,
49+
Client* pClient=nullptr
50+
);
4451

4552
// this should be the ONLY method to alter corp balances, and ONLY called from TransferFunds()
46-
static void HandleCorpTransaction(uint32 corpID, int8 entryTypeID, uint32 fromID, uint32 toID, int8 currency, uint16 accountKey, \
47-
double amount, std::string description, uint32 referenceID = 0);
53+
static void HandleCorpTransaction(
54+
uint32 corpID,
55+
int8 entryTypeID,
56+
uint32 fromID,
57+
uint32 toID,
58+
int8 currency,
59+
uint16 accountKey,
60+
double amount,
61+
std::string description,
62+
uint32 referenceID = 0
63+
);
4864

4965
protected:
5066
AccountDB m_db;

src/eve-server/agents/AgentBound.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,9 +270,9 @@ PyResult AgentBound::DoAction(PyCallArgs &call, std::optional <PyInt*> actionID)
270270
}
271271
/** @todo add fleet sharing */
272272
if (offer.rewardISK)
273-
AccountService::TranserFunds(m_agent->GetID(), pchar->itemID(), offer.rewardISK, "Mission Reward", Journal::EntryType::AgentMissionReward, m_agent->GetID());
273+
AccountService::TransferFunds(m_agent->GetID(), pchar->itemID(), offer.rewardISK, "Mission Reward", Journal::EntryType::AgentMissionReward, m_agent->GetID());
274274
if ((offer.bonusTime > 0) and (offer.bonusTime < (offer.dateAccepted - GetFileTimeNow())))
275-
AccountService::TranserFunds(m_agent->GetID(), pchar->itemID(), offer.bonusISK, "Mission Bonus Reward", Journal::EntryType::AgentMissionTimeBonusReward, m_agent->GetID());
275+
AccountService::TransferFunds(m_agent->GetID(), pchar->itemID(), offer.bonusISK, "Mission Bonus Reward", Journal::EntryType::AgentMissionTimeBonusReward, m_agent->GetID());
276276
/** @todo add lp, etc, etc */
277277
if (offer.rewardLP)
278278
LPService::AddLP(pchar->itemID(), m_agent->GetCorpID(), offer.rewardLP);

src/eve-server/character/CharMgrService.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,7 @@ PyResult CharMgrService::GetPublicInfo(PyCallArgs &call, PyInt* ownerID) {
239239
return result;
240240
}
241241

242-
PyResult CharMgrService::AddToBounty(PyCallArgs& call, PyInt* characterID, PyInt* amount)
243-
{
242+
PyResult CharMgrService::AddToBounty(PyCallArgs& call, PyInt* characterID, PyInt* amount) {
244243
if (call.client->GetCharacterID() == characterID->value()){
245244
call.client->SendErrorMsg("You cannot put a bounty on yourself.");
246245
return nullptr;
@@ -249,7 +248,7 @@ PyResult CharMgrService::AddToBounty(PyCallArgs& call, PyInt* characterID, PyInt
249248
if (amount->value() < call.client->GetBalance()) {
250249
std::string reason = "Placing Bounty on ";
251250
reason += m_db.GetCharName(characterID->value());
252-
AccountService::TranserFunds(call.client->GetCharacterID(), corpCONCORD, amount->value(), reason, Journal::EntryType::Bounty, characterID->value());
251+
AccountService::TransferFunds(call.client->GetCharacterID(), corpCONCORD, amount->value(), reason, Journal::EntryType::Bounty, characterID->value());
253252
m_db.AddBounty(characterID->value(), call.client->GetCharacterID(), amount->value());
254253
// new system gives target a mail from concord about placement of bounty and char name placing it.
255254
} else {

0 commit comments

Comments
 (0)