diff options
author | Yorhel <git@yorhel.nl> | 2010-12-06 19:35:58 +0100 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2010-12-06 19:35:58 +0100 |
commit | 44bf4252f35e028d7fa462465ea0f2a4ad40714a (patch) | |
tree | 68a8de032d87d3d8cf477d397b7e13493e72522c /main.ml | |
parent | 26dee6703f180bd471fca367fb07a7e826be13d8 (diff) |
Added login window and made many more changes
We're still in the alpha phase of an experimental program, don't expect
me to properly document my changes. -.-;
Diffstat (limited to 'main.ml')
-rw-r--r-- | main.ml | 66 |
1 files changed, 35 insertions, 31 deletions
@@ -9,43 +9,46 @@ let pollfunc sock read 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 _ = + ignore (GtkMain.Main.init ()); + let win = new Gui.mainwin () in + 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) + in -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 :(" - ) + api#set_linefunc (Some (fun sent str -> + win#add_debuglog (if sent then `write else `read) + (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 + )); + api#set_disconnectfunc (Some win#set_loggedout); -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#login#set_on_connect (fun anon user pass -> + api#connect (fun ip port -> + win#add_debuglog `status ("Connected to " ^ (Unix.string_of_inet_addr ip) ^ ":" ^ (string_of_int port)); + win#login#set_connected; + let u = if anon = true then VndbApi.Anonymous else VndbApi.User (user, pass) in + let du = if anon = true then "Anon" else user in + api#login u (fun r -> + match r with + | VndbApi.ROK -> win#set_loggedin du + | VndbApi.RError ("auth", msg, _) -> + win#login#failed ("Login failed: "^msg); + api#disconnect + | _ -> + win#login#failed "Login failed for some odd reason. :("; + api#disconnect + ) + ) (fun _ _ msg -> win#login#failed ("Connection failed: "^msg)) ); - win#set_debug_docmd (fun str -> + win#set_on_debug_cmd (fun str -> win#statusmsg "Executing custom command..."; api#addcmd str (fun r -> win#statusmsg "Custom command finished."; @@ -58,5 +61,6 @@ let _ = ) ); + win#show; GMain.Main.main () |