local Config = require("Config")
local Json = require("common.Json")
local Define = require("platform.Define")
local CommonDefine = require("common.CommonDefine")
local PfLogic = require("platform.PfLogic")

function quit(human,code)
	if Config.IS_WINDOWS then
		return
	end

	if not PfLogic.isQQ()  then
		return
	end
	if code == CommonDefine.DISCONNECT_NORMAL then
		return
	end

	s2aParam = {}
    local now = os.time()

    local pf_info = human.pf_info
    if (pf_info == nil) then
        return
    end

	api_param = {}
    api_param.userip = human.ip or ""
    api_param.time = now
    api_param.pf = pf_info.pf
    api_param.worldid = pf_info.serverid
    --api_param.opuid = human.db._id
    api_param.opopenid = pf_info.openid
    api_param.onlinetime = now - human.db.lastLoginTime

    api_param.level = human.db.lv
    api_param.actionid = 9

    s2aParam.api_param = api_param

	_G.thread_http.send(Define.REPORT_QUIT_PHP,Json.Encode(s2aParam))
end

function login(human)
	if not PfLogic.isQQ() then
		return
	end
	
	s2aParam = {}
    local now = os.time()

    local pf_info = human.pf_info
    if (pf_info == nil) then
        return
    end

	api_param = {}
    api_param.userip = human.ip
    api_param.time = now
    api_param.pf = pf_info.pf
    api_param.worldid = pf_info.serverid
    api_param.opopenid = pf_info.openid

    api_param.level = human.db.lv
    api_param.actionid = 1

    s2aParam.api_param = api_param

	_G.thread_http.send(Define.REPORT_LOGIN_PHP,Json.Encode(s2aParam))
end

function register(human)
	if not PfLogic.isQQ() then
		return
	end
	
	s2aParam = {}
    local now = os.time()

    local pf_info = human.pf_info
    if (pf_info == nil) then
        return
    end

	api_param = {}
    api_param.userip = human.ip
    api_param.time = now
    api_param.pf = pf_info.pf
    api_param.worldid = pf_info.serverid
    api_param.opopenid = pf_info.openid
    s2aParam.api_param = api_param

    api_param.level = human.db.lv
    api_param.actionid = 2

    _G.thread_http.send(Define.REPORT_REG_PHP,Json.Encode(s2aParam))
end

function create(human)
	if not PfLogic.isQQ() then
		return
	end
	
	s2aParam = {}
    local now = os.time()

    local pf_info = human.pf_info
    if (pf_info == nil) then
        return
    end

	api_param = {}
    api_param.userip = human.ip
    api_param.time = now
    api_param.pf = pf_info.pf
    api_param.worldid = pf_info.serverid
    api_param.opopenid = pf_info.openid

    api_param.level = human.db.lv
    api_param.actionid = 12

    s2aParam.api_param = api_param

    _G.thread_http.send(Define.REPORT_CREATE_PHP,Json.Encode(s2aParam))
end

