Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
var io = require('socket.io-client');

var socket = io('http://botws.generals.io');
var socket = io('https://bot.generals.io');

socket.on('disconnect', function() {
console.error('Disconnected from server.');
process.exit(1);
});

socket.on('error_set_username', function(response) {
console.log(`Error setting username: ${response}`);
})

socket.on('connect', function() {
console.log('Connected to server.');

Expand All @@ -16,9 +20,9 @@ socket.on('connect', function() {
* replacing this line with something that instead supplies the user_id via an environment variable, e.g.
* var user_id = process.env.BOT_USER_ID;
*/
var user_id = 'my_example_bot_id';
var username = 'Example Bot';

var user_id = 'my_example_bot'; // CHANGE ME
// Bot usernames must start with [Bot] and be no longer than 18 characters
var username = '[Bot]ExampleBot'; // CHANGE ME
// Set the username for the bot.
// This should only ever be done once. See the API reference for more details.
socket.emit('set_username', user_id, username);
Expand All @@ -27,6 +31,8 @@ socket.on('connect', function() {
// Custom games are a great way to test your bot while you develop it because you can play against your bot!
var custom_game_id = 'my_private_game';
socket.emit('join_private', custom_game_id, user_id);


socket.emit('set_force_start', custom_game_id, true);
console.log('Joined custom game at http://bot.generals.io/games/' + encodeURIComponent(custom_game_id));

Expand Down Expand Up @@ -146,8 +152,9 @@ socket.on('game_update', function(data) {

function leaveGame() {
socket.emit('leave_game');
console.log('Left game');
}

socket.on('game_lost', leaveGame);

socket.on('game_won', leaveGame);
socket.on('game_won', leaveGame);