Results 1 to 20 of 20

Thread: Cod4 Rcon / Udp Connection

  1. #1

    Thread Starter
    New Member computermat's Avatar
    Join Date
    Apr 2008
    Posts
    9

    Question Cod4 Rcon / Udp Connection

    Hi, I am looking to make my own remote control application for my clans call of duty 4 servers. I am a COD4 Admin, Webmaster and mod developer for WYDGAMING.com and I am wishing to make admining our servers much easier. I have searched the internet and this site and cannot really find an answer to my problem.

    I need to know how to connect to the server console so I can send server commands. I know all commands and things that can be used on the server so i just need to know how to connect to it. I believe from research Call of Duty 4 using a UDP port for connecting to the console via remote application.

    Does anyone know of how I can make the UDP connection or know anyother site where i can find the info to do this.

    Thanks for reading
    Matt

  2. #2
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: Cod4 Rcon / Udp Connection

    Welcome to the forum.
    First of all, what language are you using?
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  3. #3

    Thread Starter
    New Member computermat's Avatar
    Join Date
    Apr 2008
    Posts
    9

    Re: Cod4 Rcon / Udp Connection

    I am using VB.net 2.0 (2005). Didnt mention that in my original post becuase I thought this was a vb.net forum. My bad

  4. #4
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: Cod4 Rcon / Udp Connection

    Dont let the name of this forum fool you, we've got a wide variety of languages on here
    Do you know exactly how these messages to the server should look? Wouldnt you need some sort of authentication?
    Sending the UDP messages is the easy part:

    vb Code:
    1. Dim client As New System.Net.Sockets.Socket(Net.Sockets.AddressFamily.InterNetwork, Net.Sockets.SocketType.Dgram, Net.Sockets.ProtocolType.Udp)
    2.         Dim sendBuffer(1) As Byte
    3.         sendBuffer(0) = 40
    4.         sendBuffer(1) = 23
    5.  
    6.         client.Connect("hostname/IP here", portnumber)
    7.         client.Send(sendBuffer, sendBuffer.Length, Net.Sockets.SocketFlags.None)

    Note that even though the Connect method is called in this piece of code, there is no actuall connection, it will just label the datagrams with this destination IP before sending them on their way. UDP is a connectionless protocoll.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  5. #5

    Thread Starter
    New Member computermat's Avatar
    Join Date
    Apr 2008
    Posts
    9

    Re: Cod4 Rcon / Udp Connection

    Hey, thanks for repling. I will try get that code into my program when I get home. I have found this topic on another website where someone has nearly got the required connection working.

    Code:
    Imports System.Net
    Imports System.Net.Sockets
    Imports System.Text
    Imports System.IO
    
    
    Public Class Form1
        Inherits System.Windows.Forms.Form
    
    ' rconPassword is the password to login for admin control
        Dim sPass As String = "/rcon login rconPassword"
    ' sv_hostname is the variable on the server that has text im trying to receive    
    Dim hostName As String = "sv_hostname"
    
    ' multi-line textbox named txtBox1 for sending the information to, to read
    Private Sub txt(ByVal Text As String)
            txtBox1.AppendText(Text & vbCrLf)
            txtBox1.ScrollToCaret()
        End Sub
    
        Private Sub btnConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConnect.Click
            
            Dim udpClient As New UdpClient(12345)
            Try
                ' Not the real ip address or port number
                udpClient.Connect("123.45.67.89", 12345)
    
                ' Here i try to send the login attempt and hostname request
                Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes(sPass & hostName)
    
    
                udpClient.Send(sendBytes, sendBytes.Length)
    
                
                Dim RemoteIpEndPoint As New IPEndPoint(IPAddress.Any, 0)
    
                
                Dim receiveBytes As [Byte]() = udpClient.Receive(RemoteIpEndPoint)
                Dim returnData As String = Encoding.ASCII.GetString(receiveBytes)
    
              
                txt("Hostname: " + returnData.ToString())
                
                udpClient.Close()
    
    
            Catch ex As Exception
                txt(ex.ToString())
            End Try
        End Sub
    End Class
    Resulting comment

    Code:
    Hostname: disconnect
    Full topic listed here
    http://www.dreamincode.net/forums/showtopic39722.htm

    Matt
    Last edited by computermat; Apr 15th, 2008 at 11:04 AM.

  6. #6
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: Cod4 Rcon / Udp Connection

    Have you found any documentation on the protocol that these server uses?
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  7. #7

    Thread Starter
    New Member computermat's Avatar
    Join Date
    Apr 2008
    Posts
    9

    Re: Cod4 Rcon / Udp Connection

    I have had a dig round, some of my findings below.

    JAVA based rcon (modern rcon)
    That simply means my program is reading very poor UDP packets. In-fact, the exact code to detect this goes a little something like this:

    - Send the "status" command to the server.
    - Read the response it gets back; I expect to see the following:

    Code:
    map: mp_pipeline
    num score ping guid                             name            lastmsg address               qport rate
    --- ----- ---- -------------------------------- --------------- ------- --------------------- ----- -----
      0     0   54 727fcaba55b4f67b68a64191053438e8 ^3CoDHQ ^1JD^7             50 24.93.10.111:-3200    -4994 25000
    - If the 1st line of the response says "map: " then I save the next series of characters as the map name.
    ----> If the 1st line does NOT say "map: " then there is a problem... try again. Maximum retries are 3.

    - If the 3rd line is a bunch of hyphens (----) then start populating the player list with the listed players.
    ----> If the 3rd line is not a bunch of hyphens, then there is a problem... Try again, a maximum of 3 times.

    - If I've tried 3 times on either of those conditions, and it still doesn't match what I am expecting, show the error message "Your server is returning really bad UDP packets" (or whatever that message says).

    So basically, your server is returning a FRAGMENTED response out-of-order. So since the UDP protocol is so unreliable sometimes, my program cannot account for and detect every case where the packets are messed up. So that warning is there to explain that the program might not function properly. Sometimes when people get the warning, the program works semi-fine, but some players are missing from the list. Other people just don't see anything, depending on how messed up their UDP packets are.
    Also found this on a PHP based rcon at http://planetozh.com/download/webrcon.txt
    Code:
    function status ($ip, $port, $timeout = 15) {
    	$errno = $errstr = null;
    	$cmd = "ÿÿÿÿgetstatus\n";
    	$f = fsockopen('udp://' . $ip, $port, $errno, $errstr, $timeout);
    	if (!$f)
    	    die ("Unable to connect. Error $errno - $errstr\n");
    	socket_set_timeout ($f, 1, 0);
    	fwrite ($f, $cmd);
    	$data = '';
    	while ($d = fread ($f, 10000)) {
    	    $data .= $d;
    	}
    	fclose ($f);
    	$data = stripcolors ($data);
    	return $data;
    }
    
    function rcon ($ip, $port, $rcon_pass, $command) {
    	$fp = fsockopen("udp://$ip",$port, $errno, $errstr, 2);
    	socket_set_timeout($fp,2);
    
    	if (!$fp)	{
    		echo "$errstr ($errno)<br>\n";
    	} else {
    		$query = "\xFF\xFF\xFF\xFFrcon \"" . $rcon_pass . "\" " . $command;
    		fwrite($fp,$query);
    	}
    	$data = '';
    	while ($d = fread ($fp, 10000)) {
    	    $data .= $d;
    	}
    	fclose ($fp);
    	$data = preg_replace ("/....print\n/", "", $data);
    	$data = stripcolors ($data);
    	return $data;
    }
    I have read on several sites the main rcon protocol is 115 but that might be for the previous versions

    Code:
    \Admin\wydadmin\Email\[email protected]\g_compassShowEnemies\0\g_gametype\war\gamename\Call of Duty 4\mapname\mp_convoy\protocol\4\shortversion\1.5\sv_allowAnonymous\0\sv_disableClientConsole\0\sv_floodprotect\4\sv_hostname\^2WWW.^1W^7Y^4D^2-HQ.COM\sv_maxclients\32\sv_maxPing\350\sv_maxRate\25000\sv_minPing\0\sv_privateClients\0\sv_punkbuster\1\sv_pure\1\sv_voice\1\ui_maxclients\50\URL\www.wydgaming.com
    I see protocol 4 in the above code what I took from one my server log files.

    Also found This site

    Hope this helps, if you want me to provide anything else let me know,

    Matt
    Last edited by computermat; Apr 15th, 2008 at 05:12 PM.
    Visual Studio 2005 (.net 2.0)
    Please note: I am 17 and dont have the exerience of an experienced programmer so I apologise in advance if my posts are confusing


  8. #8
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: Cod4 Rcon / Udp Connection

    Well, lets try this. See if this is working:
    VB.NET Code:
    1. Dim client As New System.Net.Sockets.Socket(Net.Sockets.AddressFamily.InterNetwork, Net.Sockets.SocketType.Dgram, Net.Sockets.ProtocolType.Udp)
    2.         Dim command As String = "ÿÿÿÿ rcon yourPassword say Is this working?"
    3.         Dim sendBuffer() As Byte = System.Text.Encoding.UTF8.GetBytes(command)
    4.         Dim receivedReply As Boolean
    5.         Dim availableBytes As Integer
    6.  
    7.         client.Connect("hostname/IP here", 5)
    8.         client.Send(sendBuffer, sendBuffer.Length, Net.Sockets.SocketFlags.None)
    9.  
    10.         Do
    11.             availableBytes = client.Available
    12.             If (availableBytes > 0) Then
    13.                 Dim receiveBuffer(availableBytes - 1) As Byte
    14.                 client.Receive(receiveBuffer, availableBytes, Net.Sockets.SocketFlags.None)
    15.                 MessageBox.Show(System.Text.Encoding.UTF8.GetString(receiveBuffer))
    16.                 receivedReply = True
    17.             End If
    18.         Loop Until receivedReply
    Just put your password in there, where it says "yourPassword", and try it out.

    EDIT: well, change the IP and port too
    Last edited by Atheist; Apr 15th, 2008 at 05:41 PM.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  9. #9
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: Cod4 Rcon / Udp Connection

    It would be great if the creators of Call of duty would supply us with some sort of documentation on the server protocoll. Valve has some good documentation I've use a couple of times; http://developer.valvesoftware.com/w...Query_Protocol
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  10. #10

    Thread Starter
    New Member computermat's Avatar
    Join Date
    Apr 2008
    Posts
    9

    Re: Cod4 Rcon / Udp Connection

    Quote Originally Posted by Atheist
    VB.NET Code:
    1. Dim client As New System.Net.Sockets.Socket(Net.Sockets.AddressFamily.InterNetwork, Net.Sockets.SocketType.Dgram, Net.Sockets.ProtocolType.Udp)
    2.         Dim command As String = "ÿÿÿÿ rcon yourPassword say Is this working?"
    3.         Dim sendBuffer() As Byte = System.Text.Encoding.UTF8.GetBytes(command)
    4.         Dim receivedReply As Boolean
    5.         Dim availableBytes As Integer
    6.  
    7.         client.Connect("hostname/IP here", 5)
    8.         client.Send(sendBuffer, sendBuffer.Length, Net.Sockets.SocketFlags.None)
    9.  
    10.         Do
    11.             availableBytes = client.Available
    12.             If (availableBytes > 0) Then
    13.                 Dim receiveBuffer(availableBytes - 1) As Byte
    14.                 client.Receive(receiveBuffer, availableBytes, Net.Sockets.SocketFlags.None)
    15.                 MessageBox.Show(System.Text.Encoding.UTF8.GetString(receiveBuffer))
    16.                 receivedReply = True
    17.             End If
    18.         Loop Until receivedReply
    Gave it a try and unfortunately it didnt do the job. In the top part of the image below this is what I get when I query the game port. If I query any other port i get the bottom part of the image.


    IF you cant see the image

    From using your code I think the port used in the connection has to be to the game connection port or both the game connection port and a UDP port have to be used. Im not sure though.

    Any more ideas, maybe its an authentication problem or is it suppose to do that?
    Visual Studio 2005 (.net 2.0)
    Please note: I am 17 and dont have the exerience of an experienced programmer so I apologise in advance if my posts are confusing


  11. #11
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: Cod4 Rcon / Udp Connection

    The format of the sent message must be wrong.
    And since I dont know the protocol syntax/semantics, I can only guess on other ways to write the command. Try changing the command to:
    VB.NET Code:
    1. Dim command As String = "ÿÿÿÿrcon yourPassword say Is this working?"
    The only difference is that there's no space between '&#255;&#255;&#255;&#255;' and 'rcon'.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  12. #12

    Thread Starter
    New Member computermat's Avatar
    Join Date
    Apr 2008
    Posts
    9

    Re: Cod4 Rcon / Udp Connection

    Still not working, still getting the disconnect msg.

    Thanks for your help, I am going to post on codbaords.com see if someone with knowledge in COD protocols sees my post.

    Thanks again, your efforts are greatly appreciated

    Matt
    Visual Studio 2005 (.net 2.0)
    Please note: I am 17 and dont have the exerience of an experienced programmer so I apologise in advance if my posts are confusing


  13. #13
    Junior Member
    Join Date
    Feb 2007
    Posts
    30

    Re: Cod4 Rcon / Udp Connection

    i am working on a similar, if not same project as you.. did you have any look with the application ???

  14. #14

    Thread Starter
    New Member computermat's Avatar
    Join Date
    Apr 2008
    Posts
    9

    Re: Cod4 Rcon / Udp Connection

    Yes I did manage to get the connection working but never completed my application. I will try and find the vb file and post the code here.
    Visual Studio 2005 (.net 2.0)
    Please note: I am 17 and dont have the exerience of an experienced programmer so I apologise in advance if my posts are confusing


  15. #15
    Junior Member
    Join Date
    Feb 2007
    Posts
    30

    Re: Cod4 Rcon / Udp Connection

    thankyou very much, i am at the same point at which you left, and dont look to be getting much further any time soon...

    the disconnect message when i send a command...

  16. #16

    Thread Starter
    New Member computermat's Avatar
    Join Date
    Apr 2008
    Posts
    9

    Re: Cod4 Rcon / Udp Connection

    I found the project file and made sure it was working before posting here. I have included it as an attachement. Any questions regarding it please feel free to ask and I will try to answer them
    Attached Files Attached Files
    Visual Studio 2005 (.net 2.0)
    Please note: I am 17 and dont have the exerience of an experienced programmer so I apologise in advance if my posts are confusing


  17. #17
    Junior Member
    Join Date
    Feb 2007
    Posts
    30

    Re: Cod4 Rcon / Udp Connection

    thank you so much, just done a quick ststus command on a few servers, and all working fine.. will have a bash at adding it to my app when i next have time..

    thanks again...

  18. #18
    New Member
    Join Date
    Apr 2009
    Posts
    1

    Re: Cod4 Rcon / Udp Connection

    I converted it to C# if anyone was interested.

    Code:
     
    
    public String rcon(String gameServerIP, int gameServerPort, String password, String rconCommand){
    
    
               // 'connecting to server
                Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
    
    			client.Connect(IPAddress.Parse(gameServerIP), gameServerPort);
    
    
    			String command;
    			command = "rcon " + password + " " + rconCommand;
                Byte[] bufferTemp = Encoding.ASCII.GetBytes(command);
                Byte[] bufferSend = new Byte[bufferTemp.Length + 5];
    
    
    			//'intial 5 characters as per standard
    			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 < bufferTemp.Length ; i++){
                    bufferSend[j] = bufferTemp[i];
                     j++;
                }
    
    
                IPEndPoint RemoteIpEndPoint = new IPEndPoint(IPAddress.Any, 0);
    			client.Send(bufferSend, SocketFlags.None);
    
    			//'big enough to receive response
    			Byte[] bufferRec = new Byte[64999];
                client.Receive(bufferRec);
                String result = Encoding.ASCII.GetString(bufferRec).Replace("\0", ""); // remove blanks
                return result;
    
            }

  19. #19
    New Member
    Join Date
    Sep 2009
    Posts
    1

    Re: Cod4 Rcon / Udp Connection

    Quote Originally Posted by computermat View Post
    I found the project file and made sure it was working before posting here. I have included it as an attachement. Any questions regarding it please feel free to ask and I will try to answer them
    I can't open it with Visual Basic 2008.
    Could you please convert it for VB.NET 2008 ?

    Thanks in advance!

  20. #20
    Lively Member SLeePYG72786's Avatar
    Join Date
    Sep 2010
    Posts
    66

    Re: Cod4 Rcon / Udp Connection

    I know this is kind of a dead thread, but I'm trying to do the exact same thing. There just isn't much about this on the 'net at this point, even though the game has been out for over 3 years. :sigh:

    I have downloaded the file from post #16, and have tried adding commands like Fast Restart, Change Map, Change Gametype, etc., but I just have no clue how to get them working. Also, when I connect to my server, it always shows "????print" above the player information. I would like for that to not be shown.

    If anyone has ANY additional information about this, please please post something.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width