Hi, im wondering how I could contact my Call of Duty: Black Ops game server's console, through RCon, through an application I have created in VB.net

All I want to beable to do is have the ingame console in a textbox or something, it doesnt even have to be live, just so I can execute commands remotely.


Recommended Answers

All 6 Replies

Here is a sample module i used in one of my projects....

Imports System.Net.Sockets
Imports System.Text

Module Module1

	Sub Main()
		Console.WriteLine(RconQuery("", 20100, "myRcon", "status"))
	End Sub

	Friend Function RconQuery(ByVal ip As String, ByVal port As Integer, ByVal rcon As String, ByVal cmd As String) As String
		Using udpClient As New UdpClient()
			udpClient.Client.ReceiveTimeout = 10
			Dim RemoteIpEndPoint As New Net.IPEndPoint(Net.IPAddress.Any, 0)
			Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes(String.Format("ÿÿÿÿrcon {0} {1}{2}", rcon, cmd, Chr(0)))
			Dim i As Integer
			For i = 0 To 3
				sendBytes(i) = 255
			Dim sb As New StringBuilder()
				udpClient.Send(sendBytes, sendBytes.Length, ip, port)
				WaitForPackets(sb, RemoteIpEndPoint, udpClient)
				Return sb.ToString
			Catch ex As Exception 'thrown if server didnt respond after 5 sec##
				Debug.WriteLine(String.Format("Exception in RconQuery: {0}{1}Details: {2}", ex.GetType, vbNewLine, ex.Message))
				Return ""
			End Try
		End Using
	End Function

	Private Sub WaitForPackets(ByRef _return As StringBuilder, ByVal endpoint As Net.IPEndPoint, ByVal client As UdpClient)
		While True
				Dim data As Byte() = client.Receive(endpoint)
			Catch ex As Exception
			End Try
		End While
	End Sub
End Module

That looks nice.

Is the 111.11.111 20100 IP & Port?


How exactly can I use this code to send commands to the rcon server?

Console.WriteLine(RconQuery("", 20100, "myRcon", "status"))

this writes the return from rcon when sending the command "status"
myRcon is your rcon password.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.