screepers/node-screeps-api

Name: node-screeps-api

Owner: screepers

Description: Node.js API For screeps

Created: 2016-07-29 20:04:47.0

Updated: 2018-02-02 02:17:29.0

Pushed: 2018-01-08 16:50:53.0

Homepage: null

Size: 256

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Screeps API

This is a nodejs API for the game Screeps

JavaScript Style Guide License Version Downloads CircleCI

npm

Notice on authentication

As of 12/29/2017 Screeps now uses auth tokens obtained via your screeps account settings. User/pass auth will stop working February 1, 2018! Screeps Announcement

Basic usage

As of 1.0, all functions return Promises

t { ScreepsAPI } = require('screeps-api');
t fs = require('fs');

ll options are optional
t api = new ScreepsAPI({
ken: 'Your Token from Account/Auth Tokens'
otocol: 'https',
stname: 'screeps.com',
rt: 443,
th: '/' // Do no include '/api', it will be added automatically


ou can overwrite parameters if needed
auth('screeps@email.com','notMyPass',{
otocol: 'https',
stname: 'screeps.com',
rt: 443,
th: '/' // Do no include '/api', it will be added automatically


f you want to point to the screeps PTR (Public Test Realm),
ou can set the 'path' option to '/ptr' and it will work fine.

ump Memory
memory.get()
hen(memory => {
fs.writeFileSync('memory.json', JSON.stringify(memory))

atch(err => console.error(err));


ump Memory Path
memory.get('rooms.W0N0')
hen(memory => {
fs.writeFileSync('memory.rooms.W0N0.json', JSON.stringify(memory))

atch(err => console.error(err));

et user info
me().then((user)=>console.log(user))

ocket API

socket.connect()
vents have the structure of:

 channel: 'room',
 id: 'E3N3', // Only on certain events
 data: { ... }

socket.on('connected',()=>{
// Do stuff after conntected

socket.on('auth',(event)=>{
event.data.status contains either 'ok' or 'failed'
// Do stuff after auth


vents: (Not a complete list)
onnected disconnected message auth time protocol package subscribe unsubscribe console

ubscribtions can be queued even before the socket connects or auths,
lthough you may want to subscribe from the connected or auth callback to better handle reconnects

socket.subscribe('console')
socket.on('console',(event)=>{
event.data.messages.log // List of console.log output for tick



tarting in 1.0, you can also pass a handler straight to subscribe!
socket.subscribe('console', (event)=>{
event.data.messages.log // List of console.log output for tick


ore common examples
socket.subscribe('cpu',(event)=>console.log('cpu',event.data))
code.get('default').then(data=>console.log('code',data))
code.set('default',{
main: 'module.exports.loop = function(){ ... }'

socket.subscribe('memory/stats',(event)=>{
console.log('stats',event.data)

socket.subscribe('memory/rooms.E0N0',(event)=>{
console.log('E0N0 Memory',event.data)

Endpoint documentation

Server endpoints are listed in the docs folder:


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.