EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
EntityList.h
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  Rewrite: Allan
25 */
26 
27 #ifndef EVE_ENTITY_LIST_H
28 #define EVE_ENTITY_LIST_H
29 
30 #include <vector>
31 #include <map>
32 #include <set>
33 #include "eve-compat.h"
34 #include "eve-common.h"
35 #include "utils/Singleton.h"
36 #include "threading/Mutex.h"
37 
38 class Agent;
39 class Client;
40 class PyAddress;
42 class SystemManager;
43 class ProbeSE;
44 class PyTuple;
45 class PyServiceMgr;
46 class SystemEntity;
47 class TargetManager;
48 
49 typedef enum {
53 
54 //this object is a set of "or"s, matching any criteria is sufficient.
57 public:
58  std::set<uint32> characters;
59  std::set<uint32> locations;
60  std::set<uint32> corporations;
61 };
62 
64 : public Singleton<EntityList>
65 {
66 public:
67  EntityList();
68  ~EntityList();
69 
70  typedef std::set<uint32> character_set;
71 
72  void Initialize();
73  void Close();
74  void Process();
75  void Shutdown();
76  void Add(Client* pClient);
77  void Remove(Client* pClient);
78  // this must be called AFTER a character is selected, after Client and Character class construction is complete. (need complete data)
79  void AddPlayer(Client* pClient);
80  // this must only be called for a logged-in character.
81  void RemovePlayer(Client* pClient);
82  void AddNPC() { ++m_npcs; }
83  void RemoveNPC() { --m_npcs; }
84  void SetService(PyServiceMgr* svc) { m_services = svc; }
85 
86  // updated to use station guest list instead of full clientlist loop
87  void GetStationGuestList(uint32 stationID, std::vector<Client* > &result) const;
88 
89  // for main loop thread sleeping
90  bool HasClients() { return !m_players.empty(); }
91 
92  Agent* GetAgent(uint32 agentID);
93 
94  // will return nullptr if character not online
95  Client* FindClientByName(const char* name) const;
96  // will return nullptr if character not online
97  Client* FindClientByCharID(uint32 charID) const;
98 
99  // this will return nullptr and throw console msg on failure.
101 
102  bool IsOnline(uint32 charID);
103  PyRep* PyIsOnline(uint32 charID);
104 
105  uint32 GetNPCCount() { return m_npcs; }
106  uint32 GetClientCount() const { return m_clients.size(); }
107  uint32 GetPlayerCount() const { return m_players.size(); }
108  uint32 GetSystemCount() const { return m_systems.size(); }
109  uint32 GetStationCount() const { return m_stations.size(); }
111 
112  /* stamp shit here */
113  uint32 GetStamp() { return m_stamp; }
115 
116  // gets Client* for all ingame players
117  void GetClients(std::vector<Client* > &result) const;
118  void GetCorpClients(std::vector<Client*> &result, uint32 corpID) const;
119 
120  void AddStation(uint32 stationID, StationItemRef itemRef);
121  void RemoveStation(uint32 stationID);
123 
124  void RegisterSID(int64& sessionID);
125  void RemoveSID(int64 sessionID);
126 
127  std::string GetAnomalyID();
128 
129  bool GetTracking() { return m_shipTracking; }
130  void SetTracking(bool set=false) { m_shipTracking = set; }
131 
134  void GetUpTime(std::string& time);
136 
137 
138  // new shit for replacing current crazy notification sending
139  // this method will send notification to online members that have the role required for the notification sent.
141  void CorpNotify(uint32 corpID, uint8 bCastType, const char* notifyType, const char* idType, PyTuple* payload) const;
142  // current crazy notification sending methods
144  void Broadcast(const char* notifyType, const char* idType, PyTuple** payload) const;
145  void Broadcast(const PyAddress &dest, EVENotificationStream &noti) const;
146  void Multicast(const char* notifyType, const char* idType, PyTuple** in_payload, NotificationDestination target, uint32 target_id, bool seq = true);
147  void Multicast(const char* notifyType, const char* idType, PyTuple** payload, const MulticastTarget &mcset, bool seq=true);
148  void Multicast(const character_set &cset, const PyAddress &dest, EVENotificationStream &noti) const;
149  void Multicast(const character_set &cset, const char* notifyType, const char* idType, PyTuple** payload, bool seq=true) const;
150  void Unicast(uint32 charID, const char* notifyType, const char* idType, PyTuple** payload, bool seq=true);
151 
152  //testing target tics in <1hz
153  // add SE* and targMgr* to map
155  { m_targMgrs.emplace(pSE, pTM); }
156  // remove SE* and targMgr* from map
157  void DeleteTargMgr(SystemEntity* pSE) { m_targMgrs.erase(pSE); }
158 
159  // add ProbeSE* to map
160  void AddProbe(uint32 probeID, ProbeSE* pSE) { m_probes[probeID] = pSE; }
161  // remove ProbeSE* from map
162  void RemoveProbe(uint32 probeID) { m_probes.erase(probeID); }
163 
164 
165 protected:
166  PyServiceMgr* m_services; //we do not own this, only used for booting systems.
167 
169 
170 private:
174 
175  // connected clients (incomplete client class data)
176  // use this to delete Client*
177  std::vector<Client*> m_clients;
178  // logged-in players (complete client class data)
179  // DO NOT delete this Client* (use m_clients instead.)
180  std::map<uint32, Client*> m_players;
181  std::set<int64> m_sessions;
182  std::map<uint32, SystemManager*> m_systems;
183  std::map<uint32, StationItemRef> m_stations;
184  std::vector<std::string> m_anomIDs;
185  std::map<uint32, Agent*> m_agents;
186 
187  //testing target tics in <1hz
188  std::unordered_map<SystemEntity*, TargetManager*> m_targMgrs;
189  // also running scan probes at sub-hz tics
190  std::map<uint32, ProbeSE*> m_probes;
191 
192  // make list for corp members and their roles for easy access of notifications etc.
193  typedef std::map<Client*, int64> corpRole;
194  std::map<uint32, corpRole> m_corpMembers; //corpID/{Client*/corpRole}
195 
197 
203 
205 };
206 
207 //Singleton
208 #define sEntityList \
209  ( EntityList::get() )
210 
211 
212 #endif
213 
Base Python wire object.
Definition: PyRep.h:66
uint32 GetClientCount() const
Definition: EntityList.h:106
int64 m_startTime
Definition: EntityList.h:204
void AddPlayer(Client *pClient)
Definition: EntityList.cpp:156
unsigned __int8 uint8
Definition: eve-compat.h:46
std::set< uint32 > corporations
Definition: EntityList.h:60
std::map< uint32, Agent * > m_agents
Definition: EntityList.h:185
PyRep * PyIsOnline(uint32 charID)
Definition: EntityList.cpp:356
std::map< uint32, SystemManager * > m_systems
Definition: EntityList.h:182
void RemovePlayer(Client *pClient)
Definition: EntityList.cpp:173
uint16 GetClientSeed()
Definition: EntityList.h:110
void Unicast(uint32 charID, const char *notifyType, const char *idType, PyTuple **payload, bool seq=true)
Definition: EntityList.cpp:757
std::vector< std::string > m_anomIDs
Definition: EntityList.h:184
bool GetTracking()
Definition: EntityList.h:129
Agent * GetAgent(uint32 agentID)
Definition: EntityList.cpp:310
void SetTracking(bool set=false)
Definition: EntityList.h:130
uint32 m_minutes
Definition: EntityList.h:200
Client * FindClientByName(const char *name) const
Definition: EntityList.cpp:766
StationItemRef GetStationByID(uint32 stationID)
Definition: EntityList.cpp:371
std::unordered_map< SystemEntity *, TargetManager * > m_targMgrs
Definition: EntityList.h:188
void Add(Client *pClient)
Definition: EntityList.cpp:140
uint32 GetSystemCount() const
Definition: EntityList.h:108
void AddTargMgr(SystemEntity *pSE, TargetManager *pTM)
Definition: EntityList.h:154
NotificationDestination
Definition: EntityList.h:49
void GetCorpClients(std::vector< Client * > &result, uint32 corpID) const
Definition: EntityList.cpp:329
std::map< Client *, int64 > corpRole
Definition: EntityList.h:193
Common wrapper for platform-specific mutexes.
Definition: Mutex.h:36
Python tuple.
Definition: PyRep.h:567
void AddStation(uint32 stationID, StationItemRef itemRef)
Definition: EntityList.cpp:302
std::map< uint32, ProbeSE * > m_probes
Definition: EntityList.h:190
uint32 GetConnections()
Definition: EntityList.h:135
void Broadcast(const char *notifyType, const char *idType, PyTuple **payload) const
Definition: EntityList.cpp:610
void RegisterSID(int64 &sessionID)
Definition: EntityList.cpp:777
std::map< uint32, corpRole > m_corpMembers
Definition: EntityList.h:194
void Initialize()
Definition: EntityList.cpp:79
void RemoveSID(int64 sessionID)
Definition: EntityList.cpp:788
uint32 m_stamp
Definition: EntityList.h:199
void Multicast(const char *notifyType, const char *idType, PyTuple **in_payload, NotificationDestination target, uint32 target_id, bool seq=true)
Definition: EntityList.cpp:640
uint32 GetMinutes()
Definition: EntityList.h:114
Mutex mMutex
Definition: EntityList.h:168
Timer m_minuteTimer
Definition: EntityList.h:172
Definition: Agent.h:21
Definition: Probes.h:71
uint16 m_clientSeedID
Definition: EntityList.h:202
void RemoveProbe(uint32 probeID)
Definition: EntityList.h:162
Timer m_stampTimer
Definition: EntityList.h:171
void Shutdown()
Definition: EntityList.cpp:96
SystemManager * FindOrBootSystem(uint32 systemID)
Definition: EntityList.cpp:279
void GetStationGuestList(uint32 stationID, std::vector< Client * > &result) const
Definition: EntityList.cpp:343
void RemoveNPC()
Definition: EntityList.h:83
int64 GetStartTime()
Definition: EntityList.h:133
uint32 GetNPCCount()
Definition: EntityList.h:105
Definition: Client.h:66
std::string GetAnomalyID()
Definition: EntityList.cpp:378
void RemoveStation(uint32 stationID)
Definition: EntityList.cpp:306
uint32 GetPlayerCount() const
Definition: EntityList.h:107
uint32 GetStamp()
Definition: EntityList.h:113
unsigned __int32 uint32
Definition: eve-compat.h:50
std::set< uint32 > characters
Definition: EntityList.h:58
std::map< uint32, StationItemRef > m_stations
Definition: EntityList.h:183
std::set< uint32 > character_set
Definition: EntityList.h:70
void AddProbe(uint32 probeID, ProbeSE *pSE)
Definition: EntityList.h:160
double GetFileTimeNow()
Definition: utils_time.cpp:84
signed __int64 int64
Definition: eve-compat.h:51
std::map< uint32, Client * > m_players
Definition: EntityList.h:180
void GetClients(std::vector< Client * > &result) const
Definition: EntityList.cpp:324
PyServiceMgr * m_services
Definition: EntityList.h:166
void ResetStartTime()
Definition: EntityList.h:132
void SetService(PyServiceMgr *svc)
Definition: EntityList.h:84
Client * FindClientByCharID(uint32 charID) const
Definition: EntityList.cpp:363
Template used for singleton classes.
Definition: Singleton.h:43
Timer m_targTimer
Definition: EntityList.h:173
bool HasClients()
Definition: EntityList.h:90
void Remove(Client *pClient)
Definition: EntityList.cpp:146
void Process()
Definition: EntityList.cpp:188
bool IsOnline(uint32 charID)
Definition: EntityList.cpp:349
uint32 m_connections
Definition: EntityList.h:201
void GetUpTime(std::string &time)
Definition: EntityList.cpp:395
void CorpNotify(uint32 corpID, uint8 bCastType, const char *notifyType, const char *idType, PyTuple *payload) const
Definition: EntityList.cpp:432
std::set< int64 > m_sessions
Definition: EntityList.h:181
void AddNPC()
Definition: EntityList.h:82
Definition: timer.h:30
void DeleteTargMgr(SystemEntity *pSE)
Definition: EntityList.h:157
void Close()
Definition: EntityList.cpp:108
uint32 m_npcs
Definition: EntityList.h:198
std::set< uint32 > locations
Definition: EntityList.h:59
unsigned __int16 uint16
Definition: eve-compat.h:48
uint32 GetStationCount() const
Definition: EntityList.h:109
bool m_shipTracking
Definition: EntityList.h:196
std::vector< Client * > m_clients
Definition: EntityList.h:177