Bugs and Feature Requests for PlanetsCentral and other VGAP software

[Posting] Planetscentral API
Thread opener
Posted Thu, 2023-02-02 17:19 GMT

Hi Stefan, do you have some kind of API / script to get RTS and send TRN files from a batch? Thank you!

[Posting] Re: Planetscentral API
Posted Thu, 2023-02-02 20:14 GMT

do you have some kind of API / script to get RTS and send TRN files from a batch?

There is a HTTP API (although it's pretty old-style, i.e. not REST).

API playground: https://planetscentral.com/dev/playground.cgi

Beware, it's the real thing, NOT a sandbox. Any POST you do with it affects live data. I assume you can figure out with the browser developer tools how it works.

To log in, use GET with action=whoami on the "user" endpoint, passing api_user and api_password parameters. This returns information about the user, including a token.

To list your games, use GET with action=gamelist on the "host" endpoint, passing api_token (or api_user/api_password).

To upload a turn, use POST with action=trn, api_token, and the file as data attribute.

There currently doesn't seem to be a way to access a result directly from the host, that's just not implemented yet. If you have assigned a game directory on the server, you can use the "file" endpoint, which has "ls" and "get" actions to get it from there; this is what PCC2ng currently does.

The C++ code from PCC2ng is here but it's pretty rough, not very well-documented, and not part of any release yet.

--Stefan

[Posting] Re: Planetscentral API
Thread opener
Posted Fri, 2023-02-03 05:44 GMT

There is a HTTP API (although it's pretty old-style, i.e. not REST).

Thanks again - I will check this, if I can do it quick and dirty :smile:

[Posting] Re: Planetscentral API
Thread opener
Posted Sat, 2023-02-04 08:20 GMT, edited Sat, 2023-02-04 08:20 GMT

There is a HTTP API (although it's pretty old-style, i.e. not REST).

Thanks again - I will check this, if I can do it quick and dirty :smile:

Sorry, ich scheitere schon an den einfachsten Dingen, wie rufe ich die API auf?

So geht es in perl jedenfalls nicht :smile:

my $reply = httpCall("GET /dev/playground.cgi/user HTTP/1.0\n", httpBuildQuery(action => 'whoami', api_user => $user, api_password => $pass));

Ich versuche mein Script auf dein c2nu.pl aufzubauen...

[Posting] Re: Planetscentral API
Posted Sat, 2023-02-04 15:33 GMT

So geht es in perl jedenfalls nicht :smile:

my $reply = httpCall("GET /dev/playground.cgi/user HTTP/1.0\n", httpBuildQuery(action => 'whoami', api_user => $user, api_password => $pass));

Ich versuche mein Script auf dein c2nu.pl aufzubauen...

Well, you didn't look close enough in browser developer tools :smile: API endpoints are things like "/api/user.cgi".

I just hacked a small PlanetsCentral API client based on c2nu.pl here: https://github.com/stefanreuther/c2nu/blob/c2connect/c2connect.pl

Basically, it can do the same operations that PCC2ng can do (although it can not yet download player files): download the result file from a managed game directory, and upload a turn file for a hosted game.

It happens that the original c2nu.pl has a bug in its httpCall function that generates slightly wrong HTTP requests (\n linefeeds instead of \r\n). Whereas many web servers seem to be flexible here, the web server that runs on PlanetsCentral.com actually insists on the correct format; thus, you'd not get results with the original c2nu.pl version. I fixed that in c2connect.pl.

Disclaimer: c2connect.pl is a proof-of-concept. One important restiction is that it does not do HTTPS, and thus transmits your password in plaintext. At least, avoid it in public wifi.

--Stefan

[Posting] Re: Planetscentral API
Thread opener
Posted Sat, 2023-02-04 16:05 GMT

Well, you didn't look close enough in browser developer tools :smile: API endpoints are things like "/api/user.cgi".

True - and maybe because of lack of knowledge :embarassed: Again thank you - i will give that a try.

[Posting] Re: Planetscentral API
Thread opener
Posted Sun, 2023-02-05 10:50 GMT

True - and maybe because of lack of knowledge :embarassed: Again thank you - i will give that a try.

I expanded the functionality - shall load it to github? Why did HTTPS not work? Problems on the server? I tried this - but it worked only with HTTP not HTTPS...

my $ua = LWP::UserAgent->new;
#$ua->ssl_opts(verify_hostname => 0); #Verify hostname ausschalten, falls nötig
my $content = "action=whoami&api_user=$user&api_password=$pass";
my $reply = $ua->post("https://$host/api/user.cgi", Content => $content);
[Posting] Re: Planetscentral API
Posted Sun, 2023-02-05 12:45 GMT

I expanded the functionality - shall load it to github? Why did HTTPS not work? Problems on the server?

I just had not implemented HTTPS before.

Basically, I try to keep my Perl programs self-contained and with few dependencies. This way, they run on pretty much everything, including Windows with Perl installations of questionable quality. Opening a socket and speaking HTTP is easy - but unencrypted.

I now modified it to use IO::Socket::SSL.

You are using LWP::UserAgent, I have never used that. Feel free to turn my proof-of-concept into something better. I will probably not go much farther here, because I'm concentrating on PCC2ng. Just got a few minutes of idle time while that is building in the newly set-up Continuous Integration...

Also, feel free to poke me if you need something in the API that does not yet exist.

Should I make a developer forum? :smile:

--Stefan

[Posting] Re: Planetscentral API
Thread opener
Posted Sun, 2023-02-05 17:20 GMT, edited Sun, 2023-02-05 17:41 GMT

I just had not implemented HTTPS before. I now modified it to use IO::Socket::SSL.

Ah OK, perfect. Thank you.

Feel free to turn my proof-of-concept into something better.

I will not go to far either, just to run my batches and avoid using the browser for file exchange.

Most important change: I added the download of utilx.dat :smile:

Also, feel free to poke me if you need something in the API that does not yet exist.

Should I make a developer forum? :smile:

I think its alright - using this thread will be enough, too. I assume.

Quapla

This is a testing version.
It may be incomplete, and have more bugs (or features) than the public live version at planetscentral.com.