mudgangster

Log | Files | Refs

commit 4c82d15ab0a304d32583ff59c516fbef08c0faa6
parent 6ac79c40e2a818d23f3db3c781a6a2eb45e54549
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Thu,  6 Sep 2018 15:45:57 +0300

Chat name changing

Diffstat:
src/lua/chat.lua | 30+++++++++++++++++++-----------
1 file changed, 19 insertions(+), 11 deletions(-)

diff --git a/src/lua/chat.lua b/src/lua/chat.lua @@ -1,6 +1,8 @@ local handleChat +local chat_name = "FromDaHood" local CommandBytes = { + name_change = "\1", all = "\4", pm = "\5", message = "\7", @@ -76,7 +78,7 @@ function Client:new( sock, address, port ) table.insert( Clients, client ) - socket.send( sock, "CHAT:Hirve\n127.0.0.14050 " ) + socket.send( sock, "CHAT:%s\n127.0.0.14050 " % chat_name ) return client end @@ -112,8 +114,8 @@ local function dataHandler( client, loop, watcher ) assert( coroutine.resume( client.handler, data ) ) end -function mud.chatns( form, ... ) - local named = "\nHirve" .. form:format( ... ) +function mud.chat_no_space( form, ... ) + local named = "\n" .. chat_name .. form:format( ... ) local data = CommandBytes.all .. named:parseColours() .. "\n\255" for _, client in ipairs( Clients ) do @@ -123,7 +125,6 @@ function mud.chatns( form, ... ) end mud.printb( "#lr%s", named ) - handleChat() end function mud.chat( form, ... ) @@ -162,7 +163,6 @@ mud.alias( "/call", { mud.alias( "/hang", { [ "^(%S+)$" ] = function( name ) local client = clientFromName( name ) - if client then client:kill() end @@ -182,7 +182,6 @@ mud.alias( "/silentpm", { if client then local coloured = message:parseColours() - sendPM( client, coloured ) end end, @@ -194,12 +193,8 @@ mud.alias( "/pm", { if client then local coloured = message:parseColours() - sendPM( client, coloured ) - - local toPrint = ( "You chat to %s, '" % client.name ) .. coloured .. "'" - - handleChat( toPrint ) + mud.printb( "\n#lrYou chat to %s, \"%s\"", client.name, coloured ) end end, } ) @@ -207,6 +202,19 @@ mud.alias( "/pm", { mud.alias( "/emoteto", function( args ) end ) +mud.alias( "/chatname", function( name ) + chat_name = name + + local message = CommandBytes.name_change .. chat_name .. "\255" + for _, client in ipairs( Clients ) do + if client.state == "connected" then + socket.send( client.socket, message ) + end + end + + mud.print( "\n#s> Chat name changed to %s", chat_name ) +end ) + return { init = function( chatHandler ) handleChat = chatHandler