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

#include "TradeService.h"

Inheritance diagram for TradeService:
Collaboration diagram for TradeService:

Classes

struct  ActiveSession
 

Public Member Functions

 TradeService (PyServiceMgr *mgr)
 
virtual ~TradeService ()
 
uint32 GetTradeSessionID ()
 
void InitiateTrade (Client *pClient, PyRep *resp)
 
void RemoveActiveSession (uint32 myID)
 
void CancelTrade (Client *pClient)
 
void TransferContainerContents (SystemManager *pSysMgr, InventoryItemRef itemRef, uint32 newOwnerID)
 
- 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 ()
 

Public Attributes

std::map< uint32, ActiveSessionm_activeSessions
 

Protected Member Functions

virtual PyBoundObjectCreateBoundObject (Client *pClient, const PyRep *bind_args)
 
 PyCallable_DECL_CALL (InitiateTrade)
 
- Protected Member Functions inherited from PyService
PyObject_BuildCachedReturn (PySubStream **result, const char *sessionInfo, CacheCheckTime check)
 
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
 
PyServiceMgrm_SvcMgr
 
uint32 m_SessionID
 
- 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 36 of file TradeService.h.

Constructor & Destructor Documentation

TradeService::TradeService ( PyServiceMgr mgr)

Definition at line 98 of file TradeService.cpp.

References PyCallable::_SetCallDispatcher(), InitiateTrade(), m_dispatch, m_SessionID, m_SvcMgr, minTradeCont, and PyCallable_REG_CALL.

99 : PyService(mgr, "trademgr"),
100  m_dispatch(new Dispatcher(this))
101 {
102  m_SvcMgr = mgr;
105 
107 }
uint32 m_SessionID
Definition: TradeService.h:67
PyService(PyServiceMgr *mgr, const char *serviceName)
Definition: PyService.cpp:32
void _SetCallDispatcher(CallDispatcher *d)
Definition: PyCallable.h:87
void InitiateTrade(Client *pClient, PyRep *resp)
#define PyCallable_REG_CALL(c, m)
Definition: PyServiceCD.h:78
PyServiceMgr * m_SvcMgr
Definition: TradeService.h:61
Dispatcher *const m_dispatch
Definition: TradeService.h:59
#define minTradeCont
Definition: EVE_Defines.h:129

Here is the call graph for this function:

TradeService::~TradeService ( )
virtual

Definition at line 109 of file TradeService.cpp.

References m_dispatch.

109  {
110  delete m_dispatch;
111 }
Dispatcher *const m_dispatch
Definition: TradeService.h:59

Member Function Documentation

void TradeService::CancelTrade ( Client pClient)

Definition at line 678 of file TradeService.cpp.

References TradeBound::CancelTrade(), Client::ClearTradeSession(), TradeSession::Session::containerID, Client::GetTradeSession(), TradeSession::Session::herID, PyService::m_manager, TradeSession::m_tradeSession, TradeSession::Session::myID, PyIncRef, RemoveActiveSession(), SafeDelete(), Client::SendNotification(), sEntityList, and PyTuple::SetItem().

Referenced by Client::UndockFromStation(), and Client::~Client().

678  {
679  TradeSession* pTSes = pClient->GetTradeSession();
680  Client* pOther = sEntityList.FindClientByCharID(pTSes->m_tradeSession.herID);
681 
682  TradeBound* pTB = new TradeBound(m_manager);
683  pTB->CancelTrade(pClient, pOther, pTSes);
684 
685  PyTuple* tuple = new PyTuple(2);
686  tuple->SetItem(0, new PyString("Cancel"));
687  tuple->SetItem(1, new PyInt(pTSes->m_tradeSession.containerID));
688  PyIncRef(tuple);
689  // now send it, bypassing the extra shit and wrong dest name added in Client::SendNotification
690  pClient->SendNotification("OnTrade", "charid", &tuple);
691  pOther->SendNotification("OnTrade", "charid", &tuple);
694  SafeDelete(pTSes);
695  pClient->ClearTradeSession();
696  pOther->ClearTradeSession();
697  // returns none
698 }
void SendNotification(const PyAddress &dest, EVENotificationStream &noti, bool seq=true)
Definition: Client.cpp:2245
Python string.
Definition: PyRep.h:430
#define sEntityList
Definition: EntityList.h:208
Python tuple.
Definition: PyRep.h:567
void ClearTradeSession()
Definition: Client.h:310
void SafeDelete(T *&p)
Deletes and nullifies a pointer.
Definition: SafeMem.h:83
void SetItem(size_t index, PyRep *object)
Stores Python object.
Definition: PyRep.h:610
Python integer.
Definition: PyRep.h:231
Session m_tradeSession
Definition: TradeService.h:105
TradeSession * GetTradeSession()
Definition: Client.h:311
PyServiceMgr *const m_manager
Definition: PyService.h:91
Definition: Client.h:66
#define PyIncRef(op)
Definition: PyRep.h:56
void RemoveActiveSession(uint32 myID)
void CancelTrade(Client *pClient, Client *pOther, TradeSession *pTSes)

Here is the call graph for this function:

Here is the caller graph for this function:

PyBoundObject * TradeService::CreateBoundObject ( Client pClient,
const PyRep bind_args 
)
protectedvirtual
Todo:
update to multiple trade sessions per client. current code only allows one at a time.

Reimplemented from PyService.

Definition at line 113 of file TradeService.cpp.

References _log, args, PyRep::Clone(), codelog, TradeSession::Session::containerID, TradeService::ActiveSession::contID, TradeSession::Session::fileTime, PyService::GetName(), GetTradeSessionID(), TradeService::ActiveSession::herID, TradeSession::Session::herID, TradeSession::Session::herMoney, TradeSession::Session::herState, m_activeSessions, PyService::m_manager, TradeSession::m_tradeSession, TradeService::ActiveSession::myID, TradeSession::Session::myID, TradeSession::Session::myMoney, TradeSession::Session::myState, TradeService::ActiveSession::ourTS, Client::SetTradeSession(), TradeSession::Session::stationID, and EVEDB::invTypes::TradeSession.

113  {
114  // each client's trade session has it's own bound object.
115  // create code for multiple sessions per client, using TradeBound and TradeSession.
116  Trade_BindArgs args;
117  //crap
118  PyRep* tmp(bind_args->Clone());
119  if (!args.Decode(&tmp)) {
120  codelog(SERVICE__ERROR, "%s: Failed to decode bind args.", GetName());
121  return nullptr;
122  }
123 
124  _log(COLLECT__OTHER_DUMP, "Trade bind request for:");
125  args.Dump(COLLECT__OTHER_DUMP, " ");
126 
129  // check to see if this is target calling for a bound object. if not, create new session
130  std::map<uint32, ActiveSession>::iterator itr = m_activeSessions.find(args.myID);
131  if (itr == m_activeSessions.end()) {
132  TradeSession* pTSes = new TradeSession();
133  pClient->SetTradeSession(pTSes);
134  uint32 contID(GetTradeSessionID());
135  pTSes->m_tradeSession.containerID = contID;
136  pTSes->m_tradeSession.stationID = args.stationID;
137  pTSes->m_tradeSession.myID = args.myID;
138  pTSes->m_tradeSession.herID = args.herID;
139  pTSes->m_tradeSession.myState = false;
140  pTSes->m_tradeSession.herState = false;
141  pTSes->m_tradeSession.myMoney = args.myMoney;
142  pTSes->m_tradeSession.herMoney = args.herMoney;
143  pTSes->m_tradeSession.fileTime = args.fileTime;
144  ActiveSession cAS = ActiveSession();
145  cAS.myID = args.myID;
146  cAS.herID = args.herID;
147  cAS.contID = contID;
148  cAS.ourTS = pTSes;
149  m_activeSessions.insert(std::make_pair(args.myID, cAS));
150  m_activeSessions.insert(std::make_pair(args.herID, cAS));
151  } else {
152  pClient->SetTradeSession(itr->second.ourTS);
153  }
154 
155  TradeBound* pTB = new TradeBound(m_manager);
156  return pTB;
157 }
Base Python wire object.
Definition: PyRep.h:66
std::map< uint32, ActiveSession > m_activeSessions
Definition: TradeService.h:56
#define _log(type, fmt,...)
Definition: logsys.h:124
virtual PyRep * Clone() const =0
Clones object.
const char * GetName() const
Definition: PyService.h:54
uint32 GetTradeSessionID()
* args
#define codelog(type, fmt,...)
Definition: logsys.h:128
Session m_tradeSession
Definition: TradeService.h:105
PyServiceMgr *const m_manager
Definition: PyService.h:91
void SetTradeSession(TradeSession *ts)
Definition: Client.h:309
unsigned __int32 uint32
Definition: eve-compat.h:50

Here is the call graph for this function:

uint32 TradeService::GetTradeSessionID ( )

Definition at line 700 of file TradeService.cpp.

References m_SessionID, maxTradeCont, and minTradeCont.

Referenced by CreateBoundObject().

701 {
703  return ++m_SessionID;
704 
705  return (m_SessionID = minTradeCont);
706 }
uint32 m_SessionID
Definition: TradeService.h:67
#define maxTradeCont
Definition: EVE_Defines.h:130
#define minTradeCont
Definition: EVE_Defines.h:129

Here is the caller graph for this function:

void TradeService::InitiateTrade ( Client pClient,
PyRep resp 
)

Definition at line 665 of file TradeService.cpp.

References Client::GetCharacterID(), Client::SendNotification(), and PyTuple::SetItem().

Referenced by TradeService().

665  {
666  PyTuple* tuple = new PyTuple(3);
667  tuple->SetItem(0, new PyString("Initiate"));
668  tuple->SetItem(1, new PyInt(pClient->GetCharacterID()));
669  tuple->SetItem(2, resp);
670  // now send it, bypassing the extra shit and wrong dest name added in Client::SendNotification
671  pClient->SendNotification("OnTrade", "charid", &tuple);
672 }
void SendNotification(const PyAddress &dest, EVENotificationStream &noti, bool seq=true)
Definition: Client.cpp:2245
Python string.
Definition: PyRep.h:430
int32 GetCharacterID() const
Definition: Client.h:113
Python tuple.
Definition: PyRep.h:567
void SetItem(size_t index, PyRep *object)
Stores Python object.
Definition: PyRep.h:610
Python integer.
Definition: PyRep.h:231

Here is the call graph for this function:

Here is the caller graph for this function:

TradeService::PyCallable_DECL_CALL ( InitiateTrade  )
protected
void TradeService::RemoveActiveSession ( uint32  myID)

Definition at line 674 of file TradeService.cpp.

References m_activeSessions.

Referenced by CancelTrade().

674  {
675  m_activeSessions.erase(myID);
676 }
std::map< uint32, ActiveSession > m_activeSessions
Definition: TradeService.h:56

Here is the caller graph for this function:

void TradeService::TransferContainerContents ( SystemManager pSysMgr,
InventoryItemRef  itemRef,
uint32  newOwnerID 
)

Definition at line 598 of file TradeService.cpp.

References InventoryItem::categoryID(), ShipDB::DeleteInsuranceByShipID(), RefPtr< X >::get(), SystemManager::GetContainerFromInventory(), Inventory::GetInventoryMap(), InventoryItem::GetMyInventory(), SystemManager::GetShipFromInventory(), CargoContainer::IsEmpty(), InventoryItem::itemID(), EVEDB::invCategories::Ship, and sItemFactory.

Referenced by TradeBound::ExchangeItems().

599 {
600  std::map<uint32, InventoryItemRef> InventoryMap;
601  InventoryMap.clear();
602 
603  if (itemRef->categoryID() == EVEDB::invCategories::Ship) {
604  // if we change this to use shipItem, this will need rework
606  ShipItemRef shipRef = pSysMgr->GetShipFromInventory(itemRef->itemID());
607  if (shipRef.get() == nullptr)
608  shipRef = sItemFactory.GetShip(itemRef->itemID());
609  if (!shipRef->GetMyInventory()->IsEmpty())
610  shipRef->GetMyInventory()->GetInventoryMap(InventoryMap);
611  } else {
612  CargoContainerRef contRef = pSysMgr->GetContainerFromInventory(itemRef->itemID());
613  if (contRef.get() == nullptr)
614  contRef = sItemFactory.GetCargoContainer(itemRef->itemID());
615  if (!contRef->IsEmpty())
616  contRef->GetMyInventory()->GetInventoryMap(InventoryMap);
617  }
618 
619  for (auto cur : InventoryMap)
620  cur.second->ChangeOwner(newOwnerID, true);
621 }
ShipItemRef GetShipFromInventory(uint32 shipID)
CargoContainerRef GetContainerFromInventory(uint32 contID)
static void DeleteInsuranceByShipID(uint32 shipID)
Definition: ShipDB.cpp:65
X * get() const
Definition: RefPtr.h:213
#define sItemFactory
Definition: ItemFactory.h:165
uint8 categoryID() const
uint32 itemID() const
Definition: InventoryItem.h:98

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

std::map<uint32, ActiveSession> TradeService::m_activeSessions

Definition at line 56 of file TradeService.h.

Referenced by CreateBoundObject(), and RemoveActiveSession().

Dispatcher* const TradeService::m_dispatch
protected

Definition at line 59 of file TradeService.h.

Referenced by TradeService(), and ~TradeService().

uint32 TradeService::m_SessionID
protected

Definition at line 67 of file TradeService.h.

Referenced by GetTradeSessionID(), and TradeService().

PyServiceMgr* TradeService::m_SvcMgr
protected

Definition at line 61 of file TradeService.h.

Referenced by TradeService().


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