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 #include <boost/any.hpp>
13 
14 #include <cppconn/driver.h>
15 #include <cppconn/exception.h>
16 #include <cppconn/resultset.h>
17 #include <cppconn/statement.h>
18 #include <cppconn/prepared_statement.h>
19 
20 #include "../Commands/ChatCommand.h"
21 #include "../Events/Structs.h"
22 #include "../Maps/MapList.h"
23 #include "../Methods/Methods.h"
24 #include "../Objects/Player.h"
25 #include "../Objects/Map.h"
26 #include "../UI/UIManager.h"
27 #include "../Utils/Logging.h"
28 
29 #include "PluginHandler.h"
30 
31 //* Controller
35 struct Controller
36 {
38  std::map<std::string, Player>* Players;
40  sql::Connection* Database;
44 };
45 
46 //* Plugin
50 class Plugin
51 {
52 public:
56  virtual void Init() = 0;
57 
63  void SetController(Controller* controllerPtr)
64  {
65  controller = controllerPtr;
66  }
67 
68  std::map<std::string, std::string> Settings;
70  std::vector<std::function<void()>> EverySecond;
71  std::vector<std::function<void()>> EveryMinute;
72  std::vector<std::function<void(Player)>> PlayerConnect;
73  std::vector<std::function<void(Player)>> PlayerDisconnect;
74  std::vector<std::function<void(Player, std::string)>> PlayerChat;
75  std::vector<std::function<void(std::string, std::string)>> Echo;
76  std::vector<std::function<void()>> BeginMatch;
77  std::vector<std::function<void(std::vector<PlayerRanking>, int)>> EndMatch;
78  std::vector<std::function<void(Map)>> BeginMap;
79  std::vector<std::function<void(Map)>> EndMap;
80  std::vector<std::function<void(int, std::string)>> StatusChanged;
81  std::vector<std::function<void(Player, int, int, int)>> PlayerCheckpoint;
82  std::vector<std::function<void(Player, int)>> PlayerFinish;
83  std::vector<std::function<void(Player)>> PlayerIncoherence;
84  std::vector<std::function<void(int, int, std::string, int)>> BillUpdated;
85  std::vector<std::function<void(int, int, bool)>> MapListModified;
86  std::vector<std::function<void(Player)>> PlayerInfoChanged;
87  std::vector<std::function<void(std::string, std::string, std::string, std::string)>> VoteUpdated;
89  std::map<std::string, ChatCommand> Commands;
90  std::map<std::string, ChatCommand> AdminCommands;
91  std::map<std::string, std::function<boost::any(boost::any)>> Methods;
93  std::string Version;
94  std::string Author;
95  std::string Description;
97 protected:
107  void RegisterCommand(std::string name, std::string description, std::function<void(Player, std::vector<std::string>)> method)
108  {
109  ChatCommand command = ChatCommand();
110  command.PluginVersion = Version;
111  command.PluginAuthor = Author;
112  command.Command = name;
113  command.Description = description;
114  command.Method = method;
115  Commands.insert(std::pair<std::string, ChatCommand>(name, command));
116  }
117 
126  void RegisterAdminCommand(std::string name, std::string description, Permission access, std::function<void(Player, std::vector<std::string>)> method)
127  {
128  ChatCommand command = ChatCommand();
129  command.PluginVersion = Version;
130  command.PluginAuthor = Author;
131  command.Command = name;
132  command.Description = description;
133  command.Access = access;
134  command.Method = method;
135  AdminCommands.insert(std::pair<std::string, ChatCommand>(name, command));
136  }
137 
144  void RegisterCallableMethod(std::string name, std::function<boost::any(boost::any)> method)
145  {
146  Methods.insert(std::pair<std::string, std::function<boost::any(boost::any)>>(name, method));
147  }
148 };
149 
150 #endif // PLUGIN_H_
std::vector< std::function< void()> > EverySecond
Vector with functions for the EverySecond event.
Definition: Plugin.h:70
std::map< std::string, std::string > Settings
Plugin settings (from the config file).
Definition: Plugin.h:68
ServerInfo * Info
Server information instance.
Definition: Plugin.h:43
std::vector< std::function< void(int, std::string)> > StatusChanged
Vector with functions for the StatusChanged event.
Definition: Plugin.h:80
std::vector< std::function< void(Player)> > PlayerDisconnect
Vector with functions for the PlayerDisconnect event.
Definition: Plugin.h:73
Controller * controller
Struct with needed instances.
Definition: Plugin.h:98
std::vector< std::function< void(std::string, std::string, std::string, std::string)> > VoteUpdated
Vector with functions for the VoteUpdated event.
Definition: Plugin.h:87
UIManager * UI
UI manager instance.
Definition: Plugin.h:41
std::string PluginVersion
Version of the plugin the command belongs to.
Definition: ChatCommand.h:14
std::string Author
Plugin author.
Definition: Plugin.h:94
Manages the user interface on the server (ManiaLinks).
Definition: UIManager.h:17
std::map< std::string, ChatCommand > AdminCommands
Map with admin chat commands for the plugin.
Definition: Plugin.h:90
PluginHandler * Plugins
Plugin handler instance.
Definition: Plugin.h:42
std::string Description
Chat command description.
Definition: ChatCommand.h:18
Contains all information about a player in easy-to-use format.
Definition: Player.h:11
std::function< void(Player, std::vector< std::string >)> Method
Chat command method.
Definition: ChatCommand.h:20
std::map< std::string, Player > * Players
Playerlist instance.
Definition: Plugin.h:38
std::vector< std::function< void(Player, int, int, int)> > PlayerCheckpoint
Vector with functions for the PlayerCheckpoint event.
Definition: Plugin.h:81
std::string Version
Plugin version.
Definition: Plugin.h:93
std::vector< std::function< void(std::string, std::string)> > Echo
Vector with functions for the Echo event.
Definition: Plugin.h:75
Methods * Server
Methods instance.
Definition: Plugin.h:37
Plugin interface, inherited by all plugins.
Definition: Plugin.h:50
std::vector< std::function< void()> > EveryMinute
Vector with functions for the EveryMinute event.
Definition: Plugin.h:71
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:86
std::vector< std::function< void(std::vector< PlayerRanking >, int)> > EndMatch
Vector with functions for the EndMatch event.
Definition: Plugin.h:77
Permission Access
Command access level.
Definition: ChatCommand.h:19
Contains all server methods and returns usable data types.
Definition: Methods.h:15
Definition: PluginHandler.h:27
std::vector< std::function< void()> > BeginMatch
Vector with functions for the BeginMatch event.
Definition: Plugin.h:76
Stuct containing information about a chat command.
Definition: ChatCommand.h:11
Struct with all instances needed for plugins.
Definition: Plugin.h:35
MapList * Maps
Maplist instance.
Definition: Plugin.h:39
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:74
std::map< std::string, std::function< boost::any(boost::any)> > Methods
Map with callable methods for the plugin.
Definition: Plugin.h:91
std::string Description
Plugin description.
Definition: Plugin.h:95
void RegisterCallableMethod(std::string name, std::function< boost::any(boost::any)> method)
Register callable method.
Definition: Plugin.h:144
void SetController(Controller *controllerPtr)
Sets the controller instance.
Definition: Plugin.h:63
std::vector< std::function< void(int, int, std::string, int)> > BillUpdated
Vector with functions for the BillUpdated event.
Definition: Plugin.h:84
std::string Command
Chat command.
Definition: ChatCommand.h:17
std::vector< std::function< void(Player, int)> > PlayerFinish
Vector with functions for the PlayerFinish event.
Definition: Plugin.h:82
void RegisterAdminCommand(std::string name, std::string description, Permission access, std::function< void(Player, std::vector< std::string >)> method)
Register admin chat command.
Definition: Plugin.h:126
std::vector< std::function< void(Player)> > PlayerIncoherence
Vector with functions for the PlayerIncoherence event.
Definition: Plugin.h:83
sql::Connection * Database
Database instance.
Definition: Plugin.h:40
std::vector< std::function< void(Player)> > PlayerConnect
Vector with functions for the PlayerConnect event.
Definition: Plugin.h:72
void RegisterCommand(std::string name, std::string description, std::function< void(Player, std::vector< std::string >)> method)
Register chat command.
Definition: Plugin.h:107
std::vector< std::function< void(Map)> > BeginMap
Vector with functions for the BeginMap event.
Definition: Plugin.h:78
std::string PluginAuthor
Author of the plugin the command belongs to.
Definition: ChatCommand.h:15
std::vector< std::function< void(Map)> > EndMap
Vector with functions for the EndMap event.
Definition: Plugin.h:79
std::vector< std::function< void(int, int, bool)> > MapListModified
Vector with functions for the MapListModified event.
Definition: Plugin.h:85
std::map< std::string, ChatCommand > Commands
Map with normal chat commands for the plugin.
Definition: Plugin.h:89
Struct with server information.
Definition: Structs.h:41