import {ApiCall} from "tsrpc";
import {PlayerFun} from '../../public/player';
import {ReqPing, ResPing} from "../../shared/protocols/user/PtlPing";
import {PublicShared} from "../../shared/public/public";

export default async function (call: ApiCall<ReqPing, ResPing>) {
    let onlineTime = call.conn?.gud?.onlineTime || 0;

    if (call.uid && call.conn.gud && call.conn.onlineTime) {
        let addSecond = G.time - call.conn.onlineTime;
        if (addSecond > 0) {
            PlayerFun.changeAttr(call.uid, {onlineTime: call.conn.gud.onlineTime + addSecond, newonlinetime: G.time});
        }
        call.conn.onlineTime = G.time;
        onlineTime = call.conn.gud.onlineTime + addSecond;
    }

    call.succ({
        time: G.time,
        onlineTime: onlineTime,
        openDay: PublicShared.getOpenServerDay()
    });

    let gud = call.conn?.gud
    G.server.sendMsgByUid(call.uid, 'msg_s2c/PlayerChange', {
        jinbi: gud?.jinbi,
        rmbmoney: gud?.rmbmoney
    });
}