ServerBorwser | Java


(Dit) #1

Hi there!

I need some Help
I try to create a little java tool, ServerBrowser.

But i have some problems to get Informationpackets from Server.
What are the key words i have to send to the server?

“status” gives me not al information, just Map name und only one Player in the playerlist.

How can i get the whole player list ?

private void getData() throws IOException {
		String ask = "status";
		byte[] request = setRequest(ask);
		byte[] answer = new byte[1024];
		DatagramPacket requestPacket = new DatagramPacket(request,request.length, new InetSocketAddress(serverIP, port));
		socket = new DatagramSocket();
		socket.setSoTimeout(1000);
		DatagramPacket answerPacket = new DatagramPacket(answer,answer.length);
		socket.send(requestPacket);
		socket.receive(answerPacket);
		
		byte[] data = answerPacket.getData();
		
		serverInfos[4] = (new String(data,0,answerPacket.getLength()));
		socket.close();
	}


	private byte[] setRequest(String ask) {
		byte[] request = new byte[1024];
		byte wort[] = ("\u00FF\u00FF\u00FF\u00FF rcon\"" + RCON + "\" " + ask).getBytes();
		System.arraycopy(wort, 0, request, 0, wort.length);
		return request;
	}


OUTPUT Server was full at that moment

ÿÿÿÿprint
map: v2_factory
num score ping name            lastmsg address               qport rate
--- ----- ---- --------------- ------- --------------------- ----- -----
  6 38052   62 ^2Kakaszi^1PL         0 89.79.8.240:27960     49357 25000
  7 

Please help me :slight_smile:


(Paul) #2

I have no real experience in Java, but I made the same system in PHP for my web rcon (not 100% finished yet).

But maybe here:
System.arraycopy(wort, 0, request, 0, wort.length);

worth.length is maybe shorter than the hole array, so it misses some stuff.

& You can send getstatus command too, then you don’t need rcon password for similar data


(Dit) #3

ok thx Paul :slight_smile: with getstatus i got the whole PLayer List :slight_smile:

But with rcon the same problem :(, need rcon cause of some useful information like IP, Server slot etc…


(merlin1991) #4

I assume this is part of your rcon system:

    private byte[] setRequest(String ask) {
        byte[] request = new byte[1024];
        byte wort[] = ("\u00FF\u00FF\u00FF\u00FF rcon\"" + RCON + "\" " + ask).getBytes();
        System.arraycopy(wort, 0, request, 0, wort.length);
        return request;
    }

you got a problem with the stuff you send to the server it should look like this:

ÿÿÿÿrcon RCONPASSWORD fancyommand
yours looks like this:

ÿÿÿÿRCON" STUFFROMASK
btw you might want to raise the buffersize of the answer pakets (I use 4096 :P)

and .getBytes() isn’t save, .getBytes() uses the default encoding wich can bring you to troubles when you try to run the java tool on a machine with default encoding wich is different to ascii (for example most linux distros would run on UTF8 and the et server would’nt understand it because of that)


(Dit) #5

Hi
if i raise the buffersize of the answer pakets

byte[] answer = new byte[4096];
			DatagramPacket answerPacket = new DatagramPacket(answer,
					answer.length, serverAdresse);
			socket.receive(answerPacket);

my output looks like this :frowning:

 
map: warbell
num score ping name            lastmsg address               qport rate
--- ----- ---- --------------- ------- --------------------- ----- -----
  0 10854   12 ^9[AwB]-=Catkiller=-     50 91.12.122.227:27960   30789 25000
  1 [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][[][][][][][][][][][][][][][]

i think this [][][] are null-bits or something :frowning:

any idea ?

P.S.
without rcon, Command getstatus i’ve got the whole player list :frowning:


(valkyr) #6

You need to set up a loop to receive more than one packet.

The response from an RCON command has a maximum packet size of about ~288bytes. If the response is larger than this then the message is truncated and continues being sent in a new packet.

For some reason the response from a non-RCON command is sent in a larger packet, meaning only 1 is needed.


(Dit) #7

yes the problem was solved with a loop, but how to get info in which team one player is playing ?


(ailmanki) #8

A serverbrowser which need rcon is a bad idea, I guess no one can use it.

You don’t need that to get teams and all the infos…
You only need the public response on these 2:
getstatus and getinfo

both give depending on server and settings different output.

Some servers don’t give the list with players, and some don’t give the teams…

One info you get is the KEY P,
P\1—113113-112112222222-23221

This string, represents the slot and team a player is in.

1,2,3, = axis,allies, spec

  • = free slot
    And the slot number… the outer left is slot 1, and so on.

(Dit) #9

@ ailmanki thy very much!

got it :slight_smile: P ------12211121012122212111221212

its not just server browser it should be ServerBrowser for admins only, to check IP, make screenshot etc…
cause HLSW prog dont work on Linux :slight_smile:


(ailmanki) #10

Looking forward to it :)…
an idea, get the maps with fdir maps/*.bsp
and list them …
hope it will work for OSX also…


(Dit) #11

wow!!!
thx :slight_smile: