electric 0 Posted June 21, 2019 Report Share Posted June 21, 2019 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 Abraço Link to post Share on other sites
electric 0 Posted June 25, 2019 Author Report Share Posted June 25, 2019 (edited) 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 MsgBox("1") On Error Resume Next MsgBox("2") Dim rcon As New QuakeRcon.RCON MsgBox("3") Dim response As String = rcon.sendRCON(txtCommand.Text, txtGameServerIP.Text, txtRconPassword.Text, txtGameServerPort.Text) MsgBox("4") 'replacing \n with \r\n so that it could be treated as enter in text area response = response.Replace(Constants.vbLf, Constants.vbCrLf) MsgBox("5") txtResponse.Text = response MsgBox("6") 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 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) Next 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 Obg Edited June 25, 2019 by electric Link to post Share on other sites
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now