Need help on sending an rcon command to a Call of Duty server
6 replies, posted
Hello, I have become very interested in network programming and have a cool idea for my clan but I am a little confused as to how to it. Basically I would like to obtain info from a website and send this data to the server via rcon. Fetching the html data is cake but I'm stumped on sending an rcon command...
I would really appreciate it if anyone can help. I have been googling for a while now so I might have missed it.
Woops forgot to mention I am doing this in c#.
Closest thing I could find, [url]http://github.com/aiusepsi/SourceRcon/tree/master[/url] But that only works with source's specific implementation of the rcon protocol..
Thanks.
Searching for "CoD rcon protocol" is yay easy, but I believe the network layer is right off Quake 3's, according to [url]http://icculus.org/pipermail/cod/2008-July/011106.html[/url].
I got a C# app working with (COD4) rcon, but it was a right pain sorting out the receiving end - sometimes you get duplicate packets, sometimes nothing comes through, sometimes it's corrupted and you have no way of knowing...anyway, not sure if I still have the app. I'll have a look.
[QUOTE=NovembrDobby;16225369]I got a C# app working with (COD4) rcon, but it was a right pain sorting out the receiving end - sometimes you get duplicate packets, sometimes nothing comes through, sometimes it's corrupted and you have no way of knowing...anyway, not sure if I still have the app. I'll have a look.[/QUOTE]
Cool, should be useful.
[QUOTE=NovembrDobby;16225369]I got a C# app working with (COD4) rcon, but it was a right pain sorting out the receiving end - sometimes you get duplicate packets, sometimes nothing comes through, sometimes it's corrupted and you have no way of knowing...anyway, not sure if I still have the app. I'll have a look.[/QUOTE]
It's the magic of UDP :downs:
The receive side of things, threaded and looping (and naturally, inefficient as hell):
[code]
public void Recieve() //remember to end the thread when you quit
{
while (true)
{
Thread.Sleep(1);
int avail = client.Available;
if (avail > 0)
{
byte[] receiveBuffer = new byte[avail];
client.Receive(receiveBuffer, avail, SocketFlags.None);
string toadd = System.Text.Encoding.UTF8.GetString(receiveBuffer);
if(toadd.IndexOf("print") == 4)
toadd = toadd.Substring(10);
data += toadd; //data is a global string
}
}
}
[/code]
Sending:
[code]
byte[] actualCommand = System.Text.Encoding.ASCII.GetBytes(
"rcon " + "password" + " " + "commands");
//e.g: rcon 1234 status
byte[] bufferSend = new byte[actualCommand.Length + 5];
bufferSend[0] = byte.Parse("255");
bufferSend[1] = byte.Parse("255");
bufferSend[2] = byte.Parse("255");
bufferSend[3] = byte.Parse("255");
bufferSend[4] = byte.Parse("02");
int j = 5;
for (int i = 0; i < actualCommand.Length; i++)
{
bufferSend[j] = actualCommand[i];
j++;
}
try
{
client.Connect("192.168.1.1", 28960);
client.Send(bufferSend, bufferSend.Length, SocketFlags.None);
}
catch (SocketException)
{
//stuff
}
catch (InvalidOperationException)
{
//stuff
}
Thread.Sleep(700); //the receiving thread time to get data
[/code]
[QUOTE=NovembrDobby;16238606]The receive side of things, threaded and looping (and naturally, inefficient as hell):
[code]
public void Recieve() //remember to end the thread when you quit
{
while (true)
{
Thread.Sleep(1);
int avail = client.Available;
if (avail > 0)
{
byte[] receiveBuffer = new byte[avail];
client.Receive(receiveBuffer, avail, SocketFlags.None);
string toadd = System.Text.Encoding.UTF8.GetString(receiveBuffer);
if(toadd.IndexOf("print") == 4)
toadd = toadd.Substring(10);
data += toadd; //data is a global string
}
}
}
[/code]
Sending:
[code]
byte[] actualCommand = System.Text.Encoding.ASCII.GetBytes(
"rcon " + "password" + " " + "commands");
//e.g: rcon 1234 status
byte[] bufferSend = new byte[actualCommand.Length + 5];
bufferSend[0] = byte.Parse("255");
bufferSend[1] = byte.Parse("255");
bufferSend[2] = byte.Parse("255");
bufferSend[3] = byte.Parse("255");
bufferSend[4] = byte.Parse("02");
int j = 5;
for (int i = 0; i < actualCommand.Length; i++)
{
bufferSend[j] = actualCommand[i];
j++;
}
try
{
client.Connect("192.168.1.1", 28960);
client.Send(bufferSend, bufferSend.Length, SocketFlags.None);
}
catch (SocketException)
{
//stuff
}
catch (InvalidOperationException)
{
//stuff
}
Thread.Sleep(700); //the receiving thread time to get data
[/code][/QUOTE]
Ah, exactly what I need! Thank you so much!
Sorry, you need to Log In to post a reply to this thread.