1
1
var io = require ( 'socket.io-client' ) ;
2
2
3
- var socket = io ( 'http ://botws .generals.io' ) ;
3
+ var socket = io ( 'https ://bot .generals.io' ) ;
4
4
5
5
socket . on ( 'disconnect' , function ( ) {
6
6
console . error ( 'Disconnected from server.' ) ;
7
7
process . exit ( 1 ) ;
8
8
} ) ;
9
9
10
+ socket . on ( 'error_set_username' , function ( response ) {
11
+ console . log ( `Error setting username: ${ response } ` ) ;
12
+ } )
13
+
10
14
socket . on ( 'connect' , function ( ) {
11
15
console . log ( 'Connected to server.' ) ;
12
16
@@ -16,17 +20,19 @@ socket.on('connect', function() {
16
20
* replacing this line with something that instead supplies the user_id via an environment variable, e.g.
17
21
* var user_id = process.env.BOT_USER_ID;
18
22
*/
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
22
26
// Set the username for the bot.
23
27
// 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);
25
29
26
30
// Join a custom game and force start immediately.
27
31
// Custom games are a great way to test your bot while you develop it because you can play against your bot!
28
32
var custom_game_id = 'my_private_game' ;
29
33
socket . emit ( 'join_private' , custom_game_id , user_id ) ;
34
+
35
+
30
36
socket . emit ( 'set_force_start' , custom_game_id , true ) ;
31
37
console . log ( 'Joined custom game at http://bot.generals.io/games/' + encodeURIComponent ( custom_game_id ) ) ;
32
38
@@ -146,8 +152,9 @@ socket.on('game_update', function(data) {
146
152
147
153
function leaveGame ( ) {
148
154
socket . emit ( 'leave_game' ) ;
155
+ console . log ( 'Left game' ) ;
149
156
}
150
157
151
158
socket . on ( 'game_lost' , leaveGame ) ;
152
159
153
- socket . on ( 'game_won' , leaveGame ) ;
160
+ socket . on ( 'game_won' , leaveGame ) ;
0 commit comments