Giter Club home page Giter Club logo

screeps-multimeter's Introduction

NPM version

screeps-multimeter

Multimeter is a hackable console for the game Screeps. It lets you access your Screeps console without loading up the full website (and as a result lets you play Screeps for much longer on a single battery charge), and is hackable with plugins.

screenshot of main interface

Features:

  • Terminal (command line) program, no browser or GUI required.
  • Send console commands from the program.
  • Rich console output formatting.
  • Add plugins to get new functionality.

Installation

npm install -g screeps-multimeter
multimeter

Configuration

Multimeter now uses the screeps unified credentials file, as used by screeps-api.

Example .screeps.yaml config file:

servers:
  main:
    host: screeps.com
    secure: true
    token: '00000000-0a0a-0a00-000a-a0000a0000a0'
  ptr:
    host: screeps.com
    secure: true
    path: '/ptr'
    token: '00000000-0a0a-0a00-000a-a0000a0000a0'
  season:
    host: screeps.com
    secure: true
    path: '/season'
    token: '00000000-0a0a-0a00-000a-a0000a0000a0'
  private:
    host: 127.0.0.1
    port: 21025
    secure: false
    username: bob
    password: password123
configs:
  multimeter:
    plugins: []
    aliases: {}
    logFilename: 'multimeter.log'

Environment Variable

You can also set SCREEPS_TOKEN as an environment variable instead of adding the token in the yaml file. If set, the token from the yaml file will take precedence over the environment variable.

This can be useful if you want to commit your .screeps.yaml to a repo, but don't want your TOKEN exposed.

Connecting to the official server

You will need to create a Screeps API token and update the config as appropriate.

Connecting to a private server

To enable access to your own private server you will need to set up screepsmod-auth and create a password. The username may be your username or email address, depending on the mod settings.

Usage

The main interface has a command line on the bottom. Type /help to see a list of the available commands. Type /quit to exit the program.

Colors and Formatting

Console coloring and formatting is made possible by blessed's tags. Some of the tags you can use are:

  • {color-fg} - Change the foreground color.
  • {color-bg} - Change the background color.
  • {bold}, {underline}, {blink}, {inverse}, {invisible} - Apply the character style.
  • {/style} - Stop using the given style, e.g. {/bold}.
  • {/} - Reset to normal characters.
  • {|} - Align the rest of the line to the right.

Colors can be specified as a name, e.g. red, blue, yellow, cyan (see colorNames from blessed for a complete list), or as a hex code, e.g. #ffff00.

Plugins

To add additional plugins, add them to a plugins array in your config file:

configs:
  multimeter:
    plugins: ["./plugins/myCustomPlugin"]

Multimeter ships with the following plugins enabled by default:

Plugin: Alias

The alias plugin can be used to easily store and access commonly used console commands. Create a new alias by using /alias NAME COMMAND. Now, /NAME will automatically expand to COMMAND. For example, this alias will let you list all damaged creeps by typing /damagedCreeps:

/alias damagedCreeps _.filter(Game.creeps, (c) => c.hits < c.hitsMax)
/damagedCreeps

Aliases can also take parameters. There will be available in variables like $1, $2, etc. The entire passed string is available as $args. For example:

/alias hitsLeft "Creep " + $1 + " has " + Game.creeps[$1].hits + " hits left"
/hitsLeft Ryan

Plugin: Watch

The watch plugin will log an expression to your console on every tick. To install it, copy watch-client.js to your script and add some code to your loop function:

var watcher = require('watch-client');
exports.loop = function() {
  // Rest of your code...

  watcher();
};

There are two ways to watch expressions. You can log it to the console normally by using /watch console EXPR. You can also log to a status bar at the bottom of the screen using /watch status EXPR. For example, /watch status _.keys(Game.creeps).length will keep a count of the number of live creeps at the bottom of the terminal.

The watch plugin will be automatically enabled for all shards with assigned CPU > 0.

Plugin: HTML

