mudgangster

Tiny, scriptable MUD client
Log | Files | Refs | README

commit 43df96ee7d42ed866d034bd372ccb80a8e3e3b42
parent c27d4b9fd265a81ec55ae8f5df134d619719bc97
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Sat,  9 May 2020 12:27:19 +0300

Timeout chats that don't complee a handshake

Diffstat:
Msrc/lua/chat.lua | 15++++++++++++---
Msrc/lua/main.lua | 6+++---
2 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/src/lua/chat.lua b/src/lua/chat.lua @@ -148,6 +148,8 @@ local function call( address, port ) state = "connecting", handler = coroutine.create( dataCoro ), + + called_at = os.time(), } assert( coroutine.resume( chat.handler, chat ) ) @@ -206,9 +208,6 @@ mud.alias( "/pm", { end, } ) -mud.alias( "/emoteto", function( args ) -end ) - mud.alias( "/chatname", function( name ) chatName = name @@ -223,6 +222,16 @@ mud.alias( "/chatname", function( name ) handleChat() end ) +mud.interval( function() + local now = os.time() + for i = #Chats, 1, -1 do + if Chats[ i ].state == "connecting" and now - Chats[ i ].called_at >= 10 then + mud.print( "\n#s> No response from %s", Chats[ i ].name ) + killChat( Chats[ i ] ) + end + end +end, 5 ) + return { init = function( chatHandler ) handleChat = chatHandler diff --git a/src/lua/main.lua b/src/lua/main.lua @@ -26,9 +26,6 @@ local socket_api = { local socket_data_handler = require( "socket" ).init( socket_api ) -require( "mud" ).init( handlers.data ) -require( "chat" ).init( handlers.chat ) - mud.printMain = printMain mud.newlineMain = newlineMain mud.printChat = printChat @@ -39,6 +36,9 @@ mud.now = get_time mud.last_human_input_time = mud.now() +require( "mud" ).init( handlers.data ) +require( "chat" ).init( handlers.chat ) + mud.alias( "/font", { [ "^(.-)%s+(%d+)$" ] = function( name, size ) size = tonumber( size )