-- Sends a build/binary fingerprint to the server right after login, so the
-- server-side handler (extendedopcode.lua, opcode ExtendedIds.ClientOrigin)
-- can flag connections from an unknown or modified client. This is a
-- "raise the bar" measure, not a hard guarantee: since this whole client is
-- open source, anyone willing to read this file can reproduce the expected
-- value in their own modified build. It still catches unmodified bots/older
-- builds and off-the-shelf tampered clients that don't bother spoofing it.

local function sendOrigin()
    local protocolGame = g_game.getProtocolGame()
    if not protocolGame then
        return false
    end

    -- Pipe-delimited, not JSON: the server-side TFS Lua environment has no
    -- json library available, and this is simple enough not to need one.
    local payload = table.concat({
        g_app.getBuildCommit(),
        g_app.getBuildRevision(),
        g_resources.selfChecksum(),
        g_game.getOs(),
    }, "|")
    protocolGame:sendExtendedOpcode(ExtendedIds.ClientOrigin, payload)
    return true
end

function onGameStart()
    sendOrigin()
end

function init()
    connect(g_game, {
        onGameStart = onGameStart
    })
end

function terminate()
    disconnect(g_game, {
        onGameStart = onGameStart
    })
end
