Jump to content
Sign in to follow this  

Conecçao Rcon

Recommended Posts


Bom dia a todos,

Estive a procura no forum e nao encontrei nada referente a Rcon no campo de vb.net,

Online existem algumas coisas mas tambem nada que me tenha realmente ajudado.. 


Questao a minha é a seguinte


Preciso fazer uma conneccao por Rcon 

Tenho o ip a porta e a porta rcon

Alguem me da uma luzinha de como fazer a coneccao ?


Obrigado desde ja



Share this post

Link to post
Share on other sites

Boa noite,

Após algum pesquisa encontrei este projecto já antigo...

o problema é que nao me da nada nem obtenho um erro a unica coisa que tenho é no output


Exception thrown: 'System.InvalidCastException' in Microsoft.VisualBasic.dll
Exception thrown: 'System.NullReferenceException' in RCON.exe


Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Public Class main

    Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSend.Click
        On Error Resume Next
        Dim rcon As New QuakeRcon.RCON
        Dim response As String = rcon.sendRCON(txtCommand.Text, txtGameServerIP.Text, txtRconPassword.Text, txtGameServerPort.Text)
        'replacing \n with \r\n so that it could be treated as enter in text area
        response = response.Replace(Constants.vbLf, Constants.vbCrLf)
        txtResponse.Text = response

        If txtResponse.Text.Contains("????print") Then
            response = response.Replace(Constants.vbLf, Constants.vbCrLf)
            txtResponse.Text.Replace("????print", "")
            btnSend.Text = "Connected"
        End If
    End Sub
End Class



Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports System.Net.Sockets
Imports System.Net

Namespace QuakeRcon
	Friend Class RCON

		        Public Function prepareCommand(ByVal command As String) As Byte()
            Dim bufferTemp As Byte() = Encoding.ASCII.GetBytes(command)
            Dim bufferSend As Byte() = New Byte(bufferTemp.Length + 3) {}

            '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")

            'copying bytes from challenge rcon to send buffer
            Dim j As Integer = 4

            For i As Integer = 0 To bufferTemp.Length - 1
                bufferSend(System.Math.Max(System.Threading.Interlocked.Increment(j), j - 1)) = bufferTemp(i)
            Return bufferSend
        End Function

        Public Function sendRCON(ByVal serverIp As String, ByVal serverPort As Integer, ByVal rconPassword As String, ByVal rconCommand As String) As String

            Dim client As New UdpClient()
            client.Connect(serverIp, serverPort)

            'sending challenge command to counter strike server 
            Dim getChallenge As String = "challenge rcon" & vbLf
            Dim bufferSend As Byte() = Me.prepareCommand(getChallenge)

            'send challenge command and get response
            Dim RemoteIpEndPoint As New IPEndPoint(IPAddress.Any, 0)
            client.Send(bufferSend, bufferSend.Length)
            Dim bufferRec As Byte() = client.Receive(RemoteIpEndPoint)

            'retrive number from challenge response 
            Dim challenge_rcon As String = Encoding.ASCII.GetString(bufferRec)
            challenge_rcon = String.Join(Nothing, Regex.Split(challenge_rcon, "[^\d]"))

            'preparing rcon command to send
            Dim command As String = "rcon """ + challenge_rcon + """ " + rconPassword + " " + rconCommand + vbLf
            bufferSend = Me.prepareCommand(command)

            client.Send(bufferSend, bufferSend.Length)
            bufferRec = client.Receive(RemoteIpEndPoint)
            Return Encoding.ASCII.GetString(bufferRec)

        End Function
	End Class
End Namespace



Edited by electric

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.