954,541 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Contact Game Server RCon Console through VB.net?

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.

Thanks

BleepyE
Junior Poster in Training
87 posts since Dec 2010
Reputation Points: 10
Solved Threads: 0
 

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("11.111.111.11", 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
			Next
			Dim sb As New StringBuilder()
			Try
				udpClient.Send(sendBytes, sendBytes.Length, ip, port)
				WaitForPackets(sb, RemoteIpEndPoint, udpClient)
				udpClient.Close()
				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
			Try
				Dim data As Byte() = client.Receive(endpoint)
				_return.Append(Encoding.ASCII.GetString(data))
			Catch ex As Exception
				Return
			End Try
		End While
	End Sub
End Module
GeekByChoiCe
Master Poster
721 posts since Jun 2009
Reputation Points: 208
Solved Threads: 168
 

That looks nice.

Is the 111.11.111 20100 IP & Port?

BleepyE
Junior Poster in Training
87 posts since Dec 2010
Reputation Points: 10
Solved Threads: 0
 

yes

GeekByChoiCe
Master Poster
721 posts since Jun 2009
Reputation Points: 208
Solved Threads: 168
 

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

BleepyE
Junior Poster in Training
87 posts since Dec 2010
Reputation Points: 10
Solved Threads: 0
 

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

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

GeekByChoiCe
Master Poster
721 posts since Jun 2009
Reputation Points: 208
Solved Threads: 168
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You