EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
StandingDB.cpp
Go to the documentation of this file.
1 /*
2  ------------------------------------------------------------------------------------
3  LICENSE:
4  ------------------------------------------------------------------------------------
5  This file is part of EVEmu: EVE Online Server Emulator
6  Copyright 2006 - 2021 The EVEmu Team
7  For the latest information visit https://evemu.dev
8  ------------------------------------------------------------------------------------
9  This program is free software; you can redistribute it and/or modify it under
10  the terms of the GNU Lesser General Public License as published by the Free Software
11  Foundation; either version 2 of the License, or (at your option) any later
12  version.
13 
14  This program is distributed in the hope that it will be useful, but WITHOUT
15  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General Public License along with
19  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
20  Place - Suite 330, Boston, MA 02111-1307, USA, or go to
21  http://www.gnu.org/copyleft/lesser.txt.
22  ------------------------------------------------------------------------------------
23  Author: Zhur
24  Rewrite: Allan
25 */
26 
27 #include "Client.h"
28 #include "StaticDataMgr.h"
29 #include "standing/StandingDB.h"
30 
31 /* re-write of standing system -allan 10Apr15
32  * DB tables have identical field names for ease of implementation
33  * Get Fields
34  * toID = me|myCorp|myAlliance
35  * fromID = char|agent|corp|faction|alliance
36  * standing = fraction representing current value
37  * Set Fields
38  * toID = char|agent|corp|faction|alliance
39  * fromID = me|myCorp|myAlliance
40  * standing = fraction representing current value
41 
42  DB tables [fields] (notes)
43  repFactions [fromID, toID, standing] (NPC Faction<-->NPC Faction) {populated, hard-coded -- cant change}
44  repStandings [fromID, toID, standing] (agent-->char, agent-->PC corp -- changed by missions status')
45  repStandings [fromID, toID, standing] (corporation<-->alliance, alliance<-->alliance -- changed thru Corp window)
46  repStandings [fromID, toID, standing] (corporation-->character, corporation<-->corporation -- changed thru Corp window)
47  repStandings [fromID, toID, standing] (character<-->character, character-->corporation -- changed thru PnP window)
48  repStandings [fromID, toID, standing] (NPC corp-->char, NPC corp-->PC corp -- changed by missions and faction kills)
49 
50  all change logs will go here. not sure of all fields yet
51  repStandingChanges [fromID, toID, eventID, eventTypeID, eventDateTime, modification, originalFromID, originalToID, int_1, int_2, int_3, msg] ()
52 
53  http://www.eveinfo.net/wiki/ind~4067.htm
54  */
55 
57 {
58  // repFactions table is ONLY faction standings
59  DBQueryResult res;
60  sDatabase.RunQuery(res, "SELECT fromID,toID,standing FROM repFactions");
61  return DBResultToCRowset(res);
62 }
63 
65 {
66  DBQueryResult res;
67  sDatabase.RunQuery(res, "SELECT fromID, standing AS rank FROM repStandings WHERE toID = %u", charID);
68  return DBResultToCRowset(res);
69 }
70 
72 {
73  DBQueryResult res;
74  sDatabase.RunQuery(res, "SELECT fromID, toID, standing FROM repStandings WHERE toID = %u OR fromID = %u",
75  pClient->GetCharacterID(), pClient->GetCharacterID());
76  return DBResultToCRowset(res);
77 }
78 
80 {
81  DBQueryResult res;
82  sDatabase.RunQuery(res, "SELECT fromID, toID, standing FROM repStandings WHERE toID = %u OR fromID = %u", pClient->GetCorporationID(), pClient->GetCorporationID());
83  return DBResultToCRowset(res);
84 }
85 
87 {
88  DBQueryResult res;
89  sDatabase.RunQuery(res, "SELECT fromID, toID, standing FROM chrNPCStandings WHERE toID = %u", charID);
90  return DBResultToCRowset(res);
91 }
92 
95 {
96  DBQueryResult res;
97  if (!sDatabase.RunQuery(res,
98  "SELECT "
99  " itemID AS ownerID,"
100  " itemName AS ownerName,"
101  " typeID"
102  " FROM entity"
103  " WHERE itemID < 0"))
104  {
105  _log(DATABASE__ERROR, "Error in PrimeCharStandings query: %s", res.error.c_str());
106  return nullptr;
107  }
108 
109  return DBResultToRowset(res);
110 }
111 
112 PyRep *StandingDB::GetStandingTransactions(Call_GetStandingTransactions &args)
113 {
114  //GetStandingTransactions(fromID, toID, direction, eventID, eventType, eventDateTime)
117  DBQueryResult res;
118  if (!sDatabase.RunQuery(res,
119  "SELECT"
120  " eventID,"
121  " eventTypeID,"
122  " eventDateTime,"
123  " fromID,"
124  " toID,"
125  " modification,"
126  " originalFromID,"
127  " originalToID,"
128  " int_1,"
129  " int_2,"
130  " int_3,"
131  " msg"
132  " FROM repStandingChanges"
133  " WHERE toID = %u AND fromID = %u",
134  args.toID, args.fromID))
135  {
136  codelog(SERVICE__ERROR, "Error in query: %s", res.error.c_str());
137  return nullptr;
138  }
139  return DBResultToRowset(res);
140 }
141 
143 {
144  DBQueryResult res;
145  sDatabase.RunQuery(res, "SELECT standing FROM repStandings WHERE fromID=%u AND toID=%u", fromID, toID);
146  DBResultRow row;
147  if (res.GetRow(row))
148  {
149  return row.GetFloat(0);
150  }
151  else
152  {
153  return 0.0f;
154  }
155 }
156 
157 void StandingDB::SetStanding(uint32 fromID, uint32 toID, float standing)
158 {
159  DBerror err;
160  sDatabase.RunQuery(err, "INSERT INTO repStandings (fromID, toID, standing) VALUES (%u,%u,%f)", fromID, toID, standing);
161 }
162 
163 void StandingDB::UpdateStanding(uint32 fromID, uint32 toID, float standing)
164 {
165  DBerror err;
166  sDatabase.RunQuery(err,
167  "INSERT INTO repStandings (fromID, toID, standing)"
168  " VALUES (%u,%u,%f)"
169  " ON DUPLICATE KEY UPDATE standing = standing + %f",
170  fromID, toID, standing, standing);
171 }
172 
174 void StandingDB::SaveStandingChanges(uint32 fromID, uint32 toID, uint16 eventType, float amount, std::string msg)
175 {
176  /* eventTypeID,eventDateTime,fromID,toID,modification,originalFromID,originalToID,int_1,int_2,int_3,msg */
177  DBerror err;
178  sDatabase.RunQuery(err,
179  "INSERT INTO repStandingChanges (eventTypeID, eventDateTime, fromID, toID, modification, msg)"
180  " VALUES (%u, %f, %u, %u, %f, '%s' )",
181  eventType, GetFileTimeNow(), fromID, toID, amount, msg.c_str());
182 }
183 
185 {
186  // ownerID, standing ...
187 
188  return PyStatic.NewNone();
189 }
static float GetStanding(uint32 fromID, uint32 toID)
Definition: StandingDB.cpp:142
Base Python wire object.
Definition: PyRep.h:66
PyRep * GetCharNPCStandings(uint32 charID)
Definition: StandingDB.cpp:86
#define sDatabase
Definition: dbcore.h:199
#define _log(type, fmt,...)
Definition: logsys.h:124
float GetFloat(uint32 index) const
Definition: dbcore.cpp:682
PyObjectEx * DBResultToCRowset(DBQueryResult &result)
Definition: EVEDBUtils.cpp:402
static PyObjectEx * GetFactionStandings()
Definition: StandingDB.cpp:56
int32 GetCharacterID() const
Definition: Client.h:113
int32 GetCorporationID() const
Definition: Client.h:123
* args
bool GetRow(DBResultRow &into)
Definition: dbcore.cpp:552
Python extended object.
Definition: PyRep.h:861
static void UpdateStanding(uint32 fromID, uint32 toID, float standing)
Definition: StandingDB.cpp:163
static PyRep * GetMyStandings(uint32 charID)
Definition: StandingDB.cpp:64
const char * c_str() const
Definition: dbcore.h:48
#define codelog(type, fmt,...)
Definition: logsys.h:128
PyObject * DBResultToRowset(DBQueryResult &result)
Definition: EVEDBUtils.cpp:81
PyRep * GetStandingTransactions(Call_GetStandingTransactions &args)
Definition: StandingDB.cpp:112
#define PyStatic
Definition: PyRep.h:1209
Definition: Client.h:66
PyRep * PrimeCharStandings(uint32 charID)
Definition: StandingDB.cpp:94
unsigned __int32 uint32
Definition: eve-compat.h:50
PyRep * GetCorpStandings(Client *pClient)
Definition: StandingDB.cpp:79
static void SetStanding(uint32 fromID, uint32 toID, float standing)
Definition: StandingDB.cpp:157
double GetFileTimeNow()
Definition: utils_time.cpp:84
PyRep * GetCharStandings(Client *pClient)
Definition: StandingDB.cpp:71
DBerror error
Definition: dbcore.h:69
PyRep * GetStandingCompositions(uint32 fromID, uint32 toID)
Definition: StandingDB.cpp:184
static void SaveStandingChanges(uint32 fromID, uint32 toID, uint16 eventType, float amount, std::string msg)
Definition: StandingDB.cpp:174
unsigned __int16 uint16
Definition: eve-compat.h:48
Definition: dbcore.h:39