The HTML plugin allows you to style the log output using the 'style' attribute of HTML tags. It converts the values for the style attributes to the relevant blessed tags. It should work with any html tags, though has only been tested with <div>, <span>, and <a>.

It currently supports: color, background, bold, and underline:

  • Text color: style="color: #00FFFF; or style="color: blue;"
  • Background: style="background: #FFFF00;" or style="background: green;"
  • Bold: style="font-weight: bold;"
  • Underline: style="text-decoration: underline;"
<span style="color: green;">Hello, World!</span>

Multiple styles may be included in a single tag:

<span style="color: #FF0000; background: blue; font-weight: bold;">Red-on-blue bolded text</span>

Tags may be nested:

<span style="color: #FF0000;">This is red <span style="color: #00FF00;">This is green </span> <span style="font-weight: bold;">This is bold red</span></span>

//The same string, with newlines for visual clarity
<span style="color: #FF0000;">
    This is red
    <span style="color: #00FF00;">This is green </span>
    <span style="text-decoration: underline;">This is red and underlined</span>
</span>

Plugin: Logging

The logging plugin allows you to log screeps output and error output to a file. To enable logging, add logging to your config file:

configs:
  multimeter:
    logFilename: "multimeter.log"

To log errors to a separate file, add this to your multimeter config as well:

configs:
  multimeter:
    errorLogFilename: "screepsErrors.log"

Contributing

If you have feedback, bugs, or feature requests for multimeter, don't hesitate to look through the issues and add your thoughts. Please search to see if someone else has already filed a related issue before you submit a new one.

Multimeter is built for hacking! The easiest way to add a feature to multimeter is to make a new plugin for it. If you need to change something and it can't be done with a plugin, you can fork multimeter and submit a pull request. Ideally, you can add the necessary hooks so that other plugins can take advantage of them.

Note that multimeter uses lodash 4, whereas screeps still uses lodash 3.

Contributors

Multimeter has been built by a collection of users. Github provides a list of all contributors to the project.

Publishing

To release a new version:

  • Update CHANGELOG.md
  • Use npm version to update the version in package.json (npm will automatically commit and tag)
  • git push origin v$VERSION
  • npm publish
  • open https://github.com/screepers/screeps-multimeter/releases/new?tag=v$VERSION

Name the release "$VERSION released" and write the release notes using these bullet point templates:

  • Bugfix: some bug in some circumstance (by User)
  • New feature: something that used to not exist but now does (by User)

screeps-multimeter's People

Contributors

alinanova21 avatar cgamesplay avatar dependabot[bot] avatar dessix avatar fancyfurret avatar hopgoldy avatar invalidfire avatar jd0yle avatar jordansafer avatar kagurazakanyaa avatar matheusvellone avatar pyrodogg avatar systemparadox avatar tomekbielaszewski avatar topjor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

screeps-multimeter's Issues

The app fails soon after start

After start it can work a few seconds, and then fail with the following error.

TypeError: Cannot read properties of null (reading 'slice')
    at C:\Users\Alexey\AppData\Roaming\npm\node_modules\screeps-multimeter\node_modules\blessed\lib\program.js:2543:35
    at Array.forEach (<anonymous>)
    at Program._attr (C:\Users\Alexey\AppData\Roaming\npm\node_modules\screeps-multimeter\node_modules\blessed\lib\program.js:2542:11)
    at FastLog.Element._parseTags (C:\Users\Alexey\AppData\Roaming\npm\node_modules\screeps-multimeter\node_modules\blessed\lib\widgets\element.js:498:26)
    at FastLog.Element.parseContent (C:\Users\Alexey\AppData\Roaming\npm\node_modules\screeps-multimeter\node_modules\blessed\lib\widgets\element.js:393:22)
    at FastLog.Element.setContent (C:\Users\Alexey\AppData\Roaming\npm\node_modules\screeps-multimeter\node_modules\blessed\lib\widgets\element.js:335:8)
    at FastLog.Element.insertLine (C:\Users\Alexey\AppData\Roaming\npm\node_modules\screeps-multimeter\node_modules\blessed\lib\widgets\element.js:2383:8)
    at FastLog.Element.pushLine (C:\Users\Alexey\AppData\Roaming\npm\node_modules\screeps-multimeter\node_modules\blessed\lib\widgets\element.js:2526:15)
    at C:\Users\Alexey\AppData\Roaming\npm\node_modules\screeps-multimeter\src\FastLog.js:57:14
    at processTicksAndRejections (node:internal/process/task_queues:78:11)

