EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
MailMgrService.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: Luck, caytchen
24 */
25 
26 #include "eve-server.h"
27 
28 #include "PyServiceCD.h"
29 #include "mail/MailDB.h"
30 #include "mail/MailMgrService.h"
31 #include "EVE_Mail.h"
32 
34 
36 : PyService(mgr, "mailMgr"),
37  m_dispatch(new Dispatcher(this)),
38  m_db(new MailDB())
39 {
40  _SetCallDispatcher(m_dispatch);
42  PyCallable_REG_CALL(MailMgrService, PrimeOwners);
44  PyCallable_REG_CALL(MailMgrService, GetMailHeaders);
45  PyCallable_REG_CALL(MailMgrService, MoveToTrash);
46  PyCallable_REG_CALL(MailMgrService, MoveFromTrash);
47  PyCallable_REG_CALL(MailMgrService, MarkAsUnread);
49  PyCallable_REG_CALL(MailMgrService, MoveAllToTrash);
50  PyCallable_REG_CALL(MailMgrService, MoveToTrashByLabel);
51  PyCallable_REG_CALL(MailMgrService, MoveToTrashByList);
52  PyCallable_REG_CALL(MailMgrService, MarkAllAsUnread);
53  PyCallable_REG_CALL(MailMgrService, MarkAsUnreadByLabel);
54  PyCallable_REG_CALL(MailMgrService, MarkAsUnreadByList);
55  PyCallable_REG_CALL(MailMgrService, MarkAllAsRead);
56  PyCallable_REG_CALL(MailMgrService, MarkAsReadByLabel);
57  PyCallable_REG_CALL(MailMgrService, MarkAsReadByList);
58  PyCallable_REG_CALL(MailMgrService, MoveAllFromTrash);
62  PyCallable_REG_CALL(MailMgrService, AssignLabels);
63  PyCallable_REG_CALL(MailMgrService, RemoveLabels);
64 
65  // implemented
68  PyCallable_REG_CALL(MailMgrService, CreateLabel);
69  PyCallable_REG_CALL(MailMgrService, DeleteLabel);
70 }
71 
73  delete m_dispatch;
74  delete m_db;
75 }
76 
77 PyResult MailMgrService::Handle_SendMail(PyCallArgs &call)
78 {
79  Call_SendMail args;
80  if (!args.Decode(&call.tuple)) {
81  codelog(SERVICE__ERROR, "%s: Failed to decode arguments.", GetName());
82  return nullptr;
83  }
84 
85  int sender = call.client->GetCharacterID();
86  return new PyInt(m_db->SendMail(sender, args.toCharacterIDs, args.toListID, args.toCorpOrAllianceID, args.title, args.body, args.isReplyTo, args.isForwardedFrom));
87 }
88 
89 PyResult MailMgrService::Handle_PrimeOwners(PyCallArgs &call)
90 {
91  Call_SingleIntList args;
92  if (!args.Decode(&call.tuple)) {
93  codelog(SERVICE__ERROR, "%s: Failed to decode arguments.", GetName());
94  return nullptr;
95  }
96 
97  return ServiceDB::PrimeOwners(args.ints);
98 }
99 
100 PyResult MailMgrService::Handle_SyncMail(PyCallArgs &call)
101 {
102  int firstId = 0, secondId = 0;
103 
104  if (call.tuple->size() == 2 && !call.tuple->GetItem(0)->IsNone() && !call.tuple->GetItem(1)->IsNone())
105  {
106  Call_TwoIntegerArgs args;
107  if (!args.Decode(&call.tuple)) {
108  codelog(SERVICE__ERROR, "%s: Failed to decode arguments.", GetName());
109  return nullptr;
110  }
111 
112  // referring to a mail id range
113  int firstId = args.arg1, secondId = args.arg2;
114  }
115 
116  PyDict* dummy = new PyDict;
117  dummy->SetItemString("oldMail", PyStatic.NewNone());
118  dummy->SetItemString("newMail", m_db->GetNewMail(call.client->GetCharacterID()));
119  dummy->SetItemString("mailStatus", m_db->GetMailStatus(call.client->GetCharacterID()));
120  return new PyObject("util.KeyVal", dummy);
121 }
122 
123 PyResult MailMgrService::Handle_AssignLabels(PyCallArgs &call)
124 {
125  Call_AssignLabels args;
126  if (!args.Decode(&call.tuple)) {
127  codelog(SERVICE__ERROR, "%s: Failed to decode arguments.", GetName());
128  return nullptr;
129  }
130 
131  int labelID = args.labelId;
132  m_db->ApplyLabels(args.messageIds, labelID);
133 
134  return nullptr;
135 }
136 
137 PyResult MailMgrService::Handle_CreateLabel(PyCallArgs &call)
138 {
139  Call_CreateLabel args;
140  if (!args.Decode(&call.tuple)) {
141  codelog(SERVICE__ERROR, "%s: Failed to decode arguments.", GetName());
142  return nullptr;
143  }
144 
145  uint32 ret;
146  if (m_db->CreateLabel(call.client->GetCharacterID(), args, ret))
147  return new PyInt(ret);
148  return nullptr;
149 }
150 
151 PyResult MailMgrService::Handle_DeleteLabel(PyCallArgs &call)
152 {
153  Call_SingleIntegerArg args;
154  if (!args.Decode(&call.tuple)) {
155  codelog(SERVICE__ERROR, "%s: Failed to decode arguments.", GetName());
156  return nullptr;
157  }
158 
159  m_db->DeleteLabel(call.client->GetCharacterID(), args.arg /*labelID*/);
160 
161  return nullptr;
162 }
163 
164 PyResult MailMgrService::Handle_DeleteMail(PyCallArgs &call)
165 {
166  Call_SingleIntList args;
167  if (!args.Decode(&call.tuple)) {
168  codelog(SERVICE__ERROR, "%s: Failed to decode arguments.", GetName());
169  return nullptr;
170  }
171 
172  std::vector<int32> messageIDs = args.ints;
173 
174  for (int i = 0; i < messageIDs.size(); i++) {
175  int32 messageID = messageIDs[i];
176  m_db->DeleteMail(messageID);
177  }
178 
179  return nullptr;
180 }
181 
182 PyResult MailMgrService::Handle_EditLabel(PyCallArgs &call)
183 {
184  Call_EditLabel args;
185  if (!args.Decode(&call.tuple)) {
186  codelog(SERVICE__ERROR, "%s: Failed to decode arguments.", GetName());
187  return nullptr;
188  }
189 
191  return nullptr;
192 }
193 
194 PyResult MailMgrService::Handle_EmptyTrash(PyCallArgs &call)
195 {
196  // @TODO: TEST
198  return nullptr;
199 }
200 
201 PyResult MailMgrService::Handle_GetBody(PyCallArgs &call)
202 {
203  Call_MailGetBody args;
204  if (!args.Decode(&call.tuple)) {
205  codelog(SERVICE__ERROR, "%s: Failed to decode arguments.", GetName());
206  return nullptr;
207  }
208 
209  if (!args.isUnread) {
210  m_db->SetMailUnread(args.messageId);
211  } else {
212  m_db->SetMailRead(args.messageId);
213  }
214 
215  return m_db->GetMailBody(args.messageId);
216 }
217 
218 PyResult MailMgrService::Handle_GetLabels(PyCallArgs &call)
219 {
220  return m_db->GetLabels(call.client->GetCharacterID());
221 }
222 
223 PyResult MailMgrService::Handle_GetMailHeaders(PyCallArgs &call)
224 {
225  // @TODO: Stub
226  // contains message ids
227  Call_SingleIntList args;
228  if (!args.Decode(&call.tuple)) {
229  codelog(SERVICE__ERROR, "%s: Failed to decode arguments.", GetName());
230  return nullptr;
231  }
232 
233  return nullptr;
234 }
235 
236 PyResult MailMgrService::Handle_MarkAllAsRead(PyCallArgs &call)
237 {
239 
240  return nullptr;
241 }
242 
243 PyResult MailMgrService::Handle_MarkAllAsUnread(PyCallArgs &call)
244 {
246  return nullptr;
247 }
248 
249 PyResult MailMgrService::Handle_MarkAsRead(PyCallArgs &call)
250 {
251  // message id list
252  Call_SingleIntList args;
253  if (!args.Decode(&call.tuple)) {
254  codelog(SERVICE__ERROR, "%s: Failed to decode arguments.", GetName());
255  return nullptr;
256  }
257 
258  m_db->SetMailsRead(args.ints);
259 
260  return nullptr;
261 }
262 
263 PyResult MailMgrService::Handle_MarkAsReadByLabel(PyCallArgs &call)
264 {
265  Call_SingleIntegerArg args;
266  if (!args.Decode(&call.tuple)) {
267  codelog(SERVICE__ERROR, "%s: Failed to decode arguments.", GetName());
268  return nullptr;
269  }
270 
271  int labelId = args.arg;
272  m_db->MarkAllAsReadByLabel(call.client->GetCharacterID(), labelId);
273 
274  return nullptr;
275 }
276 
277 PyResult MailMgrService::Handle_MarkAsReadByList(PyCallArgs &call)
278 {
279  Call_SingleIntegerArg args;
280  if (!args.Decode(&call.tuple)) {
281  codelog(SERVICE__ERROR, "%s: Failed to decode arguments.", GetName());
282  return nullptr;
283  }
284 
285  int listId = args.arg;
286 
287  return nullptr;
288 }
289 
290 PyResult MailMgrService::Handle_MarkAsUnread(PyCallArgs &call)
291 {
292  // message id list
293  Call_SingleIntList args;
294  if (!args.Decode(&call.tuple)) {
295  codelog(SERVICE__ERROR, "%s: Failed to decode arguments.", GetName());
296  return nullptr;
297  }
298 
299  m_db->SetMailsUnread(args.ints);
300 
301  return nullptr;
302 }
303 
304 PyResult MailMgrService::Handle_MarkAsUnreadByLabel(PyCallArgs &call)
305 {
306  Call_SingleIntegerArg args;
307  if (!args.Decode(&call.tuple)) {
308  codelog(SERVICE__ERROR, "%s: Failed to decode arguments.", GetName());
309  return nullptr;
310  }
311 
312  int labelId = args.arg;
314 
315  return nullptr;
316 }
317 
318 PyResult MailMgrService::Handle_MarkAsUnreadByList(PyCallArgs &call)
319 {
320  // @TODO: Stub
321  Call_SingleIntegerArg args;
322  if (!args.Decode(&call.tuple)) {
323  codelog(SERVICE__ERROR, "%s: Failed to decode arguments.", GetName());
324  return nullptr;
325  }
326 
327  int listId = args.arg;
328 
329  return nullptr;
330 }
331 
332 PyResult MailMgrService::Handle_MoveAllFromTrash(PyCallArgs &call)
333 {
335  return nullptr;
336 }
337 
338 PyResult MailMgrService::Handle_MoveAllToTrash(PyCallArgs &call)
339 {
341  return nullptr;
342 }
343 
344 PyResult MailMgrService::Handle_MoveFromTrash(PyCallArgs &call)
345 {
346  // message id list
347  Call_SingleIntList args;
348  if (!args.Decode(&call.tuple)) {
349  codelog(SERVICE__ERROR, "%s: Failed to decode arguments.", GetName());
350  return nullptr;
351  }
352 
354 
355  return nullptr;
356 }
357 
358 PyResult MailMgrService::Handle_MoveToTrash(PyCallArgs &call)
359 {
360  // message id list
361  Call_SingleIntList args;
362  if (!args.Decode(&call.tuple)) {
363  codelog(SERVICE__ERROR, "%s: Failed to decode arguments.", GetName());
364  return nullptr;
365  }
366 
368 
369  return nullptr;
370 }
371 
372 PyResult MailMgrService::Handle_MoveToTrashByLabel(PyCallArgs &call)
373 {
374  // @TODO: Stub
375  Call_SingleIntegerArg args;
376  if (!args.Decode(&call.tuple)) {
377  codelog(SERVICE__ERROR, "%s: Failed to decode arguments.", GetName());
378  return nullptr;
379  }
380 
381  int labelId = args.arg;
382 
383 
384  return nullptr;
385 }
386 
387 PyResult MailMgrService::Handle_MoveToTrashByList(PyCallArgs &call)
388 {
389  // @TODO: Stub
390  Call_SingleIntegerArg args;
391  if (!args.Decode(&call.tuple)) {
392  codelog(SERVICE__ERROR, "%s: Failed to decode arguments.", GetName());
393  return nullptr;
394  }
395 
396  int listId = args.arg;
397 
398  return nullptr;
399 }
400 
401 PyResult MailMgrService::Handle_RemoveLabels(PyCallArgs &call)
402 {
403  // we reuse Call_AssignLabels here because the arguments match
404  Call_AssignLabels args;
405  if (!args.Decode(&call.tuple)) {
406  codelog(SERVICE__ERROR, "%s: Failed to decode arguments.", GetName());
407  return nullptr;
408  }
409 
410  m_db->RemoveLabels(args.messageIds, args.labelId);
411 
412  return nullptr;
413 }
PyRep * GetLabels(int characterID) const
Definition: MailDB.cpp:282
void DeleteMail(int32 messageID)
Definition: MailDB.cpp:374
void MarkAllAsUnreadByLabel(uint32 characterID, int labelID)
Definition: MailDB.cpp:213
Dispatcher *const m_dispatch
void DeleteLabel(int characterID, int labelID) const
Definition: MailDB.cpp:335
PyRep * GetItem(size_t index) const
Returns Python object.
Definition: PyRep.h:602
Python's dictionary.
Definition: PyRep.h:719
size_t size() const
Definition: PyRep.h:591
void EditLabel(int characterID, Call_EditLabel &args) const
Definition: MailDB.cpp:354
void MoveAllToTrash(uint32 characterID)
Definition: MailDB.cpp:408
int32 GetCharacterID() const
Definition: Client.h:113
const char * GetName() const
Definition: PyService.h:54
void RemoveStatusMasks(std::vector< int32 > messageIDs, int mask)
Definition: MailDB.cpp:469
void SetMailUnread(int id)
Definition: MailDB.cpp:166
signed __int32 int32
Definition: eve-compat.h:49
* args
void MarkAllAsReadByLabel(uint32 characterID, int labelID)
Definition: MailDB.cpp:230
Python object.
Definition: PyRep.h:826
#define codelog(type, fmt,...)
Definition: logsys.h:128
void EmptyTrash(uint32 characterID)
Definition: MailDB.cpp:386
Python integer.
Definition: PyRep.h:231
void MarkAllAsRead(uint32 characterID)
Definition: MailDB.cpp:200
void ApplyLabels(std::vector< int32 > messageIDs, int labelID)
Definition: MailDB.cpp:276
void MarkAllAsUnread(uint32 characterID)
Definition: MailDB.cpp:186
#define PyStatic
Definition: PyRep.h:1209
void SetMailRead(int id)
Definition: MailDB.cpp:171
Dispatcher *const m_dispatch
PyCallable_Make_InnerDispatcher(MailMgrService) MailMgrService
int SendMail(int sender, std::vector< int > &toCharacterIDs, int toListID, int toCorpOrAllianceID, std::string &title, std::string &body, int isReplyTo, int isForwardedFrom)
Definition: MailDB.cpp:59
Client *const client
Definition: PyCallable.h:49
Definition: MailDB.h:36
#define PyCallable_REG_CALL(c, m)
Definition: PyServiceCD.h:78
unsigned __int32 uint32
Definition: eve-compat.h:50
static PyRep * PrimeOwners(std::vector< int32 > &itemIDs)
Definition: ServiceDB.cpp:540
PyRep * GetNewMail(int charId)
Definition: MailDB.cpp:47
bool IsNone() const
Definition: PyRep.h:111
PyString * GetMailBody(int id) const
Definition: MailDB.cpp:151
PyRep * GetMailStatus(int charId)
Definition: MailDB.cpp:34
void SetMailsRead(std::vector< int32 > ids)
Definition: MailDB.cpp:181
bool CreateLabel(int characterID, Call_CreateLabel &args, uint32 &newID) const
Definition: MailDB.cpp:304
virtual ~MailMgrService()
void RemoveLabels(std::vector< int32 > messageIDs, int labelID)
Definition: MailDB.cpp:246
void ApplyStatusMasks(std::vector< int32 > messageIDs, int mask)
Definition: MailDB.cpp:448
void SetItemString(const char *key, PyRep *value)
SetItemString adds or sets a database entry.
Definition: PyRep.h:812
void SetMailsUnread(std::vector< int32 > ids)
Definition: MailDB.cpp:176
PyTuple * tuple
Definition: PyCallable.h:50
void MoveAllFromTrash(uint32 characterID)
Definition: MailDB.cpp:397