EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ShipDB.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, Allan
24 */
25 
26 #include "eve-server.h"
27 
28 #include "PyBoundObject.h"
29 #include "ship/ShipDB.h"
30 
31 
33  DBQueryResult res;
34  DBResultRow row;
35  sDatabase.RunQuery(res,
36  "SELECT startDate, shipName, shipID, endDate, ownerID, fraction"
37  " FROM shipInsurance"
38  " WHERE shipID = %u", shipID );
39 
40  if (res.GetRow(row))
41  return DBRowToRow(row);
42 
43  return PyStatic.NewZero();
44 }
45 
47  DBQueryResult res;
48  sDatabase.RunQuery(res,
49  "SELECT startDate, shipName, shipID, endDate, ownerID, fraction"
50  " FROM shipInsurance"
51  " WHERE ownerID = %u", ownerID );
52 
53  return DBResultToRowset(res);
54 }
55 
56 bool ShipDB::InsertInsuranceByShipID(uint32 shipID, std::string name, uint32 ownerID, float fraction, double payOut, bool isCorpItem, uint8 numWeeks) {
57  DBerror err;
58  return sDatabase.RunQuery(err, "INSERT INTO shipInsurance"
59  " (shipID, shipName, ownerID, isCorpItem, startDate, endDate, fraction, payOutAmount)"
60  " VALUES (%u, '%s', %u, %u, %f, %f, %.2f, %f)",
61  shipID, name.c_str(), ownerID, isCorpItem, GetFileTimeNow(), \
62  (GetFileTimeNow() + (EvE::Time::Week * numWeeks)), fraction, payOut );
63 }
64 
66  DBerror err;
67  sDatabase.RunQuery(err, "DELETE FROM shipInsurance WHERE shipID=%u", shipID);
68 }
69 
71  DBQueryResult res;
72  DBResultRow row;
73  sDatabase.RunQuery(res, "SELECT payOutAmount FROM shipInsurance WHERE shipID = %u", shipID);
74  if (res.GetRow(row))
75  return row.GetFloat(0);
76 
78  return 15000; //default to flat 15K for no insurance.
79 }
80 
82 {
83  DBQueryResult res;
84  sDatabase.RunQuery(res, "SELECT ownerID FROM shipInsurance WHERE shipID = %u", shipID );
85  DBResultRow row;
86  if (res.GetRow(row))
87  return true;
88 
89  return false;
90 }
91 
93 {
94  DBerror err;
95  sDatabase.RunQuery(err, "DELETE FROM shipWeaponGroups WHERE shipID = %u", shipID );
96 }
97 
99 {
100  sDatabase.RunQuery(res, "SELECT masterID, slaveID FROM shipWeaponGroups WHERE shipID = %u", shipID );
101 }
102 
103 void ShipDB::SaveWeaponGroups(uint32 shipID, std::multimap< uint32, uint32 >& data)
104 {
105  DBerror err;
106  sDatabase.RunQuery(err, "DELETE FROM shipWeaponGroups WHERE shipID = %u", shipID );
107  std::ostringstream Inserts;
108  // start the insert data.
109  Inserts << "INSERT INTO shipWeaponGroups";
110  Inserts << " (shipID, masterID, slaveID)";
111  bool first = true;
112  for (auto cur : data) {
113  if (first) {
114  Inserts << " VALUES ";
115  first = false;
116  } else {
117  Inserts << ", ";
118  }
119  Inserts << "(" << shipID << ", " << cur.first << ", " << cur.second << ")";
120  }
121 
122  if (!first)
123  if (!sDatabase.RunQuery(err, Inserts.str().c_str()))
124  _log(DATABASE__ERROR, "SaveLinkedWeapons - unable to save data - %s", err.c_str());
125 }
Base Python wire object.
Definition: PyRep.h:66
unsigned __int8 uint8
Definition: eve-compat.h:46
#define sDatabase
Definition: dbcore.h:199
#define _log(type, fmt,...)
Definition: logsys.h:124
float GetFloat(uint32 index) const
Definition: dbcore.cpp:682
PyRep * GetInsuranceByOwnerID(uint32 ownerID)
Definition: ShipDB.cpp:46
static void SaveWeaponGroups(uint32 shipID, std::multimap< uint32, uint32 > &data)
Definition: ShipDB.cpp:103
bool GetRow(DBResultRow &into)
Definition: dbcore.cpp:552
PyObject * DBRowToRow(DBResultRow &row, const char *type)
Definition: EVEDBUtils.cpp:208
const char * c_str() const
Definition: dbcore.h:48
static void LoadWeaponGroups(uint32 shipID, DBQueryResult &res)
Definition: ShipDB.cpp:98
bool IsShipInsured(uint32 shipID)
Definition: ShipDB.cpp:81
PyObject * DBResultToRowset(DBQueryResult &result)
Definition: EVEDBUtils.cpp:81
static void DeleteInsuranceByShipID(uint32 shipID)
Definition: ShipDB.cpp:65
#define PyStatic
Definition: PyRep.h:1209
float GetShipInsurancePayout(uint32 shipID)
Definition: ShipDB.cpp:70
unsigned __int32 uint32
Definition: eve-compat.h:50
double GetFileTimeNow()
Definition: utils_time.cpp:84
PyRep * GetInsuranceByShipID(uint32 shipID)
Definition: ShipDB.cpp:32
bool InsertInsuranceByShipID(uint32 shipID, std::string name, uint32 ownerID, float level, double payOut, bool isCorpItem=false, uint8 numWeeks=12)
Definition: ShipDB.cpp:56
Definition: dbcore.h:39
static void ClearWeaponGroups(uint32 shipID)
Definition: ShipDB.cpp:92