CGC_Codes

SPPT AH

Jul 3rd, 2017
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.30 KB | None | 0 0
  1. using System;
  2. using System.ComponentModel;
  3. using System.IO;
  4. using System.Reflection;
  5. using System.Runtime.InteropServices;
  6. using SPPT.NetworkHandlers;
  7. using SPPT.Settings;
  8. using NLog;
  9. using SEModAPIExtensions.API.Plugin;
  10. using SEModAPIInternal.API.Server;
  11.  
  12. namespace SPPT
  13. {
  14.     public class SPPT : IPlugin
  15.     {
  16.         public static Logger Log = LogManager.GetLogger("PluginLog");
  17.         internal static SPPT Instance;
  18.  
  19.         public static string PluginPath { get; set; }
  20.  
  21.         #region Public Properties
  22.  
  23.         [Browsable(true)]
  24.         [ReadOnly(false)]
  25.         [Category("Anti-Hack")]
  26.         [Description("Enables or disables this plugin")]
  27.         public bool Enabled
  28.         {
  29.             get { return PluginSettings.Instance.PluginEnabled; }
  30.             set { PluginSettings.Instance.PluginEnabled = value; }
  31.         }
  32.  
  33.         [Browsable(true)]
  34.         [ReadOnly(false)]
  35.         [Category("Anti-Hack")]
  36.         [Description("SteamIDs of players allowed to delete ships and use space master")]
  37.         public ulong[] AllowedPlayers
  38.         {
  39.             get { return PluginSettings.Instance.AllowedPlayers; }
  40.             set { PluginSettings.Instance.AllowedPlayers = value; }
  41.         }
  42.  
  43.         [Browsable(true)]
  44.         [ReadOnly(false)]
  45.         [Category("SPPT")]
  46.         [Description("The server will automatically kick any players it detects deleting grids when they shouldn't")]
  47.         public bool AutoKick
  48.         {
  49.             get { return PluginSettings.Instance.AutoKick; }
  50.             set { PluginSettings.Instance.AutoKick = value; }
  51.         }
  52.  
  53.         [Browsable(true)]
  54.         [ReadOnly(false)]
  55.         [Category("SPPT")]
  56.         [Description("The server will automatically BAN any players it detects deleting grids when they shouldn't")]
  57.         public bool AutoBan
  58.         {
  59.             get { return PluginSettings.Instance.AutoBan; }
  60.             set { PluginSettings.Instance.AutoBan = value; }
  61.         }
  62.  
  63.         [Browsable(true)]
  64.         [ReadOnly(false)]
  65.         [Category("SPPT")]
  66.         [Description("This message is broadcast to the entire server when a cheater is detected. '%player%' is replaced with the offending player's name")]
  67.         public string Message
  68.         {
  69.             get { return PluginSettings.Instance.PulicMessage; }
  70.             set { PluginSettings.Instance.PulicMessage = value; }
  71.         }
  72.         #endregion
  73.  
  74.         public void Init()
  75.         {
  76.             Log.Debug("Initializing SPPT plugin at path {0}\\", Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));
  77.             DoInit(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\");
  78.         }
  79.  
  80.         public void Update()
  81.         {
  82.         }
  83.  
  84.         public void Shutdown()
  85.         {
  86.         }
  87.  
  88.         public void InitWithPath(string modPath)
  89.         {
  90.             Log.Debug("Initializing SPPT plugin at path {0}\\", Path.GetDirectoryName(modPath));
  91.             DoInit(Path.GetDirectoryName(modPath) + "\\");
  92.         }
  93.  
  94.         private void DoInit(string path)
  95.         {
  96.             Instance = this;
  97.             PluginPath = path;
  98.             PluginSettings.Instance.Load();
  99.  
  100.             ServerNetworkManager.Instance.RegisterNetworkHandlers(new NetworkHandlerBase[]
  101.                                                                   {
  102.                                                                       new EntityCloseHandler(),
  103.                                                                       new RemoveEntityHandler(),
  104.                                                                       new RemoveTrashHandler(),
  105.                                                                   });
  106.  
  107.             Log.Info($"Plugin '{Name}' initialized. (Version: {Version}  ID: {Id})");
  108.         }
  109.  
  110.         #region IPlugin Members
  111.  
  112.         public Guid Id
  113.         {
  114.             get
  115.             {
  116.                 var guidAttr = (GuidAttribute)typeof(SPPT).Assembly.GetCustomAttributes(typeof(GuidAttribute), true)[0];
  117.                 return new Guid(guidAttr.Value);
  118.             }
  119.         }
  120.  
  121.         public string Name
  122.         {
  123.             get { return "SPPT Plugin"; }
  124.         }
  125.  
  126.         public Version Version
  127.         {
  128.             get { return typeof(SPPT).Assembly.GetName().Version; }
  129.         }
  130.  
  131.         #endregion
  132.     }
  133. }
Advertisement
Add Comment
Please, Sign In to add comment