EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
CalendarDB.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: Allan
24 */
25 
26 
27 #include "eve-server.h"
28 
29 #include "../../eve-common/EVE_Calendar.h"
30 #include "system/CalendarDB.h"
31 
32 
34 {
35  DBerror err;
36  sDatabase.RunQuery(err, "UPDATE sysCalendarEvents SET isDeleted = 1 WHERE eventID = %u", eventID);
37 }
38 
39 // for personal char events
40 PyRep* CalendarDB::SaveNewEvent(uint32 ownerID, Call_CreateEventWithInvites& args)
41 {
43  data = GetTimeParts(args.startDateTime);
44 
45  DBerror err;
46  if (!args.invitees->empty()) {
47  bool comma(false);
48  std::ostringstream str;
49  PyList* list(args.invitees->AsList());
50  PyList::const_iterator itr = list->begin(), end = list->end();
51  while (itr != end) {
52  if (comma) {
53  str << ",";
54  } else {
55  comma = true;
56  }
57  str << *itr;
58  ++itr;
59  }
60 
61  sDatabase.RunQuery(err,
62  "INSERT INTO `sysCalendarInvitees`(`eventID`, `inviteeList`)"
63  " VALUES %s", str.str().c_str());
64  }
65 
66  uint32 eventID(0);
67  if (args.duration) {
68  if (!sDatabase.RunQueryLID(err, eventID,
69  "INSERT INTO sysCalendarEvents(ownerID, creatorID, eventDateTime, eventDuration, importance,"
70  " eventTitle, eventText, flag, month, year)"
71  " VALUES (%u, %u, %li, %u, %u, '%s', '%s', %u, %u, %u)",
72  ownerID, ownerID, args.startDateTime, args.duration, args.important, args.title.c_str(),
73  args.description.c_str(), Calendar::Flag::Personal, data.month, data.year))
74  {
75  codelog(DATABASE__ERROR, "Error in SaveNewEvent query: %s", err.c_str());
76  return PyStatic.NewZero();
77  }
78  } else {
79  if (!sDatabase.RunQueryLID(err, eventID,
80  "INSERT INTO sysCalendarEvents(ownerID, creatorID, eventDateTime, importance,"
81  " eventTitle, eventText, flag, month, year)"
82  " VALUES (%u, %u, %li, %u, '%s', '%s', %u, %u, %u)",
83  ownerID, ownerID, args.startDateTime, args.important, args.title.c_str(),
84  args.description.c_str(), Calendar::Flag::Personal, data.month, data.year))
85  {
86  codelog(DATABASE__ERROR, "Error in SaveNewEvent query: %s", err.c_str());
87  return PyStatic.NewZero();
88  }
89  }
90 
91  return new PyInt(eventID);
92 }
93 
94 // for corp/alliance events
95 PyRep* CalendarDB::SaveNewEvent(uint32 ownerID, uint32 creatorID, Call_CreateEvent &args)
96 {
98  if (IsCharacterID(ownerID)) {
100  } else if (IsCorp(ownerID)) { // this would also be Automated for pos fuel
101  flag = Calendar::Flag::Corp;
102  } else if (IsAlliance(ownerID)) {
104  } else if (ownerID == 1) {
105  flag = Calendar::Flag::CCP;
106  } else {
108  }
109 
111  data = GetTimeParts(args.startDateTime);
112 
113  uint32 eventID(0);
114  DBerror err;
115  if (args.duration) {
116  if (!sDatabase.RunQueryLID(err, eventID,
117  "INSERT INTO sysCalendarEvents(ownerID, creatorID, eventDateTime, eventDuration, importance,"
118  " eventTitle, eventText, flag, month, year)"
119  " VALUES (%u, %u, %li, %u, %u, '%s', '%s', %u, %u, %u)",
120  ownerID, creatorID, args.startDateTime, args.duration, args.important,
121  args.title.c_str(), args.description.c_str(), flag, data.month, data.year))
122  {
123  codelog(DATABASE__ERROR, "Error in SaveNewEvent query: %s", err.c_str());
124  return PyStatic.NewZero();
125  }
126  } else {
127  if (!sDatabase.RunQueryLID(err, eventID,
128  "INSERT INTO sysCalendarEvents(ownerID, creatorID, eventDateTime, importance,"
129  " eventTitle, eventText, flag, month, year)"
130  " VALUES (%u, %u, %li, %u, '%s', '%s', %u, %u, %u)",
131  ownerID, creatorID, args.startDateTime, args.important,
132  args.title.c_str(), args.description.c_str(), flag, data.month, data.year))
133  {
134  codelog(DATABASE__ERROR, "Error in SaveNewEvent query: %s", err.c_str());
135  return PyStatic.NewZero();
136  }
137  }
138 
139  return new PyInt(eventID);
140 }
141 
142 // for system/auto events
143 uint32 CalendarDB::SaveSystemEvent(uint32 ownerID, uint32 creatorID, int64 startDateTime, uint8 autoEventType,
144  std::string title, std::string description, bool important/*false*/)
145 {
147  data = GetTimeParts(startDateTime);
148 
149  uint32 eventID(0);
150  DBerror err;
151  sDatabase.RunQueryLID(err, eventID,
152  "INSERT INTO sysCalendarEvents(ownerID, creatorID, eventDateTime, autoEventType,"
153  " eventTitle, eventText, flag, month, year, importance)"
154  " VALUES (%u, %u, %li, %u, '%s', '%s', %u, %u, %u, %u)",
155  ownerID, creatorID, startDateTime, autoEventType, title.c_str(), description.c_str(),
156  Calendar::Flag::Automated, data.month, data.year, important?1:0);
157 
158  return eventID;
159 }
160 
161 
163 {
164  if (ownerID == 0)
165  return nullptr;
166 
167  DBQueryResult res;
168  if (!sDatabase.RunQuery(res,
169  "SELECT eventID, ownerID, eventDateTime, dateModified, eventDuration, importance, eventTitle, flag,"
170  " autoEventType, isDeleted"
171  " FROM sysCalendarEvents WHERE ownerID = %u AND month = %u AND year = %u", ownerID, month, year))
172  {
173  codelog(DATABASE__ERROR, "Error in GetEventList query: %s", res.error.c_str());
174  return nullptr;
175  }
176 
177  if (res.GetRowCount() < 1)
178  return nullptr;
179 
180  DBResultRow row;
181  PyList* list = new PyList();
182  while (res.GetRow(row)) {
183  PyDict* dict = new PyDict();
184  dict->SetItemString("eventID", new PyInt(row.GetInt(0)));
185  dict->SetItemString("ownerID", new PyInt(row.GetInt(1)));
186  dict->SetItemString("eventDateTime", new PyLong(row.GetInt64(2)));
187  dict->SetItemString("dateModified", row.IsNull(3) ? PyStatic.NewNone() : new PyLong(row.GetInt64(3)));
188  dict->SetItemString("eventDuration", row.IsNull(4) ? PyStatic.NewNone() : new PyInt(row.GetInt(4)));
189  dict->SetItemString("importance", new PyBool(row.GetBool(5)));
190  dict->SetItemString("eventTitle", new PyString(row.GetText(6)));
191  dict->SetItemString("flag", new PyInt(row.GetInt(7)));
192  // client patch to allow non-corp automated events for ram jobs
193  if (row.GetInt(7) == Calendar::Flag::Automated)
194  dict->SetItemString("autoEventType", new PyInt(row.GetInt(8)));
195  dict->SetItemString("isDeleted", new PyBool(row.GetBool(9)));
196  list->AddItem(new PyObject("util.KeyVal", dict));
197  }
198 
199  return list;
200 }
201 
203 {
204  if (eventID == 0)
205  return nullptr;
206 
207  DBQueryResult res;
208  if (!sDatabase.RunQuery(res,
209  "SELECT ownerID, creatorID, eventText"
210  " FROM sysCalendarEvents WHERE eventID = %u", eventID))
211  {
212  codelog(DATABASE__ERROR, "Error in GetEventList query: %s", res.error.c_str());
213  return nullptr;
214  }
215 
216  DBResultRow row;
217  if (!res.GetRow(row))
218  return nullptr;
219 
220  PyDict* dict = new PyDict();
221  dict->SetItemString("eventID", new PyInt(eventID));
222  dict->SetItemString("ownerID", new PyInt(row.GetInt(0)));
223  dict->SetItemString("creatorID", new PyInt(row.GetInt(1)));
224  dict->SetItemString("eventText", new PyString(row.GetText(2)));
225 
226  return new PyObject("util.KeyVal", dict);
227 }
228 
229 void CalendarDB::SaveEventResponse(uint32 charID, Call_SendEventResponse& args)
230 {
231  DBerror err;
232  sDatabase.RunQuery(err,
233  "INSERT INTO `sysCalendarResponses`(`eventID`, `charID`, `response`)"
234  " VALUES (%u, %u, %u)", args.eventID, charID, args.response);
235 }
236 
238 {
239  DBQueryResult res;
240  if (!sDatabase.RunQuery(res,"SELECT eventID, response FROM sysCalendarResponses WHERE charID = %u", charID)) {
241  codelog(DATABASE__ERROR, "Error in GetEventList query: %s", res.error.c_str());
242  return nullptr;
243  }
244 
245  DBResultRow row;
246  PyList *list = new PyList();
247  while (res.GetRow(row)) {
248  // list char response for each event
249  PyDict* dict = new PyDict();
250  dict->SetItemString("eventID", new PyInt(row.GetInt(0)));
251  dict->SetItemString("status", new PyInt(row.GetInt(1)));
252  list->AddItem(new PyObject("util.KeyVal", dict));
253  }
254 
255  return list;
256 }
257 
259 {
260  DBQueryResult res;
261  if (!sDatabase.RunQuery(res,"SELECT charID, response FROM sysCalendarResponses WHERE eventID = %u", eventID)) {
262  codelog(DATABASE__ERROR, "Error in GetEventList query: %s", res.error.c_str());
263  return nullptr;
264  }
265 
266  DBResultRow row;
267  PyList *list = new PyList();
268  while (res.GetRow(row)) {
269  // list char response for each event
270  PyDict* dict = new PyDict();
271  dict->SetItemString("characterID", new PyInt(row.GetInt(0)));
272  dict->SetItemString("status", new PyInt(row.GetInt(1)));
273  list->AddItem(new PyObject("util.KeyVal", dict));
274  }
275 
276  return list;
277 }
278 
279 void CalendarDB::UpdateEventParticipants(Call_UpdateEventParticipants& args)
280 {
281  DBerror err;
282 }
283 
284 
285 
static PyRep * GetEventDetails(uint32 eventID)
Definition: CalendarDB.cpp:202
Base Python wire object.
Definition: PyRep.h:66
unsigned __int8 uint8
Definition: eve-compat.h:46
static PyRep * SaveNewEvent(uint32 ownerID, Call_CreateEventWithInvites &args)
Definition: CalendarDB.cpp:40
#define sDatabase
Definition: dbcore.h:199
const char * GetText(uint32 index) const
Definition: dbcore.h:104
static void SaveEventResponse(uint32 charID, Call_SendEventResponse &args)
Definition: CalendarDB.cpp:229
Python string.
Definition: PyRep.h:430
int32 GetInt(uint32 index) const
Definition: dbcore.cpp:635
Python's dictionary.
Definition: PyRep.h:719
const_iterator begin() const
Definition: PyRep.h:660
storage_type::const_iterator const_iterator
Definition: PyRep.h:644
static uint32 SaveSystemEvent(uint32 ownerID, uint32 creatorID, int64 startDateTime, uint8 autoEventType, std::string title, std::string description, bool important=false)
Definition: CalendarDB.cpp:143
static void UpdateEventParticipants(Call_UpdateEventParticipants &args)
Definition: CalendarDB.cpp:279
void AddItem(PyRep *i)
Definition: PyRep.h:701
* args
bool GetRow(DBResultRow &into)
Definition: dbcore.cpp:552
bool GetBool(uint32 index) const
Definition: dbcore.cpp:647
Python boolean.
Definition: PyRep.h:323
const char * c_str() const
Definition: dbcore.h:48
Python object.
Definition: PyRep.h:826
static PyRep * GetResponsesForCharacter(uint32 charID)
Definition: CalendarDB.cpp:237
#define codelog(type, fmt,...)
Definition: logsys.h:128
Python integer.
Definition: PyRep.h:231
#define PyStatic
Definition: PyRep.h:1209
bool IsNull(uint32 index) const
Definition: dbcore.h:102
static PyRep * GetEventList(uint32 ownerID, uint32 month, uint32 year)
Definition: CalendarDB.cpp:162
#define IsCharacterID(itemID)
Definition: EVE_Defines.h:206
unsigned __int32 uint32
Definition: eve-compat.h:50
#define IsCorp(itemID)
Definition: EVE_Defines.h:234
static PyRep * GetResponsesToEvent(uint32 eventID)
Definition: CalendarDB.cpp:258
DBerror error
Definition: dbcore.h:69
signed __int64 int64
Definition: eve-compat.h:51
EvE::TimeParts GetTimeParts(int64 filetime)
Definition: utils_time.cpp:157
size_t GetRowCount()
Definition: dbcore.h:72
#define IsAlliance(itemID)
Definition: EVE_Defines.h:244
static void DeleteEvent(uint32 eventID)
Definition: CalendarDB.cpp:33
int64 GetInt64(uint32 index) const
Definition: dbcore.cpp:670
Definition: dbcore.h:39
Python list.
Definition: PyRep.h:639
void SetItemString(const char *key, PyRep *value)
SetItemString adds or sets a database entry.
Definition: PyRep.h:812
Python long integer.
Definition: PyRep.h:261