Android Question Inconvertible types error

voiD

Member
Licensed User
Longtime User
Hi guys,

i hope you can help me. Iam trying to rebuild a function from c++ to B4A but i dont know why it doesnt work :(

Here the C++ Function

B4X:
unsigned char[] RCON_Command(std::string Command, int ServerData)
{
    unsigned char Packet[static_cast<unsigned char>((13 + Command.length())) + 1];
    Packet[0] = Command.length() + 9; //Packet Size (Integer)
    Packet[4] = 0; //Request Id (Integer)
    Packet[8] = ServerData; //SERVERDATA_EXECCOMMAND / SERVERDATA_AUTH (Integer)
    for (int X = 0; X < Command.length(); X++)
    {
        Packet[12 + X] = System::Text::Encoding::Default->GetBytes(Command[X])[0];
    }
    return Packet;

And Here my try in B4A:
B4X:
Sub Button1_Click
    Dim SERVERAUTH() As Byte
    Dim rCON As String = "flo1993lol"
   
    SERVERAUTH(0) = rCON.Length + 13
    SERVERAUTH(4) = 0
    SERVERAUTH(8) = SERVERDATA_AUTH
    SERVERAUTH(12) = rCON.GetBytes("ascii")
    AStreams.Write(SERVERAUTH)

    ToastMessageShow("Finisched",True)
End Sub

It throws the following error:

B4A line: 80
SERVERAUTH(12) = rCON.GetBytes(\
javac 1.7.0_17
src\b4a\example\main.java:386: error: inconvertible types
_serverauth[(int) (12)] = (byte)(_rcon.getBytes("ascii"));
^
required: byte
found: byte[]
1 error

I hope you can help me :s

best regards,

voiD
 

stevel05

Expert
Licensed User
Longtime User
Because you are assigning the byte array returned by GetBytes to a single element of a Byte Array which requires a byte not an array.

You need to implement the loop

Something like:

B4X:
For i = 0 To rCON.Length - 1
    SERVERAUTH(12+i) = rCON.SubString2(i,i+1).GetBytes("ascii")(0)
Next
 
Last edited:
Upvote 0

voiD

Member
Licensed User
Longtime User
Iam unable to get this working :(
Alreade got that he sends a packet to the server but it's wrong and so the server wont answer :S

I hope somebody can help me again :s
 
Upvote 0

eps

Expert
Licensed User
Longtime User
What's the error you are getting now, or is it the same or similar one? What does the code look like now?

What is the server expecting to receive?
 
Upvote 0

voiD

Member
Licensed User
Longtime User
Here the code:
B4X:
Dim SERVERAUTH(128) As Byte
      Dim rCON As String = "xxxxxx"
 
        SERVERAUTH(0) =  rCON.Length
        SERVERAUTH(4) = 0
        SERVERAUTH(8) = SERVERDATA_AUTH
        SERVERAUTH(12) = rCON.GetBytes("UTF8")
       
    For i = 0 To rCON.Length - 1
        SERVERAUTH(12+i) = rCON.SubString2(i,i+1).GetBytes("UTF8")(0)
    Next
   
   
    AStreams.Write(SERVERAUTH)

Iam trying to rebuilde the Source RCON Protocol
See here:
https://developer.valvesoftware.com/wiki/Source_RCON_Protocol
 
Upvote 0
Top