Commit 5e98d9ee authored by Jonathan Michalon's avatar Jonathan Michalon
Browse files

clients/bot: use new table listing/selection mechanism

Use the new table listing/selection mechanism from previous commits in bot.
This adds also an optional interactive mode accessible through -i.
parent 080f399f
......@@ -5,13 +5,15 @@
public class Bot : OVCCClient.Client
private MainLoop loop = null;
private MainLoop loop = null;
private bool interactive = false;
private OVCC.SigQueue sigqueue = new OVCC.SigQueue ();
public async bool join (OVCCClient.Server server)
throws Error
uint player_suffix = 7;
int table_to_join = -1;
/* connect to the server */
yield bind_to (server);
......@@ -34,10 +36,29 @@ public class Bot : OVCCClient.Client
debug ("Logged in with player_suffix = %u", player_suffix);
/* join any open table */
debug ("Trying to join a table...");
/* join an open table */
var list = yield server.enumerate_tables(OVCCClient.TablesFilter.OPEN);
Please register or sign in to reply
print ("List of open tables:\n");
var idx = 0;
foreach (var d in list) {
print (" - %02i: %s\n", idx, d.to_string());
if (list.length == 0) {
  • this should probably be used around the listing itself, is doesn't make so much sense to do that after listing, does it?

    if (list.length == 0) {
      print ("meh :(\n");
    } else {
      print ("Open tables:\n");
      foreach (var d in list) {
        print ("\t ...");
  • Idea was to keep the header printed in all cases to get consistent output and just fill a placeholder when empty, and yes could be if/else but output is exact same then?

  • Mmm, OK if you prefer having the same heading in the empty cases, why not.

Please register or sign in to reply
print ("(currently no table)\n");
print ("What table index to join? (-1 or empty for any open table) ");
  • it doesn't make sense to ask if it's not interactive, does it?

  • I thought that it would make sense when reading logs to see what step this was, just shortcut the interactive read and print the default answer as if it was typed in?

  • Heh, I myself though this would be confusing when actually no question is asked :) But I don't mind, and yeah that could kinda serve as seeing what code ran when debugging… so whichever you like best.

Please register or sign in to reply
string? line = interactive ? stdin.read_line () : "";
if (line != null && line != "") {
table_to_join = int.parse(line);
debug ("Trying to join table %i...", table_to_join);
try {
yield join_table (-1);
yield join_table (table_to_join);
} catch (Error e4) {
leave ();
throw e4;
......@@ -144,9 +165,10 @@ public class Bot : OVCCClient.Client
loop.quit ();
public Bot (MainLoop l)
public Bot (MainLoop l, bool i = false)
loop = l;
interactive = i;
......@@ -179,21 +201,34 @@ private static void setup_signal_handlers ()
Bot bot = null;
// has to be outside of main to be const ?!
  • what do you mean, "const"? you don't want them const as you want them modified through CLI?

  • but yeah, should rather not be at the root scope…

  • const as ref in the array of OptionEntry later which is const itself. Otherwise won't compile at all. Seems more like static to me but well…

  • 😕 ok if Vala isn't happy otherwise…

Please register or sign in to reply
unowned string host = "localhost";
uint16 port = 0xDEAD;
bool interactive = false;
public int main (string[] args)
var host = "localhost";
uint16 port = 0xdead;
if (args.length > 1) {
host = args[1];
if (args.length > 2) {
port = (uint16)int.parse (args[2]);
const OptionEntry[] options = {
{ "server", 's', 0, OptionArg.STRING, ref host, "Use this server", "SERVER" },
{ "port", 'p', 0, OptionArg.INT, ref port, "Use this port number", "PORT" },
{ "interactive", 'i', 0, OptionArg.NONE, ref interactive, "Be interactive", null },
{ null }
try {
var opt_context = new OptionContext ("- OVCC Bot");
opt_context.set_help_enabled (true);
opt_context.add_main_entries (options, null);
opt_context.parse (ref args);
} catch (OptionError e) {
print ("error: %s\n", e.message);
print ("Run '%s --help' to see a full list of available command line options.\n", args[0]);
Please register or sign in to reply
return 0;
var loop = new MainLoop ();
var server = new OVCCClient.Server (host, port);
bot = new Bot (loop);
bot = new Bot (loop, interactive);
setup_signal_handlers ();
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