Mania++
 All Classes Functions Variables Pages
Plugin.h
1 #ifndef PLUGIN_H_
2 #define PLUGIN_H_
3 
4 #include <stdio.h>
5 #include <cstring>
6 #include <string>
7 #include <map>
8 #include <iostream>
9 #include <sstream>
10 #include <cstdlib>
11 #include <functional>
12 
13 #include <cppconn/driver.h>
14 #include <cppconn/exception.h>
15 #include <cppconn/resultset.h>
16 #include <cppconn/statement.h>
17 #include <cppconn/prepared_statement.h>
18 
19 #include "../Events/Structs.h"
20 #include "../Maps/MapList.h"
21 #include "../Methods/Methods.h"
22 #include "../Objects/Player.h"
23 #include "../Objects/Map.h"
24 #include "../UI/UIManager.h"
25 #include "../Utils/Logging.h"
26 
27 //* Controller
31 struct Controller
32 {
34  std::map<std::string, Player>* Players;
36  sql::Connection* Database;
38 };
39 
40 //* Plugin
44 class Plugin
45 {
46 public:
50  virtual void Init() = 0;
51 
57  void SetController(Controller* controllerPtr)
58  {
59  controller = controllerPtr;
60  }
61 
62  std::map<std::string, std::string> Settings;
64  std::vector<std::function<void(Player)>> PlayerConnect;
65  std::vector<std::function<void(Player)>> PlayerDisconnect;
66  std::vector<std::function<void(Player, std::string)>> PlayerChat;
67  std::vector<std::function<void(std::string, std::string)>> Echo;
68  std::vector<std::function<void()>> BeginMatch;
69  std::vector<std::function<void(std::vector<PlayerRanking>, int)>> EndMatch;
70  std::vector<std::function<void(Map)>> BeginMap;
71  std::vector<std::function<void(Map)>> EndMap;
72  std::vector<std::function<void(int, std::string)>> StatusChanged;
73  std::vector<std::function<void(Player, int, int, int)>> PlayerCheckpoint;
74  std::vector<std::function<void(Player, int)>> PlayerFinish;
75  std::vector<std::function<void(Player)>> PlayerIncoherence;
76  std::vector<std::function<void(int, int, std::string, int)>> BillUpdated;
77  std::vector<std::function<void(int, int, bool)>> MapListModified;
78  std::vector<std::function<void(Player)>> PlayerInfoChanged;
79  std::vector<std::function<void(std::string, std::string, std::string, std::string)>> VoteUpdated;
81  std::map<std::string, std::function<void(Player, std::vector<std::string>)>> Commands =
82  std::map<std::string, std::function<void(Player, std::vector<std::string>)>>();
83  std::map<std::string, std::function<void(Player, std::vector<std::string>)>> AdminCommands =
84  std::map<std::string, std::function<void(Player, std::vector<std::string>)>>();
86  std::string Version;
87  std::string Author;
89 protected:
98  void RegisterCommand(std::string name, std::function<void(Player, std::vector<std::string>)> method)
99  {
100  Commands.insert(std::pair<std::string, std::function<void(Player, std::vector<std::string>)>>(name, method));
101  }
102 
109  void RegisterAdminCommand(std::string name, std::function<void(Player, std::vector<std::string>)> method)
110  {
111  AdminCommands.insert(std::pair<std::string, std::function<void(Player, std::vector<std::string>)>>(name, method));
112  }
113 };
114 
115 #endif // PLUGIN_H_
std::map< std::string, std::string > Settings
Plugin settings (from the config file).
Definition: Plugin.h:62
void RegisterCommand(std::string name, std::function< void(Player, std::vector< std::string >)> method)
Register chat command.
Definition: Plugin.h:98
std::vector< std::function< void(int, std::string)> > StatusChanged
Vector with functions for the StatusChanged event.
Definition: Plugin.h:72
std::vector< std::function< void(Player)> > PlayerDisconnect
Vector with functions for the PlayerDisconnect event.
Definition: Plugin.h:65
Controller * controller
Struct with needed instances.
Definition: Plugin.h:90
std::vector< std::function< void(std::string, std::string, std::string, std::string)> > VoteUpdated
Vector with functions for the VoteUpdated event.
Definition: Plugin.h:79
UIManager * UI
UI manager instance.
Definition: Plugin.h:37
std::string Author
Plugin author.
Definition: Plugin.h:87
Manages the user interface on the server (ManiaLinks).
Definition: UIManager.h:17
Contains all information about a player in easy-to-use format.
Definition: Player.h:10
std::map< std::string, std::function< void(Player, std::vector< std::string >)> > AdminCommands
Map with admin chat commands for the plugin.
Definition: Plugin.h:83
std::map< std::string, Player > * Players
Playerlist instance.
Definition: Plugin.h:34
std::vector< std::function< void(Player, int, int, int)> > PlayerCheckpoint
Vector with functions for the PlayerCheckpoint event.
Definition: Plugin.h:73
std::string Version
Plugin version.
Definition: Plugin.h:86
std::vector< std::function< void(std::string, std::string)> > Echo
Vector with functions for the Echo event.
Definition: Plugin.h:67
Methods * Server
Methods instance.
Definition: Plugin.h:33
Plugin interface, inherited by all plugins.
Definition: Plugin.h:44
Contains the maplist and a pointer to the current map.
Definition: MapList.h:10
std::vector< std::function< void(Player)> > PlayerInfoChanged
Vector with functions for the PlayerInfoChanged event.
Definition: Plugin.h:78
std::vector< std::function< void(std::vector< PlayerRanking >, int)> > EndMatch
Vector with functions for the EndMatch event.
Definition: Plugin.h:69
Contains all server methods and returns usable data types.
Definition: Methods.h:14
std::vector< std::function< void()> > BeginMatch
Vector with functions for the BeginMatch event.
Definition: Plugin.h:68
Struct with all instances needed for plugins.
Definition: Plugin.h:31
MapList * Maps
Maplist instance.
Definition: Plugin.h:35
virtual void Init()=0
Initializes plugin (called after loading all plugins).
std::vector< std::function< void(Player, std::string)> > PlayerChat
Vector with functions for the PlayerChat event.
Definition: Plugin.h:66
void SetController(Controller *controllerPtr)
Sets the controller instance.
Definition: Plugin.h:57
std::vector< std::function< void(int, int, std::string, int)> > BillUpdated
Vector with functions for the BillUpdated event.
Definition: Plugin.h:76
std::map< std::string, std::function< void(Player, std::vector< std::string >)> > Commands
Map with normal chat commands for the plugin.
Definition: Plugin.h:81
std::vector< std::function< void(Player, int)> > PlayerFinish
Vector with functions for the PlayerFinish event.
Definition: Plugin.h:74
void RegisterAdminCommand(std::string name, std::function< void(Player, std::vector< std::string >)> method)
Register admin chat command.
Definition: Plugin.h:109
std::vector< std::function< void(Player)> > PlayerIncoherence
Vector with functions for the PlayerIncoherence event.
Definition: Plugin.h:75
sql::Connection * Database
Database instance.
Definition: Plugin.h:36
std::vector< std::function< void(Player)> > PlayerConnect
Vector with functions for the PlayerConnect event.
Definition: Plugin.h:64
std::vector< std::function< void(Map)> > BeginMap
Vector with functions for the BeginMap event.
Definition: Plugin.h:70
std::vector< std::function< void(Map)> > EndMap
Vector with functions for the EndMap event.
Definition: Plugin.h:71
std::vector< std::function< void(int, int, bool)> > MapListModified
Vector with functions for the MapListModified event.
Definition: Plugin.h:77