I'm using logging plugin, my config is like this

servers:
  main:
    host: localhost
    secure: false
    port: "21025"
    username: oleksii
    password: qwerty
configs:
  multimeter:
    plugins: []  
    logFilename: "multimeter.log"

some logs may be added to the file before the crash

Multiple servers in config

Could it be made possible for multiple configurations, to select on start/via parameter for which server to launch multimeter?

Like having:

  1. mmo
  2. s+
  3. s+2
    etc.

Private server support

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?

HTML plugin can not handle function return string

I often use strings as function return values to avoid output annoying undefined in the console. But I noticed that HTML plugin can only handle strings output by console.log.

As an example, here is a global function that prints info:

global.showLog = () => {
    console.log('<span style="color: green;">Hello, World!</span>')
    return '<span style="color: green;">Hello, World!</span>'
}

The console output is:

Is this a bug or intentionally?

Strip HTML tags from output

This is awesome! one feature that would be really appreciated would be the ability to strip out html tags from the console output

Alternatively, if the HTML tags could be converted to the tags that blessed uses, that could also be a win.

App crashes when logging "<==" in console

Multimeter crashes when I log my creep state changes. My logs for standard state changes looks like this:

[21897200] creep[Builder:21896981]: idle-state ==> refilling-state
[21897200] creep[Builder:21897008]: refilling-state ==> repairing-state
[21897200] creep[Builder:21897008]: repairing-state ==> idle-state
[21897200] creep[Builder:21897008]: idle-state ==> refilling-state

but when this logs is printed in console it crashes:

[21897201] creep[Harvester:21895835]: storing-state <== moving-state

with error:
Parse Error: <== moving-state

Watch plugin only works with shard0

The watch plugin only appears to work with shard0 at the moment. We're currently doing api.memory.get('watch'), but this just defaults to shard0. If the player isn't on shard0, this just returns { ok: 1 }, but contains no other data.

The api.memory.get() and api.memory.set() functions appear to also accept a second argument for the shard name.

The quick-fix is to just use the shard defined in the config file, but perhaps this should integrate with /shard somehow.

Logging module not found. Release 1.8.3.

I am running screeps on a private server on my laptop. I have managed to setup screeps-multimeter to work from both Linux and windows on both boots of my desktop.

However, the import thing is the logging module. Unfortunately, I can't get this to work.
Here is my screeps-multimeter.json on both boots.

{
  "shard": "shard0",
  "password": "mypassword",
  "username": "myusername",
  "port": "21025",
  "hostname": "desktop-abcdef",
  "logFilename": "screeps.log",
  "plugins": ["Loging"]
}

I have also tried "Log", "log" and "logging" for plugin name.
Windows it just fails with no explanation.
Linux I get the stack trace.

piers@Mavin:~/Downloads/screeps-multimeter-1.8.3/bin$ multimeter
{ Error: Cannot find module 'Logging'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
    at Function.Module._load (internal/modules/cjs/loader.js:562:25)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at requireRelative (/usr/lib/node_modules/screeps-multimeter/node_modules/require-relative/index.js:25:15)
    at _.each.name (/usr/lib/node_modules/screeps-multimeter/src/multimeter.js:240:22)
    at arrayEach (/usr/lib/node_modules/screeps-multimeter/node_modules/lodash/index.js:1289:13)
    at Function.<anonymous> (/usr/lib/node_modules/screeps-multimeter/node_modules/lodash/index.js:3345:13)
    at Multimeter.loadPlugins (/usr/lib/node_modules/screeps-multimeter/src/multimeter.js:239:7)
    at Multimeter.run (/usr/lib/node_modules/screeps-multimeter/src/multimeter.js:175:10)
    at Promise.resolve.then.then (/usr/lib/node_modules/screeps-multimeter/bin/multimeter:19:9) code: 'MODULE_NOT_FOUND' }

