diff --git a/otpgo/lua/MsgTypes.lua b/otpgo/lua/MsgTypes.lua index 4238706..7a7ea74 100644 --- a/otpgo/lua/MsgTypes.lua +++ b/otpgo/lua/MsgTypes.lua @@ -5,4 +5,6 @@ CLIENT_HEARTBEAT = 52 -- new toontown specific login message, adds last logged in, and if child account has parent acount CLIENT_LOGIN_TOONTOWN = 125 -CLIENT_DISCONNECT_GENERIC = 1 +CLIENT_DISCONNECT_GENERIC = 1 +CLIENT_DISCONNECT_RELOGIN = 100 +CLIENT_DISCONNECT_BAD_VERSION = 125 diff --git a/otpgo/lua/ToontownClient.lua b/otpgo/lua/ToontownClient.lua index e5b24ba..8e70ad0 100644 --- a/otpgo/lua/ToontownClient.lua +++ b/otpgo/lua/ToontownClient.lua @@ -11,7 +11,33 @@ function receiveDatagram(client, dgi) client:handleHeartbeat() elseif msgType == CLIENT_DISCONNECT then client:handleDisconnect() + elseif msgType == CLIENT_LOGIN_TOONTOWN then + handleLoginToontown(client, dgi) else client:sendDisconnect(CLIENT_DISCONNECT_GENERIC, string.format("Unknown message type: %d", msgType), true) end end + +function handleLoginToontown(client, dgi) + local playToken = dgi:readString() + local version = dgi:readString() + local hash = dgi:readUint32() + local tokenType = dgi:readInt32() + local wantMagicWords = dgi:readString() + + if client:authenticated() then + client:sendDisconnect(CLIENT_DISCONNECT_RELOGIN, "Authenticated client tried to login twice!", true) + return + end + + -- Check if version and hash matches + if version ~= SERVER_VERSION then + client:sendDisconnect(CLIENT_DISCONNECT_BAD_VERSION, string.format("Client version mismatch: client=%s, server=%s", version, SERVER_VERSION), true) + return + end + + if hash ~= DC_HASH then + client:sendDisconnect(CLIENT_DISCONNECT_BAD_VERSION, string.format("Client DC hash mismatch: client=%d, server=%d", hash, DC_HASH), true) + return + end +end