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

#include "NPCMarket.h"

Inheritance diagram for NPCMarket:
Collaboration diagram for NPCMarket:

Classes

struct  stationOrder
 

Public Member Functions

 NPCMarket ()
 
- Public Member Functions inherited from XMLParserEx
template<typename T >
void AddMemberParser (const char *name, T &instance, bool(T::*method)(const TiXmlElement *))
 Adds a member parser. More...
 
template<typename T >
void AddValueParser (const char *name, T &value)
 Adds a value parser. More...
 
- Public Member Functions inherited from XMLParser
 XMLParser ()
 Primary constructor. More...
 
virtual ~XMLParser ()
 A destructor. More...
 
bool ParseFile (const char *file)
 Parses file using registered parsers. More...
 
bool ParseElement (const TiXmlElement *element) const
 Parses element using registered parsers. More...
 
bool ParseElementChildren (const TiXmlElement *element, size_t max=0) const
 Parses element's children using registered parsers. More...
 
void AddParser (const char *name, ElementParser *parser)
 Adds a parser. More...
 
void RemoveParser (const char *name)
 Removes a parser. More...
 
void ClearParsers ()
 Clears all parsers. More...
 

Static Public Member Functions

static void CreateNPCMarketFromFile (std::string filename)
 

Private Member Functions

bool ProcessNPCOrders (const TiXmlElement *ele)
 
bool ProcessStation (const TiXmlElement *ele)
 
bool ProcessOrder (const TiXmlElement *ele)
 

Private Attributes

MarketDB m_db
 
uint32 StationID
 
struct NPCMarket::stationOrder order
 
std::list< stationOrdernewOrders
 

Additional Inherited Members

- Public Attributes inherited from XMLParser
std::unique_ptr< TiXmlDocument > m_pXML_Document
 
- Protected Member Functions inherited from XMLParserEx
template<typename T >
void AddMemberParser (const char *name, bool(T::*method)(const TiXmlElement *))
 Adds a member parser, assuming that instance is this. More...
 

Detailed Description

Definition at line 41 of file NPCMarket.h.

Constructor & Destructor Documentation

NPCMarket::NPCMarket ( )

Definition at line 11 of file NPCMarket.cpp.

References XMLParserEx::AddMemberParser(), and ProcessNPCOrders().

12 {
13  AddMemberParser("npcMarketOrders", &NPCMarket::ProcessNPCOrders);
14 }
bool ProcessNPCOrders(const TiXmlElement *ele)
Definition: NPCMarket.cpp:43
void AddMemberParser(const char *name, T &instance, bool(T::*method)(const TiXmlElement *))
Adds a member parser.
Definition: XMLParserEx.h:55

Here is the call graph for this function:

Member Function Documentation

void NPCMarket::CreateNPCMarketFromFile ( std::string  filename)
static

Process an xml file to create NPC market orders.

Parameters
filenamethe file to process, path relative to the server root directory.

Definition at line 16 of file NPCMarket.cpp.

References _log, DBerror::c_str(), XMLParser::ParseFile(), sDatabase, and sLog.

17 {
18  sLog.White("NPCMarket", "Regenerating NPC market from file %s", filename.c_str());
19  DBerror err;
20 
21  // delete all old market orders.
22  // TO-DO: make this safe for concurrency.
23  sLog.White("NPCMarket", "Deleting old NPC orders.");
24  if (!sDatabase.RunQuery(err, "DELETE FROM market_orders WHERE duration > 90"))
25  {
26  _log(MARKET__ERROR, "Error in query: %s.", err.c_str());
27  sLog.White("NPCMarket", "Failed to clear old NPC market.");
28  return;
29  }
30 
31  sLog.White("NPCMarket", "Reading NPC Market xml file %s", filename.c_str());
32  // Create a NPCMarket object to process the file.
33  NPCMarket npcMarket;
34  const char *NPC_MARKET_FILE = (std::string(EVEMU_ROOT) + filename).c_str();
35  // Process the file.
36  if (!npcMarket.ParseFile(NPC_MARKET_FILE))
37  {
38  sLog.Warning("Failed to generate NPC market from %s.", NPC_MARKET_FILE);
39  }
40  sLog.White("NPCMarket", "NPC market created from file %s", filename.c_str());
41 }
#define sDatabase
Definition: dbcore.h:199
#define _log(type, fmt,...)
Definition: logsys.h:124
bool ParseFile(const char *file)
Parses file using registered parsers.
Definition: XMLParser.cpp:44
#define sLog
Evaluates to a NewLog instance.
Definition: LogNew.h:250
const char * c_str() const
Definition: dbcore.h:48
Definition: dbcore.h:39

Here is the call graph for this function:

bool NPCMarket::ProcessNPCOrders ( const TiXmlElement *  ele)
private

Process the NPC Orders from the xml document.

Parameters
elethe xml element to process.
Returns
true if successful, false on error.

Definition at line 43 of file NPCMarket.cpp.

References XMLParserEx::AddMemberParser(), XMLParserEx::AddValueParser(), NPCMarket::stationOrder::Bid, order, XMLParser::ParseElementChildren(), NPCMarket::stationOrder::Price, ProcessOrder(), ProcessStation(), NPCMarket::stationOrder::Qty, XMLParser::RemoveParser(), StationID, and NPCMarket::stationOrder::TypeID.

Referenced by NPCMarket().

44 {
45  // add parsers for the child properties.
47  AddValueParser("StationID", StationID);
49  AddValueParser("TypeID", order.TypeID);
50  AddValueParser("Qty", order.Qty);
51  AddValueParser("Price", order.Price);
52  AddValueParser("Bid", order.Bid);
53  // parse the <npcMarketOrders> element
54  const bool result = ParseElementChildren(ele);
55  RemoveParser("TypeID");
56  RemoveParser("Qty");
57  RemoveParser("Price");
58  RemoveParser("Bid");
59  RemoveParser("Order");
60  RemoveParser("StationID");
61  RemoveParser("Station");
62  return result;
63 }
bool ProcessOrder(const TiXmlElement *ele)
Definition: NPCMarket.cpp:146
uint32 StationID
Definition: NPCMarket.h:61
bool ProcessStation(const TiXmlElement *ele)
Definition: NPCMarket.cpp:65
void RemoveParser(const char *name)
Removes a parser.
Definition: XMLParser.cpp:106
bool ParseElementChildren(const TiXmlElement *element, size_t max=0) const
Parses element's children using registered parsers.
Definition: XMLParser.cpp:72
void AddValueParser(const char *name, T &value)
Adds a value parser.
Definition: XMLParserEx.h:67
void AddMemberParser(const char *name, T &instance, bool(T::*method)(const TiXmlElement *))
Adds a member parser.
Definition: XMLParserEx.h:55
struct NPCMarket::stationOrder order

Here is the call graph for this function:

Here is the caller graph for this function:

bool NPCMarket::ProcessOrder ( const TiXmlElement *  ele)
private

Process the order entries from the xml document.

Parameters
elethe xml element to process.
Returns
true if successful, false on error.

Definition at line 146 of file NPCMarket.cpp.

References NPCMarket::stationOrder::Bid, newOrders, order, XMLParser::ParseElementChildren(), NPCMarket::stationOrder::Price, NPCMarket::stationOrder::Qty, and NPCMarket::stationOrder::TypeID.

Referenced by ProcessNPCOrders().

147 {
148  order.Price = 0;
149  order.Bid = 0;
150  order.TypeID = 0;
151  order.Qty = 0;
152  // parse the <order> element
153  const bool result = ParseElementChildren(ele);
154  // if all of the order information was found add it to the list of new orders.
155  if (order.Price != 0 && order.Qty != 0 && order.TypeID != 0)
156  newOrders.push_back(order);
157  return result;
158 }
std::list< stationOrder > newOrders
Definition: NPCMarket.h:87
bool ParseElementChildren(const TiXmlElement *element, size_t max=0) const
Parses element's children using registered parsers.
Definition: XMLParser.cpp:72
struct NPCMarket::stationOrder order

Here is the call graph for this function:

Here is the caller graph for this function:

bool NPCMarket::ProcessStation ( const TiXmlElement *  ele)
private

Process the station entries from the xml document.

Parameters
elethe xml element to process.
Returns
true if successful, false on error.

Definition at line 65 of file NPCMarket.cpp.

References _log, DBerror::c_str(), codelog, GetFileTimeNow(), newOrders, XMLParser::ParseElementChildren(), StationData::regionID, sDatabase, sLog, StationID, stDataMgr, and StationData::systemID.

