-
Jun 26th, 2019, 02:26 PM
#1
Thread Starter
New Member
Rcon Vb.net ARK server
Hello,
Make sometime i dont code and i always code for fun but iam trying to connect and send some Rcon commands to my ark (steam) server, so i find a project but dosent work and i dont know why because dont get much info from vb... iam workin on last version of vb.net
code iam using
Code:
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:
Code:
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
can someone help me to make that working xD
thanks
-
Jun 26th, 2019, 03:13 PM
#2
Re: Rcon Vb.net ARK server
Welcome to VBForums
The first step to solving this is to remove the line On Error Resume Next from your code... it is just a way to tell VB "I don't care if any of the following code works, so just carry on blindly and don't tell me about any problems"
As you are forcing VB to hide information about errors from you, the only way to work out what might be going wrong (out of thousands of possibilities for that code) is to guess. Even very well educated guesses are likely to be wrong, so knowing the details of any errors is important, as it narrows down the options immensely.
If you aren't getting an error after that, the next step in working it out is debugging (things like using breakpoints and stepping the code). It is much easier than you would imagine, and gives extremely good results. There is a good guide here: https://docs.microsoft.com/en-gb/vis...h-the-debugger
-
Jun 26th, 2019, 03:53 PM
#3
Thread Starter
New Member
Re: Rcon Vb.net ARK server
hello my friend first let me say thanks
so after remove the line i get error because
Code:
Dim response As String = rcon.sendRCON(txtCommand.Text, txtGameServerIP.Text, txtRconPassword.Text, txtGameServerPort.Text)
cant be converted to integer so i change and put that
Code:
Dim ipserver As Double
If Double.TryParse(txtGameServerIP.Text, ipserver) Then
End If
Dim rcon As New ArkRcon.RCON
Dim response As String = rcon.sendRCON(txtCommand.Text, ipserver, txtRconPassword.Text, txtGameServerPort.Text)
but now i get that error:
vb.net System.Net.Sockets.SocketException: 'this anfitriã is not known'
Code:
Dim client As New UdpClient()
client.Connect(serverIp, serverPort)
-
Jun 26th, 2019, 05:05 PM
#4
Re: Rcon Vb.net ARK server
Originally Posted by jottaonline
but now i get that error:
vb.net System.Net.Sockets.SocketException: 'this anfitriã is not known'
Code:
Dim client As New UdpClient()
client.Connect(serverIp, serverPort)
An online translator implies that the error is "The Host is not known".
Based on that I recommend checking that the variables on the line with the error contain what they should (you can check by putting a breakpoint on that line, then when the code pauses there hover the mouse over the variable names), and that you have them in the correct order.
-
Jun 26th, 2019, 05:46 PM
#5
Thread Starter
New Member
Re: Rcon Vb.net ARK server
ok, so what i can see is the ipserver dont get the IP, because result is "0"
i try change some stuff but still same
-
Jun 26th, 2019, 05:47 PM
#6
Thread Starter
New Member
Re: Rcon Vb.net ARK server
ok, so what i can see is the ipserver dont get the IP, because result is "0"
i try change some stuff but still same
-
Jun 27th, 2019, 03:03 AM
#7
Thread Starter
New Member
Re: Rcon Vb.net ARK server
Hello ppl
So i fix that one var are not on right place and dont get correct nimber the ip so i make a new var and give the ip...
But now get a error about matriz on buffersend on the for
-
Jun 28th, 2019, 02:37 AM
#8
Re: Rcon Vb.net ARK server
Originally Posted by jottaonline
But now get a error about matriz on buffersend on the for
Show us your current code, and let us know what line the error happens on.
Also tell us the actual error message (even if it isn't in English), as that gives us a good guide to what is going wrong.
-
Jun 28th, 2019, 05:55 PM
#9
Thread Starter
New Member
Re: Rcon Vb.net ARK server
Hello my friend,
sorry for delay but just come from work now ... so my code is that one :
main form:
Code:
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
Dim ip As String = "94.23.8.143"
Dim port As String = "27020"
Dim rconpass As String = "xxxxx"
Dim command As String = "Permissions.ListGroups"
Dim ipserver As Double
'If Double.TryParse(txtGameServerIP.Text, ipserver) Then
' 'O texto da txt_idade foi convertido para double 'number' variável
'End If
'On Error Resume Next
Dim rcon As New ArkRcon.RCON
Dim response As String = rcon.sendRCON(ip, port, rconpass, command)
'Dim response As String = rcon.sendRCON(ipserver, txtGameServerPort.Text, txtRconPassword.Text, txtCommand.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
class:
Code:
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports System.Net.Sockets
Imports System.Net
Imports System.Text.RegularExpressions
Namespace ArkRcon
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)
bufferSend(Math.Max(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 UdpClient = NewMethod()
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
Private Shared Function NewMethod() As UdpClient
Dim client As New UdpClient()
Return client
End Function
End Class
End Namespace
error:
Code:
bufferSend(Math.Max(Threading.Interlocked.Increment(j), j - 1)) = bufferTemp(i)
System.IndexOutOfRangeException: 'Índice fora dos limites da matriz.'
thanks
Last edited by jottaonline; Jun 28th, 2019 at 07:20 PM.
-
Jun 28th, 2019, 06:33 PM
#10
Re: Rcon Vb.net ARK server
That's pretty old and creaky looking code. Possibly converted from C# using an early version of a C#to VB converter tool? Dunno.
Anyways, without rewriting it too much at this stage, try altering the prepareCommand function as so:
Code:
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 4 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
For i As Integer = 0 To bufferTemp.Length - 1
bufferSend(i + 4) = bufferTemp(i)
Next
Return bufferSend
End Function
-
Jun 28th, 2019, 06:46 PM
#11
Re: Rcon Vb.net ARK server
The code you posted appears to contain an external IP address, listening port, and password. Gotta give your code a once over before you post anything that you know contains connection info like that.
-
Jun 28th, 2019, 09:04 PM
#12
Re: Rcon Vb.net ARK server
I see the OP has removed the password and altered the IP from the original, so I would say that it is sufficiently obfuscated at this time.
My usual boring signature: Nothing
-
Jun 29th, 2019, 01:43 AM
#13
Thread Starter
New Member
Re: Rcon Vb.net ARK server
Yea qhen i past the first time i think i need remove password but after forget just stupid sorry for that
-
Jun 30th, 2019, 05:24 AM
#14
Thread Starter
New Member
Re: Rcon Vb.net ARK server
Originally Posted by Inferrd
That's pretty old and creaky looking code. Possibly converted from C# using an early version of a C#to VB converter tool? Dunno.
Anyways, without rewriting it too much at this stage, try altering the prepareCommand function as so:
Code:
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 4 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
For i As Integer = 0 To bufferTemp.Length - 1
bufferSend(i + 4) = bufferTemp(i)
Next
Return bufferSend
End Function
hello first iam sorry for late answer but allot work no time
i change the code and place that one but now i don get errors... i make a break point and the code stuck there :
Code:
bufferSend(i + 4) = bufferTemp(i)
dont get anyting on break or help from program and if i dont put a break program just stuck and dont do notthing :\
-
Jun 30th, 2019, 07:02 AM
#15
Re: Rcon Vb.net ARK server
Originally Posted by jottaonline
i change the code and place that one but now i don get errors... i make a break point and the code stuck there :
Code:
bufferSend(i + 4) = bufferTemp(i)
I don't see how the code could hang on that line. It simply copies the value of an element in one array to an element in another array. You should post the code you are currently using.
I was more expecting you to hit problems when you try to send/receive data using the UDP Client. I have no experience with Steam RCon, but from what I have read the protocol now uses TCP, not UDP. Maybe you should check into that yourself before you proceed. See the docs for the Source RCON Protocol.
-
Jun 30th, 2019, 05:21 PM
#16
Thread Starter
New Member
Re: Rcon Vb.net ARK server
hello i try all day and read about other stuff
i dunno if peaple still using that for Arkserver but yea the original shold be translate from C++
i try change for UDP but get allot errors... i go still trying i dont want just giveup but not easy xD like i say on begin i dont make code allong time agoo lol but like more easy stuff hehe
thanks for all the help i go updating when have new stuff
-
Jul 1st, 2019, 06:14 PM
#17
Thread Starter
New Member
Re: Rcon Vb.net ARK server
Hello ppl i start gething always more errors each time i change code..
iam sorry for the question but someone can make me the connection code
just the parto to connect to server :$
thanks
-
Jul 3rd, 2019, 06:05 PM
#18
Re: Rcon Vb.net ARK server
Originally Posted by jottaonline
can make me the connection code
just the parto to connect to server :$
Connecting to the server is as simple as:
Code:
Dim Client As TcpClient
Client = New TcpClient(Ip, Port)
You then have to send an auth request packet to the server. That's a type 3 (SERVERDATA_AUTH) packet where the Body field is your password and the Id field is any integer value of your choosing.
The server will respond with a type 2 (SERVERDATA_AUTH_RESPONSE) packet where the Id field should have the same value as the Id you sent it. However, if the Id field contains -1 (0xFFFFFFFF), then it has refused to auth you.
This is all based on the protocol docs I linked to earlier.
Things become complicated very quickly after that. If you haven't coded much in VB with .NET, I fear you will struggle with this.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|