Example #1
0
        //-------------------------------------------------------------------------
        // 客户端断开连接
        public async Task c2sClientDeattach()
        {
            EbLog.Note("CellPlayer.c2sClientDeattach() EtGuid=" + Entity.Guid);

            CachePlayerData.player_server_state = PlayerServerState.Offline;

            // 通知PlayerProxy,玩家离线
            var grain             = Entity.getUserData <GrainCellPlayer>();
            var grain_playerproxy = grain.GF.GetGrain <ICellPlayerProxy>(new Guid(Entity.Guid));

            grain_playerproxy.s2sPlayerServerStateChange(CachePlayerData.player_server_state);

            string data = EbTool.jsonSerialize(CachePlayerData);
            //DbClientCouchbase.Instance.asyncSave(CachePlayerKey, data, TimeSpan.FromSeconds(15.0));

            await CoPlayerDesktop.leaveDesktop();
        }
Example #2
0
    //-------------------------------------------------------------------------
    async Task <MethodData> _c2sPlayerRequest(MethodData method_data)
    {
        var player_request = EbTool.protobufDeserialize <PlayerRequest>(method_data.param1);

        switch (player_request.id)
        {
        case PlayerRequestId.PlayNow:    // 立即玩
        {
            EbLog.Note("CellPlayer._c2sPlayerRequest PlayNow() EtGuid=" + Entity.Guid);

            // 通过桌子服务请求立即玩
            await CoPlayerDesktop.enterDesktopPlayNow();
        }
        break;

        case PlayerRequestId.CreatePrivateDesktop:    // c->s,创建私有桌子
        {
            EbLog.Note("CellPlayer.c2sPlayerRequest() CreatePrivateDesktop");

            // 正在进入桌子中
            if (CoPlayerDesktop.IsEntering)
            {
                goto End;
            }

            // 检测玩家是否已在桌子中
            if (!string.IsNullOrEmpty(CoPlayerDesktop.DesktopEtGuid))
            {
                goto End;
            }

            // 创建私人桌并入座
            var desktop_createinfo = EbTool.protobufDeserialize <PrivateDesktopCreateInfo>(player_request.data);
            await CoPlayerDesktop.enterDesktopPrivate(desktop_createinfo);

            PlayerResponse player_response;
            player_response.id   = PlayerResponseId.CreatePrivateDesktop;
            player_response.data = null;

            MethodData result = new MethodData();
            result.method_id = MethodType.s2cPlayerResponse;
            result.param1    = EbTool.protobufSerialize <PlayerResponse>(player_response);
            return(result);
        }

        case PlayerRequestId.EnterDesktopAny:
        {
            EbLog.Note("CellPlayer.c2sPlayerRequest EnterDesktopAny() EtGuid=" + Entity.Guid);

            await CoPlayerDesktop.enterDesktopPlayNow();

            PlayerResponse player_response;
            player_response.id   = PlayerResponseId.EnterDesktopAny;
            player_response.data = null;

            MethodData result = new MethodData();
            result.method_id = MethodType.s2cPlayerResponse;
            result.param1    = EbTool.protobufSerialize <PlayerResponse>(player_response);
            return(result);
        }

        case PlayerRequestId.EnterDesktop:    // 进入桌子
        {
            EbLog.Note("CellPlayer.c2sPlayerRequest EnterDesktop() EtGuid=" + Entity.Guid);

            var desktop_etguid = EbTool.protobufDeserialize <string>(player_request.data);
            if (!string.IsNullOrEmpty(desktop_etguid))
            {
                await CoPlayerDesktop.enterDesktop(desktop_etguid);
            }

            PlayerResponse player_response;
            player_response.id   = PlayerResponseId.EnterDesktop;
            player_response.data = null;

            MethodData result = new MethodData();
            result.method_id = MethodType.s2cPlayerResponse;
            result.param1    = EbTool.protobufSerialize <PlayerResponse>(player_response);
            return(result);
        }

        case PlayerRequestId.LeaveDesktop:    // 离开桌子
        {
            EbLog.Note("CellPlayer.c2sPlayerRequest LeaveDesktop() EtGuid=" + Entity.Guid);

            await CoPlayerDesktop.leaveDesktop();

            PlayerResponse player_response;
            player_response.id   = PlayerResponseId.LeaveDesktop;
            player_response.data = null;

            MethodData result = new MethodData();
            result.method_id = MethodType.s2cPlayerResponse;
            result.param1    = EbTool.protobufSerialize <PlayerResponse>(player_response);
            return(result);
        }

        case PlayerRequestId.GetOnlinePlayerNum:    // 获取在线玩家数量
        {
            var grain = Entity.getUserData <GrainCellPlayer>();
            var grain_playerservice = grain.GF.GetGrain <ICellPlayerService>(0);
            var num = await grain_playerservice.getOnlinePlayerNum();

            PlayerResponse player_response;
            player_response.id   = PlayerResponseId.GetOnlinePlayerNum;
            player_response.data = EbTool.protobufSerialize <int>(num);

            MethodData result = new MethodData();
            result.method_id = MethodType.s2cPlayerResponse;
            result.param1    = EbTool.protobufSerialize <PlayerResponse>(player_response);
            return(result);
        }

        case PlayerRequestId.DevConsoleCmd:    // 请求执行控制台命令
        {
            var    map_param = EbTool.protobufDeserialize <Dictionary <byte, string> >(player_request.data);
            string cmd       = (string)map_param[0];

            if (cmd == "AddItem")
            {
                int  item_id = int.Parse(map_param[1]);
                int  count   = int.Parse(map_param[2]);
                Item item    = null;
                CoBag.newItem(item_id, count, out item);
            }
            else if (cmd == "OperateItem")
            {
                string      operate_id   = map_param[1];
                string      item_objid   = map_param[2];
                ItemOperate item_operate = new ItemOperate();
                item_operate.operate_id = operate_id;
                item_operate.item_objid = item_objid;
                CoBag.operateItem(item_operate);
            }
            else if (cmd == "SetLevel")
            {
                int level = int.Parse(map_param[1]);
                int exp   = int.Parse(map_param[2]);
                CoActor.Def.mPropExperience.set(exp);
                CoActor.Def.mPropLevel.set(level);
            }
        }
        break;

        case PlayerRequestId.GetPlayerInfoOther:    // 请求获取其他玩家信息
        {
            var player_etguid = EbTool.protobufDeserialize <string>(player_request.data);

            var grain = Entity.getUserData <GrainCellPlayer>();
            var grain_playerservice = grain.GF.GetGrain <ICellPlayerService>(0);
            var player_info         = await grain_playerservice.getPlayerInfoOther(player_etguid);

            PlayerResponse player_response;
            player_response.id   = PlayerResponseId.GetPlayerInfoOther;
            player_response.data = EbTool.protobufSerialize <PlayerInfoOther>(player_info);

            MethodData result = new MethodData();
            result.method_id = MethodType.s2cPlayerResponse;
            result.param1    = EbTool.protobufSerialize <PlayerResponse>(player_response);
            return(result);
        }

        case PlayerRequestId.ChangeProfileSkin:    // 请求换肤
        {
            var profileskin_tableid = EbTool.protobufDeserialize <int>(player_request.data);

            var profileskin = EbDataMgr.Instance.getData <TbDataPlayerProfileSkin>(profileskin_tableid);
            if (profileskin == null)
            {
                goto End;
            }

            CoActor.Def.mPropProfileSkinTableId.set(profileskin_tableid);

            var grain = Entity.getUserData <GrainCellPlayer>();
            grain.asyncSaveState();

            PlayerResponse player_response;
            player_response.id   = PlayerResponseId.ChangeProfileSkin;
            player_response.data = EbTool.protobufSerialize <int>(profileskin_tableid);

            MethodData result = new MethodData();
            result.method_id = MethodType.s2cPlayerResponse;
            result.param1    = EbTool.protobufSerialize <PlayerResponse>(player_response);
            return(result);
        }

        case PlayerRequestId.ChangeNickName:    // 请求改昵称
        {
            var nick_name = EbTool.protobufDeserialize <string>(player_request.data);

            CoActor.Def.mPropNickName.set(nick_name);

            var grain = Entity.getUserData <GrainCellPlayer>();
            grain.asyncSaveState();

            PlayerResponse player_response;
            player_response.id   = PlayerResponseId.ChangeNickName;
            player_response.data = EbTool.protobufSerialize <string>(nick_name);

            MethodData result = new MethodData();
            result.method_id = MethodType.s2cPlayerResponse;
            result.param1    = EbTool.protobufSerialize <PlayerResponse>(player_response);
            return(result);
        }

        case PlayerRequestId.ChangeIndividualSignature:    // 请求改签名
        {
            var sign = EbTool.protobufDeserialize <string>(player_request.data);

            CoActor.Def.mPropIndividualSignature.set(sign);

            var grain = Entity.getUserData <GrainCellPlayer>();
            grain.asyncSaveState();

            PlayerResponse player_response;
            player_response.id   = PlayerResponseId.ChangeIndividualSignature;
            player_response.data = EbTool.protobufSerialize <string>(sign);

            MethodData result = new MethodData();
            result.method_id = MethodType.s2cPlayerResponse;
            result.param1    = EbTool.protobufSerialize <PlayerResponse>(player_response);
            return(result);
        }

        case PlayerRequestId.RefreshIpAddress:    // 请求刷新Ip所在地
        {
            _refreshIpAddress();

            PlayerResponse player_response;
            player_response.id   = PlayerResponseId.RefreshIpAddress;
            player_response.data = EbTool.protobufSerialize <string>(CoActor.Def.mPropIpAddress.get());

            MethodData result = new MethodData();
            result.method_id = MethodType.s2cPlayerResponse;
            result.param1    = EbTool.protobufSerialize <PlayerResponse>(player_response);
            return(result);
        }

        case PlayerRequestId.ReportPlayer:    // 举报玩家
        {
            var report = EbTool.protobufDeserialize <ReportPlayer>(player_request.data);

            PlayerResponse player_response;
            player_response.id   = PlayerResponseId.ReportPlayer;
            player_response.data = EbTool.protobufSerialize <ReportPlayer>(report);

            MethodData result = new MethodData();
            result.method_id = MethodType.s2cPlayerResponse;
            result.param1    = EbTool.protobufSerialize <PlayerResponse>(player_response);
            return(result);
        }

        case PlayerRequestId.InvitePlayerEnterDesktop:    // 邀请玩家进桌
        {
            var invite = EbTool.protobufDeserialize <InvitePlayerEnterDesktop>(player_request.data);

            var grain             = Entity.getUserData <GrainCellPlayer>();
            var grain_playerproxy = grain.GF.GetGrain <ICellPlayerProxy>(new Guid(invite.player_info.player_etguid));
            grain_playerproxy.s2sInvitePlayerEnterDesktop(Entity.Guid, invite.desktop_etguid,
                                                          invite.sb, invite.bb, invite.player_num, invite.seat_num);

            PlayerResponse player_response;
            player_response.id   = PlayerResponseId.InvitePlayerEnterDesktop;
            player_response.data = EbTool.protobufSerialize <ProtocolResult>(ProtocolResult.Success);

            MethodData result = new MethodData();
            result.method_id = MethodType.s2cPlayerResponse;
            result.param1    = EbTool.protobufSerialize <PlayerResponse>(player_response);
            return(result);
        }

        case PlayerRequestId.GivePlayerChip:    // 赠送玩家筹码
        {
            var give_chip = EbTool.protobufDeserialize <GivePlayerChip>(player_request.data);

            ProtocolResult re       = ProtocolResult.Failed;
            int            chip_cur = CoActor.Def.PropGold.get();

            if (chip_cur >= 100000 && give_chip.chip >= 100000 && chip_cur >= give_chip.chip)
            {
                var grain             = Entity.getUserData <GrainCellPlayer>();
                var grain_playerproxy = grain.GF.GetGrain <ICellPlayerProxy>(new Guid(give_chip.player_info.player_etguid));
                await grain_playerproxy.s2sGivePlayerChip(Entity.Guid, give_chip.chip);

                re        = ProtocolResult.Success;
                chip_cur -= give_chip.chip;
                CoActor.Def.PropGold.set(chip_cur);
            }
            else
            {
                re = ProtocolResult.Failed;
            }

            PlayerResponse player_response;
            player_response.id   = PlayerResponseId.GivePlayerChip;
            player_response.data = EbTool.protobufSerialize <ProtocolResult>(re);

            MethodData result = new MethodData();
            result.method_id = MethodType.s2cPlayerResponse;
            result.param1    = EbTool.protobufSerialize <PlayerResponse>(player_response);
            return(result);
        }

        case PlayerRequestId.SetVip4Test:    // 请求设置是否为Vip
        {
            EbLog.Note("CellPlayer.c2sPlayerRequest LeaveDesktop() EtGuid=" + Entity.Guid);

            var is_vip = EbTool.protobufDeserialize <bool>(player_request.data);
            CoActor.Def.mPropIsVIP.set(is_vip);

            var grain = Entity.getUserData <GrainCellPlayer>();
            grain.asyncSaveState();

            PlayerResponse player_response;
            player_response.id   = PlayerResponseId.SetVip4Test;
            player_response.data = EbTool.protobufSerialize(is_vip);

            MethodData result = new MethodData();
            result.method_id = MethodType.s2cPlayerResponse;
            result.param1    = EbTool.protobufSerialize <PlayerResponse>(player_response);
            return(result);
        }

        case PlayerRequestId.SetAFK:    // 请求设置是否挂机
        {
            var afk = EbTool.protobufDeserialize <bool>(player_request.data);
            if (CoActor.Def.mPropIsBot.get())
            {
                // 机器人总是挂机状态,无需设置
                goto End;
            }

            if (CoActor.Def.mPropIsAFK.get() != afk)
            {
                CoActor.Def.mPropIsAFK.set(afk);

                PlayerNotify player_notify;
                player_notify.id   = PlayerNotifyId.SetAFK;
                player_notify.data = EbTool.protobufSerialize <bool>(afk);

                MethodData notify_data = new MethodData();
                notify_data.method_id = MethodType.s2cPlayerNotify;
                notify_data.param1    = EbTool.protobufSerialize <PlayerNotify>(player_notify);
                var grain        = Entity.getUserData <GrainCellPlayer>();
                var grain_player = grain.GF.GetGrain <ICellPlayer>(new Guid(Entity.Guid));
                grain_player.s2sNotify(notify_data);
            }
        }
        break;

        default:
            break;
        }

End:
        MethodData r = new MethodData();

        r.method_id = MethodType.None;
        return(r);
    }