Referenced by ProcessNPCOrders().

66 {
67  static int nStations = 0;
68  newOrders.clear();
69  StationID = 0;
70  // parse the <station> element
71  const bool result = ParseElementChildren(ele);
72  if(result == false)
73  return false;
74 
75  // done if there were no orders.
76  if (newOrders.size() == 0 || StationID == 0)
77  return true;
78 
79  // count how many stations have been found.
80  nStations++;
81  sLog.White("NPCMarket", "%d: Adding %d orders to stationID= %d", nStations, newOrders.size(), StationID);
82 
83  DBerror err;
84 
85  // get the solar system and region IDs.
86  StationData data = StationData();
87  if (!stDataMgr.GetStationData(StationID, data)) {
88  _log(DATA__ERROR, "Failed to retrieve data for station %u", StationID);
89  newOrders.clear();
90  // adding these market orders failed but that does not mean the xml is at fault.
91  // return a successful processing of the xml.
92  return true;
93  }
94 
95  uint32 orderID;
96  std::ostringstream values;
97  int64 trnTime = GetFileTimeNow();
98  bool first = true;
99  // create a single insert command to improve sql performance.
100  std::list<stationOrder>::iterator itr = newOrders.begin();
101  while (itr != newOrders.end())
102  {
103  if (!first)
104  values << ", ";
105  first = false;
106  values << "(";
107  values << (*itr).TypeID;
108  values << ", 0"; // clientID
109  values << ", " << data.regionID;
110  values << ", " << StationID;
111  values << ", 0"; // orderRange
112  values << ", " << (*itr).Bid;
113  values << ", " << (*itr).Price;
114  values << ", " << (*itr).Qty;
115  values << ", " << (*itr).Qty;
116  values << ", " << trnTime;
117  values << ", 1"; // minVolume
118  values << ", 0"; // contraband
119  values << ", 0"; // accountID
120  values << ", 365"; // duration
121  values << ", 0"; // isCorp
122  values << ", " << data.systemID;
123  values << ", 0"; // escrow
124  values << ", 1"; // jumps
125  values << ")";
126  itr++;
127  }
128  // process the sql command.
129  if (!sDatabase.RunQueryLID(err, orderID,
130  "INSERT INTO market_orders ("
131  " typeID, charID, regionID, stationID,"
132  " `range`, bid, price, volEntered, volRemaining, issued,"
133  " minVolume, contraband, accountID, duration,"
134  " isCorp, solarSystemID, escrow, jumps "
135  " ) VALUES %s",
136  values.str().c_str()
137  ))
138  {
139  codelog(MARKET__ERROR, "Error in query: %s", err.c_str());
140  }
141  newOrders.clear();
142 
143  return true;
144 }
#define sDatabase
Definition: dbcore.h:199
#define _log(type, fmt,...)
Definition: logsys.h:124
#define stDataMgr
std::list< stationOrder > newOrders
Definition: NPCMarket.h:87
#define sLog
Evaluates to a NewLog instance.
Definition: LogNew.h:250
uint32 StationID
Definition: NPCMarket.h:61
const char * c_str() const
Definition: dbcore.h:48
#define codelog(type, fmt,...)
Definition: logsys.h:128
unsigned __int32 uint32
Definition: eve-compat.h:50
double GetFileTimeNow()
Definition: utils_time.cpp:84
signed __int64 int64
Definition: eve-compat.h:51
bool ParseElementChildren(const TiXmlElement *element, size_t max=0) const
Parses element's children using registered parsers.
Definition: XMLParser.cpp:72
Definition: dbcore.h:39

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

MarketDB NPCMarket::m_db
private

Access to the market database information.

Definition at line 57 of file NPCMarket.h.

std::list<stationOrder> NPCMarket::newOrders
private

A list of orders retrieved for the current station.

Definition at line 87 of file NPCMarket.h.

Referenced by ProcessOrder(), and ProcessStation().

struct NPCMarket::stationOrder NPCMarket::order
private

Referenced by ProcessNPCOrders(), and ProcessOrder().

uint32 NPCMarket::StationID
private

Container for the retrieved station ID.

Definition at line 61 of file NPCMarket.h.

Referenced by ProcessNPCOrders(), and ProcessStation().


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