Added the SwgDatabaseServer project, still need to handle generated files

This commit is contained in:
Anonymous
2014-01-17 07:02:57 -07:00
parent 63ccf4eb43
commit 84d3709fdc
220 changed files with 21265 additions and 0 deletions
@@ -0,0 +1,180 @@
// ======================================================================
//
// AuctionLocationsBuffer.cpp
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#include "SwgDatabaseServer/FirstSwgDatabaseServer.h"
#include "SwgDatabaseServer/AuctionLocationsBuffer.h"
#include "SwgDatabaseServer/CommoditiesQuery.h"
#include "SwgDatabaseServer/CommoditiesSchema.h"
#include "serverGame/ServerPlayerObjectTemplate.h"
#include "sharedDatabaseInterface/DbSession.h"
#include "sharedLog/Log.h"
#include <vector>
// ======================================================================
AuctionLocationsBuffer::AuctionLocationsBuffer(DB::ModeQuery::Mode mode) :
AbstractTableBuffer(),
m_mode(mode),
m_rows()
{
}
// ----------------------------------------------------------------------
AuctionLocationsBuffer::~AuctionLocationsBuffer(void)
{
for (IndexType::iterator i=m_rows.begin(); i!=m_rows.end(); ++i)
{
delete i->second;
i->second=NULL;
}
}
// ----------------------------------------------------------------------
bool AuctionLocationsBuffer::load(DB::Session *session, const DB::TagSet &tags, const std::string &schema, bool usingGoldDatabase)
{
return true;
}
// ----------------------------------------------------------------------
void AuctionLocationsBuffer::removeObject(const NetworkId &object)
{
removeAuctionLocations(object);
}
// ----------------------------------------------------------------------
void AuctionLocationsBuffer::removeAuctionLocations(const NetworkId &locationId)
{
IndexType::iterator i=m_rows.find(locationId);
if (i!=m_rows.end())
{
delete i->second;
i->second=NULL;
m_rows.erase(i);
}
}
// ----------------------------------------------------------------------
void AuctionLocationsBuffer::setAuctionLocations(const NetworkId &locationId)
{
DBSchema::AuctionLocationsRow *row=findRowByIndex(locationId);
if (!row)
{
row=new DBSchema::AuctionLocationsRow;
addRowToIndex(locationId, row);
}
row->location_id = locationId;
}
// ----------------------------------------------------------------------
void AuctionLocationsBuffer::setAuctionLocations(const NetworkId &locationId, const std::string &locationName, const int salesTax, const NetworkId &salesTaxBankId, const int emptyDate, const int lastAccessDate, const int inactiveDate, const int status, const bool searchEnabled, const int entranceCharge)
{
DBSchema::AuctionLocationsRow *row=findRowByIndex(locationId);
if (!row)
{
row=new DBSchema::AuctionLocationsRow;
addRowToIndex(locationId, row);
}
row->location_id = locationId;
row->location_name = locationName;
row->sales_tax = salesTax;
row->sales_tax_bank_id = salesTaxBankId;
row->empty_date = emptyDate;
row->last_access_date = lastAccessDate;
row->inactive_date = inactiveDate;
row->status = status;
row->search_enabled = searchEnabled;
row->entrance_charge = entranceCharge;
}
// ----------------------------------------------------------------------
void AuctionLocationsBuffer::setAuctionLocations(const NetworkId &locationId, const std::string &locationName, const NetworkId &ownerId, const int salesTax, const NetworkId &salesTaxBankId, const int emptyDate, const int lastAccessDate, const int inactiveDate, const int status, const bool searchEnabled, const int entranceCharge)
{
DBSchema::AuctionLocationsRow *row=findRowByIndex(locationId);
if (!row)
{
row=new DBSchema::AuctionLocationsRow;
addRowToIndex(locationId, row);
}
row->location_id = locationId;
row->location_name = locationName;
row->owner_id = ownerId;
row->sales_tax = salesTax;
row->sales_tax_bank_id = salesTaxBankId;
row->empty_date = emptyDate;
row->last_access_date = lastAccessDate;
row->inactive_date = inactiveDate;
row->status = status;
row->search_enabled = searchEnabled;
row->entrance_charge = entranceCharge;
}
// ----------------------------------------------------------------------
DBSchema::AuctionLocationsRow * AuctionLocationsBuffer::findRowByIndex(const NetworkId &locationId)
{
IndexType::iterator i=m_rows.find(locationId);
if (i==m_rows.end())
return 0;
else
return (*i).second;
}
// ----------------------------------------------------------------------
void AuctionLocationsBuffer::addRowToIndex (const NetworkId &locationId, DBSchema::AuctionLocationsRow *row)
{
m_rows[locationId]=row;
}
// ----------------------------------------------------------------------
bool AuctionLocationsBuffer::save(DB::Session *session)
{
LOG("SaveCounts",("AuctionLocations: %i saved to db",m_rows.size()));
DEBUG_REPORT_LOG(true, ("Saving Auctions Locations Buffer. mode:%d rowcount:%d\n", m_mode, m_rows.size()));
DBQuery::AuctionLocationsQuery qry;
if (m_mode==DB::ModeQuery::mode_INSERT)
qry.insertMode();
else if (m_mode == DB::ModeQuery::mode_UPDATE)
qry.updateMode();
else
qry.deleteMode();
if (!qry.setupData(session))
return false;
for (IndexType::iterator i=m_rows.begin(); i!=m_rows.end(); ++i)
{
if (!qry.addData(i->second))
return false;
if (qry.getNumItems() >= AuctionLocationsTableBufferNamespace::ms_maxItemsPerExec)
{
if (! (session->exec(&qry)))
return false;
qry.clearData();
}
}
if (qry.getNumItems() != 0)
if (! (session->exec(&qry)))
return false;
qry.done();
qry.freeData();
return true;
}
// ======================================================================
@@ -0,0 +1,65 @@
// ======================================================================
//
// AuctionLocationsBuffer.h
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#ifndef INCLUDED_AuctionLocationsBuffer_H
#define INCLUDED_AuctionLocationsBuffer_H
// ======================================================================
#include "SwgDatabaseServer/CommoditiesQuery.h"
#include "SwgDatabaseServer/CommoditiesSchema.h"
#include "serverDatabase/AbstractTableBuffer.h"
#include <map>
#include <string>
// ======================================================================
namespace AuctionLocationsTableBufferNamespace
{
const int ms_maxItemsPerExec = 10000;
}
using namespace AuctionLocationsTableBufferNamespace;
// ======================================================================
class AuctionLocationsBuffer : public AbstractTableBuffer
{
public:
explicit AuctionLocationsBuffer (DB::ModeQuery::Mode mode);
virtual ~AuctionLocationsBuffer ();
virtual bool load(DB::Session *session, const DB::TagSet &tags, const std::string &schema, bool usingGoldDatabase);
virtual bool save(DB::Session *session);
DBSchema::AuctionLocationsRow * findRowByIndex (const NetworkId &locationId);
void setAuctionLocations (const NetworkId &locationId);
void setAuctionLocations (const NetworkId &locationId, const std::string &locationName, const int salesTax, const NetworkId &salesTaxBankId, const int emptyDate, const int lastAccessDate, const int inactiveDate, const int status, const bool searchEnabled, const int entranceCharge);
void setAuctionLocations (const NetworkId &locationId, const std::string &locationName, const NetworkId &ownerId, const int salesTax, const NetworkId &salesTaxBankId, const int emptyDate, const int lastAccessDate, const int inactiveDate, const int status, const bool searchEnabled, const int entranceCharge);
void removeAuctionLocations (const NetworkId &locationId);
virtual void removeObject (const NetworkId &object);
private:
void addRowToIndex (const NetworkId &locationId, DBSchema::AuctionLocationsRow *row);
private:
typedef std::map<NetworkId, DBSchema::AuctionLocationsRow*> IndexType;
DB::ModeQuery::Mode m_mode;
IndexType m_rows;
private:
AuctionLocationsBuffer(); //disable
AuctionLocationsBuffer(const AuctionLocationsBuffer&); //disable
AuctionLocationsBuffer & operator=(const AuctionLocationsBuffer&); //disable
}; //lint !e1712 // IndexKey has no default constructor
// ======================================================================
#endif
@@ -0,0 +1,165 @@
// ======================================================================
//
// BattlefieldParticipantBuffer.cpp
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#include "SwgDatabaseServer/FirstSwgDatabaseServer.h"
#include "SwgDatabaseServer/BattlefieldParticipantBuffer.h"
#include "SwgDatabaseServer/BattlefieldParticipantQuery.h"
#include "SwgDatabaseServer/Schema.h"
#include "serverGame/ServerBattlefieldMarkerObjectTemplate.h"
#include "sharedDatabaseInterface/DbSession.h"
#include "sharedLog/Log.h"
// ======================================================================
BattlefieldParticipantBuffer::BattlefieldParticipantBuffer(DB::ModeQuery::Mode mode) :
AbstractTableBuffer(),
m_rows(),
m_mode(mode)
{
}
// ----------------------------------------------------------------------
BattlefieldParticipantBuffer::~BattlefieldParticipantBuffer(void)
{
for (IndexType::iterator i=m_rows.begin(); i!=m_rows.end(); ++i)
{
delete i->second;
i->second=NULL;
}
}
// ----------------------------------------------------------------------
void BattlefieldParticipantBuffer::setParticipantForRegion(const NetworkId &regionObjectId, const NetworkId &characterObjectId, uint32 factionId)
{
DBSchema::BattlefieldParticipantRow *row=findRowByIndex(regionObjectId,characterObjectId);
if (!row)
{
row=new DBSchema::BattlefieldParticipantRow;
addRowToIndex(regionObjectId,characterObjectId,row);
}
row->region_object_id = regionObjectId;
row->character_object_id = characterObjectId;
row->faction_id = static_cast<int>(factionId);
}
// ----------------------------------------------------------------------
bool BattlefieldParticipantBuffer::getParticipantsForRegion(const NetworkId &objectId, std::vector<std::pair<NetworkId, uint32> > &values) const
{
DEBUG_FATAL(values.size()!=0,("Values vector should be empty on call to getBattlefieldParticipantForRegion()\n"));
IndexType::const_iterator i ( m_rows.lower_bound(IndexKey(objectId,NetworkId::cms_invalid)) );
if (i==m_rows.end())
return false;
for (; (i!=m_rows.end()) && (((*i).second)->region_object_id.getValue()==objectId); ++i)
{
NetworkId temp;
(*i).second->character_object_id.getValue(temp);
values.push_back(std::pair<NetworkId, uint32>(temp, static_cast<uint32>((*i).second->faction_id.getValue())));
}
return true;
}
// ----------------------------------------------------------------------
DBSchema::BattlefieldParticipantRow * BattlefieldParticipantBuffer::findRowByIndex(const NetworkId &regionObjectId, const NetworkId &characterObjectId)
{
IndexType::iterator i=m_rows.find(IndexKey(regionObjectId,characterObjectId));
if (i==m_rows.end())
return 0;
else
return (*i).second;
}
// ----------------------------------------------------------------------
void BattlefieldParticipantBuffer::addRowToIndex (const NetworkId &regionObjectId, const NetworkId &characterObjectId, DBSchema::BattlefieldParticipantRow *row)
{
m_rows[IndexKey(regionObjectId,characterObjectId)]=row;
}
// ----------------------------------------------------------------------
/**
* Load the attributes for all the remembered objectId's.
*/
bool BattlefieldParticipantBuffer::load(DB::Session *session, const DB::TagSet &tags, const std::string &schema, bool)
{
int rowsFetched = 0;
if (tags.find(static_cast<Tag>(ServerBattlefieldMarkerObjectTemplate::ServerBattlefieldMarkerObjectTemplate_tag)) != tags.end())
{
DBQuery::GetAllBattlefieldParticipant qry(schema);
if (! (session->exec(&qry)))
return false;
while ((rowsFetched = qry.fetch()) > 0)
{
size_t numRows = qry.getNumRowsFetched();
size_t count = 0;
const std::vector<DBSchema::BattlefieldParticipantRow> &data = qry.getData();
for (std::vector<DBSchema::BattlefieldParticipantRow>::const_iterator i=data.begin(); i!=data.end(); ++i)
{
if (++count > numRows)
break;
DBSchema::BattlefieldParticipantRow *row=new DBSchema::BattlefieldParticipantRow(*i);
NOT_NULL(row);
NetworkId temp;
row->character_object_id.getValue(temp);
addRowToIndex(row->region_object_id.getValue(),temp,row);
}
}
qry.done();
}
return (rowsFetched >= 0);
}
// ----------------------------------------------------------------------
bool BattlefieldParticipantBuffer::save(DB::Session *session)
{
LOG("SaveCounts",("BattlefieldParticipants: %i saved to db",m_rows.size()));
DBQuery::BattlefieldParticipantQuery qry;
if (m_mode==DB::ModeQuery::mode_INSERT)
qry.insertMode();
else
qry.updateMode();
for (IndexType::iterator i=m_rows.begin(); i!=m_rows.end(); ++i)
{
qry.setData(*(i->second));
if (! (session->exec(&qry)))
return false;
}
qry.done();
return true;
}
// ----------------------------------------------------------------------
void BattlefieldParticipantBuffer::removeObject(const NetworkId &object)
{
IndexType::iterator i=m_rows.lower_bound(IndexKey(object,NetworkId::cms_invalid));
while (i!=m_rows.end() && i->first.m_regionObjectId==object)
{
IndexType::iterator next=i;
++next;
delete i->second;
i->second=NULL;
m_rows.erase(i);
i=next;
}
}
// ======================================================================
@@ -0,0 +1,102 @@
// ======================================================================
//
// BattlefieldParticipantBuffer.h
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#ifndef INCLUDED_BattlefieldParticipantBuffer_H
#define INCLUDED_BattlefieldParticipantBuffer_H
// ======================================================================
#include <map>
#include <string>
#include "serverDatabase/TableBuffer.h"
#include "SwgDatabaseServer/BattlefieldParticipantQuery.h"
#include "SwgDatabaseServer/Schema.h"
// ======================================================================
class BattlefieldParticipantBuffer : public AbstractTableBuffer
{
public:
explicit BattlefieldParticipantBuffer (DB::ModeQuery::Mode mode);
virtual ~BattlefieldParticipantBuffer ();
virtual bool load (DB::Session *session, const DB::TagSet &tags, const std::string &schema, bool usingGoldDatabase);
virtual bool save (DB::Session *session);
virtual void removeObject (const NetworkId &object);
DBSchema::BattlefieldParticipantRow * findRowByIndex (const NetworkId &regionObjectId, const NetworkId &characterObjectId);
void setParticipantForRegion (const NetworkId &regionObjectId, const NetworkId &characterObjectId, uint32 factionId);
void removeParticipantForRegion (const NetworkId &regionObjectId, const NetworkId &characterObjectId);
bool getParticipantsForRegion (const NetworkId &regionObjectId, std::vector<std::pair<NetworkId, uint32> > &values) const;
private:
void addRowToIndex (const NetworkId &regionObjectId, const NetworkId &characterObjectId, DBSchema::BattlefieldParticipantRow *row);
private:
struct IndexKey
{
NetworkId m_regionObjectId;
NetworkId m_characterObjectId;
IndexKey(const NetworkId &regionObjectId, const NetworkId &characterObjectId);
bool operator==(const IndexKey &rhs) const;
};
struct IndexSorter
{
bool operator() (const IndexKey &left, const IndexKey &right) const;
};
typedef std::map<IndexKey,DBSchema::BattlefieldParticipantRow*,IndexSorter> IndexType;
IndexType m_rows;
DB::ModeQuery::Mode m_mode;
private:
BattlefieldParticipantBuffer(); //disable
BattlefieldParticipantBuffer(const BattlefieldParticipantBuffer&); //disable
BattlefieldParticipantBuffer & operator=(const BattlefieldParticipantBuffer&); //disable
}; //lint !e1712 // IndexKey has no default constructor
// ======================================================================
inline BattlefieldParticipantBuffer::IndexKey::IndexKey(const NetworkId &regionObjectId, const NetworkId &characterObjectId) :
m_regionObjectId(regionObjectId),
m_characterObjectId(characterObjectId)
{
}
// ----------------------------------------------------------------------
inline bool BattlefieldParticipantBuffer::IndexKey::operator==(const IndexKey &rhs) const
{
return ((m_regionObjectId == rhs.m_regionObjectId) && (m_characterObjectId == rhs.m_characterObjectId));
}
// ----------------------------------------------------------------------
inline bool BattlefieldParticipantBuffer::IndexSorter::operator() (const IndexKey &left, const IndexKey &right) const
{
if (left.m_regionObjectId == right.m_regionObjectId)
return (left.m_characterObjectId < right.m_characterObjectId);
else
return (left.m_regionObjectId < right.m_regionObjectId);
}
// ----------------------------------------------------------------------
/**
* Removing a battlefield participant is the same as setting it to 0. (The database package
* will delete the row if faction_id == 0.)
*/
inline void BattlefieldParticipantBuffer::removeParticipantForRegion(const NetworkId &regionObjectId, const NetworkId &characterObjectId)
{
setParticipantForRegion(regionObjectId,characterObjectId,0);
}
// ======================================================================
#endif
@@ -0,0 +1,184 @@
// ======================================================================
//
// BountyHunterTargetBuffer.cpp
// copyright (c) 2004 Sony Online Entertainment
//
// ======================================================================
#include "SwgDatabaseServer/FirstSwgDatabaseServer.h"
#include "SwgDatabaseServer/BountyHunterTargetBuffer.h"
#include "SwgDatabaseServer/BountyHunterTargetQuery.h"
#include "SwgDatabaseServer/Schema.h"
#include "serverDatabase/ConfigServerDatabase.h"
#include "serverDatabase/GameServerConnection.h"
#include "serverGame/ServerPlanetObjectTemplate.h"
#include "sharedDatabaseInterface/DbSession.h"
#include "sharedLog/Log.h"
// ======================================================================
BountyHunterTargetBuffer::BountyHunterTargetBuffer() :
AbstractTableBuffer(),
m_data()
{
}
// ----------------------------------------------------------------------
BountyHunterTargetBuffer::~BountyHunterTargetBuffer()
{
for (DataType::iterator i=m_data.begin(); i!=m_data.end(); ++i)
{
delete i->second;
i->second=NULL;
}
}
// ----------------------------------------------------------------------
void BountyHunterTargetBuffer::setBountyHunterTarget(const NetworkId &objectId, const NetworkId &targetId)
{
DBSchema::BountyHunterTargetRow *row=findRowByIndex(objectId);
if (!row)
{
row=new DBSchema::BountyHunterTargetRow;
addRowToIndex(objectId, row);
}
row->object_id = objectId;
row->target_id = targetId;
}
// ----------------------------------------------------------------------
void BountyHunterTargetBuffer::sendBountyHunterTargetMessage(GameServerConnection & conn) const
{
if (m_data.empty())
return;
std::vector< std::pair< NetworkId, NetworkId > > targetList;
for (DataType::const_iterator row = m_data.begin(); row != m_data.end(); ++row)
{
NOT_NULL(row->second);
NetworkId objectId;
NetworkId targetId;
row->second->object_id.getValue(objectId);
row->second->target_id.getValue(targetId);
targetList.push_back(std::make_pair(objectId, targetId));
}
DEBUG_REPORT_LOG(true,("Sending BountyHunterTargetsList\n"));
BountyHunterTargetListMessage msg(targetList);
conn.send(msg,true);
}
// ----------------------------------------------------------------------
DBSchema::BountyHunterTargetRow * BountyHunterTargetBuffer::findRowByIndex(const NetworkId &objectId)
{
DataType::iterator i=m_data.find(objectId);
if (i==m_data.end())
return 0;
else
return (*i).second;
}
// ----------------------------------------------------------------------
void BountyHunterTargetBuffer::addRowToIndex (const NetworkId &objectId, DBSchema::BountyHunterTargetRow *row)
{
m_data[objectId]=row;
}
// ----------------------------------------------------------------------
bool BountyHunterTargetBuffer::save(DB::Session *session)
{
bool rval = true;
if (m_data.empty())
return true;
int actualSaves=0;
DBQuery::BountyHunterTargetQuery qry;
if (!qry.setupData(session))
return false;
for (DataType::const_iterator i=m_data.begin(); i!=m_data.end(); ++i)
{
++actualSaves;
NOT_NULL(i->second);
if (!qry.addData(*(i->second)))
return false;
if (qry.getNumItems() == ConfigServerDatabase::getDefaultMessageBulkBindSize())
{
if (! (session->exec(&qry)))
return false;
qry.clearData();
}
}
if (qry.getNumItems() != 0)
rval = session->exec(&qry);
qry.done();
qry.freeData();
LOG("SaveCounts",("BountyHunterTargets: %i saved in db",actualSaves));
return rval;
}
// ----------------------------------------------------------------------
bool BountyHunterTargetBuffer::load(DB::Session *session, const DB::TagSet &tags, const std::string &schema, bool usingGoldDatabase)
{
int rowsFetched = 0;
// Only load Bounty Hunter Target data if the planets are being loaded
if (tags.find(ServerPlanetObjectTemplate::ServerPlanetObjectTemplate_tag)!=tags.end())
{
DEBUG_REPORT_LOG(true,("Loading BountyHunterTargets\n"));
DBQuery::BountyHunterTargetQuerySelect qry(schema);
if (! (session->exec(&qry)))
return false;
while ((rowsFetched = qry.fetch()) > 0)
{
size_t const numRows = qry.getNumRowsFetched();
size_t count = 0;
std::vector<DBSchema::BountyHunterTargetRow> const & data = qry.getData();
for (std::vector<DBSchema::BountyHunterTargetRow>::const_iterator i=data.begin(); i!=data.end(); ++i)
{
if (++count > numRows)
break;
DBSchema::BountyHunterTargetRow *row=new DBSchema::BountyHunterTargetRow(*i);
NOT_NULL(row);
NetworkId temp;
row->object_id.getValue(temp);
m_data.insert(std::make_pair(row->object_id.getValue(), row));
}
}
qry.done();
}
return (rowsFetched >= 0);
}
// ----------------------------------------------------------------------
void BountyHunterTargetBuffer::removeObject(const NetworkId &object)
{
DBSchema::BountyHunterTargetRow *row=findRowByIndex(object);
if (row)
{
const NetworkId zeroNetworkId(static_cast<NetworkId::NetworkIdType>(0));
row->object_id = object;
row->target_id = zeroNetworkId;
}
}
// ======================================================================
@@ -0,0 +1,59 @@
// ======================================================================
//
// BountyHunterTargetBuffer.h
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#ifndef INCLUDED_BountyHunterTargetBuffer_H
#define INCLUDED_BountyHunterTargetBuffer_H
// ======================================================================
#include "serverDatabase/AbstractTableBuffer.h"
#include "serverNetworkMessages/BountyHunterTargetListMessage.h"
#include "serverNetworkMessages/BountyHunterTargetMessage.h"
// ======================================================================
namespace DB
{
class Session;
}
namespace DBSchema
{
struct BountyHunterTargetRow;
}
class GameServerConnection;
// ======================================================================
/**
* A buffer to hold bounty hunter target data.
*/
class BountyHunterTargetBuffer : public AbstractTableBuffer
{
public:
void setBountyHunterTarget (const NetworkId &objectId, const NetworkId &targetId);
void sendBountyHunterTargetMessage (GameServerConnection & conn) const;
virtual bool save(DB::Session *session);
virtual bool load(DB::Session *session, const DB::TagSet &tags, const std::string &schema, bool usingGoldDatabase);
virtual void removeObject(const NetworkId &object);
DBSchema::BountyHunterTargetRow * findRowByIndex (const NetworkId &objectId);
public:
BountyHunterTargetBuffer();
virtual ~BountyHunterTargetBuffer();
private:
void addRowToIndex (const NetworkId &objectId, DBSchema::BountyHunterTargetRow *row);
typedef std::map<NetworkId, DBSchema::BountyHunterTargetRow*> DataType;
DataType m_data;
};
// ======================================================================
#endif
@@ -0,0 +1,249 @@
// ======================================================================
//
// CreatureObjectBuffer.cpp
// copyright (c) 2003 Sony Online Entertainment
//
// ======================================================================
#include "SwgDatabaseServer/FirstSwgDatabaseServer.h"
#include "SwgDatabaseServer/CreatureObjectBuffer.h"
#include "serverNetworkMessages/UpdateObjectPositionMessage.h"
#include "sharedLog/Log.h"
// ======================================================================
CreatureObjectBuffer::CreatureObjectBuffer(DB::ModeQuery::Mode mode) :
IndexedNetworkTableBuffer<DBSchema::CreatureObjectBufferRow, DBSchema::CreatureObjectRow, DBQuery::CreatureObjectQuery, DBQuery::CreatureObjectQuerySelect>(mode)
{
}
// ----------------------------------------------------------------------
bool CreatureObjectBuffer::handleUpdateObjectPosition(const UpdateObjectPositionMessage &message)
{
DBSchema::CreatureObjectBufferRow *row=dynamic_cast<DBSchema::CreatureObjectBufferRow*>(findRowByIndex(message.getNetworkId()));
if (row==0)
{
row=addEmptyRow(message.getNetworkId());
}
Vector v = message.getWorldspaceTransform().getPosition_p();
row->ws_x = static_cast<double>(v.x);
row->ws_y = static_cast<double>(v.y);
row->ws_z = static_cast<double>(v.z);
return true;
}
// ----------------------------------------------------------------------
void CreatureObjectBuffer::setAttribute(const NetworkId &objectId, Attributes::Enumerator type, Attributes::Value value)
{
DBSchema::CreatureObjectBufferRow *row=dynamic_cast<DBSchema::CreatureObjectBufferRow*>(findRowByIndex(objectId));
if (row==0)
{
row=addEmptyRow(objectId);
}
switch (type)
{
case 0:
row->attribute_0=value;
break;
case 1:
row->attribute_1=value;
break;
case 2:
row->attribute_2=value;
break;
case 3:
row->attribute_3=value;
break;
case 4:
row->attribute_4=value;
break;
case 5:
row->attribute_5=value;
break;
case 6:
row->attribute_6=value;
break;
case 7:
row->attribute_7=value;
break;
case 8:
row->attribute_8=value;
break;
case 9:
row->attribute_9=value;
break;
case 10:
row->attribute_10=value;
break;
case 11:
row->attribute_11=value;
break;
case 12:
row->attribute_12=value;
break;
case 13:
row->attribute_13=value;
break;
case 14:
row->attribute_14=value;
break;
case 15:
row->attribute_15=value;
break;
case 16:
row->attribute_16=value;
break;
case 17:
row->attribute_17=value;
break;
case 18:
row->attribute_18=value;
break;
case 19:
row->attribute_19=value;
break;
case 20:
row->attribute_20=value;
break;
case 21:
row->attribute_21=value;
break;
case 22:
row->attribute_22=value;
break;
case 23:
row->attribute_23=value;
break;
case 24:
row->attribute_24=value;
break;
case 25:
row->attribute_25=value;
break;
case 26:
row->attribute_26=value;
break;
default:
WARNING_STRICT_FATAL(true,("Programmer bug: setAttribute(%s, %i, %i): %i is not a valid attribute identifier",objectId.getValueString().c_str(), type, value, type));
}
}
// ----------------------------------------------------------------------
/**
* Retreive a range of attributes for an object
*/
void CreatureObjectBuffer::getAttributesForObject(const NetworkId &objectId, std::vector<Attributes::Value> &values, int offset, int howMany) const
{
const DBSchema::CreatureObjectBufferRow *row=dynamic_cast<const DBSchema::CreatureObjectBufferRow*>(findConstRowByIndex(objectId));
for (int position=offset; position<offset+howMany; ++position)
{
int value=0;
switch(position)
{
case 0:
row->attribute_0.getValue(value);
break;
case 1:
row->attribute_1.getValue(value);
break;
case 2:
row->attribute_2.getValue(value);
break;
case 3:
row->attribute_3.getValue(value);
break;
case 4:
row->attribute_4.getValue(value);
break;
case 5:
row->attribute_5.getValue(value);
break;
case 6:
row->attribute_6.getValue(value);
break;
case 7:
row->attribute_7.getValue(value);
break;
case 8:
row->attribute_8.getValue(value);
break;
case 9:
row->attribute_9.getValue(value);
break;
case 10:
row->attribute_10.getValue(value);
break;
case 11:
row->attribute_11.getValue(value);
break;
case 12:
row->attribute_12.getValue(value);
break;
case 13:
row->attribute_13.getValue(value);
break;
case 14:
row->attribute_14.getValue(value);
break;
case 15:
row->attribute_15.getValue(value);
break;
case 16:
row->attribute_16.getValue(value);
break;
case 17:
row->attribute_17.getValue(value);
break;
case 18:
row->attribute_18.getValue(value);
break;
case 19:
row->attribute_19.getValue(value);
break;
case 20:
row->attribute_20.getValue(value);
break;
case 21:
row->attribute_21.getValue(value);
break;
case 22:
row->attribute_22.getValue(value);
break;
case 23:
row->attribute_23.getValue(value);
break;
case 24:
row->attribute_24.getValue(value);
break;
case 25:
row->attribute_25.getValue(value);
break;
case 26:
row->attribute_26.getValue(value);
break;
default:
FATAL(true,("Programmer bug: getAttributesForObject(%s, &values, %i, %i): attempted to read attribute %i, which is out of range",objectId.getValueString().c_str(),offset, howMany, position));
}
if (value == -999)
{
WARNING(true,("Object %s had null attribute %i, defaulting to 100",objectId.getValueString().c_str(), position));
value = 100;
}
values.push_back(static_cast<Attributes::Value>(value));
}
}
// ======================================================================
@@ -0,0 +1,35 @@
// ======================================================================
//
// CreatureObjectBuffer.h
// copyright (c) 2003 Sony Online Entertainment
//
// ======================================================================
#ifndef INCLUDED_CreatureObjectBuffer_H
#define INCLUDED_CreatureObjectBuffer_H
// ======================================================================
#include "SwgDatabaseServer/IndexedNetworkTableBuffer.h"
#include "SwgDatabaseServer/ObjectQueries.h"
#include "SwgDatabaseServer/Schema.h"
#include "swgSharedUtility/Attributes.def"
class UpdateObjectPositionMessage;
// ======================================================================
class CreatureObjectBuffer : public IndexedNetworkTableBuffer<DBSchema::CreatureObjectBufferRow, DBSchema::CreatureObjectRow, DBQuery::CreatureObjectQuery, DBQuery::CreatureObjectQuerySelect>
{
public:
CreatureObjectBuffer(DB::ModeQuery::Mode mode);
void setAttribute(const NetworkId &objectId, Attributes::Enumerator type, Attributes::Value value);
void getAttributesForObject (const NetworkId &objectId, std::vector<Attributes::Value> &values, int offset, int howMany) const;
virtual bool handleUpdateObjectPosition(const UpdateObjectPositionMessage &message);
};
// ======================================================================
#endif
@@ -0,0 +1,166 @@
// ======================================================================
//
// ExperienceBuffer.cpp
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#include "SwgDatabaseServer/FirstSwgDatabaseServer.h"
#include "SwgDatabaseServer/ExperienceBuffer.h"
#include "SwgDatabaseServer/ExperienceQuery.h"
#include "SwgDatabaseServer/Schema.h"
#include "serverGame/ServerPlayerObjectTemplate.h"
#include "sharedDatabaseInterface/DbSession.h"
#include "sharedLog/Log.h"
#include <vector>
// ======================================================================
ExperienceBuffer::ExperienceBuffer(DB::ModeQuery::Mode mode) :
AbstractTableBuffer(),
m_mode(mode),
m_rows()
{
}
// ----------------------------------------------------------------------
ExperienceBuffer::~ExperienceBuffer(void)
{
for (IndexType::iterator i=m_rows.begin(); i!=m_rows.end(); ++i)
{
delete i->second;
i->second=NULL;
}
}
// ----------------------------------------------------------------------
void ExperienceBuffer::setExperience(const NetworkId &objectId, const std::string &experienceType, int value)
{
DBSchema::ExperiencePointRow *row=findRowByIndex(objectId,experienceType);
if (!row)
{
row=new DBSchema::ExperiencePointRow;
addRowToIndex(objectId,experienceType,row);
}
row->object_id = objectId;
row->experience_type=experienceType;
row->points = value;
}
// ----------------------------------------------------------------------
bool ExperienceBuffer::getExperienceForObject(const NetworkId &objectId, std::vector<std::pair<std::string, int> > &values) const
{
DEBUG_FATAL(values.size()!=0,("Values vector should be empty on call to getExperienceForObject()\n"));
IndexType::const_iterator i ( m_rows.lower_bound(IndexKey(objectId,"")) );
if (i==m_rows.end())
return false;
for (; (i!=m_rows.end()) && (((*i).second)->object_id.getValue()==objectId); ++i)
{
std::string temp;
(*i).second->experience_type.getValue(temp);
values.push_back(std::pair<std::string, int>(temp, (*i).second->points.getValue()));
}
return true;
}
// ----------------------------------------------------------------------
DBSchema::ExperiencePointRow * ExperienceBuffer::findRowByIndex(const NetworkId &objectId, const std::string &experienceType)
{
IndexType::iterator i=m_rows.find(IndexKey(objectId,experienceType));
if (i==m_rows.end())
return 0;
else
return (*i).second;
}
// ----------------------------------------------------------------------
void ExperienceBuffer::addRowToIndex (const NetworkId &objectId, const std::string &experienceType, DBSchema::ExperiencePointRow *row)
{
m_rows[IndexKey(objectId,experienceType)]=row;
}
// ----------------------------------------------------------------------
/**
* Load the attributes for all the remembered objectId's.
*/
bool ExperienceBuffer::load(DB::Session *session, const DB::TagSet &tags, const std::string &schema, bool)
{
int rowsFetched = 0;
if (tags.find(static_cast<Tag>(ServerPlayerObjectTemplate::ServerPlayerObjectTemplate_tag)) != tags.end())
{
DBQuery::GetAllExperience qry(schema);
if (! (session->exec(&qry)))
return false;
while ((rowsFetched = qry.fetch()) > 0)
{
size_t numRows = qry.getNumRowsFetched();
size_t count = 0;
const std::vector<DBSchema::ExperiencePointRow> &data = qry.getData();
for (std::vector<DBSchema::ExperiencePointRow>::const_iterator i=data.begin(); i!=data.end(); ++i)
{
if (++count > numRows)
break;
DBSchema::ExperiencePointRow *row=new DBSchema::ExperiencePointRow(*i);
NOT_NULL(row);
std::string temp;
row->experience_type.getValue(temp);
addRowToIndex(row->object_id.getValue(),temp,row);
}
}
qry.done();
}
return (rowsFetched >= 0);
}
// ----------------------------------------------------------------------
bool ExperienceBuffer::save(DB::Session *session)
{
LOG("SaveCounts",("Experience: %i saved to db",m_rows.size()));
DBQuery::ExperienceQuery qry;
if (m_mode==DB::ModeQuery::mode_INSERT)
qry.insertMode();
else
qry.updateMode();
for (IndexType::iterator i=m_rows.begin(); i!=m_rows.end(); ++i)
{
qry.setData(*(i->second));
if (! (session->exec(&qry)))
return false;
}
qry.done();
return true;
}
// ----------------------------------------------------------------------
void ExperienceBuffer::removeObject(const NetworkId &object)
{
IndexType::iterator i=m_rows.lower_bound(IndexKey(object,""));
while (i!=m_rows.end() && i->first.m_objectId==object)
{
IndexType::iterator next=i;
++next;
delete i->second;
i->second=NULL;
m_rows.erase(i);
i=next;
}
}
// ======================================================================
@@ -0,0 +1,102 @@
// ======================================================================
//
// ExperienceBuffer.h
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#ifndef INCLUDED_ExperienceBuffer_H
#define INCLUDED_ExperienceBuffer_H
// ======================================================================
#include "SwgDatabaseServer/ExperienceQuery.h"
#include "SwgDatabaseServer/Schema.h"
#include "serverDatabase/AbstractTableBuffer.h"
#include <map>
#include <string>
// ======================================================================
class ExperienceBuffer : public AbstractTableBuffer
{
public:
explicit ExperienceBuffer (DB::ModeQuery::Mode mode);
virtual ~ExperienceBuffer ();
virtual bool load (DB::Session *session, const DB::TagSet &tags, const std::string &schema, bool usingGoldDatabase);
virtual bool save (DB::Session *session);
virtual void removeObject (const NetworkId &object);
DBSchema::ExperiencePointRow * findRowByIndex (const NetworkId &objectId, const std::string &experienceType);
void setExperience (const NetworkId &objectId, const std::string &experienceType, int value);
void removeExperience (const NetworkId &objectId, std::string experienceType);
bool getExperienceForObject (const NetworkId &objectId, stdvector<std::pair<std::string, int> >::fwd &values) const;
private:
void addRowToIndex (const NetworkId &objectId, const std::string &experienceType, DBSchema::ExperiencePointRow *row);
private:
struct IndexKey
{
NetworkId m_objectId;
std::string m_experienceType;
IndexKey(NetworkId objectId, std::string experienceType);
bool operator==(const IndexKey &rhs) const;
};
struct IndexSorter
{
bool operator() (const IndexKey &left, const IndexKey &right) const;
};
typedef std::map<IndexKey,DBSchema::ExperiencePointRow*,IndexSorter> IndexType;
DB::ModeQuery::Mode m_mode;
IndexType m_rows;
private:
ExperienceBuffer(); //disable
ExperienceBuffer(const ExperienceBuffer&); //disable
ExperienceBuffer & operator=(const ExperienceBuffer&); //disable
}; //lint !e1712 // IndexKey has no default constructor
// ======================================================================
inline ExperienceBuffer::IndexKey::IndexKey(NetworkId objectId, std::string experienceType) :
m_objectId(objectId),
m_experienceType(experienceType)
{
}
// ----------------------------------------------------------------------
inline bool ExperienceBuffer::IndexKey::operator==(const IndexKey &rhs) const
{
return ((m_objectId == rhs.m_objectId) && (m_experienceType == rhs.m_experienceType));
}
// ----------------------------------------------------------------------
inline bool ExperienceBuffer::IndexSorter::operator() (const IndexKey &left, const IndexKey &right) const
{
if (left.m_objectId == right.m_objectId)
return (left.m_experienceType < right.m_experienceType);
else
return (left.m_objectId < right.m_objectId);
}
// ----------------------------------------------------------------------
/**
* Removing experience is the same as setting it to 0. (The database package
* will delete the row if points == 0.)
*/
inline void ExperienceBuffer::removeExperience(const NetworkId &objectId, std::string experienceType)
{
setExperience(objectId,experienceType,0);
}
// ======================================================================
#endif
@@ -0,0 +1,11 @@
// ======================================================================
//
// IndexedNetworkTableBuffer.cpp
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#include "SwgDatabaseServer/FirstSwgDatabaseServer.h"
#include "IndexedNetworkTableBuffer.h"
// ======================================================================
@@ -0,0 +1,270 @@
// ======================================================================
//
// IndexedNetworkTableBuffer.h
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#ifndef INCLUDED_IndexedNetworkTableBuffer_H
#define INCLUDED_IndexedNetworkTableBuffer_H
// ======================================================================
#include "serverDatabase/AbstractTableBuffer.h"
#include "sharedDatabaseInterface/DbModeQuery.h"
#include "sharedDatabaseInterface/DbSession.h"
#include "sharedFoundation/NetworkId.h"
#include <map>
#include <set>
#include <vector>
// ======================================================================
namespace IndexedNetworkTableBufferNamespace
{
const int ms_maxItemsPerExec = 10000;
}
using namespace IndexedNetworkTableBufferNamespace;
/**
* A TableBuffer organized to track data by objects, one row per object.
*
* @todo: Rename the class. Name makes no sense anymore. Un-templatize.
*/
template <class BUFFERROW, class ROW, class QUERY, class SELECTQUERY>
class IndexedNetworkTableBuffer : public AbstractTableBuffer
{
public:
explicit IndexedNetworkTableBuffer(DB::ModeQuery::Mode mode);
~IndexedNetworkTableBuffer();
public:
virtual bool load(DB::Session *session, const DB::TagSet &tags, const std::string &schema, bool usingGoldDatabase);
virtual bool save(DB::Session *session);
BUFFERROW *findRowByIndex(const NetworkId &indexValue);
const BUFFERROW *findConstRowByIndex(const NetworkId &indexValue) const;
BUFFERROW *addEmptyRow(const NetworkId &indexValue);
virtual void removeObject(const NetworkId &object);
DB::ModeQuery::Mode getMode(void) const;
void addTag(Tag tag);
static int getRowsCreated() { return m_sRowsCreated; }
static int getRowsDeleted() { return m_sRowsDeleted; }
static int getRowsActive()
{
int i_retval = m_sRowsCreated - m_sRowsDeleted;
if ( i_retval < 0 )
return 0;
return i_retval;
}
protected:
typedef std::map<NetworkId, BUFFERROW*> IndexType;
IndexType m_rows;
private:
DB::ModeQuery::Mode m_mode;
DB::TagSet m_relevantTags;
private:
void addRow(const NetworkId &indexValue,BUFFERROW *row);
static volatile int m_sRowsCreated;
static volatile int m_sRowsDeleted;
private:
IndexedNetworkTableBuffer(); // disable
};
template <class B, class R, class Q, class S> volatile int IndexedNetworkTableBuffer<B,R,Q,S>::m_sRowsCreated = 0;
template <class B, class R, class Q, class S> volatile int IndexedNetworkTableBuffer<B,R,Q,S>::m_sRowsDeleted = 0;
// ======================================================================
template <class BUFFERROW, class ROW, class QUERY, class SELECTQUERY>
IndexedNetworkTableBuffer<BUFFERROW,ROW,QUERY,SELECTQUERY>::IndexedNetworkTableBuffer(DB::ModeQuery::Mode mode) :
AbstractTableBuffer(),
m_rows(),
m_mode(mode)
{
}
// ----------------------------------------------------------------------
template <class BUFFERROW, class ROW, class QUERY, class SELECTQUERY>
IndexedNetworkTableBuffer<BUFFERROW,ROW,QUERY,SELECTQUERY>::~IndexedNetworkTableBuffer()
{
for (typename IndexType::iterator i=m_rows.begin(); i!=m_rows.end(); ++i)
{
delete i->second;
++m_sRowsDeleted;
i->second=NULL;
}
}
// ----------------------------------------------------------------------
template <class BUFFERROW, class ROW, class QUERY, class SELECTQUERY>
void IndexedNetworkTableBuffer<BUFFERROW,ROW,QUERY,SELECTQUERY>::addRow(const NetworkId &indexValue,BUFFERROW *row)
{
m_rows[indexValue]=row;
++m_sRowsCreated;
}
// ----------------------------------------------------------------------
template <class BUFFERROW, class ROW, class QUERY, class SELECTQUERY>
BUFFERROW *IndexedNetworkTableBuffer<BUFFERROW,ROW,QUERY,SELECTQUERY>::findRowByIndex(const NetworkId &indexValue)
{
typename IndexType::iterator i=m_rows.find(indexValue);
if (i==m_rows.end())
return 0;
else
return i->second;
}
// ----------------------------------------------------------------------
template <class BUFFERROW, class ROW, class QUERY, class SELECTQUERY>
const BUFFERROW *IndexedNetworkTableBuffer<BUFFERROW,ROW,QUERY,SELECTQUERY>::findConstRowByIndex(const NetworkId &indexValue) const
{
typename IndexType::const_iterator i=m_rows.find(indexValue);
if (i==m_rows.end())
return 0;
else
return i->second;
}
// ----------------------------------------------------------------------
template <class BUFFERROW, class ROW, class QUERY, class SELECTQUERY>
BUFFERROW *IndexedNetworkTableBuffer<BUFFERROW,ROW,QUERY,SELECTQUERY>::addEmptyRow(const NetworkId &indexValue)
{
BUFFERROW *row=new BUFFERROW;
row->setPrimaryKey(indexValue);
addRow(indexValue,row);
return row;
}
// ----------------------------------------------------------------------
template <class BUFFERROW, class ROW, class QUERY, class SELECTQUERY>
void IndexedNetworkTableBuffer<BUFFERROW,ROW,QUERY,SELECTQUERY>::removeObject(const NetworkId &object)
{
typename IndexType::iterator i=m_rows.find(object);
if (i!=m_rows.end())
{
delete i->second;
++m_sRowsDeleted;
i->second=NULL;
m_rows.erase(i);
}
}
// ----------------------------------------------------------------------
template <class BUFFERROW, class ROW, class QUERY, class SELECTQUERY>
DB::ModeQuery::Mode IndexedNetworkTableBuffer<BUFFERROW,ROW,QUERY,SELECTQUERY>::getMode(void) const
{
return m_mode;
}
// ----------------------------------------------------------------------
template <class BUFFERROW, class ROW, class QUERY, class SELECTQUERY>
bool IndexedNetworkTableBuffer<BUFFERROW,ROW,QUERY,SELECTQUERY>::save(DB::Session *session)
{
QUERY qry;
if (getMode()==DB::ModeQuery::mode_INSERT)
qry.insertMode();
else
qry.updateMode();
if (!qry.setupData(session))
return false;
for (typename IndexType::iterator i=m_rows.begin(); i!=m_rows.end(); ++i)
{
if (!qry.addData((i->second)))
return false;
if (qry.getNumItems() == IndexedNetworkTableBufferNamespace::ms_maxItemsPerExec)
{
if (! (session->exec(&qry)))
return false;
qry.clearData();
}
}
if (qry.getNumItems() != 0)
if (! (session->exec(&qry)))
return false;
qry.done();
qry.freeData();
return true;
}
// ----------------------------------------------------------------------
/**
* Load rows into the buffer from the database.
*
* The query is assumed to return 0 or more rows, which will be placed
* in the buffer. The virtual addRow function is used to make sure indexes,
* etc., are updated as needed.
*/
template <class BUFFERROW, class ROW, class QUERY, class SELECTQUERY>
bool IndexedNetworkTableBuffer<BUFFERROW,ROW,QUERY,SELECTQUERY>::load(DB::Session *session, const DB::TagSet &tags, const std::string &schema, bool)
{
int rowsFetched = 0;
if (m_relevantTags.empty() || hasCommonTags(m_relevantTags, tags))
{
SELECTQUERY qry(schema);
FATAL (getMode()!=DB::ModeQuery::mode_SELECT,("load() was invoked on a TableBuffer that was not in tbm_select mode."));
if (! (session->exec(&qry)))
return false;
while ((rowsFetched = qry.fetch()) > 0)
{
int numRows = qry.getNumRowsFetched();
int count = 0;
const std::vector<ROW> &data = qry.getData();
for (typename std::vector<ROW>::const_iterator i=data.begin(); i!=data.end(); ++i)
{
if (++count > numRows)
break;
BUFFERROW *newRow=new BUFFERROW(*i);
addRow(newRow->getPrimaryKey(),newRow);
}
}
qry.done();
}
return (rowsFetched >= 0);
}
// ----------------------------------------------------------------------
/**
* Add a tag to the list we are interested in. If the current snapshot
* contains no objects with tags in this list, this buffer will skip its
* load. (Exception: If no tags are registered at all, the load will
* always happen.)
*/
template <class BUFFERROW, class ROW, class QUERY, class SELECTQUERY>
void IndexedNetworkTableBuffer<BUFFERROW,ROW,QUERY,SELECTQUERY>::addTag(Tag tag)
{
m_relevantTags.insert(tag);
}
// ======================================================================
#endif
@@ -0,0 +1,54 @@
#if 0 //@todo code reorg
// ======================================================================
//
// IndexedNetworkTableBuffer.h
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#ifndef INCLUDED_IndexedNetworkTableBuffer_H
#define INCLUDED_IndexedNetworkTableBuffer_H
// ======================================================================
#include <hash_map>
#include "serverDatabase/TableBuffer.h"
// ======================================================================
/**
* Adds to NetworkTableBuffer the ability to retrieve rows based on an
* integer index.
* @todo Remove "Network" from the name because it no longer has anything to
* do with the network.
* @todo If we have time someday :) Play with the idea of making this be a
* class that's attached to a TableBuffer, much the same way a real DB index
* is attached to a table. The TableBuffer could have a list of pointers
* to indexes, and it would invoke addRow, etc., as needed.
*/
class IndexedNetworkTableBuffer : public TableBuffer
{
public:
void addRowToIndex(int indexValue, DB::Row *row);
DB::Row *findRowByIndex(int indexValue);
protected:
IndexedNetworkTableBuffer(TableBufferMode mode, DB::ModeQuery *query);
private:
typedef std::hash_map<int, DB::Row*> IndexType;
/**
* Index to locate rows.
*
* Note that the rows are owned by the TableBuffer base class. This
* is just an index to find a specific row quickly. Therefore, this
* class does not create or delete the rows.
*/
IndexType m_index;
};
// ======================================================================
#endif
#endif
@@ -0,0 +1,165 @@
// ======================================================================
//
// LocationBuffer.cpp
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#include "SwgDatabaseServer/FirstSwgDatabaseServer.h"
#include "LocationBuffer.h"
#include "SwgDatabaseServer/LocationQuery.h"
#include "serverGame/ServerCreatureObjectTemplate.h"
#include "sharedLog/Log.h"
// ======================================================================
LocationBuffer::LocationBuffer(DB::ModeQuery::Mode mode) :
AbstractTableBuffer()
{
UNREF(mode);
}
// ----------------------------------------------------------------------
LocationBuffer::~LocationBuffer()
{
}
// ----------------------------------------------------------------------
bool LocationBuffer::save(DB::Session *session)
{
LOG("SaveCounts",("Locations: %i saved to db",m_saveData.size()));
DBQuery::SaveLocationQuery qry;
for (SaveDataType::const_iterator i=m_saveData.begin(); i!=m_saveData.end(); ++i)
{
NetworkId networkId=i->first;
const std::vector<BufferEntry> &data=i->second;
for (std::vector<BufferEntry>::const_iterator j=data.begin(); j!=data.end(); ++j)
{
qry.setData(networkId, j->m_listId, j->m_action, j->m_index, j->m_data);
if (! (session->exec(&qry)))
return false;
}
}
qry.done();
return true;
}
// ----------------------------------------------------------------------
bool LocationBuffer::load(DB::Session *session, const DB::TagSet &tags, const std::string &schema, bool)
{
int rowsFetched = 0;
if (tags.find(static_cast<Tag>(ServerCreatureObjectTemplate::ServerCreatureObjectTemplate_tag)) != tags.end())
{
DBQuery::LoadLocationQuery qry(schema);
LocationData temp;
if (! (session->exec(&qry)))
return false;
while ((rowsFetched = qry.fetch()) > 0)
{
size_t numRows = qry.getNumRowsFetched();
size_t count = 0;
const std::vector<DBQuery::LoadLocationQuery::LocationRow> &data = qry.getData();
for (std::vector<DBQuery::LoadLocationQuery::LocationRow>::const_iterator i=data.begin(); i!=data.end(); ++i)
{
if (++count > numRows)
break;
i->name.getValue(temp.name);
i->scene.getValue(temp.scene);
temp.location.setCenter(static_cast<float>(i->x.getValue()),static_cast<float>(i->y.getValue()),static_cast<float>(i->z.getValue()));
temp.location.setRadius(static_cast<float>(i->radius.getValue()));
m_loadData[IndexKey(i->object_id.getValue(),i->list_id.getValue(),i->index.getValue())]=temp;
}
}
qry.done();
}
return (rowsFetched >= 0);
}
// ----------------------------------------------------------------------
void LocationBuffer::removeObject(const NetworkId &object)
{
m_saveData.erase(object);
}
// ----------------------------------------------------------------------
void LocationBuffer::addAction(BufferEntry::Action action, const NetworkId &objectId, size_t listId, size_t sequenceNumber, const LocationData &value)
{
m_saveData[objectId].push_back(BufferEntry(listId, action, sequenceNumber, value));
}
// ----------------------------------------------------------------------
void LocationBuffer::getLocationList(const NetworkId &objectId, size_t listId, std::vector<LocationData> &values) const
{
#ifdef _DEBUG
size_t expectedIndex = 0;
#endif
for (LoadDataType::const_iterator i=m_loadData.find(IndexKey(objectId, listId, 0)); (i!=m_loadData.end()) && (i->first.m_objectId == objectId) && (i->first.m_listId == listId); ++i)
{
DEBUG_FATAL(i->first.m_index != expectedIndex++,("Programmer bug: location list was not sorted or had gaps in the sequence. Object id %s, list id %i, sequence %i\n",objectId.getValueString().c_str(), listId, i->first.m_index));
values.push_back(i->second);
}
}
// ======================================================================
LocationBuffer::BufferEntry::BufferEntry(size_t listId, Action action, size_t index, const LocationData &data) :
m_listId(listId),
m_action(action),
m_index(index),
m_data(data)
{
}
// ======================================================================
LocationBuffer::IndexKey::IndexKey()
{
}
// ----------------------------------------------------------------------
LocationBuffer::IndexKey::IndexKey(const NetworkId &objectId, size_t listId, size_t index) :
m_objectId(objectId),
m_listId(listId),
m_index(index)
{
}
// ----------------------------------------------------------------------
LocationBuffer::IndexKey::IndexKey(const IndexKey &rhs) :
m_objectId(rhs.m_objectId),
m_listId(rhs.m_listId),
m_index(rhs.m_index)
{
}
// ----------------------------------------------------------------------
bool LocationBuffer::IndexKey::operator<(const IndexKey &rhs) const
{
if (m_objectId == rhs.m_objectId)
if (m_listId == rhs.m_listId)
return (m_index < rhs.m_index);
else
return (m_listId < rhs.m_listId);
else
return (m_objectId < rhs.m_objectId);
}
// ======================================================================
@@ -0,0 +1,114 @@
// ======================================================================
//
// LocationBuffer.h
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#ifndef INCLUDED_LocationBuffer_H
#define INCLUDED_LocationBuffer_H
// ======================================================================
#include <map>
#include <vector>
#include "serverDatabase/TableBuffer.h"
#include "serverUtility/LocationData.h"
#include "sharedFoundation/NetworkId.h"
namespace DBSchema
{
struct LocationRow;
}
// ======================================================================
/**
* LocationBuffer is a table buffer customized to the job of loading and
* saving locations for OnArrivedAt() targets, etc.
*
* Locations are keyed by object id, a list number, and a sequence number. (Thus
* each object can have multiple lists of locations.)
*
* Unlike most other buffer classes, this class does not maintain a list of rows.
* Instead, it has a map of vectors of actions to be applied in the database.
*/
class LocationBuffer : public AbstractTableBuffer
{
public:
explicit LocationBuffer(DB::ModeQuery::Mode mode);
virtual ~LocationBuffer(void);
virtual bool load(DB::Session *session, const DB::TagSet &tags, const std::string &schema, bool usingGoldDatabase);
virtual bool save(DB::Session *session);
virtual void removeObject(const NetworkId &object);
void set (const NetworkId &objectId, size_t listId, size_t sequenceNumber, const LocationData &value);
void insert (const NetworkId &objectId, size_t listId, size_t sequenceNumber, const LocationData &value);
void erase (const NetworkId &objectId, size_t listId, size_t sequenceNumber);
void getLocationList(const NetworkId &objectId, size_t listId, std::vector<LocationData> &values) const;
private:
struct BufferEntry
{
enum Action {be_INSERT, be_ERASE, be_SET};
size_t m_listId;
Action m_action;
size_t m_index;
LocationData m_data;
BufferEntry(size_t listId, Action action, size_t index, const LocationData &data);
};
struct IndexKey
{
NetworkId m_objectId;
size_t m_listId;
size_t m_index;
IndexKey();
IndexKey(const NetworkId &objectId, size_t listId, size_t index);
IndexKey(const IndexKey &rhs);
bool operator < (const IndexKey &rhs) const;
};
typedef std::map<NetworkId, std::vector<BufferEntry> > SaveDataType;
SaveDataType m_saveData;
typedef std::map<IndexKey, LocationData> LoadDataType;
LoadDataType m_loadData;
private:
void addAction(BufferEntry::Action action, const NetworkId &objectId, size_t listId, size_t sequenceNumber, const LocationData &value);
private:
LocationBuffer(); //disable
LocationBuffer(const LocationBuffer&); //disable
LocationBuffer & operator=(const LocationBuffer&); //disable
}; //lint !e1712 // IndexKey has no default constructor
// ======================================================================
inline void LocationBuffer::set(const NetworkId &objectId, size_t listId, size_t sequenceNumber, const LocationData &value)
{
addAction(BufferEntry::be_SET, objectId, listId, sequenceNumber, value);
}
// ----------------------------------------------------------------------
inline void LocationBuffer::insert(const NetworkId &objectId, size_t listId, size_t sequenceNumber, const LocationData &value)
{
addAction(BufferEntry::be_INSERT, objectId, listId, sequenceNumber, value);
}
// ----------------------------------------------------------------------
inline void LocationBuffer::erase(const NetworkId &objectId, size_t listId, size_t sequenceNumber)
{
addAction(BufferEntry::be_ERASE, objectId, listId, sequenceNumber, LocationData());
}
// ======================================================================
#endif
@@ -0,0 +1,183 @@
// ======================================================================
//
// ManufactureSchematicAttributeBuffer.cpp
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#include "SwgDatabaseServer/FirstSwgDatabaseServer.h"
#include "SwgDatabaseServer/ManufactureSchematicAttributeBuffer.h"
#include "SwgDatabaseServer/ManufactureSchematicAttributeQuery.h"
#include "serverGame/ServerManufactureSchematicObjectTemplate.h"
#include "sharedDatabaseInterface/DbSession.h"
#include "sharedLog/Log.h"
#include<vector>
// ======================================================================
ManufactureSchematicAttributeBuffer::ManufactureSchematicAttributeBuffer(DB::ModeQuery::Mode mode) :
AbstractTableBuffer(),
m_mode(mode),
m_rows()
{
}
// ----------------------------------------------------------------------
ManufactureSchematicAttributeBuffer::~ManufactureSchematicAttributeBuffer(void)
{
for (IndexType::iterator i=m_rows.begin(); i!=m_rows.end(); ++i)
{
delete i->second;
i->second=NULL;
}
}
// ----------------------------------------------------------------------
void ManufactureSchematicAttributeBuffer::setManufactureSchematicAttribute(const NetworkId &objectId, std::string attributeType, float value)
{
DBSchema::ManufactureSchematicAttributeRow *row=findRowByIndex(objectId,attributeType);
if (!row)
{
row=new DBSchema::ManufactureSchematicAttributeRow;
addRowToIndex(objectId,attributeType,row);
}
row->action = 1; //TODO: enum somewhere
row->object_id = objectId;
row->attribute_type=attributeType;
row->value = value;
}
// ----------------------------------------------------------------------
void ManufactureSchematicAttributeBuffer::removeManufactureSchematicAttribute(const NetworkId &objectId, std::string attributeType)
{
DBSchema::ManufactureSchematicAttributeRow *row=findRowByIndex(objectId,attributeType);
if (!row)
{
row=new DBSchema::ManufactureSchematicAttributeRow;
addRowToIndex(objectId,attributeType,row);
}
row->action = 0; //TODO: enum somewhere
}
// ----------------------------------------------------------------------
bool ManufactureSchematicAttributeBuffer::getDataForObject(const NetworkId &objectId, std::vector<std::pair<std::string, float> > &values) const
{
DEBUG_FATAL(values.size()!=0,("Values vector should be empty on call to getExperienceForObject()\n"));
IndexType::const_iterator i ( m_rows.lower_bound(IndexKey(objectId,"")) );
if (i==m_rows.end())
return false;
for (; (i!=m_rows.end()) && (((*i).second)->object_id.getValue()==objectId); ++i)
{
std::string temp;
(*i).second->attribute_type.getValue(temp);
values.push_back(std::pair<std::string, float>(temp, static_cast<float>((*i).second->value.getValue())));
}
return true;
}
// ----------------------------------------------------------------------
DBSchema::ManufactureSchematicAttributeRow * ManufactureSchematicAttributeBuffer::findRowByIndex(NetworkId objectId, std::string experienceType)
{
IndexType::iterator i=m_rows.find(IndexKey(objectId,experienceType));
if (i==m_rows.end())
return 0;
else
return (*i).second;
}
// ----------------------------------------------------------------------
void ManufactureSchematicAttributeBuffer::addRowToIndex(NetworkId objectId, std::string attributeType, DBSchema::ManufactureSchematicAttributeRow *row)
{
m_rows[IndexKey(objectId,attributeType)]=row;
}
// ----------------------------------------------------------------------
/**
* Load the attributes for all the remembered objectId's.
*/
bool ManufactureSchematicAttributeBuffer::load(DB::Session *session, const DB::TagSet &tags, const std::string &schema, bool)
{
int rowsFetched = 0;
if (tags.find(static_cast<Tag>(ServerManufactureSchematicObjectTemplate::ServerManufactureSchematicObjectTemplate_tag)) != tags.end())
{
DBQuery::GetAllManufactureSchematicAttributes qry(schema);
if (! (session->exec(&qry)))
return false;
while ((rowsFetched = qry.fetch()) > 0)
{
size_t numRows = qry.getNumRowsFetched();
size_t count = 0;
const std::vector<DBSchema::ManufactureSchematicAttributeRow> &data = qry.getData();
for (std::vector<DBSchema::ManufactureSchematicAttributeRow>::const_iterator i=data.begin(); i!=data.end(); ++i)
{
if (++count > numRows)
break;
DBSchema::ManufactureSchematicAttributeRow *row=new DBSchema::ManufactureSchematicAttributeRow(*i);
NOT_NULL(row);
std::string temp;
row->attribute_type.getValue(temp);
addRowToIndex(row->object_id.getValue(),temp,row);
}
}
qry.done();
}
return (rowsFetched >= 0);
}
// ----------------------------------------------------------------------
bool ManufactureSchematicAttributeBuffer::save(DB::Session *session)
{
LOG("SaveCounts",("ManufactureSchematicAttributeBuffer: %i saved to db",m_rows.size()));
DBQuery::ManufactureSchematicAttributeQuery qry;
if (m_mode==DB::ModeQuery::mode_INSERT)
qry.insertMode();
else
qry.updateMode();
for (IndexType::iterator i=m_rows.begin(); i!=m_rows.end(); ++i)
{
qry.setData(*(i->second));
if (! (session->exec(&qry)))
return false;
}
qry.done();
return true;
}
// ----------------------------------------------------------------------
void ManufactureSchematicAttributeBuffer::removeObject(const NetworkId &object)
{
IndexType::iterator i=m_rows.lower_bound(IndexKey(object,""));
while (i!=m_rows.end() && i->first.m_objectId==object)
{
IndexType::iterator next=i;
++next;
delete i->second;
i->second=NULL;
m_rows.erase(i);
i=next;
}
}
// ======================================================================
@@ -0,0 +1,97 @@
// ======================================================================
//
// ManufactureSchematicAttributeBuffer.h
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#ifndef INCLUDED_ManufactureSchematicAttributeBuffer_H
#define INCLUDED_ManufactureSchematicAttributeBuffer_H
// ======================================================================
#include <map>
#include <string>
#include "serverDatabase/AbstractTableBuffer.h"
#include "SwgDatabaseServer/ManufactureSchematicAttributeQuery.h"
namespace DBSchema
{
struct ManufactureSchematicAttributeRow;
}
// ======================================================================
class ManufactureSchematicAttributeBuffer : public AbstractTableBuffer // <DBSchema::ManufactureSchematicAttributeRow, DBQuery::ManufactureSchematicAttributeQuery>
{
public:
explicit ManufactureSchematicAttributeBuffer (DB::ModeQuery::Mode mode);
virtual ~ManufactureSchematicAttributeBuffer ();
virtual bool load (DB::Session *session, const DB::TagSet &tags, const std::string &schema, bool usingGoldDatabase);
virtual bool save (DB::Session *session);
virtual void removeObject (const NetworkId &object);
DBSchema::ManufactureSchematicAttributeRow * findRowByIndex (NetworkId objectId, std::string attributeType);
void setManufactureSchematicAttribute (const NetworkId &objectId, std::string attributeType, float value);
void removeManufactureSchematicAttribute (const NetworkId &objectId, std::string attributeType);
bool getDataForObject (const NetworkId &objectId, stdvector<std::pair<std::string, float> >::fwd &values) const;
private:
void addRowToIndex (NetworkId objectId, std::string attributeType, DBSchema::ManufactureSchematicAttributeRow *row);
private:
struct IndexKey
{
NetworkId m_objectId;
std::string m_attributeType;
IndexKey(NetworkId objectId, std::string attributeType);
bool operator==(const IndexKey &rhs) const;
};
struct IndexSorter
{
bool operator() (const IndexKey &left, const IndexKey &right) const;
};
typedef std::map<IndexKey,DBSchema::ManufactureSchematicAttributeRow*,IndexSorter> IndexType;
DB::ModeQuery::Mode m_mode;
IndexType m_rows;
private:
ManufactureSchematicAttributeBuffer(); //disable
ManufactureSchematicAttributeBuffer(const ManufactureSchematicAttributeBuffer&); //disable
ManufactureSchematicAttributeBuffer & operator=(const ManufactureSchematicAttributeBuffer&); //disable
}; //lint !e1712 // IndexKey has no default constructor
// ======================================================================
inline ManufactureSchematicAttributeBuffer::IndexKey::IndexKey(NetworkId objectId, std::string attributeType) :
m_objectId(objectId),
m_attributeType(attributeType)
{
}
// ----------------------------------------------------------------------
inline bool ManufactureSchematicAttributeBuffer::IndexKey::operator==(const IndexKey &rhs) const
{
return ((m_objectId == rhs.m_objectId) && (m_attributeType == rhs.m_attributeType));
}
// ----------------------------------------------------------------------
inline bool ManufactureSchematicAttributeBuffer::IndexSorter::operator() (const IndexKey &left, const IndexKey &right) const
{
if (left.m_objectId == right.m_objectId)
return (left.m_attributeType < right.m_attributeType);
else
return (left.m_objectId < right.m_objectId);
}
// ======================================================================
#endif
@@ -0,0 +1,138 @@
// ======================================================================
//
// MarketAuctionBidsBuffer.cpp
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#include "SwgDatabaseServer/FirstSwgDatabaseServer.h"
#include "SwgDatabaseServer/MarketAuctionBidsBuffer.h"
#include "SwgDatabaseServer/CommoditiesQuery.h"
#include "SwgDatabaseServer/CommoditiesSchema.h"
#include "serverGame/ServerPlayerObjectTemplate.h"
#include "sharedDatabaseInterface/DbSession.h"
#include "sharedLog/Log.h"
#include <vector>
// ======================================================================
MarketAuctionBidsBuffer::MarketAuctionBidsBuffer(DB::ModeQuery::Mode mode) :
AbstractTableBuffer(),
m_mode(mode),
m_rows()
{
}
// ----------------------------------------------------------------------
MarketAuctionBidsBuffer::~MarketAuctionBidsBuffer(void)
{
for (IndexType::iterator i=m_rows.begin(); i!=m_rows.end(); ++i)
{
delete i->second;
i->second=NULL;
}
}
// ----------------------------------------------------------------------
bool MarketAuctionBidsBuffer::load(DB::Session *session, const DB::TagSet &tags, const std::string &schema, bool usingGoldDatabase)
{
return true;
}
// ----------------------------------------------------------------------
void MarketAuctionBidsBuffer::removeObject(const NetworkId &object)
{
removeMarketAuctionBids(object);
}
// ----------------------------------------------------------------------
void MarketAuctionBidsBuffer::removeMarketAuctionBids(const NetworkId &itemId)
{
IndexType::iterator i=m_rows.find(itemId);
if (i!=m_rows.end())
{
delete i->second;
i->second=NULL;
m_rows.erase(i);
}
}
// ----------------------------------------------------------------------
void MarketAuctionBidsBuffer::setMarketAuctionBids(const NetworkId &itemId, const NetworkId &bidderId, const int bid, const int maxProxyBid)
{
DBSchema::MarketAuctionBidsRow *row=findRowByIndex(itemId);
if (!row)
{
row=new DBSchema::MarketAuctionBidsRow;
addRowToIndex(itemId, row);
}
row->item_id = itemId;
row->bidder_id = bidderId;
row->bid = bid;
row->max_proxy_bid = maxProxyBid;
}
// ----------------------------------------------------------------------
DBSchema::MarketAuctionBidsRow * MarketAuctionBidsBuffer::findRowByIndex(const NetworkId &itemId)
{
IndexType::iterator i=m_rows.find(itemId);
if (i==m_rows.end())
return 0;
else
return (*i).second;
}
// ----------------------------------------------------------------------
void MarketAuctionBidsBuffer::addRowToIndex (const NetworkId &itemId, DBSchema::MarketAuctionBidsRow *row)
{
m_rows[itemId]=row;
}
// ----------------------------------------------------------------------
bool MarketAuctionBidsBuffer::save(DB::Session *session)
{
LOG("SaveCounts",("MarketAuctionBids: %i saved to db",m_rows.size()));
DEBUG_REPORT_LOG(true, ("Saving Market Auction Bids Buffer. mode:%d rowcount:%d\n", m_mode, m_rows.size()));
DBQuery::MarketAuctionBidsQuery qry;
if (m_mode==DB::ModeQuery::mode_INSERT)
qry.insertMode();
else if (m_mode == DB::ModeQuery::mode_UPDATE)
qry.updateMode();
else
qry.deleteMode();
if (!qry.setupData(session))
return false;
for (IndexType::iterator i=m_rows.begin(); i!=m_rows.end(); ++i)
{
if (!qry.addData(i->second))
return false;
if (qry.getNumItems() >= MarketAuctionBidsTableBufferNamespace::ms_maxItemsPerExec)
{
if (! (session->exec(&qry)))
return false;
qry.clearData();
}
}
if (qry.getNumItems() != 0)
if (! (session->exec(&qry)))
return false;
qry.done();
qry.freeData();
return true;
}
// ======================================================================
@@ -0,0 +1,63 @@
// ======================================================================
//
// MarketAuctionBidsBuffer.h
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#ifndef INCLUDED_MarketAuctionBidsBuffer_H
#define INCLUDED_MarketAuctionBidsBuffer_H
// ======================================================================
#include "SwgDatabaseServer/CommoditiesQuery.h"
#include "SwgDatabaseServer/CommoditiesSchema.h"
#include "serverDatabase/AbstractTableBuffer.h"
#include <map>
#include <string>
// ======================================================================
namespace MarketAuctionBidsTableBufferNamespace
{
const int ms_maxItemsPerExec = 10000;
}
using namespace MarketAuctionBidsTableBufferNamespace;
// ======================================================================
class MarketAuctionBidsBuffer : public AbstractTableBuffer
{
public:
explicit MarketAuctionBidsBuffer (DB::ModeQuery::Mode mode);
virtual ~MarketAuctionBidsBuffer ();
virtual bool load(DB::Session *session, const DB::TagSet &tags, const std::string &schema, bool usingGoldDatabase);
virtual bool save(DB::Session *session);
DBSchema::MarketAuctionBidsRow * findRowByIndex (const NetworkId &itemId);
void setMarketAuctionBids (const NetworkId &itemId, const NetworkId &bidderId, const int bid, const int maxProxyBid);
void removeMarketAuctionBids(const NetworkId &itemId);
virtual void removeObject (const NetworkId &object);
private:
void addRowToIndex (const NetworkId &itemId, DBSchema::MarketAuctionBidsRow *row);
private:
typedef std::map<NetworkId, DBSchema::MarketAuctionBidsRow*> IndexType;
DB::ModeQuery::Mode m_mode;
IndexType m_rows;
private:
MarketAuctionBidsBuffer(); //disable
MarketAuctionBidsBuffer(const MarketAuctionBidsBuffer&); //disable
MarketAuctionBidsBuffer & operator=(const MarketAuctionBidsBuffer&); //disable
}; //lint !e1712 // IndexKey has no default constructor
// ======================================================================
#endif
@@ -0,0 +1,433 @@
// ======================================================================
//
// MarketAuctionsBuffer.cpp
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#include "SwgDatabaseServer/FirstSwgDatabaseServer.h"
#include "SwgDatabaseServer/MarketAuctionsBuffer.h"
#include "SwgDatabaseServer/CommoditiesQuery.h"
#include "SwgDatabaseServer/CommoditiesSchema.h"
#include "serverGame/ServerPlayerObjectTemplate.h"
#include "sharedDatabaseInterface/DbSession.h"
#include "sharedLog/Log.h"
#include <vector>
// ======================================================================
MarketAuctionsBufferCreate::MarketAuctionsBufferCreate() :
AbstractTableBuffer(),
m_rows(),
m_attributes()
{
}
// ----------------------------------------------------------------------
MarketAuctionsBufferCreate::~MarketAuctionsBufferCreate(void)
{
for (IndexType::iterator i=m_rows.begin(); i!=m_rows.end(); ++i)
{
delete i->second;
i->second=NULL;
}
}
// ----------------------------------------------------------------------
bool MarketAuctionsBufferCreate::load(DB::Session *session, const DB::TagSet &tags, const std::string &schema, bool usingGoldDatabase)
{
return true;
}
// ----------------------------------------------------------------------
void MarketAuctionsBufferCreate::removeObject(const NetworkId &object)
{
removeMarketAuctions(object);
}
// ----------------------------------------------------------------------
void MarketAuctionsBufferCreate::removeMarketAuctions(const NetworkId &itemId)
{
DEBUG_REPORT_LOG(true, ("MarketAuctionsBufferCreate Removing Market Auctions Buffer Row. rowcount:%d\n", m_rows.size()));
DBSchema::MarketAuctionsRow *row=findRowByIndex(itemId);
if (row)
{
delete row;
IGNORE_RETURN(m_rows.erase(itemId));
IGNORE_RETURN(m_attributes.erase(itemId));
DEBUG_REPORT_LOG(true, ("MarketAuctionsBufferCreate Removing Market Auctions Buffer Row. rowcount:%d\n", m_rows.size()));
}
}
// ----------------------------------------------------------------------
void MarketAuctionsBufferCreate::setMarketAuctions(const NetworkId &itemId, const NetworkId &ownerId, const int active)
{
DBSchema::MarketAuctionsRow *row=findRowByIndex(itemId);
if (!row)
{
row=new DBSchema::MarketAuctionsRow;
addRowToIndex(itemId, row);
}
row->item_id = itemId;
row->owner_id = ownerId;
row->active = active;
}
// ----------------------------------------------------------------------
void MarketAuctionsBufferCreate::setMarketAuctions(const NetworkId &itemId, const NetworkId &ownerId, const NetworkId &creatorId, const NetworkId &locationId, const int minBid, const int buyNowPrice, const int auctionTimer, std::vector<std::pair<std::string, Unicode::String> > const & attributes, const Unicode::String userDescription, const int category, const int itemTemplateId, const Unicode::String itemName, const int itemTimer, const int active, const int itemSize)
{
DBSchema::MarketAuctionsRow *row=findRowByIndex(itemId);
if (!row)
{
row=new DBSchema::MarketAuctionsRow;
addRowToIndex(itemId, row);
}
row->item_id = itemId;
row->owner_id = ownerId;
row->creator_id = creatorId;
row->location_id = locationId;
row->min_bid = minBid;
row->buy_now_price = buyNowPrice;
row->auction_timer = auctionTimer;
// row->oob = oob;
row->user_description = userDescription;
row->category = category;
row->item_name = itemName;
row->item_timer = itemTimer;
row->active = active;
row->item_size = itemSize;
row->object_template_id = itemTemplateId;
LOG("CommoditiesServer", ("MarketAuctionsBufferCreate Added MarketAuctionsBuffer row for item %s", row->item_id.getValueASCII().c_str()));
m_attributes[itemId] = attributes;
}
// ----------------------------------------------------------------------
DBSchema::MarketAuctionsRow * MarketAuctionsBufferCreate::findRowByIndex(const NetworkId &itemId)
{
DEBUG_REPORT_LOG(true, ("MarketAuctionsBufferCreate Finding row by Index. ItemId : %s.\n", itemId.getValueString().c_str()));
IndexType::iterator i=m_rows.find(itemId);
if (i==m_rows.end())
return 0;
else
return (*i).second;
}
// ----------------------------------------------------------------------
void MarketAuctionsBufferCreate::addRowToIndex (const NetworkId &itemId, DBSchema::MarketAuctionsRow *row)
{
DEBUG_REPORT_LOG(true, ("MarketAuctionsBufferCreate Adding row to Index. ItemId : %s.\n", itemId.getValueString().c_str()));
m_rows[itemId]=row;
}
// ----------------------------------------------------------------------
bool MarketAuctionsBufferCreate::save(DB::Session *session)
{
{
// count how many attributes we're saving
size_t numAttributes = 0;
for (AttributesType::const_iterator i=m_attributes.begin(); i!=m_attributes.end(); ++i)
numAttributes += i->second.size();
LOG("SaveCounts",("MarketAuctionsBufferCreate: %i auctions, %i auction attributes saved to db",m_rows.size(), numAttributes));
DEBUG_REPORT_LOG(true, ("MarketAuctionsBufferCreate Saving Market Auctions Buffer. rowcount:%d auctions, %d auction attributes\n", m_rows.size(), numAttributes));
}
{
DBQuery::MarketAuctionsQuery qry;
qry.insertMode();
if (!qry.setupData(session))
return false;
for (IndexType::iterator i=m_rows.begin(); i!=m_rows.end(); ++i)
{
if (!qry.addData(i->second))
return false;
LOG("CommoditiesServer", ("MarketAuctionsBufferCreate Added row to MarketAuctionsQuery VARRAY for item %s", (i->second)->item_id.getValueASCII().c_str()));
if (qry.getNumItems() >= MarketAuctionsTableBufferNamespace::ms_maxItemsPerExec)
{
if (! (session->exec(&qry)))
return false;
qry.clearData();
}
}
if (qry.getNumItems() != 0)
if (! (session->exec(&qry)))
return false;
qry.done();
qry.freeData();
}
{
DBQuery::MarketAuctionsAttributesQuery qry;
qry.insertMode();
if (!qry.setupData(session))
return false;
for (AttributesType::const_iterator i=m_attributes.begin(); i!=m_attributes.end(); ++i)
{
for (std::vector<std::pair<std::string, Unicode::String> >::const_iterator j=i->second.begin(); j!=i->second.end(); ++j)
{
if (!qry.addData(i->first, j->first, j->second))
return false;
if (qry.getNumItems() >= MarketAuctionsTableBufferNamespace::ms_maxItemsPerExec)
{
if (! (session->exec(&qry)))
return false;
qry.clearData();
}
}
}
if (qry.getNumItems() != 0)
if (! (session->exec(&qry)))
return false;
qry.done();
qry.freeData();
}
return true;
}
// ======================================================================
MarketAuctionsBufferDelete::MarketAuctionsBufferDelete() :
AbstractTableBuffer(),
m_rows()
{
}
// ----------------------------------------------------------------------
MarketAuctionsBufferDelete::~MarketAuctionsBufferDelete(void)
{
for (IndexType::iterator i=m_rows.begin(); i!=m_rows.end(); ++i)
{
delete i->second;
i->second=NULL;
}
}
// ----------------------------------------------------------------------
bool MarketAuctionsBufferDelete::load(DB::Session *session, const DB::TagSet &tags, const std::string &schema, bool usingGoldDatabase)
{
return true;
}
// ----------------------------------------------------------------------
void MarketAuctionsBufferDelete::removeObject(const NetworkId &object)
{
removeMarketAuctions(object);
}
// ----------------------------------------------------------------------
void MarketAuctionsBufferDelete::removeMarketAuctions(const NetworkId &itemId)
{
DEBUG_REPORT_LOG(true, ("MarketAuctionsBufferDelete Removing Market Auctions Buffer Row. rowcount:%d\n", m_rows.size()));
DBSchema::MarketAuctionsRowDelete *row=findRowByIndex(itemId);
if (row)
{
delete row;
IGNORE_RETURN(m_rows.erase(itemId));
DEBUG_REPORT_LOG(true, ("MarketAuctionsBufferDelete Removing Market Auctions Buffer Row. rowcount:%d\n", m_rows.size()));
}
}
// ----------------------------------------------------------------------
void MarketAuctionsBufferDelete::setMarketAuctions(const NetworkId &itemId)
{
DBSchema::MarketAuctionsRowDelete *row=findRowByIndex(itemId);
if (!row)
{
row=new DBSchema::MarketAuctionsRowDelete;
addRowToIndex(itemId, row);
}
row->item_id = itemId;
}
// ----------------------------------------------------------------------
DBSchema::MarketAuctionsRowDelete * MarketAuctionsBufferDelete::findRowByIndex(const NetworkId &itemId)
{
DEBUG_REPORT_LOG(true, ("MarketAuctionsBufferDelete Finding row by Index. ItemId : %s.\n", itemId.getValueString().c_str()));
IndexType::iterator i=m_rows.find(itemId);
if (i==m_rows.end())
return 0;
else
return (*i).second;
}
// ----------------------------------------------------------------------
void MarketAuctionsBufferDelete::addRowToIndex (const NetworkId &itemId, DBSchema::MarketAuctionsRowDelete *row)
{
DEBUG_REPORT_LOG(true, ("MarketAuctionsBufferDelete Adding row to Index. ItemId : %s.\n", itemId.getValueString().c_str()));
m_rows[itemId]=row;
}
// ----------------------------------------------------------------------
bool MarketAuctionsBufferDelete::save(DB::Session *session)
{
LOG("SaveCounts",("MarketAuctionsBufferDelete: %i saved to db",m_rows.size()));
DEBUG_REPORT_LOG(true, ("MarketAuctionsBufferDelete Saving Market Auctions Buffer. rowcount:%d\n", m_rows.size()));
DBQuery::MarketAuctionsQuery qry;
qry.deleteMode();
if (!qry.setupData(session))
return false;
for (IndexType::iterator i=m_rows.begin(); i!=m_rows.end(); ++i)
{
if (!qry.addData(i->second))
return false;
LOG("CommoditiesServer", ("MarketAuctionsBufferDelete Added row to MarketAuctionsQuery VARRAY for item %s", (i->second)->item_id.getValueASCII().c_str()));
if (qry.getNumItems() >= MarketAuctionsTableBufferNamespace::ms_maxItemsPerExec)
{
if (! (session->exec(&qry)))
return false;
qry.clearData();
}
}
if (qry.getNumItems() != 0)
if (! (session->exec(&qry)))
return false;
qry.done();
qry.freeData();
return true;
}
// ======================================================================
MarketAuctionsBufferUpdate::MarketAuctionsBufferUpdate() :
AbstractTableBuffer(),
m_rows()
{
}
// ----------------------------------------------------------------------
MarketAuctionsBufferUpdate::~MarketAuctionsBufferUpdate(void)
{
for (IndexType::iterator i=m_rows.begin(); i!=m_rows.end(); ++i)
{
delete i->second;
i->second=NULL;
}
}
// ----------------------------------------------------------------------
bool MarketAuctionsBufferUpdate::load(DB::Session *session, const DB::TagSet &tags, const std::string &schema, bool usingGoldDatabase)
{
return true;
}
// ----------------------------------------------------------------------
void MarketAuctionsBufferUpdate::removeObject(const NetworkId &object)
{
removeMarketAuctions(object);
}
// ----------------------------------------------------------------------
void MarketAuctionsBufferUpdate::removeMarketAuctions(const NetworkId &itemId)
{
DEBUG_REPORT_LOG(true, ("MarketAuctionsBufferUpdate Removing Market Auctions Buffer Row. rowcount:%d\n", m_rows.size()));
DBSchema::MarketAuctionsRowUpdate *row=findRowByIndex(itemId);
if (row)
{
delete row;
IGNORE_RETURN(m_rows.erase(itemId));
DEBUG_REPORT_LOG(true, ("MarketAuctionsBufferUpdate Removing Market Auctions Buffer Row. rowcount:%d\n", m_rows.size()));
}
}
// ----------------------------------------------------------------------
void MarketAuctionsBufferUpdate::setMarketAuctions(const NetworkId &itemId, const NetworkId &ownerId, const int active)
{
DBSchema::MarketAuctionsRowUpdate *row=findRowByIndex(itemId);
if (!row)
{
row=new DBSchema::MarketAuctionsRowUpdate;
addRowToIndex(itemId, row);
}
row->item_id = itemId;
row->owner_id = ownerId;
row->active = active;
}
// ----------------------------------------------------------------------
DBSchema::MarketAuctionsRowUpdate * MarketAuctionsBufferUpdate::findRowByIndex(const NetworkId &itemId)
{
DEBUG_REPORT_LOG(true, ("MarketAuctionsBufferUpdate Finding row by Index. ItemId : %s.\n", itemId.getValueString().c_str()));
IndexType::iterator i=m_rows.find(itemId);
if (i==m_rows.end())
return 0;
else
return (*i).second;
}
// ----------------------------------------------------------------------
void MarketAuctionsBufferUpdate::addRowToIndex (const NetworkId &itemId, DBSchema::MarketAuctionsRowUpdate *row)
{
DEBUG_REPORT_LOG(true, ("MarketAuctionsBufferUpdate Adding row to Index. ItemId : %s.\n", itemId.getValueString().c_str()));
m_rows[itemId]=row;
}
// ----------------------------------------------------------------------
bool MarketAuctionsBufferUpdate::save(DB::Session *session)
{
LOG("SaveCounts",("MarketAuctionsBufferUpdate: %i saved to db",m_rows.size()));
DEBUG_REPORT_LOG(true, ("MarketAuctionsBufferUpdate Saving Market Auctions Buffer. rowcount:%d\n", m_rows.size()));
DBQuery::MarketAuctionsQuery qry;
qry.updateMode();
if (!qry.setupData(session))
return false;
for (IndexType::iterator i=m_rows.begin(); i!=m_rows.end(); ++i)
{
if (!qry.addData(i->second))
return false;
LOG("CommoditiesServer", ("MarketAuctionsBufferUpdate Added row to MarketAuctionsQuery VARRAY for item %s", (i->second)->item_id.getValueASCII().c_str()));
if (qry.getNumItems() >= MarketAuctionsTableBufferNamespace::ms_maxItemsPerExec)
{
if (! (session->exec(&qry)))
return false;
qry.clearData();
}
}
if (qry.getNumItems() != 0)
if (! (session->exec(&qry)))
return false;
qry.done();
qry.freeData();
return true;
}
// ======================================================================
@@ -0,0 +1,121 @@
// ======================================================================
//
// MarketAuctionsBuffer.h
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#ifndef INCLUDED_MarketAuctionsBuffer_H
#define INCLUDED_MarketAuctionsBuffer_H
// ======================================================================
#include "SwgDatabaseServer/CommoditiesQuery.h"
#include "SwgDatabaseServer/CommoditiesSchema.h"
#include "serverDatabase/AbstractTableBuffer.h"
#include <hash_map>
#include <string>
// ======================================================================
namespace MarketAuctionsTableBufferNamespace
{
const int ms_maxItemsPerExec = 10000;
}
using namespace MarketAuctionsTableBufferNamespace;
// ======================================================================
class MarketAuctionsBufferCreate : public AbstractTableBuffer
{
public:
MarketAuctionsBufferCreate();
virtual ~MarketAuctionsBufferCreate();
virtual bool load(DB::Session *session, const DB::TagSet &tags, const std::string &schema, bool usingGoldDatabase);
virtual bool save(DB::Session *session);
DBSchema::MarketAuctionsRow * findRowByIndex (const NetworkId &itemId);
void setMarketAuctions (const NetworkId &itemId, const NetworkId &ownerId, const int active);
void setMarketAuctions (const NetworkId &itemId, const NetworkId &ownerId, const NetworkId &creatorId, const NetworkId &locationId, const int minBid, const int buyNowPrice, const int auctionTimer, std::vector<std::pair<std::string, Unicode::String> > const & attributes, const Unicode::String userDescription, const int category, const int itemTemplateId, const Unicode::String itemName, const int itemTimer, const int active, const int itemSize);
void removeMarketAuctions (const NetworkId &itemId);
virtual void removeObject (const NetworkId &object);
private:
void addRowToIndex (const NetworkId &itemId, DBSchema::MarketAuctionsRow *row);
private:
typedef std::hash_map<NetworkId, DBSchema::MarketAuctionsRow*> IndexType;
IndexType m_rows;
typedef std::hash_map<NetworkId, std::vector<std::pair<std::string, Unicode::String> > > AttributesType;
AttributesType m_attributes;
private:
MarketAuctionsBufferCreate(const MarketAuctionsBufferCreate&); //disable
MarketAuctionsBufferCreate & operator=(const MarketAuctionsBufferCreate&); //disable
}; //lint !e1712 // IndexKey has no default constructor
// ======================================================================
class MarketAuctionsBufferDelete : public AbstractTableBuffer
{
public:
explicit MarketAuctionsBufferDelete();
virtual ~MarketAuctionsBufferDelete();
virtual bool load(DB::Session *session, const DB::TagSet &tags, const std::string &schema, bool usingGoldDatabase);
virtual bool save(DB::Session *session);
DBSchema::MarketAuctionsRowDelete * findRowByIndex(const NetworkId &itemId);
void setMarketAuctions (const NetworkId &itemId);
void removeMarketAuctions (const NetworkId &itemId);
virtual void removeObject (const NetworkId &object);
private:
void addRowToIndex (const NetworkId &itemId, DBSchema::MarketAuctionsRowDelete *row);
private:
typedef std::hash_map<NetworkId, DBSchema::MarketAuctionsRowDelete*> IndexType;
IndexType m_rows;
private:
MarketAuctionsBufferDelete(const MarketAuctionsBufferDelete&); //disable
MarketAuctionsBufferDelete & operator=(const MarketAuctionsBufferDelete&); //disable
}; //lint !e1712 // IndexKey has no default constructor
// ======================================================================
class MarketAuctionsBufferUpdate : public AbstractTableBuffer
{
public:
explicit MarketAuctionsBufferUpdate();
virtual ~MarketAuctionsBufferUpdate();
virtual bool load(DB::Session *session, const DB::TagSet &tags, const std::string &schema, bool usingGoldDatabase);
virtual bool save(DB::Session *session);
DBSchema::MarketAuctionsRowUpdate * findRowByIndex(const NetworkId &itemId);
void setMarketAuctions (const NetworkId &itemId, const NetworkId &ownerId, const int active);
void removeMarketAuctions (const NetworkId &itemId);
virtual void removeObject (const NetworkId &object);
private:
void addRowToIndex (const NetworkId &itemId, DBSchema::MarketAuctionsRowUpdate *row);
private:
typedef std::hash_map<NetworkId, DBSchema::MarketAuctionsRowUpdate*> IndexType;
IndexType m_rows;
private:
MarketAuctionsBufferUpdate(const MarketAuctionsBufferUpdate&); //disable
MarketAuctionsBufferUpdate & operator=(const MarketAuctionsBufferUpdate&); //disable
}; //lint !e1712 // IndexKey has no default constructor
// ======================================================================
#endif
@@ -0,0 +1,205 @@
// ======================================================================
//
// MessageBuffer.cpp
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#include "SwgDatabaseServer/FirstSwgDatabaseServer.h"
#include "SwgDatabaseServer/MessageBuffer.h"
#include "SwgDatabaseServer/MessageQuery.h"
#include "serverDatabase/ConfigServerDatabase.h"
#include "serverDatabase/DatabaseProcess.h"
#include "serverDatabase/GameServerConnection.h"
#include "serverDatabase/Loader.h"
#include "serverDatabase/MessageToManager.h"
#include "serverNetworkMessages/MessageToMessage.h"
#include "sharedDatabaseInterface/DbSession.h"
#include "sharedLog/Log.h"
// ======================================================================
MessageBuffer::~MessageBuffer()
{
}
// ----------------------------------------------------------------------
void MessageBuffer::handleMessageTo(const MessageToPayload &message)
{
DEBUG_FATAL(m_data.find(message.getMessageId())!=m_data.end(),("Received duplicate messageTo, id %s.\n",message.getMessageId().getValueString().c_str()));
if (message.getNetworkId().getValue() <= static_cast<NetworkId::NetworkIdType>(0))
DEBUG_WARNING(true,("Ignored persisted messageTo sent to invalid object id %s, method %s",message.getNetworkId().getValueString().c_str(), message.getMethod().c_str()));
else
m_data[message.getMessageId()]=message;
}
// ----------------------------------------------------------------------
void MessageBuffer::handleMessageToAck(const MessageToId &messageId)
{
MessageMap::iterator i=m_data.find(messageId);
if (i!=m_data.end())
{
// we have the message in the buffer, so we can just delete it without involving the database
m_data.erase(i);
}
else
{
// we don't have the message, so it must have already been persisted to the database
// set a flag to remove it from the DB
m_ackedMessages.push_back(messageId);
}
}
// ----------------------------------------------------------------------
bool MessageBuffer::save(DB::Session *session)
{
int actualSaves=0;
DBQuery::SaveMessageQuery qry;
if (!qry.setupData(session))
return false;
for (MessageMap::const_iterator i=m_data.begin(); i!=m_data.end(); ++i)
{
if (m_cancelledObjects.find(i->second.getNetworkId())==m_cancelledObjects.end())
{
++actualSaves;
if (!qry.addData((*i).second))
return false;
if (qry.getNumItems() == ConfigServerDatabase::getDefaultMessageBulkBindSize())
{
if (! (session->exec(&qry)))
return false;
qry.clearData();
}
}
}
if (qry.getNumItems() != 0)
if (! (session->exec(&qry)))
return false;
qry.done();
qry.freeData();
DBQuery::AckMessageQuery ackqry;
if (!ackqry.setupData(session))
return false;
for (AckedMessagesType::const_iterator j=m_ackedMessages.begin(); j!=m_ackedMessages.end(); ++j)
{
if (!ackqry.addData(*j))
return false;
if (ackqry.getNumItems() == ConfigServerDatabase::getDefaultMessageBulkBindSize())
{
if (! (session->exec(&ackqry)))
return false;
ackqry.clearData();
}
}
if (ackqry.getNumItems() != 0)
if (! (session->exec(&ackqry)))
return false;;
ackqry.done();
ackqry.freeData();
LOG("SaveCounts",("Messages: %i out of %i saved in db, %i acks sent to db",actualSaves,m_data.size(),m_ackedMessages.size()));
return true;
}
// ----------------------------------------------------------------------
bool MessageBuffer::load(DB::Session *session, const DB::TagSet &tags, const std::string &schema, bool)
{
int rowsFetched;
UNREF(tags); // any object can have messages
DBQuery::LoadMessagesQuery qry(schema);
if (! (session->exec(&qry)))
return false;
while ((rowsFetched = qry.fetch()) > 0)
{
size_t numRows = qry.getNumRowsFetched();
size_t count = 0;
const std::vector<DBQuery::LoadMessagesQuery::MessageRow> &data =qry.getData();
for (std::vector<DBQuery::LoadMessagesQuery::MessageRow>::const_iterator i=data.begin(); i!=data.end(); ++i)
{
if (++count > numRows)
break;
std::string utf8data;
i->packed_data.getValue(utf8data);
std::vector<int8> packedDataVector;
qry.convertUTF8ToMessage(utf8data, packedDataVector);
MessageToPayload messageData(i->object_id.getValue(),
i->message_id.getValue(),
Unicode::wideToNarrow(i->method.getValue()),
packedDataVector,
i->call_time.getValue(),
i->guaranteed.getValue(),
static_cast<MessageToPayload::DeliveryType>(i->delivery_type.getValue()),
NetworkId::cms_invalid,
std::string(),
0);
messageData.setPersisted(true);
m_data[i->message_id.getValue()]=messageData;
}
}
qry.done();
return (rowsFetched >= 0);
}
// ----------------------------------------------------------------------
/**
* Send all the messages in the buffer to the GameServer, which will enqueue
* them and handle them when their timers expire.
* Note: This requires that all the objects loaded have already been
* sent to the game server.
*/
void MessageBuffer::sendMessages(GameServerConnection &conn) const
{
for (MessageMap::const_iterator i=m_data.begin(); i!=m_data.end(); ++i)
{
if (!MessageToManager::getInstance().hasMessage(i->second.getMessageId()))
{
MessageToMessage const msg((*i).second, DatabaseProcess::getInstance().getProcessId());
conn.send(msg, true);
}
}
}
// ----------------------------------------------------------------------
void MessageBuffer::removeObject(const NetworkId &object)
{
// Too slow to hunt down all the messages & acks for this object, so easier to make
// a set of objects and skip any new messages for these objects
m_cancelledObjects.insert(object);
}
// ----------------------------------------------------------------------
/**
* Called by the main thread after persistence is complete.
* Remove all the saved messages from the MessageToManager, since
* they will be reloaded from the DB if needed.
*/
void MessageBuffer::removeSavedMessagesFromMemory () const
{
for (MessageMap::const_iterator i=m_data.begin(); i!=m_data.end(); ++i)
MessageToManager::getInstance().onMessagePersisted(i->second.getMessageId());
}
// ======================================================================
@@ -0,0 +1,62 @@
// ======================================================================
//
// MessageBuffer.h
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#ifndef INCLUDED_MessageBuffer_H
#define INCLUDED_MessageBuffer_H
// ======================================================================
#include "serverDatabase/AbstractTableBuffer.h"
#include "serverNetworkMessages/MessageToPayload.h"
#include <map>
#include <vector>
#include <set>
// ======================================================================
namespace DB
{
class Session;
}
class GameServerConnection;
// ======================================================================
/**
* A buffer to hold messageTo commands.
*/
class MessageBuffer : public AbstractTableBuffer
{
public:
void handleMessageTo (const MessageToPayload &message);
void handleMessageToAck (const MessageToId &messageId);
void sendMessages (GameServerConnection &conn) const;
void removeSavedMessagesFromMemory () const;
virtual bool save(DB::Session *session);
virtual bool load(DB::Session *session, const DB::TagSet &tags, const std::string &schema, bool usingGoldDatabase);
virtual void removeObject(const NetworkId &object);
public:
virtual ~MessageBuffer();
private:
typedef std::map<MessageToId,MessageToPayload> MessageMap;
typedef std::vector<MessageToId> AckedMessagesType;
typedef std::set<NetworkId> OIDList;
private:
MessageMap m_data;
AckedMessagesType m_ackedMessages;
OIDList m_cancelledObjects;
};
// ======================================================================
#endif
@@ -0,0 +1,819 @@
// ======================================================================
//
// ObjectTableBuffer.cpp
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#include "SwgDatabaseServer/FirstSwgDatabaseServer.h"
#include "ObjectTableBuffer.h"
#include <vector>
#include <map>
#include <set>
#include "SwgDatabaseServer/DeleteDemandLoadedContainerQuery.h"
#include "SwgDatabaseServer/Schema.h"
#include "serverDatabase/DatabaseProcess.h"
#include "serverDatabase/GetContentsList.h"
#include "serverNetworkMessages/GetMoneyFromOfflineObjectMessage.h"
#include "serverNetworkMessages/UpdateObjectPositionMessage.h"
#include "sharedDatabaseInterface/DbSession.h"
#include "sharedLog/Log.h"
#include "sharedMath/Quaternion.h"
#include "sharedNetworkMessages/MessageQueueDataTransform.h"
#include "sharedNetworkMessages/ObjectChannelMessages.h"
// ======================================================================
namespace ObjectTableBufferNamespace
{
static const int s_numPositions = 20;
static const int s_positionMasks[20] = {1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768,65536,131072,262144,524288};
static const int s_allPositionsSet = 1048575;
}
using namespace ObjectTableBufferNamespace;
// ======================================================================
ObjectTableBuffer::ObjectTableBuffer(DB::ModeQuery::Mode mode) :
IndexedNetworkTableBuffer<DBSchema::ObjectBufferRow, DBSchema::ObjectRow, DBQuery::ObjectsTableQuery, DBQuery::ObjectsTableQuerySelect>(mode)
{
}
// ======================================================================
ObjectTableBuffer::~ObjectTableBuffer()
{
}
// ----------------------------------------------------------------------
/**
* Called when a new object is created.
*
* Sets up the data for the object in the Objects table.
*/
void ObjectTableBuffer::newObject(const NetworkId &objectId, int templateId, Tag typeId)
{
DBSchema::ObjectBufferRow *row=addEmptyRow(objectId);
row->object_template_id.setValue(templateId);
row->type_id.setValue(static_cast<long>(typeId)); // cast because tags are unsigned
row->deleted.setValue(0);
row->controller_type.setValue(0);
}
// ----------------------------------------------------------------------
bool ObjectTableBuffer::handleUpdateObjectPosition(const UpdateObjectPositionMessage &message)
{
DBSchema::ObjectBufferRow *row=dynamic_cast<DBSchema::ObjectBufferRow*>(findRowByIndex(message.getNetworkId()));
if (row==0)
{
row=addEmptyRow(message.getNetworkId());
}
Vector v = message.getTransform().getPosition_p();
row->x = static_cast<double>(v.x);
row->y = static_cast<double>(v.y);
row->z = static_cast<double>(v.z);
Quaternion q(message.getTransform());
Transform t;
q.getTransform(&t);
row->quaternion_w = static_cast<double>(q.w);
row->quaternion_x = static_cast<double>(q.x);
row->quaternion_y = static_cast<double>(q.y);
row->quaternion_z = static_cast<double>(q.z);
row->node_x=roundToNode(v.x);
row->node_y=roundToNode(v.y);
row->node_z=roundToNode(v.z);
row->contained_by = message.getContainerId();
row->slot_arrangement = message.getSlotArrangement();
row->load_with = message.getLoadWith();
return true;
}
// ----------------------------------------------------------------------
/**
* Process a delete message for an object.
*
* Sets the "deleted" column to "true".
*
* Note: even if the object is a new object, leaves it in the buffer
* (but filters it out in save().) This is to avoid a possible bug
* where some delta comes to the object after it is deleted, and we end
* up creating a new row that doesn't have "deleted" set.
*/
void ObjectTableBuffer::handleDeleteMessage(const NetworkId &objectId, int reasonCode, bool demandLoadedContainer, bool cascadeDeleteReason)
{
DEBUG_FATAL(reasonCode==0,("Programmer bug: The gameserver sent 0 as the reason code when deleting object %s, but 0 indicates the object is not deleted.\n",objectId.getValueString().c_str()));
DBSchema::ObjectBufferRow *row=dynamic_cast<DBSchema::ObjectBufferRow*>(findRowByIndex(objectId));
if (row==0)
row=addEmptyRow(objectId);
row->deleted.setValue(reasonCode);
if (demandLoadedContainer)
{
if (cascadeDeleteReason)
m_demandLoadedContainersToDelete.push_back(std::make_pair(objectId, reasonCode));
else
m_demandLoadedContainersToDelete.push_back(std::make_pair(objectId, 0));
}
}
// ----------------------------------------------------------------------
int ObjectTableBuffer::roundToNode(real coordinate)
{
int c=static_cast<int>(coordinate);
// (c/chunksize)*chunksize : ... blah
return (c >= 0) ? (c/100)*100 : (((c-100)+1)/100)*100;
}
// ----------------------------------------------------------------------
// Topological sort
struct DFSNode
{
NetworkId m_oid;
NetworkId m_containedBy;
bool m_visited;
};
// ----------------------------------------------------------------------
void ObjectTableBuffer::getTags(DB::TagSet &tags) const
{
for (IndexType::const_iterator r=m_rows.begin(); r!=m_rows.end(); ++r)
tags.insert(r->second->type_id.getValue());
}
// ----------------------------------------------------------------------
void ObjectTableBuffer::getObjectList(stdvector<NetworkId>::fwd &theList) const
{
typedef std::map <NetworkId, DFSNode> NodesType;
NodesType nodes;
std::vector <DFSNode*> nodeStack;
// Copy the rows to our temporary space for sorting
for (IndexType::const_iterator r=m_rows.begin(); r!=m_rows.end(); ++r)
{
DFSNode &newNode = nodes[r->second->object_id.getValue()];
newNode.m_oid = r->second->object_id.getValue();
newNode.m_containedBy = r->second->contained_by.getValue();
newNode.m_visited = false;
}
// Depth-first search, outputting the nodes as we recurse *out* of them
for (NodesType::iterator i=nodes.begin(); i!=nodes.end(); ++i)
{
if (!i->second.m_visited)
{
nodeStack.push_back(&i->second);
i->second.m_visited = true;
while (!nodeStack.empty())
{
DFSNode *theNode = nodeStack.back();
bool noContainer = true;
if (theNode->m_containedBy!=NetworkId::cms_invalid)
{
NodesType::iterator j=nodes.find(theNode->m_containedBy);
if (j!=nodes.end() && !(j->second.m_visited))
{
nodeStack.push_back(&(j->second));
j->second.m_visited = true;
noContainer=false;
}
}
if (noContainer)
{
nodeStack.pop_back();
theList.push_back(theNode->m_oid);
}
}
}
}
}
// ----------------------------------------------------------------------
bool ObjectTableBuffer::save(DB::Session *session)
{
int updates=0;
int deletes=0;
int onlyPositionOrDeletes=0;
DBQuery::ObjectsTableQuery qry;
if (getMode()==DB::ModeQuery::mode_INSERT)
qry.insertMode();
else
qry.updateMode();
if (!qry.setupData(session))
return false;
for (IndexType::iterator i=m_rows.begin(); i!=m_rows.end(); ++i)
{
if (i->second->object_template_id.isNull() &&
i->second->type_id.isNull() &&
i->second->scene_id.isNull() &&
i->second->controller_type.isNull() &&
i->second->object_name.isNull() &&
i->second->volume.isNull() &&
i->second->slot_arrangement.isNull() &&
i->second->player_controlled.isNull() &&
i->second->cache_version.isNull() &&
i->second->load_contents.isNull() &&
i->second->cash_balance.isNull() &&
i->second->bank_balance.isNull() &&
i->second->complexity.isNull() &&
i->second->name_string_table.isNull() &&
i->second->name_string_text.isNull())
{
++onlyPositionOrDeletes;
}
if (!i->second->deleted.isNull() && i->second->deleted.getValue()!=0)
++deletes;
if (getMode()==DB::ModeQuery::mode_INSERT && !i->second->deleted.isNull() && i->second->deleted.getValue()!=0)
{
// DEBUG_REPORT_LOG(true,("Skipped saving deleted object %s\n",i->second->object_id.getValue().getValueString().c_str()));
}
else
{
++updates;
qry.setData(*(i->second));
#if 0 // Enable this to debug load_with problems
DEBUG_REPORT_LOG(true,("Save object %s ",i->second->object_id.getValue().getValueString().c_str()));
if (i->second->contained_by.isNull())
DEBUG_REPORT_LOG(true, ("contained_by NULL "));
else
DEBUG_REPORT_LOG(true, ("contained_by %s ",i->second->contained_by.getValue().getValueString().c_str()));
if (i->second->load_with.isNull())
DEBUG_REPORT_LOG(true,("load_with NULL\n"));
else
DEBUG_REPORT_LOG(true,("load_with %s\n",i->second->load_with.getValue().getValueString().c_str()));
#endif
if (!qry.addData((i->second)))
return false;
if (qry.getNumItems() == ObjectTableBufferNamespace::ms_maxItemsPerExec)
{
if (! (session->exec(&qry)))
return false;
qry.clearData();
}
}
}
if (qry.getNumItems() != 0)
if (! (session->exec(&qry)))
return false;
qry.done();
qry.freeData();
if (!m_demandLoadedContainersToDelete.empty())
{
DBQuery::DeleteDemandLoadedContainerQuery ddlcq;
if (!ddlcq.setupData(*session))
return false;
for (std::vector<std::pair<NetworkId, int> >::const_iterator i=m_demandLoadedContainersToDelete.begin(); i!=m_demandLoadedContainersToDelete.end(); ++i)
{
if (!ddlcq.addData(i->first, i->second))
return false;
if (ddlcq.getCount() == ObjectTableBufferNamespace::ms_maxItemsPerExec)
{
if (! (session->exec(&ddlcq)))
return false;
ddlcq.clearData();
}
}
if (ddlcq.getCount() != 0)
{
if (! (session->exec(&ddlcq)))
return false;
ddlcq.clearData();
}
ddlcq.done();
ddlcq.freeData();
}
if (getMode()==DB::ModeQuery::mode_INSERT)
LOG("SaveCounts",("Object table new objects: %i (out of %i) total, %i only position or delete, %i delete\n",updates,m_rows.size(),onlyPositionOrDeletes,deletes));
else
LOG("SaveCounts",("Object table updates: %i total, %i only position or delete, %i delete\n",updates,onlyPositionOrDeletes,deletes));
return true;
}
// ----------------------------------------------------------------------
void ObjectTableBuffer::decodeObjVarFreeFlags(const NetworkId &objectId, int freePositions)
{
// DEBUG_REPORT_LOG(true,("OBJVAR_DEBUG: decodeObjVarFreeFlags(%s,%i)\n",objectId.getValueString().c_str(),freePositions));
DBSchema::ObjectBufferRow *row=dynamic_cast<DBSchema::ObjectBufferRow*>(findRowByIndex(objectId));
if (row==0)
row=addEmptyRow(objectId);
for (int i=0; i<s_numPositions; ++i)
{
bool set=((s_positionMasks[i] & freePositions)!=0);
if (set)
{
switch (i)
{
case 0:
row->objvar_0_type = -1;
break;
case 1:
row->objvar_1_type = -1;
break;
case 2:
row->objvar_2_type = -1;
break;
case 3:
row->objvar_3_type = -1;
break;
case 4:
row->objvar_4_type = -1;
break;
case 5:
row->objvar_5_type = -1;
break;
case 6:
row->objvar_6_type = -1;
break;
case 7:
row->objvar_7_type = -1;
break;
case 8:
row->objvar_8_type = -1;
break;
case 9:
row->objvar_9_type = -1;
break;
case 10:
row->objvar_10_type = -1;
break;
case 11:
row->objvar_11_type = -1;
break;
case 12:
row->objvar_12_type = -1;
break;
case 13:
row->objvar_13_type = -1;
break;
case 14:
row->objvar_14_type = -1;
break;
case 15:
row->objvar_15_type = -1;
break;
case 16:
row->objvar_16_type = -1;
break;
case 17:
row->objvar_17_type = -1;
break;
case 18:
row->objvar_18_type = -1;
break;
case 19:
row->objvar_19_type = -1;
break;
default:
DEBUG_FATAL(true,("ObjectId %s had freePositions flag %i, which is not valid.",objectId.getValueString().c_str(),freePositions));
}
}
}
}
// ----------------------------------------------------------------------
void ObjectTableBuffer::handlePackedObjvar(const NetworkId &objectId, int position, const std::string &objvarName, int typeId, const std::string &packedValue)
{
// DEBUG_REPORT_LOG(true,("OBJVAR_DEBUG: handlePackedObjvar(%s,%i,%s,%i,%s)\n",objectId.getValueString().c_str(),position,objvarName.c_str(), typeId, packedValue.c_str()));
DBSchema::ObjectBufferRow *row=dynamic_cast<DBSchema::ObjectBufferRow*>(findRowByIndex(objectId));
if (row==0)
row=addEmptyRow(objectId);
switch(position)
{
case 0:
row->objvar_0_name = objvarName;
row->objvar_0_type = typeId;
row->objvar_0_value = packedValue;
break;
case 1:
row->objvar_1_name = objvarName;
row->objvar_1_type = typeId;
row->objvar_1_value = packedValue;
break;
case 2:
row->objvar_2_name = objvarName;
row->objvar_2_type = typeId;
row->objvar_2_value = packedValue;
break;
case 3:
row->objvar_3_name = objvarName;
row->objvar_3_type = typeId;
row->objvar_3_value = packedValue;
break;
case 4:
row->objvar_4_name = objvarName;
row->objvar_4_type = typeId;
row->objvar_4_value = packedValue;
break;
case 5:
row->objvar_5_name = objvarName;
row->objvar_5_type = typeId;
row->objvar_5_value = packedValue;
break;
case 6:
row->objvar_6_name = objvarName;
row->objvar_6_type = typeId;
row->objvar_6_value = packedValue;
break;
case 7:
row->objvar_7_name = objvarName;
row->objvar_7_type = typeId;
row->objvar_7_value = packedValue;
break;
case 8:
row->objvar_8_name = objvarName;
row->objvar_8_type = typeId;
row->objvar_8_value = packedValue;
break;
case 9:
row->objvar_9_name = objvarName;
row->objvar_9_type = typeId;
row->objvar_9_value = packedValue;
break;
case 10:
row->objvar_10_name = objvarName;
row->objvar_10_type = typeId;
row->objvar_10_value = packedValue;
break;
case 11:
row->objvar_11_name = objvarName;
row->objvar_11_type = typeId;
row->objvar_11_value = packedValue;
break;
case 12:
row->objvar_12_name = objvarName;
row->objvar_12_type = typeId;
row->objvar_12_value = packedValue;
break;
case 13:
row->objvar_13_name = objvarName;
row->objvar_13_type = typeId;
row->objvar_13_value = packedValue;
break;
case 14:
row->objvar_14_name = objvarName;
row->objvar_14_type = typeId;
row->objvar_14_value = packedValue;
break;
case 15:
row->objvar_15_name = objvarName;
row->objvar_15_type = typeId;
row->objvar_15_value = packedValue;
break;
case 16:
row->objvar_16_name = objvarName;
row->objvar_16_type = typeId;
row->objvar_16_value = packedValue;
break;
case 17:
row->objvar_17_name = objvarName;
row->objvar_17_type = typeId;
row->objvar_17_value = packedValue;
break;
case 18:
row->objvar_18_name = objvarName;
row->objvar_18_type = typeId;
row->objvar_18_value = packedValue;
break;
case 19:
row->objvar_19_name = objvarName;
row->objvar_19_type = typeId;
row->objvar_19_value = packedValue;
break;
default:
WARNING_STRICT_FATAL(true,("ObjectId %s had objvar %s with postion %i, which is not a valid position.",objectId.getValueString().c_str(),objvarName.c_str(), position));
}
}
// ----------------------------------------------------------------------
void ObjectTableBuffer::getObjvarsForObject(const NetworkId &objectId, std::vector<DynamicVariableList::MapType::Command> &commands) const
{
const DBSchema::ObjectBufferRow *row=safe_cast<const DBSchema::ObjectBufferRow*>(findConstRowByIndex(objectId));
if (row==0)
{
WARNING_STRICT_FATAL(true,("Loaded OBJECT_VARIABLES for %s, but had no OBJECTS row.",objectId.getValueString().c_str()));
return;
}
DynamicVariableList::MapType::Command c;
c.cmd = DynamicVariableList::MapType::Command::ADD;
if (row->objvar_0_type.getValue() >= 0)
{
row->objvar_0_name.getValue(c.key);
c.value.load(0, row->objvar_0_type.getValue(), row->objvar_0_value.getValue());
commands.push_back(c);
}
if (row->objvar_1_type.getValue() >= 0)
{
row->objvar_1_name.getValue(c.key);
c.value.load(1, row->objvar_1_type.getValue(), row->objvar_1_value.getValue());
commands.push_back(c);
}
if (row->objvar_2_type.getValue() >= 0)
{
row->objvar_2_name.getValue(c.key);
c.value.load(2, row->objvar_2_type.getValue(), row->objvar_2_value.getValue());
commands.push_back(c);
}
if (row->objvar_3_type.getValue() >= 0)
{
row->objvar_3_name.getValue(c.key);
c.value.load(3, row->objvar_3_type.getValue(), row->objvar_3_value.getValue());
commands.push_back(c);
}
if (row->objvar_4_type.getValue() >= 0)
{
row->objvar_4_name.getValue(c.key);
c.value.load(4, row->objvar_4_type.getValue(), row->objvar_4_value.getValue());
commands.push_back(c);
}
if (row->objvar_5_type.getValue() >= 0)
{
row->objvar_5_name.getValue(c.key);
c.value.load(5, row->objvar_5_type.getValue(), row->objvar_5_value.getValue());
commands.push_back(c);
}
if (row->objvar_6_type.getValue() >= 0)
{
row->objvar_6_name.getValue(c.key);
c.value.load(6, row->objvar_6_type.getValue(), row->objvar_6_value.getValue());
commands.push_back(c);
}
if (row->objvar_7_type.getValue() >= 0)
{
row->objvar_7_name.getValue(c.key);
c.value.load(7, row->objvar_7_type.getValue(), row->objvar_7_value.getValue());
commands.push_back(c);
}
if (row->objvar_8_type.getValue() >= 0)
{
row->objvar_8_name.getValue(c.key);
c.value.load(8, row->objvar_8_type.getValue(), row->objvar_8_value.getValue());
commands.push_back(c);
}
if (row->objvar_9_type.getValue() >= 0)
{
row->objvar_9_name.getValue(c.key);
c.value.load(9, row->objvar_9_type.getValue(), row->objvar_9_value.getValue());
commands.push_back(c);
}
if (row->objvar_10_type.getValue() >= 0)
{
row->objvar_10_name.getValue(c.key);
c.value.load(10, row->objvar_10_type.getValue(), row->objvar_10_value.getValue());
commands.push_back(c);
}
if (row->objvar_11_type.getValue() >= 0)
{
row->objvar_11_name.getValue(c.key);
c.value.load(11, row->objvar_11_type.getValue(), row->objvar_11_value.getValue());
commands.push_back(c);
}
if (row->objvar_12_type.getValue() >= 0)
{
row->objvar_12_name.getValue(c.key);
c.value.load(12, row->objvar_12_type.getValue(), row->objvar_12_value.getValue());
commands.push_back(c);
}
if (row->objvar_13_type.getValue() >= 0)
{
row->objvar_13_name.getValue(c.key);
c.value.load(13, row->objvar_13_type.getValue(), row->objvar_13_value.getValue());
commands.push_back(c);
}
if (row->objvar_14_type.getValue() >= 0)
{
row->objvar_14_name.getValue(c.key);
c.value.load(14, row->objvar_14_type.getValue(), row->objvar_14_value.getValue());
commands.push_back(c);
}
if (row->objvar_15_type.getValue() >= 0)
{
row->objvar_15_name.getValue(c.key);
c.value.load(15, row->objvar_15_type.getValue(), row->objvar_15_value.getValue());
commands.push_back(c);
}
if (row->objvar_16_type.getValue() >= 0)
{
row->objvar_16_name.getValue(c.key);
c.value.load(16, row->objvar_16_type.getValue(), row->objvar_16_value.getValue());
commands.push_back(c);
}
if (row->objvar_17_type.getValue() >= 0)
{
row->objvar_17_name.getValue(c.key);
c.value.load(17, row->objvar_17_type.getValue(), row->objvar_17_value.getValue());
commands.push_back(c);
}
if (row->objvar_18_type.getValue() >= 0)
{
row->objvar_18_name.getValue(c.key);
c.value.load(18, row->objvar_18_type.getValue(), row->objvar_18_value.getValue());
commands.push_back(c);
}
if (row->objvar_19_type.getValue() >= 0)
{
row->objvar_19_name.getValue(c.key);
c.value.load(19, row->objvar_19_type.getValue(), row->objvar_19_value.getValue());
commands.push_back(c);
}
}
// ----------------------------------------------------------------------
int ObjectTableBuffer::encodeObjVarFreeFlags(const NetworkId & objectId) const
{
const DBSchema::ObjectBufferRow *row=findConstRowByIndex(objectId);
WARNING_STRICT_FATAL(row==NULL,("Loading object %s, no ObjectRow in the buffer\n",objectId.getValueString().c_str()));
if (!row)
return 0;
int positionFlags=0;
for (int i=0; i<s_numPositions; ++i)
{
bool free = false;
switch(i)
{
case 0:
free = (row->objvar_0_type.getValue() < 0);
break;
case 1:
free = (row->objvar_1_type.getValue() < 0);
break;
case 2:
free = (row->objvar_2_type.getValue() < 0);
break;
case 3:
free = (row->objvar_3_type.getValue() < 0);
break;
case 4:
free = (row->objvar_4_type.getValue() < 0);
break;
case 5:
free = (row->objvar_5_type.getValue() < 0);
break;
case 6:
free = (row->objvar_6_type.getValue() < 0);
break;
case 7:
free = (row->objvar_7_type.getValue() < 0);
break;
case 8:
free = (row->objvar_8_type.getValue() < 0);
break;
case 9:
free = (row->objvar_9_type.getValue() < 0);
break;
case 10:
free = (row->objvar_10_type.getValue() < 0);
break;
case 11:
free = (row->objvar_11_type.getValue() < 0);
break;
case 12:
free = (row->objvar_12_type.getValue() < 0);
break;
case 13:
free = (row->objvar_13_type.getValue() < 0);
break;
case 14:
free = (row->objvar_14_type.getValue() < 0);
break;
case 15:
free = (row->objvar_15_type.getValue() < 0);
break;
case 16:
free = (row->objvar_16_type.getValue() < 0);
break;
case 17:
free = (row->objvar_17_type.getValue() < 0);
break;
case 18:
free = (row->objvar_18_type.getValue() < 0);
break;
case 19:
free = (row->objvar_19_type.getValue() < 0);
break;
default:
DEBUG_FATAL(true,("Iterated through too many positions. WTF?"));
}
if (free)
positionFlags += s_positionMasks[i];
}
return positionFlags;
}
// ----------------------------------------------------------------------
void ObjectTableBuffer::getWorldContainers(std::vector<NetworkId> &containers) const
{
for (IndexType::const_iterator r=m_rows.begin(); r!=m_rows.end(); ++r)
{
if ((r->second->contained_by.getValue()==NetworkId::cms_invalid) && (r->second->load_contents.getValue()))
containers.push_back(r->second->object_id.getValue());
}
}
// ----------------------------------------------------------------------
bool ObjectTableBuffer::getMoneyFromOfflineObject(uint32 replyServer, NetworkId const & sourceObject, int amount, NetworkId const & replyTo, std::string const & successCallback, std::string const & failCallback, stdvector<int8>::fwd const & packedDictionary)
{
DBSchema::ObjectBufferRow * const row=findRowByIndex(sourceObject);
if (!row)
return false;
// We might have buffered values for bank balance, cash balance, both, or neither
// We can only change the ones for which we have a value.
bool const definiteBankBalance = !row->bank_balance.isNull();
bool const definiteCashBalance = !row->cash_balance.isNull();
int const previousBankBalance = definiteBankBalance ? row->bank_balance.getValue() : 0;
int const previousCashBalance = definiteCashBalance ? row->cash_balance.getValue() : 0;
if (previousBankBalance + previousCashBalance < amount)
{
if (definiteBankBalance && definiteCashBalance)
{
// send failure message
GetMoneyFromOfflineObjectMessage replyMessage(sourceObject, amount, replyTo, successCallback, failCallback, packedDictionary, false);
DatabaseProcess::getInstance().sendToGameServer(replyServer, replyMessage);
}
else
return false; // can't be handled in memory, but there's a possibility it could be handled in the DB
}
// Has enough money to handle this in memory
int newBankBalance = previousBankBalance - amount;
int newCashBalance = previousCashBalance;
if (newBankBalance < 0)
{
int const remainingAmount = -newBankBalance;
newBankBalance = 0;
newCashBalance -= remainingAmount;
DEBUG_FATAL(newCashBalance < 0,("Programmer bug: newCashBalance ended up negative, which should not be possible. Indicates bad logic in getMoneyFromOfflineObject()"));
}
if (definiteBankBalance)
row->bank_balance=newBankBalance;
if (definiteCashBalance)
row->cash_balance=newCashBalance;
// Send success message
GetMoneyFromOfflineObjectMessage replyMessage(sourceObject, amount, replyTo, successCallback, failCallback, packedDictionary, true);
DatabaseProcess::getInstance().sendToGameServer(replyServer, replyMessage);
return true;
}
// ======================================================================
@@ -0,0 +1,78 @@
// ======================================================================
//
// ObjectTableBuffer.h
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#ifndef INCLUDED_ObjectTableBuffer_H
#define INCLUDED_ObjectTableBuffer_H
// ======================================================================
#include "IndexedNetworkTableBuffer.h"
#include "SwgDatabaseServer/ObjectsTableQuery.h"
#include "sharedFoundation/DynamicVariableList.h"
#include "sharedFoundation/Tag.h"
// ======================================================================
class NetworkId;
class UpdateObjectPositionMessage;
namespace DB
{
class Session;
}
namespace DBSchema
{
struct ObjectRow;
}
namespace ObjectTableBufferNamespace
{
const int ms_maxItemsPerExec = 10000;
}
using namespace ObjectTableBufferNamespace;
// ======================================================================
class ObjectTableBuffer : public IndexedNetworkTableBuffer<DBSchema::ObjectBufferRow, DBSchema::ObjectRow, DBQuery::ObjectsTableQuery, DBQuery::ObjectsTableQuerySelect>
{
public:
explicit ObjectTableBuffer(DB::ModeQuery::Mode mode);
virtual ~ObjectTableBuffer();
// virtual void loadRow(DB::Session *session, const NetworkId &primaryKey);
virtual bool handleUpdateObjectPosition(const UpdateObjectPositionMessage &message);
void handleDeleteMessage(const NetworkId &objectId, int reasonCode, bool demandLoadedContainer, bool cascadeDeleteReason);
void decodeObjVarFreeFlags(const NetworkId &objectId, int freePositions);
int encodeObjVarFreeFlags(const NetworkId & objectId) const;
void handlePackedObjvar(const NetworkId &objectId, int position, const std::string &objvarName, int typeId, const std::string &packedValue);
void getObjvarsForObject(const NetworkId &objectId, std::vector<DynamicVariableList::MapType::Command> &commands) const;
bool getMoneyFromOfflineObject(uint32 replyServer,NetworkId const & sourceObject, int amount, NetworkId const & replyTo, std::string const & successCallback, std::string const & failCallback, stdvector<int8>::fwd const & packedDictionary);
void newObject(const NetworkId &objectId, int templateId, Tag typeId);
// std::vector<NetworkId> queueForLoadWithContents(const stdvector<NetworkId>::fwd &oidList, DB::Session *session);
void getObjectList(stdvector<NetworkId>::fwd &theList) const;
void getWorldContainers(stdvector<NetworkId>::fwd &containers) const;
void getTags(DB::TagSet &tags) const;
virtual bool save(DB::Session *session);
private:
static int roundToNode(real coordinate);
std::vector<std::pair<NetworkId,int> > m_demandLoadedContainersToDelete;
private:
ObjectTableBuffer(); // disable
};
// ======================================================================
#endif
@@ -0,0 +1,348 @@
// ======================================================================
//
// ObjvarBuffer.cpp
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#include "SwgDatabaseServer/FirstSwgDatabaseServer.h"
#include "ObjvarBuffer.h"
#include "SwgDatabaseServer/ObjvarNameManager.h"
#include "serverDatabase/ConfigServerDatabase.h"
#include "serverDatabase/DatabaseProcess.h"
#include "sharedDatabaseInterface/DbSession.h"
#include "sharedLog/Log.h"
// ======================================================================
namespace ObjvarBufferNamespace
{
const int ms_maxItemsPerExec = 10000;
}
using namespace ObjvarBufferNamespace;
// ======================================================================
ObjvarBuffer::ObjvarBuffer(DB::ModeQuery::Mode mode, ObjectTableBuffer *objectTableBuffer, bool useGoldNames) :
AbstractTableBuffer(),
m_mode(mode),
m_data(),
m_objectTableBuffer(objectTableBuffer),
m_useGoldNames(useGoldNames)
{
}
// ----------------------------------------------------------------------
ObjvarBuffer::~ObjvarBuffer()
{
}
// ----------------------------------------------------------------------
/**
* Loads all the object variables for the remembered objectId's
*/
bool ObjvarBuffer::load(DB::Session *session,const DB::TagSet &tags, const std::string &schema, bool usingGoldDatabase)
{
int rowsFetched;
UNREF(tags); // all objects have objvars
DBQuery::GetAllObjectVariables qry(schema);
if (! (session->exec(&qry)))
return false;
while ((rowsFetched = qry.fetch()) > 0)
{
size_t numRows = qry.getNumRowsFetched();
size_t count = 0;
const std::vector<DBSchema::ObjectVariableRow> &data = qry.getData();
for (std::vector<DBSchema::ObjectVariableRow>::const_iterator row=data.begin(); row!=data.end(); ++row)
{
if (++count > numRows)
{
break;
}
IndexKey key(row->object_id.getValue(), row->name_id.getValue());
ObjvarValue value;
value.m_type=row->type.getValue();
// The string is stored in the database as utf8, so a wide-to-narrow is appropriate
value.m_value=Unicode::wideToNarrow(row->value.getValue());
value.m_detached=false;
m_data.insert(std::make_pair(key,value));
}
}
qry.done();
if (rowsFetched < 0)
return false;
if (usingGoldDatabase)
{
// Check for local overrides to the gold data
DBQuery::GetObjectVariableOverrides qry(DatabaseProcess::getInstance().getSchemaQualifier(), schema);
if (! (session->exec(&qry)))
return false;
while ((rowsFetched = qry.fetch()) > 0)
{
size_t numRows = qry.getNumRowsFetched();
size_t count = 0;
const std::vector<DBSchema::ObjectVariableRow> &data = qry.getData();
for (std::vector<DBSchema::ObjectVariableRow>::const_iterator row=data.begin(); row!=data.end(); ++row)
{
if (++count > numRows)
{
break;
}
IndexKey key(row->object_id.getValue(), row->name_id.getValue());
ObjvarValue value;
value.m_type=row->type.getValue();
// The string is stored in the database as utf8, so a wide-to-narrow is appropriate
value.m_value=Unicode::wideToNarrow(row->value.getValue());
value.m_detached=false;
m_overrides.insert(std::make_pair(key,value));
}
}
qry.done();
}
return (rowsFetched >= 0);
}
// ----------------------------------------------------------------------
bool ObjvarBuffer::save(DB::Session *session)
{
LOG("SaveCounts",("Objvars: %i saved to db",m_data.size()));
{
DBQuery::AddObjectVariableQuery addQuery;
if (!addQuery.setupData(session))
return false;
for (DataType::iterator i=m_data.begin(); i!=m_data.end(); ++i)
{
if (!i->second.m_detached && !i->second.m_inDatabase)
if (!addQuery.addData(i->first.m_objectId, i->first.m_nameId, i->second.m_type, i->second.m_value))
return false;
if (addQuery.getNumItems() == ObjvarBufferNamespace::ms_maxItemsPerExec)
{
if (! (session->exec(&addQuery)))
return false;
addQuery.clearData();
}
}
if (addQuery.getNumItems() != 0)
if (! (session->exec(&addQuery)))
return false;
addQuery.done();
addQuery.freeData();
}
{
DBQuery::UpdateObjectVariableQuery updateQuery;
if (!updateQuery.setupData(session))
return false;
for (DataType::iterator i=m_data.begin(); i!=m_data.end(); ++i)
{
if (!i->second.m_detached && i->second.m_inDatabase)
if (!updateQuery.addData(i->first.m_objectId, i->first.m_nameId, i->second.m_type, i->second.m_value))
return false;
if (updateQuery.getNumItems() == ObjvarBufferNamespace::ms_maxItemsPerExec)
{
if (! (session->exec(&updateQuery)))
return false;
updateQuery.clearData();
}
}
if (updateQuery.getNumItems() != 0)
if (! (session->exec(&updateQuery)))
return false;
updateQuery.done();
updateQuery.freeData();
}
{
DBQuery::RemoveObjectVariableQuery removeQuery;
if (!removeQuery.setupData(session))
return false;
for (DataType::iterator i=m_data.begin(); i!=m_data.end(); ++i)
{
if (i->second.m_detached && i->second.m_inDatabase)
if (!removeQuery.addData(i->first.m_objectId, i->first.m_nameId))
return false;
if (removeQuery.getNumItems() == ObjvarBufferNamespace::ms_maxItemsPerExec)
{
if (! (session->exec(&removeQuery)))
return false;
removeQuery.clearData();
}
}
if (removeQuery.getNumItems() != 0)
if (! (session->exec(&removeQuery)))
return false;
removeQuery.done();
removeQuery.freeData();
}
return true;
}
// ----------------------------------------------------------------------
void ObjvarBuffer::getObjvarsForObject(const NetworkId &objectId, std::vector<DynamicVariableList::MapType::Command> &commands) const
{
DynamicVariableList::MapType::Command c;
// unpacked object variables
{
for (DataType::const_iterator i= m_data.lower_bound(IndexKey(objectId,0)); (i!=m_data.end()) && (i->first.m_objectId==objectId); ++i)
{
std::string name;
bool foundName = false;
if (m_useGoldNames)
foundName=ObjvarNameManager::getGoldInstance().getName(i->first.m_nameId, name);
else
foundName=ObjvarNameManager::getInstance().getName(i->first.m_nameId, name);
if (foundName)
{
c.cmd = DynamicVariableList::MapType::Command::ADD;
c.key = name;
c.value.load(-1, i->second.m_type, Unicode::utf8ToWide(i->second.m_value));
commands.push_back(c);
}
else
WARNING_STRICT_FATAL(true,("Object %s has an objvar with name_id %i, which was not in the list of names.",objectId.getValueString().c_str(), i->first.m_nameId));
}
}
//packed object variables
m_objectTableBuffer->getObjvarsForObject(objectId, commands);
// Apply overrides, if any.
// The last objvar sent to the game takes precedence, so we want to send the overrides after the values read in through the regular process
{
for (DataType::const_iterator i= m_overrides.lower_bound(IndexKey(objectId,0)); (i!=m_overrides.end()) && (i->first.m_objectId==objectId); ++i)
{
std::string name;
bool foundName = false;
foundName=ObjvarNameManager::getInstance().getName(i->first.m_nameId, name); // overrides always use the live names, not the gold names.
if (foundName)
{
c.cmd = DynamicVariableList::MapType::Command::ADD;
c.key = name;
c.value.load(-1, i->second.m_type, Unicode::utf8ToWide(i->second.m_value));
commands.push_back(c);
}
else
WARNING_STRICT_FATAL(true,("Object %s has an objvar with name_id %i, which was not in the list of names.",objectId.getValueString().c_str(), i->first.m_nameId));
}
}
}
// ----------------------------------------------------------------------
void ObjvarBuffer::updateObjvars(const NetworkId &objectId, const std::vector<DynamicVariableList::MapType::Command> &commands)
{
bool override=false; // flag that we're dealing with the gold data override case (storing an objvar change in the live database, on an object that came from the gold database)
if (ConfigServerDatabase::getEnableGoldDatabase() && objectId < ConfigServerDatabase::getMaxGoldNetworkId())
override=true;
for (std::vector<DynamicVariableList::MapType::Command>::const_iterator i=commands.begin(); i!=commands.end(); ++i)
{
switch(i->cmd)
{
case DynamicVariableList::MapType::Command::ADD :
case DynamicVariableList::MapType::Command::SET :
{
std::string packedValue(Unicode::wideToUTF8(i->value.getPackedValueString()));
if (i->value.getPosition() !=-1 && ConfigServerDatabase::getEnableObjvarPacking() && !override)
{
m_objectTableBuffer->handlePackedObjvar(objectId, i->value.getPosition(), i->key, i->value.getType(), packedValue);
}
else
{
int nameId = ObjvarNameManager::getInstance().getOrAddNameId(i->key);
DataType::iterator row=m_data.find(IndexKey(objectId, nameId));
if (row==m_data.end())
{
row=m_data.insert(std::make_pair(IndexKey(objectId, nameId),ObjvarValue())).first;
if (i->cmd==DynamicVariableList::MapType::Command::ADD || override)
row->second.m_inDatabase=false; // new variable
else
row->second.m_inDatabase=true; // update to existing variable
}
row->second.m_type = i->value.getType();
row->second.m_value = packedValue;
row->second.m_detached = false;
}
break;
}
case DynamicVariableList::MapType::Command::ERASE :
{
int nameId = ObjvarNameManager::getInstance().getNameId(i->key);
if (nameId != 0) // It's possible to get an ERASE for a packed objvar where the name was never used in the OBJECT_VARIABLES table. We can safely ignore these.
{
DataType::iterator row=m_data.find(IndexKey(objectId, nameId));
if (row==m_data.end())
{
if (i->value.getPosition() == -1 || override)
{
row=m_data.insert(std::make_pair(IndexKey(objectId, nameId),ObjvarValue())).first;
row->second.m_inDatabase=true; // deleting existing variable
}
// else it was a packed objvar, and no update is necessary
}
row->second.m_type = i->value.getType();
row->second.m_detached = true;
}
break;
}
default:
WARNING_STRICT_FATAL(true,("Unknown command %i unpacked in object variables for object %s.",i->cmd,objectId.getValueString().c_str()));
}
}
DEBUG_WARNING(commands.size() > 100,("Object %s has a suspicious number of objvar updates (%i updates).",objectId.getValueString().c_str(),commands.size()));
}
// ----------------------------------------------------------------------
void ObjvarBuffer::removeObject(const NetworkId &object)
{
DataType::iterator i=m_data.lower_bound(IndexKey(object,0));
while (i!=m_data.end() && i->first.m_objectId==object)
{
DataType::iterator next=i;
++next;
m_data.erase(i);
i=next;
}
}
// ======================================================================
@@ -0,0 +1,122 @@
// ======================================================================
//
// ObjvarBuffer.h
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#ifndef INCLUDED_ObjvarBuffer_H
#define INCLUDED_ObjvarBuffer_H
// ======================================================================
#include "SwgDatabaseServer/ObjectTableBuffer.h"
#include "SwgDatabaseServer/ObjectVariableQueries.h"
#include "serverDatabase/AbstractTableBuffer.h"
#include "sharedFoundation/DynamicVariableList.h"
#include <map>
#include <string>
// ======================================================================
class ObjectTableBuffer;
namespace DBSchema
{
struct ObjvarRow;
}
// ======================================================================
/**
* ObjvarBuffer is a table buffer customized to the job of loading and
* saving object variables.
*
* Differences from standard table buffers:
*
* 1) Objvars are keyed by object_id and name
*
* 2) When loading, only the object_id is specified, and all objvars
* are loaded for that object.
*/
class ObjvarBuffer : public AbstractTableBuffer
{
public:
explicit ObjvarBuffer(DB::ModeQuery::Mode mode, ObjectTableBuffer *objectTableBuffer, bool useGoldNames);
virtual ~ObjvarBuffer(void);
virtual bool load(DB::Session *session,const DB::TagSet &tags, const std::string &schema, bool usingGoldDatabase);
virtual bool save(DB::Session *session);
virtual void removeObject(const NetworkId &object);
DBSchema::ObjectVariableRow *findRowByIndex(const NetworkId &objectId, const std::string &name);
void updateObjvars(const NetworkId &objectId, const std::vector<DynamicVariableList::MapType::Command> &commands);
void getObjvarsForObject(const NetworkId &objectId, std::vector<DynamicVariableList::MapType::Command> &commands) const;
private:
struct IndexKey
{
NetworkId m_objectId;
int m_nameId;
IndexKey(const NetworkId &objectId, int nameId);
bool operator==(const IndexKey &rhs) const;
bool operator<(const IndexKey &rhs) const;
};
struct ObjvarValue
{
int m_type;
std::string m_value;
bool m_detached;
bool m_inDatabase;
};
typedef std::map<IndexKey,ObjvarValue> DataType;
DB::ModeQuery::Mode m_mode;
DataType m_data;
DataType m_overrides;
ObjectTableBuffer *m_objectTableBuffer;
bool m_useGoldNames;
// typedef std::map<NetworkId,std::vector<DBSchema::ObjectVariableRow*> > LoadIndexType;
// LoadIndexType m_loadIndex;
private:
ObjvarBuffer(); //disable
ObjvarBuffer(const ObjvarBuffer&); //disable
ObjvarBuffer & operator=(const ObjvarBuffer&); //disable
}; //lint !e1712 // IndexKey has no default constructor
// ======================================================================
inline ObjvarBuffer::IndexKey::IndexKey(const NetworkId &objectId, int nameId) :
m_objectId(objectId),
m_nameId(nameId)
{
}
// ----------------------------------------------------------------------
inline bool ObjvarBuffer::IndexKey::operator==(const IndexKey &rhs) const
{
return ((m_objectId == rhs.m_objectId) && (m_nameId == rhs.m_nameId));
}
// ----------------------------------------------------------------------
inline bool ObjvarBuffer::IndexKey::operator<(const IndexKey &rhs) const
{
if (m_objectId < rhs.m_objectId)
return true;
else if (m_objectId == rhs.m_objectId)
return (m_nameId < rhs.m_nameId);
else
return false;
}
// ======================================================================
#endif
@@ -0,0 +1,263 @@
// ======================================================================
//
// PropertyListBuffer.cpp
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#include "SwgDatabaseServer/FirstSwgDatabaseServer.h"
#include "PropertyListBuffer.h"
#include "SwgDatabaseServer/PropertyListQuery.h"
#include "sharedDatabaseInterface/DbSession.h"
#include "sharedLog/Log.h"
// ======================================================================
using namespace PropertyListBufferNamespace;
// ======================================================================
PropertyListBuffer::PropertyListBuffer(DB::ModeQuery::Mode mode) :
TableBuffer<DBSchema::PropertyListQueryData, DBQuery::PropertyListQuery>(mode),
m_loadData()
{
}
// ----------------------------------------------------------------------
PropertyListBuffer::~PropertyListBuffer(void)
{
}
// ----------------------------------------------------------------------
void PropertyListBuffer::insertProperty(const NetworkId &objectId, int listId, const std::string &value)
{
PropertyListEntry entry(objectId, listId, value);
m_adds.insert(entry);
m_deletes.erase(entry); // if this add cancels out a previous delete, don't save the delete
}
// ----------------------------------------------------------------------
void PropertyListBuffer::deleteProperty(const NetworkId &objectId, int listId, const std::string &value)
{
PropertyListEntry entry(objectId, listId, value);
m_deletes.insert(entry);
m_adds.erase(entry); // if this delete cancels out a previous add, don't save the add
}
// ----------------------------------------------------------------------
void PropertyListBuffer::clearProperties(const NetworkId &objectId, int listId)
{
static const std::string emptyString;
PropertyListEntry entry(objectId, listId, emptyString);
// erase any changes we saved for this object & list previously. For each set, find the range
// of entries corresponding to this object & list, then erase them
PropertyListSet::iterator startOfRange = m_deletes.lower_bound(entry);
PropertyListSet::iterator endOfRange;
for (endOfRange = startOfRange;
endOfRange!=m_deletes.end() && endOfRange->m_objectId == objectId && endOfRange->m_listId == listId;
++endOfRange)
;
m_deletes.erase(startOfRange, endOfRange);
startOfRange = m_adds.lower_bound(entry);
for (endOfRange = startOfRange;
endOfRange!=m_adds.end() && endOfRange->m_objectId == objectId && endOfRange->m_listId == listId;
++endOfRange)
;
m_adds.erase(startOfRange, endOfRange);
m_clears.insert(entry);
}
// ----------------------------------------------------------------------
/**
* Get all the commands for a particular object and value type.
*/
bool PropertyListBuffer::getPropertyListForObject(const NetworkId &objectId, int listId, std::set<std::string> &values) const
{
static const std::string emptyString;
DEBUG_FATAL(!values.empty(),("Values vector should be empty on call to getPropertyListsForObject()\n"));
// The data is ordered by object id then by list id, so start with the first entry matching the object id and list id.
// Return all the entries in sequence until we move to the next list or the next object
for (PropertyListSet::const_iterator i = m_loadData.lower_bound(PropertyListEntry(objectId, listId, emptyString));
i!=m_loadData.end() && i->m_objectId == objectId && i->m_listId == listId;
++i)
{
values.insert(i->m_value);
}
return true;
}
// ----------------------------------------------------------------------
bool PropertyListBuffer::load(DB::Session *session, const DB::TagSet &tags, const std::string &schema, bool)
{
int rowsFetched;
UNREF(tags);
DBQuery::GetAllPropertyLists qry(schema);
if (! (session->exec(&qry)))
return false;
while ((rowsFetched = qry.fetch()) > 0)
{
size_t numRows = qry.getNumRowsFetched();
size_t count = 0;
const std::vector<DBSchema::PropertyListQueryData> &data = qry.getData();
for (std::vector<DBSchema::PropertyListQueryData>::const_iterator i=data.begin(); i!=data.end(); ++i)
{
if (++count > numRows)
break;
const DBSchema::PropertyListQueryData &row=*i;
m_loadData.insert(PropertyListEntry(row.object_id.getValue(), row.list_id.getValue(), row.value.getValueASCII()));
}
}
qry.done();
return (rowsFetched >= 0);
}
// ----------------------------------------------------------------------
bool PropertyListBuffer::save(DB::Session *session)
{
DBQuery::PropertyListQuery qry_ot_CLEAR;
DBQuery::PropertyListQuery qry_ot_DELETE;
DBQuery::PropertyListQuery qry_ot_INSERT;
int actualSaves=0;
if (!qry_ot_DELETE.setupData(session)) return false;
if (!qry_ot_INSERT.setupData(session)) return false;
if (!qry_ot_CLEAR.setupData(session)) return false;
// Clears must be done first, so that we don't clear something we were trying to add
{
for (PropertyListSet::const_iterator i=m_clears.begin(); i!=m_clears.end(); ++i)
{
if (m_cancelledObjects.find(i->m_objectId) == m_cancelledObjects.end())
{
++actualSaves;
if (!qry_ot_CLEAR.addData(i->m_objectId, i->m_listId, i->m_value, DBSchema::PropertyListQueryData::ot_CLEAR))
return false;
if (qry_ot_CLEAR.getNumItems() == PropertyListBufferNamespace::ms_maxItemsPerExec)
{
if (! (session->exec(&qry_ot_CLEAR)))
return false;
qry_ot_CLEAR.clearData();
}
}
}
if (qry_ot_CLEAR.getNumItems() != 0)
{
if (! (session->exec(&qry_ot_CLEAR)))
return false;
}
qry_ot_CLEAR.done();
qry_ot_CLEAR.freeData();
}
{
for (PropertyListSet::const_iterator i=m_adds.begin(); i!=m_adds.end(); ++i)
{
if (m_cancelledObjects.find(i->m_objectId) == m_cancelledObjects.end())
{
++actualSaves;
if (!qry_ot_INSERT.addData(i->m_objectId, i->m_listId, i->m_value, DBSchema::PropertyListQueryData::ot_INSERT))
return false;
if (qry_ot_INSERT.getNumItems() == PropertyListBufferNamespace::ms_maxItemsPerExec)
{
if (! (session->exec(&qry_ot_INSERT)))
return false;
qry_ot_INSERT.clearData();
}
}
}
if (qry_ot_INSERT.getNumItems() != 0)
{
if (! (session->exec(&qry_ot_INSERT)))
return false;
}
qry_ot_INSERT.done();
qry_ot_INSERT.freeData();
}
{
for (PropertyListSet::const_iterator i=m_deletes.begin(); i!=m_deletes.end(); ++i)
{
if (m_cancelledObjects.find(i->m_objectId) == m_cancelledObjects.end())
{
++actualSaves;
if (!qry_ot_DELETE.addData(i->m_objectId, i->m_listId, i->m_value, DBSchema::PropertyListQueryData::ot_DELETE))
return false;
if (qry_ot_DELETE.getNumItems() == PropertyListBufferNamespace::ms_maxItemsPerExec)
{
if (! (session->exec(&qry_ot_DELETE)))
return false;
qry_ot_DELETE.clearData();
}
}
}
if (qry_ot_DELETE.getNumItems() != 0)
{
if (! (session->exec(&qry_ot_DELETE)))
return false;
}
qry_ot_DELETE.done();
qry_ot_DELETE.freeData();
}
LOG("SaveCounts",("PropertyList updates: %i (out of %i) saved to db",actualSaves, m_rows.size()));
return true;
}
// ----------------------------------------------------------------------
void PropertyListBuffer::removeObject(const NetworkId &object)
{
m_cancelledObjects.insert(object);
}
// ======================================================================
PropertyListBuffer::PropertyListEntry::PropertyListEntry() :
m_objectId(),
m_listId(0),
m_value()
{
}
// ----------------------------------------------------------------------
PropertyListBuffer::PropertyListEntry::PropertyListEntry(const PropertyListBuffer::PropertyListEntry & rhs) :
m_objectId(rhs.m_objectId),
m_listId(rhs.m_listId),
m_value(rhs.m_value)
{
}
// ----------------------------------------------------------------------
PropertyListBuffer::PropertyListEntry & PropertyListBuffer::PropertyListEntry::operator=(const PropertyListBuffer::PropertyListEntry & rhs)
{
m_objectId=rhs.m_objectId;
m_listId=rhs.m_listId;
m_value=rhs.m_value;
return *this;
}
// ======================================================================
@@ -0,0 +1,135 @@
// ======================================================================
//
// PropertyListBuffer.h
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#ifndef INCLUDED_PropertyListBuffer_H
#define INCLUDED_PropertyListBuffer_H
// ======================================================================
#include "SwgDatabaseServer/PropertyListQuery.h"
#include "serverDatabase/TableBuffer.h"
#include "sharedFoundation/NetworkId.h"
#include <map>
#include <set>
// ======================================================================
namespace PropertyListBufferNamespace
{
const int ms_maxItemsPerExec = 10000;
}
using namespace PropertyListBufferNamespace;
// ======================================================================
/**
* PropertyListBuffer is a buffer customized to the job of loading and
* saving lists of sets.
*
* This buffer does not combine changes. All operations given to it are
* sent to the database.
*/
class PropertyListBuffer : public TableBuffer<DBSchema::PropertyListQueryData, DBQuery::PropertyListQuery>
{
public:
// WARNING: Do not renumber anything in this list. You will break objects that are already persisted.
// If you remove something from the list, leave the numbers of other items unchanged
enum ListIds
{
LI_Commands=0,
LI_DraftSchematics=1,
// removed: LI_PvpEnemies=2,
LI_Allowed=3,
LI_Banned=4,
LI_GuildNames=5,
LI_GuildAbbrevs=6,
LI_GuildMembers=7,
LI_GuildEnemies=8,
LI_GuildLeaders=10,
LI_Skills=11,
LI_Cities=12,
LI_Citizens=13,
LI_CityStructures=14
};
public:
explicit PropertyListBuffer(DB::ModeQuery::Mode mode);
virtual ~PropertyListBuffer(void);
virtual bool load(DB::Session *session, const DB::TagSet &tags, const std::string &schema, bool usingGoldDatabase);
virtual bool save(DB::Session *session);
virtual void removeObject(const NetworkId &object);
bool getPropertyListForObject(const NetworkId &objectId, int listId, std::set<std::string> &values) const;
void insertProperty (const NetworkId &objectId, int listId, const std::string &value);
void deleteProperty (const NetworkId &objectId, int listId, const std::string &value);
void clearProperties(const NetworkId &objectId, int listId);
private:
struct PropertyListEntry
{
NetworkId m_objectId;
int m_listId;
std::string m_value;
PropertyListEntry(const NetworkId &objectId, int listId, const std::string &value);
bool operator<(const PropertyListEntry &rhs) const;
PropertyListEntry();
PropertyListEntry(const PropertyListEntry & rhs);
PropertyListEntry & operator=(const PropertyListEntry & rhs);
};
typedef std::set<PropertyListEntry> PropertyListSet;
PropertyListSet m_loadData;
PropertyListSet m_adds;
PropertyListSet m_deletes;
PropertyListSet m_clears;
typedef std::set<NetworkId> OIDList;
OIDList m_cancelledObjects;
private:
PropertyListBuffer(); //disable
PropertyListBuffer(const PropertyListBuffer&); //disable
PropertyListBuffer & operator=(const PropertyListBuffer&); //disable
}; //lint !e1712 // IndexKey has no default constructor
// ======================================================================
inline PropertyListBuffer::PropertyListEntry::PropertyListEntry(const NetworkId &objectId, int listId, const std::string &value) :
m_objectId(objectId),
m_listId(listId),
m_value(value)
{
}
// ----------------------------------------------------------------------
inline bool PropertyListBuffer::PropertyListEntry::operator<(const PropertyListEntry &right) const
{
if (m_objectId < right.m_objectId)
return true;
if (m_objectId == right.m_objectId)
{
if (m_listId < right.m_listId)
return true;
if (m_listId == right.m_listId)
return m_value < right.m_value;
}
return false;
}
// ======================================================================
#endif
@@ -0,0 +1,266 @@
// ======================================================================
//
// ResourceTypeBuffer.cpp
// copyright (c) 2004 Sony Online Entertainment
//
// ======================================================================
#include "SwgDatabaseServer/FirstSwgDatabaseServer.h"
#include "SwgDatabaseServer/ResourceTypeBuffer.h"
#include "SwgDatabaseServer/ResourceTypeQuery.h"
#include "SwgDatabaseServer/Schema.h"
#include "serverDatabase/ConfigServerDatabase.h"
#include "serverDatabase/GameServerConnection.h"
#include "serverGame/ServerPlanetObjectTemplate.h"
#include "sharedDatabaseInterface/DbSession.h"
#include "sharedLog/Log.h"
// ======================================================================
ResourceTypeBuffer::ResourceTypeBuffer() :
AbstractTableBuffer(),
m_data()
{
}
// ----------------------------------------------------------------------
ResourceTypeBuffer::~ResourceTypeBuffer()
{
for (DataType::iterator i=m_data.begin(); i!=m_data.end(); ++i)
{
delete i->second;
i->second=NULL;
}
}
// ----------------------------------------------------------------------
void ResourceTypeBuffer::handleAddResourceTypeMessage(AddResourceTypeMessage const & message)
{
for (std::vector<AddResourceTypeMessageNamespace::ResourceTypeData>::const_iterator typeData = message.getData().begin(); typeData != message.getData().end(); ++typeData)
{
DBSchema::ResourceTypeRow * row = NULL;
DataType::iterator rowIter = m_data.find(typeData->m_networkId);
if (rowIter == m_data.end())
{
row = new DBSchema::ResourceTypeRow;
row->resource_id = typeData->m_networkId;
m_data.insert(std::make_pair(typeData->m_networkId, row));
}
else
row=rowIter->second;
row->resource_name = typeData->m_name;
row->resource_class = typeData->m_parentClass;
row->depleted_timestamp = typeData->m_depletedTimestamp;
// Pack attributes:
{
std::string packedAttributes;
for (std::vector<std::pair<std::string, int> >::const_iterator i=typeData->m_attributes.begin(); i!=typeData->m_attributes.end(); ++i)
{
char buffer[256];
snprintf(buffer, 256, "%s %i:", i->first.c_str(), i->second);
buffer[255]='\0';
packedAttributes+=buffer;
}
if (packedAttributes.size()==0)
packedAttributes=" ";
row->attributes = packedAttributes;
}
// Pack fractal seeds:
{
std::string packedSeeds;
for (std::vector<std::pair<NetworkId, int> >::const_iterator i=typeData->m_fractalSeeds.begin(); i!=typeData->m_fractalSeeds.end(); ++i)
{
char buffer[256];
snprintf(buffer, 256, "%s %i:", i->first.getValueString().c_str(), i->second);
buffer[255]='\0';
packedSeeds+=buffer;
}
if (packedSeeds.size()==0)
packedSeeds=" ";
row->fractal_seeds = packedSeeds;
}
}
}
// ----------------------------------------------------------------------
void ResourceTypeBuffer::sendResourceTypeObjects(GameServerConnection & conn) const
{
if (m_data.empty())
return;
std::vector<AddResourceTypeMessageNamespace::ResourceTypeData> resourceTypeDataVector;
for (DataType::const_iterator row = m_data.begin(); row != m_data.end(); ++row)
{
AddResourceTypeMessageNamespace::ResourceTypeData typeData;
NOT_NULL(row->second);
row->second->resource_id.getValue(typeData.m_networkId);
row->second->resource_name.getValue(typeData.m_name);
row->second->resource_class.getValue(typeData.m_parentClass);
row->second->depleted_timestamp.getValue(typeData.m_depletedTimestamp);
// unpack attributes:
{
std::string packedAttributes;
row->second->attributes.getValue(packedAttributes);
static const int BUFSIZE = 256;
char buffer[BUFSIZE];
char *bufpos = buffer;
std::string currentAttributeName;
for (std::string::iterator i = packedAttributes.begin(); i != packedAttributes.end() && bufpos < buffer + BUFSIZE; ++i)
{
if ((*i) == ' ')
{
*bufpos = '\0';
currentAttributeName = buffer;
// remove double quotes around some double quoted resource name
if (currentAttributeName.find_first_of('"') == 0)
{
std::string::size_type const closingQuote = currentAttributeName.find_last_of('"');
if ((closingQuote >= 2) && (closingQuote == (currentAttributeName.size() - 1)))
currentAttributeName = currentAttributeName.substr(1, (closingQuote - 1));
}
bufpos = buffer;
}
else if ((*i) == ':')
{
*bufpos = '\0';
typeData.m_attributes.push_back(std::make_pair(currentAttributeName, atoi(buffer)));
bufpos = buffer;
}
else
{
*(bufpos++) = *i;
}
}
}
// unpack fractal seeds:
{
std::string packedSeeds;
row->second->fractal_seeds.getValue(packedSeeds);
static const int BUFSIZE = 256;
char buffer[BUFSIZE];
char *bufpos = buffer;
NetworkId currentPlanetId;
for (std::string::iterator i = packedSeeds.begin(); i != packedSeeds.end() && bufpos < buffer + BUFSIZE; ++i)
{
if ((*i) == ' ')
{
*bufpos = '\0';
currentPlanetId = NetworkId(std::string(buffer));
bufpos = buffer;
}
else if ((*i) == ':')
{
*bufpos = '\0';
typeData.m_fractalSeeds.push_back(std::make_pair(currentPlanetId, atoi(buffer)));
bufpos = buffer;
}
else
{
*(bufpos++) = *i;
}
}
}
resourceTypeDataVector.push_back(typeData);
}
AddResourceTypeMessage msg(resourceTypeDataVector);
conn.send(msg,true);
}
// ----------------------------------------------------------------------
bool ResourceTypeBuffer::save(DB::Session *session)
{
if (m_data.empty())
return true;
int actualSaves=0;
DBQuery::ResourceTypeQuery qry;
if (!qry.setupData(session))
return false;
for (DataType::const_iterator i=m_data.begin(); i!=m_data.end(); ++i)
{
++actualSaves;
NOT_NULL(i->second);
if (!qry.addData(*(i->second)))
return false;
if (qry.getNumItems() == ConfigServerDatabase::getDefaultMessageBulkBindSize())
{
if (! (session->exec(&qry)))
return false;
qry.clearData();
}
}
if (qry.getNumItems() != 0)
if (! (session->exec(&qry)))
return false;
qry.done();
qry.freeData();
LOG("SaveCounts",("Resource types: %i saved in db",actualSaves));
return true;
}
// ----------------------------------------------------------------------
bool ResourceTypeBuffer::load(DB::Session *session, const DB::TagSet &tags, const std::string &schema, bool usingGoldDatabase)
{
int rowsFetched = 0;
// Resource data is associated with PlanetObjects, so load it if the planets are being loaded
if (tags.find(ServerPlanetObjectTemplate::ServerPlanetObjectTemplate_tag)!=tags.end())
{
DEBUG_REPORT_LOG(true,("Loading resource types\n"));
DBQuery::ResourceTypeQuerySelect qry(schema);
if (! (session->exec(&qry)))
return false;
while ((rowsFetched = qry.fetch()) > 0)
{
size_t const numRows = qry.getNumRowsFetched();
size_t count = 0;
std::vector<DBSchema::ResourceTypeRow> const & data = qry.getData();
for (std::vector<DBSchema::ResourceTypeRow>::const_iterator i=data.begin(); i!=data.end(); ++i)
{
if (++count > numRows)
break;
DBSchema::ResourceTypeRow *row=new DBSchema::ResourceTypeRow(*i);
NOT_NULL(row);
NetworkId temp;
row->resource_id.getValue(temp);
m_data.insert(std::make_pair(row->resource_id.getValue(), row));
}
}
qry.done();
}
return (rowsFetched >= 0);
}
// ----------------------------------------------------------------------
void ResourceTypeBuffer::removeObject(const NetworkId &object)
{
}
// ======================================================================
@@ -0,0 +1,58 @@
// ======================================================================
//
// ResourceTypeBuffer.h
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#ifndef INCLUDED_ResourceTypeBuffer_H
#define INCLUDED_ResourceTypeBuffer_H
// ======================================================================
#include "serverDatabase/AbstractTableBuffer.h"
#include "serverNetworkMessages/AddResourceTypeMessage.h"
// ======================================================================
namespace DB
{
class Session;
}
namespace DBSchema
{
struct ResourceTypeRow;
}
class GameServerConnection;
// ======================================================================
/**
* A buffer to hold resource type data.
*/
class ResourceTypeBuffer : public AbstractTableBuffer
{
public:
void handleAddResourceTypeMessage (AddResourceTypeMessage const & message);
void sendResourceTypeObjects (GameServerConnection & conn) const;
virtual bool save(DB::Session *session);
virtual bool load(DB::Session *session, const DB::TagSet &tags, const std::string &schema, bool usingGoldDatabase);
virtual void removeObject(const NetworkId &object);
public:
ResourceTypeBuffer();
virtual ~ResourceTypeBuffer();
private:
typedef std::map<NetworkId, DBSchema::ResourceTypeRow*> DataType;
private:
DataType m_data;
};
// ======================================================================
#endif
@@ -0,0 +1,131 @@
// ======================================================================
//
// ScriptBuffer.cpp
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#include "SwgDatabaseServer/FirstSwgDatabaseServer.h"
#include "ScriptBuffer.h"
#include "serverDatabase/ScriptQueries.h"
#include "sharedDatabaseInterface/DbSession.h"
#include <algorithm>
#include <map>
#include <set>
// ======================================================================
ScriptBuffer::ScriptBuffer() :
m_loadedData(new LoadedDataType)
{
}
// ----------------------------------------------------------------------
ScriptBuffer::~ScriptBuffer()
{
delete m_loadedData;
m_loadedData=0;
}
// ----------------------------------------------------------------------
void ScriptBuffer::clearScripts(const NetworkId &objectId)
{
m_objectsToClear.insert(objectId);
}
// ----------------------------------------------------------------------
bool ScriptBuffer::save(DB::Session *session)
{
DBQuery::ScriptClearQuery clearQry;
for (std::set<NetworkId>::const_iterator i=m_objectsToClear.begin(); i!=m_objectsToClear.end(); ++i)
{
clearQry.setNetworkId(*i);
if (! (session->exec(&clearQry)))
return false;
}
clearQry.done();
return true;
}
// ----------------------------------------------------------------------
bool ScriptBuffer::load(DB::Session *session,const DB::TagSet &tags, const std::string &schema, bool)
{
int rowsFetched;
UNREF(tags); // any object can have scripts
DBQuery::GetScripts qry(schema);
if (! (session->exec(&qry)))
return false;
std::string scriptName;
while ((rowsFetched = qry.fetch()) > 0)
{
size_t numRows = qry.getNumRowsFetched();
size_t count = 0;
const std::vector<DBQuery::GetScripts::ScriptRow> &data = qry.getData();
for (std::vector<DBQuery::GetScripts::ScriptRow>::const_iterator i=data.begin(); i!=data.end(); ++i)
{
if (++count > numRows)
break;
i->script_name.getValue(scriptName);
(*m_loadedData)[IndexKey(i->object_id.getValue(),i->index.getValue())]=scriptName;
}
}
qry.done();
return (rowsFetched >= 0);
}
// ----------------------------------------------------------------------
void ScriptBuffer::getScriptsForObject(const NetworkId &objectId, std::vector<std::string> &scripts) const
{
scripts.clear();
#ifdef _DEBUG
int expectedIndex = 0;
#endif
for (LoadedDataType::const_iterator i=m_loadedData->find(IndexKey(objectId,0)); (i!=m_loadedData->end()) && (i->first.m_objectId==objectId); ++i)
{
DEBUG_WARNING((i->first.m_index != expectedIndex++), ("Programmer bug: Script buffer was not sorted, or there were gaps in the sequence. ObjectId %s, sequence number %i\n",objectId.getValueString().c_str(),i->first.m_index));
scripts.push_back(i->second);
}
}
// ----------------------------------------------------------------------
void ScriptBuffer::removeObject(const NetworkId &object)
{
m_objectsToClear.erase(object);
}
// ======================================================================
ScriptBuffer::IndexKey::IndexKey(const NetworkId &objectId, int index) :
m_objectId(objectId),
m_index(index)
{
}
// ----------------------------------------------------------------------
bool ScriptBuffer::IndexKey::operator<(const IndexKey &rhs) const
{
if (m_objectId == rhs.m_objectId)
return (m_index < rhs.m_index);
else
return (m_objectId < rhs.m_objectId);
}
// ======================================================================
@@ -0,0 +1,74 @@
// ======================================================================
//
// ScriptBuffer.h
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#ifndef INCLUDED_ScriptBuffer_H
#define INCLUDED_ScriptBuffer_H
// ======================================================================
#include <list>
#include <map>
#include <set>
#include <string>
#include <vector>
#include "serverDatabase/AbstractTableBuffer.h"
#include "sharedFoundation/NetworkId.h"
#include "sharedLog/Log.h"
namespace DB
{
class Session;
}
// ======================================================================
/**
* A buffer to hold script attach & detach commands.
* Unlike many of the other buffers, this does not attempt to combine
* operations (e.g. match up a detach with an attach already in the buffer,
* and so skip sending either to the database). Instead, it just keeps a
* list of everything to do.
*/
class ScriptBuffer : public AbstractTableBuffer
{
public:
void clearScripts(const NetworkId &objectId);
virtual bool save(DB::Session *session);
virtual bool load(DB::Session *session,const DB::TagSet &tags, const std::string &schema, bool usingGoldDatabase);
virtual void removeObject(const NetworkId &object);
void addObject(const NetworkId &objectId);
void getScriptsForObject(const NetworkId &objectId, std::vector<std::string> &scripts) const;
ScriptBuffer();
virtual ~ScriptBuffer();
private:
class IndexKey
{
public:
NetworkId m_objectId;
int m_index;
public:
IndexKey(const NetworkId &objectId, int index);
public:
bool operator<(const IndexKey &rhs) const;
};
std::set<NetworkId> m_objectsToClear;
typedef stdmap<IndexKey, std::string>::fwd LoadedDataType;
LoadedDataType *m_loadedData; // data loaded from the database
};
// ======================================================================
#endif
@@ -0,0 +1,158 @@
// ======================================================================
//
// WaypointBuffer.cpp
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#include "SwgDatabaseServer/FirstSwgDatabaseServer.h"
#include "SwgDatabaseServer/WaypointBuffer.h"
#include "SwgDatabaseServer/Schema.h"
#include "SwgDatabaseServer/WaypointQuery.h"
#include "serverGame/ServerMissionObjectTemplate.h"
#include "serverGame/ServerPlayerObjectTemplate.h"
#include "sharedDatabaseInterface/DbException.h"
#include "sharedDatabaseInterface/DbSession.h"
#include "sharedUtility/Location.h"
#include "sharedLog/Log.h"
#include <vector>
// ======================================================================
WaypointBuffer::WaypointBuffer(DB::ModeQuery::Mode mode) :
AbstractTableBuffer(),
m_mode(mode),
m_data()
{
}
// ----------------------------------------------------------------------
WaypointBuffer::~WaypointBuffer(void)
{
}
// ----------------------------------------------------------------------
void WaypointBuffer::setWaypoint(const NetworkId &objectId, const NetworkId &waypointId, const PersistableWaypoint &value)
{
m_data[IndexKey(objectId,waypointId)] = value;
}
// ----------------------------------------------------------------------
bool WaypointBuffer::getWaypointsForObject(const NetworkId &objectId, stdvector<PersistableWaypoint>::fwd &values) const
{
DEBUG_FATAL(values.size()!=0,("Values vector should be empty on call to getWaypointForObject()\n"));
IndexType::const_iterator i ( m_data.lower_bound(IndexKey(objectId,NetworkId::cms_invalid)) );
if (i==m_data.end())
return false;
for (; (i!=m_data.end()) && (i->first.m_objectId==objectId); ++i)
{
std::string temp;
values.push_back(i->second);
}
return true;
}
// ----------------------------------------------------------------------
bool WaypointBuffer::load(DB::Session *session,const DB::TagSet &tags, const std::string &schema, bool)
{
int rowsFetched = 0;
if ( tags.find(static_cast<Tag>(ServerPlayerObjectTemplate::ServerPlayerObjectTemplate_tag)) != tags.end()
|| tags.find(static_cast<Tag>(ServerMissionObjectTemplate::ServerMissionObjectTemplate_tag)) != tags.end())
{
DBQuery::GetAllWaypoints qry(schema);
if (! (session->exec(&qry)))
return false;
while ((rowsFetched = qry.fetch()) > 0)
{
size_t numRows = qry.getNumRowsFetched();
size_t count = 0;
const std::vector<DBSchema::WaypointRow> &data = qry.getData();
for (std::vector<DBSchema::WaypointRow>::const_iterator i=data.begin(); i!=data.end(); ++i)
{
if (++count > numRows)
break;
const DBSchema::WaypointRow &row=*i;
PersistableWaypoint temp;
temp.m_appearanceNameCrc = row.appearance_name_crc.getValue();
temp.m_location = Location(Vector(static_cast<float>(row.location_x.getValue()),
static_cast<float>(row.location_y.getValue()),
static_cast<float>(row.location_z.getValue())),
row.location_cell.getValue(),row.location_scene.getValue());
temp.m_name = row.name.getValue();
temp.m_networkId = row.waypoint_id.getValue();
temp.m_color = static_cast<unsigned char>(row.color.getValue());
temp.m_active = row.active.getValue();
temp.m_detached = false;
m_data[IndexKey(row.object_id.getValue(),temp.m_networkId)]=temp;
}
}
qry.done();
}
return (rowsFetched >= 0);
}
// ----------------------------------------------------------------------
bool WaypointBuffer::save(DB::Session *session)
{
LOG("SaveCounts",("Waypoint: %i saved to db",m_data.size()));
DBQuery::WaypointQuery qry;
if (m_mode==DB::ModeQuery::mode_INSERT)
qry.insertMode();
else
qry.updateMode();
for (IndexType::iterator i=m_data.begin(); i!=m_data.end(); ++i)
{
DBSchema::WaypointRow row;
row.object_id = i->first.m_objectId;
row.waypoint_id = i->first.m_waypointId;
row.appearance_name_crc = i->second.m_appearanceNameCrc;
row.location_x = i->second.m_location.getCoordinates().x;
row.location_y = i->second.m_location.getCoordinates().y;
row.location_z = i->second.m_location.getCoordinates().z;
row.location_cell = i->second.m_location.getCell();
row.location_scene = i->second.m_location.getSceneIdCrc();
row.name = i->second.m_name;
row.color = i->second.m_color;
row.active = i->second.m_active;
row.detached = i->second.m_detached;
qry.setData(row);
if (! (session->exec(&qry)))
return false;
}
qry.done();
return true;
}
// ----------------------------------------------------------------------
void WaypointBuffer::removeObject(const NetworkId &object)
{
IndexType::iterator i=m_data.lower_bound(IndexKey(object,NetworkId::cms_invalid));
while (i!=m_data.end() && i->first.m_objectId==object)
{
IndexType::iterator next=i;
++next;
m_data.erase(i);
i=next;
}
}
// ======================================================================
@@ -0,0 +1,98 @@
// ======================================================================
//
// WaypointBuffer.h
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#ifndef INCLUDED_WaypointBuffer_H
#define INCLUDED_WaypointBuffer_H
// ======================================================================
#include "SwgDatabaseServer/PersistableWaypoint.h"
#include "SwgDatabaseServer/Schema.h"
#include "SwgDatabaseServer/WaypointQuery.h"
#include "serverDatabase/AbstractTableBuffer.h"
#include <map>
#include <string>
// ======================================================================
class WaypointBuffer : public AbstractTableBuffer
{
public:
explicit WaypointBuffer (DB::ModeQuery::Mode mode);
virtual ~WaypointBuffer ();
virtual bool load (DB::Session *session,const DB::TagSet &tags, const std::string &schema, bool usingGoldDatabase);
virtual bool save (DB::Session *session);
virtual void removeObject (const NetworkId &object);
void setWaypoint (const NetworkId &objectId, const NetworkId &waypointId, const PersistableWaypoint &value);
void removeWaypoint (const NetworkId &objectId, const NetworkId &waypointId);
bool getWaypointsForObject(const NetworkId &objectId, stdvector<PersistableWaypoint>::fwd &values) const;
private:
struct IndexKey
{
NetworkId m_objectId;
NetworkId m_waypointId;
IndexKey(const NetworkId &objectId, const NetworkId &waypointId);
bool operator==(const IndexKey &rhs) const;
bool operator<(const IndexKey &rhs) const;
};
typedef std::map<IndexKey,PersistableWaypoint> IndexType;
DB::ModeQuery::Mode m_mode;
IndexType m_data;
private:
WaypointBuffer(); //disable
WaypointBuffer(const WaypointBuffer&); //disable
WaypointBuffer & operator=(const WaypointBuffer&); //disable
}; //lint !e1712 // IndexKey has no default constructor
// ======================================================================
inline WaypointBuffer::IndexKey::IndexKey(const NetworkId &objectId, const NetworkId &waypointId) :
m_objectId(objectId),
m_waypointId(waypointId)
{
}
// ----------------------------------------------------------------------
inline bool WaypointBuffer::IndexKey::operator==(const IndexKey &rhs) const
{
return ((m_objectId == rhs.m_objectId) && (m_waypointId == rhs.m_waypointId));
}
// ----------------------------------------------------------------------
inline bool WaypointBuffer::IndexKey::operator< (const IndexKey &rhs) const
{
if (m_objectId == rhs.m_objectId)
return (m_waypointId < rhs.m_waypointId);
else
return (m_objectId < rhs.m_objectId);
}
// ----------------------------------------------------------------------
/**
*
*/
inline void WaypointBuffer::removeWaypoint(const NetworkId &objectId, const NetworkId &waypointId)
{
PersistableWaypoint temp;
temp.m_networkId=waypointId;
temp.m_detached=true;
setWaypoint(objectId,waypointId,temp);
}
// ======================================================================
#endif
@@ -0,0 +1,157 @@
// ======================================================================
//
// DataCleanupManager.cpp
// copyright (c) 2004 Sony Online Entertainment
//
// ======================================================================
#include "SwgDatabaseServer/FirstSwgDatabaseServer.h"
#include "DataCleanupManager.h"
#include "SwgDatabaseServer/TaskConsolidateExperience.h"
#include "SwgDatabaseServer/TaskDailyCleanup.h"
#include "SwgDatabaseServer/TaskAnySQL.h"
#include "SwgDatabaseServer/TaskObjvarNameCleanup.h"
#include "SwgDatabaseServer/TaskOrphanedObjectCleanup.h"
#include "SwgDatabaseServer/TaskMarketAttributesCleanup.h"
#include "SwgDatabaseServer/TaskMessagesCleanup.h"
#include "SwgDatabaseServer/TaskBrokenObjectCleanup.h"
#include "SwgDatabaseServer/TaskVendorObjectCleanup.h"
#include "SwgDatabaseServer/TaskFixBadCells.h"
#include "SwgDatabaseServer/TaskObjectTemplateListUpdater.h"
#include "serverDatabase/DatabaseProcess.h"
#include "sharedDatabaseInterface/DbTaskQueue.h"
#include "sharedLog/Log.h"
#include "sharedLog/LogManager.h"
#include "sharedFoundation/Os.h"
#include "serverDatabase/ConfigServerDatabase.h"
#include "serverMetrics/MetricsManager.h"
#include "sharedNetwork/NetworkHandler.h"
// ======================================================================
DataCleanupManager::DataCleanupManager() :
m_taskQueue(new DB::TaskQueue(1, DatabaseProcess::getInstance().getDBServer(), 0))
{
}
// ----------------------------------------------------------------------
DataCleanupManager::~DataCleanupManager()
{
delete m_taskQueue; // Note: The destructor of TaskQueue waits for all the tasks to be finished
}
// ----------------------------------------------------------------------
void DataCleanupManager::runDailyCleanup( void )
{
if ( ConfigServerDatabase::getEnableFixBadCells() ) // do this first...
{
TaskFixBadCells *task = new TaskFixBadCells;
m_taskQueue->asyncRequest(task);
}
if ( ConfigServerDatabase::getObjectTemplateListUpdateFilename() != 0)
{
TaskObjectTemplateListUpdater *task = new TaskObjectTemplateListUpdater( ConfigServerDatabase::getObjectTemplateListUpdateFilename() );
m_taskQueue->asyncRequest(task);
}
if ( ConfigServerDatabase::getEnableDataCleanup() )
{
if ( ConfigServerDatabase::getExperienceConsolidationTime() != 0)
{
TaskConsolidateExperience *task = new TaskConsolidateExperience( ConfigServerDatabase::getExperienceConsolidationTime() );
m_taskQueue->asyncRequest(task);
}
if ( ConfigServerDatabase::getObjvarNameCleanupTime() != 0)
{
TaskObjvarNameCleanup *task = new TaskObjvarNameCleanup( ConfigServerDatabase::getObjvarNameCleanupTime() );
m_taskQueue->asyncRequest(task);
}
if ( ConfigServerDatabase::getOrphanedObjectCleanupTime() != 0)
{
TaskOrphanedObjectCleanup *task = new TaskOrphanedObjectCleanup( ConfigServerDatabase::getOrphanedObjectCleanupTime() );
m_taskQueue->asyncRequest(task);
}
LOG("Cleanup:attributes:",("%d", ConfigServerDatabase::getMarketAttributesCleanupTime() ));
if ( ConfigServerDatabase::getMarketAttributesCleanupTime() != 0)
{
TaskMarketAttributesCleanup *task = new TaskMarketAttributesCleanup( ConfigServerDatabase::getMarketAttributesCleanupTime() );
m_taskQueue->asyncRequest(task);
}
LOG("Cleanup:messages:",("%d", ConfigServerDatabase::getMarketAttributesCleanupTime() ));
if ( ConfigServerDatabase::getMessagesCleanupTime() != 0)
{
TaskMessagesCleanup *task = new TaskMessagesCleanup( ConfigServerDatabase::getMessagesCleanupTime() );
m_taskQueue->asyncRequest(task);
}
LOG("Cleanup:brokenobj:",("%d", ConfigServerDatabase::getBrokenObjectCleanupTime() ));
if ( ConfigServerDatabase::getBrokenObjectCleanupTime() != 0)
{
TaskBrokenObjectCleanup *task = new TaskBrokenObjectCleanup( ConfigServerDatabase::getBrokenObjectCleanupTime() );
m_taskQueue->asyncRequest(task);
}
if ( ConfigServerDatabase::getVendorObjectCleanupTime() != 0)
{
TaskVendorObjectCleanup *task = new TaskVendorObjectCleanup( ConfigServerDatabase::getVendorObjectCleanupTime() );
m_taskQueue->asyncRequest(task);
}
}
//
// Open custom sql file and execute everything in there (in queries folder)
//
std::string s_filename( ConfigServerDatabase::getCustomSQLFilename() );
if ( s_filename.length() )
{
std::string s_path( "../../src/game/server/database/queries/" );
s_path += s_filename;
FILE* in = fopen(s_path.c_str(), "r");
if ( in )
{
char line[4096];
std::string s_sql;
while( fgets(line, 4096, in ) )
{
if ( line[0] != '#' )
s_sql+=line;
if ( s_sql.find(';') != std::string::npos )
{
TaskAnySQL *task = new TaskAnySQL( s_sql.c_str() );
m_taskQueue->asyncRequest( task );
s_sql.clear();
}
}
fclose( in );
}
else
{
LOG("Cleanup:AnySQL:",("Couldn't open: %s",s_path.c_str()));
}
}
// Sleep until all the cleanup is done....
while( m_taskQueue->isIdle() == false )
{
const int ki_sleeptime = 100;
Os::sleep(ki_sleeptime);
m_taskQueue->update(float(ki_sleeptime) / float(1000.0));
MetricsManager::update(float(ki_sleeptime) / float(1000.0));
NetworkHandler::update();
NetworkHandler::dispatch();
NetworkHandler::clearBytesThisFrame();
}
}
// ======================================================================
@@ -0,0 +1,39 @@
// ======================================================================
//
// DataCleanupManager.h
// copyright (c) 2004 Sony Online Entertainment
//
// ======================================================================
#ifndef INCLUDED_DataCleanupManager_H
#define INCLUDED_DataCleanupManager_H
// ======================================================================
namespace DB
{
class TaskQueue;
}
// ======================================================================
/**
* Class to run cleanup scripts on the database before starting
* the cluster. This class can be deleted when its work is complete.
*/
class DataCleanupManager
{
public:
DataCleanupManager();
~DataCleanupManager();
public:
void runDailyCleanup( );
private:
DB::TaskQueue * m_taskQueue;
};
// ======================================================================
#endif
@@ -0,0 +1,71 @@
// ======================================================================
//
// TaskAnySQL.cpp
// copyright (c) 2003 Sony Online Entertainment
//
// ======================================================================
#include "SwgDatabaseServer/FirstSwgDatabaseServer.h"
#include "TaskAnySQL.h"
#include "SwgDatabaseServer/ObjvarNameManager.h"
#include "serverDatabase/DatabaseProcess.h"
#include "serverDatabase/Loader.h"
#include "sharedDatabaseInterface/DbSession.h"
#include "sharedLog/Log.h"
// ======================================================================
bool TaskAnySQL::process(DB::Session *session)
{
LOG("TaskANYSQL",("%s", m_sSQL.c_str() ));
AnyQuery qry( m_sSQL.c_str() );
return (session->exec(&qry));
}
// ----------------------------------------------------------------------
void TaskAnySQL::onComplete()
{
}
// ======================================================================
TaskAnySQL::AnyQuery::AnyQuery( const char* pSQL ) : m_sSQL(pSQL)
{
// Erase trailing semicolon from each line
size_t pos = m_sSQL.rfind(';');
if ( pos != std::string::npos )
m_sSQL.erase( pos );
}
// ----------------------------------------------------------------------
void TaskAnySQL::AnyQuery::getSQL(std::string &sql)
{
sql=m_sSQL;
}
// ----------------------------------------------------------------------
bool TaskAnySQL::AnyQuery::bindParameters()
{
return true;
}
// ----------------------------------------------------------------------
bool TaskAnySQL::AnyQuery::bindColumns()
{
return true;
}
// ----------------------------------------------------------------------
DB::Query::QueryMode TaskAnySQL::AnyQuery::getExecutionMode() const
{
return MODE_DML;
}
// ======================================================================
@@ -0,0 +1,52 @@
// ======================================================================
//
// TaskAnySQL.h
// copyright (c) 2004 Sony Online Entertainment
//
// ======================================================================
#ifndef INCLUDED_TaskAnySQL_H
#define INCLUDED_TaskAnySQL_H
// ======================================================================
#include "sharedDatabaseInterface/DbQuery.h"
#include "sharedDatabaseInterface/DbTaskRequest.h"
#include <string>
// ======================================================================
/**
* Run arbitrary cleanup SQL (doesn't support any input or output)
*/
class TaskAnySQL : public DB::TaskRequest
{
public:
TaskAnySQL( const char* pSQL ) : m_sSQL(pSQL) {}
virtual bool process (DB::Session *session);
virtual void onComplete ();
private:
class AnyQuery : public DB::Query
{
public:
AnyQuery( const char* pSQL );
virtual void getSQL(std::string &sql);
virtual bool bindParameters();
virtual bool bindColumns();
virtual QueryMode getExecutionMode() const;
private:
AnyQuery(const AnyQuery&);
AnyQuery& operator=(const AnyQuery&);
std::string m_sSQL;
};
std::string m_sSQL;
};
// ======================================================================
#endif
@@ -0,0 +1,80 @@
// ======================================================================
//
// TaskBrokenObjectCleanup.cpp
// copyright (c) 2003 Sony Online Entertainment
//
// ======================================================================
#include "SwgDatabaseServer/FirstSwgDatabaseServer.h"
#include "TaskBrokenObjectCleanup.h"
#include "SwgDatabaseServer/ObjvarNameManager.h"
#include "serverDatabase/DatabaseProcess.h"
#include "serverDatabase/Loader.h"
#include "sharedDatabaseInterface/DbSession.h"
#include "sharedLog/Log.h"
// ======================================================================
bool TaskBrokenObjectCleanup::process(DB::Session *session)
{
time_t t_start = time(0);
while( (time(0) - t_start) < m_tSeconds ) // limit the run time
{
DataCleanupQuery qry;
if ( session->exec(&qry) == false )
{
LOG("TaskBrokenObjectCleanup::process",( "returned false!" ));
return false;
}
LOG("TaskBrokenObjectCleanup::process",("ROWS = %d", qry.result.getValue() ));
if( qry.result.getValue() == 0 ) // cleanup done
break;
}
LOG("TaskBrokenObjectCleanup",("TIME = %d", time(0)-t_start ));
return true;
}
// ----------------------------------------------------------------------
void TaskBrokenObjectCleanup::onComplete()
{
}
// ======================================================================
TaskBrokenObjectCleanup::DataCleanupQuery::DataCleanupQuery()
{
}
// ----------------------------------------------------------------------
void TaskBrokenObjectCleanup::DataCleanupQuery::getSQL(std::string &sql)
{
sql="begin :result := "+DatabaseProcess::getInstance().getSchemaQualifier()+"data_cleanup.broken_object_cleanup(); end;";
}
// ----------------------------------------------------------------------
bool TaskBrokenObjectCleanup::DataCleanupQuery::bindParameters()
{
if (!bindParameter(result)) return false;
return true;
}
// ----------------------------------------------------------------------
bool TaskBrokenObjectCleanup::DataCleanupQuery::bindColumns()
{
return true;
}
// ----------------------------------------------------------------------
DB::Query::QueryMode TaskBrokenObjectCleanup::DataCleanupQuery::getExecutionMode() const
{
return MODE_PROCEXEC;
}
// ======================================================================
@@ -0,0 +1,55 @@
// ======================================================================
//
// TaskBrokenObjectCleanup.h
// copyright (c) 2004 Sony Online Entertainment
//
// ======================================================================
#ifndef INCLUDED_TaskBrokenObjectCleanup_H
#define INCLUDED_TaskBrokenObjectCleanup_H
// ======================================================================
#include "sharedDatabaseInterface/DbQuery.h"
#include "sharedDatabaseInterface/DbTaskRequest.h"
#include "sharedDatabaseInterface/Bindable.h"
#include <time.h>
// ======================================================================
/**
* Runs scripts to do regular daily cleanup in the database.
*/
class TaskBrokenObjectCleanup : public DB::TaskRequest
{
public:
TaskBrokenObjectCleanup( time_t tSeconds ) { m_tSeconds = tSeconds; }
virtual bool process (DB::Session *session);
virtual void onComplete ();
private:
time_t m_tSeconds;
class DataCleanupQuery : public DB::Query
{
public:
DataCleanupQuery();
virtual void getSQL(std::string &sql);
virtual bool bindParameters();
virtual bool bindColumns();
virtual QueryMode getExecutionMode() const;
DB::BindableLong result;
private:
DataCleanupQuery(const DataCleanupQuery&);
DataCleanupQuery& operator=(const DataCleanupQuery&);
};
};
// ======================================================================
#endif
@@ -0,0 +1,311 @@
// ======================================================================
//
// TaskConsolidateExperience.cpp
// copyright (c) 2004 Sony Online Entertainment
//
// ======================================================================
#include "SwgDatabaseServer/FirstSwgDatabaseServer.h"
#include "SwgDatabaseServer/TaskConsolidateExperience.h"
#include "serverDatabase/DatabaseProcess.h"
#include "sharedDatabaseInterface/DbSession.h"
#include "sharedDebug/PerformanceTimer.h"
#include "sharedFoundation/NetworkId.h"
#include <map>
#include <string>
#include <vector>
// ======================================================================
TaskConsolidateExperience::TaskConsolidateExperience(float timeLimit) :
m_timeLimit(timeLimit)
{
}
// ----------------------------------------------------------------------
TaskConsolidateExperience::~TaskConsolidateExperience()
{
}
// ----------------------------------------------------------------------
bool TaskConsolidateExperience::process(DB::Session *session)
{
int rowsFetched = 0;
NOT_NULL(session);
session->setAutoCommitMode(false);
PerformanceTimer timer;
timer.start();
std::vector<NetworkId> objectQueue;
{
// Make an ordered list of objects with lots of messages pending
FindLotsOfMessagesQuery qry;
if (! (session->exec(&qry)))
return false;
while ((rowsFetched = qry.fetch()) > 0)
{
objectQueue.push_back(qry.getNetworkId());
}
}
if (rowsFetched < 0)
return false;
for (std::vector<NetworkId>::const_iterator objectToClean=objectQueue.begin(); objectToClean!=objectQueue.end() && timer.getSplitTime() < m_timeLimit; ++objectToClean)
{
bool bail=false;
std::map<std::string, int> experiencePoints;
{
// Total up the experience grants for the object
GetExperienceQuery qry(*objectToClean);
if (! (session->exec(&qry)))
return false;
while ((rowsFetched = qry.fetch()) > 0 && !bail)
{
std::string type;
int amount;
if (splitExperience(qry.getData(), type, amount))
{
experiencePoints[type]+=amount;
}
else
{
WARNING(true,("Unrecognized experience string \"%s\" for object %s. Bailing out of experience consolidation for this object.\n",
qry.getData().c_str(), objectToClean->getValueString().c_str()));
bail=true;
}
}
}
if (rowsFetched < 0)
return false;
if (!bail)
{
{
// delete all xp grants
DeleteExperienceQuery qry(*objectToClean);
if (! (session->exec(&qry)))
return false;
}
{
// replace with simplified grants
GrantExperienceQuery qry;
for (std::map<std::string, int>::const_iterator i=experiencePoints.begin(); i!=experiencePoints.end(); ++i)
{
qry.setData(*objectToClean, makeExperienceString(i->first, i->second));
if (! (session->exec(&qry)))
return false;
}
}
session->commitTransaction();
}
bail=false;
}
return true;
}
// ----------------------------------------------------------------------
void TaskConsolidateExperience::onComplete()
{
}
// ----------------------------------------------------------------------
/**
* Convert packed experience data into the type name and the amount.
*/
bool TaskConsolidateExperience::splitExperience(const std::string &packedData, std::string &type, int &amount) const
{
size_t spacePos=packedData.find(' ');
if (spacePos==std::string::npos) return false;
type=std::string(packedData,0,spacePos);
std::string amountString(packedData,spacePos+1,static_cast<unsigned int>(std::string::npos));
amount=atoi(amountString.c_str());
if (amount <= 0) return false; // string is probably badly-formed or parsed wrong
return true;
}
// ----------------------------------------------------------------------
std::string TaskConsolidateExperience::makeExperienceString(const std::string &type, int amount)
{
char buffer[1000];
snprintf(buffer,1000,"%s %i",type.c_str(), amount);
return std::string(buffer);
}
// ======================================================================
TaskConsolidateExperience::FindLotsOfMessagesQuery::FindLotsOfMessagesQuery()
{
}
// ----------------------------------------------------------------------
void TaskConsolidateExperience::FindLotsOfMessagesQuery::getSQL(std::string &sql)
{
sql="begin :rc := "+DatabaseProcess::getInstance().getSchemaQualifier()+"data_cleanup.getObjectsWithExpMessages(); end;";
}
// ----------------------------------------------------------------------
bool TaskConsolidateExperience::FindLotsOfMessagesQuery::bindParameters()
{
return true;
}
// ----------------------------------------------------------------------
bool TaskConsolidateExperience::FindLotsOfMessagesQuery::bindColumns()
{
if (!bindCol(object_id)) return false;
return true;
}
// ----------------------------------------------------------------------
DB::Query::QueryMode TaskConsolidateExperience::FindLotsOfMessagesQuery::getExecutionMode() const
{
return MODE_PLSQL_REFCURSOR;
}
// ----------------------------------------------------------------------
NetworkId TaskConsolidateExperience::FindLotsOfMessagesQuery::getNetworkId() const
{
return object_id.getValue();
}
// ======================================================================
TaskConsolidateExperience::GetExperienceQuery::GetExperienceQuery(const NetworkId &objectId) :
object_id(objectId)
{
}
// ----------------------------------------------------------------------
void TaskConsolidateExperience::GetExperienceQuery::getSQL(std::string &sql)
{
sql="begin :rc := "+DatabaseProcess::getInstance().getSchemaQualifier()+"data_cleanup.getExperienceGrants(:object_id); end;";
}
// ----------------------------------------------------------------------
bool TaskConsolidateExperience::GetExperienceQuery::bindParameters()
{
if (!bindParameter(object_id)) return false;
return true;
}
// ----------------------------------------------------------------------
bool TaskConsolidateExperience::GetExperienceQuery::bindColumns()
{
if (!bindCol(grant_data)) return false;
return true;
}
// ----------------------------------------------------------------------
DB::Query::QueryMode TaskConsolidateExperience::GetExperienceQuery::getExecutionMode() const
{
return MODE_PLSQL_REFCURSOR;
}
// ----------------------------------------------------------------------
const std::string TaskConsolidateExperience::GetExperienceQuery::getData() const
{
return grant_data.getValueASCII();
}
// ======================================================================
TaskConsolidateExperience::DeleteExperienceQuery::DeleteExperienceQuery(const NetworkId &objectId) :
object_id(objectId)
{
}
// ----------------------------------------------------------------------
void TaskConsolidateExperience::DeleteExperienceQuery::getSQL(std::string &sql)
{
sql="begin "+DatabaseProcess::getInstance().getSchemaQualifier()+"data_cleanup.delete_experience(:object_id); end;";
}
// ----------------------------------------------------------------------
bool TaskConsolidateExperience::DeleteExperienceQuery::bindParameters()
{
if (!bindParameter(object_id)) return false;
return true;
}
// ----------------------------------------------------------------------
bool TaskConsolidateExperience::DeleteExperienceQuery::bindColumns()
{
return true;
}
// ----------------------------------------------------------------------
DB::Query::QueryMode TaskConsolidateExperience::DeleteExperienceQuery::getExecutionMode() const
{
return MODE_PROCEXEC;
}
// ======================================================================
TaskConsolidateExperience::GrantExperienceQuery::GrantExperienceQuery()
{
}
// ----------------------------------------------------------------------
void TaskConsolidateExperience::GrantExperienceQuery::getSQL(std::string &sql)
{
sql="begin "+DatabaseProcess::getInstance().getSchemaQualifier()+"data_cleanup.grant_experience(:object_id, :experience_data); end;";
}
// ----------------------------------------------------------------------
bool TaskConsolidateExperience::GrantExperienceQuery::bindParameters()
{
if (!bindParameter(object_id)) return false;
if (!bindParameter(experience_data)) return false;
return true;
}
// ----------------------------------------------------------------------
bool TaskConsolidateExperience::GrantExperienceQuery::bindColumns()
{
return true;
}
// ----------------------------------------------------------------------
DB::Query::QueryMode TaskConsolidateExperience::GrantExperienceQuery::getExecutionMode() const
{
return MODE_PROCEXEC;
}
// ----------------------------------------------------------------------
void TaskConsolidateExperience::GrantExperienceQuery::setData(const NetworkId &objectId, const std::string &data)
{
object_id=objectId;
experience_data=data;
}
// ======================================================================
@@ -0,0 +1,128 @@
// ======================================================================
//
// TaskConsolidateExperience.h
// copyright (c) 2004 Sony Online Entertainment
//
// ======================================================================
#ifndef INCLUDED_TaskConsolidateExperience_H
#define INCLUDED_TaskConsolidateExperience_H
// ======================================================================
#include "sharedDatabaseInterface/DbQuery.h"
#include "sharedDatabaseInterface/DbTaskRequest.h"
#include "sharedDatabaseInterface/BindableNetworkId.h"
// ======================================================================
/**
* Look for players with lots of pending experience grants, combine them
* into a single grant with the sum of the experience.
*
* A time limit can be specified, in which case this task will do as much
* as it can before the time limit expires.
*/
class TaskConsolidateExperience : public DB::TaskRequest
{
public:
TaskConsolidateExperience(float timeLimit);
~TaskConsolidateExperience();
public:
virtual bool process (DB::Session *session);
virtual void onComplete ();
private:
class FindLotsOfMessagesQuery : public DB::Query
{
public:
FindLotsOfMessagesQuery();
virtual void getSQL(std::string &sql);
virtual bool bindParameters();
virtual bool bindColumns();
virtual QueryMode getExecutionMode() const;
NetworkId getNetworkId() const;
private:
DB::BindableNetworkId object_id;
private:
FindLotsOfMessagesQuery(const FindLotsOfMessagesQuery&);
FindLotsOfMessagesQuery& operator=(const FindLotsOfMessagesQuery&);
};
class GetExperienceQuery : public DB::Query
{
public:
GetExperienceQuery(const NetworkId &objectId);
virtual void getSQL(std::string &sql);
virtual bool bindParameters();
virtual bool bindColumns();
virtual QueryMode getExecutionMode() const;
const std::string getData() const;
private:
DB::BindableNetworkId object_id;
DB::BindableString<1000> grant_data;
private:
GetExperienceQuery(const GetExperienceQuery&);
GetExperienceQuery& operator=(const GetExperienceQuery&);
};
class DeleteExperienceQuery : public DB::Query
{
public:
DeleteExperienceQuery(const NetworkId &targetObject);
virtual void getSQL(std::string &sql);
virtual bool bindParameters();
virtual bool bindColumns();
virtual QueryMode getExecutionMode() const;
private:
DB::BindableNetworkId object_id;
private:
DeleteExperienceQuery(const DeleteExperienceQuery&);
DeleteExperienceQuery& operator=(const DeleteExperienceQuery&);
};
class GrantExperienceQuery : public DB::Query
{
public:
GrantExperienceQuery();
virtual void getSQL(std::string &sql);
virtual bool bindParameters();
virtual bool bindColumns();
virtual QueryMode getExecutionMode() const;
void setData(const NetworkId &objectId, const std::string &data);
private:
DB::BindableNetworkId object_id;
DB::BindableString<1000> experience_data;
private:
GrantExperienceQuery(const GrantExperienceQuery&);
GrantExperienceQuery& operator=(const GrantExperienceQuery&);
};
private:
bool splitExperience(const std::string &packedData, std::string &type, int &amount) const;
std::string makeExperienceString(const std::string &type, int amount);
private:
float m_timeLimit;
};
// ======================================================================
#endif
@@ -0,0 +1,66 @@
// ======================================================================
//
// TaskDailyCleanup.cpp
// copyright (c) 2003 Sony Online Entertainment
//
// ======================================================================
#include "SwgDatabaseServer/FirstSwgDatabaseServer.h"
#include "TaskDailyCleanup.h"
#include "SwgDatabaseServer/ObjvarNameManager.h"
#include "serverDatabase/DatabaseProcess.h"
#include "serverDatabase/Loader.h"
#include "sharedDatabaseInterface/DbSession.h"
// ======================================================================
bool TaskDailyCleanup::process(DB::Session *session)
{
DataCleanupQuery qry;
return (session->exec(&qry));
}
// ----------------------------------------------------------------------
void TaskDailyCleanup::onComplete()
{
DEBUG_REPORT_LOG(true,("[DATABASE CLEANUP] : TaskDailyCleanup::onComplete().\n"));
}
// ======================================================================
TaskDailyCleanup::DataCleanupQuery::DataCleanupQuery()
{
}
// ----------------------------------------------------------------------
void TaskDailyCleanup::DataCleanupQuery::getSQL(std::string &sql)
{
sql="begin "+DatabaseProcess::getInstance().getSchemaQualifier()+"data_cleanup.run_cleanup(); end;";
}
// ----------------------------------------------------------------------
bool TaskDailyCleanup::DataCleanupQuery::bindParameters()
{
return true;
}
// ----------------------------------------------------------------------
bool TaskDailyCleanup::DataCleanupQuery::bindColumns()
{
return true;
}
// ----------------------------------------------------------------------
DB::Query::QueryMode TaskDailyCleanup::DataCleanupQuery::getExecutionMode() const
{
return MODE_PROCEXEC;
}
// ======================================================================
@@ -0,0 +1,46 @@
// ======================================================================
//
// TaskDailyCleanup.h
// copyright (c) 2004 Sony Online Entertainment
//
// ======================================================================
#ifndef INCLUDED_TaskDailyCleanup_H
#define INCLUDED_TaskDailyCleanup_H
// ======================================================================
#include "sharedDatabaseInterface/DbQuery.h"
#include "sharedDatabaseInterface/DbTaskRequest.h"
// ======================================================================
/**
* Runs scripts to do regular daily cleanup in the database.
*/
class TaskDailyCleanup : public DB::TaskRequest
{
public:
virtual bool process (DB::Session *session);
virtual void onComplete ();
private:
class DataCleanupQuery : public DB::Query
{
public:
DataCleanupQuery();
virtual void getSQL(std::string &sql);
virtual bool bindParameters();
virtual bool bindColumns();
virtual QueryMode getExecutionMode() const;
private:
DataCleanupQuery(const DataCleanupQuery&);
DataCleanupQuery& operator=(const DataCleanupQuery&);
};
};
// ======================================================================
#endif
@@ -0,0 +1,68 @@
// ======================================================================
//
// TaskFixBadCells.cpp
// copyright (c) 2005 Sony Online Entertainment
//
// ======================================================================
#include "SwgDatabaseServer/FirstSwgDatabaseServer.h"
#include "TaskFixBadCells.h"
#include "serverDatabase/DatabaseProcess.h"
//#include "serverDatabase/Loader.h"
#include "sharedDatabaseInterface/DbSession.h"
// ======================================================================
bool TaskFixBadCells::process(DB::Session *session)
{
FixBadCellsQuery qry;
DEBUG_REPORT_LOG(true,("[DATABASE CLEANUP] : Processing Bad Cells Query.\n"));
return (session->exec(&qry));
}
// ----------------------------------------------------------------------
void TaskFixBadCells::onComplete()
{
DEBUG_REPORT_LOG(true,("[DATABASE CLEANUP] : TaskFixBadCells::onComplete().\n"));
}
// ======================================================================
TaskFixBadCells::FixBadCellsQuery::FixBadCellsQuery()
{
DEBUG_REPORT_LOG(true,("[DATABASE CLEANUP] : TaskFixBadCells::FixBadCellsQuery::FixBadCellsQuery().\n"));
}
// ----------------------------------------------------------------------
void TaskFixBadCells::FixBadCellsQuery::getSQL(std::string &sql)
{
sql="begin "+DatabaseProcess::getInstance().getSchemaQualifier()+"data_cleanup.run_fix_bad_cells(); end;";
DEBUG_REPORT_LOG(true,("[DATABASE CLEANUP] : Query : %s.\n", sql.c_str()));
}
// ----------------------------------------------------------------------
bool TaskFixBadCells::FixBadCellsQuery::bindParameters()
{
return true;
}
// ----------------------------------------------------------------------
bool TaskFixBadCells::FixBadCellsQuery::bindColumns()
{
return true;
}
// ----------------------------------------------------------------------
DB::Query::QueryMode TaskFixBadCells::FixBadCellsQuery::getExecutionMode() const
{
return MODE_PROCEXEC;
}
// ======================================================================
@@ -0,0 +1,46 @@
// ======================================================================
//
// TaskFixBadCells.h
// copyright (c) 2005 Sony Online Entertainment
//
// ======================================================================
#ifndef INCLUDED_TaskFixBadCells_H
#define INCLUDED_TaskFixBadCells_H
// ======================================================================
#include "sharedDatabaseInterface/DbQuery.h"
#include "sharedDatabaseInterface/DbTaskRequest.h"
// ======================================================================
/**
* Fixes cells that have the wrong load_with.
*/
class TaskFixBadCells : public DB::TaskRequest
{
public:
virtual bool process (DB::Session *session);
virtual void onComplete ();
private:
class FixBadCellsQuery : public DB::Query
{
public:
FixBadCellsQuery();
virtual void getSQL(std::string &sql);
virtual bool bindParameters();
virtual bool bindColumns();
virtual QueryMode getExecutionMode() const;
private:
FixBadCellsQuery(const FixBadCellsQuery&);
FixBadCellsQuery& operator=(const FixBadCellsQuery&);
};
};
// ======================================================================
#endif
@@ -0,0 +1,80 @@
// ======================================================================
//
// TaskMarketAttributesCleanup.cpp
// copyright (c) 2003 Sony Online Entertainment
//
// ======================================================================
#include "SwgDatabaseServer/FirstSwgDatabaseServer.h"
#include "TaskMarketAttributesCleanup.h"
#include "SwgDatabaseServer/ObjvarNameManager.h"
#include "serverDatabase/DatabaseProcess.h"
#include "serverDatabase/Loader.h"
#include "sharedDatabaseInterface/DbSession.h"
#include "sharedLog/Log.h"
// ======================================================================
bool TaskMarketAttributesCleanup::process(DB::Session *session)
{
time_t t_start = time(0);
while( (time(0) - t_start) < m_tSeconds ) // limit the run time
{
DataCleanupQuery qry;
if ( session->exec(&qry) == false )
{
LOG("TaskMarketAttributesCleanup::process",( "returned false!" ));
return false;
}
LOG("TaskMarketAttributesCleanup::process",("ROWS = %d", qry.result.getValue() ));
if( qry.result.getValue() == 0 ) // cleanup done
break;
}
LOG("TaskMarketAttributesCleanup",("TIME = %d", time(0)-t_start ));
return true;
}
// ----------------------------------------------------------------------
void TaskMarketAttributesCleanup::onComplete()
{
}
// ======================================================================
TaskMarketAttributesCleanup::DataCleanupQuery::DataCleanupQuery()
{
}
// ----------------------------------------------------------------------
void TaskMarketAttributesCleanup::DataCleanupQuery::getSQL(std::string &sql)
{
sql="begin :result := "+DatabaseProcess::getInstance().getSchemaQualifier()+"data_cleanup.market_attributes_cleanup(); end;";
}
// ----------------------------------------------------------------------
bool TaskMarketAttributesCleanup::DataCleanupQuery::bindParameters()
{
if (!bindParameter(result)) return false;
return true;
}
// ----------------------------------------------------------------------
bool TaskMarketAttributesCleanup::DataCleanupQuery::bindColumns()
{
return true;
}
// ----------------------------------------------------------------------
DB::Query::QueryMode TaskMarketAttributesCleanup::DataCleanupQuery::getExecutionMode() const
{
return MODE_PROCEXEC;
}
// ======================================================================
@@ -0,0 +1,55 @@
// ======================================================================
//
// TaskMarketAttributesCleanup.h
// copyright (c) 2004 Sony Online Entertainment
//
// ======================================================================
#ifndef INCLUDED_TaskMarketAttributesCleanup_H
#define INCLUDED_TaskMarketAttributesCleanup_H
// ======================================================================
#include "sharedDatabaseInterface/DbQuery.h"
#include "sharedDatabaseInterface/DbTaskRequest.h"
#include "sharedDatabaseInterface/Bindable.h"
#include <time.h>
// ======================================================================
/**
* Runs scripts to do regular daily cleanup in the database.
*/
class TaskMarketAttributesCleanup : public DB::TaskRequest
{
public:
TaskMarketAttributesCleanup( time_t tSeconds ) { m_tSeconds = tSeconds; }
virtual bool process (DB::Session *session);
virtual void onComplete ();
private:
time_t m_tSeconds;
class DataCleanupQuery : public DB::Query
{
public:
DataCleanupQuery();
virtual void getSQL(std::string &sql);
virtual bool bindParameters();
virtual bool bindColumns();
virtual QueryMode getExecutionMode() const;
DB::BindableLong result;
private:
DataCleanupQuery(const DataCleanupQuery&);
DataCleanupQuery& operator=(const DataCleanupQuery&);
};
};
// ======================================================================
#endif
@@ -0,0 +1,80 @@
// ======================================================================
//
// TaskMessagesCleanup.cpp
// copyright (c) 2003 Sony Online Entertainment
//
// ======================================================================
#include "SwgDatabaseServer/FirstSwgDatabaseServer.h"
#include "TaskMessagesCleanup.h"
#include "SwgDatabaseServer/ObjvarNameManager.h"
#include "serverDatabase/DatabaseProcess.h"
#include "serverDatabase/Loader.h"
#include "sharedDatabaseInterface/DbSession.h"
#include "sharedLog/Log.h"
// ======================================================================
bool TaskMessagesCleanup::process(DB::Session *session)
{
time_t t_start = time(0);
while( (time(0) - t_start) < m_tSeconds ) // limit the run time
{
DataCleanupQuery qry;
if ( session->exec(&qry) == false )
{
LOG("TaskMessagesCleanup::process",( "returned false!" ));
return false;
}
LOG("TaskMessagesCleanup::process",("ROWS = %d", qry.result.getValue() ));
if( qry.result.getValue() == 0 ) // cleanup done
break;
}
LOG("TaskMessagesCleanup",("TIME = %d", time(0)-t_start ));
return true;
}
// ----------------------------------------------------------------------
void TaskMessagesCleanup::onComplete()
{
}
// ======================================================================
TaskMessagesCleanup::DataCleanupQuery::DataCleanupQuery()
{
}
// ----------------------------------------------------------------------
void TaskMessagesCleanup::DataCleanupQuery::getSQL(std::string &sql)
{
sql="begin :result := "+DatabaseProcess::getInstance().getSchemaQualifier()+"data_cleanup.messages_cleanup(); end;";
}
// ----------------------------------------------------------------------
bool TaskMessagesCleanup::DataCleanupQuery::bindParameters()
{
if (!bindParameter(result)) return false;
return true;
}
// ----------------------------------------------------------------------
bool TaskMessagesCleanup::DataCleanupQuery::bindColumns()
{
return true;
}
// ----------------------------------------------------------------------
DB::Query::QueryMode TaskMessagesCleanup::DataCleanupQuery::getExecutionMode() const
{
return MODE_PROCEXEC;
}
// ======================================================================
@@ -0,0 +1,55 @@
// ======================================================================
//
// TaskMessagesCleanup.h
// copyright (c) 2004 Sony Online Entertainment
//
// ======================================================================
#ifndef INCLUDED_TaskMessagesCleanup_H
#define INCLUDED_TaskMessagesCleanup_H
// ======================================================================
#include "sharedDatabaseInterface/DbQuery.h"
#include "sharedDatabaseInterface/DbTaskRequest.h"
#include "sharedDatabaseInterface/Bindable.h"
#include <time.h>
// ======================================================================
/**
* Runs scripts to do regular daily cleanup in the database.
*/
class TaskMessagesCleanup : public DB::TaskRequest
{
public:
TaskMessagesCleanup( time_t tSeconds ) { m_tSeconds = tSeconds; }
virtual bool process (DB::Session *session);
virtual void onComplete ();
private:
time_t m_tSeconds;
class DataCleanupQuery : public DB::Query
{
public:
DataCleanupQuery();
virtual void getSQL(std::string &sql);
virtual bool bindParameters();
virtual bool bindColumns();
virtual QueryMode getExecutionMode() const;
DB::BindableLong result;
private:
DataCleanupQuery(const DataCleanupQuery&);
DataCleanupQuery& operator=(const DataCleanupQuery&);
};
};
// ======================================================================
#endif
@@ -0,0 +1,122 @@
// ======================================================================
//
// TaskObjectTemplateListUpdater.cpp
// copyright (c) 2003 Sony Online Entertainment
//
// ======================================================================
#include "SwgDatabaseServer/FirstSwgDatabaseServer.h"
#include "TaskObjectTemplateListUpdater.h"
#include "SwgDatabaseServer/ObjvarNameManager.h"
#include "serverDatabase/DatabaseProcess.h"
#include "serverDatabase/Loader.h"
#include "sharedDatabaseInterface/DbSession.h"
#include "sharedLog/Log.h"
// ======================================================================
// Update the object_templates table based on the contents of the crc string table file
// This file can be found in:
// ../../dsrc/sku.0/sys.server/built/game/misc/object_template_crc_string_table.tab
//
bool TaskObjectTemplateListUpdater::process(DB::Session *session)
{
if ( m_sPath.empty() )
return true;
FILE *in = fopen(m_sPath.c_str(),"r");
if ( in )
{
LOG("TaskObjectTemplateListUpdater",("File open OK" ));
char s_sql[4096];
int i_lines = 0;
while(1)
{
int i_id;
char s_name[4096];
int i_retval = 0;
if ( i_lines++ == 0 ) // do the delete first
strcpy(s_sql,"delete object_templates");
else // read a line
{
i_retval = fscanf(in,"0x%X\t%s\n", &i_id, s_name ); // format = ID(hex) Name(string)
if ( EOF == i_retval ) // commit after final one
strcpy(s_sql,"commit");
else if ( i_retval == 2 ) // got ID & Name
{
s_name[256]=0; // null term to make sure it fits
sprintf(s_sql,"insert into object_templates values (%d,'%s')",i_id,s_name);
}
else
continue;
}
if ( i_lines % 1000 == 0 ) // periodic log
{
LOG("TaskObjectTemplateListUpdater",("(%d) = %s", time(0), s_sql ));
}
AnyQuery qry( s_sql );
session->exec(&qry);
if ( EOF == i_retval ) // done
break;
}
fclose(in);
}
#ifndef WIN32
else
{
char cwdbuf[4096];
LOG("TaskObjectTemplateListUpdater",("Couldn't open %s from %s", m_sPath.c_str(), getcwd(cwdbuf,4096) ));
}
#endif
return true;
}
// ----------------------------------------------------------------------
void TaskObjectTemplateListUpdater::onComplete()
{
}
// ======================================================================
TaskObjectTemplateListUpdater::AnyQuery::AnyQuery( const char* pSQL ) : m_sSQL(pSQL)
{
// Erase trailing semicolon from each line
size_t pos = m_sSQL.rfind(';');
if ( pos != std::string::npos )
m_sSQL.erase( pos );
}
// ----------------------------------------------------------------------
void TaskObjectTemplateListUpdater::AnyQuery::getSQL(std::string &sql)
{
sql=m_sSQL;
}
// ----------------------------------------------------------------------
bool TaskObjectTemplateListUpdater::AnyQuery::bindParameters()
{
return true;
}
// ----------------------------------------------------------------------
bool TaskObjectTemplateListUpdater::AnyQuery::bindColumns()
{
return true;
}
// ----------------------------------------------------------------------
DB::Query::QueryMode TaskObjectTemplateListUpdater::AnyQuery::getExecutionMode() const
{
return MODE_DML;
}
// ======================================================================
@@ -0,0 +1,57 @@
// ======================================================================
//
// TaskObjectTemplateListUpdater.h
// copyright (c) 2004 Sony Online Entertainment
//
// ======================================================================
#ifndef INCLUDED_TaskObjectTemplateListUpdater_H
#define INCLUDED_TaskObjectTemplateListUpdater_H
// ======================================================================
#include "sharedDatabaseInterface/DbQuery.h"
#include "sharedDatabaseInterface/DbTaskRequest.h"
#include "sharedDatabaseInterface/Bindable.h"
#include <time.h>
// ======================================================================
/**
* Runs scripts to do regular daily cleanup in the database.
*/
class TaskObjectTemplateListUpdater : public DB::TaskRequest
{
public:
TaskObjectTemplateListUpdater( const char* sPath ) { m_sPath = sPath; }
virtual bool process (DB::Session *session);
virtual void onComplete ();
private:
std::string m_sPath;
class AnyQuery : public DB::Query
{
public:
AnyQuery( const char* pSQL );
virtual void getSQL(std::string &sql);
virtual bool bindParameters();
virtual bool bindColumns();
virtual QueryMode getExecutionMode() const;
private:
AnyQuery(const AnyQuery&);
AnyQuery& operator=(const AnyQuery&);
std::string m_sSQL;
};
};
// ======================================================================
#endif
@@ -0,0 +1,80 @@
// ======================================================================
//
// TaskObjvarNameCleanup.cpp
// copyright (c) 2003 Sony Online Entertainment
//
// ======================================================================
#include "SwgDatabaseServer/FirstSwgDatabaseServer.h"
#include "TaskObjvarNameCleanup.h"
#include "SwgDatabaseServer/ObjvarNameManager.h"
#include "serverDatabase/DatabaseProcess.h"
#include "serverDatabase/Loader.h"
#include "sharedDatabaseInterface/DbSession.h"
#include "sharedLog/Log.h"
// ======================================================================
bool TaskObjvarNameCleanup::process(DB::Session *session)
{
time_t t_start = time(0);
while( (time(0) - t_start) < m_tSeconds ) // limit the run time
{
DataCleanupQuery qry;
if ( session->exec(&qry) == false )
{
LOG("TaskObjvarNameCleanup::process",( "returned false!" ));
return false;
}
LOG("TaskObjvarNameCleanup::process",("ROWS = %d", qry.result.getValue() ));
if( qry.result.getValue() == 0 ) // cleanup done
break;
}
LOG("TaskObjvarNameCleanup",("TIME = %d", time(0)-t_start ));
return true;
}
// ----------------------------------------------------------------------
void TaskObjvarNameCleanup::onComplete()
{
}
// ======================================================================
TaskObjvarNameCleanup::DataCleanupQuery::DataCleanupQuery()
{
}
// ----------------------------------------------------------------------
void TaskObjvarNameCleanup::DataCleanupQuery::getSQL(std::string &sql)
{
sql="begin :result := "+DatabaseProcess::getInstance().getSchemaQualifier()+"data_cleanup.object_variable_name_cleanup(); end;";
}
// ----------------------------------------------------------------------
bool TaskObjvarNameCleanup::DataCleanupQuery::bindParameters()
{
if (!bindParameter(result)) return false;
return true;
}
// ----------------------------------------------------------------------
bool TaskObjvarNameCleanup::DataCleanupQuery::bindColumns()
{
return true;
}
// ----------------------------------------------------------------------
DB::Query::QueryMode TaskObjvarNameCleanup::DataCleanupQuery::getExecutionMode() const
{
return MODE_PROCEXEC;
}
// ======================================================================
@@ -0,0 +1,55 @@
// ======================================================================
//
// TaskObjvarNameCleanup.h
// copyright (c) 2004 Sony Online Entertainment
//
// ======================================================================
#ifndef INCLUDED_TaskObjvarNameCleanup_H
#define INCLUDED_TaskObjvarNameCleanup_H
// ======================================================================
#include "sharedDatabaseInterface/DbQuery.h"
#include "sharedDatabaseInterface/DbTaskRequest.h"
#include "sharedDatabaseInterface/Bindable.h"
#include <time.h>
// ======================================================================
/**
* Runs scripts to do regular daily cleanup in the database.
*/
class TaskObjvarNameCleanup : public DB::TaskRequest
{
public:
TaskObjvarNameCleanup( time_t tSeconds ) { m_tSeconds = tSeconds; }
virtual bool process (DB::Session *session);
virtual void onComplete ();
private:
time_t m_tSeconds;
class DataCleanupQuery : public DB::Query
{
public:
DataCleanupQuery();
virtual void getSQL(std::string &sql);
virtual bool bindParameters();
virtual bool bindColumns();
virtual QueryMode getExecutionMode() const;
DB::BindableLong result;
private:
DataCleanupQuery(const DataCleanupQuery&);
DataCleanupQuery& operator=(const DataCleanupQuery&);
};
};
// ======================================================================
#endif
@@ -0,0 +1,80 @@
// ======================================================================
//
// TaskOrphanedObjectCleanup.cpp
// copyright (c) 2003 Sony Online Entertainment
//
// ======================================================================
#include "SwgDatabaseServer/FirstSwgDatabaseServer.h"
#include "TaskOrphanedObjectCleanup.h"
#include "SwgDatabaseServer/ObjvarNameManager.h"
#include "serverDatabase/DatabaseProcess.h"
#include "serverDatabase/Loader.h"
#include "sharedDatabaseInterface/DbSession.h"
#include "sharedLog/Log.h"
// ======================================================================
bool TaskOrphanedObjectCleanup::process(DB::Session *session)
{
time_t t_start = time(0);
while( (time(0) - t_start) < m_tSeconds ) // limit the run time
{
DataCleanupQuery qry;
if ( session->exec(&qry) == false )
{
LOG("TaskOrphanedObjectCleanup::process",( "returned false!" ));
return false;
}
LOG("TaskOrphanedObjectCleanup::process",("ROWS = %d", qry.result.getValue() ));
if( qry.result.getValue() == 0 ) // cleanup done
break;
}
LOG("TaskOrphanedObjectCleanup",("TIME = %d", time(0)-t_start ));
return true;
}
// ----------------------------------------------------------------------
void TaskOrphanedObjectCleanup::onComplete()
{
}
// ======================================================================
TaskOrphanedObjectCleanup::DataCleanupQuery::DataCleanupQuery()
{
}
// ----------------------------------------------------------------------
void TaskOrphanedObjectCleanup::DataCleanupQuery::getSQL(std::string &sql)
{
sql="begin :result := "+DatabaseProcess::getInstance().getSchemaQualifier()+"data_cleanup.orphaned_object_cleanup(); end;";
}
// ----------------------------------------------------------------------
bool TaskOrphanedObjectCleanup::DataCleanupQuery::bindParameters()
{
if (!bindParameter(result)) return false;
return true;
}
// ----------------------------------------------------------------------
bool TaskOrphanedObjectCleanup::DataCleanupQuery::bindColumns()
{
return true;
}
// ----------------------------------------------------------------------
DB::Query::QueryMode TaskOrphanedObjectCleanup::DataCleanupQuery::getExecutionMode() const
{
return MODE_PROCEXEC;
}
// ======================================================================
@@ -0,0 +1,55 @@
// ======================================================================
//
// TaskOrphanedObjectCleanup.h
// copyright (c) 2004 Sony Online Entertainment
//
// ======================================================================
#ifndef INCLUDED_TaskOrphanedObjectCleanup_H
#define INCLUDED_TaskOrphanedObjectCleanup_H
// ======================================================================
#include "sharedDatabaseInterface/DbQuery.h"
#include "sharedDatabaseInterface/DbTaskRequest.h"
#include "sharedDatabaseInterface/Bindable.h"
#include <time.h>
// ======================================================================
/**
* Runs scripts to do regular daily cleanup in the database.
*/
class TaskOrphanedObjectCleanup : public DB::TaskRequest
{
public:
TaskOrphanedObjectCleanup( time_t tSeconds ) { m_tSeconds = tSeconds; }
virtual bool process (DB::Session *session);
virtual void onComplete ();
private:
time_t m_tSeconds;
class DataCleanupQuery : public DB::Query
{
public:
DataCleanupQuery();
virtual void getSQL(std::string &sql);
virtual bool bindParameters();
virtual bool bindColumns();
virtual QueryMode getExecutionMode() const;
DB::BindableLong result;
private:
DataCleanupQuery(const DataCleanupQuery&);
DataCleanupQuery& operator=(const DataCleanupQuery&);
};
};
// ======================================================================
#endif
@@ -0,0 +1,80 @@
// ======================================================================
//
// TaskVendorObjectCleanup.cpp
// copyright (c) 2003 Sony Online Entertainment
//
// ======================================================================
#include "SwgDatabaseServer/FirstSwgDatabaseServer.h"
#include "TaskVendorObjectCleanup.h"
#include "SwgDatabaseServer/ObjvarNameManager.h"
#include "serverDatabase/DatabaseProcess.h"
#include "serverDatabase/Loader.h"
#include "sharedDatabaseInterface/DbSession.h"
#include "sharedLog/Log.h"
// ======================================================================
bool TaskVendorObjectCleanup::process(DB::Session *session)
{
time_t t_start = time(0);
while( (time(0) - t_start) < m_tSeconds ) // limit the run time
{
DataCleanupQuery qry;
if ( session->exec(&qry) == false )
{
LOG("TaskVendorObjectCleanup::process",( "returned false!" ));
return false;
}
LOG("TaskVendorObjectCleanup::process",("ROWS = %d", qry.result.getValue() ));
if( qry.result.getValue() == 0 ) // cleanup done
break;
}
LOG("TaskVendorObjectCleanup",("TIME = %d", time(0)-t_start ));
return true;
}
// ----------------------------------------------------------------------
void TaskVendorObjectCleanup::onComplete()
{
}
// ======================================================================
TaskVendorObjectCleanup::DataCleanupQuery::DataCleanupQuery()
{
}
// ----------------------------------------------------------------------
void TaskVendorObjectCleanup::DataCleanupQuery::getSQL(std::string &sql)
{
sql="begin :result := "+DatabaseProcess::getInstance().getSchemaQualifier()+"data_cleanup.vendor_object_cleanup(); end;";
}
// ----------------------------------------------------------------------
bool TaskVendorObjectCleanup::DataCleanupQuery::bindParameters()
{
if (!bindParameter(result)) return false;
return true;
}
// ----------------------------------------------------------------------
bool TaskVendorObjectCleanup::DataCleanupQuery::bindColumns()
{
return true;
}
// ----------------------------------------------------------------------
DB::Query::QueryMode TaskVendorObjectCleanup::DataCleanupQuery::getExecutionMode() const
{
return MODE_PROCEXEC;
}
// ======================================================================
@@ -0,0 +1,55 @@
// ======================================================================
//
// TaskVendorObjectCleanup.h
// copyright (c) 2004 Sony Online Entertainment
//
// ======================================================================
#ifndef INCLUDED_TaskVendorObjectCleanup_H
#define INCLUDED_TaskVendorObjectCleanup_H
// ======================================================================
#include "sharedDatabaseInterface/DbQuery.h"
#include "sharedDatabaseInterface/DbTaskRequest.h"
#include "sharedDatabaseInterface/Bindable.h"
#include <time.h>
// ======================================================================
/**
* Runs scripts to do regular daily cleanup in the database.
*/
class TaskVendorObjectCleanup : public DB::TaskRequest
{
public:
TaskVendorObjectCleanup( time_t tSeconds ) { m_tSeconds = tSeconds; }
virtual bool process (DB::Session *session);
virtual void onComplete ();
private:
time_t m_tSeconds;
class DataCleanupQuery : public DB::Query
{
public:
DataCleanupQuery();
virtual void getSQL(std::string &sql);
virtual bool bindParameters();
virtual bool bindColumns();
virtual QueryMode getExecutionMode() const;
DB::BindableLong result;
private:
DataCleanupQuery(const DataCleanupQuery&);
DataCleanupQuery& operator=(const DataCleanupQuery&);
};
};
// ======================================================================
#endif
@@ -0,0 +1,269 @@
// ======================================================================
//
// CMLoader.cpp
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#include "SwgDatabaseServer/FirstSwgDatabaseServer.h"
#include "CMLoader.h"
#include "serverDatabase/ConfigServerDatabase.h"
#include "serverDatabase/DatabaseProcess.h"
#include "serverNetworkMessages/CommoditiesLoadDoneMessage.h"
#include "serverNetworkMessages/LoadCommoditiesMessage.h"
#include "serverNetworkMessages/GetAuctionLocationsMessage.h"
#include "serverNetworkMessages/GetMarketAuctionAttributesMessage.h"
#include "serverNetworkMessages/GetMarketAuctionBidsMessage.h"
#include "serverNetworkMessages/GetMarketAuctionsMessage.h"
#include "sharedDatabaseInterface/DbTaskQueue.h"
#include "sharedFoundation/ExitChain.h"
#include "sharedFoundation/Os.h"
#include "sharedLog/Log.h"
#include "TaskGetAuctionAttributeList.h"
#include "TaskGetAuctionList.h"
#include "TaskGetLocationList.h"
#include "TaskGetBidList.h"
CMLoader *CMLoader::ms_instance = NULL;
// ======================================================================
void CMLoader::install()
{
DEBUG_FATAL(ms_instance, ("Installed CMLoader twice.\n"));
ms_instance = new CMLoader;
ExitChain::add(&remove, "Loader::remove");
}
// ----------------------------------------------------------------------
void CMLoader::remove()
{
NOT_NULL(ms_instance);
delete ms_instance;
ms_instance = NULL;
}
// ----------------------------------------------------------------------
CMLoader::CMLoader() :
m_tablesLoaded(0),
m_auctionLocationsCount(0),
m_marketAuctionsCount(0),
m_marketAuctionAttributesCount(0),
m_marketAuctionBidsCount(0),
m_mutex(),
m_taskQ(new DB::TaskQueue(static_cast<unsigned int>(ConfigServerDatabase::getLoaderThreads()),DatabaseProcess::getInstance().getDBServer(),0)),
m_locationList(),
m_auctionList(),
m_auctionAttributeList(),
m_bidList(),
m_timeLoadStarted(0), // 0 means load hasn't started yet
m_loadTime(-1) // -1 means load hasn't completed yet
{
;
}
// ----------------------------------------------------------------------
CMLoader:: ~CMLoader()
{
}
// ----------------------------------------------------------------------
// It is important that commodity tables are loaded in the following order:
// AUCTION_LOCATIONS, MARKET_AUCTIONS, MARKET_AUCTION_ATTRIBUTES, and MARKET_AUCTION_BIDS.
// To make sure commodity tables are loaded in this order, TaskGetLocationList is put
// into taskQ first. When onLoadComplete for AUCTION_LOCATIONS finishes,
// TaskGetAuctionList is put into taskQ, and so on.
void CMLoader::loadCommoditiesData()
{
m_timeLoadStarted = time(0); // mark when the load started
m_loadTime = -1; // -1 means load hasn't completed yet
m_tablesLoaded = 0;
m_taskQ->asyncRequest(new TaskGetLocationList);
LOG("SwgDatabaseServer", ("start CommoditiesLoad"));
}
void CMLoader::onLoadComplete(const std::string & tableName, const int count)
{
m_tablesLoaded++;
if (tableName == "AUCTION_LOCATIONS")
{
m_auctionLocationsCount = count;
m_taskQ->asyncRequest(new TaskGetAuctionList);
LOG("SwgDatabaseServer", ("finish loading AUCTION_LOCATIONS, start loading MARKET_AUCTIONS"));
}
else if (tableName == "MARKET_AUCTIONS")
{
m_marketAuctionsCount = count;
m_taskQ->asyncRequest(new TaskGetAuctionAttributeList);
LOG("SwgDatabaseServer", ("finish loading MARKET_AUCTIONS, start loading MARKET_AUCTION_ATTRIBUTES"));
}
else if (tableName == "MARKET_AUCTION_ATTRIBUTES")
{
m_marketAuctionAttributesCount = count;
m_taskQ->asyncRequest(new TaskGetBidList);
LOG("SwgDatabaseServer", ("finish loading MARKET_AUCTION_ATTRIBUTES, start loading MARKET_AUCTION_BIDS"));
}
else if (tableName == "MARKET_AUCTION_BIDS")
{
m_marketAuctionBidsCount = count;
LOG("SwgDatabaseServer", ("finish loading MARKET_AUCTION_BIDS"));
}
else
FATAL(true, ("Unknown table %s loaded for commodities.\n", tableName.c_str()));
}
// ----------------------------------------------------------------------
void CMLoader::update()
{
volatile int i;
NOT_NULL(m_taskQ);
m_taskQ->update(0);
m_mutex.enter();
if (! m_locationList.empty())
{
GetAuctionLocationsMessage msg;
int numLocations = 0;
std::list<LocationRecord>::iterator locationIterator = m_locationList.begin();
while (locationIterator != m_locationList.end())
{
msg.addAuctionLocation(
locationIterator->m_locationId,
locationIterator->m_locationString.length(),
locationIterator->m_locationString,
locationIterator->m_ownerId,
locationIterator->m_salesTax,
locationIterator->m_salesTaxBankId,
locationIterator->m_emptyDate,
locationIterator->m_lastAccessDate,
locationIterator->m_inactiveDate,
locationIterator->m_status,
locationIterator->m_searchEnabled,
locationIterator->m_entranceCharge
);
if (++numLocations >= ConfigServerDatabase::getAuctionLocationLoadBatchSize())
{
DatabaseProcess::getInstance().sendToCommoditiesServer(msg, true);
numLocations = 0;
msg.clearAllAuctionLocations();
}
++locationIterator;
}
if (!msg.getAuctionLocations().empty())
DatabaseProcess::getInstance().sendToCommoditiesServer(msg, true);
m_locationList.clear();
}
if (! m_auctionList.empty())
{
GetMarketAuctionsMessage msg;
int numAuctions = 0;
std::list<AuctionRecord>::iterator auctionIterator = m_auctionList.begin();
while (auctionIterator != m_auctionList.end())
{
msg.addAuction(auctionIterator->m_itemId, auctionIterator->m_ownerId, auctionIterator->m_creatorId, auctionIterator->m_locationId, auctionIterator->m_minBid, auctionIterator->m_buyNowPrice, auctionIterator->m_auctionTimer, auctionIterator->m_oob.length(), auctionIterator->m_oob, auctionIterator->m_userDescription.length(), auctionIterator->m_userDescription, auctionIterator->m_category, auctionIterator->m_itemTemplateId, auctionIterator->m_itemName.length(), auctionIterator->m_itemName, auctionIterator->m_itemTimer, auctionIterator->m_active, auctionIterator->m_itemSize);
if (++numAuctions >= ConfigServerDatabase::getAuctionLoadBatchSize())
{
DatabaseProcess::getInstance().sendToCommoditiesServer(msg, true);
numAuctions = 0;
msg.clearAllAuctions();
}
++auctionIterator;
}
if (!msg.getAuctions().empty())
DatabaseProcess::getInstance().sendToCommoditiesServer(msg, true);
m_auctionList.clear();
}
if (! m_auctionAttributeList.empty())
{
GetMarketAuctionAttributesMessage msg;
int numAttributes = 0;
std::list<std::pair<NetworkId, std::pair<std::string, Unicode::String> > >::iterator auctionAttributeIterator = m_auctionAttributeList.begin();
while (auctionAttributeIterator != m_auctionAttributeList.end())
{
msg.addAttribute(auctionAttributeIterator->first, auctionAttributeIterator->second.first, auctionAttributeIterator->second.second);
if (++numAttributes >= ConfigServerDatabase::getAuctionAttributeLoadBatchSize())
{
DatabaseProcess::getInstance().sendToCommoditiesServer(msg, true);
numAttributes = 0;
msg.clearAllAttributes();
}
++auctionAttributeIterator;
}
if (!msg.getAttributes().empty())
DatabaseProcess::getInstance().sendToCommoditiesServer(msg, true);
m_auctionAttributeList.clear();
}
if (! m_bidList.empty())
{
GetMarketAuctionBidsMessage msg;
int numBids = 0;
std::list<BidRecord>::iterator bidIterator = m_bidList.begin();
while (bidIterator != m_bidList.end())
{
msg.addMarketAuctionBid(bidIterator->m_itemId, bidIterator->m_bidderId, bidIterator->m_bid, bidIterator->m_maxProxyBid);
if (++numBids >= ConfigServerDatabase::getAuctionBidLoadBatchSize())
{
DatabaseProcess::getInstance().sendToCommoditiesServer(msg, true);
numBids = 0;
msg.clearAllMarketAuctionBids();
}
++bidIterator;
}
if (!msg.getMarketAuctionBids().empty())
DatabaseProcess::getInstance().sendToCommoditiesServer(msg, true);
m_bidList.clear();
}
i = m_tablesLoaded;
if (i == 4)
{
m_tablesLoaded = 0;
// record how long it took to load
if ((m_loadTime == -1) && (m_timeLoadStarted != 0))
m_loadTime = int((time(0) - m_timeLoadStarted) / 60);
// commodity loading finished, send message back to CommoditiesServer
DEBUG_REPORT_LOG(true, ("Sending CommoditiesLoadDoneMessage to CommoditesServer. Auction_Locations = %d, Market_Auctions = %d, Market_Auction_Attributes = %d, Market_Auction_Bids = %d\n",
m_auctionLocationsCount, m_marketAuctionsCount, m_marketAuctionAttributesCount, m_marketAuctionBidsCount));
LOG("SwgDatabaseServer", ("Sending CommoditiesLoadDoneMessage to CommoditesServer. Auction_Locations = %d, Market_Auctions = %d, Market_Auction_Attributes = %d, Market_Auction_Bids = %d\n",
m_auctionLocationsCount, m_marketAuctionsCount, m_marketAuctionAttributesCount, m_marketAuctionBidsCount));
CommoditiesLoadDoneMessage msg(m_auctionLocationsCount, m_marketAuctionsCount, m_marketAuctionAttributesCount, m_marketAuctionBidsCount);
DatabaseProcess::getInstance().sendToCommoditiesServer(msg, true);
}
m_mutex.leave();
}
// ----------------------------------------------------------------------
int CMLoader::getLoadTime() const
{
if (m_timeLoadStarted == 0)
{
// load hasn't started yet
return 0;
}
else
{
if (m_loadTime != -1)
return m_loadTime;
else
// return how long we have been loading
return int((time(0) - m_timeLoadStarted) / 60);
}
}
// ======================================================================
@@ -0,0 +1,85 @@
// ======================================================================
//
// CMLoader.h
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#ifndef INCLUDED_CMLoader_H
#define INCLUDED_CMLoader_H
#include "serverDatabase/dBAuctionRecord.h"
#include "serverDatabase/dBBidRecord.h"
#include "serverDatabase/dBLocationRecord.h"
#include "sharedFoundation/FirstSharedFoundation.h"
#include "sharedSynchronization/Mutex.h"
#include <list>
// ======================================================================
namespace DB
{
class TaskQueue;
class Server;
}
/**
* Singleton that organizes and queues requests to load objects from the database.
*/
class CMLoader
{
public:
static void install();
static CMLoader &getInstance();
void update();
void onLoadComplete(const std::string & tableName, const int count);
void loadCommoditiesData();
void addAuctionLocation(const LocationRecord & data) {m_mutex.enter(); m_locationList.push_back(data); m_mutex.leave();};
void addAuctionLocationNoLockMutex(const LocationRecord & data) {m_locationList.push_back(data);};
void addMarketAuctions(const AuctionRecord & data) {m_mutex.enter(); m_auctionList.push_back(data); m_mutex.leave();};
void addMarketAuctionsNoLockMutex(const AuctionRecord & data) {m_auctionList.push_back(data);};
void addMarketAuctionAttributes(const NetworkId & itemId, const std::string & attributeName, const Unicode::String & attributeValue) {m_mutex.enter(); m_auctionAttributeList.push_back(std::make_pair(itemId, std::make_pair(attributeName, attributeValue))); m_mutex.leave();};
void addMarketAuctionAttributesNoLockMutex(const NetworkId & itemId, const std::string & attributeName, const Unicode::String & attributeValue) {m_auctionAttributeList.push_back(std::make_pair(itemId, std::make_pair(attributeName, attributeValue)));};
void addMarketAuctionBid(const BidRecord & data) {m_mutex.enter(); m_bidList.push_back(data); m_mutex.leave();};
void addMarketAuctionBidNoLockMutex(const BidRecord & data) {m_bidList.push_back(data);};
void lockMutex() {m_mutex.enter();};
void unlockMutex() {m_mutex.leave();};
int getLoadTime() const;
private:
CMLoader();
virtual ~CMLoader();
CMLoader(const CMLoader &);
CMLoader & operator = (const CMLoader &);
static void remove();
static CMLoader *ms_instance;
int m_tablesLoaded;
int m_auctionLocationsCount;
int m_marketAuctionsCount;
int m_marketAuctionAttributesCount;
int m_marketAuctionBidsCount;
Mutex m_mutex;
DB::TaskQueue *m_taskQ;
std::list<LocationRecord> m_locationList;
std::list<AuctionRecord> m_auctionList;
std::list<std::pair<NetworkId, std::pair<std::string, Unicode::String> > > m_auctionAttributeList;
std::list<BidRecord> m_bidList;
time_t m_timeLoadStarted;
int m_loadTime;
};
// ----------------------------------------------------------------------
inline CMLoader &CMLoader::getInstance()
{
NOT_NULL(ms_instance);
return *ms_instance;
}
// ======================================================================
#endif
@@ -0,0 +1,427 @@
// ======================================================================
//
// SwgSnapshot.cpp
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#include "SwgDatabaseServer/FirstSwgDatabaseServer.h"
#include "SwgDatabaseServer/CommoditiesSnapshot.h"
#include "Archive/AutoDeltaSet.h"
#include "Archive/AutoDeltaVector.h"
#include "serverDatabase/ConfigServerDatabase.h"
#include "serverDatabase/DatabaseProcess.h" //TODO: remove after cleaning up authority transfer stuff
#include "serverDatabase/GameServerConnection.h"
#include "serverDatabase/ImmediateDeleteCustomPersistStep.h"
#include "serverDatabase/MessageToManager.h"
#include "serverDatabase/ObjectLocator.h"
#include "serverDatabase/Persister.h"
#include "serverNetworkMessages/CMCreateAuctionMessage.h"
#include "serverNetworkMessages/CMCreateAuctionBidMessage.h"
#include "serverNetworkMessages/CMCreateLocationMessage.h"
#include "serverNetworkMessages/CMDeleteAuctionMessage.h"
#include "serverNetworkMessages/CMDeleteLocationMessage.h"
#include "serverNetworkMessages/CMUpdateAuctionMessage.h"
#include "serverNetworkMessages/CMUpdateLocationMessage.h"
#include "serverUtility/MissionLocation.h"
#include "sharedFoundation/DynamicVariableList.h"
#include "sharedFoundation/GameControllerMessage.h"
#include "sharedFoundation/NetworkIdArchive.h"
#include "sharedFoundation/Os.h"
#include "sharedUtility/Location.h"
#include "sharedGame/MatchMakingId.h"
#include "sharedLog/Log.h"
#include "sharedMath/Quaternion.h"
#include "sharedMathArchive/TransformArchive.h"
#include "sharedMathArchive/VectorArchive.h"
#include "swgSharedUtility/Attributes.def"
#include "SwgDatabaseServer/ObjectTableBuffer.h"
#include "unicodeArchive/UnicodeArchive.h"
// ======================================================================
/**
* Construct a snapshot.
*
* This and the header file should be the only places that the entire
* list of buffers is hard-coded. Every other place where you want to refer
* to all the buffers should use m_bufferList. This will reduce the number
* of places the code needs to be changed if new buffers are added.
* (Referring to a _specific_ buffer when you know you need that buffer
* is kosher.)
*/
CommoditiesSnapshot::CommoditiesSnapshot(DB::ModeQuery::Mode mode) :
Snapshot(mode, false),
m_deleteMarketAuctionsBuffer(),
m_deleteAuctionLocationsBuffer(DB::ModeQuery::mode_DELETE),
m_createMarketAuctionsBuffer(),
m_createAuctionLocationsBuffer(DB::ModeQuery::mode_INSERT),
m_createMarketAuctionBidsBuffer(DB::ModeQuery::mode_INSERT),
m_updateMarketAuctionsBuffer(),
m_updateAuctionLocationsBuffer(DB::ModeQuery::mode_UPDATE),
doLoadAfterSaveComplete(false)
{
;
}
// ----------------------------------------------------------------------
CommoditiesSnapshot::~CommoditiesSnapshot()
{
}
// ----------------------------------------------------------------------
/**
* Called by a worker thread. Saves the snapshot to the database
* @todo: would it be better to have SwgSnapshot add a CustomStep for
* the objectTableBuffer and not override this function?
*/
bool CommoditiesSnapshot::saveToDB(DB::Session *session)
{
if (Snapshot::getTimeStamp()!=0)
{
if (! (Snapshot::saveTimestamp(session)))
return false;
}
LOG("CommoditiesServer", ("start save CommoditiesSnapshot"));
// artificial delay can be added here to help debug timing issues
if (ConfigServerDatabase::getWriteDelay() > 0)
{
LOG("CommoditiesSnapshot::saveToDB",("Delaying writing of snapshot for %i seconds",ConfigServerDatabase::getWriteDelay()));
Os::sleep(ConfigServerDatabase::getWriteDelay()*1000);
}
DEBUG_REPORT_LOG(true, ("Snapshot calling MarketAuctionsBuffer.save().\n"));
session->setAutoCommitMode(false);
// If we want to use database rferential integrity (and we do),
// then these must be executed in order!
if (! (m_deleteAuctionLocationsBuffer.save(session)))
return false;
if (! (m_deleteMarketAuctionsBuffer.save(session)))
return false;
if (! (m_createAuctionLocationsBuffer.save(session)))
return false;
if (! (m_createMarketAuctionsBuffer.save(session)))
return false;
if (! (m_createMarketAuctionBidsBuffer.save(session)))
return false;
if (! (m_updateAuctionLocationsBuffer.save(session)))
return false;
if (! (m_updateMarketAuctionsBuffer.save(session)))
return false;
session->commitTransaction();
LOG("CommoditiesServer", ("finish save CommoditiesSnapshot"));
return true;
}
/**
* Called when a message is received to update an object's transform and container.
*
* Identifies what the message changes, and puts it in the appropriate
* table buffer.
*/
void CommoditiesSnapshot::handleUpdateObjectPosition(const UpdateObjectPositionMessage &message)
{
;
}
// ----------------------------------------------------------------------
/**
* Called when a message is received to delete an object.
*
* Tells the objectTableBuffer to set the deleted column to true.
*/
void CommoditiesSnapshot::handleDeleteMessage(const NetworkId &objectId, int reasonCode, bool immediate, bool demandLoadedContainer, bool cascadeReason)
{
;
}
// ----------------------------------------------------------------------
void CommoditiesSnapshot::handleMessageTo(const MessageToPayload &data)
{
;
}
// ----------------------------------------------------------------------
void CommoditiesSnapshot::handleMessageToAck(const MessageToId &messageId)
{
;
}
// ----------------------------------------------------------------------
/**
* Load the objects.
*
* This function will load all the objects listed in m_oidList.
*/
bool CommoditiesSnapshot::load(DB::Session *session)
{
return true;
}
// ----------------------------------------------------------------------
/**
* Send the snapshot to the appropriate server.
*
* This function will send messages to the appropriate gameServer to
* create a proxy for the objects in the snapshot, then it will send a
* message to central to relinquish authority for the objects.
*
* @return true if the objects were sent, false if they were not.
*/
bool CommoditiesSnapshot::send(GameServerConnection *connection) const
{
return true;
}
// ----------------------------------------------------------------------
void CommoditiesSnapshot::saveCompleted()
{
Snapshot::saveCompleted();
if (doLoadAfterSaveComplete)
Persister::getInstance().startLoadCommodities();
}
// ----------------------------------------------------------------------
void CommoditiesSnapshot::newObject(NetworkId const & objectId, int templateId, Tag typeId)
{
WARNING(true,("Attempt to create object %s. It has unknown type %i.",objectId.getValueString().c_str(),typeId));
}
// ----------------------------------------------------------------------
void CommoditiesSnapshot::handleCommoditiesDataMessage(const MessageDispatch::MessageBase & message)
{
if (message.isType("CMCreateAuctionMessage"))
{
Archive::ReadIterator ri = static_cast<const GameNetworkMessage &>(message).getByteStream().begin();
CMCreateAuctionMessage msg(ri);
handleCreateAuctionMessage(msg);
}
else if (message.isType("CMCreateLocationMessage"))
{
Archive::ReadIterator ri = static_cast<const GameNetworkMessage &>(message).getByteStream().begin();
CMCreateLocationMessage msg(ri);
handleCreateLocationMessage(msg);
}
else if (message.isType("CMCreateAuctionBidMessage"))
{
Archive::ReadIterator ri = static_cast<const GameNetworkMessage &>(message).getByteStream().begin();
CMCreateAuctionBidMessage msg(ri);
handleCreateAuctionBidMessage(msg);
}
else if (message.isType("CMUpdateAuctionMessage"))
{
Archive::ReadIterator ri = static_cast<const GameNetworkMessage &>(message).getByteStream().begin();
CMUpdateAuctionMessage msg(ri);
handleUpdateAuctionMessage(msg);
}
else if (message.isType("CMUpdateLocationMessage"))
{
Archive::ReadIterator ri = static_cast<const GameNetworkMessage &>(message).getByteStream().begin();
CMUpdateLocationMessage msg(ri);
handleUpdateLocationMessage(msg);
}
else if (message.isType("CMDeleteAuctionMessage"))
{
Archive::ReadIterator ri = static_cast<const GameNetworkMessage &>(message).getByteStream().begin();
CMDeleteAuctionMessage msg(ri);
handleDeleteAuctionMessage(msg);
}
else if (message.isType("CMDeleteLocationMessage"))
{
Archive::ReadIterator ri = static_cast<const GameNetworkMessage &>(message).getByteStream().begin();
CMDeleteLocationMessage msg(ri);
handleDeleteLocationMessage(msg);
}
}
// ----------------------------------------------------------------------
void CommoditiesSnapshot::startLoadAfterSaveComplete()
{
doLoadAfterSaveComplete = true;
}
// ----------------------------------------------------------------------
void CommoditiesSnapshot::handleCreateAuctionMessage(CMCreateAuctionMessage &msg)
{
DEBUG_REPORT_LOG(true, ("CommoditiesSnapshot Received CMCreateAuctionMessage\n"));
LOG("CommoditiesServer", ("Handling CMCreateAuctionMessage for item %s", msg.GetItemId().getValueString().c_str()));
m_createMarketAuctionsBuffer.setMarketAuctions(
msg.GetItemId(),
msg.GetOwnerId(),
msg.GetCreatorId(),
msg.GetLocationId(),
msg.GetMinimumBid(),
msg.GetBuyNowPrice(),
msg.GetAuctionTimer(),
msg.GetAttributes(),
msg.GetUserDescription(),
msg.GetItemType(),
msg.GetItemTemplateId(),
msg.GetItemName(),
msg.GetExpireTimer(),
msg.GetFlags(),
msg.GetItemSize());
}
void CommoditiesSnapshot::handleCreateAuctionBidMessage(CMCreateAuctionBidMessage &msg)
{
DEBUG_REPORT_LOG(true, ("CommoditiesSnapshot Received CMCreateAuctionBidMessage\n"));
m_createMarketAuctionBidsBuffer.setMarketAuctionBids(
msg.GetItemId(),
msg.GetBidderId(),
msg.GetBid(),
msg.GetMaxProxyBid());
}
void CommoditiesSnapshot::handleCreateLocationMessage(CMCreateLocationMessage &msg)
{
DEBUG_REPORT_LOG(true, ("CommoditiesSnapshot Received CMCreateLocationMessage\n"));
m_createAuctionLocationsBuffer.setAuctionLocations(
msg.GetLocationId(),
msg.GetLocationString(),
msg.GetOwnerId(),
msg.GetSalesTax(),
msg.GetBankId(),
msg.GetEmptyDate(),
msg.GetLastAccessDate(),
msg.GetInactiveDate(),
msg.GetStatus(),
msg.GetSearchEnabled(),
msg.GetEntranceCharge());
}
void CommoditiesSnapshot::handleUpdateAuctionMessage(CMUpdateAuctionMessage &msg)
{
DEBUG_REPORT_LOG(true, ("CommoditiesSnapshot Received CMUpdateAuctionMessage\n"));
DBSchema::MarketAuctionsRow *row = m_createMarketAuctionsBuffer.findRowByIndex(msg.GetItemId());
if (row)
{
m_createMarketAuctionsBuffer.setMarketAuctions(msg.GetItemId(), msg.GetOwnerId(), msg.GetFlags());
}
else
{
m_updateMarketAuctionsBuffer.setMarketAuctions(msg.GetItemId(), msg.GetOwnerId(), msg.GetFlags());
}
}
void CommoditiesSnapshot::handleUpdateLocationMessage(CMUpdateLocationMessage &msg)
{
DEBUG_REPORT_LOG(true, ("CommoditiesSnapshot Received CMUpdateLocationMessage\n"));
DBSchema::AuctionLocationsRow *row = m_createAuctionLocationsBuffer.findRowByIndex(msg.GetLocationId());
if (row)
{
m_createAuctionLocationsBuffer.setAuctionLocations(
msg.GetLocationId(),
msg.GetLocationString(),
msg.GetOwnerId(),
msg.GetSalesTax(),
msg.GetBankId(),
msg.GetEmptyDate(),
msg.GetLastAccessDate(),
msg.GetInactiveDate(),
msg.GetStatus(),
msg.GetSearchEnabled(),
msg.GetEntranceCharge());
}
else
{
m_updateAuctionLocationsBuffer.setAuctionLocations(
msg.GetLocationId(),
msg.GetLocationString(),
msg.GetOwnerId(),
msg.GetSalesTax(),
msg.GetBankId(),
msg.GetEmptyDate(),
msg.GetLastAccessDate(),
msg.GetInactiveDate(),
msg.GetStatus(),
msg.GetSearchEnabled(),
msg.GetEntranceCharge());
}
}
void CommoditiesSnapshot::handleDeleteAuctionMessage(CMDeleteAuctionMessage &msg)
{
DEBUG_REPORT_LOG(true, ("CommoditiesSnapshot Received CMDeleteAuctionMessage\n"));
m_createMarketAuctionsBuffer.removeMarketAuctions(msg.GetItemId());
m_updateMarketAuctionsBuffer.removeMarketAuctions(msg.GetItemId());
m_createMarketAuctionBidsBuffer.removeMarketAuctionBids(msg.GetItemId());
m_deleteMarketAuctionsBuffer.setMarketAuctions(msg.GetItemId());
}
void CommoditiesSnapshot::handleDeleteLocationMessage(CMDeleteLocationMessage &msg)
{
DEBUG_REPORT_LOG(true, ("CommoditiesSnapshot Received CMDeleteLocationMessage\n"));
m_createAuctionLocationsBuffer.removeAuctionLocations(msg.GetLocationId());
m_updateAuctionLocationsBuffer.removeAuctionLocations(msg.GetLocationId());
m_deleteAuctionLocationsBuffer.setAuctionLocations(msg.GetLocationId());
}
// ----------------------------------------------------------------------
/**
* For gold mode, return a list of all the objects in the world that may be
* ordinary (non-demand-load) containers. The live database will be checked
* for objects inside these objects.
*/
void CommoditiesSnapshot::getWorldContainers(stdvector<NetworkId>::fwd &containers) const
{
}
// ----------------------------------------------------------------------
void CommoditiesSnapshot::decodeServerData(NetworkId const & objectId, Tag typeId, uint16 index, Archive::ReadIterator &bs, bool isBaseline)
{
}
void CommoditiesSnapshot::decodeSharedData(NetworkId const & objectId, Tag typeId, uint16 index, Archive::ReadIterator &bs, bool isBaseline)
{
}
void CommoditiesSnapshot::decodeClientData(NetworkId const & objectId, Tag typeId, uint16 index, Archive::ReadIterator &bs, bool isBaseline)
{
}
void CommoditiesSnapshot::decodeParentClientData(NetworkId const & objectId, Tag typeId, uint16 index, Archive::ReadIterator &bs, bool isBaseline)
{
}
bool CommoditiesSnapshot::encodeSharedData(NetworkId const & objectId, Tag typeId, std::vector<BatchBaselinesMessageData> &baselines) const
{
return false;
}
bool CommoditiesSnapshot::encodeServerData(NetworkId const & objectId, Tag typeId, std::vector<BatchBaselinesMessageData> &baselines) const
{
return false;
}
bool CommoditiesSnapshot::encodeClientData(NetworkId const & objectId, Tag typeId, std::vector<BatchBaselinesMessageData> &baselines) const
{
return false;
}
bool CommoditiesSnapshot::encodeParentClientData(NetworkId const & objectId, Tag typeId, std::vector<BatchBaselinesMessageData> &baselines) const
{
return false;
}
@@ -0,0 +1,104 @@
// ======================================================================
//
// CommoditiesSnapshot.h
// copyright (c) 2004 Sony Online Entertainment
//
// ======================================================================
#ifndef INCLUDED_CommoditiesSnapshot_H
#define INCLUDED_CommoditiesSnapshot_H
// ======================================================================
#include "Archive/ByteStream.h"
#include "serverDatabase/Snapshot.h"
#include "serverDatabase/TableBuffer.h"
#include "sharedFoundation/Tag.h"
#include "SwgDatabaseServer/AuctionLocationsBuffer.h"
#include "SwgDatabaseServer/MarketAuctionsBuffer.h"
#include "SwgDatabaseServer/MarketAuctionBidsBuffer.h"
class CMCreateAuctionMessage;
class CMCreateAuctionBidMessage;
class CMCreateLocationMessage;
class CMDeleteAuctionMessage;
class CMDeleteLocationMessage;
class CMUpdateAuctionMessage;
class CMUpdateLocationMessage;
namespace DB
{
class Session;
}
// ======================================================================
/**
* A Snapshot customized to Star Wars Galaxies Commodities Server.
*
* @todo: there are a lot of public functions that could be made private
*/
class CommoditiesSnapshot : public Snapshot
{
public:
CommoditiesSnapshot(DB::ModeQuery::Mode mode);
~CommoditiesSnapshot();
// Network Functions:
virtual void handleUpdateObjectPosition(const UpdateObjectPositionMessage &message);
virtual void handleDeleteMessage (const NetworkId &objectID, int reasonCode, bool immediate, bool demandLoadedContainer, bool cascadeReason);
virtual void handleMessageTo (const MessageToPayload &data);
virtual void handleMessageToAck (const MessageToId &messageId);
virtual void handleAddResourceTypeMessage (const AddResourceTypeMessage &) { ;}
virtual void handleBountyHunterTargetMessage (const BountyHunterTargetMessage &) { ;}
virtual bool send (GameServerConnection *connection) const;
// Saving and Loading:
virtual bool saveToDB (DB::Session *session);
virtual bool load (DB::Session *session);
virtual void saveCompleted ();
virtual void getWorldContainers (stdvector<NetworkId>::fwd &containers) const;
virtual void handleCommoditiesDataMessage(const MessageDispatch::MessageBase & message);
virtual void startLoadAfterSaveComplete();
// Functions for object creation:
virtual void newObject(NetworkId const & objectId, int templateId, Tag typeId);
protected:
MarketAuctionsBufferDelete m_deleteMarketAuctionsBuffer;
AuctionLocationsBuffer m_deleteAuctionLocationsBuffer;
MarketAuctionsBufferCreate m_createMarketAuctionsBuffer;
AuctionLocationsBuffer m_createAuctionLocationsBuffer;
MarketAuctionBidsBuffer m_createMarketAuctionBidsBuffer;
MarketAuctionsBufferUpdate m_updateMarketAuctionsBuffer;
AuctionLocationsBuffer m_updateAuctionLocationsBuffer;
bool doLoadAfterSaveComplete;
private:
void handleCreateAuctionMessage(CMCreateAuctionMessage &msg);
void handleCreateAuctionBidMessage(CMCreateAuctionBidMessage &msg);
void handleCreateLocationMessage(CMCreateLocationMessage &msg);
void handleUpdateAuctionMessage(CMUpdateAuctionMessage &msg);
void handleUpdateLocationMessage(CMUpdateLocationMessage &msg);
void handleDeleteAuctionMessage(CMDeleteAuctionMessage &msg);
void handleDeleteLocationMessage(CMDeleteLocationMessage &msg);
virtual void decodeServerData(NetworkId const & objectId, Tag typeId, uint16 index, Archive::ReadIterator &bs, bool isBaseline);
virtual void decodeSharedData(NetworkId const & objectId, Tag typeId, uint16 index, Archive::ReadIterator &bs, bool isBaseline);
virtual void decodeClientData(NetworkId const & objectId, Tag typeId, uint16 index, Archive::ReadIterator &bs, bool isBaseline);
virtual void decodeParentClientData(NetworkId const & objectId, Tag typeId, uint16 index, Archive::ReadIterator &bs, bool isBaseline);
virtual bool encodeParentClientData(NetworkId const & objectId, Tag typeId, stdvector<BatchBaselinesMessageData>::fwd &baselines) const;
virtual bool encodeClientData(NetworkId const & objectId, Tag typeId, stdvector<BatchBaselinesMessageData>::fwd &baselines) const;
virtual bool encodeServerData(NetworkId const & objectId, Tag typeId, stdvector<BatchBaselinesMessageData>::fwd &baselines) const;
virtual bool encodeSharedData(NetworkId const & objectId, Tag typeId, stdvector<BatchBaselinesMessageData>::fwd &baselines) const;
private:
CommoditiesSnapshot(const CommoditiesSnapshot&); //disable
CommoditiesSnapshot &operator=(const CommoditiesSnapshot&); //disable
};
// ======================================================================
#endif
@@ -0,0 +1,25 @@
// ======================================================================
//
// FirstSwgDatabaseServer.h
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#ifndef INCLUDED_FirstSwgDatabaseServer_H
#define INCLUDED_FirstSwgDatabaseServer_H
// ======================================================================
#include "sharedFoundation/FirstSharedFoundation.h"
#include "sharedDebug/FirstSharedDebug.h"
#include "sharedMemoryManager/FirstSharedMemoryManager.h"
#include "sharedFoundation/NetworkIdArchive.h"
#ifdef _WIN32
#pragma warning(disable: 4100) // unreferenced formal parameter
#endif
// ======================================================================
#endif
@@ -0,0 +1,57 @@
// ======================================================================
//
// MiscPack.cpp
// copyright (c) 2001 Sony Online Entertainment
//
// Defines various packing and unpacking functions needed for SwgDatabaseServer
//
// ======================================================================
#include "SwgDatabaseServer/FirstSwgDatabaseServer.h"
#include "serverUtility/MissionLocation.h"
#include "sharedDatabaseInterface/Bindable.h"
#include "sharedDatabaseInterface/BindableNetworkId.h"
#include "sharedDatabaseInterface/BufferString.h"
// ======================================================================
void MissionLocation::unpackFromDatabase(const DB::BindableDouble &x,const DB::BindableDouble &y, const DB::BindableDouble &z, const DB::BindableString<500> &planet, const DB::BindableString<500> &region_name, const DB::BindableNetworkId &cellId)
{
x.getValue(coordinates.x);
y.getValue(coordinates.y);
z.getValue(coordinates.z);
planet.getValue(planetName);
region_name.getValue(regionName);
cellId.getValue(cell);
}
// ----------------------------------------------------------------------
void MissionLocation::packToDatabase(DB::BindableDouble &x,DB::BindableDouble &y, DB::BindableDouble &z, DB::BindableString<500> &planet, DB::BindableString<500> &region_name, DB::BindableNetworkId &cellId) const
{
x.setValue(coordinates.x);
y.setValue(coordinates.y);
z.setValue(coordinates.z);
planet.setValue(planetName);
region_name.setValue(regionName);
cellId.setValue(cell);
}
// ----------------------------------------------------------------------
void StringId::unpackFromDatabase(const DB::BufferString &table, const DB::BufferString &text)
{
table.getValue(m_table);
text.getValue(m_text);
}
// ----------------------------------------------------------------------
void StringId::packToDatabase(DB::BufferString &table, DB::BufferString &text) const
{
table.setValue(m_table);
text.setValue(m_text);
}
// ======================================================================
@@ -0,0 +1,174 @@
// ======================================================================
//
// ObjvarNameManager.cpp
// copyright (c) 2003 Sony Online Entertainment
//
// ======================================================================
#include "SwgDatabaseServer/FirstSwgDatabaseServer.h"
#include "ObjvarNameManager.h"
#include "SwgDatabaseServer/TaskSaveObjvarNames.h"
#include "sharedFoundation/ExitChain.h"
#include <hash_map>
#include <string>
#include <vector>
// ======================================================================
ObjvarNameManager * ObjvarNameManager::ms_instance = NULL;
ObjvarNameManager * ObjvarNameManager::ms_goldInstance = NULL;
// ======================================================================
void ObjvarNameManager::install()
{
DEBUG_FATAL(ms_instance,("Installed ObjvarNameManager twice.\n"));
ExitChain::add(remove,"ObjvarNameManager::remove");
ms_instance = new ObjvarNameManager;
ms_goldInstance = new ObjvarNameManager;
}
// ----------------------------------------------------------------------
void ObjvarNameManager::remove()
{
NOT_NULL(ms_instance);
delete ms_instance;
ms_instance = NULL;
NOT_NULL(ms_goldInstance);
delete ms_goldInstance;
ms_goldInstance = NULL;
}
// ----------------------------------------------------------------------
ObjvarNameManager::ObjvarNameManager() :
m_nameToIdMap(new NameToIdMapType),
m_idToNameMap(new IdToNameMapType),
m_newNames(new NewNamesType),
m_nextAvailableId(0),
m_namesLoaded(false)
{
}
// ----------------------------------------------------------------------
ObjvarNameManager::~ObjvarNameManager()
{
DEBUG_FATAL(!m_newNames->empty(),("Database server was shut down without allowing all object variable names to be saved."));
delete m_nameToIdMap;
delete m_idToNameMap;
delete m_newNames;
m_nameToIdMap=NULL;
m_idToNameMap=NULL;
m_newNames=NULL;
}
// ----------------------------------------------------------------------
int ObjvarNameManager::getNameId(const std::string &name) const
{
DEBUG_FATAL(!m_namesLoaded,("Programmer bug: Attempted to look up object variable names before all were loaded."));
NameToIdMapType::const_iterator i=m_nameToIdMap->find(name);
if (i!=m_nameToIdMap->end())
return i->second;
else
return 0;
}
// ----------------------------------------------------------------------
/**
* Lookup a name in the map. Add the name if it isn't already in use.
*/
int ObjvarNameManager::getOrAddNameId (const std::string &name)
{
DEBUG_FATAL(!m_namesLoaded,("Programmer bug: Attempted to look up object variable names before all were loaded."));
int id=getNameId(name);
if (id!=0)
return id;
else
{
id = m_nextAvailableId++;
(*m_nameToIdMap)[name]=id;
(*m_idToNameMap)[id]=name;
m_newNames->push_back(std::make_pair(id, name));
return id;
}
}
// ----------------------------------------------------------------------
/**
* Lookup a name in the map.
*/
bool ObjvarNameManager::getName(int id, std::string &name) const
{
DEBUG_FATAL(!m_namesLoaded,("Programmer bug: Attempted to look up object variable names before all were loaded."));
IdToNameMapType::const_iterator i=m_idToNameMap->find(id);
if (i!=m_idToNameMap->end())
{
name = i->second;
return true;
}
else
return false;
}
// ----------------------------------------------------------------------
/**
* Add a name to the map, e.g. when loaded from the database
*/
void ObjvarNameManager::addNameMapping (int id, const std::string &name)
{
NameToIdMapType::iterator i=m_nameToIdMap->find(name);
if (i!=m_nameToIdMap->end())
{
int lower=std::min(id, i->second);
DEBUG_REPORT_LOG(true,("Objvar name %s is duplicated in the database. Ids are %i and %i. Using %i for this name\n", name.c_str(), id, i->second, lower));
i->second = lower;
}
else
(*m_nameToIdMap)[name]=id;
(*m_idToNameMap)[id]=name;
if (id >= m_nextAvailableId)
m_nextAvailableId = id+1;
}
// ----------------------------------------------------------------------
void ObjvarNameManager::allNamesLoaded()
{
m_namesLoaded=true;
if (m_nextAvailableId==0)
m_nextAvailableId=1; // start with 1 if there are no names in the database. 0 is reserved for "invalid name"
}
// ----------------------------------------------------------------------
/**
* Make a CustomPersistStep to save all the new names to the database.
*/
DB::TaskRequest *ObjvarNameManager::saveNewNames()
{
if (!m_newNames->empty())
{
DB::TaskRequest *task = new TaskSaveObjvarNames(*m_newNames);
m_newNames->clear();
return task;
}
else
return NULL;
}
// ======================================================================
@@ -0,0 +1,77 @@
// ======================================================================
//
// ObjvarNameManager.h
// copyright (c) 2003 Sony Online Entertainment
//
// ======================================================================
#ifndef INCLUDED_ObjvarNameManager_H
#define INCLUDED_ObjvarNameManager_H
// ======================================================================
namespace DB
{
class TaskRequest;
}
// ======================================================================
class ObjvarNameManager
{
public:
static void install();
static ObjvarNameManager &getInstance();
static ObjvarNameManager &getGoldInstance();
public:
int getOrAddNameId(const std::string &name);
int getNameId(const std::string &name) const;
bool getName(int id, std::string &name) const;
void addNameMapping(int id, const std::string &name);
void allNamesLoaded();
DB::TaskRequest *saveNewNames();
private:
typedef stdhash_map<std::string, int>::fwd NameToIdMapType;
NameToIdMapType *m_nameToIdMap;
typedef stdhash_map<int, std::string>::fwd IdToNameMapType;
IdToNameMapType *m_idToNameMap;
typedef stdvector<std::pair<int, std::string> >::fwd NewNamesType;
NewNamesType *m_newNames;
int m_nextAvailableId;
bool m_namesLoaded;
private:
static void remove();
ObjvarNameManager();
~ObjvarNameManager();
private:
static ObjvarNameManager *ms_instance;
static ObjvarNameManager *ms_goldInstance;
};
// ======================================================================
inline ObjvarNameManager &ObjvarNameManager::getInstance()
{
NOT_NULL(ms_instance);
return *ms_instance;
}
// ----------------------------------------------------------------------
inline ObjvarNameManager &ObjvarNameManager::getGoldInstance()
{
NOT_NULL(ms_goldInstance);
return *ms_goldInstance;
}
// ======================================================================
#endif
@@ -0,0 +1,290 @@
// ======================================================================
//
// SwgDatabaseServer.cpp
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#include "SwgDatabaseServer/FirstSwgDatabaseServer.h"
#include "SwgDatabaseServer.h"
#include "SwgDatabaseServer/DataCleanupManager.h"
#include "SwgDatabaseServer/ObjvarNameManager.h"
#include "SwgDatabaseServer/SwgLoader.h"
#include "SwgDatabaseServer/SwgPersister.h"
#include "serverDatabase/ConfigServerDatabase.h"
#include "serverDatabase/DataLookup.h"
#include "serverDatabase/LazyDeleter.h"
#include "serverDatabase/MessageToManager.h"
#include "SwgDatabaseServer/CMLoader.h"
#include "serverMetrics/MetricsData.h"
#include "sharedLog/Log.h"
#include "SwgSnapshot.h"
#include "../queries/CommoditiesSchema.h"
#include "../tasks/TaskLoadObjvarNames.h"
#include "sharedFoundation/Os.h"
// ======================================================================
void SwgDatabaseServer::install()
{
DatabaseProcess::installDerived(new SwgDatabaseServer);
}
// ----------------------------------------------------------------------
SwgDatabaseServer::SwgDatabaseServer() :
DatabaseProcess()
{
}
// ----------------------------------------------------------------------
SwgDatabaseServer::~SwgDatabaseServer()
{
}
// ----------------------------------------------------------------------
void SwgDatabaseServer::run()
{
SwgPersister::install();
SwgLoader::install();
DataLookup::install();
LazyDeleter::install();
ObjvarNameManager::install();
MessageToManager::install();
CMLoader::install();
setupSwgMetrics(); // Game specific metrics
DataCleanupManager cleanupManager;
cleanupManager.runDailyCleanup();
DatabaseProcess::run();
}
// ----------------------------------------------------------------------
void SwgDatabaseServer::frameTick()
{
tickSwgMetrics();
}
// ----------------------------------------------------------------------
/**
* This function is needed to be able to use callbackWithExceptionHandling()
*/
void SwgDatabaseServer::runStatic()
{
getInstance().run();
}
// ----------------------------------------------------------------------
void SwgDatabaseServer::setupSwgMetrics()
{
MetricsData* p_met = MetricsData::getInstance();
if ( p_met )
{
m_metricTableBufferBattlefieldMarkerObjectBufferCreated = p_met->addMetric("Buffers.Created.BattlefieldMarkerObjectBuffer");
m_metricTableBufferBattlefieldMarkerObjectBufferActive = p_met->addMetric("Buffers.Active.BattlefieldMarkerObjectBuffer");
m_metricTableBufferBuildingObjectBufferCreated = p_met->addMetric("Buffers.Created.BuildingObjectBuffer");
m_metricTableBufferBuildingObjectBufferActive = p_met->addMetric("Buffers.Active.BuildingObjectBuffer");
m_metricTableBufferCellObjectBufferCreated = p_met->addMetric("Buffers.Created.CellObjectBuffer");
m_metricTableBufferCellObjectBufferActive = p_met->addMetric("Buffers.Active.CellObjectBuffer");
m_metricTableBufferCityObjectBufferCreated = p_met->addMetric("Buffers.Created.CityObjectBuffer");
m_metricTableBufferCityObjectBufferActive = p_met->addMetric("Buffers.Active.CityObjectBuffer");
m_metricTableBufferCreatureObjectBufferCreated = p_met->addMetric("Buffers.Created.CreatureObjectBuffer");
m_metricTableBufferCreatureObjectBufferActive = p_met->addMetric("Buffers.Active.CreatureObjectBuffer");
m_metricTableBufferFactoryObjectBufferCreated = p_met->addMetric("Buffers.Created.FactoryObjectBuffer");
m_metricTableBufferFactoryObjectBufferActive = p_met->addMetric("Buffers.Active.FactoryObjectBuffer");
m_metricTableBufferGuildObjectBufferCreated = p_met->addMetric("Buffers.Created.GuildObjectBuffer");
m_metricTableBufferGuildObjectBufferActive = p_met->addMetric("Buffers.Active.GuildObjectBuffer");
m_metricTableBufferHarvesterInstallationObjectBufferCreated = p_met->addMetric("Buffers.Created.HarvesterInstallationObjectBuffer");
m_metricTableBufferHarvesterInstallationObjectBufferActive = p_met->addMetric("Buffers.Active.HarvesterInstallationObjectBuffer");
m_metricTableBufferInstallationObjectBufferCreated = p_met->addMetric("Buffers.Created.InstallationObjectBuffer");
m_metricTableBufferInstallationObjectBufferActive = p_met->addMetric("Buffers.Active.InstallationObjectBuffer");
m_metricTableBufferIntangibleObjectBufferCreated = p_met->addMetric("Buffers.Created.IntangibleObjectBuffer");
m_metricTableBufferIntangibleObjectBufferActive = p_met->addMetric("Buffers.Active.IntangibleObjectBuffer");
m_metricTableBufferManufactureInstallationObjectBufferCreated = p_met->addMetric("Buffers.Created.ManufactureInstallationObjectBuffer");
m_metricTableBufferManufactureInstallationObjectBufferActive = p_met->addMetric("Buffers.Active.ManufactureInstallationObjectBuffer");
m_metricTableBufferManufactureSchematicObjectBufferCreated = p_met->addMetric("Buffers.Created.ManufactureSchematicObjectBuffer");
m_metricTableBufferManufactureSchematicObjectBufferActive = p_met->addMetric("Buffers.Active.ManufactureSchematicObjectBuffer");
m_metricTableBufferMissionObjectBufferCreated = p_met->addMetric("Buffers.Created.MissionObjectBuffer");
m_metricTableBufferMissionObjectBufferActive = p_met->addMetric("Buffers.Active.MissionObjectBuffer");
m_metricTableBufferObjectTableBufferCreated = p_met->addMetric("Buffers.Created.ObjectTableBuffer");
m_metricTableBufferObjectTableBufferActive = p_met->addMetric("Buffers.Active.ObjectTableBuffer");
m_metricTableBufferPlanetObjectBufferCreated = p_met->addMetric("Buffers.Created.PlanetObjectBuffer");
m_metricTableBufferPlanetObjectBufferActive = p_met->addMetric("Buffers.Active.PlanetObjectBuffer");
m_metricTableBufferPlayerObjectBufferCreated = p_met->addMetric("Buffers.Created.PlayerObjectBuffer");
m_metricTableBufferPlayerObjectBufferActive = p_met->addMetric("Buffers.Active.PlayerObjectBuffer");
m_metricTableBufferResourceContainerObjectBufferCreated = p_met->addMetric("Buffers.Created.ResourceContainerObjectBuffer");
m_metricTableBufferResourceContainerObjectBufferActive = p_met->addMetric("Buffers.Active.ResourceContainerObjectBuffer");
m_metricTableBufferShipObjectBufferCreated = p_met->addMetric("Buffers.Created.ShipObjectBuffer");
m_metricTableBufferShipObjectBufferActive = p_met->addMetric("Buffers.Active.ShipObjectBuffer");
m_metricTableBufferStaticObjectBufferCreated = p_met->addMetric("Buffers.Created.StaticObjectBuffer");
m_metricTableBufferStaticObjectBufferActive = p_met->addMetric("Buffers.Active.StaticObjectBuffer");
m_metricTableBufferTangibleObjectBufferCreated = p_met->addMetric("Buffers.Created.TangibleObjectBuffer");
m_metricTableBufferTangibleObjectBufferActive = p_met->addMetric("Buffers.Active.TangibleObjectBuffer");
m_metricTableBufferUniverseObjectBufferCreated = p_met->addMetric("Buffers.Created.UniverseObjectBuffer");
m_metricTableBufferUniverseObjectBufferActive = p_met->addMetric("Buffers.Active.UniverseObjectBuffer");
m_metricTableBufferVehicleObjectBufferCreated = p_met->addMetric("Buffers.Created.VehicleObjectBuffer");
m_metricTableBufferVehicleObjectBufferActive = p_met->addMetric("Buffers.Active.VehicleObjectBuffer");
m_metricTableBufferWeaponObjectBufferCreated = p_met->addMetric("Buffers.Created.WeaponObjectBuffer");
m_metricTableBufferWeaponObjectBufferActive = p_met->addMetric("Buffers.Active.WeaponObjectBuffer");
// Auction Metrics
m_metricAuctionLocationsRowCreated = p_met->addMetric("CBuffers.Created.AuctionLocationsRow");
m_metricAuctionLocationsRowActive = p_met->addMetric("CBuffers.Active.AuctionLocationsRow");
m_metricMarketAuctionsRowCreated = p_met->addMetric("CBuffers.Created.MarketAuctionsRow");
m_metricMarketAuctionsRowActive = p_met->addMetric("CBuffers.Active.MarketAuctionsRow");
m_metricMarketAuctionBidsRowCreated = p_met->addMetric("CBuffers.Created.MarketAuctionBidsRow");
m_metricMarketAuctionBidsRowActive = p_met->addMetric("CBuffers.Active.MarketAuctionBidsRow");
m_metricObjvarNameRowsActive = p_met->addMetric("ObjvarRowsActive" );
m_metricGoldObjvarNameRowsActive = p_met->addMetric("ObjvarGoldRowsActive" );
}
else
{
LOG("SwgDatabaseServer::setupSwgMetrics", ("Metrics create FAILED!" ));
}
}
// ----------------------------------------------------------------------
void SwgDatabaseServer::tickSwgMetrics()
{
//return;
static time_t st_lastTime = 0;
if ( time(0) == st_lastTime )
return;
st_lastTime=time(0);
MetricsData* p_met = MetricsData::getInstance();
if ( p_met == 0 )
return;
p_met->updateMetric( m_metricTableBufferBattlefieldMarkerObjectBufferCreated, BattlefieldMarkerObjectBuffer::getRowsCreated() );
p_met->updateMetric( m_metricTableBufferBattlefieldMarkerObjectBufferActive, BattlefieldMarkerObjectBuffer::getRowsActive() );
p_met->updateMetric( m_metricTableBufferBuildingObjectBufferCreated, BuildingObjectBuffer::getRowsCreated() );
p_met->updateMetric( m_metricTableBufferBuildingObjectBufferActive, BuildingObjectBuffer::getRowsActive() );
p_met->updateMetric( m_metricTableBufferCellObjectBufferCreated, CellObjectBuffer::getRowsCreated() );
p_met->updateMetric( m_metricTableBufferCellObjectBufferActive, CellObjectBuffer::getRowsActive() );
p_met->updateMetric( m_metricTableBufferCityObjectBufferCreated, CityObjectBuffer::getRowsCreated() );
p_met->updateMetric( m_metricTableBufferCityObjectBufferActive, CityObjectBuffer::getRowsActive() );
p_met->updateMetric( m_metricTableBufferCreatureObjectBufferCreated, CreatureObjectBuffer::getRowsCreated() );
p_met->updateMetric( m_metricTableBufferCreatureObjectBufferActive, CreatureObjectBuffer::getRowsActive() );
p_met->updateMetric( m_metricTableBufferFactoryObjectBufferCreated, FactoryObjectBuffer::getRowsCreated() );
p_met->updateMetric( m_metricTableBufferFactoryObjectBufferActive, FactoryObjectBuffer::getRowsActive() );
p_met->updateMetric( m_metricTableBufferGuildObjectBufferCreated, GuildObjectBuffer::getRowsCreated() );
p_met->updateMetric( m_metricTableBufferGuildObjectBufferActive, GuildObjectBuffer::getRowsActive() );
p_met->updateMetric( m_metricTableBufferHarvesterInstallationObjectBufferCreated, HarvesterInstallationObjectBuffer::getRowsCreated() );
p_met->updateMetric( m_metricTableBufferHarvesterInstallationObjectBufferActive, HarvesterInstallationObjectBuffer::getRowsActive() );
p_met->updateMetric( m_metricTableBufferInstallationObjectBufferCreated, InstallationObjectBuffer::getRowsCreated() );
p_met->updateMetric( m_metricTableBufferInstallationObjectBufferActive, InstallationObjectBuffer::getRowsActive() );
p_met->updateMetric( m_metricTableBufferIntangibleObjectBufferCreated, IntangibleObjectBuffer::getRowsCreated() );
p_met->updateMetric( m_metricTableBufferIntangibleObjectBufferActive, IntangibleObjectBuffer::getRowsActive() );
p_met->updateMetric( m_metricTableBufferManufactureInstallationObjectBufferCreated, ManufactureInstallationObjectBuffer::getRowsCreated() );
p_met->updateMetric( m_metricTableBufferManufactureInstallationObjectBufferActive, ManufactureInstallationObjectBuffer::getRowsActive() );
p_met->updateMetric( m_metricTableBufferManufactureSchematicObjectBufferCreated, ManufactureSchematicObjectBuffer::getRowsCreated() );
p_met->updateMetric( m_metricTableBufferManufactureSchematicObjectBufferActive, ManufactureSchematicObjectBuffer::getRowsActive() );
p_met->updateMetric( m_metricTableBufferMissionObjectBufferCreated, MissionObjectBuffer::getRowsCreated() );
p_met->updateMetric( m_metricTableBufferMissionObjectBufferActive, MissionObjectBuffer::getRowsActive() );
p_met->updateMetric( m_metricTableBufferObjectTableBufferCreated, ObjectTableBuffer::getRowsCreated() );
p_met->updateMetric( m_metricTableBufferObjectTableBufferActive, ObjectTableBuffer::getRowsActive() );
p_met->updateMetric( m_metricTableBufferPlanetObjectBufferCreated, PlanetObjectBuffer::getRowsCreated() );
p_met->updateMetric( m_metricTableBufferPlanetObjectBufferActive, PlanetObjectBuffer::getRowsActive() );
p_met->updateMetric( m_metricTableBufferPlayerObjectBufferCreated, PlayerObjectBuffer::getRowsCreated() );
p_met->updateMetric( m_metricTableBufferPlayerObjectBufferActive, PlayerObjectBuffer::getRowsActive() );
p_met->updateMetric( m_metricTableBufferResourceContainerObjectBufferCreated, ResourceContainerObjectBuffer::getRowsCreated() );
p_met->updateMetric( m_metricTableBufferResourceContainerObjectBufferActive, ResourceContainerObjectBuffer::getRowsActive() );
p_met->updateMetric( m_metricTableBufferShipObjectBufferCreated, ShipObjectBuffer::getRowsCreated() );
p_met->updateMetric( m_metricTableBufferShipObjectBufferActive, ShipObjectBuffer::getRowsActive() );
p_met->updateMetric( m_metricTableBufferStaticObjectBufferCreated, StaticObjectBuffer::getRowsCreated() );
p_met->updateMetric( m_metricTableBufferStaticObjectBufferActive, StaticObjectBuffer::getRowsActive() );
p_met->updateMetric( m_metricTableBufferTangibleObjectBufferCreated, TangibleObjectBuffer::getRowsCreated() );
p_met->updateMetric( m_metricTableBufferTangibleObjectBufferActive, TangibleObjectBuffer::getRowsActive() );
p_met->updateMetric( m_metricTableBufferUniverseObjectBufferCreated, UniverseObjectBuffer::getRowsCreated() );
p_met->updateMetric( m_metricTableBufferUniverseObjectBufferActive, UniverseObjectBuffer::getRowsActive() );
p_met->updateMetric( m_metricTableBufferVehicleObjectBufferCreated, VehicleObjectBuffer::getRowsCreated() );
p_met->updateMetric( m_metricTableBufferVehicleObjectBufferActive, VehicleObjectBuffer::getRowsActive() );
p_met->updateMetric( m_metricTableBufferWeaponObjectBufferCreated, WeaponObjectBuffer::getRowsCreated() );
p_met->updateMetric( m_metricTableBufferWeaponObjectBufferActive, WeaponObjectBuffer::getRowsActive() );
// Auction metrics
p_met->updateMetric( m_metricAuctionLocationsRowCreated, DBSchema::AuctionLocationsRow::getRowsCreated() );
p_met->updateMetric( m_metricAuctionLocationsRowActive, DBSchema::AuctionLocationsRow::getRowsActive() );
p_met->updateMetric( m_metricMarketAuctionsRowCreated, DBSchema::MarketAuctionsRow::getRowsCreated() );
p_met->updateMetric( m_metricMarketAuctionsRowActive, DBSchema::MarketAuctionsRow::getRowsActive() );
p_met->updateMetric( m_metricMarketAuctionBidsRowCreated, DBSchema::MarketAuctionBidsRow::getRowsCreated() );
p_met->updateMetric( m_metricMarketAuctionBidsRowActive, DBSchema::MarketAuctionBidsRow::getRowsActive() );
// Objvars
p_met->updateMetric( m_metricObjvarNameRowsActive, TaskLoadObjvarNames::getObjvarNamesCount() );
p_met->updateMetric( m_metricGoldObjvarNameRowsActive, TaskLoadObjvarNames::getGoldObjvarNamesCount() );
}
// ======================================================================
@@ -0,0 +1,119 @@
// ======================================================================
//
// SwgDatabaseServer.h
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#ifndef INCLUDED_SwgDatabaseServer_H
#define INCLUDED_SwgDatabaseServer_H
#include "serverDatabase/DatabaseProcess.h"
// ======================================================================
class SwgDatabaseServer : public DatabaseProcess
{
public:
static void install();
virtual void run();
static void runStatic();
virtual void frameTick();
void setupSwgMetrics();
void tickSwgMetrics();
private:
SwgDatabaseServer();
virtual ~SwgDatabaseServer();
public:
int m_metricTableBufferBattlefieldMarkerObjectBufferCreated;
int m_metricTableBufferBattlefieldMarkerObjectBufferActive;
int m_metricTableBufferBuildingObjectBufferCreated;
int m_metricTableBufferBuildingObjectBufferActive;
int m_metricTableBufferCellObjectBufferCreated;
int m_metricTableBufferCellObjectBufferActive;
int m_metricTableBufferCityObjectBufferCreated;
int m_metricTableBufferCityObjectBufferActive;
int m_metricTableBufferCreatureObjectBufferCreated;
int m_metricTableBufferCreatureObjectBufferActive;
int m_metricTableBufferFactoryObjectBufferCreated;
int m_metricTableBufferFactoryObjectBufferActive;
int m_metricTableBufferGuildObjectBufferCreated;
int m_metricTableBufferGuildObjectBufferActive;
int m_metricTableBufferHarvesterInstallationObjectBufferCreated;
int m_metricTableBufferHarvesterInstallationObjectBufferActive;
int m_metricTableBufferInstallationObjectBufferCreated;
int m_metricTableBufferInstallationObjectBufferActive;
int m_metricTableBufferIntangibleObjectBufferCreated;
int m_metricTableBufferIntangibleObjectBufferActive;
int m_metricTableBufferManufactureInstallationObjectBufferCreated;
int m_metricTableBufferManufactureInstallationObjectBufferActive;
int m_metricTableBufferManufactureSchematicObjectBufferCreated;
int m_metricTableBufferManufactureSchematicObjectBufferActive;
int m_metricTableBufferMissionObjectBufferCreated;
int m_metricTableBufferMissionObjectBufferActive;
int m_metricTableBufferObjectTableBufferCreated;
int m_metricTableBufferObjectTableBufferActive;
int m_metricTableBufferPlanetObjectBufferCreated;
int m_metricTableBufferPlanetObjectBufferActive;
int m_metricTableBufferPlayerObjectBufferCreated;
int m_metricTableBufferPlayerObjectBufferActive;
int m_metricTableBufferResourceContainerObjectBufferCreated;
int m_metricTableBufferResourceContainerObjectBufferActive;
int m_metricTableBufferShipObjectBufferCreated;
int m_metricTableBufferShipObjectBufferActive;
int m_metricTableBufferStaticObjectBufferCreated;
int m_metricTableBufferStaticObjectBufferActive;
int m_metricTableBufferTangibleObjectBufferCreated;
int m_metricTableBufferTangibleObjectBufferActive;
int m_metricTableBufferUniverseObjectBufferCreated;
int m_metricTableBufferUniverseObjectBufferActive;
int m_metricTableBufferVehicleObjectBufferCreated;
int m_metricTableBufferVehicleObjectBufferActive;
int m_metricTableBufferWeaponObjectBufferCreated;
int m_metricTableBufferWeaponObjectBufferActive;
// Auction metrics
int m_metricAuctionLocationsRowCreated;
int m_metricAuctionLocationsRowActive;
int m_metricMarketAuctionsRowCreated;
int m_metricMarketAuctionsRowActive;
int m_metricMarketAuctionBidsRowCreated;
int m_metricMarketAuctionBidsRowActive;
// Objvar
int m_metricObjvarNameRowsActive;
int m_metricGoldObjvarNameRowsActive;
};
// ======================================================================
#endif
@@ -0,0 +1,130 @@
// ======================================================================
//
// SwgLoader.cpp
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#include "SwgDatabaseServer/FirstSwgDatabaseServer.h"
#include "SwgLoader.h"
#include "SwgDatabaseServer/SwgLoaderSnapshotGroup.h"
#include "SwgDatabaseServer/TaskGetCharacters.h"
#include "SwgDatabaseServer/TaskLoadObjvarNames.h"
#include "SwgDatabaseServer/TaskLocateStructure.h"
#include "SwgDatabaseServer/TaskVerifyCharacter.h"
#include "serverDatabase/ConfigServerDatabase.h"
#include "serverDatabase/DatabaseProcess.h"
#include "sharedDatabaseInterface/DbTaskQueue.h"
#include "sharedDebug/Profiler.h"
// ======================================================================
void SwgLoader::install()
{
Loader::installDerived(new SwgLoader);
}
// ----------------------------------------------------------------------
SwgLoader::SwgLoader() :
Loader(),
m_pendingTaskVerifyCharacter(NULL),
m_loadingTaskVerifyCharacter(NULL),
m_verifyCharacterTaskQ(NULL)
{
m_verifyCharacterTaskQ = new DB::TaskQueue(1,DatabaseProcess::getInstance().getDBServer(),4);
}
// ----------------------------------------------------------------------
SwgLoader:: ~SwgLoader()
{
m_verifyCharacterTaskQ->cancel();
delete m_verifyCharacterTaskQ;
delete m_pendingTaskVerifyCharacter;
m_loadingTaskVerifyCharacter = 0; // owned by a db task queue, freed elsewhere
m_verifyCharacterTaskQ = 0;
}
// ----------------------------------------------------------------------
LoaderSnapshotGroup *SwgLoader::makeLoaderSnapshotGroup(uint32 processId)
{
PROFILER_AUTO_BLOCK_DEFINE("SwgLoader::makeLoaderSnapshotGroup");
return new SwgLoaderSnapshotGroup(processId);
}
// ----------------------------------------------------------------------
// /**
// * Called to request that the Loader get the list of characters for
// * an account and send them to central.
// */
// void SwgLoader::getCharacters(uint32 accountNumber)
// {
// TaskGetCharacters *task=new TaskGetCharacters(accountNumber);
// taskQ->asyncRequest(task);
// }
// ----------------------------------------------------------------------
/**
* Called to verify that a player can use a particular character,
* and to get location data needed for login.
*/
void SwgLoader::verifyCharacter(StationId suid, const NetworkId &characterId, const TransferCharacterData * transferCharacterData)
{
if (!m_pendingTaskVerifyCharacter)
{
if (ConfigServerDatabase::getEnableGoldDatabase())
m_pendingTaskVerifyCharacter = new TaskVerifyCharacter(DatabaseProcess::getInstance().getGoldSchemaQualifier());
else
{
static std::string nullSchema;
m_pendingTaskVerifyCharacter = new TaskVerifyCharacter(nullSchema);
}
}
m_pendingTaskVerifyCharacter->addCharacter(suid,characterId, transferCharacterData);
}
// ----------------------------------------------------------------------
void SwgLoader::update(real updateTime)
{
if (m_pendingTaskVerifyCharacter && !m_loadingTaskVerifyCharacter)
{
m_loadingTaskVerifyCharacter = m_pendingTaskVerifyCharacter;
m_pendingTaskVerifyCharacter = NULL;
m_verifyCharacterTaskQ->asyncRequest(m_loadingTaskVerifyCharacter);
}
m_verifyCharacterTaskQ->update(ConfigServerDatabase::getDefaultQueueUpdateTimeLimit());
Loader::update(updateTime);
}
// ----------------------------------------------------------------------
void SwgLoader::verifyCharacterFinished (TaskVerifyCharacter *task)
{
UNREF(task);
DEBUG_FATAL(task!=m_loadingTaskVerifyCharacter,("Programmer bug: wrong TaskVerifyCharacter finished.\n"));
m_loadingTaskVerifyCharacter = NULL;
}
// ----------------------------------------------------------------------
void SwgLoader::locateStructure(const NetworkId &structureId, const std::string whoRequested)
{
TaskLocateStructure *task = new TaskLocateStructure(structureId, whoRequested);
taskQ->asyncRequest(task);
}
// ----------------------------------------------------------------------
void SwgLoader::loadStartupData()
{
taskQ->asyncRequest(new TaskLoadObjvarNames);
}
// ======================================================================
@@ -0,0 +1,57 @@
// ======================================================================
//
// SwgLoader.h
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#ifndef INCLUDED_SwgLoader_H
#define INCLUDED_SwgLoader_H
// ======================================================================
#include "serverDatabase/Loader.h"
// ======================================================================
class TaskVerifyCharacter;
class TransferCharacterData;
// ======================================================================
/**
* Singleton that organizes and queues requests to load objects from the database.
*/
class SwgLoader : public Loader
{
public:
static void install();
public:
// virtual void getCharacters(uint32 accountNumber);
virtual void verifyCharacter(StationId suid, const NetworkId &id, const TransferCharacterData *);
virtual void update(real updateTime);
void verifyCharacterFinished (TaskVerifyCharacter *task);
virtual void locateStructure(const NetworkId &structureId, const std::string whoRequested);
private:
virtual LoaderSnapshotGroup *makeLoaderSnapshotGroup(uint32 processId);
virtual void loadStartupData();
private:
SwgLoader();
virtual ~SwgLoader();
SwgLoader(const SwgLoader &);
SwgLoader & operator = (const SwgLoader &);
private:
TaskVerifyCharacter *m_pendingTaskVerifyCharacter;
TaskVerifyCharacter *m_loadingTaskVerifyCharacter;
DB::TaskQueue *m_verifyCharacterTaskQ;
};
// ======================================================================
#endif
@@ -0,0 +1,33 @@
// ======================================================================
//
// SwgLoaderSnapshotGroup.cpp
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#include "SwgDatabaseServer/FirstSwgDatabaseServer.h"
#include "SwgLoaderSnapshotGroup.h"
#include "SwgDatabaseServer/SwgSnapshot.h"
// ======================================================================
SwgLoaderSnapshotGroup::SwgLoaderSnapshotGroup(uint32 requestingProcess) :
LoaderSnapshotGroup(requestingProcess, new SwgSnapshot(DB::ModeQuery::mode_SELECT, false))
{
}
// ----------------------------------------------------------------------
SwgLoaderSnapshotGroup::~SwgLoaderSnapshotGroup()
{
}
// ----------------------------------------------------------------------
Snapshot *SwgLoaderSnapshotGroup::makeGoldSnapshot()
{
return new SwgSnapshot(DB::ModeQuery::mode_SELECT, true);
}
// ======================================================================
@@ -0,0 +1,35 @@
// ======================================================================
//
// SwgLoaderSnapshotGroup.h
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#ifndef INCLUDED_SwgLoaderSnapshotGroup_H
#define INCLUDED_SwgLoaderSnapshotGroup_H
// ======================================================================
#include "serverDatabase/LoaderSnapshotGroup.h"
namespace DB
{
class Session;
}
class SwgSnapshot;
// ======================================================================
class SwgLoaderSnapshotGroup : public LoaderSnapshotGroup
{
public:
SwgLoaderSnapshotGroup(uint32 requestingProcess);
virtual ~SwgLoaderSnapshotGroup();
private:
virtual Snapshot *makeGoldSnapshot();
};
// ======================================================================
#endif
@@ -0,0 +1,123 @@
// ======================================================================
//
// SwgPersister.cpp
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#include "SwgDatabaseServer/FirstSwgDatabaseServer.h"
#include "SwgPersister.h"
#include "sharedDatabaseInterface/DbTaskQueue.h"
#include "serverDatabase/CMLoader.h"
#include "SwgDatabaseServer/CommoditiesSnapshot.h"
#include "SwgDatabaseServer/ObjvarNameManager.h"
#include "SwgDatabaseServer/SwgSnapshot.h"
#include "SwgDatabaseServer/TaskRestoreCharacter.h"
#include "SwgDatabaseServer/TaskRestoreHouse.h"
#include "SwgDatabaseServer/TaskUndeleteItem.h"
#include "SwgDatabaseServer/TaskMoveToPlayer.h"
// ======================================================================
void SwgPersister::install()
{
Persister::installDerived(new SwgPersister);
}
// ----------------------------------------------------------------------
SwgPersister::SwgPersister() :
Persister()
{
}
// ----------------------------------------------------------------------
SwgPersister::~SwgPersister()
{
}
// ----------------------------------------------------------------------
Snapshot *SwgPersister::makeSnapshot(DB::ModeQuery::Mode mode) const
{
return new SwgSnapshot(mode, false);
}
// ----------------------------------------------------------------------
Snapshot *SwgPersister::makeCommoditiesSnapshot(DB::ModeQuery::Mode mode) const
{
return new CommoditiesSnapshot(mode);
}
// ----------------------------------------------------------------------
void SwgPersister::startLoadCommodities()
{
CMLoader::getInstance().loadCommoditiesData();
}
// ----------------------------------------------------------------------
/**
* Save new object variable names, if necessary, then call the base class'
* startSave function.
*/
void SwgPersister::startSave()
{
DB::TaskRequest *req = ObjvarNameManager::getInstance().saveNewNames();
if (req)
taskQueue->asyncRequest(req);
Persister::startSave();
}
// ----------------------------------------------------------------------
void SwgPersister::restoreHouse(const NetworkId &houseId, const std::string &whoRequested)
{
TaskRestoreHouse *task = new TaskRestoreHouse (houseId, whoRequested);
taskQueue->asyncRequest(task);
}
// ----------------------------------------------------------------------
void SwgPersister::restoreCharacter(const NetworkId &characterId, const std::string &whoRequested)
{
TaskRestoreCharacter *task = new TaskRestoreCharacter (characterId, whoRequested);
taskQueue->asyncRequest(task);
}
// ----------------------------------------------------------------------
void SwgPersister::undeleteItem(const NetworkId &itemId, const std::string &whoRequested)
{
TaskUndeleteItem *task = new TaskUndeleteItem (itemId, whoRequested);
taskQueue->asyncRequest(task);
}
// ----------------------------------------------------------------------
void SwgPersister::moveToPlayer(const NetworkId &oid, const NetworkId &player, const std::string &whoRequested)
{
TaskMoveToPlayer *task = new TaskMoveToPlayer (oid, player, whoRequested);
taskQueue->asyncRequest(task);
}
// ----------------------------------------------------------------------
void SwgPersister::getMoneyFromOfflineObject(uint32 replyServer, NetworkId const & sourceObject, int amount, NetworkId const & replyTo, std::string const & successCallback, std::string const & failCallback, stdvector<int8>::fwd const & packedDictionary)
{
SwgSnapshot * snapshot=NULL;
if (hasDataForObject(sourceObject))
snapshot=safe_cast<SwgSnapshot*>(&getSnapshotForObject(sourceObject, 0));
else
snapshot=safe_cast<SwgSnapshot*>(&getSnapshotForServer(0));
snapshot->getMoneyFromOfflineObject(replyServer, sourceObject, amount, replyTo, successCallback, failCallback, packedDictionary);
}
// ======================================================================
@@ -0,0 +1,40 @@
// ======================================================================
//
// SwgPersister.h
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#ifndef INCLUDED_SwgPersister_H
#define INCLUDED_SwgPersister_H
#include "serverDatabase/Persister.h"
// ======================================================================
class SwgPersister : public Persister
{
public:
static void install();
private:
virtual Snapshot * makeSnapshot (DB::ModeQuery::Mode mode) const;
virtual Snapshot * makeCommoditiesSnapshot(DB::ModeQuery::Mode mode) const;
virtual void startLoadCommodities();
virtual void startSave();
virtual void restoreHouse(const NetworkId &houseId, const std::string &whoRequested);
virtual void restoreCharacter(const NetworkId &playerId, const std::string &whoRequested);
virtual void undeleteItem(const NetworkId &itemId, const std::string &whoRequested);
virtual void moveToPlayer(const NetworkId &oid, const NetworkId &player, const std::string &whoRequested);
virtual void getMoneyFromOfflineObject(uint32 replyServer, NetworkId const & sourceObject, int amount, NetworkId const & replyTo, std::string const & successCallback, std::string const & failCallback, stdvector<int8>::fwd const & packedDictionary);
private:
SwgPersister();
virtual ~SwgPersister();
SwgPersister(const SwgPersister &);
SwgPersister & operator = (const SwgPersister &);
};
// ======================================================================
#endif
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,459 @@
// ======================================================================
//
// SwgSnapshot.h
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#ifndef INCLUDED_SwgSnapshot_H
#define INCLUDED_SwgSnapshot_H
// ======================================================================
#include "Archive/ByteStream.h"
#include "serverDatabase/Snapshot.h"
#include "serverDatabase/TableBuffer.h"
#include "sharedFoundation/Tag.h"
#include "SwgDatabaseServer/BattlefieldParticipantBuffer.h"
#include "SwgDatabaseServer/BountyHunterTargetBuffer.h"
#include "SwgDatabaseServer/CreatureObjectBuffer.h"
#include "SwgDatabaseServer/ExperienceBuffer.h"
#include "SwgDatabaseServer/IndexedNetworkTableBuffer.h"
#include "SwgDatabaseServer/LocationBuffer.h"
#include "SwgDatabaseServer/ManufactureSchematicAttributeBuffer.h"
#include "SwgDatabaseServer/MessageBuffer.h"
#include "SwgDatabaseServer/ObjectQueries.h"
#include "SwgDatabaseServer/ObjectTableBuffer.h"
#include "SwgDatabaseServer/ObjvarBuffer.h"
#include "SwgDatabaseServer/PropertyListBuffer.h"
#include "SwgDatabaseServer/ResourceTypeBuffer.h"
#include "SwgDatabaseServer/Schema.h"
#include "SwgDatabaseServer/ScriptBuffer.h"
#include "SwgDatabaseServer/WaypointBuffer.h"
namespace DB
{
class Session;
}
class BatchBaselinesMessageData;
class BaselinesMessage;
class DeltasMessage;
class GameServerConnection;
class ImmediateDeleteCustomPersistStep;
class NetworkTableBuffer;
class OfflineMoneyCustomPersistStep;
class UpdateObjectPositionMessage;
typedef IndexedNetworkTableBuffer<DBSchema::BattlefieldMarkerObjectBufferRow, DBSchema::BattlefieldMarkerObjectRow, DBQuery::BattlefieldMarkerObjectQuery, DBQuery::BattlefieldMarkerObjectQuerySelect> BattlefieldMarkerObjectBuffer;
typedef IndexedNetworkTableBuffer<DBSchema::BuildingObjectBufferRow, DBSchema::BuildingObjectRow, DBQuery::BuildingObjectQuery, DBQuery::BuildingObjectQuerySelect> BuildingObjectBuffer;
typedef IndexedNetworkTableBuffer<DBSchema::CellObjectBufferRow, DBSchema::CellObjectRow, DBQuery::CellObjectQuery, DBQuery::CellObjectQuerySelect> CellObjectBuffer;
typedef IndexedNetworkTableBuffer<DBSchema::CityObjectBufferRow, DBSchema::CityObjectRow, DBQuery::CityObjectQuery, DBQuery::CityObjectQuerySelect> CityObjectBuffer;
typedef IndexedNetworkTableBuffer<DBSchema::FactoryObjectBufferRow, DBSchema::FactoryObjectRow, DBQuery::FactoryObjectQuery, DBQuery::FactoryObjectQuerySelect> FactoryObjectBuffer;
typedef IndexedNetworkTableBuffer<DBSchema::GuildObjectBufferRow, DBSchema::GuildObjectRow, DBQuery::GuildObjectQuery, DBQuery::GuildObjectQuerySelect> GuildObjectBuffer;
typedef IndexedNetworkTableBuffer<DBSchema::HarvesterInstallationObjectBufferRow, DBSchema::HarvesterInstallationObjectRow, DBQuery::HarvesterInstallationObjectQuery, DBQuery::HarvesterInstallationObjectQuerySelect> HarvesterInstallationObjectBuffer;
typedef IndexedNetworkTableBuffer<DBSchema::InstallationObjectBufferRow, DBSchema::InstallationObjectRow, DBQuery::InstallationObjectQuery, DBQuery::InstallationObjectQuerySelect> InstallationObjectBuffer;
typedef IndexedNetworkTableBuffer<DBSchema::IntangibleObjectBufferRow, DBSchema::IntangibleObjectRow, DBQuery::IntangibleObjectQuery, DBQuery::IntangibleObjectQuerySelect> IntangibleObjectBuffer;
typedef IndexedNetworkTableBuffer<DBSchema::ManufactureInstallationObjectBufferRow, DBSchema::ManufactureInstallationObjectRow, DBQuery::ManufactureInstallationObjectQuery, DBQuery::ManufactureInstallationObjectQuerySelect> ManufactureInstallationObjectBuffer;
typedef IndexedNetworkTableBuffer<DBSchema::ManufactureSchematicObjectBufferRow, DBSchema::ManufactureSchematicObjectRow, DBQuery::ManufactureSchematicObjectQuery, DBQuery::ManufactureSchematicObjectQuerySelect> ManufactureSchematicObjectBuffer;
typedef IndexedNetworkTableBuffer<DBSchema::MissionObjectBufferRow, DBSchema::MissionObjectRow, DBQuery::MissionObjectQuery, DBQuery::MissionObjectQuerySelect> MissionObjectBuffer;
typedef IndexedNetworkTableBuffer<DBSchema::PlanetObjectBufferRow, DBSchema::PlanetObjectRow, DBQuery::PlanetObjectQuery, DBQuery::PlanetObjectQuerySelect> PlanetObjectBuffer;
typedef IndexedNetworkTableBuffer<DBSchema::PlayerObjectBufferRow, DBSchema::PlayerObjectRow, DBQuery::PlayerObjectQuery, DBQuery::PlayerObjectQuerySelect> PlayerObjectBuffer;
typedef IndexedNetworkTableBuffer<DBSchema::ResourceContainerObjectBufferRow, DBSchema::ResourceContainerObjectRow, DBQuery::ResourceContainerObjectQuery, DBQuery::ResourceContainerObjectQuerySelect> ResourceContainerObjectBuffer;
typedef IndexedNetworkTableBuffer<DBSchema::ShipObjectBufferRow, DBSchema::ShipObjectRow, DBQuery::ShipObjectQuery, DBQuery::ShipObjectQuerySelect> ShipObjectBuffer;
typedef IndexedNetworkTableBuffer<DBSchema::StaticObjectBufferRow, DBSchema::StaticObjectRow, DBQuery::StaticObjectQuery, DBQuery::StaticObjectQuerySelect> StaticObjectBuffer;
typedef IndexedNetworkTableBuffer<DBSchema::TangibleObjectBufferRow, DBSchema::TangibleObjectRow, DBQuery::TangibleObjectQuery, DBQuery::TangibleObjectQuerySelect> TangibleObjectBuffer;
typedef IndexedNetworkTableBuffer<DBSchema::UniverseObjectBufferRow, DBSchema::UniverseObjectRow, DBQuery::UniverseObjectQuery, DBQuery::UniverseObjectQuerySelect> UniverseObjectBuffer;
typedef IndexedNetworkTableBuffer<DBSchema::VehicleObjectBufferRow, DBSchema::VehicleObjectRow, DBQuery::VehicleObjectQuery, DBQuery::VehicleObjectQuerySelect> VehicleObjectBuffer;
typedef IndexedNetworkTableBuffer<DBSchema::WeaponObjectBufferRow, DBSchema::WeaponObjectRow, DBQuery::WeaponObjectQuery, DBQuery::WeaponObjectQuerySelect> WeaponObjectBuffer;
typedef IndexedNetworkTableBuffer<DBSchema::PlayerQuestObjectBufferRow, DBSchema::PlayerQuestObjectRow, DBQuery::PlayerQuestObjectQuery, DBQuery::PlayerQuestObjectQuerySelect> PlayerQuestObjectBuffer;
// ======================================================================
/**
* A Snapshot customized to Star Wars Galaxies.
*
* @todo: there are a lot of public functions that could be made private
*/
class SwgSnapshot : public Snapshot
{
public:
SwgSnapshot(DB::ModeQuery::Mode mode, bool useGoldDatabase);
~SwgSnapshot();
// Network Functions:
virtual void handleUpdateObjectPosition(const UpdateObjectPositionMessage &message);
virtual void handleDeleteMessage (const NetworkId &objectID, int reasonCode, bool immediate, bool demandLoadedContainer, bool cascadeReason);
virtual void handleMessageTo (const MessageToPayload &data);
virtual void handleMessageToAck (const MessageToId &messageId);
virtual void handleAddResourceTypeMessage (AddResourceTypeMessage const & message);
virtual void handleBountyHunterTargetMessage (const BountyHunterTargetMessage &message);
virtual bool send (GameServerConnection *connection) const;
// Misc game-specific persistence
void getMoneyFromOfflineObject (uint32 replyServer, NetworkId const & sourceObject, int amount, NetworkId const & replyTo, std::string const & successCallback, std::string const & failCallback, stdvector<int8>::fwd const & packedDictionary);
// Saving and Loading:
virtual bool saveToDB(DB::Session *session);
virtual bool load (DB::Session *session);
virtual void saveCompleted ();
virtual void getWorldContainers (stdvector<NetworkId>::fwd &containers) const;
virtual void handleCommoditiesDataMessage(const MessageDispatch::MessageBase & message);
virtual void startLoadAfterSaveComplete();
// Functions for object creation:
virtual void newObject(NetworkId const & objectId, int templateId, Tag typeId);
void newBattlefieldMarkerObject (NetworkId const & objectId);
void newBuildingObject (NetworkId const & objectId);
void newCellObject (NetworkId const & objectId);
void newCityObject (NetworkId const & objectId);
void newCountingObject (NetworkId const & objectId);
void newCreatureObject (NetworkId const & objectId);
void newFactoryObject (NetworkId const & objectId);
void newGuildObject (NetworkId const & objectId);
void newHarvesterInstallationObject (NetworkId const & objectId);
void newInstallationObject (NetworkId const & objectId);
void newIntangibleObject (NetworkId const & objectId);
void newManufactureInstallationObject (NetworkId const & objectId);
void newManufactureSchematicObject (NetworkId const & objectId);
void newMissionObject (NetworkId const & objectId);
void newPlanetObject (NetworkId const & objectId);
void newPlayerObject (NetworkId const & objectId);
void newPlayerQuestObject (NetworkId const & objectId);
void newRegionCircleObject (NetworkId const & objectId);
void newRegionObject (NetworkId const & objectId);
void newRegionRectangleObject (NetworkId const & objectId);
void newResourceContainerObject (NetworkId const & objectId);
void newShipObject (NetworkId const & objectId);
void newStaticObject (NetworkId const & objectId);
void newTangibleObject (NetworkId const & objectId);
void newUniverseObject (NetworkId const & objectId);
void newVehicleObject (NetworkId const & objectId);
void newWeaponObject (NetworkId const & objectId);
// Functions for object loading:
// virtual void addObjectIdForLoad(NetworkId const & objectId);
void loadAttributes (DB::Session *session, NetworkId const & objectId);
void loadBattlefieldMarkerObject (DB::Session *session, NetworkId const & objectId);
void loadBuildingObject (DB::Session *session, NetworkId const & objectId);
void loadCellObject (DB::Session *session, NetworkId const & objectId);
void loadCityObject (DB::Session *session, NetworkId const & objectId);
void loadCommands (DB::Session *session, NetworkId const & objectId);
void loadCountingObject (DB::Session *session, NetworkId const & objectId);
void loadCreatureObject (DB::Session *session, NetworkId const & objectId);
void loadFactoryObject (DB::Session *session, NetworkId const & objectId);
void loadGuildObject (DB::Session *session, NetworkId const & objectId);
void loadHarvesterInstallationObject (DB::Session *session, NetworkId const & objectId);
void loadInstallationObject (DB::Session *session, NetworkId const & objectId);
void loadIntangibleObject (DB::Session *session, NetworkId const & objectId);
void loadManufactureInstallationObject (DB::Session *session, NetworkId const & objectId);
void loadManufactureSchematicObject (DB::Session *session, NetworkId const & objectId);
void loadMissionObject (DB::Session *session, NetworkId const & objectId);
void loadPlanetObject (DB::Session *session, NetworkId const & objectId);
void loadPlayerObject (DB::Session *session, NetworkId const & objectId);
void loadPlayerQuestObject (DB::Session *session, NetworkId const & objectId);
void loadRegionCircleObject (DB::Session *session, NetworkId const & objectId);
void loadRegionObject (DB::Session *session, NetworkId const & objectId);
void loadRegionRectangleObject (DB::Session *session, NetworkId const & objectId);
void loadResourceContainerObject (DB::Session *session, NetworkId const & objectId);
void loadSkills (DB::Session *session, NetworkId const & objectId);
void loadShipObject (DB::Session *session, NetworkId const & objectId);
void loadStaticObject (DB::Session *session, NetworkId const & objectId);
void loadTangibleObject (DB::Session *session, NetworkId const & objectId);
void loadUniverseObject (DB::Session *session, NetworkId const & objectId);
void loadVehicleObject (DB::Session *session, NetworkId const & objectId);
void loadWeaponObject (DB::Session *session, NetworkId const & objectId);
protected:
BattlefieldMarkerObjectBuffer m_battlefieldMarkerObjectBuffer;
BattlefieldParticipantBuffer m_battlefieldParticipantBuffer;
BountyHunterTargetBuffer m_bountyHunterTargetBuffer;
BuildingObjectBuffer m_buildingObjectBuffer;
CellObjectBuffer m_cellObjectBuffer;
CityObjectBuffer m_cityObjectBuffer;
CreatureObjectBuffer m_creatureObjectBuffer;
ExperienceBuffer m_experienceBuffer;
FactoryObjectBuffer m_factoryObjectBuffer;
GuildObjectBuffer m_guildObjectBuffer;
HarvesterInstallationObjectBuffer m_harvesterInstallationObjectBuffer;
InstallationObjectBuffer m_installationObjectBuffer;
IntangibleObjectBuffer m_intangibleObjectBuffer;
LocationBuffer m_locationBuffer;
ManufactureInstallationObjectBuffer m_manufactureInstallationObjectBuffer;
ManufactureSchematicAttributeBuffer m_manufactureSchematicAttributeBuffer;
ManufactureSchematicObjectBuffer m_manufactureSchematicObjectBuffer;
MessageBuffer m_messageBuffer;
MissionObjectBuffer m_missionObjectBuffer;
ObjectTableBuffer m_objectTableBuffer;
ObjvarBuffer m_objvarBuffer;
PlanetObjectBuffer m_planetObjectBuffer;
PlayerObjectBuffer m_playerObjectBuffer;
PlayerQuestObjectBuffer m_playerQuestObjectBuffer;
PropertyListBuffer m_propertyListBuffer;
ResourceContainerObjectBuffer m_resourceContainerObjectBuffer;
ResourceTypeBuffer m_resourceTypeBuffer;
ScriptBuffer m_scriptBuffer;
ShipObjectBuffer m_shipObjectBuffer;
StaticObjectBuffer m_staticObjectBuffer;
TangibleObjectBuffer m_tangibleObjectBuffer;
UniverseObjectBuffer m_universeObjectBuffer;
VehicleObjectBuffer m_vehicleObjectBuffer;
WaypointBuffer m_waypointBuffer;
WeaponObjectBuffer m_weaponObjectBuffer;
typedef std::vector<NetworkId> OIDListType;
// OIDListType m_oidList;
ImmediateDeleteCustomPersistStep *m_immediateDeleteStep;
OfflineMoneyCustomPersistStep *m_offlineMoneyCustomPersistStep;
private:
void registerTags();
void loadObject(DB::Session *session,const Tag &typeId, const NetworkId &objectId);
virtual void decodeServerData(NetworkId const & objectId, Tag typeId, uint16 index, Archive::ReadIterator &bs, bool isBaseline);
virtual void decodeSharedData(NetworkId const & objectId, Tag typeId, uint16 index, Archive::ReadIterator &bs, bool isBaseline);
virtual void decodeClientData(NetworkId const & objectId, Tag typeId, uint16 index, Archive::ReadIterator &bs, bool isBaseline);
virtual void decodeParentClientData(NetworkId const & objectId, Tag typeId, uint16 index, Archive::ReadIterator &bs, bool isBaseline);
virtual bool encodeParentClientData(NetworkId const & objectId, Tag typeId, stdvector<BatchBaselinesMessageData>::fwd &baselines) const;
virtual bool encodeClientData(NetworkId const & objectId, Tag typeId, stdvector<BatchBaselinesMessageData>::fwd &baselines) const;
virtual bool encodeServerData(NetworkId const & objectId, Tag typeId, stdvector<BatchBaselinesMessageData>::fwd &baselines) const;
virtual bool encodeSharedData(NetworkId const & objectId, Tag typeId, stdvector<BatchBaselinesMessageData>::fwd &baselines) const;
void decodeClientBattlefieldMarkerObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline);
void decodeClientBuildingObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline);
void decodeClientCellObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline);
void decodeClientCityObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline);
void decodeClientCreatureObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline);
void decodeClientGuildObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline);
void decodeClientHarvesterInstallationObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline);
void decodeClientInstallationObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline);
void decodeClientIntangibleObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline);
void decodeClientManufactureInstallationObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline);
void decodeClientMissionObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline);
void decodeClientPlanetObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline);
void decodeClientPlayerObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline);
void decodeClientPlayerQuestObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline);
void decodeClientRegionCircleObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline);
void decodeClientRegionObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline);
void decodeClientRegionRectangleObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline);
void decodeClientResourceContainerObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline);
void decodeClientServerObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline);
void decodeClientShipObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline);
void decodeClientStaticObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline);
void decodeClientTangibleObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline);
void decodeClientUniverseObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline);
void decodeClientVehicleObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline);
void decodeClientWeaponObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline);
void decodeServerBattlefieldMarkerObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline);
void decodeServerBuildingObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline);
void decodeServerCellObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline);
void decodeServerCityObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline);
void decodeServerCreatureObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline);
void decodeServerGuildObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline);
void decodeServerHarvesterInstallationObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline);
void decodeServerInstallationObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline);
void decodeServerIntangibleObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline);
void decodeServerManufactureInstallationObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline);
void decodeServerMissionObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline);
void decodeServerPlanetObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline);
void decodeServerPlayerObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline);
void decodeServerPlayerQuestObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline);
void decodeServerRegionCircleObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline);
void decodeServerRegionObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline);
void decodeServerRegionRectangleObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline);
void decodeServerResourceContainerObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline);
void decodeServerServerObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline);
void decodeServerShipObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline);
void decodeServerStaticObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline);
void decodeServerTangibleObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline);
void decodeServerUniverseObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline);
void decodeServerVehicleObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline);
void decodeServerWeaponObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline);
void decodeSharedBattlefieldMarkerObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline);
void decodeSharedBuildingObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline);
void decodeSharedCellObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline);
void decodeSharedCityObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline);
void decodeSharedCreatureObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline);
void decodeSharedGuildObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline);
void decodeSharedHarvesterInstallationObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline);
void decodeSharedInstallationObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline);
void decodeSharedIntangibleObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline);
void decodeSharedManufactureInstallationObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline);
void decodeSharedMissionObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline);
void decodeSharedPlanetObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline);
void decodeSharedPlayerObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline);
void decodeSharedPlayerQuestObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline);
void decodeSharedRegionCircleObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline);
void decodeSharedRegionObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline);
void decodeSharedRegionRectangleObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline);
void decodeSharedResourceContainerObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline);
void decodeSharedServerObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline);
void decodeSharedShipObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline);
void decodeSharedStaticObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline);
void decodeSharedTangibleObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline);
void decodeSharedUniverseObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline);
void decodeSharedVehicleObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline);
void decodeSharedWeaponObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline);
void decodeServerManufactureSchematicObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline);
void decodeClientManufactureSchematicObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline);
void decodeSharedManufactureSchematicObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline);
bool encodeServerManufactureSchematicObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const;
bool encodeClientManufactureSchematicObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const;
bool encodeSharedManufactureSchematicObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const;
void decodeSharedFactoryObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline);
void decodeServerFactoryObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline);
void decodeClientFactoryObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline);
bool encodeServerFactoryObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const;
bool encodeSharedFactoryObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const;
bool encodeClientFactoryObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const;
void decodeSharedCountingObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline);
void decodeServerCountingObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline);
void decodeClientCountingObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline);
bool encodeSharedCountingObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const;
bool encodeServerCountingObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const;
bool encodeClientCountingObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const;
bool encodeClientBattlefieldMarkerObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const;
bool encodeClientBuildingObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const;
bool encodeClientCellObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const;
bool encodeClientCityObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const;
bool encodeClientCreatureObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const;
bool encodeClientGuildObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const;
bool encodeClientHarvesterInstallationObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const;
bool encodeClientInstallationObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const;
bool encodeClientIntangibleObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const;
bool encodeClientManufactureInstallationObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const;
bool encodeClientMissionObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const;
bool encodeClientPlanetObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const;
bool encodeClientPlayerObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const;
bool encodeClientPlayerQuestObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const;
bool encodeClientRegionCircleObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const;
bool encodeClientRegionObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const;
bool encodeClientRegionRectangleObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const;
bool encodeClientResourceContainerObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const;
bool encodeClientServerObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const;
bool encodeClientShipObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const;
bool encodeClientStaticObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const;
bool encodeClientTangibleObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const;
bool encodeClientUniverseObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const;
bool encodeClientVehicleObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const;
bool encodeClientWeaponObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const;
bool encodeServerBattlefieldMarkerObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const;
bool encodeServerBuildingObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const;
bool encodeServerCellObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const;
bool encodeServerCityObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const;
bool encodeServerCreatureObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const;
bool encodeServerGuildObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const;
bool encodeServerHarvesterInstallationObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const;
bool encodeServerInstallationObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const;
bool encodeServerIntangibleObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const;
bool encodeServerManufactureInstallationObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const;
bool encodeServerMissionObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const;
bool encodeServerPlanetObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const;
bool encodeServerPlayerObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const;
bool encodeServerPlayerQuestObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const;
bool encodeServerRegionCircleObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const;
bool encodeServerRegionObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const;
bool encodeServerRegionRectangleObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const;
bool encodeServerResourceContainerObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const;
bool encodeServerServerObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const;
bool encodeServerShipObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const;
bool encodeServerStaticObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const;
bool encodeServerTangibleObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const;
bool encodeServerUniverseObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const;
bool encodeServerVehicleObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const;
bool encodeServerWeaponObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const;
bool encodeSharedBattlefieldMarkerObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const;
bool encodeSharedBuildingObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const;
bool encodeSharedCellObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const;
bool encodeSharedCityObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const;
bool encodeSharedCreatureObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const;
bool encodeSharedGuildObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const;
bool encodeSharedHarvesterInstallationObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const;
bool encodeSharedInstallationObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const;
bool encodeSharedIntangibleObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const;
bool encodeSharedManufactureInstallationObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const;
bool encodeSharedMissionObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const;
bool encodeSharedPlanetObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const;
bool encodeSharedPlayerObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const;
bool encodeSharedPlayerQuestObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const;
bool encodeSharedRegionCircleObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const;
bool encodeSharedRegionObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const;
bool encodeSharedRegionRectangleObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const;
bool encodeSharedResourceContainerObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const;
bool encodeSharedServerObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const;
bool encodeSharedShipObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const;
bool encodeSharedStaticObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const;
bool encodeSharedTangibleObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const;
bool encodeSharedUniverseObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const;
bool encodeSharedVehicleObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const;
bool encodeSharedWeaponObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const;
void decodeParentClientPlayerObject(NetworkId const & objectId, uint16 index, Archive::ReadIterator &data, bool isBaseline);
bool encodeParentClientPlayerObject(NetworkId const & objectId, Archive::ByteStream &data, bool addCount=true) const;
private:
void decodeAttributes (const NetworkId &objectId, Archive::ReadIterator &data, bool isBaseline, int offset);
void decodeBattlefieldParticipants(const NetworkId &objectId, Archive::ReadIterator &data, bool isBaseline);
void decodePropertyList (const NetworkId &objectId, int listId, Archive::ReadIterator &data, bool isBaseline);
void decodeExperience (const NetworkId &objectId, Archive::ReadIterator &data, bool isBaseline);
void decodeLocationDataList (const NetworkId &objectId, size_t listId, Archive::ReadIterator &data, bool isBaseline);
void decodeManufactureSchematicAttributes(const NetworkId &objectId, Archive::ReadIterator &data, bool isBaseline);
void decodeMissionLocation (Archive::ReadIterator &data, DB::BindableDouble &x,DB::BindableDouble &y, DB::BindableDouble &z, DB::BindableString<500> &planet, DB::BindableString<500> &region_name,DB::BindableNetworkId &cell) const;
void decodeObjVars (NetworkId const & objectId, Archive::ReadIterator &data, bool isBaseline);
void decodeObjVarFreeFlags (const NetworkId &objectId, Archive::ReadIterator &data, bool isBaseline);
void decodeScriptObject (NetworkId const & objectId, Archive::ReadIterator &data, bool isBaseline);
void decodeStringId (Archive::ReadIterator &data,DB::BufferString &table,DB::BufferString &text) const;
void decodeVector (Archive::ReadIterator &data, DB::BindableDouble &x,DB::BindableDouble &y, DB::BindableDouble &z) const;
void decodeMatchMakingId (Archive::ReadIterator &data, DB::BufferString &column) const;
void decodeComponents (NetworkId const & objectId, Archive::ReadIterator &data, bool isBaseline);
void decodeLocation (Archive::ReadIterator &data, DB::BindableDouble &x,DB::BindableDouble &y, DB::BindableDouble &z, DB::BindableNetworkId &cell, DB::BindableLong &planet) const;
void decodeWaypoints (const NetworkId &objectId, Archive::ReadIterator &data, bool isBaseline);
void decodeSingleWaypoint (const NetworkId &objectId, Archive::ReadIterator &data, bool isBaseline);
void decodeQuests (NetworkId const & networkId, Archive::ReadIterator &data, DB::BufferString &part1, DB::BufferString &part2, DB::BufferString &part3, DB::BufferString &part4) const;
void decodePersistedBuffs (Archive::ReadIterator &data, DB::BufferString &dbString) const;
void encodeAttributes (const NetworkId & objectId, Archive::ByteStream &data, int offset) const;
void encodeBattlefieldParticipants(const NetworkId &objectId, Archive::ByteStream &data) const;
void encodePropertyList (const NetworkId & objectId, int listId, Archive::ByteStream &data) const;
void encodeExperience (const NetworkId & objectId, Archive::ByteStream &data) const;
void encodeLocationDataList (const NetworkId & objectId, size_t listId, Archive::ByteStream &data) const;
void encodeManufactureSchematicAttributes(const NetworkId & objectId, Archive::ByteStream &data) const;
void encodeMissionLocation (Archive::ByteStream &data, const DB::BindableDouble &x,const DB::BindableDouble &y, const DB::BindableDouble &z, const DB::BindableString<500> &planet, const DB::BindableString<500> &region_name, const DB::BindableNetworkId &cell) const;
void encodeObjVars (const NetworkId & objectId, Archive::ByteStream &data) const;
void encodeObjVarFreeFlags (const NetworkId & objectId, Archive::ByteStream &data) const;
void encodeScriptObject (const NetworkId & objectId, Archive::ByteStream &data) const;
void encodeStringId (Archive::ByteStream &data, const DB::BufferString &table, const DB::BufferString &text) const;
void encodeVector (Archive::ByteStream &data, const DB::BindableDouble &x, const DB::BindableDouble &y, const DB::BindableDouble &z) const;
void encodeMatchMakingId (Archive::ByteStream &data, const DB::BufferString &column) const;
void encodeComponents (const NetworkId &objectId, Archive::ByteStream &data) const;
void encodeLocation (Archive::ByteStream &data, const DB::BindableDouble &x,const DB::BindableDouble &y, const DB::BindableDouble &z, const DB::BindableNetworkId &cell, const DB::BindableLong &planet) const;
void encodeWaypoints (const NetworkId & objectId, Archive::ByteStream &data) const;
void encodeSingleWaypoint (const NetworkId & objectId, Archive::ByteStream &data) const;
void encodeQuests (Archive::ByteStream &data, DB::BufferString const &part1, DB::BufferString const &part2, DB::BufferString const &part3, DB::BufferString const &part4) const;
void encodePersistedBuffs (Archive::ByteStream &data, DB::BufferString const& dbString) const;
void ignorePersistedFlag (const NetworkId &objectId, Archive::ReadIterator &data) const;
OfflineMoneyCustomPersistStep * SwgSnapshot::getOfflineMoneyCustomPersistStep();
private:
SwgSnapshot(const SwgSnapshot&); //disable
SwgSnapshot &operator=(const SwgSnapshot&); //disable
};
// ======================================================================
#endif
@@ -0,0 +1 @@
#include "../tasks/TaskGetAuctionAttributeList.h"
@@ -0,0 +1 @@
#include "../tasks/TaskGetAuctionList.h"
@@ -0,0 +1 @@
#include "../tasks/TaskGetBidList.h"
@@ -0,0 +1 @@
#include "../tasks/TaskGetLocationList.h"
@@ -0,0 +1,52 @@
// GENERATED CODE
// DO NOT EDIT THIS FILE
#include "SwgDatabaseServer/FirstSwgDatabaseServer.h"
#include "SwgDatabaseServer/SwgSnapshot.h"
#include "Archive/Archive.h"
#include "Archive/AutoDeltaPackedMap.h"
#include "sharedFoundation/AutoDeltaNetworkIdPackedMap.h"
#include "Archive/ByteStream.h"
#include "ObjectTableBuffer.h"
#include "Schema.h"
#include "ScriptBuffer.h"
#include "serverGame/ServerBattlefieldMarkerObjectTemplate.h"
#include "serverGame/ServerBuildingObjectTemplate.h"
#include "serverGame/ServerCellObjectTemplate.h"
#include "serverGame/ServerCityObjectTemplate.h"
#include "serverGame/ServerCreatureObjectTemplate.h"
#include "serverGame/ServerFactoryObjectTemplate.h"
#include "serverGame/ServerGuildObjectTemplate.h"
#include "serverGame/ServerHarvesterInstallationObjectTemplate.h"
#include "serverGame/ServerInstallationObjectTemplate.h"
#include "serverGame/ServerIntangibleObjectTemplate.h"
#include "serverGame/ServerManufactureInstallationObjectTemplate.h"
#include "serverGame/ServerManufactureSchematicObjectTemplate.h"
#include "serverGame/ServerMissionObjectTemplate.h"
#include "serverGame/ServerObjectTemplate.h"
#include "serverGame/ServerPlanetObjectTemplate.h"
#include "serverGame/ServerPlayerQuestObjectTemplate.h"
#include "serverGame/ServerPlayerObjectTemplate.h"
#include "serverGame/ServerResourceContainerObjectTemplate.h"
#include "serverGame/ServerShipObjectTemplate.h"
#include "serverGame/ServerStaticObjectTemplate.h"
#include "serverGame/ServerTangibleObjectTemplate.h"
#include "serverGame/ServerVehicleObjectTemplate.h"
#include "serverGame/ServerWeaponObjectTemplate.h"
#include "serverUtility/MissionLocation.h"
#include "sharedDatabaseInterface/NullEncodedUnicodeString.h"
#include "sharedDatabaseInterface/NullEncodedStandardString.h"
#include "sharedFoundation/StationId.h"
#include "sharedGame/Buff.h"
#include "sharedGame/PlayerQuestData.h"
#include "swgSharedUtility/Attributes.def"
#include "swgSharedUtility/Postures.def"
#include "unicodeArchive/UnicodeArchive.h"
// Auto-generated code has some warnings, but code is OK
#pragma warning(disable : 4065)
#pragma warning(disable : 4100)
//!!!BEGIN GENERATED DECODER
//!!!END GENERATED DECODER
@@ -0,0 +1,53 @@
// GENERATED CODE
// DO NOT EDIT THIS FILE
#include "SwgDatabaseServer/FirstSwgDatabaseServer.h"
#include "SwgDatabaseServer/SwgSnapshot.h"
#include "Archive/Archive.h"
#include "Archive/AutoDeltaPackedMap.h"
#include "Archive/ByteStream.h"
#include "ObjectTableBuffer.h"
#include "Schema.h"
#include "ScriptBuffer.h"
#include "serverDatabase/GameServerConnection.h"
#include "serverGame/ServerBattlefieldMarkerObjectTemplate.h"
#include "serverGame/ServerBuildingObjectTemplate.h"
#include "serverGame/ServerCellObjectTemplate.h"
#include "serverGame/ServerCityObjectTemplate.h"
#include "serverGame/ServerCreatureObjectTemplate.h"
#include "serverGame/ServerFactoryObjectTemplate.h"
#include "serverGame/ServerGuildObjectTemplate.h"
#include "serverGame/ServerHarvesterInstallationObjectTemplate.h"
#include "serverGame/ServerInstallationObjectTemplate.h"
#include "serverGame/ServerIntangibleObjectTemplate.h"
#include "serverGame/ServerManufactureInstallationObjectTemplate.h"
#include "serverGame/ServerManufactureSchematicObjectTemplate.h"
#include "serverGame/ServerMissionObjectTemplate.h"
#include "serverGame/ServerObjectTemplate.h"
#include "serverGame/ServerPlanetObjectTemplate.h"
#include "serverGame/ServerPlayerQuestObjectTemplate.h"
#include "serverGame/ServerPlayerObjectTemplate.h"
#include "serverGame/ServerResourceContainerObjectTemplate.h"
#include "serverGame/ServerShipObjectTemplate.h"
#include "serverGame/ServerStaticObjectTemplate.h"
#include "serverGame/ServerTangibleObjectTemplate.h"
#include "serverGame/ServerVehicleObjectTemplate.h"
#include "serverGame/ServerWeaponObjectTemplate.h"
#include "serverUtility/MissionLocation.h"
#include "sharedDatabaseInterface/NullEncodedUnicodeString.h"
#include "sharedDatabaseInterface/NullEncodedStandardString.h"
#include "sharedDebug/Profiler.h"
#include "sharedFoundation/StationId.h"
#include "sharedGame/Buff.h"
#include "sharedGame/PlayerQuestData.h"
#include "sharedNetworkMessages/BaselinesMessage.h"
#include "sharedNetworkMessages/BatchBaselinesMessage.h"
#include "swgSharedUtility/Attributes.def"
#include "swgSharedUtility/Postures.def"
#include "unicodeArchive/UnicodeArchive.h"
#include <string>
//!!!BEGIN GENERATED ENCODER
//!!!END GENERATED ENCODER
@@ -0,0 +1,31 @@
#include "SwgDatabaseServer/FirstSwgDatabaseServer.h"
#include "SwgDatabaseServer/SwgSnapshot.h"
#include "serverGame/ServerBattlefieldMarkerObjectTemplate.h"
#include "serverGame/ServerBuildingObjectTemplate.h"
#include "serverGame/ServerCellObjectTemplate.h"
#include "serverGame/ServerCityObjectTemplate.h"
#include "serverGame/ServerConstructionContractObjectTemplate.h"
#include "serverGame/ServerCreatureObjectTemplate.h"
#include "serverGame/ServerDraftSchematicObjectTemplate.h"
#include "serverGame/ServerFactoryObjectTemplate.h"
#include "serverGame/ServerGuildObjectTemplate.h"
#include "serverGame/ServerHarvesterInstallationObjectTemplate.h"
#include "serverGame/ServerInstallationObjectTemplate.h"
#include "serverGame/ServerManufactureInstallationObjectTemplate.h"
#include "serverGame/ServerManufactureSchematicObjectTemplate.h"
#include "serverGame/ServerMissionObjectTemplate.h"
#include "serverGame/ServerObjectTemplate.h"
#include "serverGame/ServerPlanetObjectTemplate.h"
#include "serverGame/ServerPlayerQuestObjectTemplate.h"
#include "serverGame/ServerPlayerObjectTemplate.h"
#include "serverGame/ServerResourceContainerObjectTemplate.h"
#include "serverGame/ServerShipObjectTemplate.h"
#include "serverGame/ServerStaticObjectTemplate.h"
#include "serverGame/ServerTangibleObjectTemplate.h"
#include "serverGame/ServerVehicleObjectTemplate.h"
#include "serverGame/ServerWeaponObjectTemplate.h"
//!!!BEGIN GENERATED LOADOBJECT
//!!!END GENERATED LOADOBJECT
@@ -0,0 +1,23 @@
#include "SwgDatabaseServer/FirstSwgDatabaseServer.h"
#include "ObjectQueries.h"
#include "SwgDatabaseServer/Schema.h"
#include "serverDatabase/DatabaseProcess.h"
using namespace DBQuery;
using namespace DBSchema;
// ======================================================================
namespace ObjectQueriesNamespace
{
const int ms_fetchBatchSize = 1000;
}
using namespace ObjectQueriesNamespace;
// ======================================================================
//!!!BEGIN GENERATED QUERYDEFINITIONS
//!!!END GENERATED QUERYDEFINITIONS
// ======================================================================
@@ -0,0 +1,34 @@
// ======================================================================
//
// ObjectQueries.h
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#ifndef INCLUDED_ObjectQueries_H
#define INCLUDED_ObjectQueries_H
// ======================================================================
#include "SwgDatabaseServer/Schema.h"
#include "serverDatabase/DatabaseProcessQuery.h"
#include "sharedDatabaseInterface/DbBindableVarray.h"
#include "sharedDatabaseInterface/DbModeQuery.h"
#include "sharedFoundation/NetworkId.h"
#include <vector>
// ======================================================================
namespace DBQuery
{
//!!!BEGIN GENERATED QUERYDECLARATIONS
//!!!END GENERATED QUERYDECLARATIONS
// ======================================================================
} // namespace
#endif
@@ -0,0 +1,258 @@
// ======================================================================
//
// Schema.h
// copyright (c) 2001 Sony Online Entertainment
//
// Edit the file Schema_h.template. Do not edit Schema.h.
//
// ======================================================================
#ifndef INCLUDED_Schema_H
#define INCLUDED_Schema_H
#include "sharedDatabaseInterface/Bindable.h"
#include "sharedDatabaseInterface/BindableNetworkId.h"
#include "sharedDatabaseInterface/BufferString.h"
#include "sharedDatabaseInterface/DbRow.h"
namespace DBSchema
{
struct PlayerObjectRow : public DB::Row
{
enum {QUEST_DATA_SIZE=4000};
DB::BindableNetworkId object_id;
DB::BindableLong station_id;
DB::BindableNetworkId house_id;
DB::BindableLong account_num_lots;
DB::BindableBool account_is_outcast;
DB::BindableDouble account_cheater_level;
DB::BindableLong account_max_lots_adjustment;
DB::BindableString<200> personal_profile_id;
DB::BindableString<200> character_profile_id;
DB::BindableString<200> skill_title;
DB::BindableLong born_date;
DB::BindableLong played_time;
DB::BindableDouble force_regen_rate;
DB::BindableLong force_power;
DB::BindableLong max_force_power;
DB::BindableBitArray<2047> active_quests;
DB::BindableBitArray<2047> completed_quests;
DB::BindableLong current_quest;
DB::BindableString<QUEST_DATA_SIZE> quests;
DB::BindableLong role_icon_choice;
DB::BindableString<QUEST_DATA_SIZE> quests2;
DB::BindableString<QUEST_DATA_SIZE> quests3;
DB::BindableString<QUEST_DATA_SIZE> quests4;
DB::BindableString<200> skill_template;
DB::BindableString<200> working_skill;
DB::BindableLong current_gcw_points;
DB::BindableLong current_gcw_rating;
DB::BindableLong current_pvp_kills;
DB::BindableInt64 lifetime_gcw_points;
DB::BindableLong max_gcw_imperial_rating;
DB::BindableLong max_gcw_rebel_rating;
DB::BindableLong lifetime_pvp_kills;
DB::BindableLong next_gcw_rating_calc_time;
DB::BindableBitArray<16000> collections;
DB::BindableBool show_backpack;
DB::BindableBool show_helmet;
DB::BindableBitArray<16000> collections2;
virtual void copy(const DB::Row &rhs)
{
*this = dynamic_cast<const PlayerObjectRow&>(rhs);
}
void setPrimaryKey(const NetworkId &keyValue)
{
object_id.setValue(keyValue);
}
NetworkId getPrimaryKey() const
{
return object_id.getValue();
}
};
struct PlayerObjectBufferRow : public DB::Row
{
DB::BindableNetworkId object_id;
DB::BindableLong station_id;
DB::BindableNetworkId house_id;
DB::BindableLong account_num_lots;
DB::BindableBool account_is_outcast;
DB::BindableDouble account_cheater_level;
DB::BindableLong account_max_lots_adjustment;
DB::BufferString personal_profile_id;
DB::BufferString character_profile_id;
DB::BufferString skill_title;
DB::BindableLong born_date;
DB::BindableLong played_time;
DB::BindableDouble force_regen_rate;
DB::BindableLong force_power;
DB::BindableLong max_force_power;
DB::BindableBitArray<2047> active_quests;
DB::BindableBitArray<2047> completed_quests;
DB::BindableLong current_quest;
DB::BufferString quests;
DB::BindableLong role_icon_choice;
DB::BufferString quests2;
DB::BufferString quests3;
DB::BufferString quests4;
DB::BufferString skill_template;
DB::BufferString working_skill;
DB::BindableLong current_gcw_points;
DB::BindableLong current_gcw_rating;
DB::BindableLong current_pvp_kills;
DB::BindableInt64 lifetime_gcw_points;
DB::BindableLong max_gcw_imperial_rating;
DB::BindableLong max_gcw_rebel_rating;
DB::BindableLong lifetime_pvp_kills;
DB::BindableLong next_gcw_rating_calc_time;
DB::BindableBitArray<16000> collections;
DB::BindableBool show_backpack;
DB::BindableBool show_helmet;
DB::BindableBitArray<16000> collections2;
virtual void copy(const DB::Row &rhs)
{
*this = dynamic_cast<const PlayerObjectBufferRow&>(rhs);
}
void setPrimaryKey(const NetworkId &keyValue)
{
object_id.setValue(keyValue);
}
NetworkId getPrimaryKey() const
{
return object_id.getValue();
}
PlayerObjectBufferRow (const PlayerObjectRow & rhs) :
object_id (rhs.object_id),
station_id (rhs.station_id),
house_id (rhs.house_id),
account_num_lots (rhs.account_num_lots),
account_is_outcast (rhs.account_is_outcast),
account_cheater_level (rhs.account_cheater_level),
account_max_lots_adjustment (rhs.account_max_lots_adjustment),
personal_profile_id (rhs.personal_profile_id),
character_profile_id (rhs.character_profile_id),
skill_title (rhs.skill_title),
born_date (rhs.born_date),
played_time (rhs.played_time),
force_regen_rate (rhs.force_regen_rate),
force_power (rhs.force_power),
max_force_power (rhs.max_force_power),
active_quests (rhs.active_quests),
completed_quests (rhs.completed_quests),
current_quest (rhs.current_quest),
quests (rhs.quests),
role_icon_choice (rhs.role_icon_choice),
quests2 (rhs.quests2),
quests3 (rhs.quests3),
quests4 (rhs.quests4),
skill_template (rhs.skill_template),
working_skill (rhs.working_skill),
current_gcw_points (rhs.current_gcw_points),
current_gcw_rating (rhs.current_gcw_rating),
current_pvp_kills (rhs.current_pvp_kills),
lifetime_gcw_points (rhs.lifetime_gcw_points),
max_gcw_imperial_rating (rhs.max_gcw_imperial_rating),
max_gcw_rebel_rating (rhs.max_gcw_rebel_rating),
lifetime_pvp_kills (rhs.lifetime_pvp_kills),
next_gcw_rating_calc_time (rhs.next_gcw_rating_calc_time),
collections (rhs.collections),
show_backpack(rhs.show_backpack),
show_helmet(rhs.show_helmet),
collections2 (rhs.collections2)
{
}
PlayerObjectBufferRow() :
object_id(),
station_id(),
house_id(),
account_num_lots(),
account_is_outcast(),
account_cheater_level(),
account_max_lots_adjustment(),
personal_profile_id(200),
character_profile_id(200),
skill_title(200),
born_date(),
played_time(),
force_regen_rate(),
force_power(),
max_force_power(),
active_quests(),
completed_quests(),
current_quest(),
quests(PlayerObjectRow::QUEST_DATA_SIZE),
role_icon_choice(),
quests2(PlayerObjectRow::QUEST_DATA_SIZE),
quests3(PlayerObjectRow::QUEST_DATA_SIZE),
quests4(PlayerObjectRow::QUEST_DATA_SIZE),
skill_template(200),
working_skill(200),
current_gcw_points(),
current_gcw_rating(),
current_pvp_kills(),
lifetime_gcw_points(),
max_gcw_imperial_rating(),
max_gcw_rebel_rating(),
lifetime_pvp_kills(),
next_gcw_rating_calc_time(),
collections(),
show_backpack(),
show_helmet(),
collections2()
{
}
};
struct ObjectVariableRow : public DB::Row
{
DB::BindableNetworkId object_id;
DB::BindableLong name_id;
DB::BindableLong type;
DB::BindableString<1000> value;
DB::BindableLong detached;
virtual void copy(const DB::Row &rhs)
{
*this = dynamic_cast<const ObjectVariableRow&>(rhs);
}
};
struct WaypointRow : public DB::Row
{
DB::BindableNetworkId object_id;
DB::BindableNetworkId waypoint_id;
DB::BindableLong appearance_name_crc;
DB::BindableDouble location_x;
DB::BindableDouble location_y;
DB::BindableDouble location_z;
DB::BindableNetworkId location_cell;
DB::BindableLong location_scene;
DB::BindableUnicode<512> name;
DB::BindableLong color;
DB::BindableBool active;
DB::BindableBool detached;
virtual void copy(const DB::Row &rhs)
{
*this = dynamic_cast<const WaypointRow&>(rhs);
}
};
//!!!BEGIN GENERATED DECLARATIONS
//!!!END GENERATED DECLARATIONS
}
#endif
@@ -0,0 +1,70 @@
// ======================================================================
//
// PersistableWaypoint.cpp
// copyright (c) 2003 Sony Online Entertainment
//
// ======================================================================
#include "SwgDatabaseServer/FirstSwgDatabaseServer.h"
#include "SwgDatabaseServer/PersistableWaypoint.h"
#include "Archive/Archive.h"
#include "sharedFoundation/NetworkIdArchive.h"
#include "sharedUtility/LocationArchive.h"
#include "unicodeArchive/UnicodeArchive.h"
// ======================================================================
PersistableWaypoint::PersistableWaypoint() :
m_appearanceNameCrc(0),
m_location(),
m_name(),
m_networkId(NetworkId::cms_invalid),
m_color(0),
m_active(false),
m_detached(false)
{
}
#ifdef WIN32
bool PersistableWaypoint::operator!=(const PersistableWaypoint& rhs)
{
return m_networkId != rhs.m_networkId ||
m_location != rhs.m_location ||
m_name != rhs.m_name ||
m_appearanceNameCrc != rhs.m_appearanceNameCrc ||
m_color != rhs.m_color ||
m_active != rhs.m_active ||
m_detached != rhs.m_detached;
}
#endif
// ======================================================================
namespace Archive
{
void get (Archive::ReadIterator & source, PersistableWaypoint & target)
{
get(source, target.m_appearanceNameCrc);
get(source, target.m_location);
get(source, target.m_name);
get(source, target.m_networkId);
get(source, target.m_color);
get(source, target.m_active);
}
//-----------------------------------------------------------------------
void put (Archive::ByteStream & target, const PersistableWaypoint & source)
{
put(target, source.m_appearanceNameCrc);
put(target, source.m_location);
put(target, source.m_name);
put(target, source.m_networkId);
put(target, source.m_color);
put(target, source.m_active);
}
}
// ======================================================================
@@ -0,0 +1,49 @@
// ======================================================================
//
// PersistableWaypoint.h
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#ifndef INCLUDED_PersistableWaypoint_H
#define INCLUDED_PersistableWaypoint_H
// ======================================================================
#include "sharedUtility/Location.h"
#include "Unicode.h"
// ======================================================================
class PersistableWaypoint
{
public:
unsigned int m_appearanceNameCrc;
Location m_location;
Unicode::String m_name;
NetworkId m_networkId;
unsigned char m_color;
bool m_active;
bool m_detached;
public:
PersistableWaypoint();
#ifdef WIN32
bool operator!=(const PersistableWaypoint& rhs);
#endif
};
// ======================================================================
namespace Archive
{
class ReadIterator;
class ByteStream;
void get (Archive::ReadIterator & source, PersistableWaypoint & target);
void put (ByteStream & target, const PersistableWaypoint & source);
}
// ======================================================================
#endif
@@ -0,0 +1,134 @@
// ======================================================================
//
// BattlefieldParticipantQuery.cpp
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#include "SwgDatabaseServer/FirstSwgDatabaseServer.h"
#include "SwgDatabaseServer/BattlefieldParticipantQuery.h"
#include "SwgDatabaseServer/Schema.h"
#include "serverDatabase/ConfigServerDatabase.h"
#include "serverDatabase/DatabaseProcess.h"
// ======================================================================
using namespace DBQuery;
// ======================================================================
BattlefieldParticipantQuery::BattlefieldParticipantQuery() :
ModeQuery(new DBSchema::BattlefieldParticipantRow) //lint !e1524 // We don't delete the new row (base class does)
{
}
// ----------------------------------------------------------------------
bool BattlefieldParticipantQuery::bindParameters()
{
DBSchema::BattlefieldParticipantRow *myData=dynamic_cast<DBSchema::BattlefieldParticipantRow*>(data);
NOT_NULL(myData);
switch(mode)
{
case mode_UPDATE:
case mode_INSERT:
if (!bindParameter(myData->faction_id)) return false;
if (!bindParameter(myData->character_object_id)) return false;
if (!bindParameter(myData->region_object_id)) return false;
break;
case mode_SELECT:
default:
DEBUG_FATAL(true,("Bad query mode."));
}
return true;
}
bool BattlefieldParticipantQuery::bindColumns()
{
DBSchema::BattlefieldParticipantRow *myData=dynamic_cast<DBSchema::BattlefieldParticipantRow*>(data);
NOT_NULL(myData);
switch(mode)
{
case mode_UPDATE:
case mode_INSERT:
break;
case mode_SELECT:
default:
DEBUG_FATAL(true,("Bad query mode."));
} //lint !e788 //not all modes have an explicit case in the switch
return true;
}
// ----------------------------------------------------------------------
void BattlefieldParticipantQuery::getSQL(std::string &sql)
{
switch(mode)
{
case mode_UPDATE:
case mode_INSERT:
sql=std::string("begin ")+DatabaseProcess::getInstance().getSchemaQualifier()+"persister.save_battlefield_participants (:faction_id, :character_object_id, :region_object_id); end;";
break;
case mode_SELECT:
default:
DEBUG_FATAL(true,("Bad query mode."));
}
}
// ======================================================================
DBQuery::GetAllBattlefieldParticipant::GetAllBattlefieldParticipant(const std::string &schema) :
Query(),
m_data(ConfigServerDatabase::getDefaultFetchBatchSize()),
m_schema(schema)
{
}
bool GetAllBattlefieldParticipant::bindParameters()
{
return true;
}
bool GetAllBattlefieldParticipant::bindColumns()
{
size_t skipSize = reinterpret_cast<char*>(&(m_data[1])) - reinterpret_cast<char*>(&(m_data[0]));
setColArrayMode(skipSize, m_data.size());
if (!bindCol(m_data[0].region_object_id)) return false;
if (!bindCol(m_data[0].character_object_id)) return false;
if (!bindCol(m_data[0].faction_id)) return false;
return true;
}
// ----------------------------------------------------------------------
void GetAllBattlefieldParticipant::getSQL(std::string &sql)
{
sql=std::string("begin :result := ")+m_schema+"loader.load_battlefield_participants(); end;";
}
// ----------------------------------------------------------------------
DB::Query::QueryMode GetAllBattlefieldParticipant::getExecutionMode() const
{
if (getProtocol()==DB::PROTOCOL_OCI)
return (MODE_PLSQL_REFCURSOR);
else
{
FATAL(true,("ODBC mode is not supported for BattlefieldParticipant\n"));
return MODE_SQL; // return to avoid compiler warning
}
}
// ======================================================================
@@ -0,0 +1,66 @@
// ======================================================================
//
// BattlefieldParticipantQuery.h
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#ifndef INCLUDED_BattlefieldParticipantQuery_H
#define INCLUDED_BattlefieldParticipantQuery_H
// ======================================================================
#include "sharedDatabaseInterface/DbModeQuery.h"
#include "SwgDatabaseServer/Schema.h"
#include <vector>
// ======================================================================
namespace DBQuery
{
class BattlefieldParticipantQuery : public DB::ModeQuery
{
BattlefieldParticipantQuery(const BattlefieldParticipantQuery&); // disable
BattlefieldParticipantQuery& operator=(const BattlefieldParticipantQuery&); // disable
public:
BattlefieldParticipantQuery();
virtual bool bindParameters();
virtual bool bindColumns();
virtual void getSQL(std::string &sql);
};
// ----------------------------------------------------------------------
class GetAllBattlefieldParticipant : public DB::Query
{
public:
GetAllBattlefieldParticipant(const std::string &schema);
const std::vector<DBSchema::BattlefieldParticipantRow> &getData() const;
virtual bool bindParameters();
virtual bool bindColumns();
virtual void getSQL(std::string &sql);
virtual QueryMode getExecutionMode() const;
private:
GetAllBattlefieldParticipant(const GetAllBattlefieldParticipant&); // disable
GetAllBattlefieldParticipant& operator=(const GetAllBattlefieldParticipant&); // disable
private:
std::vector<DBSchema::BattlefieldParticipantRow> m_data;
const std::string m_schema;
};
}
// ======================================================================
inline const std::vector<DBSchema::BattlefieldParticipantRow> &DBQuery::GetAllBattlefieldParticipant::getData() const
{
return m_data;
}
// ======================================================================
#endif
@@ -0,0 +1,149 @@
// ======================================================================
//
// BountyHunterTargetQuery.cpp
// copyright (c) 2004 Sony Online Entertainment
//
// ======================================================================
#include "SwgDatabaseServer/FirstSwgDatabaseServer.h"
#include "SwgDatabaseServer/BountyHunterTargetQuery.h"
#include "SwgDatabaseServer/Schema.h"
#include "serverDatabase/DatabaseProcess.h"
// ======================================================================
namespace BountyHunterTargetQueryNamespace
{
const int ms_fetchBatchSize = 1000;
}
using namespace BountyHunterTargetQueryNamespace;
using namespace DBQuery;
// ======================================================================
BountyHunterTargetQuery::BountyHunterTargetQuery() :
m_numItems(0)
{
}
// ----------------------------------------------------------------------
bool BountyHunterTargetQuery::setupData(DB::Session *session)
{
if (!m_object_ids.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false;
if (!m_target_ids.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false;
return true;
}
// ----------------------------------------------------------------------
bool BountyHunterTargetQuery::addData(DBSchema::BountyHunterTargetRow const & data)
{
if (!m_object_ids.push_back(data.object_id.getValueASCII())) return false;
if (!m_target_ids.push_back(data.target_id.getValueASCII())) return false;
m_numItems=m_numItems.getValue() + 1;
return true;
}
// ----------------------------------------------------------------------
int BountyHunterTargetQuery::getNumItems() const
{
return m_numItems.getValue();
}
// ----------------------------------------------------------------------
void BountyHunterTargetQuery::clearData()
{
m_object_ids.clear();
m_target_ids.clear();
m_numItems=0;
}
// ----------------------------------------------------------------------
void BountyHunterTargetQuery::freeData()
{
m_object_ids.free();
m_target_ids.free();
}
// ----------------------------------------------------------------------
bool BountyHunterTargetQuery::bindParameters()
{
if (!bindParameter(m_object_ids)) return false;
if (!bindParameter(m_target_ids)) return false;
if (!bindParameter(m_numItems)) return false;
return true;
}
// ----------------------------------------------------------------------
bool BountyHunterTargetQuery::bindColumns()
{
return true;
}
// ----------------------------------------------------------------------
void BountyHunterTargetQuery::getSQL(std::string &sql)
{
sql=std::string("begin ")+DatabaseProcess::getInstance().getSchemaQualifier()+"persister.save_bounty_hunter_target (:object_id, :target_id, :chunk_size); end;";
}
// ======================================================================
BountyHunterTargetQuerySelect::BountyHunterTargetQuerySelect(const std::string &schema) :
m_data(ms_fetchBatchSize),
m_schema(schema)
{
}
// ----------------------------------------------------------------------
bool BountyHunterTargetQuerySelect::bindParameters ()
{
return true;
}
// ----------------------------------------------------------------------
bool BountyHunterTargetQuerySelect::bindColumns()
{
size_t skipSize = reinterpret_cast<char*>(&(m_data[1])) - reinterpret_cast<char*>(&(m_data[0]));
setColArrayMode(skipSize, ms_fetchBatchSize);
if (!bindCol(m_data[0].object_id)) return false;
if (!bindCol(m_data[0].target_id)) return false;
return true;
}
// ----------------------------------------------------------------------
const std::vector<DBSchema::BountyHunterTargetRow> & BountyHunterTargetQuerySelect::getData() const
{
return m_data;
}
// ----------------------------------------------------------------------
void BountyHunterTargetQuerySelect::getSQL(std::string &sql)
{
sql=std::string("begin :result := ")+m_schema+"loader.load_bounty_hunter_targets; end;";
}
// ----------------------------------------------------------------------
DB::Query::QueryMode BountyHunterTargetQuerySelect::getExecutionMode() const
{
return MODE_PLSQL_REFCURSOR;
}
// ======================================================================
@@ -0,0 +1,74 @@
// ======================================================================
//
// BountyHunterTargetQuery,h
// copyright (c) 2004 Sony Online Entertainment
//
// ======================================================================
#ifndef INCLUDED_BountyHunterTargetQuery_H
#define INCLUDED_BountyHunterTargetQuery_H
// ======================================================================
#include "SwgDatabaseServer/Schema.h"
#include "serverDatabase/DatabaseProcessQuery.h"
#include "sharedDatabaseInterface/DbBindableVarray.h"
#include <vector>
// ======================================================================
namespace DBQuery
{
class BountyHunterTargetQuery : public DB::Query
{
BountyHunterTargetQuery(const BountyHunterTargetQuery&);
BountyHunterTargetQuery& operator= (const BountyHunterTargetQuery&);
public:
BountyHunterTargetQuery();
virtual bool bindParameters ();
virtual bool bindColumns ();
virtual void getSQL(std::string &sql);
bool setupData(DB::Session *session);
bool addData(DBSchema::BountyHunterTargetRow const & data);
void clearData();
void freeData();
int getNumItems() const;
private:
DB::BindableVarrayString m_object_ids;
DB::BindableVarrayString m_target_ids;
DB::BindableLong m_numItems;
};
class BountyHunterTargetQuerySelect : public DB::Query
{
public:
BountyHunterTargetQuerySelect(const std::string &schema);
virtual bool bindParameters ();
virtual bool bindColumns ();
virtual void getSQL (std::string &sql);
const std::vector<DBSchema::BountyHunterTargetRow> & getData() const;
protected:
virtual QueryMode getExecutionMode() const;
private:
std::vector<DBSchema::BountyHunterTargetRow> m_data;
const std::string m_schema;
BountyHunterTargetQuerySelect (const BountyHunterTargetQuerySelect&);
BountyHunterTargetQuerySelect& operator= (const BountyHunterTargetQuerySelect&);
};
}
// ======================================================================
#endif
@@ -0,0 +1,988 @@
#include "SwgDatabaseServer/FirstSwgDatabaseServer.h"
#include "CommoditiesQuery.h"
#include "serverDatabase/DatabaseProcess.h"
#include "SwgDatabaseServer/CommoditiesSchema.h"
using namespace DBQuery;
using namespace DBSchema;
// Static instance counters
volatile int AuctionLocationsRow::m_sAuctionRowsCreated = 0;
volatile int AuctionLocationsRow::m_sAuctionRowsDeleted = 0;
volatile int MarketAuctionsRow::m_sAuctionRowsCreated = 0;
volatile int MarketAuctionsRow::m_sAuctionRowsDeleted = 0;
volatile int MarketAuctionsRowDelete::m_sAuctionRowsCreated = 0;
volatile int MarketAuctionsRowDelete::m_sAuctionRowsDeleted = 0;
volatile int MarketAuctionsRowUpdate::m_sAuctionRowsCreated = 0;
volatile int MarketAuctionsRowUpdate::m_sAuctionRowsDeleted = 0;
volatile int MarketAuctionBidsRow::m_sAuctionRowsCreated = 0;
volatile int MarketAuctionBidsRow::m_sAuctionRowsDeleted = 0;
// ======================================================================
namespace CommoditiesQueryNamespace
{
const int ms_fetchBatchSize = 1000;
}
using namespace CommoditiesQueryNamespace;
// ======================================================================
AuctionLocationsQuery::AuctionLocationsQuery() :
DatabaseProcessQuery(new AuctionLocationsRow),
m_numItems(0)
{
}
bool AuctionLocationsQuery::setupData(DB::Session *session)
{
switch(mode)
{
case mode_UPDATE:
if (!m_location_ids.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false;
if (!m_location_names.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false;
if (!m_owner_ids.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false;
if (!m_sales_taxes.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false;
if (!m_sales_tax_bank_ids.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false;
if (!m_empty_date.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false;
if (!m_last_access_date.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false;
if (!m_inactive_date.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false;
if (!m_status.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false;
if (!m_search_enabled.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false;
if (!m_entrance_charge.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false;
break;
case mode_INSERT:
if (!m_location_ids.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false;
if (!m_location_names.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false;
if (!m_owner_ids.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false;
if (!m_sales_taxes.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false;
if (!m_sales_tax_bank_ids.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false;
if (!m_empty_date.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false;
if (!m_last_access_date.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false;
if (!m_inactive_date.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false;
if (!m_status.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false;
if (!m_search_enabled.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false;
if (!m_entrance_charge.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false;
break;
case mode_SELECT:
break;
case mode_DELETE:
if (!m_location_ids.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false;
break;
default:
DEBUG_FATAL(true,("Bad query mode."));
}
return true;
}
bool AuctionLocationsQuery::addData(const DB::Row *_data)
{
const AuctionLocationsRow *myData=dynamic_cast<const AuctionLocationsRow*>(_data);
FATAL(myData == NULL, ("Adding NULL data into AuctionLocations"));
switch(mode)
{
case mode_UPDATE:
if (!m_location_ids.push_back(myData->location_id.getValueASCII())) return false;
if (!m_location_names.push_back(myData->location_name.getValueASCII())) return false;
if (!m_owner_ids.push_back(myData->owner_id.isNull(), myData->owner_id.getValueASCII())) return false;
if (!m_sales_taxes.push_back(myData->sales_tax.isNull(), myData->sales_tax.getValue())) return false;
if (!m_sales_tax_bank_ids.push_back(myData->sales_tax_bank_id.isNull(), myData->sales_tax_bank_id.getValue())) return false;
if (!m_empty_date.push_back(myData->empty_date.isNull(), myData->empty_date.getValue())) return false;
if (!m_last_access_date.push_back(myData->last_access_date.isNull(), myData->last_access_date.getValue())) return false;
if (!m_inactive_date.push_back(myData->inactive_date.isNull(), myData->inactive_date.getValue())) return false;
if (!m_status.push_back(myData->status.isNull(), myData->status.getValue())) return false;
if (!m_search_enabled.push_back(myData->search_enabled.isNull(), myData->search_enabled.getValue())) return false;
if (!m_entrance_charge.push_back(myData->entrance_charge.isNull(), myData->entrance_charge.getValue())) return false;
break;
case mode_INSERT:
if (!m_location_ids.push_back(myData->location_id.getValueASCII())) return false;
if (!m_location_names.push_back(myData->location_name.getValueASCII())) return false;
if (!m_owner_ids.push_back(myData->owner_id.isNull(), myData->owner_id.getValueASCII())) return false;
if (!m_sales_taxes.push_back(myData->sales_tax.isNull(), myData->sales_tax.getValue())) return false;
if (!m_sales_tax_bank_ids.push_back(myData->sales_tax_bank_id.isNull(), myData->sales_tax_bank_id.getValue())) return false;
if (!m_empty_date.push_back(myData->empty_date.isNull(), myData->empty_date.getValue())) return false;
if (!m_last_access_date.push_back(myData->last_access_date.isNull(), myData->last_access_date.getValue())) return false;
if (!m_inactive_date.push_back(myData->inactive_date.isNull(), myData->inactive_date.getValue())) return false;
if (!m_status.push_back(myData->status.isNull(), myData->status.getValue())) return false;
if (!m_search_enabled.push_back(myData->search_enabled.isNull(), myData->search_enabled.getValue())) return false;
if (!m_entrance_charge.push_back(myData->entrance_charge.isNull(), myData->entrance_charge.getValue())) return false;
break;
case mode_SELECT:
break;
case mode_DELETE:
if (!m_location_ids.push_back(myData->location_id.getValueASCII())) return false;
break;
default:
DEBUG_FATAL(true,("Bad query mode."));
}
m_numItems=m_numItems.getValue() + 1;
return true;
}
int AuctionLocationsQuery::getNumItems() const
{
return m_numItems.getValue();
}
void AuctionLocationsQuery::clearData()
{
switch(mode)
{
case mode_UPDATE:
m_location_ids.clear();
m_location_names.clear();
m_owner_ids.clear();
m_sales_taxes.clear();
m_sales_tax_bank_ids.clear();
m_empty_date.clear();
m_last_access_date.clear();
m_inactive_date.clear();
m_status.clear();
m_search_enabled.clear();
m_entrance_charge.clear();
break;
case mode_INSERT:
m_location_ids.clear();
m_location_names.clear();
m_owner_ids.clear();
m_sales_taxes.clear();
m_sales_tax_bank_ids.clear();
m_empty_date.clear();
m_last_access_date.clear();
m_inactive_date.clear();
m_status.clear();
m_search_enabled.clear();
m_entrance_charge.clear();
break;
case mode_SELECT:
break;
case mode_DELETE:
m_location_ids.clear();
break;
default:
DEBUG_FATAL(true,("Bad query mode."));
}
m_numItems=0;
}
void AuctionLocationsQuery::freeData()
{
switch(mode)
{
case mode_UPDATE:
m_location_ids.free();
m_location_names.free();
m_owner_ids.free();
m_sales_taxes.free();
m_sales_tax_bank_ids.free();
m_empty_date.free();
m_last_access_date.free();
m_inactive_date.free();
m_status.free();
m_search_enabled.free();
m_entrance_charge.free();
break;
case mode_INSERT:
m_location_ids.free();
m_location_names.free();
m_owner_ids.free();
m_sales_taxes.free();
m_sales_tax_bank_ids.free();
m_empty_date.free();
m_last_access_date.free();
m_inactive_date.free();
m_status.free();
m_search_enabled.free();
m_entrance_charge.free();
break;
case mode_SELECT:
break;
case mode_DELETE:
m_location_ids.free();
break;
default:
DEBUG_FATAL(true,("Bad query mode."));
}
}
bool AuctionLocationsQuery::bindParameters()
{
switch(mode)
{
case mode_UPDATE:
if (!bindParameter(m_location_ids)) return false;
if (!bindParameter(m_location_names)) return false;
if (!bindParameter(m_owner_ids)) return false;
if (!bindParameter(m_sales_taxes)) return false;
if (!bindParameter(m_sales_tax_bank_ids)) return false;
if (!bindParameter(m_empty_date)) return false;
if (!bindParameter(m_last_access_date)) return false;
if (!bindParameter(m_inactive_date)) return false;
if (!bindParameter(m_status)) return false;
if (!bindParameter(m_search_enabled)) return false;
if (!bindParameter(m_entrance_charge)) return false;
if (!bindParameter(m_numItems)) return false;
break;
case mode_INSERT:
if (!bindParameter(m_location_ids)) return false;
if (!bindParameter(m_location_names)) return false;
if (!bindParameter(m_owner_ids)) return false;
if (!bindParameter(m_sales_taxes)) return false;
if (!bindParameter(m_sales_tax_bank_ids)) return false;
if (!bindParameter(m_empty_date)) return false;
if (!bindParameter(m_last_access_date)) return false;
if (!bindParameter(m_inactive_date)) return false;
if (!bindParameter(m_status)) return false;
if (!bindParameter(m_search_enabled)) return false;
if (!bindParameter(m_entrance_charge)) return false;
if (!bindParameter(m_numItems)) return false;
break;
case mode_SELECT:
break;
case mode_DELETE:
if (!bindParameter(m_location_ids)) return false;
if (!bindParameter(m_numItems)) return false;
break;
default:
DEBUG_FATAL(true,("Bad query mode."));
}
return true;
}
bool AuctionLocationsQuery::bindColumns()
{
return true;
}
void AuctionLocationsQuery::getSQL(std::string &sql)
{
switch(mode)
{
case mode_UPDATE:
sql=std::string("begin ") + DatabaseProcess::getInstance().getSchemaQualifier() + "cm_persister.update_auction_locations (:location_id, :location_name, :owner_id, :sales_tax, :sales_tax_bank_id, :empty_date, :last_access_date, :inactive_date, :status, :search_enabled, :entrance_charge, :chunk_size); end;";
break;
case mode_INSERT:
sql=std::string("begin ") + DatabaseProcess::getInstance().getSchemaQualifier() + "cm_persister.insert_auction_locations (:location_id, :location_name, :owner_id, :sales_tax, :sales_tax_bank_id, :empty_date, :last_access_date, :inactive_date, :status, :search_enabled, :entrance_charge, :chunk_size); end;";
break;
case mode_SELECT:
break;
case mode_DELETE:
sql=std::string("begin ") + DatabaseProcess::getInstance().getSchemaQualifier() + "cm_persister.delete_auction_locations (:location_id, :chunk_size ); end;";
break;
default:
DEBUG_FATAL(true,("Bad query mode."));
}
}
AuctionLocationsQuerySelect::AuctionLocationsQuerySelect(const std::string &schema) :
m_data(ms_fetchBatchSize),
m_schema(schema)
{
}
bool AuctionLocationsQuerySelect::bindParameters ()
{
return true;
}
bool AuctionLocationsQuerySelect::bindColumns()
{
size_t skipSize = reinterpret_cast<char*>(&(m_data[1])) - reinterpret_cast<char*>(&(m_data[0]));
setColArrayMode(skipSize, ms_fetchBatchSize);
if (!bindCol(m_data[0].location_id)) return false;
if (!bindCol(m_data[0].location_name)) return false;
if (!bindCol(m_data[0].owner_id)) return false;
if (!bindCol(m_data[0].sales_tax)) return false;
if (!bindCol(m_data[0].sales_tax_bank_id)) return false;
if (!bindCol(m_data[0].empty_date)) return false;
if (!bindCol(m_data[0].last_access_date)) return false;
if (!bindCol(m_data[0].inactive_date)) return false;
if (!bindCol(m_data[0].status)) return false;
if (!bindCol(m_data[0].search_enabled)) return false;
if (!bindCol(m_data[0].entrance_charge)) return false;
return true;
}
const std::vector<AuctionLocationsRow> & AuctionLocationsQuerySelect::getData() const
{
return m_data;
}
void AuctionLocationsQuerySelect::getSQL(std::string &sql)
{
sql=std::string("begin :result := ")+m_schema+"cm_loader.get_location_list(); end;";
}
DB::Query::QueryMode AuctionLocationsQuerySelect::getExecutionMode() const
{
return MODE_PLSQL_REFCURSOR;
}
// ======================================================================
MarketAuctionsQuery::MarketAuctionsQuery() :
DatabaseProcessQuery(new MarketAuctionsRow),
m_numItems(0)
{
}
bool MarketAuctionsQuery::setupData(DB::Session *session)
{
switch(mode)
{
case mode_UPDATE:
if (!m_item_ids.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false;
if (!m_owner_ids.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false;
if (!m_actives.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false;
break;
case mode_INSERT:
if (!m_item_ids.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false;
if (!m_owner_ids.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false;
if (!m_creator_ids.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false;
if (!m_location_ids.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false;
if (!m_min_bids.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false;
if (!m_buy_now_prices.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false;
if (!m_auction_timers.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false;
if (!m_oobs.create(session, "VAOFLONGSTRING", DatabaseProcess::getInstance().getSchema(),4000)) return false;
if (!m_user_descriptions.create(session, "VAOFLONGSTRING", DatabaseProcess::getInstance().getSchema(),4000)) return false;
if (!m_categories.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false;
if (!m_item_names.create(session, "VAOFLONGSTRING", DatabaseProcess::getInstance().getSchema(),4000)) return false;
if (!m_item_timers.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false;
if (!m_actives.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false;
if (!m_item_sizes.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false;
if (!m_object_template_ids.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false;
break;
case mode_SELECT:
break;
case mode_DELETE:
if (!m_item_ids.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false;
break;
default:
DEBUG_FATAL(true,("Bad query mode."));
}
return true;
}
bool MarketAuctionsQuery::addData(const DB::Row *_data)
{
switch(mode)
{
case mode_UPDATE:
{
const MarketAuctionsRowUpdate *myData=dynamic_cast<const MarketAuctionsRowUpdate*>(_data);
FATAL(myData == NULL, ("Adding NULL data into MarketAuctions for mode_UPDATE"));
if (!m_item_ids.push_back(myData->item_id.getValueASCII())) return false;
if (!m_owner_ids.push_back(myData->owner_id.getValueASCII())) return false;
if (!m_actives.push_back(myData->active.isNull(), myData->active.getValue())) return false;
break;
}
case mode_INSERT:
{
const MarketAuctionsRow *myData=dynamic_cast<const MarketAuctionsRow*>(_data);
FATAL(myData == NULL, ("Adding NULL data into MarketAuctions for mode_INSERT"));
if (!m_item_ids.push_back(myData->item_id.getValueASCII())) return false;
if (!m_owner_ids.push_back(myData->owner_id.getValueASCII())) return false;
if (!m_creator_ids.push_back(myData->creator_id.isNull(), myData->creator_id.getValueASCII())) return false;
if (!m_location_ids.push_back(myData->location_id.getValueASCII())) return false;
if (!m_min_bids.push_back(myData->min_bid.isNull(), myData->min_bid.getValue())) return false;
if (!m_buy_now_prices.push_back(myData->buy_now_price.isNull(), myData->buy_now_price.getValue())) return false;
if (!m_auction_timers.push_back(myData->auction_timer.isNull(), myData->auction_timer.getValue())) return false;
if (!m_oobs.push_back(myData->oob.isNull(), myData->oob.getValueASCII())) return false;
if (!m_user_descriptions.push_back(myData->user_description.isNull(), myData->user_description.getValue())) return false;
if (!m_categories.push_back(myData->category.isNull(), myData->category.getValue())) return false;
if (!m_item_names.push_back(myData->item_name.isNull(), myData->item_name.getValue())) return false;
if (!m_item_timers.push_back(myData->item_timer.isNull(), myData->item_timer.getValue())) return false;
if (!m_actives.push_back(myData->active.isNull(), myData->active.getValue())) return false;
if (!m_item_sizes.push_back(myData->item_size.isNull(), myData->item_size.getValue())) return false;
if (!m_object_template_ids.push_back(myData->object_template_id.isNull(), myData->object_template_id.getValue())) return false;
break;
}
case mode_SELECT:
break;
case mode_DELETE:
{
const MarketAuctionsRowDelete *myData=dynamic_cast<const MarketAuctionsRowDelete*>(_data);
FATAL(myData == NULL, ("Adding NULL data into MarketAuctions for mode_DELETE"));
if (!m_item_ids.push_back(myData->item_id.getValueASCII())) return false;
break;
}
default:
DEBUG_FATAL(true,("Bad query mode."));
}
m_numItems=m_numItems.getValue() + 1;
return true;
}
int MarketAuctionsQuery::getNumItems() const
{
return m_numItems.getValue();
}
void MarketAuctionsQuery::clearData()
{
switch(mode)
{
case mode_UPDATE:
m_item_ids.clear();
m_owner_ids.clear();
m_actives.clear();
break;
case mode_INSERT:
m_item_ids.clear();
m_owner_ids.clear();
m_creator_ids.clear();
m_location_ids.clear();
m_min_bids.clear();
m_buy_now_prices.clear();
m_auction_timers.clear();
m_oobs.clear();
m_user_descriptions.clear();
m_categories.clear();
m_item_names.clear();
m_item_timers.clear();
m_actives.clear();
m_item_sizes.clear();
m_object_template_ids.clear();
break;
case mode_SELECT:
break;
case mode_DELETE:
m_item_ids.clear();
break;
default:
DEBUG_FATAL(true,("Bad query mode."));
}
m_numItems=0;
}
void MarketAuctionsQuery::freeData()
{
switch(mode)
{
case mode_UPDATE:
m_item_ids.free();
m_owner_ids.free();
m_actives.free();
break;
case mode_INSERT:
m_item_ids.free();
m_owner_ids.free();
m_creator_ids.free();
m_location_ids.free();
m_min_bids.free();
m_buy_now_prices.free();
m_auction_timers.free();
m_oobs.free();
m_user_descriptions.free();
m_categories.free();
m_item_names.free();
m_item_timers.free();
m_actives.free();
m_item_sizes.free();
m_object_template_ids.free();
break;
case mode_SELECT:
break;
case mode_DELETE:
m_item_ids.free();
break;
default:
DEBUG_FATAL(true,("Bad query mode."));
}
}
bool MarketAuctionsQuery::bindParameters()
{
switch(mode)
{
case mode_UPDATE:
if (!bindParameter(m_item_ids)) return false;
if (!bindParameter(m_owner_ids)) return false;
if (!bindParameter(m_actives)) return false;
if (!bindParameter(m_numItems)) return false;
break;
case mode_INSERT:
if (!bindParameter(m_item_ids)) return false;
if (!bindParameter(m_owner_ids)) return false;
if (!bindParameter(m_creator_ids)) return false;
if (!bindParameter(m_location_ids)) return false;
if (!bindParameter(m_min_bids)) return false;
if (!bindParameter(m_buy_now_prices)) return false;
if (!bindParameter(m_auction_timers)) return false;
if (!bindParameter(m_oobs)) return false;
if (!bindParameter(m_user_descriptions)) return false;
if (!bindParameter(m_categories)) return false;
if (!bindParameter(m_item_names)) return false;
if (!bindParameter(m_item_timers)) return false;
if (!bindParameter(m_actives)) return false;
if (!bindParameter(m_item_sizes)) return false;
if (!bindParameter(m_object_template_ids)) return false;
if (!bindParameter(m_numItems)) return false;
break;
case mode_SELECT:
break;
case mode_DELETE:
if (!bindParameter(m_item_ids)) return false;
if (!bindParameter(m_numItems)) return false;
break;
default:
DEBUG_FATAL(true,("Bad query mode."));
}
return true;
}
bool MarketAuctionsQuery::bindColumns()
{
return true;
}
void MarketAuctionsQuery::getSQL(std::string &sql)
{
switch(mode)
{
case mode_UPDATE:
sql=std::string("begin ") + DatabaseProcess::getInstance().getSchemaQualifier() +
"cm_persister.update_market_auctions (:item_id, :owner_id, :active, :chunk_size); end;";
break;
case mode_INSERT:
sql=std::string("begin ") + DatabaseProcess::getInstance().getSchemaQualifier() +
"cm_persister.insert_market_auctions (:item_id, :owner_id, :creator_id, :location_id, :min_bid, :buy_now_price, :auction_timer, :oob, :user_description, :category, :item_name, :item_timer, :active, :item_size, :object_template_id, :chunk_size); end;";
break;
case mode_SELECT:
break;
case mode_DELETE:
sql=std::string("begin ") + DatabaseProcess::getInstance().getSchemaQualifier() +
"cm_persister.delete_market_auctions (:item_id, :chunk_size ); end;";
break;
default:
DEBUG_FATAL(true,("Bad query mode."));
}
}
MarketAuctionsQuerySelect::MarketAuctionsQuerySelect(const std::string &schema) :
m_data(ms_fetchBatchSize),
m_schema(schema)
{
}
bool MarketAuctionsQuerySelect::bindParameters ()
{
return true;
}
bool MarketAuctionsQuerySelect::bindColumns()
{
size_t skipSize = reinterpret_cast<char*>(&(m_data[1])) - reinterpret_cast<char*>(&(m_data[0]));
setColArrayMode(skipSize, ms_fetchBatchSize);
if (!bindCol(m_data[0].item_id)) return false;
if (!bindCol(m_data[0].owner_id)) return false;
if (!bindCol(m_data[0].creator_id)) return false;
if (!bindCol(m_data[0].location_id)) return false;
if (!bindCol(m_data[0].min_bid)) return false;
if (!bindCol(m_data[0].buy_now_price)) return false;
if (!bindCol(m_data[0].auction_timer)) return false;
if (!bindCol(m_data[0].oob)) return false;
if (!bindCol(m_data[0].user_description)) return false;
if (!bindCol(m_data[0].category)) return false;
if (!bindCol(m_data[0].item_name)) return false;
if (!bindCol(m_data[0].item_timer)) return false;
if (!bindCol(m_data[0].active)) return false;
if (!bindCol(m_data[0].item_size)) return false;
return true;
}
const std::vector<MarketAuctionsRow> & MarketAuctionsQuerySelect::getData() const
{
return m_data;
}
void MarketAuctionsQuerySelect::getSQL(std::string &sql)
{
sql=std::string("begin :result := ")+m_schema+"cm_loader.get_auction_list(); end;";
}
DB::Query::QueryMode MarketAuctionsQuerySelect::getExecutionMode() const
{
return MODE_PLSQL_REFCURSOR;
}
// ======================================================================
MarketAuctionBidsQuery::MarketAuctionBidsQuery() :
DatabaseProcessQuery(new MarketAuctionBidsRow),
m_numItems(0)
{
}
bool MarketAuctionBidsQuery::setupData(DB::Session *session)
{
switch(mode)
{
case mode_UPDATE:
case mode_INSERT:
if (!m_item_ids.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false;
if (!m_bidder_ids.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false;
if (!m_bids.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false;
if (!m_max_proxy_bids.create(session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false;
break;
case mode_SELECT:
break;
case mode_DELETE:
if (!m_item_ids.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false;
break;
default:
DEBUG_FATAL(true,("Bad query mode."));
}
return true;
}
bool MarketAuctionBidsQuery::addData(const DB::Row *_data)
{
const MarketAuctionBidsRow *myData=dynamic_cast<const MarketAuctionBidsRow*>(_data);
FATAL(myData == NULL, ("Adding NULL data into MarketAuctionBids"));
switch(mode)
{
case mode_UPDATE:
case mode_INSERT:
if (!m_item_ids.push_back(myData->item_id.getValueASCII())) return false;
if (!m_bidder_ids.push_back(myData->bidder_id.getValueASCII())) return false;
if (!m_bids.push_back(myData->bid.getValue())) return false;
if (!m_max_proxy_bids.push_back(myData->max_proxy_bid.isNull(), myData->max_proxy_bid.getValue())) return false;
break;
case mode_SELECT:
break;
case mode_DELETE:
if (!m_item_ids.push_back(myData->item_id.getValueASCII())) return false;
break;
default:
DEBUG_FATAL(true,("Bad query mode."));
}
m_numItems=m_numItems.getValue() + 1;
return true;
}
int MarketAuctionBidsQuery::getNumItems() const
{
return m_numItems.getValue();
}
void MarketAuctionBidsQuery::clearData()
{
switch(mode)
{
case mode_UPDATE:
case mode_INSERT:
m_item_ids.clear();
m_bidder_ids.clear();
m_bids.clear();
m_max_proxy_bids.clear();
break;
case mode_SELECT:
break;
case mode_DELETE:
m_item_ids.clear();
break;
default:
DEBUG_FATAL(true,("Bad query mode."));
}
m_numItems=0;
}
void MarketAuctionBidsQuery::freeData()
{
switch(mode)
{
case mode_UPDATE:
case mode_INSERT:
m_item_ids.free();
m_bidder_ids.free();
m_bids.free();
m_max_proxy_bids.free();
break;
case mode_SELECT:
break;
case mode_DELETE:
m_item_ids.free();
break;
default:
DEBUG_FATAL(true,("Bad query mode."));
}
}
bool MarketAuctionBidsQuery::bindParameters()
{
switch(mode)
{
case mode_UPDATE:
case mode_INSERT:
if (!bindParameter(m_item_ids)) return false;
if (!bindParameter(m_bidder_ids)) return false;
if (!bindParameter(m_bids)) return false;
if (!bindParameter(m_max_proxy_bids)) return false;
if (!bindParameter(m_numItems)) return false;
break;
case mode_SELECT:
break;
case mode_DELETE:
if (!bindParameter(m_item_ids)) return false;
if (!bindParameter(m_numItems)) return false;
break;
default:
DEBUG_FATAL(true,("Bad query mode."));
}
return true;
}
bool MarketAuctionBidsQuery::bindColumns()
{
return true;
}
void MarketAuctionBidsQuery::getSQL(std::string &sql)
{
switch(mode)
{
case mode_UPDATE:
case mode_INSERT:
sql=std::string("begin ") + DatabaseProcess::getInstance().getSchemaQualifier() +
"cm_persister.insert_market_auction_bids (:item_id, :bidder_id, :bid, :max_proxy_bid, :chunk_size); end;";
break;
case mode_SELECT:
break;
case mode_DELETE:
sql=std::string("begin ") + DatabaseProcess::getInstance().getSchemaQualifier() +
"cm_persister.delete_market_auction_bids (:item_id, :chunk_size ); end;";
break;
default:
DEBUG_FATAL(true,("Bad query mode."));
}
}
MarketAuctionBidsQuerySelect::MarketAuctionBidsQuerySelect(const std::string &schema) :
m_data(ms_fetchBatchSize),
m_schema(schema)
{
}
bool MarketAuctionBidsQuerySelect::bindParameters ()
{
return true;
}
bool MarketAuctionBidsQuerySelect::bindColumns()
{
size_t skipSize = reinterpret_cast<char*>(&(m_data[1])) - reinterpret_cast<char*>(&(m_data[0]));
setColArrayMode(skipSize, ms_fetchBatchSize);
if (!bindCol(m_data[0].item_id)) return false;
if (!bindCol(m_data[0].bidder_id)) return false;
if (!bindCol(m_data[0].bid)) return false;
if (!bindCol(m_data[0].max_proxy_bid)) return false;
return true;
}
const std::vector<MarketAuctionBidsRow> & MarketAuctionBidsQuerySelect::getData() const
{
return m_data;
}
void MarketAuctionBidsQuerySelect::getSQL(std::string &sql)
{
sql=std::string("begin :result := ")+m_schema+"cm_loader.get_bid_list(); end;";
}
DB::Query::QueryMode MarketAuctionBidsQuerySelect::getExecutionMode() const
{
return MODE_PLSQL_REFCURSOR;
}
// ======================================================================
MarketAuctionsAttributesQuery::MarketAuctionsAttributesQuery() :
DatabaseProcessQuery(new MarketAuctionsRow),
m_numItems(0)
{
}
// ----------------------------------------------------------------------
bool MarketAuctionsAttributesQuery::setupData(DB::Session *session)
{
switch(mode)
{
case mode_INSERT:
if (!m_item_ids.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false;
if (!m_attribute_names.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false;
if (!m_attribute_values.create(session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false;
break;
default:
DEBUG_FATAL(true,("Bad query mode."));
}
return true;
}
// ----------------------------------------------------------------------
bool MarketAuctionsAttributesQuery::addData(NetworkId const & itemId, std::string const & attributeName, Unicode::String const & attributeValue)
{
if (!m_item_ids.push_back(itemId)) return false;
if (!m_attribute_names.push_back(attributeName)) return false;
if (!m_attribute_values.push_back(attributeValue)) return false;
m_numItems=m_numItems.getValue() + 1;
return true;
}
// ----------------------------------------------------------------------
int MarketAuctionsAttributesQuery::getNumItems() const
{
return m_numItems.getValue();
}
// ----------------------------------------------------------------------
void MarketAuctionsAttributesQuery::clearData()
{
m_item_ids.clear();
m_attribute_names.clear();
m_attribute_values.clear();
m_numItems=0;
}
// ----------------------------------------------------------------------
void MarketAuctionsAttributesQuery::freeData()
{
m_item_ids.free();
m_attribute_names.free();
m_attribute_values.free();
}
// ----------------------------------------------------------------------
bool MarketAuctionsAttributesQuery::bindParameters()
{
if (!bindParameter(m_item_ids)) return false;
if (!bindParameter(m_attribute_names)) return false;
if (!bindParameter(m_attribute_values)) return false;
if (!bindParameter(m_numItems)) return false;
return true;
}
// ----------------------------------------------------------------------
bool MarketAuctionsAttributesQuery::bindColumns()
{
return true;
}
// ----------------------------------------------------------------------
void MarketAuctionsAttributesQuery::getSQL(std::string &sql)
{
sql=std::string("begin ") + DatabaseProcess::getInstance().getSchemaQualifier() +
"cm_persister.insert_auction_attributes (:item_ids, :attribute_names, :attribute_values, :num_items); end;";
}
// ======================================================================
@@ -0,0 +1,225 @@
// CommoditiesQuery.h
// copyright (c) 2004 Sony Online Entertainment
//
// ======================================================================
#ifndef INCLUDED_CommoditiesQuery_H
#define INCLUDED_CommoditiesQuery_H
// ======================================================================
#include "serverDatabase/DatabaseProcessQuery.h"
#include "sharedDatabaseInterface/DbBindableVarray.h"
#include "sharedDatabaseInterface/DbModeQuery.h"
#include "sharedFoundation/NetworkId.h"
#include "SwgDatabaseServer/CommoditiesSchema.h"
#include <vector>
// ======================================================================
namespace DBQuery
{
class AuctionLocationsQuery : public DatabaseProcessQuery
{
AuctionLocationsQuery(const AuctionLocationsQuery&);
AuctionLocationsQuery& operator= (const AuctionLocationsQuery&);
public:
AuctionLocationsQuery();
virtual bool bindParameters ();
virtual bool bindColumns ();
virtual void getSQL(std::string &sql);
bool setupData(DB::Session *session);
bool addData(const DB::Row *_data);
void clearData();
void freeData();
int getNumItems() const;
private:
DB::BindableVarrayString m_location_ids;
DB::BindableVarrayString m_location_names;
DB::BindableVarrayString m_owner_ids;
DB::BindableVarrayNumber m_sales_taxes;
DB::BindableVarrayString m_sales_tax_bank_ids;
DB::BindableVarrayNumber m_empty_date;
DB::BindableVarrayNumber m_last_access_date;
DB::BindableVarrayNumber m_inactive_date;
DB::BindableVarrayNumber m_status;
DB::BindableVarrayString m_search_enabled;
DB::BindableVarrayNumber m_entrance_charge;
DB::BindableLong m_numItems;
};
class AuctionLocationsQuerySelect : public DB::Query
{
public:
AuctionLocationsQuerySelect(const std::string &schema);
virtual bool bindParameters ();
virtual bool bindColumns ();
virtual void getSQL (std::string &sql);
const std::vector<DBSchema::AuctionLocationsRow> & getData() const;
protected:
virtual QueryMode getExecutionMode() const;
private:
std::vector<DBSchema::AuctionLocationsRow> m_data;
const std::string m_schema;
AuctionLocationsQuerySelect (const AuctionLocationsQuerySelect&);
AuctionLocationsQuerySelect& operator= (const AuctionLocationsQuerySelect&);
};
// ======================================================================
class MarketAuctionsQuery : public DatabaseProcessQuery
{
MarketAuctionsQuery(const MarketAuctionsQuery&);
MarketAuctionsQuery& operator= (const MarketAuctionsQuery&);
public:
MarketAuctionsQuery();
virtual bool bindParameters ();
virtual bool bindColumns ();
virtual void getSQL(std::string &sql);
bool setupData(DB::Session *session);
bool addData(const DB::Row *_data);
void clearData();
void freeData();
int getNumItems() const;
private:
DB::BindableVarrayString m_item_ids;
DB::BindableVarrayString m_owner_ids;
DB::BindableVarrayString m_creator_ids;
DB::BindableVarrayString m_location_ids;
DB::BindableVarrayNumber m_min_bids;
DB::BindableVarrayNumber m_buy_now_prices;
DB::BindableVarrayNumber m_auction_timers;
DB::BindableVarrayString m_oobs;
DB::BindableVarrayString m_user_descriptions;
DB::BindableVarrayNumber m_categories;
DB::BindableVarrayString m_item_names;
DB::BindableVarrayNumber m_item_timers;
DB::BindableVarrayNumber m_actives;
DB::BindableVarrayNumber m_item_sizes;
DB::BindableVarrayNumber m_object_template_ids;
DB::BindableLong m_numItems;
};
class MarketAuctionsQuerySelect : public DB::Query
{
public:
MarketAuctionsQuerySelect(const std::string &schema);
virtual bool bindParameters ();
virtual bool bindColumns ();
virtual void getSQL (std::string &sql);
const std::vector<DBSchema::MarketAuctionsRow> & getData() const;
protected:
virtual QueryMode getExecutionMode() const;
private:
std::vector<DBSchema::MarketAuctionsRow> m_data;
const std::string m_schema;
MarketAuctionsQuerySelect (const MarketAuctionsQuerySelect&);
MarketAuctionsQuerySelect& operator= (const MarketAuctionsQuerySelect&);
};
// ======================================================================
class MarketAuctionBidsQuery : public DatabaseProcessQuery
{
MarketAuctionBidsQuery(const MarketAuctionBidsQuery&);
MarketAuctionBidsQuery& operator= (const MarketAuctionBidsQuery&);
public:
MarketAuctionBidsQuery();
virtual bool bindParameters ();
virtual bool bindColumns ();
virtual void getSQL(std::string &sql);
bool setupData(DB::Session *session);
bool addData(const DB::Row *_data);
void clearData();
void freeData();
int getNumItems() const;
private:
DB::BindableVarrayString m_item_ids;
DB::BindableVarrayString m_bidder_ids;
DB::BindableVarrayNumber m_bids;
DB::BindableVarrayNumber m_max_proxy_bids;
DB::BindableLong m_numItems;
};
class MarketAuctionBidsQuerySelect : public DB::Query
{
public:
MarketAuctionBidsQuerySelect(const std::string &schema);
virtual bool bindParameters ();
virtual bool bindColumns ();
virtual void getSQL (std::string &sql);
const std::vector<DBSchema::MarketAuctionBidsRow> & getData() const;
protected:
virtual QueryMode getExecutionMode() const;
private:
std::vector<DBSchema::MarketAuctionBidsRow> m_data;
const std::string m_schema;
MarketAuctionBidsQuerySelect (const MarketAuctionBidsQuerySelect&);
MarketAuctionBidsQuerySelect& operator= (const MarketAuctionBidsQuerySelect&);
};
// ======================================================================
class MarketAuctionsAttributesQuery : public DatabaseProcessQuery
{
MarketAuctionsAttributesQuery(const MarketAuctionsAttributesQuery&);
MarketAuctionsAttributesQuery& operator= (const MarketAuctionsAttributesQuery&);
public:
MarketAuctionsAttributesQuery();
virtual bool bindParameters ();
virtual bool bindColumns ();
virtual void getSQL(std::string &sql);
bool setupData(DB::Session *session);
bool addData(NetworkId const & itemId, std::string const & attributeName, Unicode::String const & attributeValue);
void clearData();
void freeData();
int getNumItems() const;
private:
DB::BindableVarrayString m_item_ids;
DB::BindableVarrayString m_attribute_names;
DB::BindableVarrayString m_attribute_values;
DB::BindableLong m_numItems;
};
// ======================================================================
} // namespace
#endif
@@ -0,0 +1,230 @@
// copyright (c) 2001 Sony Online Entertainment
//
// Edit the file Schema_h.template. Do not edit Schema.h.
//
// ======================================================================
#ifndef INCLUDED_CommoditiesSchema_H
#define INCLUDED_CommoditiesSchema_H
#include "sharedDatabaseInterface/Bindable.h"
#include "sharedDatabaseInterface/BindableNetworkId.h"
#include "sharedDatabaseInterface/DbRow.h"
namespace DBSchema
{
struct AuctionLocationsRow : public DB::Row
{
AuctionLocationsRow() { ++m_sAuctionRowsCreated; }
~AuctionLocationsRow() { ++m_sAuctionRowsDeleted; }
DB::BindableNetworkId location_id;
DB::BindableString<256> location_name;
DB::BindableNetworkId owner_id;
DB::BindableLong sales_tax;
DB::BindableNetworkId sales_tax_bank_id;
DB::BindableLong empty_date;
DB::BindableLong last_access_date;
DB::BindableLong inactive_date;
DB::BindableLong status;
DB::BindableBool search_enabled;
DB::BindableLong entrance_charge;
virtual void copy(const DB::Row &rhs)
{
*this = dynamic_cast<const AuctionLocationsRow&>(rhs);
}
void setPrimaryKey(const NetworkId &keyValue)
{
location_id.setValue(keyValue);
}
NetworkId getPrimaryKey() const
{
return location_id.getValue();
}
static int getRowsCreated() { return m_sAuctionRowsCreated; }
static int getRowsActive()
{
int i_retval = m_sAuctionRowsCreated - m_sAuctionRowsDeleted;
//if ( i_retval < 0 )
// return 0;
return i_retval;
}
private:
static volatile int m_sAuctionRowsCreated;
static volatile int m_sAuctionRowsDeleted;
};
struct MarketAuctionsRow : public DB::Row
{
MarketAuctionsRow() { ++m_sAuctionRowsCreated; }
~MarketAuctionsRow() { ++m_sAuctionRowsDeleted; }
DB::BindableNetworkId item_id;
DB::BindableNetworkId owner_id;
DB::BindableNetworkId creator_id;
DB::BindableNetworkId location_id;
DB::BindableLong min_bid;
DB::BindableLong buy_now_price;
DB::BindableLong auction_timer;
DB::BindableString<4000> oob;
DB::BindableUnicode<1024>user_description;
DB::BindableLong category;
DB::BindableUnicode<1024>item_name;
DB::BindableLong item_timer;
DB::BindableLong active;
DB::BindableLong item_size;
DB::BindableLong object_template_id;
virtual void copy(const DB::Row &rhs)
{
*this = dynamic_cast<const MarketAuctionsRow&>(rhs);
}
void setPrimaryKey(const NetworkId &keyValue)
{
item_id.setValue(keyValue);
}
NetworkId getPrimaryKey() const
{
return item_id.getValue();
}
static int getRowsCreated() { return m_sAuctionRowsCreated; }
static int getRowsActive()
{
int i_retval = m_sAuctionRowsCreated - m_sAuctionRowsDeleted;
//if ( i_retval < 0 )
// return 0;
return i_retval;
}
private:
static volatile int m_sAuctionRowsCreated;
static volatile int m_sAuctionRowsDeleted;
};
struct MarketAuctionsRowDelete : public DB::Row
{
MarketAuctionsRowDelete() { ++m_sAuctionRowsCreated; }
~MarketAuctionsRowDelete() { ++m_sAuctionRowsDeleted; }
DB::BindableNetworkId item_id;
virtual void copy(const DB::Row &rhs)
{
*this = dynamic_cast<const MarketAuctionsRowDelete&>(rhs);
}
void setPrimaryKey(const NetworkId &keyValue)
{
item_id.setValue(keyValue);
}
NetworkId getPrimaryKey() const
{
return item_id.getValue();
}
static int getRowsCreated() { return m_sAuctionRowsCreated; }
static int getRowsActive()
{
int i_retval = m_sAuctionRowsCreated - m_sAuctionRowsDeleted;
if ( i_retval < 0 )
return 0;
return i_retval;
}
private:
static volatile int m_sAuctionRowsCreated;
static volatile int m_sAuctionRowsDeleted;
};
struct MarketAuctionsRowUpdate : public DB::Row
{
MarketAuctionsRowUpdate() { ++m_sAuctionRowsCreated; }
~MarketAuctionsRowUpdate() { ++m_sAuctionRowsDeleted; }
DB::BindableNetworkId item_id;
DB::BindableNetworkId owner_id;
DB::BindableLong active;
virtual void copy(const DB::Row &rhs)
{
*this = dynamic_cast<const MarketAuctionsRowUpdate&>(rhs);
}
void setPrimaryKey(const NetworkId &keyValue)
{
item_id.setValue(keyValue);
}
NetworkId getPrimaryKey() const
{
return item_id.getValue();
}
static int getRowsCreated() { return m_sAuctionRowsCreated; }
static int getRowsActive()
{
int i_retval = m_sAuctionRowsCreated - m_sAuctionRowsDeleted;
if ( i_retval < 0 )
return 0;
return i_retval;
}
private:
static volatile int m_sAuctionRowsCreated;
static volatile int m_sAuctionRowsDeleted;
};
struct MarketAuctionBidsRow : public DB::Row
{
MarketAuctionBidsRow() { ++m_sAuctionRowsCreated; }
~MarketAuctionBidsRow() { ++m_sAuctionRowsDeleted; }
DB::BindableNetworkId item_id;
DB::BindableNetworkId bidder_id;
DB::BindableLong bid;
DB::BindableLong max_proxy_bid;
virtual void copy(const DB::Row &rhs)
{
*this = dynamic_cast<const MarketAuctionBidsRow&>(rhs);
}
void setPrimaryKey(const NetworkId &keyValue)
{
item_id.setValue(keyValue);
}
NetworkId getPrimaryKey() const
{
return item_id.getValue();
}
static int getRowsCreated() { return m_sAuctionRowsCreated; }
static int getRowsActive()
{
int i_retval = m_sAuctionRowsCreated - m_sAuctionRowsDeleted;
if ( i_retval < 0 )
return 0;
return i_retval;
}
private:
static volatile int m_sAuctionRowsCreated;
static volatile int m_sAuctionRowsDeleted;
};
};
#endif
@@ -0,0 +1,106 @@
// ======================================================================
//
// DeleteDemandLoadedContainerQuery.cpp
// copyright (c) 2003 Sony Online Entertainment
//
// ======================================================================
#include "SwgDatabaseServer/FirstSwgDatabaseServer.h"
#include "SwgDatabaseServer/DeleteDemandLoadedContainerQuery.h"
#include "serverDatabase/DatabaseProcess.h"
#include "sharedFoundation/NetworkId.h"
// ======================================================================
using namespace DBQuery;
// ======================================================================
DeleteDemandLoadedContainerQuery::DeleteDemandLoadedContainerQuery() :
object_ids(),
reasons(),
num_items(0)
{
}
// ----------------------------------------------------------------------
DeleteDemandLoadedContainerQuery::~DeleteDemandLoadedContainerQuery()
{
}
// ----------------------------------------------------------------------
bool DeleteDemandLoadedContainerQuery::bindParameters()
{
if (!bindParameter(object_ids)) return false;
if (!bindParameter(reasons)) return false;
if (!bindParameter(num_items)) return false;
return true;
}
// ----------------------------------------------------------------------
bool DeleteDemandLoadedContainerQuery::bindColumns()
{
return true;
}
// ----------------------------------------------------------------------
void DeleteDemandLoadedContainerQuery::getSQL(std::string &sql)
{
sql=std::string("begin ")+DatabaseProcess::getInstance().getSchemaQualifier()+"persister.delete_demand_container (:object_ids, :reasons, :num_items); end;";
}
// ----------------------------------------------------------------------
DB::Query::QueryMode DeleteDemandLoadedContainerQuery::getExecutionMode() const
{
return MODE_PROCEXEC;
}
// ----------------------------------------------------------------------
bool DeleteDemandLoadedContainerQuery::addData(const NetworkId &networkId, int reason)
{
if (!object_ids.push_back(networkId.getValueString())) return false;
if (!reasons.push_back(reason)) return false;
num_items=num_items.getValue() + 1;
return true;
}
// ----------------------------------------------------------------------
bool DeleteDemandLoadedContainerQuery::setupData(DB::Session &session)
{
if (!object_ids.create(&session, "VAOFSTRING", DatabaseProcess::getInstance().getSchema(),1000)) return false;
if (!reasons.create(&session, "VAOFNUMBER", DatabaseProcess::getInstance().getSchema())) return false;
return true;
}
// ----------------------------------------------------------------------
void DeleteDemandLoadedContainerQuery::clearData()
{
object_ids.clear();
reasons.clear();
}
// ----------------------------------------------------------------------
void DeleteDemandLoadedContainerQuery::freeData()
{
object_ids.free();
reasons.free();
}
// ----------------------------------------------------------------------
int DeleteDemandLoadedContainerQuery::getCount() const
{
return num_items.getValue();
}
// ======================================================================
@@ -0,0 +1,51 @@
// ======================================================================
//
// DeleteDemandLoadedContainerQuery.h
// copyright (c) 2003 Sony Online Entertainment
//
// ======================================================================
#ifndef INCLUDED_DeleteDemandLoadedContainerQuery_H
#define INCLUDED_DeleteDemandLoadedContainerQuery_H
// ======================================================================
#include "sharedDatabaseInterface/DbBindableVarray.h"
#include "sharedDatabaseInterface/DbQuery.h"
// ======================================================================
namespace DBQuery
{
class DeleteDemandLoadedContainerQuery : public DB::Query
{
public:
DeleteDemandLoadedContainerQuery();
~DeleteDemandLoadedContainerQuery();
virtual bool bindParameters();
virtual bool bindColumns();
virtual void getSQL(std::string &sql);
virtual QueryMode getExecutionMode() const;
bool addData(const NetworkId &networkId, int reason);
bool setupData(DB::Session &session);
void clearData();
void freeData();
int getCount() const;
private:
DB::BindableVarrayString object_ids;
DB::BindableVarrayNumber reasons;
DB::BindableLong num_items;
private:
DeleteDemandLoadedContainerQuery(const DeleteDemandLoadedContainerQuery&);
DeleteDemandLoadedContainerQuery& operator=(const DeleteDemandLoadedContainerQuery&);
};
}
// ======================================================================
#endif
@@ -0,0 +1,134 @@
// ======================================================================
//
// ExperienceQuery.cpp
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#include "SwgDatabaseServer/FirstSwgDatabaseServer.h"
#include "SwgDatabaseServer/ExperienceQuery.h"
#include "SwgDatabaseServer/Schema.h"
#include "serverDatabase/ConfigServerDatabase.h"
#include "serverDatabase/DatabaseProcess.h"
// ======================================================================
using namespace DBQuery;
// ======================================================================
ExperienceQuery::ExperienceQuery() :
ModeQuery(new DBSchema::ExperiencePointRow) //lint !e1524 // We don't delete the new row (base class does)
{
}
// ----------------------------------------------------------------------
bool ExperienceQuery::bindParameters()
{
DBSchema::ExperiencePointRow *myData=dynamic_cast<DBSchema::ExperiencePointRow*>(data);
NOT_NULL(myData);
switch(mode)
{
case mode_UPDATE:
case mode_INSERT:
if (!bindParameter(myData->points)) return false;
if (!bindParameter(myData->experience_type)) return false;
if (!bindParameter(myData->object_id)) return false;
break;
case mode_SELECT:
default:
DEBUG_FATAL(true,("Bad query mode."));
}
return true;
}
bool ExperienceQuery::bindColumns()
{
DBSchema::ExperiencePointRow *myData=dynamic_cast<DBSchema::ExperiencePointRow*>(data);
NOT_NULL(myData);
switch(mode)
{
case mode_UPDATE:
case mode_INSERT:
break;
case mode_SELECT:
default:
DEBUG_FATAL(true,("Bad query mode."));
} //lint !e788 //not all modes have an explicit case in the switch
return true;
}
// ----------------------------------------------------------------------
void ExperienceQuery::getSQL(std::string &sql)
{
switch(mode)
{
case mode_UPDATE:
case mode_INSERT:
sql=std::string("begin ")+DatabaseProcess::getInstance().getSchemaQualifier()+"persister.save_experience (:points, :experience_type, :object_id); end;";
break;
case mode_SELECT:
default:
DEBUG_FATAL(true,("Bad query mode."));
}
}
// ======================================================================
DBQuery::GetAllExperience::GetAllExperience(const std::string &schema) :
Query(),
m_data(ConfigServerDatabase::getDefaultFetchBatchSize()),
m_schema(schema)
{
}
bool GetAllExperience::bindParameters()
{
return true;
}
bool GetAllExperience::bindColumns()
{
size_t skipSize = reinterpret_cast<char*>(&(m_data[1])) - reinterpret_cast<char*>(&(m_data[0]));
setColArrayMode(skipSize, m_data.size());
if (!bindCol(m_data[0].object_id)) return false;
if (!bindCol(m_data[0].experience_type)) return false;
if (!bindCol(m_data[0].points)) return false;
return true;
}
// ----------------------------------------------------------------------
void GetAllExperience::getSQL(std::string &sql)
{
sql=std::string("begin :result := ")+m_schema+"loader.load_experience(); end;";
}
// ----------------------------------------------------------------------
DB::Query::QueryMode GetAllExperience::getExecutionMode() const
{
if (getProtocol()==DB::PROTOCOL_OCI)
return (MODE_PLSQL_REFCURSOR);
else
{
FATAL(true,("ODBC mode is not supported for Experience\n"));
return MODE_SQL; // return to avoid compiler warning
}
}
// ======================================================================
@@ -0,0 +1,66 @@
// ======================================================================
//
// ExperienceQuery.h
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#ifndef INCLUDED_ExperienceQuery_H
#define INCLUDED_ExperienceQuery_H
// ======================================================================
#include "sharedDatabaseInterface/DbModeQuery.h"
#include "SwgDatabaseServer/Schema.h"
#include <vector>
// ======================================================================
namespace DBQuery
{
class ExperienceQuery : public DB::ModeQuery
{
ExperienceQuery(const ExperienceQuery&); // disable
ExperienceQuery& operator=(const ExperienceQuery&); // disable
public:
ExperienceQuery();
virtual bool bindParameters();
virtual bool bindColumns();
virtual void getSQL(std::string &sql);
};
// ----------------------------------------------------------------------
class GetAllExperience : public DB::Query
{
public:
GetAllExperience(const std::string &schema);
const std::vector<DBSchema::ExperiencePointRow> &getData() const;
virtual bool bindParameters();
virtual bool bindColumns();
virtual void getSQL(std::string &sql);
virtual QueryMode getExecutionMode() const;
private:
GetAllExperience(const GetAllExperience&); // disable
GetAllExperience& operator=(const GetAllExperience&); // disable
private:
std::vector<DBSchema::ExperiencePointRow> m_data;
const std::string m_schema;
};
}
// ======================================================================
inline const std::vector<DBSchema::ExperiencePointRow> & DBQuery::GetAllExperience::getData() const
{
return m_data;
}
// ======================================================================
#endif

Some files were not shown because too many files have changed in this diff Show More