65 lines
1.9 KiB
Lua
65 lines
1.9 KiB
Lua
package.path = package.path .. ";lua/?.lua"
|
|
|
|
function readAccountBridge()
|
|
local json = require("json")
|
|
local io = require("io")
|
|
|
|
-- TODO: Custom path.
|
|
f, err = io.open("databases/accounts.json", "r")
|
|
if err then
|
|
print("ToontownClient: Returning empty table for account bridge")
|
|
return {}
|
|
end
|
|
|
|
decoder = json.new_decoder(f)
|
|
result, err = decoder:decode()
|
|
f:close()
|
|
assert(not err, err)
|
|
print("ToontownClient: Account bridge successfully loaded.")
|
|
return result
|
|
end
|
|
|
|
ACCOUNT_BRIDGE = readAccountBridge()
|
|
|
|
-- Load message types
|
|
dofile("lua/MsgTypes.lua")
|
|
|
|
function receiveDatagram(client, dgi)
|
|
-- Client received datagrams
|
|
msgType = dgi:readUint16()
|
|
|
|
if msgType == CLIENT_HEARTBEAT then
|
|
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
|