From 8d9ce1e410ac514918c923947b002039116278d7 Mon Sep 17 00:00:00 2001 From: Jon Michael Aanes Date: Fri, 8 Mar 2019 14:30:38 +0100 Subject: [PATCH] Fized issue with connection encountered on slow internet connections. --- tiger-bot.tig | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/tiger-bot.tig b/tiger-bot.tig index 2c893ba..3853b83 100644 --- a/tiger-bot.tig +++ b/tiger-bot.tig @@ -154,11 +154,16 @@ let /* Parsing util */ , num_parameters = 2 } end - function ping_respond () = + function wait_for_msg (cmd: string): message = let var msg := read_next_message() + in if msg.command <> cmd + then wait_for_msg(cmd) + else msg + end - in if msg.command = "PING" - then send_msg(cmd1("PONG", msg.parameters[0])) + function ping_respond () = + let var msg := wait_for_msg("PING") + in send_msg(cmd1("PONG", msg.parameters[0])) end function quit(quit_msg: string) = @@ -212,14 +217,20 @@ let /* Parsing util */ ; main_loop() end -in /* Establish connection */ - print("USER tiger-bot * * : yo\n") +in () + /* Establish connection */ + /* At this point, we can register */ + ; print("USER tiger-bot * * : yo\n") ; print("NICK bot-fucker\n") ; flush() - /* Respond to PING */ + /* Wait for first PING, and respond to it */ ; ping_respond() + + /* Wait for 001; so we know that we have been connected and + * registered */ ; have_registered := 1 + ; wait_for_msg("001") /* Connect to channel and greet */ ; send_msg(cmd1("JOIN", "#bot-test"))