Commit 895ead72 authored by Colomban Wendling's avatar Colomban Wendling
Browse files

Dummy bot: review a bit the thing to connect to a server

parent 2621e052
......@@ -5,13 +5,33 @@
*/
public class Main
public class Bot
{
public Main (MainLoop loop,
string nickname)
private MainLoop loop = null;
private OVCCClient.Player player = null;
public bool join (OVCCClient.Server server)
throws Error;
{
var player = new OVCCClient.Player (nickname);
var game = new OVCCClient.Game ();
uint player_suffix = 7;
OVCCClient.Game game = null;
/* connect to the server, choosing an available nickname */
while (true) {
try {
player = new OVCCClient.Player ("Clever bot %3u", player_suffix);
server.connect (player); /* may throw a rejection */
break;
} catch OVCCClient.ServerError.NICKNAME_IN_USE {
} catch OVCCClient.ServerError.MISSING_AUTHENTICATION {
}
}
/* join an open table */
if (server.open_tables.length > 0) {
player.join (server.open_tables[0]); /* may throw a rejection */
} else {
throw new OVCCClient.ServerError.NO_TABLE_OPEN ("failed to join a game");
}
/* when game is finished, just stop */
game.finished.connect (() => {
......@@ -56,12 +76,23 @@ public class Main
}
});
}
public Bot (MainLoop l)
{
loop = l;
}
}
public void main (string args)
{
var l = new MainLoop ();
var m = Main (l, "A clever bot");
var loop = new MainLoop ();
var bot = new Bot (loop);
var server = new OVCCClient.Server ("localhost", 9007);
l.run ();
try {
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