mudgangster

Log | Files | Refs

commit 2a9fbad6d7e8b0d34fbfb9cf921f06649de47f47
parent a1a83bc5df419608d390f42e609999c217b43126
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Sat,  1 Aug 2015 17:02:48 +0200

Add a message when disconnecting from chat

Diffstat:
chat.lua | 20+++++++++++++++++++-
1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/chat.lua b/chat.lua @@ -85,11 +85,29 @@ function Client:new( socket, address, port ) return client end +function Client:kill() + if self.state == "killed" then + return + end + + mud.print( "\n#s> Disconnected from %s!", self.name ) + + self.state = "killed" + self.socket:shutdown() + + for i, client in ipairs( Clients ) do + if client == self then + table.remove( Clients, i ) + break + end + end +end + local function dataHandler( client, loop, watcher ) local _, err, data = client.socket:receive( "*a" ) if err == "closed" then - client.socket:shutdown() + client:kill() watcher:stop( loop ) return