SEGS  0.6.1-develop [39915b3b]
Super Entity Game Server
HandlerLocator.h
Go to the documentation of this file.
1 /*
2  * SEGS - Super Entity Game Server
3  * http://www.segs.io/
4  * Copyright (c) 2006 - 2019 SEGS Team (see AUTHORS.md)
5  * This software is licensed under the terms of the 3-clause BSD License. See LICENSE.md for details.
6  */
7 
8 #pragma once
9 #include <deque>
10 #include <unordered_map>
11 #include <stdint.h>
12 
13 class EventProcessor;
14 class MessageBus;
20 {
21  static MessageBus *m_message_bus;
22  static EventProcessor *m_db_sync_handler;
23  static EventProcessor *m_auth_handler;
24  static EventProcessor *m_email_handler;
25  static EventProcessor *m_friend_handler;
26  static std::deque<EventProcessor *> m_game_servers;
27  static std::deque<EventProcessor *> m_map_servers;
28  static std::deque<EventProcessor *> m_game_db_servers;
29  static std::deque<std::deque<EventProcessor *>> m_map_instances;
30  static std::unordered_map<uint32_t,std::deque<EventProcessor *>> m_all_event_processors;
31 public:
33  static void setMessageBus(MessageBus *h) { m_message_bus=h; }
34  static MessageBus *getMessageBus() { return m_message_bus; }
35 
36  static void setAuthDB_Handler(EventProcessor *h) { m_db_sync_handler=h; }
37  static EventProcessor *getAuthDB_Handler() { return m_db_sync_handler; }
38 
39  static void setAuth_Handler(EventProcessor *h) { m_auth_handler=h; }
40  static EventProcessor *getAuth_Handler() { return m_auth_handler; }
41 
42  static void setEmail_Handler(EventProcessor *h) {m_email_handler=h;}
43  static EventProcessor *getEmail_Handler() { return m_email_handler; }
44 
45  static void setFriend_Handler(EventProcessor *h) { m_friend_handler=h; }
46  static EventProcessor *getFriend_Handler() { return m_friend_handler; }
47 
48  static const std::deque<EventProcessor *> &allGameDBHandlers() { return m_game_db_servers; }
49  static const std::deque<EventProcessor *> &allGameHandlers() { return m_game_servers; }
50  static EventProcessor *getGame_Handler(uint8_t id)
51  {
52  if(id>=m_game_servers.size())
53  return nullptr;
54  return m_game_servers[id];
55  }
56  static EventProcessor *getGame_DB_Handler(uint8_t id)
57  {
58  if(id>=m_game_db_servers.size())
59  return nullptr;
60  return m_game_db_servers[id];
61  }
62  static void setGame_Handler(uint8_t id,EventProcessor *h)
63  {
64  if(id>=m_game_servers.size())
65  m_game_servers.resize(id+1);
66  m_game_servers[id] = h;
67  }
68  static void setGame_DB_Handler(uint8_t id,EventProcessor *h)
69  {
70  if(id>=m_game_db_servers.size())
71  m_game_db_servers.resize(id+1);
72  m_game_db_servers[id] = h;
73  }
74  // The ID here must be the same as the GameServer ID
75  // the MapServer is the point of contact for the GameServer, and will create many MapInstances with running maps
76  static EventProcessor *getMap_Handler(uint8_t id)
77  {
78  if(id>=m_map_servers.size())
79  return nullptr;
80  return m_map_servers[id];
81  }
82  static void setMap_Handler(uint8_t id,EventProcessor *h)
83  {
84  if(id>=m_map_servers.size())
85  m_map_servers.resize(id+1);
86  m_map_servers[id] = h;
87  }
88 
89  static EventProcessor *getMapInstance_Handler(uint8_t id,uint8_t subserver_id)
90  {
91  if(id>=m_map_instances.size())
92  return nullptr;
93  if(subserver_id>=m_map_instances[id].size())
94  return nullptr;
95  return m_map_instances[id][subserver_id];
96  }
97  static void setMapInstance_Handler(uint8_t id,uint8_t subserver_id,EventProcessor *h)
98  {
99  if(id>=m_map_instances.size())
100  m_map_instances.resize(id+1);
101  if(subserver_id>=m_map_instances[id].size())
102  m_map_instances[id].resize(subserver_id+1);
103  m_map_instances[id][subserver_id] = h;
104  }
105  template<class T>
106  static EventProcessor *lookup(uint32_t instance_id)
107  {
108  auto iter = m_all_event_processors.find(T::processor_id);
109  if(iter==m_all_event_processors.end())
110  return nullptr;
111  if(instance_id>=iter->second.size())
112  return nullptr;
113  return iter->second[instance_id];
114  }
115 };
116 extern void shutDownAllActiveHandlers();
static void setFriend_Handler(EventProcessor *h)
Definition: HandlerLocator.h:45
static const std::deque< EventProcessor * > & allGameDBHandlers()
Definition: HandlerLocator.h:48
static EventProcessor * getMapInstance_Handler(uint8_t id, uint8_t subserver_id)
Definition: HandlerLocator.h:89
static EventProcessor * getFriend_Handler()
Definition: HandlerLocator.h:46
The HandlerLocator class is meant as a central point where each service registers it&#39;s presence...
Definition: HandlerLocator.h:19
static EventProcessor * getAuthDB_Handler()
Definition: HandlerLocator.h:37
static void setAuth_Handler(EventProcessor *h)
Definition: HandlerLocator.h:39
static void setMap_Handler(uint8_t id, EventProcessor *h)
Definition: HandlerLocator.h:82
static EventProcessor * getMap_Handler(uint8_t id)
Definition: HandlerLocator.h:76
void shutDownAllActiveHandlers()
Definition: HandlerLocator.cpp:30
static EventProcessor * getGame_Handler(uint8_t id)
Definition: HandlerLocator.h:50
static EventProcessor * lookup(uint32_t instance_id)
Definition: HandlerLocator.h:106
static void setMapInstance_Handler(uint8_t id, uint8_t subserver_id, EventProcessor *h)
Definition: HandlerLocator.h:97
static EventProcessor * getAuth_Handler()
Definition: HandlerLocator.h:40
static void setGame_DB_Handler(uint8_t id, EventProcessor *h)
Definition: HandlerLocator.h:68
static void setGame_Handler(uint8_t id, EventProcessor *h)
Definition: HandlerLocator.h:62
static void setAuthDB_Handler(EventProcessor *h)
Definition: HandlerLocator.h:36
static void setEmail_Handler(EventProcessor *h)
Definition: HandlerLocator.h:42
static const std::deque< EventProcessor * > & allGameHandlers()
Definition: HandlerLocator.h:49
The MessageBus class is responsible for forwarding incoming events to correct subscriber&#39;s endpoints...
Definition: MessageBus.h:25
static void setMessageBus(MessageBus *h)
Definition: HandlerLocator.h:33
Definition: EventProcessor.h:22
static EventProcessor * getGame_DB_Handler(uint8_t id)
Definition: HandlerLocator.h:56
static EventProcessor * getEmail_Handler()
Definition: HandlerLocator.h:43
static MessageBus * getMessageBus()
Definition: HandlerLocator.h:34