summaryrefslogtreecommitdiff
path: root/main.ml
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2010-12-04 14:55:05 +0100
committerYorhel <git@yorhel.nl>2010-12-04 14:55:05 +0100
commit26dee6703f180bd471fca367fb07a7e826be13d8 (patch)
tree4d826b8094acb2c53f3c27d9a71449861645c375 /main.ml
Initial commit
Diffstat (limited to 'main.ml')
-rw-r--r--main.ml62
1 files changed, 62 insertions, 0 deletions
diff --git a/main.ml b/main.ml
new file mode 100644
index 0000000..6bb5313
--- /dev/null
+++ b/main.ml
@@ -0,0 +1,62 @@
+
+(* blocking pollfunc, useful for testing the vndbApi outside of GTK *
+let pollfunc sock read cb =
+ let _,_,_ = Unix.select
+ (if read then [sock] else [])
+ (if read then [] else [sock])
+ [] (-.1.0) in
+ cb ();;
+*)
+
+
+let _ = ignore (GtkMain.Main.init ())
+let win = new Gui.mainwin ()
+let api = new VndbApi.connection
+ (fun sock read cb ->
+ ignore (GMain.Io.add_watch ~cond:[if read then `IN else `OUT]
+ ~callback:(fun _ -> cb (); false) (Glib.Io.channel_of_descr sock)))
+ (fun sec cb -> win#set_throttled (sec+5) cb)
+
+
+let debugline sent str =
+ win#add_debuglog (if sent then `write else `read) str;
+ (Str.replace_first (Str.regexp "\\(\"password\"[\r\n\t ]*:[\r\n\t ]*\"\\)[^\"]+\"") "\\1<secret>\"" str);
+ win#add_bandwidth ((String.length str)+1);
+ if not sent then win#incr_cmd_count
+
+
+let apiconnected ip port =
+ win#statusmsg ("Connected to " ^ (Unix.string_of_inet_addr ip) ^ ":" ^ (string_of_int port));
+ api#login "user" "pass" (fun r ->
+ match r with
+ | VndbApi.ROK -> win#statusmsg "Login successful."
+ | VndbApi.RError ("auth", msg, _) -> win#statusmsg ("Login failed: "^msg)
+ | _ -> win#statusmsg "Login failed :("
+ )
+
+
+let _ =
+ win#show;
+ win#statusmsg "Welcome to the Serika Testing Grounds!";
+
+ api#set_linefunc (Some debugline);
+ api#connect apiconnected (fun _ _ msg ->
+ print_endline ("Connection failed: "^msg);
+ exit 1
+ );
+
+ win#set_debug_docmd (fun str ->
+ win#statusmsg "Executing custom command...";
+ api#addcmd str (fun r ->
+ win#statusmsg "Custom command finished.";
+ match r with
+ | VndbApi.RError _ ->
+ win#add_debuglog `status ("Server replied with an error. You may want "^
+ "to check http://vndb.org/d11 for information on the available commands "^
+ "and error messages.")
+ | _ -> ()
+ )
+ );
+
+ GMain.Main.main ()
+