SEGS  0.4.2
Super Entity Game Server
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MapInstance.h
Go to the documentation of this file.
1 /*
2  * SEGS - Super Entity Game Server
3  * http://www.segs.io/
4  * Copyright (c) 2006 - 2018 SEGS Team (see Authors.txt)
5  * This software is licensed! (See License.txt for details)
6  */
7 
8 #pragma once
9 
10 #include "EntityStorage.h"
11 #include "EventProcessor.h"
13 #include "Servers/ServerEndpoint.h"
14 #include "ScriptingEngine.h"
15 #include "MapClientSession.h"
16 
17 #include <map>
18 #include <memory>
19 #include <vector>
20 
21 #define WORLD_UPDATE_TICKS_PER_SECOND 30
22 
23 class IdleEvent;
24 class MapServer;
25 class SEGSTimer;
26 class InputState;
27 class World;
28 class MapServerData;
29 
30 // server<-> server event types
31 struct ExpectMapClientRequest;
32 
33 class MapLinkEndpoint;
34 
35 class MapInstance final : public EventProcessor
36 {
38  using ScriptEnginePtr = std::unique_ptr<ScriptingEngine>;
39  QString m_data_path;
40  uint32_t m_index = 1; // what does client expect this to store, and where do we send it?
41  std::unique_ptr<SEGSTimer> m_world_update_timer;
42  std::unique_ptr<SEGSTimer> m_resend_timer;
43 
44  World * m_world;
45  uint8_t m_game_server_id=255; // 255 is `invalid` id
46  uint32_t m_owner_id;
47  uint32_t m_instance_id;
48 
49 public:
52  ScriptEnginePtr m_scripting_interface;
55 
56 public:
57  MapInstance(const QString &name,const ListenAndLocationAddresses &listen_addr);
58  ~MapInstance() override;
59  void dispatch(SEGSEvent *ev) override;
60 
61  void enqueue_client(MapClientSession *clnt);
62  void start();
63  const QString & name() const { return m_data_path; }
64  uint32_t index() const { return m_index; }
65  void spin_down();
66  bool spin_up_for(uint8_t game_server_id, uint32_t owner_id, uint32_t instance_id);
67  const MapServerData & serverData() const;
68 protected:
69  void reap_stale_links();
70  void on_client_connected_to_other_server(ClientConnectedMessage *ev);
71  void on_client_disconnected_from_other_server(ClientDisconnectedMessage *ev);
72  void process_chat(MapClientSession *sender, QString &msg_text);
73  // DB -> Server messages
74  void on_name_clash_check_result(WouldNameDuplicateResponse *ev);
75  void on_character_created(CreateNewCharacterResponse *ev);
76  void on_entity_response(GetEntityResponse *ev);
77  // Server->Server messages
78  void on_expect_client(ExpectMapClientRequest *ev);
79 
80  void on_link_lost(SEGSEvent *ev);
81  void on_disconnect(class DisconnectRequest *ev);
82  void on_scene_request(class SceneRequest *ev);
83  void on_entities_request(class EntitiesRequest *ev);
84  void on_create_map_entity(class NewEntity *ev);
85  void on_timeout(TimerEvent *ev);
86  void on_combine_boosts(class CombineRequest *);
87  void on_input_state(InputState *st);
88  void on_idle(IdleEvent *ev);
89  void on_shortcuts_request(class ShortcutsRequest *ev);
90 
91  void sendState();
92  void on_cookie_confirm(class CookieRequest *ev);
93  void on_window_state(class WindowState *ev);
94  void on_console_command(class ConsoleCommand *ev);
95  void on_client_quit(class ClientQuit *ev);
96  void on_connection_request(class ConnectRequest *ev);
98  void on_minimap_state(class MiniMapState *ev);
100  void on_location_visited(class LocationVisited *ev);
101  void on_plaque_visited(class PlaqueVisited *ev);
103  void on_enter_door(class EnterDoor *ev);
104  void on_change_stance(class ChangeStance *ev);
105  void on_set_destination(class SetDestination *ev);
106  void on_abort_queued_power(class AbortQueuedPower *ev);
109  void on_chat_reconfigured(class ChatReconfigure *ev);
110  void on_switch_viewpoint(class SwitchViewPoint *ev);
111  void on_client_options(class SaveClientOptions *ev);
113  void on_set_default_power(class SetDefaultPower *ev);
114  void on_unqueue_all(class UnqueueAll *ev);
117  void on_powers_dockmode(class PowersDockMode *ev);
118  void on_switch_tray(class SwitchTray *ev);
120  void on_reset_keybinds(class ResetKeybinds *ev);
121  void on_set_keybind(class SetKeybind *ev);
122  void on_remove_keybind(class RemoveKeybind *ev);
123  void on_emote_command(const QString &command, Entity *ent);
124  void on_interact_with(class InteractWithEntity *ev);
125 };
Definition: MapEvents.h:137
Instances of SEGSTimer class are used to schedule events in the future.
Definition: SEGSTimer.h:18
~MapInstance() override
Definition: MapInstance.cpp:154
void on_timeout(TimerEvent *ev)
Handle instance-wide timers.
Definition: MapInstance.cpp:607
Definition: EntityStorage.h:34
Definition: PlayerInfo.h:29
Definition: InteractWithEntity.h:15
Definition: MapClientSession.h:32
void on_combine_boosts(class CombineRequest *)
Definition: MapInstance.cpp:674
Definition: MapEvents.h:465
Definition: MapEvents.h:416
ListenAndLocationAddresses m_addresses
Definition: MapInstance.h:54
void on_switch_tray(class SwitchTray *ev)
Definition: MapInstance.cpp:1812
void process_chat(MapClientSession *sender, QString &msg_text)
Definition: MapInstance.cpp:844
void on_client_quit(class ClientQuit *ev)
Definition: MapInstance.cpp:376
Definition: SEGSEvent.h:32
void on_input_state(InputState *st)
Definition: MapInstance.cpp:679
void on_target_chat_channel_selected(class TargetChatChannelSelected *ev)
Definition: MapInstance.cpp:1788
void on_connection_request(class ConnectRequest *ev)
Definition: MapInstance.cpp:361
void on_chat_reconfigured(class ChatReconfigure *ev)
Definition: MapInstance.cpp:1754
Definition: MapEvents.h:41
Definition: PlaqueVisited.h:16
void on_idle(IdleEvent *ev)
Definition: MapInstance.cpp:354
Definition: WorldSimulation.h:17
Definition: NewEntity.h:12
void on_interact_with(class InteractWithEntity *ev)
Definition: MapInstance.cpp:1873
void on_change_stance(class ChangeStance *ev)
Definition: MapInstance.cpp:1684
Definition: MapEvents.h:400
void on_character_created(CreateNewCharacterResponse *ev)
Definition: MapInstance.cpp:481
MapLinkEndpoint * m_endpoint
Definition: MapInstance.h:53
void on_create_map_entity(class NewEntity *ev)
Definition: MapInstance.cpp:528
void on_console_command(class ConsoleCommand *ev)
Definition: MapInstance.cpp:1023
void on_switch_viewpoint(class SwitchViewPoint *ev)
Definition: MapInstance.cpp:1745
Definition: LocationVisited.h:15
Definition: MapEvents.h:541
void on_name_clash_check_result(WouldNameDuplicateResponse *ev)
Definition: MapInstance.cpp:424
void on_enter_door(class EnterDoor *ev)
Definition: MapInstance.cpp:1671
Definition: ChatDividerMoved.h:14
Definition: InputState.h:12
void on_link_lost(SEGSEvent *ev)
Definition: MapInstance.cpp:388
Definition: MapEvents.h:449
Definition: MapEvents.h:591
Definition: MapEvents.h:274
Definition: MapEvents.h:83
void on_window_state(class WindowState *ev)
Definition: MapInstance.cpp:729
Definition: MapServerData.h:23
Definition: MapEvents.h:517
Definition: MapInstance.h:35
void on_shortcuts_request(class ShortcutsRequest *ev)
Definition: MapInstance.cpp:366
Definition: MapEvents.h:168
void on_disconnect(class DisconnectRequest *ev)
Definition: MapInstance.cpp:406
SessionStore m_session_store
Definition: MapInstance.h:50
Definition: CRUD_Events.h:84
Definition: MapEvents.h:257
ScriptEnginePtr m_scripting_interface
Definition: MapInstance.h:52
void on_inspiration_dockmode(class InspirationDockMode *ev)
Definition: MapInstance.cpp:1662
Definition: MapEvents.h:119
EntityManager m_entities
Definition: MapInstance.h:51
Definition: MapEvents.h:153
void on_client_resumed(class ClientResumedRendering *ev)
Definition: MapInstance.cpp:1626
void on_remove_keybind(class RemoveKeybind *ev)
Definition: MapInstance.cpp:1839
void on_entity_response(GetEntityResponse *ev)
Definition: MapInstance.cpp:503
void on_reset_keybinds(class ResetKeybinds *ev)
Definition: MapInstance.cpp:1853
void on_description_and_battlecry(class DescriptionAndBattleCry *ev)
Definition: MapInstance.cpp:1705
void on_client_disconnected_from_other_server(ClientDisconnectedMessage *ev)
Definition: MapInstance.cpp:182
void dispatch(SEGSEvent *ev) override
Definition: MapInstance.cpp:212
void sendState()
Definition: MapInstance.cpp:631
const QString & name() const
Definition: MapInstance.h:63
void on_emote_command(const QString &command, Entity *ent)
Definition: MapInstance.cpp:1048
Definition: Entity.h:221
void on_cookie_confirm(class CookieRequest *ev)
Definition: MapInstance.cpp:724
Definition: MapEvents.h:55
void on_set_keybind(class SetKeybind *ev)
Definition: MapInstance.cpp:1826
bool spin_up_for(uint8_t game_server_id, uint32_t owner_id, uint32_t instance_id)
This function should prepare the map for use by the specified game server.
Definition: MapInstance.cpp:138
void on_set_default_power(class SetDefaultPower *ev)
Definition: MapInstance.cpp:1770
Definition: ServerEndpoint.h:79
Definition: MapEvents.h:185
Definition: MapEvents.h:299
void reap_stale_links()
Definition: MapInstance.cpp:193
Definition: MapEvents.h:499
Definition: MapEvents.h:346
void on_unqueue_all(class UnqueueAll *ev)
Definition: MapInstance.cpp:1775
Definition: SaveClientOptions.h:12
Definition: MapEvents.h:384
Definition: MapServer.h:24
Definition: MapEvents.h:606
void on_plaque_visited(class PlaqueVisited *ev)
Definition: MapInstance.cpp:1653
const MapServerData & serverData() const
Definition: MapInstance.cpp:1848
Definition: MapEvents.h:322
void on_powers_dockmode(class PowersDockMode *ev)
Definition: MapInstance.cpp:1803
void on_scene_request(class SceneRequest *ev)
Definition: MapInstance.cpp:573
void on_client_connected_to_other_server(ClientConnectedMessage *ev)
Definition: MapInstance.cpp:160
void on_entities_request(class EntitiesRequest *ev)
Definition: MapInstance.cpp:596
void on_abort_queued_power(class AbortQueuedPower *ev)
Definition: MapInstance.cpp:1700
uint32_t index() const
Definition: MapInstance.h:64
void spin_down()
This function should stop the world simulation, and save all entities to db It is meant to be ran whe...
Definition: MapInstance.cpp:128
void on_set_destination(class SetDestination *ev)
Definition: MapInstance.cpp:1693
Definition: EventProcessor.h:13
void on_select_keybind_profile(class SelectKeybindProfile *ev)
Definition: MapInstance.cpp:1864
void on_set_default_power_send(class SetDefaultPowerSend *ev)
Definition: MapInstance.cpp:1765
void on_activate_inspiration(class ActivateInspiration *ev)
Definition: MapInstance.cpp:1797
Definition: MapEvents.h:431
void on_location_visited(class LocationVisited *ev)
Definition: MapInstance.cpp:1642
void on_expect_client(ExpectMapClientRequest *ev)
Definition: MapInstance.cpp:442
void on_command_chat_divider_moved(class ChatDividerMoved *ev)
Definition: MapInstance.cpp:1608
Definition: MapEvents.h:481
Definition: MapEvents.h:69
Definition: MapInstance.cpp:76
void on_minimap_state(class MiniMapState *ev)
Definition: MapInstance.cpp:1617
Definition: CRUD_Events.h:54
Definition: WindowState.h:12
void on_entity_info_request(class EntityInfoRequest *ev)
Definition: MapInstance.cpp:1716
Definition: SEGSEvent.h:69
Definition: MapEvents.h:366
MapInstance(const QString &name, const ListenAndLocationAddresses &listen_addr)
this value is sent to the clients
Definition: MapInstance.cpp:89
void enqueue_client(MapClientSession *clnt)
Definition: MapInstance.cpp:205
void start()
Definition: MapInstance.cpp:98
Definition: CRUD_Events.h:114
void on_client_options(class SaveClientOptions *ev)
Definition: MapInstance.cpp:1734
Definition: MapEvents.h:571