EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
CorporationDB.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 
28 #include "Client.h"
29 #include "StaticDataMgr.h"
30 #include "character/Character.h"
32 
33 /*
34  * CORP__DB_ERROR
35  * CORP__DB_WARNING
36  * CORP__DB_INFO
37  * CORP__DB_MESSAGE
38  */
39 
40 void CorporationDB::GetCorpStations(uint32 corp_id, std::vector<uint32>& stVec) {
41  DBQueryResult res;
42  if (!sDatabase.RunQuery(res, "SELECT stationID FROM staStations WHERE corporationID=%u", corp_id)) {
43  codelog(CORP__DB_ERROR, "Error in query: %s", res.error.c_str());
44  return;
45  }
46 
47  DBResultRow row;
48  while (res.GetRow(row))
49  stVec.push_back(row.GetInt(0));
50 
51  return;
52 }
53 /*
54 PyObject *CorporationDB::ListStationOffices(uint32 station_id) {
55  DBQueryResult res;
56  if (!sDatabase.RunQuery(res,
57  "SELECT itemID, officeFolderID, corporationID, stationID, typeID, lockDown, rentalFee, expiryDateTime"
58  " FROM staOffices"
59  " WHERE stationID = %u", station_id ))
60  {
61  codelog(CORP__DB_ERROR, "Error in query: %s", res.error.c_str());
62  return nullptr;
63  }
64 
65  return DBResultToRowset(res);
66 }
67 */
68 
70  DBQueryResult res;
71  if (!sDatabase.RunQuery(res,
72  "SELECT "
73  " corporationID,corporationName,description,shares,graphicID,"
74  " memberCount,ceoID,stationID,raceID,corporationType,creatorID,"
75  " hasPlayerPersonnelManager,tickerName,sendCharTerminationMessage,"
76  " shape1,shape2,shape3,color1,color2,color3,typeface,memberLimit,"
77  " allowedMemberRaceIDs,url,taxRate,minimumJoinStanding,division1,"
78  " division2,division3,division4,division5,division6,division7,"
79  " allianceID,deleted,isRecruiting"
80  " FROM crpCorporation"
81 //no idea what the criteria should be here...
82  " WHERE stationID=%u",
83  station_id
84  ))
85  {
86  codelog(CORP__DB_ERROR, "Error in query: %s", res.error.c_str());
87  return nullptr;
88  }
89 
90  return DBResultToRowset(res);
91 }
92 
95  DBQueryResult res;
96  if (sDataMgr.IsStation(stationID)) {
97  if (!sDatabase.RunQuery(res,
98  "SELECT"
99  " s.corporationID AS ownerID,"
100  " c.corporationName AS ownerName,"
101  " c.corporationType AS typeID,"
102  //" c.corporationID AS ownerNameID,"
103  " cs.gender"
104  " FROM staStations AS s"
105  " LEFT JOIN crpCorporation AS c ON cs.corporationID = c.corporationID"
106  " LEFT JOIN chrNPCCharacters AS cs ON cs.characterID = c.ceoID"
107  " WHERE s.stationID = %u", stationID ))
108  {
109  codelog(CORP__DB_ERROR, "Error in query: %s", res.error.c_str());
110  return nullptr;
111  }
112  } else {
113  if (!sDatabase.RunQuery(res,
114  "SELECT"
115  " c.corporationID AS ownerID,"
116  " c.corporationName AS ownerName,"
117  " c.corporationType AS typeID,"
118  //" c.corporationID AS ownerNameID,"
119  " cs.gender"
120  " FROM entity AS e"
121  " LEFT JOIN crpCorporation AS c USING ( corporationID )"
122  " LEFT JOIN chrCharacters AS cs ON cs.characterID = c.ceoID"
123  " WHERE e.itemID = %u", stationID ))
124  {
125  codelog(CORP__DB_ERROR, "Error in query: %s", res.error.c_str());
126  return nullptr;
127  }
128  }
129 
130  return DBResultToRowset(res);
131 }
132 
134  DBQueryResult res;
135  if (!sDatabase.RunQuery(res,
136  "SELECT corporationID, corporationName, description, creatorID, tickerName,"
137  " url, allianceID, deleted, stationID, ceoID, shares, memberCount, taxRate"
138  " FROM crpCorporation WHERE corporationID = %u", corpID))
139  {
140  codelog(CORP__DB_ERROR, "Error in retrieving corporation's data (%u)", corpID);
141  return nullptr;
142  }
143 
144  DBResultRow row;
145  if (!res.GetRow(row)) {
146  codelog(CORP__DB_WARNING, "Unable to find corporation's data (%u)", corpID);
147  return nullptr;
148  }
149 
150  //return DBResultToRowset(res);
151  return DBRowToKeyVal(row);
152 }
153 
155  // called by corp member. different from GetCorporations() below
156  // not sure what the difference between them is/should be
157  std::string table = "crpWalletDivisons";
158  if (IsNPCCorp(corpID))
159  table = "crpNPCWalletDivisons";
160  DBQueryResult res;
161  if (!sDatabase.RunQuery(res,
162  " SELECT "
163  " c.corporationID,c.corporationName,c.description,c.tickerName,c.url,"
164  " c.taxRate,c.minimumJoinStanding,c.corporationType,c.hasPlayerPersonnelManager,"
165  " c.sendCharTerminationMessage,c.creatorID,c.ceoID,c.stationID,c.raceID,"
166  " c.allianceID,c.shares,c.memberCount,c.memberLimit,c.allowedMemberRaceIDs,"
167  " c.shape1,c.shape2,c.shape3,c.color1,c.color2,c.color3,c.typeface,c.deleted,c.isRecruiting,c.warFactionID,"
168  " w.division1,w.division2,w.division3,w.division4,w.division5,w.division6,"
169  " w.division7,w.walletDivision1,w.walletDivision2,w.walletDivision3,w.walletDivision4,"
170  " w.walletDivision5,w.walletDivision6,w.walletDivision7"
171  " FROM crpCorporation AS c"
172  " LEFT JOIN %s AS w USING (corporationID)"
173  " WHERE corporationID = %u", table.c_str(), corpID))
174  {
175  codelog(CORP__DB_ERROR, "Error in retrieving corporation's data (%u)", corpID);
176  return nullptr;
177  }
178 
179  DBResultRow row;
180  if (!res.GetRow(row)) {
181  codelog(CORP__DB_WARNING, "Unable to find corporation's data (%u)", corpID);
182  return nullptr;
183  }
184 
185  return DBRowToRow(row);
186  //return DBResultToRowset(res);
187 }
188 
190  // called by non-member. different from GetCorporation() above
191  // not sure what the differece between them is/should be
192  std::string table = "crpWalletDivisons";
193  if (IsNPCCorp(corpID))
194  table = "crpNPCWalletDivisons";
195  DBQueryResult res;
196  if (!sDatabase.RunQuery(res,
197  "SELECT"
198  " c.corporationID,c.corporationName,c.description,c.tickerName,c.url,"
199  " c.taxRate,c.minimumJoinStanding,c.corporationType,c.hasPlayerPersonnelManager,"
200  " c.sendCharTerminationMessage,c.creatorID,c.ceoID,c.stationID,c.raceID,"
201  " c.allianceID,c.shares,c.memberCount,c.memberLimit,c.allowedMemberRaceIDs,"
202  " c.shape1,c.shape2,c.shape3,c.color1,c.color2,c.color3,c.typeface,c.deleted,c.isRecruiting,c.warFactionID,"
203  " w.division1,w.division2,w.division3,w.division4,w.division5,w.division6,"
204  " w.division7,w.walletDivision1,w.walletDivision2,w.walletDivision3,w.walletDivision4,"
205  " w.walletDivision5,w.walletDivision6,w.walletDivision7"
206  " FROM crpCorporation AS c"
207  " LEFT JOIN %s AS w USING (corporationID)"
208  " WHERE corporationID = %u", table.c_str(), corpID))
209  {
210  codelog(CORP__DB_ERROR, "Error in retrieving corporation's data (%u)", corpID);
211  return nullptr;
212  }
213 
214  DBResultRow row;
215  if (!res.GetRow(row)) {
216  codelog(CORP__DB_WARNING, "Unable to find corporation's data (%u)", corpID);
217  return nullptr;
218  }
219 
220  return DBRowToPackedRow(row);
221 }
222 
224 {
225  DBQueryResult res;
226  if (payable) {
227  if (!sDatabase.RunQuery(res,
228  "SELECT billID, billTypeID, debtorID, creditorID, amount, dueDateTime, interest,"
229  "externalID, paid externalID2 FROM billsPayable WHERE debtorID = %u", corpID))
230  {
231  codelog(DATABASE__ERROR, "Error in query: %s", res.error.c_str());
232  return nullptr;
233  }
234  } else {
235  if (!sDatabase.RunQuery(res,
236  "SELECT billID, billTypeID, debtorID, creditorID, amount, dueDateTime, interest,"
237  "externalID, paid externalID2 FROM billsReceivable WHERE creditorID = %u", corpID))
238  {
239  codelog(DATABASE__ERROR, "Error in query: %s", res.error.c_str());
240  return nullptr;
241  }
242  }
243 
244  return DBResultToRowset(res);
245 }
246 
248  DBQueryResult res;
249  //do we really need this order by??
250  if (!sDatabase.RunQuery(res,
251  "SELECT startDate, corporationID, deleted "
252  " FROM chrEmployment "
253  " WHERE characterID = %u "
254  " ORDER BY startDate DESC", charID
255  ))
256  {
257  codelog(CORP__DB_ERROR, "Error in query: %s", res.error.c_str());
258  return nullptr;
259  }
260 
261  return DBResultToRowset(res);
262 }
263 
264 uint16 CorporationDB::CreateMedal(uint32 ownerID, uint32 creatorID, std::string& title, std::string& description)
265 {
266  std::string cTitle, cDesc;
267  sDatabase.DoEscapeString(cTitle, title);
268  sDatabase.DoEscapeString(cDesc, description);
269  uint32 medalID = 0;
270  DBerror err;
271  sDatabase.RunQueryLID(err, medalID,
272  " INSERT INTO crpMedals (ownerID, creatorID, title, description, date)"
273  " VALUES (%u, %u, '%s', '%s', %li)", ownerID, creatorID, cTitle.c_str(), cDesc.c_str(), GetFileTimeNow());
274 
275  return medalID;
276 }
277 
278 void CorporationDB::SaveMedalData(int64 medalID, std::vector< Corp::MedalData >& dataList)
279 {
280  // loop thru data and add to query
281  std::ostringstream query;
282  query << "INSERT INTO crpMedalData(medalID, part, graphic, color)";
283  query << "VALUES ";
284 
285  bool first = true;
286  for (auto cur : dataList) {
287  if (first) {
288  first = false;
289  } else {
290  query << ",";
291  }
292  query << "(" << std::to_string(medalID) << "," << std::to_string(cur.part) << ",'" << cur.graphic << "'," << std::to_string(cur.color) << ")";
293  }
294 
295  if (!first ) {
296  DBerror err;
297  sDatabase.RunQuery(err, query.str().c_str());
298  }
299 
300  //SELECT id, part, graphic, color FROM crpMedalData
301 }
302 
304 {
305  // SELECT recepientID, medalID, corpID, date, status FROM chrMedals WHERE recepientID = %u
306  DBQueryResult res;
307  if (!sDatabase.RunQuery(res,
308  "SELECT recepientID, issuerID, date, reason, status"
309  " FROM chrMedals"
310  " WHERE medalID = %i", medalID))
311  {
312  codelog(CORP__DB_ERROR, "Error in query: %s", res.error.c_str());
313  return nullptr;
314  }
315 
316  return DBResultToCRowset(res);
317 }
318 
320 {
321  DBQueryResult res;
322  if (!sDatabase.RunQuery(res,
323  "SELECT medalID, creatorID, noRecepients, date, title, description FROM crpMedals WHERE ownerID = %u", corpID))
324  {
325  codelog(CORP__DB_ERROR, "Error in query: %s", res.error.c_str());
326  return nullptr;
327  }
328 
329  return DBResultToCRowset(res);
330 }
331 
333 {
334  DBQueryResult res;
335  if (!sDatabase.RunQuery(res,
336  "SELECT medalID, part, graphic, color FROM crpMedalData"
337  " WHERE medalID IN (SELECT medalID FROM crpMedals WHERE ownerID = %u)", corpID))
338  {
339  codelog(CORP__DB_ERROR, "Error in query: %s", res.error.c_str());
340  return nullptr;
341  }
342 
343  return DBResultToCRowset(res);
344 }
345 
347 {
348  DBQueryResult res;
349  if (!sDatabase.RunQuery(res,
350  "SELECT chr.medalID, crp.creatorID, crp.noRecepients, crp.date, crp.title, crp.description, chr.status"
351  " FROM chrMedals AS chr"
352  " LEFT JOIN crpMedals AS crp USING (medalID)"
353  " WHERE chr.recepientID = %i", charID))
354  {
355  codelog(CORP__DB_ERROR, "Error in query: %s", res.error.c_str());
356  return nullptr;
357  }
358 
359  return DBResultToCRowset(res);
360 }
361 
363 {
364  // SELECT recepientID, medalID, corpID, dateTime FROM chrMedals WHERE recepientID = %u
365  DBQueryResult res;
366  if (!sDatabase.RunQuery(res,
367  "SELECT medalID, part, graphic, color FROM crpMedalData"
368  " WHERE medalID IN (SELECT medalID FROM chrMedals WHERE recepientID = %i)", charID))
369  {
370  codelog(CORP__DB_ERROR, "Error in query: %s", res.error.c_str());
371  return nullptr;
372  }
373 
374  return DBResultToCRowset(res);
375 }
376 
378 {
379  DBQueryResult res;
380  if (!sDatabase.RunQuery(res,
381  "SELECT medalID, ownerID, creatorID, noRecepients AS numberOfRecipients, date, title, description FROM crpMedals"
382  " WHERE medalID = %i", medalID))
383  {
384  codelog(CORP__DB_ERROR, "Error in query: %s", res.error.c_str());
385  return nullptr;
386  }
387 
388  // SELECT medalID, ownerID, creatorID, noRecepients, date, title, description FROM crpMedals WHERE medalID
389 
390  return DBResultToCRowset(res);
391 }
392 
394 {
395  // this is for viewing permissions on paperdoll
396  DBQueryResult res;
397  sDatabase.RunQuery(res, "SELECT statusID, statusName FROM crpMedalStatus");
398  return DBResultToRowset(res);
399 }
400 
401 void CorporationDB::GiveMedalToCharacters(uint32 issuerID, uint32 corpID, int32 medalID, std::vector< uint32 >& charVec, std::string& reason)
402 {
403  // INSERT INTO chrMedals(recepientID, medalID, corpID, issuerID, reason, date, status) VALUES ()
404 
405  // loop thru data and add to query
406  std::ostringstream query;
407  query << "INSERT INTO chrMedals(recepientID, medalID, corpID, issuerID, date, reason)";
408  query << "VALUES ";
409 
410  bool first = true;
411  for (auto cur : charVec) {
412  if (first) {
413  first = false;
414  } else {
415  query << ",";
416  }
417  query << "(" << std::to_string(cur) << "," << std::to_string(medalID) << "," << std::to_string(corpID) << "," << std::to_string(issuerID) << ",";
418  query << std::to_string(GetFileTimeNow()) << ",'" << reason.c_str() << "')";
419  }
420 
421  if (!first ) {
422  DBerror err;
423  sDatabase.RunQuery(err, query.str().c_str());
424  sDatabase.RunQuery(err, "UPDATE crpMedals SET noRecepients=noRecepients + 1 WHERE medalID = %u", medalID );
425  }
426 }
427 
428 void CorporationDB::SetMedalStatus(uint32 charID, uint16 medalID, uint8 status)
429 {
430  DBerror err;
431  sDatabase.RunQuery(err, "UPDATE chrMedals SET status = %u WHERE recepientID = %u AND medalID = %u", status, charID, medalID);
432 }
433 
434 bool CorporationDB::IsTickerTaken(std::string ticker) {
435  DBQueryResult res;
436  sDatabase.RunQuery(res, " SELECT corporationID FROM crpCorporation WHERE tickerName = '%s'", ticker.c_str());
437  return (res.GetRowCount() != 0);
438 }
439 
440 static std::string _IoN( PyRep* r )
441 {
442  if ( !r->IsInt() )
443  return "NULL";
444  return std::to_string(PyRep::IntegerValueU32(r));
445 }
446 
447 bool CorporationDB::AddCorporation(Call_AddCorporation & corpInfo, Client* pClient, uint32 & corpID) {
448  std::string cName, cDesc, cTick, cURL;
449  sDatabase.DoEscapeString(cName, corpInfo.corpName);
450  sDatabase.DoEscapeString(cDesc, corpInfo.description);
451  sDatabase.DoEscapeString(cTick, corpInfo.corpTicker);
452  sDatabase.DoEscapeString(cURL, corpInfo.url);
453 
454  Character* pChar = pClient->GetChar().get();
455  uint32 charID = pClient->GetCharacterID();
456  uint8 raceID = (uint8)pChar->race();
457 
458  // set member limit based on creator's skills
459  uint16 mLimit = (pChar->GetSkillLevel(EvESkill::CorporationManagement) * 20);//101
460  mLimit += (pChar->GetSkillLevel(EvESkill::MegacorpManagement) * 100); //601
461  mLimit += (pChar->GetSkillLevel(EvESkill::EmpireControl) * 400); //2601
462  mLimit += (pChar->GetSkillLevel(EvESkill::Sovereignty) * 2000); //12601
463 
467  DBerror err;
468  if (!sDatabase.RunQueryLID(err, corpID,
469  " INSERT INTO crpCorporation ( "
470  " corporationName, description, tickerName, url, taxRate, corporationType, hasPlayerPersonnelManager, "
471  " creatorID, ceoID, stationID, raceID, shares, memberLimit, allowedMemberRaceIDs,"
472  " graphicID, color1, color2, color3, shape1, shape2, shape3, "
473  " isRecruiting, allianceMemberStartDate ) "
474  " VALUES "
475  " ('%s', '%s', '%s', '%s', %f, 2, 1, "
476  " %u, %u, %u, %u, 1000, %u, %u,"
477  " 0, %s, %s, %s, %s, %s, %s, "
478  " %u, 0) ",
479  cName.c_str(), cDesc.c_str(), cTick.c_str(), cURL.c_str(), corpInfo.taxRate,
480  charID, charID, pClient->GetStationID(), raceID, mLimit, raceID,
481  _IoN(corpInfo.color1).c_str(),
482  _IoN(corpInfo.color2).c_str(),
483  _IoN(corpInfo.color3).c_str(),
484  _IoN(corpInfo.shape1).c_str(),
485  _IoN(corpInfo.shape2).c_str(),
486  _IoN(corpInfo.shape3).c_str(),
487  corpInfo.applicationEnabled))
488  {
489  codelog(CORP__DB_ERROR, "Error in AddCorporation query: %s", err.c_str());
490  return false;
491  }
492 
493  // dont care if these fail....
494  // create default wallet info
495  sDatabase.RunQuery(err, "INSERT INTO crpWalletDivisons (corporationID) VALUES (%u)", corpID);
496 
497  // create default bill auto-pay
498  sDatabase.RunQuery(err, "INSERT INTO crpAutoPay (corporationID) VALUES (%u)", corpID);
499 
500  // create corp-owned shares
501  sDatabase.RunQuery(err, "INSERT INTO crpShares (corporationID, shareholderID, shares, shareholderCorporationID)"
502  " VALUES (%u, %u, 1000, %u)", corpID, corpID, corpID);
503 
504  // It has to go into the eveStaticOwners too
505  sDatabase.RunQuery(err, " INSERT INTO eveStaticOwners (ownerID,ownerName,typeID) VALUES (%u, '%s', 2)", corpID, cName.c_str());
506 
507  return true;
508 }
509 
510 #define _NI(a, b) if (row.IsNull(b)) { cc.a = PyStatic.NewNone(); } else { cc.a = new PyInt(row.GetUInt(b)); }
511 #define _NS(a, b) if (row.IsNull(b)) { cc.a = PyStatic.NewNone(); } else { cc.a = new PyString(row.GetText(b)); }
512 
513 bool CorporationDB::CreateCorporationChangePacket(OnCorporationChanged & cc, uint32 oldCorpID, uint32 newCorpID) {
514  std::string table = "crpWalletDivisons";
515  if (IsNPCCorp(newCorpID))
516  table = "crpNPCWalletDivisons";
517  DBQueryResult res;
518  DBResultRow row;
519  if (!sDatabase.RunQuery(res,
520  " SELECT "
521  " c.corporationID, c.corporationName, c.description, c.tickerName, c.allianceID, c.warFactionID, c.url, c.taxRate,"
522  " c.minimumJoinStanding, c.corporationType, c.hasPlayerPersonnelManager, c.sendCharTerminationMessage, c.creatorID, c.ceoID, c.stationID, c.raceID, "
523  " c.shares, c.memberCount, c.memberLimit, c.allowedMemberRaceIDs, c.shape1, c.shape2, c.shape3, c.color1, c.color2, c.color3,"
524  " c.typeface, w.division1, w.division2, w.division3, w.division4, w.division5, w.division6, w.division7, w.walletDivision1, w.walletDivision2,"
525  " w.walletDivision3, w.walletDivision4, w.walletDivision5, w.walletDivision6, w.walletDivision7, c.deleted, c.isRecruiting "
526  " FROM crpCorporation AS c"
527  " LEFT JOIN %s AS w USING (corporationID)"
528  " WHERE corporationID = %u ",table.c_str(), newCorpID
529  ))
530  {
531  codelog(CORP__DB_ERROR, "Error in retrieving new corporation's data (%u)", newCorpID);
532  return false;
533  }
534 
535  if (!res.GetRow(row)) {
536  codelog(CORP__DB_WARNING, "Unable to find new corporation's data (%u)", newCorpID);
537  return false;
538  }
539 
540  cc.corporationIDNew = row.GetUInt(0);
541  cc.corporationNameNew = row.GetText(1);
542  cc.descriptionNew = row.GetText(2);
543  cc.tickerNameNew = row.GetText(3);
544  _NI(allianceIDNew, 4);
545  _NI(warFactionIDNew, 5);
546  cc.urlNew = row.GetText(6);
547  cc.taxRateNew = row.GetDouble(7);
548  cc.minimumJoinStandingNew = row.GetDouble(8);
549  cc.corporationTypeNew = row.GetUInt(9);
550  cc.hasPlayerPersonnelManagerNew = row.GetUInt(10);
551  cc.sendCharTerminationMessageNew = row.GetUInt(11);
552  cc.creatorIDNew = row.GetUInt(12);
553  cc.ceoIDNew = row.GetUInt(13);
554  cc.stationIDNew = row.GetUInt(14);
555  _NI(raceIDNew, 15);
556  cc.sharesNew = row.GetInt64(16);
557  cc.memberCountNew = row.GetUInt(17);
558  cc.memberLimitNew = row.GetUInt(18);
559  cc.allowedMemberRaceIDsNew = row.GetUInt(19);
560  _NI(shape1New, 20);
561  _NI(shape2New, 21);
562  _NI(shape3New, 22);
563  _NI(color1New, 23);
564  _NI(color2New, 24);
565  _NI(color3New, 25);
566  _NI(typefaceNew, 26);
567  _NS(division1New, 27);
568  _NS(division2New, 28);
569  _NS(division3New, 29);
570  _NS(division4New, 30);
571  _NS(division5New, 31);
572  _NS(division6New, 32);
573  _NS(division7New, 33);
574  _NS(walletDivision1New, 34);
575  _NS(walletDivision2New, 35);
576  _NS(walletDivision3New, 36);
577  _NS(walletDivision4New, 37);
578  _NS(walletDivision5New, 38);
579  _NS(walletDivision6New, 39);
580  _NS(walletDivision7New, 40);
581  cc.deletedNew = row.GetUInt(41);
582  cc.isRecruitingNew = row.GetUInt(42);
583 
584  if (IsPlayerCorp(oldCorpID))
585  table = "crpWalletDivisons";
586  if (IsNPCCorp(oldCorpID))
587  table = "crpNPCWalletDivisons";
588 
589  if (!sDatabase.RunQuery(res,
590  " SELECT "
591  " c.corporationID, c.corporationName, c.description, c.tickerName, c.allianceID, c.warFactionID, c.url, c.taxRate,"
592  " c.minimumJoinStanding, c.corporationType, c.hasPlayerPersonnelManager, c.sendCharTerminationMessage, c.creatorID, c.ceoID, c.stationID, c.raceID, "
593  " c.shares, c.memberCount, c.memberLimit, c.allowedMemberRaceIDs, c.shape1, c.shape2, c.shape3, c.color1, c.color2, c.color3,"
594  " c.typeface, w.division1, w.division2, w.division3, w.division4, w.division5, w.division6, w.division7, w.walletDivision1, w.walletDivision2,"
595  " w.walletDivision3, w.walletDivision4, w.walletDivision5, w.walletDivision6, w.walletDivision7, c.deleted, c.isRecruiting "
596  " FROM crpCorporation AS c"
597  " LEFT JOIN %s AS w USING (corporationID)"
598  " WHERE corporationID = %u ", table.c_str(), oldCorpID
599  ))
600  {
601  codelog(CORP__DB_ERROR, "Error in retrieving old corporation's data (%u)", oldCorpID);
602  return false;
603  }
604 
605  if (!res.GetRow(row)) {
606  codelog(CORP__DB_WARNING, "Unable to find old corporation's data (%u)", oldCorpID);
607  return false;
608  }
609 
610  cc.corporationIDOld = new PyInt(row.GetInt(0));
611  cc.corporationNameOld = new PyString(row.GetText(1));
612  cc.descriptionOld = new PyString(row.GetText(2));
613  cc.tickerNameOld = new PyString(row.GetText(3));
614  _NI(allianceIDOld, 4);
615  _NI(warFactionIDOld, 5);
616  cc.urlOld = new PyString(row.GetText(6));
617  cc.taxRateOld = new PyFloat(row.GetDouble(7));
618  cc.minimumJoinStandingOld = new PyFloat(row.GetDouble(8));
619  cc.corporationTypeOld = new PyInt(row.GetInt(9));
620  cc.hasPlayerPersonnelManagerOld = new PyInt(row.GetInt(10));
621  cc.sendCharTerminationMessageOld = new PyInt(row.GetInt(11));
622  cc.creatorIDOld = new PyInt(row.GetInt(12));
623  cc.ceoIDOld = new PyInt(row.GetInt(13));
624  cc.stationIDOld = new PyInt(row.GetInt(14));
625  _NI(raceIDOld, 15);
626  cc.sharesOld = new PyLong(row.GetInt64(16));
627  cc.memberCountOld = new PyInt(row.GetInt(17));
628  cc.memberLimitOld = new PyInt(row.GetInt(18));
629  cc.allowedMemberRaceIDsOld = new PyInt(row.GetInt(19));
630  _NI(shape1Old, 20);
631  _NI(shape2Old, 21);
632  _NI(shape3Old, 22);
633  _NI(color1Old, 23);
634  _NI(color2Old, 24);
635  _NI(color3Old, 25);
636  _NI(typefaceOld, 26);
637  _NS(division1Old, 27);
638  _NS(division2Old, 28);
639  _NS(division3Old, 29);
640  _NS(division4Old, 30);
641  _NS(division5Old, 31);
642  _NS(division6Old, 32);
643  _NS(division7Old, 33);
644  _NS(walletDivision1Old, 34);
645  _NS(walletDivision2Old, 35);
646  _NS(walletDivision3Old, 36);
647  _NS(walletDivision4Old, 37);
648  _NS(walletDivision5Old, 38);
649  _NS(walletDivision6Old, 39);
650  _NS(walletDivision7Old, 40);
651  cc.deletedOld = new PyInt(row.GetUInt(41));
652  cc.isRecruitingOld = new PyInt(row.GetUInt(42));
653 
654  return true;
655 }
656 
657 bool CorporationDB::CreateCorporationCreatePacket(OnCorporationChanged & cc, uint32 oldCorpID, uint32 newCorpID) {
658  DBQueryResult res;
659  DBResultRow row;
660  if (!sDatabase.RunQuery(res,
661  " SELECT "
662  " c.corporationID, c.corporationName, c.description, c.tickerName, c.allianceID, c.warFactionID, c.url, c.taxRate,"
663  " c.minimumJoinStanding, c.corporationType, c.hasPlayerPersonnelManager, c.sendCharTerminationMessage, c.creatorID, c.ceoID, c.stationID, c.raceID, "
664  " c.shares, c.memberCount, c.memberLimit, c.allowedMemberRaceIDs, c.shape1, c.shape2, c.shape3, c.color1, c.color2,c. color3,"
665  " c.typeface, w.division1, w.division2, w.division3, w.division4, w.division5, w.division6, w.division7, w.walletDivision1, w.walletDivision2,"
666  " w.walletDivision3, w.walletDivision4, w.walletDivision5, w.walletDivision6, w.walletDivision7, c.deleted, c.isRecruiting "
667  " FROM crpCorporation AS c"
668  " LEFT JOIN crpWalletDivisons AS w USING (corporationID)"
669  " WHERE corporationID = %u ", newCorpID
670  ))
671  {
672  codelog(CORP__DB_ERROR, "Error in retrieving new corporation's data (%u)", newCorpID);
673  return false;
674  }
675 
676  if (!res.GetRow(row)) {
677  codelog(CORP__DB_WARNING, "Unable to find corporation's data (%u)", newCorpID);
678  return false;
679  }
680 
681  cc.corporationIDNew = row.GetUInt(0);
682  cc.corporationNameNew = row.GetText(1);
683  cc.descriptionNew = row.GetText(2);
684  cc.tickerNameNew = row.GetText(3);
685  _NI(allianceIDNew, 4);
686  _NI(warFactionIDNew, 5);
687  cc.urlNew = row.GetText(6);
688  cc.taxRateNew = row.GetDouble(7);
689  cc.minimumJoinStandingNew = row.GetDouble(8);
690  cc.corporationTypeNew = row.GetUInt(9);
691  cc.hasPlayerPersonnelManagerNew = row.GetUInt(10);
692  cc.sendCharTerminationMessageNew = row.GetUInt(11);
693  cc.creatorIDNew = row.GetUInt(12);
694  cc.ceoIDNew = row.GetUInt(13);
695  cc.stationIDNew = row.GetUInt(14);
696  _NI(raceIDNew, 15);
697  cc.sharesNew = row.GetInt64(16);
698  cc.memberCountNew = row.GetUInt(17);
699  cc.memberLimitNew = row.GetUInt(18);
700  cc.allowedMemberRaceIDsNew = row.GetUInt(19);
701  _NI(shape1New, 20);
702  _NI(shape2New, 21);
703  _NI(shape3New, 22);
704  _NI(color1New, 23);
705  _NI(color2New, 24);
706  _NI(color3New, 25);
707  _NI(typefaceNew, 26);
708  _NS(division1New, 27);
709  _NS(division2New, 28);
710  _NS(division3New, 29);
711  _NS(division4New, 30);
712  _NS(division5New, 31);
713  _NS(division6New, 32);
714  _NS(division7New, 33);
715  _NS(walletDivision1New, 34);
716  _NS(walletDivision2New, 35);
717  _NS(walletDivision3New, 36);
718  _NS(walletDivision4New, 37);
719  _NS(walletDivision5New, 38);
720  _NS(walletDivision6New, 39);
721  _NS(walletDivision7New, 40);
722  cc.deletedNew = row.GetUInt(41);
723  cc.isRecruitingNew = row.GetUInt(42);
724 
726  cc.allianceIDOld = PyStatic.NewNone();
727  cc.warFactionIDOld = PyStatic.NewNone();
728  cc.allowedMemberRaceIDsOld = PyStatic.NewNone();
729  cc.ceoIDOld = PyStatic.NewNone();
730  cc.color1Old = PyStatic.NewNone();
731  cc.color2Old = PyStatic.NewNone();
732  cc.color3Old = PyStatic.NewNone();
733  cc.corporationIDOld = PyStatic.NewNone();
734  cc.corporationNameOld = PyStatic.NewNone();
735  cc.corporationTypeOld = PyStatic.NewNone();
736  cc.creatorIDOld = PyStatic.NewNone();
737  cc.deletedOld = PyStatic.NewNone();
738  cc.descriptionOld = PyStatic.NewNone();
739  cc.division1Old = PyStatic.NewNone();
740  cc.division2Old = PyStatic.NewNone();
741  cc.division3Old = PyStatic.NewNone();
742  cc.division4Old = PyStatic.NewNone();
743  cc.division5Old = PyStatic.NewNone();
744  cc.division6Old = PyStatic.NewNone();
745  cc.division7Old = PyStatic.NewNone();
746  cc.walletDivision1Old = PyStatic.NewNone();
747  cc.walletDivision2Old = PyStatic.NewNone();
748  cc.walletDivision3Old = PyStatic.NewNone();
749  cc.walletDivision4Old = PyStatic.NewNone();
750  cc.walletDivision5Old = PyStatic.NewNone();
751  cc.walletDivision6Old = PyStatic.NewNone();
752  cc.walletDivision7Old = PyStatic.NewNone();
753  cc.hasPlayerPersonnelManagerOld = PyStatic.NewNone();
754  cc.memberCountOld = PyStatic.NewNone();
755  cc.memberLimitOld = PyStatic.NewNone();
756  cc.minimumJoinStandingOld = PyStatic.NewNone();
757  cc.raceIDOld = PyStatic.NewNone();
758  cc.sendCharTerminationMessageOld = PyStatic.NewNone();
759  cc.shape1Old = PyStatic.NewNone();
760  cc.shape2Old = PyStatic.NewNone();
761  cc.shape3Old = PyStatic.NewNone();
762  cc.sharesOld = PyStatic.NewNone();
763  cc.stationIDOld = PyStatic.NewNone();
764  cc.taxRateOld = PyStatic.NewNone();
765  cc.tickerNameOld = PyStatic.NewNone();
766  cc.typefaceOld = PyStatic.NewNone();
767  cc.urlOld = PyStatic.NewNone();
768  cc.isRecruitingOld = PyStatic.NewNone();
769 
770  return true;
771 }
772 
774 {
775  DBQueryResult res;
776  if (!sDatabase.RunQuery(res,
777  " SELECT "
778  " characterID, "
779  " corporationID,"
780  " corpAccountKey AS divisionID,"
781  " 0 AS squadronID,"
782  " title, "
783  " corpRole AS roles,"
784  " rolesAtAll, "
785  " grantableRoles, "
786  " startDateTime, "
787  " baseID,"
788  " rolesAtHQ, "
789  " grantableRolesAtHQ, "
790  " rolesAtBase, "
791  " grantableRolesAtBase,"
792  " rolesAtOther, "
793  " grantableRolesAtOther, "
794  " titleMask,"
795  " startDateTime AS rowDate,"
796  " blockRoles,"
797  " characterName"
798  " FROM chrCharacters"
799  " WHERE characterID = %u", charID))
800  {
801  codelog(CORP__DB_ERROR, "Error in query: %s", res.error.c_str());
802  return nullptr;
803  }
804 
805  DBResultRow row;
806  if (!res.GetRow(row))
807  return nullptr;
808  return DBRowToPackedRow(row);
809 }
810 
812 {
813  if (!sDatabase.RunQuery(res,
814  " SELECT "
815  " characterID, "
816  " corporationID,"
817  " corpAccountKey AS divisionID,"
818  //" 0 AS squadronID,"
819  " title, "
820  " rolesAtAll, "
821  " grantableRoles, "
822  " startDateTime, "
823  " baseID,"
824  " rolesAtHQ, "
825  " grantableRolesAtHQ, "
826  " rolesAtBase, "
827  " grantableRolesAtBase,"
828  " rolesAtOther, "
829  " grantableRolesAtOther, "
830  " titleMask,"
831  " corpAccountKey,"
832  //" %f AS rowDate,"
833  " blockRoles,"
834  " characterName"
835  " FROM chrCharacters"
836  " WHERE corporationID = %u", corpID))
837  {
838  codelog(CORP__DB_ERROR, "Error in query: %s", res.error.c_str());
839  }
840 }
841 
842 void CorporationDB::GetMembersForQuery(std::ostringstream& query, std::vector< uint32 >& result)
843 {
844  DBQueryResult res;
845  if (!sDatabase.RunQuery(res, query.str().c_str())) {
846  codelog(CORP__DB_ERROR, "Error in query: %s", res.error.c_str());
847  return;
848  }
849 
850  _log(DATABASE__RESULTS, "CorporationDB::GetMembersForQuery '%s' returned %u items", query.str().c_str(), res.GetRowCount());
851 
852  DBResultRow row;
853  while (res.GetRow(row))
854  result.push_back(row.GetInt(0));
855 }
856 
858 {
859  if (!sDatabase.RunQuery(res,
860  " SELECT "
861  " characterID, "
862  " corporationID,"
863  //" 0 AS divisionID,"
864  //" 0 AS squadronID,"
865  " title, "
866  " rolesAtAll, "
867  " grantableRoles, "
868  " startDateTime, "
869  //" clone.locationID,"
870  " rolesAtHQ, "
871  " grantableRolesAtHQ, "
872  " rolesAtBase, "
873  " grantableRolesAtBase,"
874  " rolesAtOther, "
875  " grantableRolesAtOther, "
876  " titleMask,"
877  " corpAccountKey, "
878  " baseID,"
879  " blockRoles,"
880  " characterName"
881  " FROM chrCharacters"
882  //" LEFT JOIN entity AS clone ON clone.ownerID = characterID"
883  " WHERE corporationID = %u"
884  " LIMIT %u", corpID, page * 10))
885  //" AND clone.flag='400'"
886  //" AND clone.customInfo='active'"
887  {
888  codelog(CORP__DB_ERROR, "Error in query: %s", res.error.c_str());
889  }
890 }
891 
893 {
894  DBQueryResult res;
895  if (!sDatabase.RunQuery(res, "SELECT COUNT(characterID) FROM chrCharacters WHERE corporationID = %u", corpID )) {
896  codelog(CORP__DB_ERROR, "Error in query: %s", res.error.c_str());
897  return 0;
898  }
899 
900  DBResultRow row;
901  if (res.GetRow(row))
902  return (row.GetInt(0));
903 
904  return 0;
905 }
906 
907 void CorporationDB::GetMemberIDs(uint32 corpID, std::vector< uint32 >& ids, bool online/*true*/)
908 {
909  ids.clear();
910  DBQueryResult res;
911  if (!sDatabase.RunQuery(res, "SELECT characterID FROM chrCharacters WHERE corporationID = %u AND online = %u", corpID, (online?1:0) )) {
912  codelog(CORP__DB_ERROR, "Error in query: %s", res.error.c_str());
913  return;
914  }
915 
916  DBResultRow row;
917  while (res.GetRow(row))
918  ids.push_back(row.GetInt(0));
919 }
920 
922 {
923  DBQueryResult res;
924  if (!sDatabase.RunQuery( res, "SELECT roleID, roleName, shortDescriptionID, descriptionID, roleIID FROM crpRoles")) {
925  codelog(CORP__DB_ERROR, "Error in query: %s", res.error.c_str());
926  return nullptr;
927  }
928 
929  return DBResultToCRowset(res);
930 }
931 
933 {
934  DBQueryResult res;
935  if (!sDatabase.RunQuery( res,
936  "SELECT roleGroupID, roleGroupName, roleGroupNameID, roleMask, appliesTo, appliesToGrantable, isLocational, isDivisional"
937  " FROM crpRoleGroups"))
938  {
939  codelog(CORP__DB_ERROR, "Error in query: %s", res.error.c_str());
940  return nullptr;
941  }
942 
943  return DBResultToCRowset(res);
944 }
945 
947 {
948  DBerror err;
949  sDatabase.RunQuery(err, "DELETE FROM crpRoleTitles WHERE corpID = %u AND titleID = %u", corpID, titleID);
950  std::string title = "Untitled ";
951  title += std::to_string(log2(titleID) + 1);
952  sDatabase.RunQuery(err, "INSERT INTO crpRoleTitles (corporationID, titleID, titleName) VALUES (%u,%u,'%s')", corpID, titleID, title.c_str());
953 }
954 
955 bool CorporationDB::UpdateTitle(uint32 corpID, Call_UpdateTitleData& args, PyDict* updates)
956 {
957  if (IsNPCCorp(corpID))
958  return false;
959 
960  DBQueryResult res;
961  if (!sDatabase.RunQuery( res,
962  "SELECT titleName, roles, grantableRoles, rolesAtHQ, grantableRolesAtHQ, rolesAtBase, grantableRolesAtBase, rolesAtOther, grantableRolesAtOther "
963  " FROM crpRoleTitles WHERE corporationID = %u AND titleID = %u", corpID, args.titleID))
964  {
965  codelog(CORP__DB_ERROR, "Error in query: %s", res.error.c_str());
966  return false;
967  }
968 
969  DBResultRow row;
970  if (!res.GetRow(row)) {
971  _log(CORP__DB_WARNING, "No title data for titleID %u in corpID %u.", args.titleID, corpID);
972  return false;
973  }
974 
975  std::vector<std::string> dbQ;
976  ProcessStringChange("titleName", row.GetText(0), args.titleName, updates, dbQ);
977  ProcessLongChange("roles", row.GetInt64(1), args.roles, updates, dbQ);
978  ProcessLongChange("grantableRoles", row.GetInt64(2), args.grantableRoles, updates, dbQ);
979  ProcessLongChange("rolesAtHQ", row.GetInt64(3), args.rolesAtHQ, updates, dbQ);
980  ProcessLongChange("grantableRolesAtHQ", row.GetInt64(4), args.grantableRolesAtHQ, updates, dbQ);
981  ProcessLongChange("rolesAtBase", row.GetInt64(5), args.rolesAtBase, updates, dbQ);
982  ProcessLongChange("grantableRolesAtBase", row.GetInt64(6), args.grantableRolesAtBase, updates, dbQ);
983  ProcessLongChange("rolesAtOther", row.GetInt64(7), args.rolesAtOther, updates, dbQ);
984  ProcessLongChange("grantableRolesAtOther", row.GetInt64(8), args.grantableRolesAtOther, updates, dbQ);
985 
986  std::string query = "UPDATE crpRoleTitles SET ";
987 
988  int N = dbQ.size();
989  for (int i = 0; i < N; ++i) {
990  query += dbQ[i];
991  if (i < N - 1)
992  query += ", ";
993  }
994 
995  query += " WHERE corporationID = ";
996  query += std::to_string(corpID);
997  query += " AND titleID = ";
998  query += std::to_string(args.titleID);
999 
1000  _log(CORP__DB_MESSAGE, "DB Query: %s", query.c_str());
1001 
1002  DBerror err;
1003  // We are here, so something must have changed...
1004  if (N < 1)
1005  return false;
1006 
1007  if (!sDatabase.RunQuery(err, query.c_str())) {
1008  codelog(CORP__DB_ERROR, "Error in query: %s", err.c_str());
1009  return false;
1010  }
1011  return true;
1012 }
1013 
1015 {
1016  DBQueryResult res;
1017  if (!sDatabase.RunQuery( res,
1018  "SELECT corporationID, titleID, titleName, roles, grantableRoles, rolesAtHQ, grantableRolesAtHQ, rolesAtBase, grantableRolesAtBase, rolesAtOther, grantableRolesAtOther "
1019  " FROM crpRoleTitles WHERE corporationID = %u", corpID)) {
1020  codelog(CORP__DB_ERROR, "Error in query: %s", res.error.c_str());
1021  return nullptr;
1022  }
1023  PyDict* dict = new PyDict();
1024  DBResultRow row;
1025  while (res.GetRow(row)) {
1026  PyDict* dict1 = new PyDict();
1027  dict1->SetItemString("corporationID", new PyInt(row.GetInt(0)));
1028  dict1->SetItemString("titleID", new PyInt(row.GetInt(1)));
1029  dict1->SetItemString("titleName", new PyString(row.GetText(2)));
1030  dict1->SetItemString("roles", new PyLong(row.GetInt64(3)));
1031  dict1->SetItemString("grantableRoles", new PyLong(row.GetInt64(4)));
1032  dict1->SetItemString("rolesAtHQ", new PyLong(row.GetInt64(5)));
1033  dict1->SetItemString("grantableRolesAtHQ", new PyLong(row.GetInt64(6)));
1034  dict1->SetItemString("rolesAtBase", new PyLong(row.GetInt64(7)));
1035  dict1->SetItemString("grantableRolesAtBase", new PyLong(row.GetInt64(8)));
1036  dict1->SetItemString("rolesAtOther", new PyLong(row.GetInt64(9)));
1037  dict1->SetItemString("grantableRolesAtOther", new PyLong(row.GetInt64(10)));
1038  dict->SetItem(new PyInt(row.GetInt(1)), new PyObject("util.KeyVal", dict1));
1039  }
1040 
1041  return dict;
1042 }
1043 
1045 {
1046  DBerror err;
1047  sDatabase.RunQuery(err,
1048  "INSERT INTO crpRoleTitles (corporationID, titleID, titleName) VALUES"
1049  "(%u,1,'Untitled 1'),(%u,2,'Untitled 2'),(%u,4,'Untitled 3'),(%u,8,'Untitled 4'),(%u,16,'Untitled 5'),(%u,32,'Untitled 6'),"
1050  "(%u,64,'Untitled 7'),(%u,128,'Untitled 8'),(%u,256,'Untitled 9'),(%u,512,'Untitled 10'),(%u,1024,'Untitled 11'),(%u,2048,'Untitled 12'),"
1051  "(%u,4096,'Untitled 13'),(%u,8192,'Untitled 14'),(%u,16384,'Untitled 15'),(%u,32768,'Untitled 16')",
1052  corpID,corpID,corpID,corpID,corpID,corpID,corpID,corpID,corpID,corpID,corpID,corpID,corpID,corpID,corpID,corpID);
1053 }
1054 
1055 /* * UPDATE crpRoleTitles SET corporationID=[value-1],titleID=[value-2],titleName=[value-3],roles=[value-4],grantableRoles=[value-5],rolesAtHQ=[value-6],grantableRolesAtHQ=[value-7],rolesAtBase=[value-8],grantableRolesAtBase=[value-9],rolesAtOther=[value-10],grantableRolesAtOther=[value-11] WHERE corporationID
1056  */
1057 
1059 {
1060  _log(SOV__DEBUG, "CorporationDB::GetContacts() called...");
1061 
1062  DBQueryResult res;
1063  if (!sDatabase.RunQuery( res,
1064  "SELECT contactID, inWatchlist, relationshipID, labelMask"
1065  " FROM crpContacts WHERE ownerID = %u", corpID))
1066  {
1067  codelog(CORP__DB_ERROR, "Error in query: %s", res.error.c_str());
1068  return nullptr;
1069  }
1070 
1071  PyObjectEx* obj = DBResultToCIndexedRowset(res, "contactID");
1072  if (is_log_enabled(CORP__RSP_DUMP))
1073  obj->Dump(CORP__RSP_DUMP, "");
1074 
1075  return obj;
1076 }
1077 
1078 void CorporationDB::AddContact(uint32 ownerID, Call_CorporateContactData corpData)
1079 {
1080  DBerror err;
1081  sDatabase.RunQuery(err,
1082  "INSERT INTO crpContacts (ownerID, contactID, relationshipID, "
1083  " inWatchlist, labelMask) VALUES "
1084  " (%u, %u, %i, 0, 0) ",
1085  ownerID, corpData.contactID, corpData.relationshipID);
1086 }
1087 
1088 void CorporationDB::UpdateContact(int32 relationshipID, uint32 contactID, uint32 ownerID)
1089 {
1090  DBerror err;
1091  sDatabase.RunQuery(err,
1092  "UPDATE crpContacts SET relationshipID=%i "
1093  " WHERE contactID=%u AND ownerID=%u ",
1094  relationshipID, contactID, ownerID);
1095 }
1096 
1098 {
1099  DBerror err;
1100  sDatabase.RunQuery(err,
1101  "DELETE from crpContacts "
1102  " WHERE contactID=%u AND ownerID=%u ",
1103  contactID, ownerID);
1104 }
1105 
1106 // should this be cached? ...yes
1108  DBQueryResult res;
1109 /*
1110  [PyPackedRow 9 bytes]
1111  ["ownerID" => <90046865> [I4]]
1112  ["ownerName" => <Septure> [WStr]]
1113  ["typeID" => <1375> [I4]]
1114  ["gender" => <1> [Bool]]
1115  */
1116 
1117  if (!sDatabase.RunQuery( res,
1118  "SELECT"
1119  " characterID AS ownerID,"
1120  " characterName AS ownerName,"
1121  " typeID,"
1122  " gender"
1123  " FROM chrCharacters"
1124  " WHERE corporationID = %u", corpID
1125  ))
1126  {
1127  codelog(CORP__DB_ERROR, "Error in query: %s", res.error.c_str());
1128  return nullptr;
1129  }
1130 
1131  return DBResultToRowset(res);
1132 }
1133 
1135  DBQueryResult res;
1136 
1137  if (!sDatabase.RunQuery(res,
1138  " SELECT "
1139  " stationID, stationTypeID as typeID "
1140  " FROM staStations "
1141  " WHERE corporationID = %u ", corpID
1142  ))
1143  {
1144  codelog(CORP__DB_ERROR, "Error in query: %s", res.error.c_str());
1145  return nullptr;
1146  }
1147  return DBResultToRowset(res);
1148 }
1149 
1151  DBQueryResult res;
1152 
1153  if (!sDatabase.RunQuery(res,
1154  "SELECT stationID, stationTypeID, itemID, officeFolderID"
1155  " FROM staOffices "
1156  " WHERE corporationID = %u "
1157  " LIMIT %u, %u ", corpID, from, count
1158  ))
1159  {
1160  codelog(CORP__DB_ERROR, "Error in query: %s", res.error.c_str());
1161  return nullptr;
1162  }
1163 
1164  // manually build the return. easier this way...
1165  PyList* list = new PyList();
1166 
1167  DBResultRow row;
1168  while (res.GetRow(row)) {
1169  PyList* innerList = new PyList();
1170  innerList->AddItem(new PyInt(row.GetInt(0)));
1171  innerList->AddItem(new PyInt(row.GetInt(1))); // this wants stationTypeID
1172  innerList->AddItem(new PyInt(row.GetInt(2)));
1173  innerList->AddItem(new PyInt(row.GetInt(3)));
1174  PyTuple* tuple = new PyTuple(2);
1175  tuple->SetItem(0, new PyInt(row.GetInt(0)));
1176  tuple->SetItem(1, innerList);
1177  list->AddItem(tuple);
1178  }
1179  return list;
1180 }
1181 
1182 //NOTE: it makes sense to push this up to ServiceDB, since others will likely need this too.
1184  DBQueryResult res;
1185  if (!sDatabase.RunQuery(res,
1186  " SELECT corporationID "
1187  " FROM staStations "
1188  " WHERE stationID = %u ", stationID))
1189  {
1190  codelog(CORP__DB_ERROR, "Error in query: %s", res.error.c_str());
1191  return 0;
1192  }
1193 
1194  DBResultRow row;
1195  if (!res.GetRow(row)) {
1196  codelog(CORP__DB_WARNING, "Missing stationID: %u", stationID);
1197  return 0;
1198  }
1199  return row.GetUInt(0);
1200 }
1201 
1203 {
1204  DBerror err;
1205  sDatabase.RunQuery(err, "DELETE FROM crpBulletins WHERE bulletinID = %u", bulletinID);
1206 }
1207 
1208 void CorporationDB::AddBulletin(uint32 corpID, uint32 ownerID, uint32 cCharID, std::string& title, std::string& body)
1209 {
1210  DBerror err;
1211  sDatabase.RunQuery(err,
1212  "INSERT INTO crpBulletins (corporationID, ownerID, createCharacterID, createDateTime, editCharacterID, editDateTime, title, body)"
1213  " VALUES (%u, %u, %u, %f, %u, %f, '%s', '%s')", corpID, ownerID, cCharID, GetFileTimeNow(), cCharID, GetFileTimeNow(), title.c_str(), body.c_str());
1214 }
1215 
1216 void CorporationDB::EditBulletin(uint32 bulletinID, uint32 eCharID, int64 eDataTime, std::string& title, std::string& body)
1217 {
1218  DBerror err;
1219  sDatabase.RunQuery(err,
1220  "UPDATE crpBulletins SET editCharacterID = %u, editDateTime = %li, title = '%s', body = '%s'"
1221  " WHERE bulletinID = %u", eCharID, eDataTime, title.c_str(), body.c_str(), bulletinID);
1222 }
1223 
1225 {
1226  DBQueryResult res;
1227  if (!sDatabase.RunQuery(res,
1228  "SELECT corporationID, bulletinID, ownerID, createCharacterID, createDateTime, editCharacterID, editDateTime, title, body"
1229  " FROM crpBulletins"
1230  " WHERE corporationID = %u ", corpID))
1231  {
1232  codelog(CORP__DB_ERROR, "Error in query: %s", res.error.c_str());
1233  return nullptr;
1234  }
1235  return DBResultToCRowset(res);
1236 }
1237 
1238 void CorporationDB::AddRecruiters(uint16 adID, int32 corpID, std::vector< int32 >& charVec)
1239 {
1240  std::ostringstream str;
1241  str << "INSERT INTO crpRecruiters (adID, corpID, charID) VALUES ";
1242 
1243  bool first = true;
1244  for (auto cur : charVec) {
1245  if (!IsCharacterID(cur))
1246  continue;
1247  if (first) {
1248  first = false;
1249  } else {
1250  str << ",";
1251  }
1252  str << "(" << adID << "," << corpID << "," << cur << ")";
1253  }
1254 
1255  if (!first ) {
1256  DBerror err;
1257  sDatabase.RunQuery(err, "DELETE FROM crpRecruiters WHERE corpID = %u AND adID = %u", corpID, adID);
1258  sDatabase.RunQuery(err, str.str().c_str());
1259  }
1260 }
1261 
1263 {
1264  DBQueryResult res;
1265  if (!sDatabase.RunQuery(res, "SELECT charID FROM crpRecruiters WHERE corpID = %u AND adID = %u", corpID, adID)) {
1266  codelog(CORP__DB_ERROR, "Error in query: %s", res.error.c_str());
1267  return nullptr;
1268  }
1269 
1270  PyTuple* tuple = new PyTuple(res.GetRowCount());
1271  int8 i = 0;
1272  DBResultRow row;
1273  while (res.GetRow(row))
1274  tuple->SetItem(i++, new PyInt(row.GetInt(0)));
1275 
1276  return tuple;
1277 }
1278 
1280 {
1281  DBQueryResult res;
1282  if (!sDatabase.RunQuery(res, "SELECT typeMask, typeName, typeNameID, groupID, description, descriptionID FROM crpAdTypeData")) {
1283  codelog(CORP__DB_ERROR, "Error in query: %s", res.error.c_str());
1284  return nullptr;
1285  }
1286  return DBResultToCRowset(res);
1287 }
1288 
1290 {
1291  DBQueryResult res;
1292  if (!sDatabase.RunQuery(res, "SELECT groupID, groupName, groupNameID, description, descriptionID FROM crpAdGroupData")) {
1293  codelog(CORP__DB_ERROR, "Error in query: %s", res.error.c_str());
1294  return nullptr;
1295  }
1296  return DBResultToCRowset(res);
1297 }
1298 
1299 PyRep* CorporationDB::GetAdRegistryData(int64 typeMask/*0*/, bool inAlliance/*false*/, int16 minMembers/*0*/, uint16 maxMembers/*12602*/)
1300 {
1301  // make sure this isnt 0
1302  if (maxMembers < 1)
1303  maxMembers = 12602;
1304 
1305  DBQueryResult res;
1306  if (!sDatabase.RunQuery(res,
1307  "SELECT"
1308  " adID, corporationID, allianceID, stationID, regionID, raceMask, typeMask,"
1309  " createDateTime, expiryDateTime, title, description, memberCount, channelID"
1310  " FROM crpAdRegistry"
1311  " WHERE allianceID %s 0"
1312  " AND (memberCount >= %u AND memberCount < %u)",
1313  (inAlliance ? ">" : "="), minMembers, maxMembers))
1314  {
1315  codelog(CORP__DB_ERROR, "Error in query: %s", res.error.c_str());
1316  return nullptr;
1317  }
1318 
1319  return DBResultToCRowset(res);
1320 }
1321 
1323 {
1324  DBQueryResult res;
1325  if (!sDatabase.RunQuery(res,
1326  "SELECT"
1327  " adID, corporationID, allianceID, stationID, regionID, raceMask, typeMask,"
1328  " createDateTime, expiryDateTime, title, description, memberCount, channelID"
1329  " FROM crpAdRegistry"
1330  " WHERE adID = %u", adID))
1331  {
1332  codelog(CORP__DB_ERROR, "Error in query: %s", res.error.c_str());
1333  return nullptr;
1334  }
1335 
1336  return DBResultToCRowset(res);
1337 }
1338 
1340 {
1341  DBerror err;
1342  sDatabase.RunQuery(err, "DELETE FROM crpAdRegistry WHERE adID=%u ", adID);
1343 }
1344 
1345 uint32 CorporationDB::CreateAdvert(Client* pClient, uint32 corpID, int64 typeMask, int8 days, uint16 members, std::string description, uint32 channelID, std::string title)
1346 {
1347  uint32 adID = 0;
1348  DBerror err;
1349  sDatabase.RunQueryLID(err, adID, "INSERT INTO crpAdRegistry"
1350  " (corporationID, allianceID, stationID, regionID, raceMask, typeMask,"
1351  " createDateTime, expiryDateTime, description, title, memberCount, channelID)"
1352  " VALUES (%u,%u,%u,%u,%u,%li,%f,%f,'%s','%s',%u,%u)",
1353  corpID, pClient->GetAllianceID(), pClient->GetStationID(), pClient->GetRegionID(), 15, typeMask, // raceMask isnt implemented yet
1354  GetFileTimeNow(), GetFileTimeNow() + (EvE::Time::Day * days), description.c_str(), title.c_str(), members, channelID);
1355 
1356  return adID;
1357 }
1358 
1359 void CorporationDB::UpdateAdvert(uint16 adID, uint32 corpID, int64 typeMask, int8 days, uint16 members, std::string description, uint32 channelID, std::string title)
1360 {
1361  int64 time = GetFileTimeNow() + (EvE::Time::Day * days);
1362  DBerror err;
1363  sDatabase.RunQuery(err, "UPDATE crpAdRegistry"
1364  " SET typeMask=%li, expiryDateTime=%li, description='%s', title='%s', memberCount=%u, channelID=%u"
1365  " WHERE adID=%u ",
1366  typeMask, time, description.c_str(), title.c_str(), members, channelID, adID);
1367 }
1368 
1370 {
1371  DBQueryResult res;
1372  sDatabase.RunQuery(res, "SELECT expiryDateTime FROM crpAdRegistry WHERE adID=%u AND corporationID=%u", adID, corpID);
1373  DBResultRow row;
1374  if (res.GetRow(row))
1375  return row.GetInt64(0);
1376 
1377  return 0;
1378 }
1379 
1381  // header = [applicationID, corporationID, characterID, applicationText, roles, grantableRoles, status, applicationDateTime, deleted, lastCorpUpdaterID]
1382  DBQueryResult res;
1383  if (!sDatabase.RunQuery(res,
1384  " SELECT applicationID, corporationID, characterID, applicationText, roles, grantableRoles,"
1385  " status, applicationDateTime, deleted, lastCorpUpdaterID"
1386  " FROM crpApplications"
1387  " WHERE characterID = %u ", charID))
1388  {
1389  codelog(CORP__DB_ERROR, "Error in query: %s", res.error.c_str());
1390  return nullptr;
1391  }
1392 
1393  PyObjectEx* obj = DBResultToCRowset(res);
1394  if (is_log_enabled(CORP__RSP_DUMP))
1395  obj->Dump(CORP__RSP_DUMP, "");
1396 
1397  return obj;
1398 }
1399 
1401  DBQueryResult res;
1402  if (!sDatabase.RunQuery(res,
1403  " SELECT"
1404  " applicationID, characterID, corporationID, applicationText, status,"
1405  " applicationDateTime, lastCorpUpdaterID"
1406  " FROM crpApplications"
1407  " WHERE corporationID = %u AND deleted = 0",
1408  corpID))
1409  {
1410  codelog(CORP__DB_ERROR, "Error in query: %s", res.error.c_str());
1411  return nullptr;
1412  }
1413  PyObjectEx* obj = DBResultToCIndexedRowset(res, "characterID");
1414  if (is_log_enabled(CORP__RSP_DUMP))
1415  obj->Dump(CORP__RSP_DUMP, "");
1416 
1417  return obj;
1418 }
1419 
1421  DBQueryResult res;
1422  if (!sDatabase.RunQuery(res,
1423  " SELECT"
1424  " applicationID, applicationText, roles, grantableRoles, status,"
1425  " applicationDateTime, lastCorpUpdaterID, deleted"
1426  " FROM crpApplications"
1427  " WHERE characterID = %u AND corporationID = %u AND applicationText = '%s'",
1428  aInfo.charID, aInfo.corpID, aInfo.appText.c_str()))
1429  {
1430  codelog(CORP__DB_ERROR, "Error in query: %s", res.error.c_str());
1431  aInfo.valid = false;
1432  return false;
1433  }
1434 
1435  DBResultRow row;
1436  if (!res.GetRow(row)) {
1437  codelog(CORP__DB_WARNING, "There's no application matching the sent data.");
1438  aInfo.valid = false;
1439  return false;
1440  }
1441 
1442  aInfo.appID = row.GetInt(0);
1443  aInfo.appText = row.GetText(1);
1444  aInfo.role = row.GetInt64(2);
1445  aInfo.grantRole = row.GetInt64(3);
1446  aInfo.status = row.GetInt(4);
1447  aInfo.appTime = row.GetInt64(5);
1448  aInfo.lastCID = row.GetInt(6);
1449  aInfo.deleted = row.GetInt(7);
1450  aInfo.valid = true;
1451  return true;
1452 }
1453 
1455  if (!aInfo.valid) {
1456  _log(CORP__DB_WARNING, "InsertApplication(): aInfo contains invalid data");
1457  return false;
1458  }
1459 
1460  std::string escaped;
1461  sDatabase.DoEscapeString(escaped, aInfo.appText);
1462  DBerror err;
1463  if (!sDatabase.RunQueryLID(err, aInfo.appID,
1464  " INSERT INTO crpApplications"
1465  " (corporationID, characterID, applicationText, applicationDateTime)"
1466  " VALUES (%u, %u, '%s', %li)",
1467  aInfo.corpID, aInfo.charID, escaped.c_str(), aInfo.appTime))
1468  {
1469  codelog(CORP__DB_ERROR, "Error in query: %s", err.c_str());
1470  return false;
1471  }
1472 
1473  return true;
1474 }
1475 
1477  if (!aInfo.valid) {
1478  _log(CORP__DB_WARNING, "UpdateApplication(): info contains invalid data");
1479  return false;
1480  }
1481 
1482  DBerror err;
1483  std::string escaped;
1484  sDatabase.DoEscapeString(escaped, aInfo.appText);
1485  if (!sDatabase.RunQuery(err,
1486  " UPDATE crpApplications"
1487  " SET status = %u, lastCorpUpdaterID = %u, applicationText = '%s'"
1488  " WHERE applicationID = %u", aInfo.status, aInfo.lastCID, escaped.c_str(), aInfo.appID))
1489  {
1490  codelog(CORP__DB_ERROR, "Error in query: %s", err.c_str());
1491  return false;
1492  }
1493  return true;
1494 }
1495 
1497  DBerror err;
1498  if (!sDatabase.RunQuery(err,
1499  " UPDATE crpApplications"
1500  " SET status = 3, deleted = 1"
1501  " WHERE applicationID = %u", aInfo.appID))
1502  {
1503  codelog(CORP__DB_ERROR, "Error in query: %s", err.c_str());
1504  return false;
1505  }
1506  return true;
1507 }
1508 
1510  if (!sDataMgr.IsStation(stationID))
1511  return 0;
1512  DBQueryResult res;
1513  if (!sDatabase.RunQuery(res,
1514  " SELECT c.ceoID "
1515  " FROM crpCorporation AS c"
1516  " LEFT JOIN staStations USING (corporationID) "
1517  " WHERE staStations.stationID = %u ", stationID))
1518  {
1519  codelog(CORP__DB_ERROR, "Error in query: %s", res.error.c_str());
1520  return 0;
1521  }
1522  DBResultRow row;
1523  if (!res.GetRow(row)) {
1524  codelog(CORP__DB_WARNING, "There's either no such station or the station has no corp owner or the corporation has no ceo.");
1525  return 0;
1526  }
1527  return row.GetUInt(0);
1528 }
1529 
1531  DBQueryResult res;
1532  if (!sDatabase.RunQuery(res,
1533  " SELECT ceoID "
1534  " FROM crpCorporation "
1535  " WHERE corporationID = %u ", corpID))
1536  {
1537  codelog(CORP__DB_ERROR, "Error in query: %s", res.error.c_str());
1538  return 0;
1539  }
1540  DBResultRow row;
1541  if (!res.GetRow(row)) {
1542  codelog(CORP__DB_WARNING, "There's either no such corp owner or the corporation has no ceo.");
1543  return 0;
1544  }
1545  return row.GetUInt(0);
1546 }
1547 
1549  DBQueryResult res;
1550  if (!sDatabase.RunQuery(res,
1551  " SELECT memberCount"
1552  " FROM crpCorporation"
1553  " WHERE corporationID = %u ", corpID))
1554  {
1555  codelog(CORP__DB_ERROR, "Error in query: %s", res.error.c_str());
1556  return 0;
1557  }
1558  DBResultRow row;
1559  if (!res.GetRow(row)) {
1560  codelog(CORP__DB_WARNING, "Cannot find memberCount for corpID %u", corpID);
1561  return 0;
1562  }
1563  return row.GetInt(0);
1564 }
1565 
1567 {
1568  DBQueryResult res;
1569  if (!sDatabase.RunQuery(res,
1570  " SELECT memberLimit"
1571  " FROM crpCorporation"
1572  " WHERE corporationID = %u ", corpID))
1573  {
1574  codelog(CORP__DB_ERROR, "Error in query: %s", res.error.c_str());
1575  return 0;
1576  }
1577  DBResultRow row;
1578  if (!res.GetRow(row)) {
1579  codelog(CORP__DB_WARNING, "Cannot find memberLimit for corpID %u", corpID);
1580  return 0;
1581  }
1582  return row.GetInt(0);
1583 }
1584 
1586  DBQueryResult res;
1587  if (!sDatabase.RunQuery(res,
1588  " SELECT basePrice "
1589  " FROM invTypes "
1590  " WHERE typeID = %u ", cloneTypeID))
1591  {
1592  codelog(CORP__DB_ERROR, "Failed to retrieve basePrice of typeID = %u",cloneTypeID);
1593  }
1594  DBResultRow row;
1595  if (!res.GetRow(row)) {
1596  codelog(CORP__DB_WARNING, "GetCloneTypeCostByID returned no results");
1597  return 0;
1598  }
1599  return row.GetDouble(0);
1600 }
1601 
1602 bool CorporationDB::CreateMemberAttributeUpdate(uint32 newCorpID, uint32 charID, MemberAttributeUpdate& attrib) {
1603  // What are we doing here exactly?
1604  // Corporation gets a new member
1605  // it's new to it
1606 
1607  DBQueryResult res;
1608  DBResultRow row;
1609  if (!sDatabase.RunQuery(res,
1610  " SELECT "
1611  " title, startDateTime, corporationID, "
1612  " corpRole, rolesAtAll, rolesAtBase, "
1613  " rolesAtHQ, rolesAtOther, titleMask, baseID "
1614  " FROM chrCharacters "
1615  " WHERE characterID = %u ", charID))
1616  {
1617  codelog(CORP__DB_ERROR, "Error in query: %s", res.error.c_str());
1618  return false;
1619  }
1620 
1621  if (!res.GetRow(row)) {
1622  codelog(CORP__DB_WARNING, "Cannot find character in database");
1623  return false;
1624  }
1625 
1626  // this could be stored in the db
1627 #define PRN PyStatic.NewNone()
1628 #define PRI(i) new PyInt(i)
1629 #define PRL(i) new PyLong(i)
1630 #define PRS(s) new PyString(s)
1631 #define PRNI(i) (row.IsNull(i) ? PRU(0) : PRU(row.GetInt64(i)))
1632 #define F(name, o, n) \
1633  attrib.name##Old = o; \
1634  attrib.name##New = n
1635 
1636  //element Old Value New Value
1637  F(accountKey, PRN, PRN);
1638  F(baseID, PRI(row.GetInt(9)), PRI(0));
1639  F(characterID, PRN, PRI(charID));
1640  F(corporationID, PRI(row.GetUInt(2)), PRI(newCorpID));
1641  F(divisionID, PRN, PRN);
1642  F(roles, PRL(row.GetInt64(3)), PRI(0));
1643  F(grantableRoles, PRL(row.GetInt64(4)), PRI(0));
1644  F(grantableRolesAtBase, PRL(row.GetInt64(5)), PRI(0));
1645  F(grantableRolesAtHQ, PRL(row.GetInt64(6)), PRI(0));
1646  F(grantableRolesAtOther, PRL(row.GetInt64(7)), PRI(0));
1647  F(squadronID, PRN, PRN);
1648  F(startDateTime, PRL(row.GetInt64(1)), PRL(GetFileTimeNow()));
1649  F(titleMask, PRL(row.GetInt64(8)), PRI(0));
1650 
1651 #undef F
1652 #undef PRN
1653 #undef PRI
1654 #undef PRS
1655 #undef PRL
1656 #undef PRNI
1657 
1658  return true;
1659 }
1660 
1661 bool CorporationDB::UpdateDivisionNames(uint32 corpID, const Call_UpdateDivisionNames& divs, PyDict* notif) {
1662  // updated to update wallet names, too. -allan 14Jan15
1663  if (IsNPCCorp(corpID))
1664  return false; // make error here for changing npc corp data? nah, should NEVER hit
1665  DBQueryResult res;
1666  if (!sDatabase.RunQuery(res,
1667  "SELECT"
1668  " division1, division2, division3, division4, division5, division6, division7,"
1669  " walletDivision2, walletDivision3, walletDivision4, walletDivision5, walletDivision6, walletDivision7"
1670  " FROM crpWalletDivisons"
1671  " WHERE corporationID = %u", corpID))
1672  {
1673  codelog(CORP__DB_ERROR, "Error in query: %s", res.error.c_str());
1674  return false;
1675  }
1676 
1677  DBResultRow row;
1678  if (!res.GetRow(row)) {
1679  codelog(CORP__DB_WARNING, "Corporation %u doesn't exist.", corpID);
1680  return false;
1681  }
1682 
1683  std::vector<std::string> dbQ;
1684  ProcessStringChange("division1", row.GetText(0), divs.div1, notif, dbQ);
1685  ProcessStringChange("division2", row.GetText(1), divs.div2, notif, dbQ);
1686  ProcessStringChange("division3", row.GetText(2), divs.div3, notif, dbQ);
1687  ProcessStringChange("division4", row.GetText(3), divs.div4, notif, dbQ);
1688  ProcessStringChange("division5", row.GetText(4), divs.div5, notif, dbQ);
1689  ProcessStringChange("division6", row.GetText(5), divs.div6, notif, dbQ);
1690  ProcessStringChange("division7", row.GetText(6), divs.div7, notif, dbQ);
1691  //ProcessStringChange("walletDivision1", row.GetText(7), divs.wallet1, notif, dbQ); cannot change this one
1692  ProcessStringChange("walletDivision2", row.GetText(7), divs.wallet2, notif, dbQ);
1693  ProcessStringChange("walletDivision3", row.GetText(8), divs.wallet3, notif, dbQ);
1694  ProcessStringChange("walletDivision4", row.GetText(9), divs.wallet4, notif, dbQ);
1695  ProcessStringChange("walletDivision5", row.GetText(10), divs.wallet5, notif, dbQ);
1696  ProcessStringChange("walletDivision6", row.GetText(11), divs.wallet6, notif, dbQ);
1697  ProcessStringChange("walletDivision7", row.GetText(12), divs.wallet7, notif, dbQ);
1698 
1699  std::string query = "UPDATE crpWalletDivisons SET ";
1700 
1701  int N = dbQ.size();
1702  for (int i = 0; i < N; ++i) {
1703  query += dbQ[i];
1704  if (i < N - 1)
1705  query += ", ";
1706  }
1707 
1708  query += " WHERE corporationID = ";
1709  query += std::to_string(corpID);
1710 
1711  _log(CORP__DB_MESSAGE, "DB Query: %s", query.c_str());
1712 
1713  DBerror err;
1714  // We are here, so something must have changed...
1715  if (N > 0)
1716  if (!sDatabase.RunQuery(err, query.c_str())) {
1717  codelog(CORP__DB_ERROR, "Error in query: %s", err.c_str());
1718  return false;
1719  }
1720 
1721  return true;
1722 }
1723 
1725 {
1726  DBQueryResult res;
1727  if (!sDatabase.RunQuery(res, "SELECT corporationName FROM crpCorporation WHERE corporationID = %u", corpID)) {
1728  codelog(CORP__DB_ERROR, "Error in query: %s", res.error.c_str());
1729  return "Unknown";
1730  }
1731 
1732  DBResultRow row;
1733  if (!res.GetRow(row)) {
1734  _log(CORP__DB_WARNING, "Corporation %u - Corp name not found.", corpID);
1735  return "Unknown";
1736  }
1737 
1738  return row.GetText(0);
1739 }
1740 
1741 std::string CorporationDB::GetDivisionName(uint32 corpID, uint16 acctKey)
1742 {
1743  std::string acctKeyName = "";
1744  switch (acctKey) {
1745  case Account::KeyType::Cash: acctKeyName = "division1"; break;
1746  case Account::KeyType::Cash2: acctKeyName = "division2"; break;
1747  case Account::KeyType::Cash3: acctKeyName = "division3"; break;
1748  case Account::KeyType::Cash4: acctKeyName = "division4"; break;
1749  case Account::KeyType::Cash5: acctKeyName = "division5"; break;
1750  case Account::KeyType::Cash6: acctKeyName = "division6"; break;
1751  case Account::KeyType::Cash7: acctKeyName = "division7"; break;
1752  }
1753 
1754  DBQueryResult res;
1755  if (!sDatabase.RunQuery(res, "SELECT %s FROM crpWalletDivisons WHERE corporationID = %u", acctKeyName.c_str(), corpID)) {
1756  codelog(CORP__DB_ERROR, "Error in query: %s", res.error.c_str());
1757  return "Unknown";
1758  }
1759 
1760  DBResultRow row;
1761  if (!res.GetRow(row)) {
1762  _log(CORP__DB_WARNING, "Corporation %u - division name for acctKey %u not found.", corpID, acctKey);
1763  return "Unknown";
1764  }
1765 
1766  return row.GetText(0);
1767 }
1768 
1769 
1770 bool CorporationDB::UpdateCorporation(uint32 corpID, const Call_UpdateCorporation & upd, PyDict * notif) {
1771  DBQueryResult res;
1772 
1773  if (!sDatabase.RunQuery(res,
1774  " SELECT description, url, taxRate "
1775  " FROM crpCorporation "
1776  " WHERE corporationID = %u ", corpID))
1777  {
1778  codelog(CORP__DB_ERROR, "Error in query: %s", res.error.c_str());
1779  return false;
1780  }
1781 
1782  DBResultRow row;
1783  if (!res.GetRow(row)) {
1784  codelog(CORP__DB_WARNING, "Corporation %u doesn't exists.", corpID);
1785  return false;
1786  }
1787 
1788  std::vector<std::string> dbQ;
1789  ProcessStringChange("description", row.GetText(0), upd.description, notif, dbQ);
1790  ProcessStringChange("url", row.GetText(1), upd.address, notif, dbQ);
1791  ProcessRealChange("taxRate", row.GetDouble(2), upd.tax, notif, dbQ);
1792 
1793  std::string query = " UPDATE crpCorporation SET ";
1794 
1795  int N = dbQ.size();
1796  for (int i = 0; i < N; i++) {
1797  query += dbQ[i];
1798  if (i < N - 1) query += ", ";
1799  }
1800 
1801  query += " WHERE corporationID = %u";
1802 
1803  // only update if there is anything to update
1804  if ((N > 0) && (!sDatabase.RunQuery(res.error, query.c_str(), corpID))) {
1805  codelog(CORP__DB_ERROR, "Error in query: %s", res.error.c_str());
1806  return false;
1807  }
1808 
1809  return true;
1810 }
1811 
1812 #define NI(i) row.IsNull(i) ? 0 : row.GetInt(i)
1813 bool CorporationDB::UpdateLogo(uint32 corpID, const Call_UpdateLogo & upd, PyDict * notif) {
1814  DBQueryResult res;
1815 
1817  if (!sDatabase.RunQuery(res,
1818  " SELECT shape1, shape2, shape3, color1, color2, color3, typeface "
1819  " FROM crpCorporation "
1820  " WHERE corporationID = %u ", corpID))
1821  {
1822  codelog(CORP__DB_ERROR, "Error in query: %s", res.error.c_str());
1823  return false;
1824  }
1825 
1826  DBResultRow row;
1827  if (!res.GetRow(row)) {
1828  codelog(CORP__DB_WARNING, "Corporation %u doesn't exists.", corpID);
1829  return false;
1830  }
1831 
1832  std::vector<std::string> dbQ;
1833  ProcessIntChange("shape1", NI(0), upd.shape1, notif, dbQ);
1834  ProcessIntChange("shape2", NI(1), upd.shape2, notif, dbQ);
1835  ProcessIntChange("shape3", NI(2), upd.shape3, notif, dbQ);
1836 
1837  ProcessIntChange("color1", NI(3), upd.color1, notif, dbQ);
1838  ProcessIntChange("color2", NI(4), upd.color2, notif, dbQ);
1839  ProcessIntChange("color3", NI(5), upd.color3, notif, dbQ);
1840 
1841  std::string query = " UPDATE crpCorporation SET ";
1842 
1843  int N = dbQ.size();
1844  for (int i = 0; i < N; i++) {
1845  query += dbQ[i];
1846  if (i < N - 1) query += ", ";
1847  }
1848 
1849  query += " WHERE corporationID = %u ";
1850  if ((N > 0) && (!sDatabase.RunQuery(res.error, query.c_str(), corpID))) {
1851  codelog(CORP__DB_ERROR, "Error in query: %s", res.error.c_str());
1852  return false;
1853  }
1854 
1855  return true;
1856 }
1857 #undef NI
1858 
1860 {
1861  // lastOnline(hours) needs update based on char logoffDateTime using GetElapsedHours();
1862  // no idea how to do that short of pulling/updating column every (x time) interval....and uh, no.
1863  DBQueryResult res;
1864  if (!sDatabase.RunQuery(res,
1865  "SELECT c.characterID, c.corporationID, c.title, c.startDateTime, c.corpRole AS roles, c.baseID, c.grantableRoles, c.blockRoles,"
1866  " c.logonDateTime, c.logoffDateTime, c.locationID, IFNULL(e.typeID, 0) AS shipTypeID, -1 AS lastOnline"
1867  " FROM chrCharacters AS c"
1868  " LEFT JOIN entity AS e ON e.itemID = c.shipID"
1869  " WHERE c.corporationID = %u", corpID))
1870  {
1871  codelog(CORP__DB_ERROR, "Error in query: %s", res.error.c_str());
1872  return nullptr;
1873  }
1874  return DBResultToCRowset(res);
1875 }
1876 
1878 {
1879  DBQueryResult res;
1880  if (!sDatabase.RunQuery(res,
1881  "SELECT c.characterID, c.corporationID, c.logoffDateTime, c.logonDateTime, c.title, c.startDateTime, c.corpRole AS roles,"
1882  " c.baseID, c.blockRoles, IFNULL(e.typeID, 0) AS shipTypeID"
1883  " FROM chrCharacters AS c"
1884  " LEFT JOIN entity AS e ON e.itemID = c.shipID"
1885  " WHERE corporationID = %u", corpID))
1886  {
1887  codelog(CORP__DB_ERROR, "Error in query: %s", res.error.c_str());
1888  return nullptr;
1889  }
1890  return DBResultToCRowset(res);
1891 }
1892 
1894 {
1895  sDatabase.RunQuery(res, "SELECT market, rental, broker, war, alliance, sov FROM crpAutoPay WHERE corporationID = %u", corpID);
1896 }
1897 
1899 {
1900  //UPDATE crpAutoPay SET corporationID=[value-1],market=[value-2],rental=[value-3],broker=[value-4],war=[value-5],alliance=[value-6],sov=[value-7] WHERE 1
1901 }
1902 
1903 void CorporationDB::AddItemEvent(uint32 corpID, uint32 charID, uint16 eTypeID)
1904 {
1905  DBerror err;
1906  sDatabase.RunQuery(err,
1907  "INSERT INTO crpItemEvent (corporationID, characterID, eventTypeID, eventDateTime)"
1908  " VALUES (%u, %u, %u, %f)", corpID, charID, eTypeID, GetFileTimeNow());
1909 }
1910 
1911 PyRep* CorporationDB::GetItemEvents(uint32 corpID, uint32 charID, int64 fromDate, int64 toDate, uint8 rowsPerPage)
1912 {
1913  DBQueryResult res;
1914  if (!sDatabase.RunQuery(res,
1915  " SELECT eventID, corporationID, characterID, eventTypeID, eventDateTime"
1916  " FROM crpItemEvent"
1917  " WHERE corporationID = %u AND characterID = %u AND eventDateTime > %li AND eventDateTime <= %li "
1918  " LIMIT %u", corpID, charID, fromDate, toDate, rowsPerPage))
1919  {
1920  codelog(CORP__DB_ERROR, "Error in query: %s", res.error.c_str());
1921  return nullptr;
1922  }
1923 
1924  return DBResultToCRowset(res);
1925 /*
1926  PyList* list = new PyList();
1927  if (res.GetRowCount() > 0) {
1928  DBResultRow row;
1929  while (res.GetRow(row)) {
1930  PyDict* dict = new PyDict();
1931  dict->SetItemString("eventID", new PyInt(row.GetInt(0)));
1932  dict->SetItemString("corporationID", new PyInt(row.GetInt(1)));
1933  dict->SetItemString("characterID", new PyInt(row.GetInt(2)));
1934  dict->SetItemString("eventTypeID", new PyInt(row.GetInt(3)));
1935  dict->SetItemString("eventDateTime", new PyLong(row.GetInt64(4)));
1936  list->AddItem(dict);
1937  }
1938  } else {
1939  PyDict* dict = new PyDict();
1940  dict->SetItemString("eventID", new PyInt(0));
1941  dict->SetItemString("corporationID", new PyInt(0));
1942  dict->SetItemString("characterID", new PyInt(0));
1943  dict->SetItemString("eventTypeID", new PyInt(0));
1944  dict->SetItemString("eventDateTime", new PyInt(0));
1945  list->AddItem(dict);
1946  }
1947 
1948  return new PyObject("util.KeyVal", list);
1949  */
1950 }
1951 
1952 void CorporationDB::AddRoleHistory(uint32 corpID, uint32 charID, uint32 issuerID, int64 oldRoles, int64 newRoles, bool grantable)
1953 {
1954  DBerror err;
1955  sDatabase.RunQuery(err,
1956  "INSERT INTO crpRoleHistroy (corporationID, characterID, issuerID, changeTime, oldRoles, newRoles, grantable)"
1957  " VALUES (%u, %u, %u, %f, %li, %li, %i)", corpID, charID, issuerID, GetFileTimeNow(), oldRoles, newRoles, (grantable ? 1 : 0));
1958 }
1959 
1960 PyRep* CorporationDB::GetRoleHistroy(uint32 corpID, uint32 charID, int64 fromDate, int64 toDate, uint8 rowsPerPage)
1961 {
1962  DBQueryResult res;
1963  if (!sDatabase.RunQuery(res,
1964  " SELECT corporationID, characterID, issuerID, changeTime, oldRoles, newRoles, grantable"
1965  " FROM crpRoleHistroy"
1966  " WHERE corporationID = %u and characterID = %u AND changeTime > %li AND changeTime <= %li "
1967  " LIMIT %u", corpID, charID, fromDate, toDate, rowsPerPage))
1968  {
1969  codelog(CORP__DB_ERROR, "Error in query: %s", res.error.c_str());
1970  return nullptr;
1971  }
1972 
1973  return DBResultToCRowset(res);
1974 /*
1975  PyList* list = new PyList();
1976  if (res.GetRowCount() > 0) {
1977  DBResultRow row;
1978  while (res.GetRow(row)) {
1979  PyDict* dict = new PyDict();
1980  dict->SetItemString("corporationID", new PyInt(row.GetInt(0)));
1981  dict->SetItemString("charID", new PyInt(row.GetInt(1)));
1982  dict->SetItemString("issuerID", new PyInt(row.GetInt(2)));
1983  dict->SetItemString("changeTime", new PyLong(row.GetInt64(3)));
1984  dict->SetItemString("oldRoles", new PyLong(row.GetInt64(4)));
1985  dict->SetItemString("newRoles", new PyLong(row.GetInt64(5)));
1986  dict->SetItemString("grantable", new PyBool(row.GetBool(6)));
1987  list->AddItem(dict);
1988  }
1989  } else {
1990  PyDict* dict = new PyDict();
1991  dict->SetItemString("corporationID", new PyInt(0));
1992  dict->SetItemString("charID", new PyInt(0));
1993  dict->SetItemString("issuerID", new PyInt(0));
1994  dict->SetItemString("changeTime", new PyInt(0));
1995  dict->SetItemString("oldRoles", new PyInt(0));
1996  dict->SetItemString("newRoles", new PyInt(0));
1997  dict->SetItemString("grantable", new PyBool(false));
1998  list->AddItem(dict);
1999  }
2000 
2001  return new PyObject("util.KeyVal", list);
2002  */
2003 }
2004 
2005 void CorporationDB::AddVoteCase(uint32 corpID, uint32 charID, Call_InsertVoteCase& args)
2006 { // working
2007  PyDict* dict = args.voteCaseOptions->arguments()->AsDict();
2008  dict->Dump(CORP__TRACE, " ");
2009 
2010  PyRep* rep = dict->GetItemString("lines");
2011  if (!rep->IsList()) {
2012  codelog(CORP__ERROR, "'lines' item is not PyList: %s", rep->TypeString());
2013  return;
2014  }
2015 
2016  std::vector<Corp::VoteCaseOptions> data;
2017  PyList* list = rep->AsList();
2018  for (PyList::const_iterator itr = list->begin(); itr != list->end(); ++itr) {
2019  if (!(*itr)->IsList()) {
2020  _log(CORP__ERROR, "itr item is not PyList: %s", rep->TypeString());
2021  continue;
2022  }
2023  PyList* list2 = (*itr)->AsList();
2025  //vote decision option
2026  args2.optionText = PyRep::StringContent(list2->GetItem(0));
2027  args2.optionID = PyRep::IntegerValue(list2->GetItem(1));
2028  //for kick, ceo this is charID. for war, this is corpID. for lock/unlock, this is itemID for shares/general, this is boolean
2029  args2.parameter = PyRep::IntegerValue(list2->GetItem(1));
2030  switch (args.voteType) {
2032  case Corp::VoteType::General: {
2033  // nothing
2034  } break;
2035  case Corp::VoteType::CEO:
2036  case Corp::VoteType::War:
2038  // nothing
2039  } break;
2042  //for lock/unlock, this is items typeID. for shares/general, this is 0
2043  args2.parameter1 = PyRep::IntegerValue(list2->GetItem(2));
2044  //for lock/unlock, this is items locationID. for others, this is none
2045  args2.parameter2 = PyRep::IntegerValue(list2->GetItem(3));
2046  } break;
2047  }
2048  data.push_back(args2);
2049  }
2050 
2051  uint32 voteCaseID = 0;
2052  DBerror err;
2053  sDatabase.RunQueryLID(err, voteCaseID,
2054  " INSERT INTO crpVoteItems( "
2055  " corporationID, voteType, voteCaseText, description, startDateTime, endDateTime)"
2056  " VALUES (%u, %u, '%s', '%s', %li, %li)",
2057  args.corporationID, args.voteType, args.voteCaseText.c_str(), args.description.c_str(), args.startDateTime, args.endDateTime);
2058 
2059  std::stringstream str;
2060  str << "INSERT INTO crpVoteOptions (voteCaseID, optionID, optionText, parameter, parameter1, parameter2) VALUES ";
2061 
2062  bool set = false;
2063  for (auto cur : data) {
2064  if (!set) {
2065  set = true;
2066  } else {
2067  str << ",";
2068  }
2069  str << "(" << std::to_string((int64)voteCaseID) << "," << std::to_string(cur.optionID) << ",\"" << cur.optionText << "\"," << std::to_string(cur.parameter) << ",";
2070  str << std::to_string(cur.parameter1) << "," << std::to_string(cur.parameter2) << ")";
2071  }
2072 
2073  if (set)
2074  sDatabase.RunQuery(err, str.str().c_str());
2075 }
2076 
2077 PyRep* CorporationDB::GetVoteItems(uint32 corpID, uint8 status/*0*/, uint8 maxLen/*20*/)
2078 { // working
2079  if (maxLen == 0)
2080  maxLen = 20;
2081  std::string statusTxt = "";
2082  if (status != 0) {
2083  statusTxt = "AND status = ";
2084  statusTxt += std::to_string(status);
2085  }
2086 
2087  DBQueryResult res;
2088  if (!sDatabase.RunQuery(res,
2089  " SELECT voteCaseID, voteType, voteCaseText, description, inEffect, status, actedUpon, timeActedUpon,"
2090  " rescended, timeRescended, startDateTime, endDateTime"
2091  " FROM crpVoteItems"
2092  " WHERE corporationID = %u "
2093  " %s"
2094  " LIMIT 0,%u", corpID, statusTxt.c_str(), maxLen))
2095  {
2096  codelog(CORP__DB_ERROR, "Error in query: %s", res.error.c_str());
2097  return nullptr;
2098  }
2099  return DBResultToPackedRowDict(res, "voteCaseID");
2100 }
2101 
2102 // this shit changes based on type of vote....optionID for xxx, parameter for xxx
2104 { // working
2105  DBQueryResult res;
2106  if (!sDatabase.RunQuery(res,
2107  "SELECT voteCaseID, optionID, optionText, parameter, parameter1, parameter2, votesFor"
2108  " FROM crpVoteOptions WHERE voteCaseID = %u", voteCaseID))
2109  {
2110  codelog(CORP__DB_ERROR, "Error in query: %s", res.error.c_str());
2111  return nullptr;
2112  }
2113 
2114  return DBResultToIndexRowset(res, "optionID");
2115 }
2116 
2118 { // working
2119  // status - 0:default, 1: open, 2: closed
2120  DBQueryResult res;
2121  if (!sDatabase.RunQuery(res,
2122  " SELECT voteCaseID, voteType, inEffect, actedUpon, timeActedUpon, timeRescended, endDateTime AS expires"
2123  " FROM crpVoteItems"
2124  " WHERE corporationID = %u ", corpID))
2125  {
2126  codelog(CORP__DB_ERROR, "Error in query: %s", res.error.c_str());
2127  return nullptr;
2128  }
2129 
2130  //return DBResultToPackedRowDict(res, "voteCaseID");
2131  //return DBResultToCIndexedRowset(res, "voteCaseID");
2132  //return DBResultToIndexRowset(res, "voteCaseID");
2133  return DBResultToCRowset(res);
2134 }
2135 
2137 { // working
2138  DBQueryResult res;
2139  if (!sDatabase.RunQuery(res,
2140  "SELECT charID, voteCaseID, optionID FROM crpVotes"
2141  " WHERE voteCaseID = %u", voteCaseID))
2142  {
2143  codelog(CORP__DB_ERROR, "Error in query: %s", res.error.c_str());
2144  return nullptr;
2145  }
2146 
2147  return DBResultToCIndexedRowset(res, "charID");
2148 }
2149 
2150 void CorporationDB::CastVote(uint32 corpID, uint32 charID, uint32 voteCaseID, uint8 optionID)
2151 { // working
2152  DBerror err;
2153  sDatabase.RunQuery(err, "UPDATE crpVoteItems SET votesMade=votesMade + 1 WHERE voteCaseID = %u", voteCaseID);
2154  sDatabase.RunQuery(err, "UPDATE crpVoteOptions SET votesFor=votesFor + 1 WHERE voteCaseID = %u AND optionID = %u", voteCaseID, optionID);
2155  sDatabase.RunQuery(err,
2156  "INSERT INTO crpVotes (charID,corpID,voteCaseID,optionID)"
2157  " VALUES (%u,%u,%u,%u)", charID, corpID, voteCaseID, optionID);
2158 }
2159 
2160 
2161 void CorporationDB::MoveShares(uint32 ownerID, uint32 corpID, Call_MoveShares& args)
2162 { // working
2163  //MoveShares(corporationID, toShareholderID, numberOfShares)
2164  // this will also send share update notifications as its' easier to do here..
2165 
2166  // get old owner data
2167  bool isCorp = false;
2168  if (IsPlayerCorp(ownerID))
2169  isCorp = true;
2170  DBQueryResult res;
2171  sDatabase.RunQuery(res,"SELECT shares FROM crpShares WHERE corporationID = %u AND shareholderID = %u ", corpID, ownerID);
2172  DBResultRow row;
2173  if (res.GetRow(row)) {
2174  // add to notification
2176  OnCorpShareChange corpUpdate;
2177  corpUpdate.corpID = corpID;
2178  corpUpdate.ownerID = ownerID;
2179  corpUpdate.oldShares = row.GetInt(0);
2180  corpUpdate.newShares = row.GetInt(0) - args.numberOfShares;
2181  MulticastTarget mct;
2182  if (isCorp) {
2183  mct.corporations.insert(corpID);
2184  } else {
2185  mct.characters.insert(ownerID);
2186  }
2187  PyTuple* tuple = corpUpdate.Encode();
2188  sEntityList.Multicast("OnShareChange", "*corpid&corprole", &tuple, mct);
2189  }
2190 
2191  DBerror err;
2192  // remove from old owner
2193  sDatabase.RunQuery(err,
2194  "UPDATE crpShares SET shares = shares - %i"
2195  " WHERE corporationID = %u AND shareholderID = %u ", args.numberOfShares, args.corporationID, ownerID);
2196 
2197  // get new owner data
2198  uint16 oldShares = 0;
2199  uint32 oldCorpID = 0;
2200  Client* pClient(nullptr);
2201  if (IsCharacterID(args.toShareholderID)) {
2202  pClient = sEntityList.FindClientByCharID(args.toShareholderID);
2203  if (pClient == nullptr) {
2204  oldCorpID = CharacterDB::GetCorpID(args.toShareholderID);
2205  } else {
2206  oldCorpID = pClient->GetCorporationID();
2207  }
2208  }
2209  OnCharShareChange charUpdate;
2210  charUpdate.ownerID = args.toShareholderID;
2211  charUpdate.corpID = corpID;
2212  charUpdate.newShares = args.numberOfShares; // plus existing shares this owner has of this corp
2213  //res.Reset();
2214  sDatabase.RunQuery(res,"SELECT shares, shareholderCorporationID FROM crpShares WHERE corporationID = %u AND shareholderID = %u ", corpID, args.toShareholderID);
2215  // this isnt completely right. also throws error
2216  // AttributeError: 'dict' object has no attribute 'header'
2217  if (res.GetRow(row)) {
2218  charUpdate.oldShares = (oldShares = row.GetInt(0));
2219  charUpdate.oldCorpID = row.GetInt(1);
2220  charUpdate.oldOwnerID = args.toShareholderID;
2221  charUpdate.newOwnerOldCorpID = (isCorp ? 0 : oldCorpID);
2222  } else {
2223  charUpdate.oldShares = 0;
2224  charUpdate.oldCorpID = 0;
2225  charUpdate.oldOwnerID = 0;
2226  charUpdate.newOwnerOldCorpID = 0;
2227  }
2228 
2229  charUpdate.newShares = (oldShares + args.numberOfShares);
2230  charUpdate.newCorpID = corpID;
2231  charUpdate.newOwnerID = args.toShareholderID;
2232  charUpdate.newOwnerNewCorpID = (isCorp ? 0 : oldCorpID);
2234  pClient->SendNotification("OnShareChange", "charid", charUpdate.Encode());
2235 
2236  // add to new owner
2237  sDatabase.RunQuery(err,
2238  "INSERT INTO crpShares (corporationID, shareholderID, shares, shareholderCorporationID)"
2239  " VALUES (%i, %i, %i, %u)"
2240  " ON DUPLICATE KEY UPDATE shares = shares + %i", args.corporationID, args.toShareholderID, args.numberOfShares, corpID, args.numberOfShares);
2241 }
2242 
2244 {
2245  DBQueryResult res;
2246  if (!sDatabase.RunQuery(res,
2247  " SELECT corporationID, shareholderID, shares, shareholderCorporationID"
2248  " FROM crpShares"
2249  " WHERE corporationID = %u ", corpID))
2250  {
2251  codelog(CORP__DB_ERROR, "Error in query: %s", res.error.c_str());
2252  return nullptr;
2253  }
2254  return DBResultToIndexRowset(res, "shareholderID");
2255 }
2256 
2258 {
2259  DBQueryResult res;
2260  if (!sDatabase.RunQuery(res,
2261  " SELECT corporationID, shareholderID, shares, shareholderCorporationID"
2262  " FROM crpShares"
2263  " WHERE shareholderID = %u ", ownerID))
2264  {
2265  codelog(CORP__DB_ERROR, "Error in query: %s", res.error.c_str());
2266  return nullptr;
2267  }
2268  return DBResultToRowset(res);
2269 }
2270 
2272 {
2273  DBQueryResult res;
2274  if (!sDatabase.RunQuery(res, "SELECT shareholderID FROM crpShares WHERE corporationID = %u AND shareholderID < 98000000", corpID)) {
2275  codelog(CORP__DB_ERROR, "Error in query: %s", res.error.c_str());
2276  return nullptr;
2277  }
2278 
2279  DBResultRow row;
2280  PyList* list = new PyList();
2281  while (res.GetRow(row))
2282  list->AddItem(new PyInt(row.GetInt(1)));
2283 
2284  return list;
2285 }
2286 
2288 {
2289  DBQueryResult res;
2290  if (!sDatabase.RunQuery(res, "SELECT shares FROM crpShares WHERE shareholderID = %u AND corporationID = %u", charID, corpID)) {
2291  codelog(CORP__DB_ERROR, "Error in query: %s", res.error.c_str());
2292  return false;
2293  }
2294 
2295  if (res.GetRowCount())
2296  return true;
2297 
2298  return false;
2299 }
2300 
2302 {
2303  DBQueryResult res;
2304  if (!sDatabase.RunQuery(res, "SELECT shares FROM crpShares WHERE shareholderID = %u AND corporationID = %u", charID, corpID)) {
2305  codelog(CORP__DB_ERROR, "Error in query: %s", res.error.c_str());
2306  return PyStatic.NewFalse();
2307  }
2308 
2309  if (res.GetRowCount())
2310  return PyStatic.NewTrue();
2311 
2312  return PyStatic.NewFalse();
2313 }
2314 
2315 PyRep* CorporationDB::GetAssetInventory(uint32 corpID, EVEItemFlags locFlag, const char* flags)
2316 {
2317  /* this may need more code/thought to change implementation
2318  * currently, "property" will show all corp items located in dynamic containers that are or have corp hangars
2319  * this will include items located in station hangars that have corp hangars, or anything with flagHangar(4) located in an item of itemID => playerItem
2320  * at this time, im not sure if this is desired action
2321  *
2322  * this will need to return unique locationIDs for all corp items (dupes cause problems)
2323  */
2325  DBQueryResult res;
2326  switch (locFlag) {
2327  case flagOffice: // in stations, using officeIDs (100m)
2328  case flagImpounded:
2329  case flagCorpMarket: {
2330  if (!sDatabase.RunQuery(res,
2331  " SELECT DISTINCT s.stationID AS locationID FROM entity AS e"
2332  " LEFT JOIN staOffices AS s ON (s.itemID = e.locationID)"
2333  " WHERE e.ownerID = %u AND e.flag IN %s"
2334  " AND e.locationID >= %u AND e.locationID <= %u", corpID, flags, minOffice, maxOffice))
2335  {
2336  codelog(CORP__DB_ERROR, "Error in query: %s", res.error.c_str());
2337  return (PyRep*)PyStatic.NewNone(); // cannot return nullptr cause we may deref it on the return.
2338  }
2339  } break;
2340  case flagProperty: { // in space...this will show items in containers, ships, POS, CO, etc.
2341  if (!sDatabase.RunQuery(res,
2342  " SELECT DISTINCT locationID FROM entity WHERE ownerID = %u AND flag IN %s"
2343  " AND locationID >= %u AND locationID <= %u", corpID, flags, minPlayerItem, maxPlayerItem))
2344  {
2345  codelog(CORP__DB_ERROR, "Error in query: %s", res.error.c_str());
2346  return (PyRep*)PyStatic.NewNone(); // cannot return nullptr cause we may deref it on the return.
2347  }
2348 
2349  // current thought is this option will need more work, to avoid showing corp hangars in ships in stations
2350  // or do we want to show all possible locations that are NOT corp offices?
2351  } break;
2352  default: {
2353  _log(CORP__DB_WARNING, "CorporationDB::GetAssetInventory(): unhandled locFlag sent: %u", locFlag);
2354  return (PyRep*)PyStatic.NewNone(); // cannot return nullptr cause we may deref it on the return.
2355  } break;
2356  }
2357 
2358  return DBResultToCRowset(res);
2359 }
2360 
2361 PyRep* CorporationDB::GetAssetInventoryForLocation(uint32 corpID, uint32 locationID, const char* flags)
2362 {
2363  // this will need to get full item data...locationID sent from GetAssetInventory()
2364  DBQueryResult res;
2365  if (sDataMgr.IsStation(locationID)) { // transpose stationID to officeID for item location...should never hit
2366  if (!sDatabase.RunQuery(res,
2367  " SELECT e.itemID, e.itemName, e.typeID, e.ownerID, e.locationID, e.flag AS flagID, e.singleton,"
2368  " e.quantity AS stacksize, t.groupID, g.categoryID FROM entity AS e"
2369  " LEFT JOIN invTypes AS t USING (typeID)"
2370  " LEFT JOIN invGroups AS g USING (groupID)"
2371  " WHERE e.ownerID = %u AND e.flag IN %s AND e.locationID = (SELECT itemID FROM staOffices WHERE stationID = %u AND corporationID = %u)",
2372  corpID, flags, locationID, corpID)) // quantity, contraband, x, y, z, customInfo
2373  {
2374  codelog(CORP__DB_ERROR, "Error in query: %s", res.error.c_str());
2375  return nullptr;
2376  }
2377  } else if (IsOfficeID(locationID)) { // transpose officeID to stationID for item location...most oft used (corp hangars in station)
2378  if (!sDatabase.RunQuery(res,
2379  " SELECT e.itemID, e.itemName, e.typeID, e.ownerID, e.locationID, e.flag AS flagID, e.singleton,"
2380  " e.quantity AS stacksize, t.groupID, g.categoryID FROM entity AS e"
2381  " LEFT JOIN invTypes AS t USING (typeID)"
2382  " LEFT JOIN invGroups AS g USING (groupID)"
2383  " WHERE e.ownerID = %u AND e.flag IN %s AND e.locationID = (SELECT stationID FROM staOffices WHERE itemID = %u)",
2384  corpID, flags, locationID))
2385  {
2386  codelog(CORP__DB_ERROR, "Error in query: %s", res.error.c_str());
2387  return nullptr;
2388  }
2389  } else if (IsPlayerItem(locationID)) { // location is item with corp hangar (ship, pos, etc)
2390  if (!sDatabase.RunQuery(res,
2391  " SELECT e.itemID, e.itemName, e.typeID, e.ownerID, e.locationID, e.flag AS flagID, e.singleton,"
2392  " e.quantity AS stacksize, t.groupID, g.categoryID FROM entity AS e"
2393  " LEFT JOIN invTypes AS t USING (typeID)"
2394  " LEFT JOIN invGroups AS g USING (groupID)"
2395  " WHERE e.ownerID = %u AND e.flag IN %s AND e.locationID = %u", corpID, flags, locationID))
2396  {
2397  codelog(CORP__DB_ERROR, "Error in query: %s", res.error.c_str());
2398  return nullptr;
2399  }
2400  } else {
2401  _log(CORP__DB_WARNING, "CorporationDB::GetAssetInventoryForLocation(): unhandled locationID sent: %u", locationID);
2402  return nullptr;
2403  }
2404 
2405  return DBResultToCRowset(res);
2406 }
2407 
2409 {
2410  DBQueryResult res;
2411  if (!sDatabase.RunQuery(res,
2412  "SELECT"
2413  " killID,"
2414  " solarSystemID,"
2415  " victimCharacterID,"
2416  " victimCorporationID,"
2417  " victimAllianceID,"
2418  " victimFactionID,"
2419  " victimShipTypeID,"
2420  " finalCharacterID,"
2421  " finalCorporationID,"
2422  " finalAllianceID,"
2423  " finalFactionID,"
2424  " finalShipTypeID,"
2425  " finalWeaponTypeID,"
2426  " killBlob,"
2427  " killTime,"
2428  " victimDamageTaken,"
2429  " finalSecurityStatus,"
2430  " finalDamageDone,"
2431  " moonID"
2432  " FROM chrKillTable"
2433  " WHERE victimCorporationID = %u OR finalCorporationID = %u", corpID, corpID))
2434  {
2435  codelog(CORP__DB_ERROR, "Error on query: %s", res.error.c_str());
2436  return nullptr;
2437  }
2438 
2439  _log(DATABASE__RESULTS, "CorporationDB::GetKillsAndLosses for corpID: %u returned %u items", corpID, res.GetRowCount());
2440 
2441  return DBResultToCRowset(res);
2442 }
2443 
2445 {
2446  // bid = buy order
2447  DBQueryResult res;
2448  if (!sDatabase.RunQuery(res,
2449  "SELECT sell.typeID AS typeID, sell.price AS sellPrice, sell.volRemaining AS sellQuantity, sell.issued AS sellDate, sell.stationID AS sellStationID, "
2450  " buy.price AS buyPrice, buy.volRemaining AS buyQuantity, buy.issued AS buyDate, buy.stationID AS buyStationID"
2451  " FROM mktOrders AS sell, mktOrders AS buy"
2452  " WHERE sell.ownerID = %u AND buy.ownerID = %u AND sell.typeID = buy.typeID AND sell.bid=0 AND buy.bid=1", corpID, corpID)) // bid=buy order
2453  {
2454  codelog(CORP__DB_ERROR, "Error on query: %s", res.error.c_str());
2455  }
2456 
2457  _log(DATABASE__RESULTS, "CorporationDB::GetMktBuyInfo for corpID: %u returned %u items", corpID, res.GetRowCount());
2458 
2459  return DBResultToCRowset(res);
2460 }
2461 
2463 {
2464  DBQueryResult res;
2465  if (!sDatabase.RunQuery(res,
2466  "SELECT"
2467  " taxRate,"
2468  " stationID,"
2469  " allianceID,"
2470  " warFactionID,"
2471  " corporationName,"
2472  " tickerName"
2473  " FROM crpCorporation"
2474  " WHERE corporationID = %u", data.corporationID))
2475  {
2476  codelog(DATABASE__ERROR, "Failed to query data of corporation %u: %s.", data.corporationID, res.error.c_str());
2477  return;
2478  }
2479 
2480  DBResultRow row;
2481  if (!res.GetRow(row)) {
2482  _log(DATABASE__MESSAGE, "No data found for character's %u corporation.", data.corporationID);
2483  return;
2484  }
2485 
2486  data.taxRate = row.GetDouble(0);
2487  data.corpHQ = (row.IsNull(1) ? 0 : row.GetUInt(1));
2488  data.allianceID = (row.IsNull(2) ? 0 : row.GetUInt(2));
2489  data.warFactionID = (row.IsNull(3) ? 0 : row.GetUInt(3));
2490  data.name = row.GetText(4);
2491  data.ticker = row.GetText(5);
2493 }
2494 
2496 {
2497  DBerror err;
2498  if (!sDatabase.RunQuery(err, "UPDATE crpCorporation SET stationID = %u WHERE corporationID = %u", stationID, corpID))
2499  codelog(CORP__DB_ERROR, "Error in UpdateCorpHQ query: %s", err.c_str());
2500 }
2501 
2502 void CorporationDB::EditLabel(uint32 corpID, uint32 labelID, uint32 color, std::string name)
2503 {
2504  std::string escaped;
2505  sDatabase.DoEscapeString(escaped, name);
2506 
2507  DBQueryResult res;
2508  sDatabase.RunQuery(res, "UPDATE crpLabels SET color = %u, name = '%s' WHERE ownerID = %u AND labelID = %u", color, escaped.c_str(), corpID, labelID);
2509 }
2510 
2512 {
2513  DBQueryResult res;
2514  if (!sDatabase.RunQuery(res, "SELECT labelID, color, name FROM crpLabels WHERE ownerID = %u", corpID)) {
2515  codelog(DATABASE__ERROR, "Error on query: %s", res.error.c_str());
2516  return nullptr;
2517  }
2518 
2519  return DBResultToCIndexedRowset(res, "labelID");
2520 }
2521 
2522 void CorporationDB::SetLabel(uint32 corpID, uint32 color, std::string name)
2523 {
2524  std::string escaped;
2525  sDatabase.DoEscapeString(escaped, name);
2526 
2527  DBQueryResult res;
2528  sDatabase.RunQuery(res, "INSERT INTO crpLabels (color, name, ownerID) VALUES (%u, '%s', %u)", color, escaped.c_str(), corpID);
2529 }
2530 
2532 {
2533  // not used yet
2534 }
2535 
2537 {
2538  DBQueryResult res;
2539  if (!sDatabase.RunQuery(res, "SELECT corporationID FROM chrCharacters WHERE characterID = %u", charID)) {
2540  codelog(DATABASE__ERROR, "Failed to query data of corporation for chararcterID %u: %s.", charID, res.error.c_str());
2541  return 0;
2542  }
2543 
2544  DBResultRow row;
2545  if (res.GetRow(row))
2546  return row.GetInt(0);
2547 
2548  _log(DATABASE__MESSAGE, "No data found for character's %u corporation.", charID);
2549  return 0;
2550 }
PyRep * Fetch(uint32 corpID, uint32 from, uint32 count)
Base Python wire object.
Definition: PyRep.h:66
uint32 GetStationOwner(uint32 stationID)
unsigned __int8 uint8
Definition: eve-compat.h:46
PyObjectEx * GetMedalDetails(int32 medalID)
#define IsNPCCorp(itemID)
Definition: EVE_Defines.h:238
PyRep * GetCorporations(uint32 corpID)
void AddContact(uint32 ownerID, Call_CorporateContactData corpData)
void SendNotification(const PyAddress &dest, EVENotificationStream &noti, bool seq=true)
Definition: Client.cpp:2245
bool UpdateLogo(uint32 corpID, const Call_UpdateLogo &upd, PyDict *notif)
static std::string StringContent(PyRep *pRep)
Definition: PyRep.cpp:103
bool UpdateCorporation(uint32 corpID, const Call_UpdateCorporation &upd, PyDict *notif)
#define sDatabase
Definition: dbcore.h:199
PyRep * GetCorpInfo(uint32 corpID)
std::set< uint32 > corporations
Definition: EntityList.h:60
void ProcessRealChange(const char *key, double oldValue, double newValue, PyDict *notif, std::vector< std::string > &dbQ)
Definition: ServiceDB.cpp:287
PyRep * GetMemberTrackingInfo(uint32 corpID)
const char * GetText(uint32 index) const
Definition: dbcore.h:104
#define _log(type, fmt,...)
Definition: logsys.h:124
void AddRecruiters(uint16 adID, int32 corpID, std::vector< int32 > &charVec)
PyObjectEx * DBResultToCRowset(DBQueryResult &result)
Definition: EVEDBUtils.cpp:402
PyObject * ListStationOwners(uint32 station_id)
Python string.
Definition: PyRep.h:430
uint16 GetMemberCount(uint32 corpID)
PyRep * GetCorpRoleGroups()
PyRep * GetItemString(const char *key) const
Obtains database entry based on given key string.
Definition: PyRep.cpp:702
uint32 corpHQ
int32 GetInt(uint32 index) const
Definition: dbcore.cpp:635
grantableRolesAtOther
PyRep * GetShares(uint32 corpID)
void ProcessIntChange(const char *key, uint32 oldValue, uint32 newValue, PyDict *notif, std::vector< std::string > &dbQ)
Definition: ServiceDB.cpp:304
#define minPlayerItem
Definition: EVE_Defines.h:149
Python's dictionary.
Definition: PyRep.h:719
void DeleteAdvert(uint16 adID)
PyRep * GetMedalsReceivedDetails(int32 charID)
uint32 GetUInt(uint32 index) const
Definition: dbcore.cpp:658
uint32 GetRegionID() const
Definition: Client.h:154
PyRep * GetRecipientsOfMedal(int32 medalID)
double GetDouble(uint32 index) const
Definition: dbcore.cpp:693
#define PRL(i)
grantableRolesAtHQ
void RemoveContact(uint32 contactID, uint32 ownerID)
PyRep * GetLabels(uint32 corpID)
bool CreateMemberAttributeUpdate(uint32 newCorpID, uint32 charID, MemberAttributeUpdate &attrib)
EVEItemFlags
Definition: EVE_Flags.h:13
PyRep * GetMyShares(uint32 ownerID)
bool CreateCorporationCreatePacket(OnCorporationChanged &cc, uint32 oldCorpID, uint32 newCorpID)
PyRep * GetMedalsReceived(int32 charID)
PyRep * GetRecruiters(int32 corpID, uint16 adID)
std::string appText
Definition: CorpData.h:68
Python floating point number.
Definition: PyRep.h:292
int32 GetCharacterID() const
Definition: Client.h:113
void SetLabel(uint32 corpID, uint32 color, std::string name)
bool DeleteApplication(const Corp::ApplicationInfo &aInfo)
const_iterator begin() const
Definition: PyRep.h:660
PyRep * GetCorpRoles()
int32 GetCorporationID() const
Definition: Client.h:123
#define sEntityList
Definition: EntityList.h:208
void GetCorpStations(uint32 corpID, std::vector< uint32 > &stVec)
storage_type::const_iterator const_iterator
Definition: PyRep.h:644
void EditLabel(uint32 corpID, uint32 labelID, uint32 color, std::string name)
static uint32 IntegerValueU32(PyRep *pRep)
Definition: PyRep.cpp:134
PyRep * GetKillsAndLosses(uint32 corpID, uint32 number, uint32 offset)
void AddBulletin(uint32 corpID, uint32 ownerID, uint32 cCharID, std::string &title, std::string &body)
void UpdateContact(int32 relationshipID, uint32 contactID, uint32 ownerID)
static uint32 GetCorporationCEO(uint32 corpID)
PyObjectEx * DBResultToCIndexedRowset(DBQueryResult &result, const char *key)
Definition: EVEDBUtils.cpp:419
CharacterRef GetChar() const
Definition: Client.h:164
Python tuple.
Definition: PyRep.h:567
int32 GetCorpIDforChar(int32 charID)
void Dump(FILE *into, const char *pfx) const
Dumps object to file.
Definition: PyRep.cpp:84
void CreateTitleData(uint32 corpID)
signed __int8 int8
Definition: eve-compat.h:45
int32 GetAllianceID() const
Definition: Client.h:125
static void GetMemberIDs(uint32 corpID, std::vector< uint32 > &ids, bool online=true)
bool IsList() const
Definition: PyRep.h:109
PyObject * GetCorporation(uint32 corpID)
void AddItem(PyRep *i)
Definition: PyRep.h:701
void ProcessStringChange(const char *key, const std::string &oldValue, std::string newValue, PyDict *notif, std::vector< std::string > &dbQ)
Definition: ServiceDB.cpp:266
signed __int32 int32
Definition: eve-compat.h:49
PyRep * GetSharesForCorp(uint32 corpID)
PyRep * GetItem(size_t index) const
Returns Python object.
Definition: PyRep.h:674
void GiveMedalToCharacters(uint32 issuerID, uint32 corpID, int32 medalID, std::vector< uint32 > &charVec, std::string &reason)
* args
bool GetRow(DBResultRow &into)
Definition: dbcore.cpp:552
PyObject * DBRowToRow(DBResultRow &row, const char *type)
Definition: EVEDBUtils.cpp:208
bool UpdateTitle(uint32 corpID, Call_UpdateTitleData &args, PyDict *updates)
void EditBulletin(uint32 bulletinID, uint32 eCharID, int64 eDataTime, std::string &title, std::string &body)
float taxRate
PyRep * GetApplications(uint32 corpID)
#define is_log_enabled(type)
Definition: logsys.h:78
uint16 GetCorpMemberCount(uint32 corpID)
PyRep * GetBulletins(uint32 corpID)
PyRep * GetAdTypeData()
Python extended object.
Definition: PyRep.h:861
const char * c_str() const
Definition: dbcore.h:48
#define IsPlayerItem(itemID)
Definition: EVE_Defines.h:256
Python object.
Definition: PyRep.h:826
uint16 CreateMedal(uint32 ownerID, uint32 creatorID, std::string &title, std::string &description)
PyRep * GetAssetInventoryForLocation(uint32 corpID, uint32 locationID, const char *flags)
PyObject * GetCorporationBills(uint32 corpID, bool payable)
#define codelog(type, fmt,...)
Definition: logsys.h:128
void SetItem(size_t index, PyRep *object)
Stores Python object.
Definition: PyRep.h:610
PyRep * GetAdvert(uint16 adID)
PyRep * GetVotes(uint32 voteCaseID)
bool AddCorporation(Call_AddCorporation &corpInfo, Client *pClient, uint32 &corpID)
PyRep * GetContacts(uint32 corpID)
PyRep * GetAllCorpMedals(uint32 corpID)
PyObject * DBResultToRowset(DBQueryResult &result)
Definition: EVEDBUtils.cpp:81
PyList * AsList()
Definition: PyRep.h:140
PyRep * GetAdGroupData()
Python integer.
Definition: PyRep.h:231
PyRep * GetRoleHistroy(uint32 corpID, uint32 charID, int64 fromDate, int64 toDate, uint8 rowsPerPage)
PyDict * AsDict()
Definition: PyRep.h:142
uint8 race() const
Definition: Character.h:278
void CastVote(uint32 corpID, uint32 charID, uint32 voteCaseID, uint8 optionID)
static std::string GetDivisionName(uint32 corpID, uint16 acctKey)
#define NI(i)
PyRep * GetVoteOptions(uint32 voteCaseID)
int32 allianceID
#define PyStatic
Definition: PyRep.h:1209
X * get() const
Definition: RefPtr.h:213
bool IsNull(uint32 index) const
Definition: dbcore.h:102
#define _NI(a, b)
static uint32 GetCorpID(uint32 charID)
#define IsPlayerCorp(itemID)
Definition: EVE_Defines.h:241
PyRep * GetCorpMedalData(uint32 corpID)
void DeleteTitle(uint32 corpID, uint16 titleID)
PyRep * PyHasShares(uint32 charID, uint32 corpID)
#define IsCharacterID(itemID)
Definition: EVE_Defines.h:206
PyRep * GetTitles(uint32 corpID)
void ProcessLongChange(const char *key, int64 oldValue, int64 newValue, PyDict *notif, std::vector< std::string > &dbQ)
Definition: ServiceDB.cpp:320
Definition: Client.h:66
void GetMembersForQuery(std::ostringstream &query, std::vector< uint32 > &result)
PyRep * GetMedalStatuses()
static void UpdateCorpHQ(uint32 corpID, uint32 stationID)
#define PRN
unsigned __int32 uint32
Definition: eve-compat.h:50
double GetCloneTypeCostByID(uint32 cloneTypeID)
bool GetCurrentApplicationInfo(Corp::ApplicationInfo &aInfo)
bool CreateCorporationChangePacket(OnCorporationChanged &cc, uint32 oldCorpID, uint32 newCorpID)
void AddRoleHistory(uint32 corpID, uint32 charID, uint32 issuerID, int64 oldRoles, int64 newRoles, bool grantable)
#define _NS(a, b)
#define maxPlayerItem
Definition: EVE_Defines.h:150
std::set< uint32 > characters
Definition: EntityList.h:58
grantableRolesAtBase
PyRep * GetMktInfo(uint32 corpID)
PyObject * DBResultToIndexRowset(DBQueryResult &result, const char *key)
Definition: EVEDBUtils.cpp:144
uint16 GetCorpMemberLimit(uint32 corpID)
#define PRI(i)
PyObject * GetStations(uint32 corpID)
uint32 corporationID
void GetMembersPaged(uint32 corpID, uint8 page, DBQueryResult &res)
PyRep * GetMemberTrackingInfoSimple(uint32 corpID)
double GetFileTimeNow()
Definition: utils_time.cpp:84
PyRep * GetMyApplications(uint32 charID)
#define IsOfficeID(itemID)
Definition: EVE_Defines.h:253
PyRep * GetAssetInventory(uint32 corpID, EVEItemFlags locFlag, const char *flags)
DBerror error
Definition: dbcore.h:69
signed __int64 int64
Definition: eve-compat.h:51
uint32 GetStationCorporationCEO(uint32 stationID)
const_iterator end() const
Definition: PyRep.h:661
PyObject * GetEveOwners(uint32 corpID)
PyObject * ListStationCorps(uint32 station_id)
PyRep * GetItemEvents(uint32 corpID, uint32 charID, int64 fromDate, int64 toDate, uint8 rowsPerPage)
bool UpdateApplication(const Corp::ApplicationInfo &aInfo)
void GetAutoPay(uint32 corpID, DBQueryResult &res)
int32 warFactionID
void MoveShares(uint32 ownerID, uint32 corpID, Call_MoveShares &args)
static std::string _IoN(PyRep *r)
signed __int16 int16
Definition: eve-compat.h:47
bool IsTickerTaken(std::string ticker)
int8 GetSkillLevel(uint16 skillTypeID, bool zeroForNotInjected=true) const
Definition: Character.cpp:575
void AddItemEvent(uint32 corpID, uint32 charID, uint16 eTypeID)
PyObject * GetEmploymentRecord(uint32 charID)
void UpdateAdvert(uint16 adID, uint32 corpID, int64 typeMask, int8 days, uint16 members, std::string description, uint32 channelID, std::string title)
void DeleteBulletin(uint32 bulletinID)
size_t GetRowCount()
Definition: dbcore.h:72
PyPackedRow * DBRowToPackedRow(DBResultRow &row)
Definition: EVEDBUtils.cpp:453
#define F(name, o, n)
int32 GetStationID() const
Definition: Client.h:114
PyDict * DBResultToPackedRowDict(DBQueryResult &result, const char *key)
Definition: EVEDBUtils.cpp:340
bool IsInt() const
Definition: PyRep.h:100
#define maxOffice
Definition: EVE_Defines.h:145
PyRep * GetAdRegistryData(int64 typeMask=0, bool inAlliance=false, int16 minMembers=0, uint16 maxMembers=12602)
PyObject * DBRowToKeyVal(DBResultRow &row)
Definition: EVEDBUtils.cpp:199
static int64 IntegerValue(PyRep *pRep)
Definition: PyRep.cpp:118
PyRep * GetMember(uint32 charID)
bool UpdateDivisionNames(uint32 corpID, const Call_UpdateDivisionNames &divs, PyDict *notif)
int64 GetAdvertTime(uint16 adID, uint32 corpID)
int64 GetInt64(uint32 index) const
Definition: dbcore.cpp:670
unsigned __int16 uint16
Definition: eve-compat.h:48
std::string ticker
bool HasShares(uint32 charID, uint32 corpID)
void AddVoteCase(uint32 corpID, uint32 charID, Call_InsertVoteCase &args)
PyRep * GetSanctionedItems(uint32 corpID, uint8 status=0)
void SetItem(PyRep *key, PyRep *value)
SetItem adds or sets a database entry.
Definition: PyRep.cpp:713
void GetMembers(uint32 corpID, DBQueryResult &res)
static void GetCorpData(CorpData &data)
const char * TypeString() const
Definition: PyRep.cpp:76
std::string name
Definition: dbcore.h:39
bool InsertApplication(Corp::ApplicationInfo &aInfo)
Python list.
Definition: PyRep.h:639
static std::string GetCorpName(uint32 corpID)
std::string optionText
Definition: CorpData.h:53
void SetItemString(const char *key, PyRep *value)
SetItemString adds or sets a database entry.
Definition: PyRep.h:812
#define minOffice
Definition: EVE_Defines.h:144
Python long integer.
Definition: PyRep.h:261
uint32 CreateAdvert(Client *pClient, uint32 corpID, int64 typeMask, int8 days, uint16 members, std::string description, uint32 channelID, std::string title)
PyRep * GetVoteItems(uint32 corpID, uint8 status=0, uint8 maxLen=20)
void SaveMedalData(int64 medalID, std::vector< Corp::MedalData > &dataList)
#define sDataMgr
void DeleteLabel(uint32 corpID, uint32 labelID)
void SetMedalStatus(uint32 charID, uint16 medalID, uint8 status)