mirror of
https://github.com/RaidMax/IW4M-Admin.git
synced 2025-06-11 15:52:25 -05:00
-close config files after reading oops
-added reload command -added macros! (Denoted by {{MACRO}} in server config right now only {{WISDOM}} and {{TOTALPLAYERS}}) -added IP's (tracks and rebans new accounts on same banned ip)! -aliases -reworked database classes -heartbeat gives running version -player banned in find gives last ban reason -reworked rcon yet again
This commit is contained in:
102
Admin/RCON.cs
102
Admin/RCON.cs
@ -22,52 +22,17 @@ namespace IW4MAdmin
|
||||
sv_connection.Client.SendTimeout = 1000;
|
||||
sv_connection.Client.ReceiveTimeout = 1000;
|
||||
Instance = I;
|
||||
toSend = new Queue<String>();
|
||||
toSend = new Queue<RCON_Request>();
|
||||
}
|
||||
|
||||
//When we don't care about a response
|
||||
public bool sendRCON(String message)
|
||||
{
|
||||
try
|
||||
{
|
||||
String STR_REQUEST = String.Format("ÿÿÿÿrcon {0} {1}", Instance.getPassword(), message);
|
||||
|
||||
Byte[] Request_ = Encoding.Unicode.GetBytes(STR_REQUEST);
|
||||
Byte[] Request = new Byte[Request_.Length / 2];
|
||||
|
||||
int count = 0; //This is kinda hacky but Unicode -> ASCII doesn't seem to be working correctly for this.
|
||||
foreach (Byte b in Request_)
|
||||
{
|
||||
if (b != 0)
|
||||
Request[count / 2] = b;
|
||||
count++;
|
||||
}
|
||||
|
||||
|
||||
System.Net.IPAddress IP = System.Net.IPAddress.Parse(Instance.getIP());
|
||||
IPEndPoint endPoint = new IPEndPoint(IP, Instance.getPort());
|
||||
|
||||
sv_connection.Connect(endPoint);
|
||||
sv_connection.Send(Request, Request.Length);
|
||||
}
|
||||
|
||||
catch (SocketException)
|
||||
{
|
||||
Instance.Log.Write("Unable to reach server for sending RCON", Log.Level.Debug);
|
||||
sv_connection.Close();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
//We want to read the reponse
|
||||
public String[] responseSendRCON(String message)
|
||||
{
|
||||
try
|
||||
{
|
||||
String STR_REQUEST;
|
||||
String STR_REQUEST = String.Empty;
|
||||
if (message != "getstatus")
|
||||
STR_REQUEST = String.Format("ÿÿÿÿrcon {0} {1}", Instance.getPassword().Replace("\r", String.Empty), message);
|
||||
STR_REQUEST = String.Format("ÿÿÿÿrcon {0} {1}", Instance.getPassword(), message);
|
||||
else
|
||||
STR_REQUEST = String.Format("ÿÿÿÿ getstatus");
|
||||
|
||||
@ -88,33 +53,50 @@ namespace IW4MAdmin
|
||||
|
||||
sv_connection.Connect(endPoint);
|
||||
sv_connection.Send(Request, Request.Length);
|
||||
|
||||
|
||||
Byte[] receive = sv_connection.Receive(ref endPoint);
|
||||
int num = int.Parse("0a", System.Globalization.NumberStyles.AllowHexSpecifier);
|
||||
String incoming = String.Empty;
|
||||
byte[] bufferRecv = new byte[65536];
|
||||
do
|
||||
{
|
||||
// loop on receiving the bytes
|
||||
bufferRecv = sv_connection.Receive(ref endPoint);
|
||||
|
||||
String[] response = System.Text.Encoding.UTF8.GetString(receive).Split((char)num);
|
||||
// only decode the bytes received
|
||||
incoming += (Encoding.ASCII.GetString(bufferRecv, 0, bufferRecv.Length));
|
||||
} while (sv_connection.Available > 0);
|
||||
|
||||
int num = int.Parse("0a", System.Globalization.NumberStyles.AllowHexSpecifier);
|
||||
|
||||
String[] response = incoming.Split(new char[] {(char)num} , StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
if(response[1] == "Invalid password.")
|
||||
{
|
||||
Instance.Log.Write("Invalid RCON password specified", Log.Level.Debug);
|
||||
return null;
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
catch (SocketException)
|
||||
{
|
||||
Instance.Log.Write("Unable to reach server for sending RCON", Log.Level.Debug);
|
||||
return null;
|
||||
}
|
||||
|
||||
catch (System.InvalidOperationException)
|
||||
{
|
||||
Instance.Log.Write("RCON Connection terminated by server. Uh-OH", Log.Level.Debug);
|
||||
sv_connection.Close();
|
||||
sv_connection = new UdpClient();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void addRCON(String Message, int delay)
|
||||
public String[] addRCON(String Message)
|
||||
{
|
||||
toSend.Enqueue(Message);
|
||||
RCON_Request newReq = new RCON_Request(Message);
|
||||
toSend.Enqueue(newReq);
|
||||
return newReq.waitForResponse();
|
||||
}
|
||||
|
||||
public void ManageRCONQueue()
|
||||
@ -123,7 +105,8 @@ namespace IW4MAdmin
|
||||
{
|
||||
if (toSend.Count > 0)
|
||||
{
|
||||
sendRCON(toSend.Peek());
|
||||
RCON_Request Current = toSend.Peek();
|
||||
Current.Response = responseSendRCON(Current.Request);
|
||||
toSend.Dequeue();
|
||||
Utilities.Wait(0.567);
|
||||
}
|
||||
@ -134,6 +117,31 @@ namespace IW4MAdmin
|
||||
|
||||
private UdpClient sv_connection;
|
||||
private Server Instance;
|
||||
private Queue<String> toSend;
|
||||
private Queue<RCON_Request> toSend;
|
||||
}
|
||||
|
||||
class RCON_Request
|
||||
{
|
||||
public RCON_Request(String IN)
|
||||
{
|
||||
Request = IN;
|
||||
Response = null;
|
||||
}
|
||||
|
||||
public String[] waitForResponse()
|
||||
{
|
||||
DateTime Start = DateTime.Now;
|
||||
DateTime Current = DateTime.Now;
|
||||
while (Response == null && (Current-Start).TotalMilliseconds < 1000)
|
||||
{
|
||||
Thread.Sleep(1);
|
||||
Current = DateTime.Now;
|
||||
}
|
||||
return Response;
|
||||
}
|
||||
|
||||
public String Request;
|
||||
public String[] Response;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user