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,EventData.RconCommandEventArgs e);
///
/// Occurs when an RCON command is received.
///
public static event OnRconCommandHandler OnRconCommand;
internal static int _OnRconCommand(string cmd) {
EventData.RconCommandEventArgs args = new EventData.RconCommandEventArgs(cmd);
if(OnRconCommand != null)
OnRconCommand(null, args);
return args.Handled ? 1 : 0;
}
#endregion
#region OnRconLoginAttempt
public delegate void OnRconLoginAttemptHandler(object sender,EventData.RconLoginAttemptEventArgs e);
///
/// Occurs when a play attempts to login to RCON.
///
public static event OnRconLoginAttemptHandler OnRconLoginAttempt;
internal static void _OnRconLoginAttempt(string ip, string password, int success) {
EventData.RconLoginAttemptEventArgs args = new EventData.RconLoginAttemptEventArgs(ip, password, success == 1);
if(OnRconLoginAttempt != null)
OnRconLoginAttempt(null, args);
args = null;
}
#endregion
#endregion
#region Accessors & Mutators
///
/// Gets the number of currently connected players.
///
public static int PlayerCount {
get { return Player.s_qStore.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 name of the variable to retrieve.
/// The type of variable to search for and return. Valid types are , and .
/// Returns a variable of type T containing the value of the server variable with the name varname.
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
};
};