admin port

Forum for technical discussions regarding development. If you have a general suggestion, problem or comment, please use one of the other forums.

Moderator: OpenTTD Developers

Post Reply
Honza_
Engineer
Engineer
Posts: 122
Joined: 29 Aug 2010 10:29

admin port

Post by Honza_ »

Hi,
I would like to make php library for comunicating via admin port. It shouldnt be much hard, but I failed to comunicate with server, what is quite a major problem. There is little documentation about what actually send, and I cant extract from already done libraries in jave or python.

So, is there some nice site, where is exactly said what data pack and send?

My problem is: I want to join as admin, so I have a server with admin password "password", and port is 3977.
I am sending packet 0x00 + "password" + 0x00 + "botname" + 0x00 + "version" + 0x00
But nothing is received.
Terkhen
OpenTTD Developer
OpenTTD Developer
Posts: 1034
Joined: 11 Sep 2008 07:32
Location: Spain

Re: admin port

Post by Terkhen »

As I mentioned already in your other thread, the documentation of the admin port is here:

http://vcs.openttd.org/svn/browser/trun ... etwork.txt

If something you need is missing from the documentation, I'm afraid you will need to check OpenTTD source code (somewhere in src/network IIRC) or wait for someone who knows about the admin network to answer here.
User avatar
adf88
Chief Executive
Chief Executive
Posts: 644
Joined: 14 Jan 2008 15:51
Location: PL

Re: admin port

Post by adf88 »

A packet should contain it's size on the first two bytes (LE). Your packet has...
  • size - 2 bytes
    type - 1 byte
    "password" - 9 bytes
    "botname" - 8 bytes
    "version" - 7 bytes
    ----------------------
    = 27 bytes (0x1B bytes)
...so what you should send is
  • 0x1B 0x00 + 0x00 + "password" + 0x00 + "botname" + 0x00 + "version" + 0x00
:] don't worry, be happy and checkout my patches
Honza_
Engineer
Engineer
Posts: 122
Joined: 29 Aug 2010 10:29

Re: admin port

Post by Honza_ »

thanks adf88, I will try it, seems this really could be it

Terkhen, I read that, it is good, but doesnt go to details about the packet consist as you probably know too.
Terkhen
OpenTTD Developer
OpenTTD Developer
Posts: 1034
Joined: 11 Sep 2008 07:32
Location: Spain

Re: admin port

Post by Terkhen »

Sorry but as I mentioned I don't know much about the admin network. Your best bet is the source code then.
Honza_
Engineer
Engineer
Posts: 122
Joined: 29 Aug 2010 10:29

Re: admin port

Post by Honza_ »

ok, so it works, already getting some packets from server. This admin port is sure a cool thingy
User avatar
burty
Transport Coordinator
Transport Coordinator
Posts: 326
Joined: 16 Jun 2006 17:18
Location: Somwhere near a computer

Re: admin port

Post by burty »

JOAN has a lot of example code that you will be able to port to PHP quite easily. In fact JOAN example code could be ported quite easily to almost any language if you know what you are doing in the that language.
Honza_
Engineer
Engineer
Posts: 122
Joined: 29 Aug 2010 10:29

Re: admin port

Post by Honza_ »

Thats true. Right now I can access server very easily, but major problem is handling TCP socket. My code is too much slow. Unfortunately, this cant be transfered from java :-(
User avatar
burty
Transport Coordinator
Transport Coordinator
Posts: 326
Joined: 16 Jun 2006 17:18
Location: Somwhere near a computer

Re: admin port

Post by burty »

What's the reason for needing to use PHP as opposed to Java? Hit me up on MSN if you want I've got some PHP experience so I might be able to give you some help.
Honza_
Engineer
Engineer
Posts: 122
Joined: 29 Aug 2010 10:29

Re: admin port

Post by Honza_ »

burty wrote:What's the reason for needing to use PHP as opposed to Java?

Reason is to gain control via web. Although java can be useful here, I would rather do it in php.

So I have this code:

Code: Select all

<?php
  public function connect(){
    $this->socket = fsockopen($this->host,$this->port); //open socket
    //stream_set_blocking( $this->socket, false);   //non blocking stream
  }
  
  public function send_packet($type, $subtype=""){
    $this->type = $type;
    if($subtype) $this->subtype = $subtype;
    $this->packet = new APacket();
    $this->send_prepare();
    
    fwrite($this->socket, $this->packet->send(), APcontrol::SEND_MTU);
  }
  
  public function recv_packet(){
    $output = "";
    while(($output .= fread($this->socket, APcontrol::SEND_MTU))){
       
    }
    $this->packet->recv_start($output);
    $this->recv_analyze();
  }
?>
And I have this problem:
I am able to connect, to send query, even recieve, but recieving takes a lot of time, 10+ secons, sometimes even more than php timeout. TCP should be able to do it much faster, so obviously I missed some vital thing.
With stream blocking it outpust nothing.

Any help would be very appreciated.
User avatar
Korenn
Tycoon
Tycoon
Posts: 1735
Joined: 26 Mar 2004 01:27
Location: Netherlands
Contact:

Re: admin port

Post by Korenn »

Does the admin port receive the map? If it does, that code is way too slow - you're string concatenating on each byte. If you receive large packets you'd be better off creating a buffer array and reading a chunk at a time.

You should time whether it finished the read or if your own receiving functions are the bottleneck.
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: admin port

Post by planetmaker »

Korenn wrote:Does the admin port receive the map?
No.
Honza_
Engineer
Engineer
Posts: 122
Joined: 29 Aug 2010 10:29

Re: admin port

Post by Honza_ »

No map. Recieveing data are not more than aproximately 500 bytes, if game is full.
paco
Engineer
Engineer
Posts: 4
Joined: 12 Jun 2014 02:32

Re: admin port

Post by paco »

adf88 wrote:A packet should contain it's size on the first two bytes (LE). Your packet has...
  • size - 2 bytes
    type - 1 byte
    "password" - 9 bytes
    "botname" - 8 bytes
    "version" - 7 bytes
    ----------------------
    = 27 bytes (0x1B bytes)
...so what you should send is
  • 0x1B 0x00 + 0x00 + "password" + 0x00 + "botname" + 0x00 + "version" + 0x00
:bow: Thanks for the info! I had the same problem as Honza_. I am planning to write an interface to the admin port for personal use (and fun) in the Lua programming language. The documentation at http://svn.openttd.org/trunk/docs/admin_network.txt is clear, but it doesn't tell a packet should contain its size which is essential information. My elementary program is now able to communicate with the server through the admin port and is able to grow...

Either adding the packet's size is obvious and I am stupid :shock: :) or the documentation should be updated. It took me hours of Googling and reading this forum before I found this thread and found out what I did wrong. :x If the documentation should be updated, who can I contact?
Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: No registered users and 50 guests