EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
FactionWarMgrDB.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  * FACWAR__DB_ERROR
31  * FACWAR__DB_WARNING
32  * FACWAR__DB_INFO
33  * FACWAR__DB_MESSAGE
34  */
35 
37  DBQueryResult res;
38 
39  if (!sDatabase.RunQuery(res,
40  "SELECT factionID, militiaCorporationID"
41  " FROM facFactions"
42  " WHERE militiaCorporationID IS NOT NULL"))
43  {
44  _log(DATABASE__ERROR, "Failed to query war factions: %s.", res.error.c_str());
45  return nullptr;
46  }
47 
48  return DBResultToIntIntDict(res);
49 }
50 
52 { /* done -allan 03May16 */
53  DBQueryResult res;
54  if (!sDatabase.RunQuery(res,
55  "SELECT systemID, occupierID, factionID FROM facWarSystems"))
56  {
57  _log(DATABASE__ERROR, "Failed to query war factions: %s.", res.error.c_str());
58  return nullptr;
59  }
60 
61  PyDict* result = new PyDict();
62  PyDict* dict;
63  DBResultRow row;
64  while (res.GetRow(row)) {
65  dict = new PyDict();
66  dict->SetItemString("occupierID", new PyInt(row.GetInt(1)));
67  dict->SetItemString("factionID", new PyInt(row.GetInt(2)));
68  result->SetItem(new PyInt(row.GetInt(0)), dict );
69  }
70  return result;
71 }
72 
74  DBQueryResult res;
75 
76  if (!sDatabase.RunQuery(res,
77  "SELECT militiaCorporationID"
78  " FROM facFactions"
79  " WHERE factionID=%u",
80  factionID))
81  {
82  _log(DATABASE__ERROR, "Failed to query militia corporation for faction %u: %s.", factionID, res.error.c_str());
83  return 0;
84  }
85 
86  DBResultRow row;
87  if (!res.GetRow(row)) {
88  _log(FACWAR__DB_WARNING, "Faction %u not found.", factionID);
89  return 0;
90  }
91 
92  return row.GetUInt(0);
93 }
94 
Base Python wire object.
Definition: PyRep.h:66
#define sDatabase
Definition: dbcore.h:199
#define _log(type, fmt,...)
Definition: logsys.h:124
int32 GetInt(uint32 index) const
Definition: dbcore.cpp:635
Python's dictionary.
Definition: PyRep.h:719
uint32 GetUInt(uint32 index) const
Definition: dbcore.cpp:658
uint32 GetFactionMilitiaCorporation(const uint32 factionID)
PyDict * DBResultToIntIntDict(DBQueryResult &result)
Definition: EVEDBUtils.cpp:273
bool GetRow(DBResultRow &into)
Definition: dbcore.cpp:552
const char * c_str() const
Definition: dbcore.h:48
Python integer.
Definition: PyRep.h:231
PyRep * GetWarFactions()
unsigned __int32 uint32
Definition: eve-compat.h:50
DBerror error
Definition: dbcore.h:69
PyRep * GetFacWarSystems()
void SetItem(PyRep *key, PyRep *value)
SetItem adds or sets a database entry.
Definition: PyRep.cpp:713
void SetItemString(const char *key, PyRep *value)
SetItemString adds or sets a database entry.
Definition: PyRep.h:812