commit 8d50f69543a195be67ee7c0e6b26560c3b9c5f0b
parent f85c31fc3bf2a7d53c73e426cf41eb94a883c8e5
Author: Michael Savage <mikejsavage@gmail.com>
Date: Sat, 9 May 2020 12:28:16 +0300
Fix false handshake rejections and greedy handshake parsing
Diffstat:
1 file changed, 23 insertions(+), 22 deletions(-)
diff --git a/src/lua/chat.lua b/src/lua/chat.lua
@@ -56,38 +56,39 @@ local function killChat( chat )
end
local function dataCoro( chat )
- local handshake = coroutine.yield()
- local name, handshakeLen = handshake:match( "^YES:(.+)\n()" )
+ local data = ""
- if not name then
- killChat( chat )
- return
- end
-
- chat.name = name
- chat.state = "connected"
+ while true do
+ data = data .. coroutine.yield()
- mud.print( "\n#s> Connected to %s@%s:%s", chat.name, chat.address, chat.port )
+ if chat.state == "connecting" then
+ local name, len = data:match( "^YES:(.-)\n()" )
+ if name then
+ chat.name = name
+ chat.state = "connected"
- local data = handshake:sub( handshakeLen )
+ mud.print( "\n#s> Connected to %s@%s:%s", chat.name, chat.address, chat.port )
- while true do
- while true do
- local command, args = parser:match( data )
- if not command then
- break
+ data = data:sub( len )
end
+ end
+
+ if chat.state == "connected" then
+ while true do
+ local command, args = parser:match( data )
+ if not command then
+ break
+ end
- data = data:sub( args:len() + 3 )
+ data = data:sub( args:len() + 3 )
- if command == CommandBytes.all or command == CommandBytes.pm or command == CommandBytes.message then
- local message = args:match( "^\n*(.-)\n*$" )
+ if command == CommandBytes.all or command == CommandBytes.pm or command == CommandBytes.message then
+ local message = args:match( "^\n*(.-)\n*$" )
- handleChat( message:gsub( "\r", "" ) )
+ handleChat( message:gsub( "\r", "" ) )
+ end
end
end
-
- data = data .. coroutine.yield()
end
end