Maybe you’d enjoy toying with the API some? Then I have a task for you!
Launch preparation requires some stress testing on the staging server (soon to come). For this, I was thinking “bots”. Lots of bots!
Wish to help create a bot for stress testing? Just tell me and I’ll gladly explain more about the API!
/Accipiter
Example
We will use nodejs for the bots. Let’s tease with an example.
Just change to your own username and the base64(sha256("mysecret"))
of your password:
const ResClient = require('resclient').default;
const WebSocket = require('isomorphic-ws');
// Create the API client.
// See: https://resgate.io/docs/writing-clients/resclient/
let client = new ResClient(() => new WebSocket('wss://api.wolfery.com', {
origin: 'https://wolfery.com'
}));
// Set the authentication to use when connecting to the API.
// Since we have no JWT token, we use password login.
// The password is sha256 hashed and base64 encoded.
client.setOnConnect(() => client.authenticate('auth', 'login', {
name: 'myloginname',
pass: 'ZSx9xofZjJiJME7S5AjHS2EehqQMqlHEtD8d1ZE8XNA=' // mysecret
}).catch(err => console.error("Failed to login: ", err)));
// Get the main player model.
client.call('core', 'getPlayer').then(player => {
// Call on (empty listener) to keep ResClient subscribing to player events.
player.on();
// Promise to a controlled character
let promise = null;
if (player.controlled.length > 0) {
// If we already control a character, we use that one first.
promise = Promise.resolve(player.controlled.atIndex(0))
} else if (player.chars.length > 0) {
// If we have owned characters, we control one and wake 'em up
promise = player.call('controlChar', { charId: player.chars.atIndex(0).id });
} else {
promise = Promise.reject("No owned characters");
}
// Ensure the controlled character is awake
promise.then(char => {
return (char.state == 'awake'
? char
: char.call('wakeup')
).then(() => {
// Say and repeat every 10 seconds
sayAndRepeat(char, "I am a bot", 10000);
});
});
});
// sayAndRepeat makes a character repeat something over and over.
function sayAndRepeat(char, msg, duration) {
// Say something
char.call('say', { msg: msg });
// Wait and say it again after a while
setTimeout(() => sayAndRepeat(char, msg, duration), duration);
}
Note
To run the example above, you need nodejs and the npm packages:
resclient
,isomorphic-ws
andws