Skip to content

Commit e1bdd5c

Browse files
feat(): update connection url and add some helpful debugging tools and notes
1 parent 17c32a2 commit e1bdd5c

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

main.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
var io = require('socket.io-client');
22

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

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

10+
socket.on('error_set_username', function(response) {
11+
console.log(`Error setting username: ${response}`);
12+
})
13+
1014
socket.on('connect', function() {
1115
console.log('Connected to server.');
1216

@@ -16,17 +20,19 @@ socket.on('connect', function() {
1620
* replacing this line with something that instead supplies the user_id via an environment variable, e.g.
1721
* var user_id = process.env.BOT_USER_ID;
1822
*/
19-
var user_id = 'my_example_bot_id';
20-
var username = 'Example Bot';
21-
23+
var user_id = 'my_example_bot'; // CHANGE ME
24+
// Bot usernames must start with [Bot] and be no longer than 18 characters
25+
var username = '[Bot]ExampleBot'; // CHANGE ME
2226
// Set the username for the bot.
2327
// This should only ever be done once. See the API reference for more details.
24-
socket.emit('set_username', user_id, username);
28+
// socket.emit('set_username', user_id, username);
2529

2630
// Join a custom game and force start immediately.
2731
// Custom games are a great way to test your bot while you develop it because you can play against your bot!
2832
var custom_game_id = 'my_private_game';
2933
socket.emit('join_private', custom_game_id, user_id);
34+
35+
3036
socket.emit('set_force_start', custom_game_id, true);
3137
console.log('Joined custom game at http://bot.generals.io/games/' + encodeURIComponent(custom_game_id));
3238

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

147153
function leaveGame() {
148154
socket.emit('leave_game');
155+
console.log('Left game');
149156
}
150157

151158
socket.on('game_lost', leaveGame);
152159

153-
socket.on('game_won', leaveGame);
160+
socket.on('game_won', leaveGame);

0 commit comments

Comments
 (0)