From 7365dd27e684543ba5d9b6e1faf0cfd808c188d1 Mon Sep 17 00:00:00 2001 From: Marco Hladik Date: Tue, 30 Jun 2020 18:03:37 +0200 Subject: [PATCH] Menu: Close cached TCP socket and fix timeout dialog --- src/menu-fn/m_chatrooms.cpp | 27 ++++++++++++--------------- src/menu-fn/tcp.cpp | 6 ++++-- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/src/menu-fn/m_chatrooms.cpp b/src/menu-fn/m_chatrooms.cpp index e8741904..9066ba87 100644 --- a/src/menu-fn/m_chatrooms.cpp +++ b/src/menu-fn/m_chatrooms.cpp @@ -142,9 +142,6 @@ irc_receive(string buffer) :eukara!eukara@irc.won.net PRIVMSG Frank :hello */ - print(buffer); - print("\n"); - if (substring(buffer, 0, 4) == "PING") { irc_send(sprintf("PONG :%s\n", substring(buffer, 6, -1))); return; @@ -233,6 +230,9 @@ irc_receive(string buffer) } } cr_print(sprintf("%s is now known as %s", src, argv(2))); + default: + dprint(buffer); + dprint("\n"); } } @@ -396,29 +396,26 @@ void menu_chatrooms_draw(void) g_ircroom.m_iStatus = TRUE; } - if (TCP_GetState(&tcp_irc) == STATE_CONNECTED) { - drawsetcliparea(g_menuofs[0] + 33, g_menuofs[1] + 104, 450,331); - drawresetcliparea(); - } else if (TCP_GetState(&tcp_irc) == STATE_CONNECTING) { + if (TCP_GetState(&tcp_irc) == STATE_CONNECTING || !g_ircroom.m_iReady) { /* connecting... dialog */ cr_dgConnect.Draw(); WField_Static(162, 180, m_reslbl[IDS_WON_LOGIN], 320, 260, col_prompt_text, 1.0f, 2, font_label_p); + WField_Static(162, 200, sprintf("%d seconds remaining...\n", timeout), 320, 260, + col_prompt_text, 1.0f, 2, font_label_p); WField_Static(162, 280, sprintf(m_reslbl[IDS_CHAT_JOIN], g_ircroom.m_strChannel), 320, 260, col_prompt_title, 1.0f, 2, font_label_p); timeout -= frametime; if (timeout < 0.0) { + timeout = 10.0f; + TCP_Disconnect(&tcp_irc); cr_btndone_start(); } - } - - if (!g_ircroom.m_iReady) { - cr_dgConnect.Draw(); - WField_Static(162, 180, "Connected to Frag-Net", 320, 260, - col_prompt_text, 1.0f, 2, font_label_p); - WField_Static(162, 280, sprintf("Loading room info for %s", g_ircroom.m_strChannel), 320, 260, - col_prompt_title, 1.0f, 2, font_label_p); + } else if (TCP_GetState(&tcp_irc) == STATE_CONNECTED) { + drawsetcliparea(g_menuofs[0] + 33, g_menuofs[1] + 104, 450,331); + drawresetcliparea(); + timeout = 10.0f; } /* draw the labels */ diff --git a/src/menu-fn/tcp.cpp b/src/menu-fn/tcp.cpp index 8ee293ba..2b4ed568 100644 --- a/src/menu-fn/tcp.cpp +++ b/src/menu-fn/tcp.cpp @@ -38,10 +38,11 @@ TCP_Connect(tcpinfo_t *in, string path) if (in.m_fSocket < 0) { dprint(sprintf("^1TCP_Connect^7: Unable to access %s\n", path)); + } else { + /* we got at least this far */ + in.m_iState = STATE_CONNECTING; } - /* we got at least this far */ - in.m_iState = STATE_CONNECTING; return (int)in.m_fSocket; } @@ -53,6 +54,7 @@ TCP_Disconnect(tcpinfo_t *in) in.m_iState = STATE_DISCONNECTED; fclose(in.m_fSocket); + in.m_fSocket = -1; } int