EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
PlanetMgr.cpp
Go to the documentation of this file.
1 
14 #include "eve-server.h"
15 
16 #include "Client.h"
17 #include "PyService.h"
18 #include "account/AccountService.h"
19 #include "inventory/ItemType.h"
21 #include "packets/Planet.h"
22 #include "planet/Colony.h"
23 #include "planet/Planet.h"
24 #include "planet/PlanetMgr.h"
25 #include "planet/PlanetDataMgr.h"
26 #include "system/SystemManager.h"
27 
28 
29 PlanetMgr::PlanetMgr(PyServiceMgr *mgr, Client* pClient, PlanetSE* pPlanet, Colony* pColony)
30 :m_svcMgr(mgr),
31  m_client(pClient),
32  m_colony(pColony),
33 m_planet(pPlanet)
34 {
35 }
36 
37 PyRep* PlanetMgr::UpdateNetwork(UUNCommandList& uuncl)
38 {
39  using namespace PI;
40  bool cancel = false;
41  for (int i = 0; i < uuncl.commandList->size(); ++i) {
42  if (cancel)
43  return m_colony->GetColony();
44  UUNCommand uunc;
45  if (!uunc.Decode(uuncl.commandList->GetItem(i)->AsTuple())) {
46  _log(SERVICE__ERROR, "Failed to decode args for UUNCommand");
47  uuncl.commandList->Dump(PLANET__WARNING, " ");
48  m_client->SendErrorMsg("Internal Server Error. Ref: ServerError 04508.");
49  return nullptr;
50  }
51  _log(PLANET__TRACE, "PlanetMgr::UserUpdateNetwork() - loop: %u, command: %s(%i)", i, sPlanetDataMgr.GetCommandName(uunc.command), uunc.command);
52  switch (uunc.command) {
53  case Command::CreatePin: cancel = CreatePin(uunc); break;
54  case Command::RemovePin: RemovePin(uunc); break;
55  case Command::CreateLink: CreateLink(uunc); break;
56  case Command::RemoveLink: RemoveLink(uunc); break;
57  case Command::CreateRoute: CreateRoute(uunc); break;
58  case Command::SetLinkLevel: SetLinkLevel(uunc); break;
59  case Command::UpgradeCommandCenter: cancel = UpgradeCommandCenter(uunc); break;
60  case Command::SetSchematic: SetSchematic(uunc); break;
61  case Command::RemoveRoute: RemoveRoute(uunc); break;
64  case Command::InstallProgram: InstallProgram(uunc); break;
66  case Command::PrioritizeRoute: PrioritizeRoute(uunc); break;
67  default: {
68  _log(PLANET__ERROR, "PlanetMgr::UserUpdateNetwork() %s command %i", sPlanetDataMgr.GetCommandName(uunc.command), uunc.command);
69  } break;
70  }
71  }
72 
73  m_colony->Save();
74 
75  return m_colony->GetColony();
76 }
77 
78 bool PlanetMgr::UpgradeCommandCenter(UUNCommand& nc)
79 {
80  // the return here is used to cancel loop in UpdateNetwork. return false = continue
81 
82  int8 oldLevel = m_colony->GetLevel(), newLevel = (int8)PyRep::IntegerValue(nc.command_data->GetItem(1));
83  int32 cost = 0;
84  using namespace PI::Pin;
85  while (oldLevel != newLevel) {
86  // calculate total upgrade cost in cases where upgrading multiple levels at once
87  switch (oldLevel) {
88  case Level0: cost += 580000; break;
89  case Level1: cost += 930000; break;
90  case Level2: cost += 1200000; break;
91  case Level3: cost += 1500000; break;
92  case Level4: cost += 2100000; break;
93  }
94  ++oldLevel;
95  }
96  //take the money, send wallet blink event record the transaction in their journal.
97  std::string reason = "DESC: Command Center upgrade on ";
98  reason += m_planet->GetName();
99  uint32 ownerID = corpCONCORD;
101  ownerID = corpInterbus;
104  ownerID, // concord in empire, interbus otherwise
105  cost,
106  reason.c_str(),
108  m_planet->GetID(),
110 
111  m_colony->UpgradeCommandCenter(PyRep::IntegerValue(nc.command_data->GetItem(0)), newLevel);
112  return false;
113 }
114 
115 bool PlanetMgr::CreatePin(UUNCommand& nc)
116 {
117  // the return here is used to break out of loop if needed. return false = continue
118  using namespace EVEDB::invGroups;
119  uint32 typeID = PyRep::IntegerValueU32(nc.command_data->GetItem(1));
120  uint32 groupID = sItemFactory.GetType(typeID)->groupID();
121  switch (groupID) {
122  case Command_Centers: {
123  //take the money, send wallet blink event record the transaction in their journal.
124  std::string reason = "DESC: Command Center construction on ";
125  reason += m_planet->GetName();
126  uint32 ownerID = corpCONCORD;
128  ownerID = corpInterbus;
131  ownerID, // concord in empire, interbus otherwise
132  90000,
133  reason.c_str(),
135  m_planet->GetID(),
137 
138  UUNCCommandCenter uunccc;
139  if (!uunccc.Decode(nc.command_data)) {
140  _log(SERVICE__ERROR, "Failed to decode args for UUNCCommandCenter");
141  nc.command_data->Dump(PLANET__WARNING, " ");
142  m_client->SendErrorMsg("Internal Server Error. Ref: ServerError 04508.");
143  return true;
144  }
145  m_colony->CreateCommandPin(uunccc.pinID, uunccc.typeID, uunccc.latitude, uunccc.longitude);
146  if (m_planet->GetCustomsOffice() == nullptr)
148  return false;
149  } break;
150  case Mercenary_Bases:
151  case Capsuleer_Bases:{
152  // Not Supported yet
153  _log(PLANET__ERROR, "PlanetMgr::UserUpdateNetwork::CreatePin() Planet Bases (type/group %u/%u) not supported.", typeID, groupID);
154  m_client->SendErrorMsg("Internal Server Error. Ref: ServerError 04109.");
155  return true;
156  } break;
157  }
158  uint32 cost = 0;
159  std::string pinString = "";
160  switch (groupID) {
161  case Storage_Facilities: {
162  cost = 250000;
163  pinString = "Silo";
164  } break;
165  case Processors: {
166  switch (typeID) {
167  case 2469: // Lava Basic Industry Facility
168  case 2471: // Plasma Basic Industry Facility
169  case 2473: // Barren Basic Industry Facility
170  case 2481: // Temperate Basic Industry Facility
171  case 2483: // Storm Basic Industry Facility
172  case 2490: // Oceanic Basic Industry Facility
173  case 2492: // Gas Basic Industry Facility
174  case 2493: { // Ice Basic Industry Facility
175  cost = 75000;
176  pinString = "Basic Plant";
177  } break;
178  case 2470: // Lava Advanced Industry Facility
179  case 2472: // Plasma Advanced Industry Facility
180  case 2474: // Barren Advanced Industry Facility
181  case 2480: // Temperate Advanced Industry Facility
182  case 2484: // Storm Advanced Industry Facility
183  case 2485: // Oceanic Advanced Industry Facility
184  case 2491: // Ice Advanced Industry Facility
185  case 2494: { // Gas Advanced Industry Facility
186  cost = 250000;
187  pinString = "Advanced Plant";
188  } break;
189  case 2475: // Barren High-Tech Production Plant
190  case 2482: { // Temperate High-Tech Production Plant
191  cost = 525000;
192  pinString = "High-Tech Plant";
193  } break;
194  }
195  } break;
197  cost = 45000;
198  pinString = "ECU";
199  } break;
200  case Spaceports: {
201  cost = 900000;
202  pinString = "LaunchPad";
203  } break;
204  case Planetary_Links: {
205  cost = 1000;
206  pinString = "Link";
207  } break;
208  case Extractors: {
209  cost = 100;
210  pinString = "Extractor Head";
211  } break;
212  }
213 
214  if (cost < 1) {
215  // error here....
216  m_client->SendErrorMsg("Internal Server Error. Ref: ServerError 02001.");
217  return true;
218  }
219 
220  UUNCStandardPin uuncsp;
221  if (!uuncsp.Decode(nc.command_data)) {
222  _log(SERVICE__ERROR, "Failed to decode args for UUNCStandardPin");
223  nc.command_data->Dump(PLANET__WARNING, " ");
224  m_client->SendErrorMsg("Internal Server Error. Ref: ServerError 04588.");
225  return true;
226  }
227 
228  m_colony->CreatePin(groupID, uuncsp.pinID2, uuncsp.typeID, uuncsp.latitude, uuncsp.longitude);
229 
230  //take the money, send wallet blink event record the transaction in their journal.
231  std::string reason = "DESC: ";
232  reason += pinString.c_str();
233  reason += " Construction on ";
234  reason += m_planet->GetName();
235  uint32 ownerID = corpCONCORD;
237  ownerID = corpInterbus;
240  ownerID, // concord in empire, interbus otherwise
241  cost,
242  reason.c_str(),
244  m_planet->GetID(),
246 
247  return false;
248 }
249 
250 void PlanetMgr::CreateLink(UUNCommand& nc)
251 {
252  uint32 src = 0, dest = 0, level = 0;
253  if (nc.command_data->GetItem(0)->IsInt()) {
254  if (nc.command_data->GetItem(1)->IsInt()) {
255  UUNCLinkExist uuncle;
256  if (!uuncle.Decode(nc.command_data)) {
257  _log(SERVICE__ERROR, "Failed to decode args for UUNCLinkExist");
258  nc.command_data->Dump(PLANET__WARNING, " ");
259  m_client->SendErrorMsg("Internal Server Error. Ref: ServerError 04588.");
260  return;
261  }
262  src = uuncle.src;
263  dest = uuncle.dest;
264  level = uuncle.level;
265  } else {
266  UUNCLinkCommand uunclc;
267  if (!uunclc.Decode(nc.command_data)) {
268  _log(SERVICE__ERROR, "Failed to decode args for UUNCLinkCommand");
269  nc.command_data->Dump(PLANET__WARNING, " ");
270  m_client->SendErrorMsg("Internal Server Error. Ref: ServerError 04588.");
271  return;
272  }
273  src = uunclc.src;
274  dest = uunclc.dest2;
275  level = uunclc.level;
276  }
277  } else if (nc.command_data->GetItem(0)->IsTuple()) {
278  UUNCLinkStandard uuncls;
279  if (!uuncls.Decode(nc.command_data)) {
280  _log(SERVICE__ERROR, "Failed to decode args for UUNCLinkStandard");
281  nc.command_data->Dump(PLANET__WARNING, " ");
282  m_client->SendErrorMsg("Internal Server Error. Ref: ServerError 04588.");
283  return;
284  }
285  src = uuncls.src2;
286  dest = uuncls.dest2;
287  level = uuncls.level;
288  } else {
289  //Invalid...
290  _log(PLANET__ERROR, "PlanetMgr::UserUpdateNetwork::CreateLink() command_data type unrecognized: %s", nc.command_data->GetItem(0)->TypeString());
291  m_client->SendErrorMsg("Internal Server Error. Ref: ServerError 04508.");
292  return;
293  }
294  m_colony->CreateLink(src, dest, level);
295 }
296 
297 void PlanetMgr::CreateRoute(UUNCommand& nc)
298 {
299  Call_CreateRoute args;
300  if (!args.Decode(nc.command_data)) {
301  _log(SERVICE__ERROR, "Failed to decode args for Call_CreateRoute");
302  nc.command_data->Dump(PLANET__WARNING, " ");
303  m_client->SendErrorMsg("Internal Server Error. Ref: ServerError 04588.");
304  return;
305  }
306 
307  PyIncRef(args.path);
308  m_colony->CreateRoute(args.routeID, args.typeID, args.qty, args.path);
309 }
310 
311 void PlanetMgr::RemovePin(UUNCommand& nc)
312 {
313  uint32 pinID = 0;
314  if (nc.command_data->GetItem(0)->IsInt()) {
315  pinID = PyRep::IntegerValue(nc.command_data->GetItem(0));
316  } else if (nc.command_data->GetItem(0)->IsTuple()) {
317  pinID = PyRep::IntegerValue(nc.command_data->GetItem(0)->AsTuple()->GetItem(1));
318  } else {
319  //Invalid...
320  _log(PLANET__ERROR, "PlanetMgr::UserUpdateNetwork::RemovePin() command_data type unrecognized: %s", nc.command_data->GetItem(0)->TypeString());
321  nc.command_data->Dump(PLANET__WARNING, " ");
322  m_client->SendErrorMsg("Internal Server Error. Ref: ServerError 04508.");
323  return;
324  }
325  m_colony->RemovePin(pinID);
326 }
327 
328 void PlanetMgr::RemoveLink(UUNCommand& nc)
329 {
330  _log(PLANET__TRACE, "PlanetMgr::UserUpdateNetwork::RemoveLink()");
331  nc.Dump(PLANET__WARNING, " ");
332 
333  m_colony->RemoveLink(PyRep::IntegerValue(nc.command_data->GetItem(0)), PyRep::IntegerValue(nc.command_data->GetItem(1)));
334 }
335 
336 void PlanetMgr::RemoveRoute(UUNCommand& nc)
337 {
338  uint32 routeID = 0;
339  if (nc.command_data->GetItem(0)->IsInt()) {
340  routeID = PyRep::IntegerValue(nc.command_data->GetItem(0));
341  } else if (nc.command_data->GetItem(0)->IsTuple()) {
342  routeID = PyRep::IntegerValue(nc.command_data->GetItem(0)->AsTuple()->GetItem(1));
343  } else {
344  //Invalid...
345  _log(PLANET__ERROR, "PlanetMgr::UserUpdateNetwork::RemoveRoute() command_data type unrecognized: %s", nc.command_data->GetItem(0)->TypeString());
346  nc.command_data->Dump(PLANET__WARNING, " ");
347  m_client->SendErrorMsg("Internal Server Error. Ref: ServerError 04508.");
348  return;
349  }
350  m_colony->RemoveRoute(routeID);
351 }
352 
353 void PlanetMgr::SetLinkLevel(UUNCommand& nc)
354 {
355  m_colony->UpgradeLink(PyRep::IntegerValue(nc.command_data->GetItem(0)),
356  PyRep::IntegerValue(nc.command_data->GetItem(1)),
357  PyRep::IntegerValue(nc.command_data->GetItem(2)));
358 }
359 
360 void PlanetMgr::SetSchematic(UUNCommand& nc)
361 {
362  uint32 pinID = 0;
363  if (nc.command_data->GetItem(0)->IsTuple()) {
364  pinID = PyRep::IntegerValue(nc.command_data->GetItem(0)->AsTuple()->GetItem(1));
365  } else if (nc.command_data->GetItem(0)->IsInt()) {
366  pinID = PyRep::IntegerValue(nc.command_data->GetItem(0));
367  }
368  m_colony->SetSchematic(pinID, PyRep::IntegerValue(nc.command_data->GetItem(1))); // 65 - 137
369 }
370 
371 void PlanetMgr::AddExtractorHead(UUNCommand& nc)
372 {
373  Call_AddMoveExtractorHead args;
374  if (!args.Decode(nc.command_data)) {
375  _log(SERVICE__ERROR, "Failed to decode args for Call_AddMoveExtractorHead");
376  nc.command_data->Dump(PLANET__WARNING, " ");
377  m_client->SendErrorMsg("Internal Server Error. Ref: ServerError 04588.");
378  return;
379  }
380 
381  m_colony->AddExtractorHead(args.ecuID, (uint16)args.headID, args.latitude, args.longitude);
382 }
383 
384 void PlanetMgr::MoveExtractorHead(UUNCommand& nc)
385 {
386  Call_AddMoveExtractorHead args;
387  if (!args.Decode(nc.command_data)) {
388  _log(SERVICE__ERROR, "Failed to decode args for Call_AddMoveExtractorHead");
389  nc.command_data->Dump(PLANET__WARNING, " ");
390  m_client->SendErrorMsg("Internal Server Error. Ref: ServerError 04588.");
391  return;
392  }
393 
394  m_colony->MoveExtractorHead(args.ecuID, (uint16)args.headID, args.latitude, args.longitude);
395 }
396 
397 void PlanetMgr::InstallProgram(UUNCommand& nc)
398 {
399  Call_InstallProgram args;
400  if (!args.Decode(nc.command_data)) {
401  _log(SERVICE__ERROR, "Failed to decode args for Call_InstallProgram");
402  nc.command_data->Dump(PLANET__WARNING, " ");
403  m_client->SendErrorMsg("Internal Server Error. Ref: ServerError 04588.");
404  return;
405  }
406 
407  m_colony->InstallProgram(args.ecuID, (uint16)args.typeID, args.headRadius, this);
408 }
409 
410 void PlanetMgr::KillExtractorHead(UUNCommand& nc)
411 {
412  m_colony->KillExtractorHead(PyRep::IntegerValue(nc.command_data->GetItem(0)), PyRep::IntegerValue(nc.command_data->GetItem(1)));
413 }
414 
415 void PlanetMgr::PrioritizeRoute(UUNCommand& nc)
416 {
417  _log(PLANET__TRACE, "PlanetMgr::UserUpdateNetwork::PrioritizeRoute()");
418  nc.Dump(COLONY__PKT_TRACE, " ");
419 
420  Call_PrioritizeRoute args;
421  if (!args.Decode(nc.command_data)) {
422  _log(SERVICE__ERROR, "Failed to decode args for Call_PrioritizeRoute");
423  nc.command_data->Dump(PLANET__WARNING, " ");
424  m_client->SendErrorMsg("Internal Server Error. Ref: ServerError 04588.");
425  return;
426  }
427 
428  m_colony->PrioritizeRoute(args.routeID, args.priority);
429 }
430 
Base Python wire object.
Definition: PyRep.h:66
void InstallProgram(UUNCommand &nc)
Definition: PlanetMgr.cpp:397
PlanetSE * m_planet
Definition: PlanetMgr.h:51
Client * m_client
Definition: PlanetMgr.h:49
void SetSchematic(UUNCommand &nc)
Definition: PlanetMgr.cpp:360
void SendErrorMsg(const char *fmt,...)
Definition: Client.cpp:2719
#define _log(type, fmt,...)
Definition: logsys.h:124
void Save()
Definition: Colony.cpp:190
bool CreatePin(UUNCommand &nc)
Definition: PlanetMgr.cpp:115
void KillExtractorHead(uint32 ecuID, uint16 headID)
Definition: Colony.cpp:743
int8 GetLevel()
Definition: Colony.h:91
void AddExtractorHead(UUNCommand &nc)
Definition: PlanetMgr.cpp:371
void CreatePin(uint32 groupID, uint32 pinID, uint32 typeID, double latitude, double longitude)
Definition: Colony.cpp:373
CustomsSE * GetCustomsOffice()
Definition: Planet.h:68
PyRep * UpdateNetwork(UUNCommandList &uuncl)
Definition: PlanetMgr.cpp:37
void KillExtractorHead(UUNCommand &nc)
Definition: PlanetMgr.cpp:410
int32 GetCharacterID() const
Definition: Client.h:113
const float GetSystemSecurityRating()
Definition: SystemManager.h:86
void SetLinkLevel(UUNCommand &nc)
Definition: PlanetMgr.cpp:353
static uint32 IntegerValueU32(PyRep *pRep)
Definition: PyRep.cpp:134
void RemoveRoute(uint16 routeID)
Definition: Colony.cpp:697
void CreateRoute(UUNCommand &nc)
Definition: PlanetMgr.cpp:297
void AddExtractorHead(uint32 ecuID, uint16 headID, double latitude, double longitude)
Definition: Colony.cpp:707
signed __int8 int8
Definition: eve-compat.h:45
void CreateLink(UUNCommand &nc)
Definition: PlanetMgr.cpp:250
signed __int32 int32
Definition: eve-compat.h:49
Definition: Colony.h:38
Colony * m_colony
Definition: PlanetMgr.h:50
* args
SystemManager * SystemMgr()
Definition: SystemEntity.h:196
void PrioritizeRoute(UUNCommand &nc)
Definition: PlanetMgr.cpp:415
void RemoveLink(uint32 src, uint32 dest)
Definition: Colony.cpp:684
void CreateRoute(uint16 routeID, uint32 typeID, uint32 qty, PyList *path)
Definition: Colony.cpp:505
static void TranserFunds(uint32 fromID, uint32 toID, double amount, std::string reason="", uint8 entryTypeID=Journal::EntryType::Undefined, uint32 referenceID=0, uint16 fromKey=Account::KeyType::Cash, uint16 toKey=Account::KeyType::Cash, Client *pClient=nullptr)
void CreateLink(uint32 src, uint32 dest, uint16 level)
Definition: Colony.cpp:477
void InstallProgram(uint32 ecuID, uint16 typeID, float headRadius, PlanetMgr *pPMgr)
Definition: Colony.cpp:794
void CreateCommandPin(uint32 itemID, uint32 typeID, double latitude, double longitude)
Definition: Colony.cpp:362
uint32 GetID()
Definition: SystemEntity.h:207
const char * GetName() const
Definition: SystemEntity.h:210
void RemoveLink(UUNCommand &nc)
Definition: PlanetMgr.cpp:328
Definition: Client.h:66
unsigned __int32 uint32
Definition: eve-compat.h:50
#define PyIncRef(op)
Definition: PyRep.h:56
void CreateCustomsOffice()
Definition: Planet.cpp:272
void RemovePin(UUNCommand &nc)
Definition: PlanetMgr.cpp:311
Definition: EVE_Planet.h:16
void RemoveRoute(UUNCommand &nc)
Definition: PlanetMgr.cpp:336
void MoveExtractorHead(uint32 ecuID, uint16 headID, double latitude, double longitude)
Definition: Colony.cpp:724
void UpgradeCommandCenter(uint32 pinID, int8 level)
Definition: Colony.cpp:591
void SetSchematic(uint32 pinID, uint8 schematicID=0)
Definition: Colony.cpp:753
#define sItemFactory
Definition: ItemFactory.h:165
static int64 IntegerValue(PyRep *pRep)
Definition: PyRep.cpp:118
void PrioritizeRoute(uint16 routeID, uint8 priority)
Definition: Colony.cpp:1195
PyRep * GetColony()
Definition: Colony.cpp:1313
PlanetMgr(PyServiceMgr *mgr, Client *pClient, PlanetSE *pPlanet, Colony *pColony)
Definition: PlanetMgr.cpp:29
void RemovePin(uint32 pinID)
Definition: Colony.cpp:615
unsigned __int16 uint16
Definition: eve-compat.h:48
bool UpgradeCommandCenter(UUNCommand &nc)
Definition: PlanetMgr.cpp:78
#define sPlanetDataMgr
Definition: PlanetDataMgr.h:41
void UpgradeLink(uint32 src, uint32 dest, uint8 level)
Definition: Colony.cpp:603
void MoveExtractorHead(UUNCommand &nc)
Definition: PlanetMgr.cpp:384