On windows, I just used npm install -g screeps-multimeter to install and am not sure what version it is. On Linux I used release 1.8.3 from https://github.com/screepers/screeps-multimeter/releases - only Linux binaries seem to be there.

I noticed the logging is a very recent addition, so it might be a real bug rather than me being an idiot.

Secure is ignored in config

The connection code is ignoring the secure property in the config. This makes UCF compliant configs not work for servers with https such as the screepspl.us servers.

As an aside, why not use await ScreepsAPI.fromConfig(serverName, 'multimeter')? That will return an API instance + api.appConfig will contain the multimeter section from the screeps.yml and effectively replaces this entire block

var opts = {};
opts.token = this.config.server.token;
opts.protocol = this.config.server.token ? 'https' : this.config.server.protocol || 'http';
if (this.config.server.host) opts.hostname = this.config.server.host;
if (this.config.server.port) opts.port = this.config.server.port;
if (this.config.server.path) opts.path = this.config.server.path;
this.api = new ScreepsAPI(opts);

Cannot watch TypeError

After following the set-up process and adding watch-client.js to the code base, I'm unable to use /watch. I call watcher() at the end of my game loop.

Below you can find the console output from executing /watch status _.keys(Game.creeps).length with some additional information:

*** Connecting to (https://screeps.com:443/) ...
*** Now showing Screeps console. Type /help for help.
*** Cannot watch: TypeError: Cannot read property 'expressions' of undefined
        at multimeter.api.memory.get.then.val (C:\Users\XATEV\AppData\Roaming\npm\node_modules\screeps-multimeter\plugins\watch.js:40:72)
        at processTicksAndRejections (internal/process/next_tick.js:81:5)
<<< JSON.stringify(Memory.watch)
>>> {"expressions":{},"values":{}}
<<< typeof Memory.watch
>>> object
<<< typeof Memory.watch.expressions
>>> object
*** This is Multimeter 1.8.3, which is the latest version.
<<< watcher = require("./watch-client")
>>> function() {
      if (typeof Memory.watch !== "object") {
        Memory.watch = {};
      }
      if (typeof Memory.watch.expressions !== "object") {
        Memory.watch.expressions = {};
      }
      if (typeof Memory.watch.values !== "object") {
        Memory.watch.values = {};
      }
      _.each(Memory.watch.expressions, (expr, name) => {
        if (typeof expr !== "string") return;
        let result;
        try {
          result = eval(expr);
        } catch (ex) {
          result = "Error: " + ex.message;
        }
        if (name == "console") {
          if (typeof result !== "undefined") console.log(result);      
        } else {
          Memory.watch.values[name] =
            typeof result !== "undefined" ? result.toString() : result;
        }
      });
    }

Multiline input

Is there a way to use multyline input? Cannot paste long chunks of code like I do with original console.

Cannot npm install, native deps failing to build

On a fresh checkout of this repo if I do npm install, it fails when building the native bit of the bufferutil dependency:

sample:

../../nan/nan_object_wrap.h: In static member function ‘static void Nan::ObjectWrap::WeakCallback(const v8::WeakCallbackInfo<Nan::ObjectWrap>&)’:
../../nan/nan_object_wrap.h:124:26: error: ‘class Nan::Persistent<v8::Object>’ has no member named ‘IsNearDeath’
  124 |     assert(wrap->handle_.IsNearDeath());
      |  

full log here: https://gist.github.com/Ramblurr/57b57b6bcb40ae21944ff4c94e34d128

This is on node version v12.16.1.

Is a particular version of node needed?

Cannot login to private server, throws Error: Not Authorized

When I start the private server via the Steam UI, call setPassword("BBCorn", "1234") and then try to start multimeter using multimeter -s private, I get Error: Not Authorized.

My .screeps.yaml:

servers:
  main:
    host: screeps.com
    secure: true
    token: '00000000-0a0a-0a00-000a-a0000a0000a0'
  ptr:
    host: screeps.com
    secure: true
    path: '/ptr'
    token: '00000000-0a0a-0a00-000a-a0000a0000a0'
  season:
    host: screeps.com
    secure: true
    path: '/season'
    token: '00000000-0a0a-0a00-000a-a0000a0000a0'
  private:
    host: 127.0.0.1
    port: 21025
    secure: false
    username: BBCorn
    password: 1234
  configs:
  multimeter:
    plugins: []
    aliases: {}
    logFilename: 'multimeter.log'

It does work if I make the same request with a REST Client:
image

Am I doing something wrong?

Watch plugin appears to not be working

I installed the watch-client.js file in my code base as the instructions said. And I call it at the end of my game loop as can be seen in my Foreman.endShift() function which is called as the very last line in the loop.

Below is the console output from executing /watch status _.keys(Game.creeps).length as described in the documentation, along with some things that I did to try to debug the problem myself:

*** Cannot watch: Error: watch-client.js is not installed or out of date.                                                           
        at multimeter.api.memory.get.then.val (/Users/lee/Source/lee-dohm/screeps/node_modules/screeps-multimeter/plugins/watch.js:4
4:17)                                                                                                                               
        at process._tickCallback (internal/process/next_tick.js:68:7)
<<< JSON.stringify(Memory.watch)
>>> {"expressions":{},"values":{}}
<<< typeof Memory.watch
>>> object
<<< typeof Memory.watch.expressions
>>> object
*** This is Multimeter 1.8.0, which is the latest version.
<<< watcher = require("./watch-client")
>>> function () {
      if (typeof Memory.watch !== "object") {
        Memory.watch = {}
      }
      if (typeof Memory.watch.expressions !== "object") {
        Memory.watch.expressions = {}
      }
      if (typeof Memory.watch.values !== "object") {
        Memory.watch.values = {}
      }
      _.each(Memory.watch.expressions, (expr, name) => {
        if (typeof expr !== "string") return
        let result
        try {
          result = eval(expr)
        } catch (ex) {
          result = "Error: " + ex.message
        }
        if (name == "console") {
          if (typeof result !== "undefined") console.log(result)
        } else {
          Memory.watch.values[name] = typeof result !== "undefined" ? result.toString() : result
        }
      })
    }

Cannot start

{ Error: Cannot find module 'screeps-multimeter/plugins/alias' at Function.Module._resolveFilename (module.js:469:15) at Function.Module._load (module.js:417:25) at Module.require (module.js:497:17) at requireRelative (/home/user/.npm/lib/node_modules/screeps-multimeter/node_modules/require-relative/index.js:25:15) at _.each (/home/user/.npm/lib/node_modules/screeps-multimeter/src/multimeter.js:205:20) at arrayEach (/home/user/.npm/lib/node_modules/screeps-multimeter/node_modules/lodash/index.js:1289:13) at Function.<anonymous> (/home/user/.npm/lib/node_modules/screeps-multimeter/node_modules/lodash/index.js:3345:13) at Multimeter.loadPlugins (/home/user/.npm/lib/node_modules/screeps-multimeter/src/multimeter.js:204:7) at new Multimeter (/home/user/.npm/lib/node_modules/screeps-multimeter/src/multimeter.js:117:10) at Promise.resolve.then.then (/home/user/.npm/lib/node_modules/screeps-multimeter/bin/multimeter:13:15) code: 'MODULE_NOT_FOUND' }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.