From 34e9370c175c94ca611f14d226234a3923004db5 Mon Sep 17 00:00:00 2001 From: Todd Robinson Date: Thu, 11 Aug 2022 13:25:21 -0400 Subject: [PATCH] feat(): update connection url and add some helpful debugging tools and notes --- main.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/main.js b/main.js index 0a74f2e..d311432 100644 --- a/main.js +++ b/main.js @@ -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.'); @@ -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); @@ -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)); @@ -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); \ No newline at end of file +socket.on('game_won', leaveGame);