EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
CertificateMgrDB.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 */
25 
26 #include "eve-server.h"
27 
29 
30 //PyRep* CertificateMgrDB::GetMyCertificates( uint32 characterID )
31 //{
32 // sLog.Debug( "CertificateMgrDB", "Called GetMyCertificates stub." );
33 //
34 // util_Rowset rs;
35 //
36 // rs.header.push_back( "certificateID" );
37 // rs.header.push_back( "grantDate" );
38 // rs.header.push_back( "visiblityFlags" );
39 //
40 // return rs.Encode();
41 //}
42 
44  DBQueryResult res;
45  if (!sDatabase.RunQuery(res, "SELECT categoryID, categoryName, description, dataID, categoryNameID FROM crtCategories")) {
46  codelog(DATABASE__ERROR, "Failed to query certificate categories: %s.", res.error.c_str());
47  return PyStatic.NewNone();
48  }
49 
50  return(DBResultToIndexRowset(res, "categoryID"));
51 }
52 
54  DBQueryResult res;
55  if (!sDatabase.RunQuery(res, "SELECT shipTypeID, certificateID, recommendationLevel, recommendationID FROM crtRecommendations")) {
56  codelog(DATABASE__ERROR, "Failed to query certificate categories: %s.", res.error.c_str());
57  return PyStatic.NewNone();
58  }
59 
60  return DBResultToRowset(res);
61 }
62 
64  DBQueryResult res;
65  if (!sDatabase.RunQuery(res, "SELECT classID, className, classNameID, description, dataID FROM crtClasses")) {
66  codelog(DATABASE__ERROR, "Failed to query certificate classes: %s.", res.error.c_str());
67  return PyStatic.NewNone();
68  }
69 
70  return DBResultToIntRowDict(res, 0);
71 }
72 
73 
75  DBerror err;
76  if (!sDatabase.RunQuery( err,
77  "INSERT INTO chrCertificates (characterID, certificateID, grantDate, visibilityFlags)"
78  " VALUES (%u, %u, %li, %u)", charID, cert.certificateID, cert.grantDate, cert.visibilityFlags)) {
79  _log(DATABASE__ERROR, "Failed to insert certificates of character %u: %s", charID, err.c_str() );
80  }
81 }
82 
83 void CertificateMgrDB::UpdateCertificate ( uint32 charID, uint32 certificateID, bool pub ) {
84  DBerror err;
85  if (!sDatabase.RunQuery( err,
86  "UPDATE chrCertificates SET visibilityFlags = %u WHERE characterID = %u AND certificateID = %u", (pub ? 1 : 0), charID, certificateID)) {
87  _log(DATABASE__ERROR, "Failed to insert certificates of character %u: %s", charID, err.c_str() );
88  }
89 }
90 
91 
93 {
94  DBQueryResult res;
95  if ( !sDatabase.RunQuery( res, "SELECT certificateID, grantDate, visibilityFlags FROM chrCertificates WHERE characterID=%u", characterID)) {
96  _log(DATABASE__ERROR, "Failed to query certificates of character %u: %s", characterID, res.error.c_str() );
97  return false;
98  }
99 
100  DBResultRow row;
101  while (res.GetRow(row)) {
102  CharCerts cert = CharCerts();
103  cert.certificateID = row.GetUInt( 0 );
104  cert.grantDate = row.GetInt64( 1 );
105  cert.visibilityFlags = row.GetBool( 2 );
106  into.emplace(row.GetUInt( 0 ), cert );
107  }
108 
109  return true;
110 }
111 
112 bool CertificateMgrDB::SaveCertificates( uint32 characterID, const CertMap &data )
113 {
114  std::ostringstream Inserts;
115  // start the insert into command.
116  Inserts << "INSERT INTO chrCertificates";
117  Inserts << " (characterID, certificateID, grantDate, visibilityFlags)";
118  bool first = true;
119  for (auto cur : data) {
120  if (first) {
121  Inserts << " VALUES ";
122  first = false;
123  } else {
124  Inserts << ", ";
125  }
126  Inserts << "(" << characterID << ", " << cur.first << ", " << cur.second.grantDate << ", " << cur.second.visibilityFlags << ")";
127  }
128 
129  if (!first) {
130  Inserts << "ON DUPLICATE KEY UPDATE ";
131  Inserts << "visibilityFlags=VALUES(visibilityFlags)";
132  DBerror err;
133  if (!sDatabase.RunQuery(err, Inserts.str().c_str()))
134  _log(DATABASE__ERROR, "SaveCertificates - unable to save data - %s", err.c_str());
135  }
136  return true;
137 }
Base Python wire object.
Definition: PyRep.h:66
#define sDatabase
Definition: dbcore.h:199
PyRep * GetAllShipCertificateRecommendations()
bool LoadCertificates(uint32 characterID, CertMap &into)
#define _log(type, fmt,...)
Definition: logsys.h:124
bool SaveCertificates(uint32 characterID, const CertMap &from)
PyRep * GetCertificateClasses()
uint32 GetUInt(uint32 index) const
Definition: dbcore.cpp:658
uint32 certificateID
void UpdateCertificate(uint32 charID, uint32 certificateID, bool pub=false)
std::map< uint16, CharCerts > CertMap
bool GetRow(DBResultRow &into)
Definition: dbcore.cpp:552
bool GetBool(uint32 index) const
Definition: dbcore.cpp:647
const char * c_str() const
Definition: dbcore.h:48
PyDict * DBResultToIntRowDict(DBQueryResult &result, uint32 key_index, const char *type)
Definition: EVEDBUtils.cpp:257
#define codelog(type, fmt,...)
Definition: logsys.h:128
PyObject * DBResultToRowset(DBQueryResult &result)
Definition: EVEDBUtils.cpp:81
#define PyStatic
Definition: PyRep.h:1209
PyRep * GetCertificateCategories()
unsigned __int32 uint32
Definition: eve-compat.h:50
PyObject * DBResultToIndexRowset(DBQueryResult &result, const char *key)
Definition: EVEDBUtils.cpp:144
uint8 visibilityFlags
void AddCertificate(uint32 charID, CharCerts cert)
DBerror error
Definition: dbcore.h:69
int64 grantDate
int64 GetInt64(uint32 index) const
Definition: dbcore.cpp:670
Definition: dbcore.h:39