@@ -28,27 +28,37 @@ public class IPModule : Fougerite.Module {
2828 public delegate void ConsoleHandlerDelegate ( ref ConsoleSystem . Arg arg , bool external ) ;
2929
3030 public static void ConsoleReceived ( ref ConsoleSystem . Arg arg , bool external ) {
31- string clss = arg . Class . ToLower ( ) ;
32- string func = arg . Function . ToLower ( ) ;
33- if ( ! external ) {
34- Fougerite . Player player = Fougerite . Player . FindByPlayerClient ( arg . argUser . playerClient ) ;
35- if ( player . Admin ) {
36- if ( ( clss == "ipm" || clss == "python" ) && ( func == "reload" ) ) {
37- IPModule . GetInstance ( ) . ReloadPlugins ( ) ;
38- arg . ReplyWith ( "Python Reloaded!" ) ;
39- Logger . LogDebug ( "[IPModule] " + player . Name + " executed: " + clss + ".reload" ) ;
40- return ;
41- } else if ( clss == "python" && func == "load" ) {
42- IPModule . GetInstance ( ) . LoadPlugin ( arg . ArgsStr ) ;
43- arg . ReplyWith ( "Python.load plugin executed!" ) ;
44- Logger . LogDebug ( "[IPModule] " + player . Name + " executed: " + clss + ".load " + arg . ArgsStr ) ;
45- return ;
46- } else if ( clss == "python" && func == "unload" ) {
47- IPModule . GetInstance ( ) . UnloadPlugin ( arg . ArgsStr ) ;
48- arg . ReplyWith ( "Python.unload plugin executed!" ) ;
49- Logger . LogDebug ( "[IPModule] " + player . Name + " executed: " + clss + ".unload " + arg . ArgsStr ) ;
50- return ;
51- }
31+ string clss = arg . Class . ToLower ( ) ;
32+ string func = arg . Function . ToLower ( ) ;
33+ string name = "RCON_External" ;
34+ bool adminRights = external ;
35+ if ( ! external ) {
36+ Fougerite . Player player = Fougerite . Player . FindByPlayerClient ( arg . argUser . playerClient ) ;
37+ if ( player . Admin )
38+ adminRights = true ;
39+ name = player . Name ;
40+ }
41+ if ( adminRights ) {
42+ if ( ( clss == "ipm" || clss == "python" ) && func == "reload" && arg . ArgsStr == "" ) {
43+ IPModule . GetInstance ( ) . ReloadPlugins ( ) ;
44+ arg . ReplyWith ( "Python Reloaded!" ) ;
45+ Logger . LogDebug ( "[IPModule] " + name + " executed: python.reload" ) ;
46+ return ;
47+ } else if ( clss == "python" && func == "load" ) {
48+ IPModule . GetInstance ( ) . LoadPlugin ( arg . ArgsStr ) ;
49+ arg . ReplyWith ( "Python.load plugin executed!" ) ;
50+ Logger . LogDebug ( "[IPModule] " + name + " executed: python.load " + arg . ArgsStr ) ;
51+ return ;
52+ } else if ( clss == "python" && func == "unload" ) {
53+ IPModule . GetInstance ( ) . UnloadPlugin ( arg . ArgsStr ) ;
54+ arg . ReplyWith ( "Python.unload plugin executed!" ) ;
55+ Logger . LogDebug ( "[IPModule] " + name + " executed: python.unload " + arg . ArgsStr ) ;
56+ return ;
57+ } else if ( clss == "python" && func == "reload" ) {
58+ IPModule . GetInstance ( ) . ReloadPlugin ( arg . ArgsStr ) ;
59+ arg . ReplyWith ( "Python.reload plugin executed!" ) ;
60+ Logger . LogDebug ( "[IPModule] " + name + " executed: python.reload " + arg . ArgsStr ) ;
61+ return ;
5262 }
5363 }
5464
@@ -89,18 +99,17 @@ public override void Initialize() {
8999 pluginDirectory = new DirectoryInfo ( ModuleFolder ) ;
90100 plugins = new Dictionary < string , IPPlugin > ( ) ;
91101 ReloadPlugins ( ) ;
92- Hooks . OnEntityHurt -= new Hooks . EntityHurtDelegate ( EntityHurt ) ;
93- Hooks . OnEntityHurt += new Hooks . EntityHurtDelegate ( EntityHurt ) ;
94- Hooks . OnConsoleReceived -= new Hooks . ConsoleHandlerDelegate ( ConsoleReceived ) ;
95- Hooks . OnConsoleReceived += new Hooks . ConsoleHandlerDelegate ( ConsoleReceived ) ;
96- if ( instance == null ) {
102+ Hooks . OnEntityHurt -= new Hooks . EntityHurtDelegate ( EntityHurt ) ;
103+ Hooks . OnEntityHurt += new Hooks . EntityHurtDelegate ( EntityHurt ) ;
104+ Hooks . OnConsoleReceived -= new Hooks . ConsoleHandlerDelegate ( ConsoleReceived ) ;
105+ Hooks . OnConsoleReceived += new Hooks . ConsoleHandlerDelegate ( ConsoleReceived ) ;
106+ if ( instance == null )
97107 instance = this ;
98- }
99108 }
100109
101110 public override void DeInitialize ( ) {
102111 UnloadPlugins ( ) ;
103- Hooks . OnEntityHurt -= new Hooks . EntityHurtDelegate ( EntityHurt ) ;
112+ Hooks . OnEntityHurt -= new Hooks . EntityHurtDelegate ( EntityHurt ) ;
104113 }
105114
106115 public static IPModule GetInstance ( ) {
@@ -176,8 +185,8 @@ public void LoadPlugin(string name) {
176185 public void UnloadPlugin ( string name , bool removeFromDict = true ) {
177186 Logger . LogDebug ( "[IPModule] Unloading " + name + " plugin." ) ;
178187
179- if ( plugins . ContainsKey ( name ) ) {
180- IPPlugin plugin = plugins [ name ] ;
188+ if ( plugins . ContainsKey ( name ) ) {
189+ IPPlugin plugin = plugins [ name ] ;
181190
182191 plugin . KillTimers ( ) ;
183192 RemoveHooks ( plugin ) ;
@@ -195,6 +204,11 @@ public void ReloadPlugin(IPPlugin plugin) {
195204 LoadPlugin ( plugin . Name ) ;
196205 }
197206
207+ public void ReloadPlugin ( string name ) {
208+ UnloadPlugin ( name ) ;
209+ LoadPlugin ( name ) ;
210+ }
211+
198212 #endregion
199213
200214 #region install/remove hooks
@@ -205,7 +219,7 @@ private void InstallHooks(IPPlugin plugin) {
205219 continue ;
206220
207221 Logger . LogDebug ( "Found function: " + method ) ;
208- switch ( method ) {
222+ switch ( method ) {
209223 case "On_ServerInit" : Hooks . OnServerInit += new Hooks . ServerInitDelegate ( plugin . OnServerInit ) ; break ;
210224 case "On_ServerShutdown" : Hooks . OnServerShutdown += new Hooks . ServerShutdownDelegate ( plugin . OnServerShutdown ) ; break ;
211225 case "On_ItemsLoaded" : Hooks . OnItemsLoaded += new Hooks . ItemsDatablocksLoaded ( plugin . OnItemsLoaded ) ; break ;
@@ -240,7 +254,7 @@ private void RemoveHooks(IPPlugin plugin) {
240254 continue ;
241255
242256 Logger . LogDebug ( "Removing function: " + method ) ;
243- switch ( method ) {
257+ switch ( method ) {
244258 case "On_ServerInit" : Hooks . OnServerInit -= new Hooks . ServerInitDelegate ( plugin . OnServerInit ) ; break ;
245259 case "On_ServerShutdown" : Hooks . OnServerShutdown -= new Hooks . ServerShutdownDelegate ( plugin . OnServerShutdown ) ; break ;
246260 case "On_ItemsLoaded" : Hooks . OnItemsLoaded -= new Hooks . ItemsDatablocksLoaded ( plugin . OnItemsLoaded ) ; break ;
0 commit comments