using System; using System.Text; namespace SAMP.API { public class Server { #region Class Variables // Nothing to see here #endregion #region Events, Delegates and Method Calls #region OnRconCommand public delegate void OnRconCommandHandler(object sender, System.EventArgs e); public static event OnRconCommandHandler OnRconCommand; internal static int _OnRconCommand(string cmd) { EventData.RconCommandEventArgs args = new EventData.RconCommandEventArgs(cmd); try { OnRconCommand(null, args); } catch { } return args.Handled ? 1 : 0; } #endregion #endregion #region Accessors & Mutators /// /// Gets the number of currently connected players. /// public static int PlayerCount { get { return Player.playerStore.Count; } } /// /// Gets the maximum allowed players to connect. /// public static int MaxPlayers { get { return Core.Natives.GetMaxPlayers(); } } #endregion #region Public Methods /// /// Sends an RCON command. /// /// The RCON command to be executed. public static void Rcon(string command) { Core.Natives.SendRconCommand(command); } /// /// Retrieve a server variable of the specified type. /// /// The type of variable to search for and return. Valid types are System.String, System.Int32 and System.Boolean. /// The name of the variable to retrieve. /// Returns a variable of type T containing the server variable value. public static T Var(string varname) { if(typeof(T).Equals(typeof(string))) { StringBuilder sb = new StringBuilder(1024); Core.Natives.GetServerVarAsString(varname, sb, sb.Capacity); return (T)Convert.ChangeType(sb.ToString(), typeof(T)); } else if(typeof(T).Equals(typeof(int))) { int buffer = Core.Natives.GetServerVarAsInt(varname); return (T)Convert.ChangeType(buffer, typeof(T)); } else if(typeof(T).Equals(typeof(bool))) { bool buffer = Core.Natives.GetServerVarAsInt(varname) == 1; return (T)Convert.ChangeType(buffer, typeof(T)); } else return default(T); } #endregion }; };