screepers / screeps-multimeter

The most useful tool on your screeps workbench.
MIT License
89 stars 28 forks source link

Private server support #9

Closed topjor closed 6 years ago

topjor commented 6 years ago

With the latest release and the update of the api, the private server support has been undone as well. Is there any roadmap on reintroducing this feature?

CGamesPlay commented 6 years ago

Hey, thanks for filing an issue! Unfortunately, I haven't been playing Screeps in a while and as such haven't bene doing development on this. I do accept pull requests and will happily push a new release once fixed.

Do you have an error message or stack trace when connecting to private servers?

Also CCing @SystemParadox since he made the API upgrades.

topjor commented 6 years ago

At first there was no real documentation about connecting to private servers, so i checked versions and the code to find out how to configure that, but I also saw this in the latest version: (https://github.com/screepers/screeps-multimeter/commit/d6411b28c874cd0438e4534e41ed572afee15ee0#diff-c172382433adc1be8436b11321190519L125 (commit to v1.5.0) which removes the server url parameter (as part of the api update)

@@ -122,7 +122,7 @@ module.exports = class Multimeter extends EventEmitter {

   run() {
     this.api = new ScreepsAPI({
-      serverUrl: this.config.serverUrl,
+      token: this.config.token,
     });

     this.screen = blessed.screen({

I will soon have a look and see about making a PR

SystemParadox commented 6 years ago

Yes I removed the serverUrl option because it no longer works in the newer version of screeps-api. However, it has been replaced with protocol, hostname and port, so it should be pretty simple to add it back in.

I don't think private servers have the API enabled by default, although I do remember seeing a mod to enable it.

topjor commented 6 years ago

I have just created a pr, looked at the screeps-api package for how it handles the connection, I am also thinking about writing a little doc for how it works, is the docs folder okay for the documentation? I had a little issue myself when testing in that the url needs a / at the end otherwise the url.resolve returns nothing for some reason (has nothing to do with this but the screeps api) (pr: https://github.com/screepers/screeps-multimeter/pull/10)

topjor commented 6 years ago

Also yes, for the api to work, you need to generate a api token with ether a steam token (/api/auth/signin), with a password (and screepsmod-auth) or a other mod (none that i know of) that would add static tokens, also the tokens will invalidate after a hour if I'm correct (first 2 methods), so it might be nice to add optional password auth

FancyFurret commented 6 years ago

@topjor How were you able to get an api token for your private server? I get a cannot GET error when trying to access my.server/api/auth/signin. Using an api token from the main server also doesnt work. I am able to create a password using screepsmod-auth, but this doesn't support providing a password.

topjor commented 6 years ago

@osum4est It's a POST that you need to do with a json body containing i believe a email field with your username or email (if I'm correct it picked both in that field for me), and a password (or steam api token as per default in the official screeps client)

you will get a json body back with your api key (by default it will only be valid for n hours, so you will need to renew it unfortunatly without a mod that adds permanent api keys)

(I am currently at work so I cannot verify but I believe thats how it worked)

FancyFurret commented 6 years ago

I was just about to edit that I was dumb and didn't realize it was a POST instead of GET haha. That worked, however now I'm getting a "Error: getaddrinfo ENOTFOUND socket socket:80". I'm sure that is completely unrelated to this though, so thats a separate issue. I might take a look into that, as well as adding user/pass support to this in the next few days.

topjor commented 6 years ago

by default screeps does not run on port 80 but 21025, if you get this error in your screeps logs, it cant contact steamapi domain (had that myself because of a wrong default route)

i wanted to try and implement it myself some time back but never came around to do so, so feel free, it would be great to have the option to use both methods

edit: i also have not come around and writing proper documentation for using this on a private servers

FancyFurret commented 6 years ago

Okay! I have improved the support for private servers and even adding setup for them to the start up menu. Submitted a PR!