Ejemplo n.º 1
0
    //处理重命名请求
    public void ReqRename(MsgPack pack)
    {
        ReqRename data = pack.msg.reqRename;
        GameMsg   msg  = new GameMsg
        {
            cmd = (int)CMD.RespondRename,
            //下面的代码太早了,这个名字也许存在
            //respondRename = new RespondRename
            //{
            //    name = data.name
            //}
        };

        //名字存在,返回错误码
        if (cacheSrv.IsNameExist(data.name))
        {
            msg.err = (int)ErroroCode.NameIsExist;
        }
        //不存在,更新缓存和数据库数据
        else
        {
            PlayerData playerData = cacheSrv.GetPlayerDataBySession(pack.serverSession);
            playerData.name = data.name;
            //数据库更新出错
            if (!cacheSrv.UpdatePlayerData(playerData.id, playerData))
            {
                msg.err = (int)ErroroCode.UpdateDBError;
            }
            else
            {
                msg.respondRename = new RespondRename
                {
                    name = data.name
                };
            }
        }
        //发送回去
        pack.serverSession.SendMsg(msg);
    }
Ejemplo n.º 2
0
    public void ReqGuide(MsgPack pack)
    {
        ReqGuide data = pack.msg.reqGuide;
        GameMsg  msg  = new GameMsg
        {
            cmd = (int)CMD.RspGuide
        };
        PlayerData pd          = cacheSrv.GetPlayerDataBySession(pack.serverSession);
        GuideCfg   guideConfig = cfgSvc.GetGuideCfgData(pd.guideid);

        //更新引导ID
        if (pd.guideid == data.guidid)
        {
            pd.guideid += 1;
            //更新玩家数据
            pd.coin += guideConfig.coin;
            CalculateExp(pd, guideConfig.exp);
            if (!cacheSrv.UpdatePlayerData(pd.id, pd))
            {
                msg.err = (int)ErroroCode.UpdateDBError;
            }
            else
            {
                msg.rspGuide = new RspGuide
                {
                    coin    = pd.coin,
                    exp     = pd.exp,
                    lv      = pd.lv,
                    guideid = pd.guideid,
                };
            }
        }
        else//开挂了
        {
            msg.err = (int)ErroroCode.ServerDataError;
        }
        //发送数据
        pack.serverSession.SendMsg(msg);
    }