Commit dfab8f7a authored by Jonathan Michalon's avatar Jonathan Michalon
Browse files

bot: fix bool vs. exception inconcistency and nickname loop

parent 6055c5c9
......@@ -17,29 +17,32 @@ public class Bot
uint player_suffix = 7;
OVCCClient.Game game = null;
/* Create our player instance */
player = new OVCC.Player ("""Clever bot %3u""".printf (player_suffix));
/* connect to the server, choosing an available nickname */
debug ("Trying connection...");
while (true) {
debug ("Trying to connect to server...");
do {
/* Create our player instance */
player = new OVCC.Player ("""Clever bot %3u""".printf (player_suffix));
try {
client = new OVCCClient.Client (player);
server.connect_to (player); /* may throw a rejection */
break;
} catch (OVCCClient.ServerError.NICKNAME_IN_USE e) {
player_suffix++;
} catch (OVCCClient.ServerError.MISSING_AUTHENTICATION e) {
throw e; /* avoid infinite loop */
}
}
debug ("Connected");
while (true);
debug ("Connected with player_suffix = %u", player_suffix);
/* join any open table */
debug ("Trying to join...");
debug ("Trying to join a table...");
try {
game = server.join_table (-1);
} catch (OVCCClient.ServerError.NO_OPEN_TABLE e) {
warning ("Cannot join an open table: %s", e.message);
} catch (Error e) {
server.disconnect_from ();
return false;
throw e;
}
debug ("Joined");
......@@ -111,10 +114,8 @@ public int main (string[] args)
var server = new OVCCClient.Server ("localhost", 0xdead);
try {
if (bot.join (server))
{
loop.run ();
}
bot.join (server);
loop.run ();
} catch (Error e) {
warning ("Failed to join on the server: %s", e.message);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment