//---------------------------------------------------------------------
 // 响应进入游戏世界(响应)
 public override void onEnterWorld(ClientEnterWorldResponse enterworld_response)
 {
     EbLog.Note("SampleIMListener.onEnterWorld() result=" + enterworld_response.result);
 }
示例#2
0
 //---------------------------------------------------------------------
 // 响应进入游戏世界(响应)
 public abstract void onEnterWorld(ClientEnterWorldResponse enterworld_response);
示例#3
0
        //---------------------------------------------------------------------
        // Client->Cell,Client进入游戏世界
        Task<ClientEnterWorldResponse> IGrainPlayer.ClientEnterWorld(string grainClientGuid)
        {
            Logger.Info("ClientEnterWorld() GrainId={0}", GrainKey);

            var grainMailBoxCache = GrainFactory.GetGrain<IGrainMailBoxCache>(GrainKey);
            grainMailBoxCache.ClientEnterWorld();

            // 向好友列表中广播本人上线事件
            var grainPlayerBroadcast = GrainFactory.GetGrain<IGrainPlayerBroadcast>(GrainKey);
            grainPlayerBroadcast.BroadcastPlayerOnline();

            GrainClientKey = new Guid(grainClientGuid);
            FriendInfoSync.OnClientEnterWorld();

            if (TimerHandleUpdate != null)
            {
                TimerHandleUpdate.Dispose();
                TimerHandleUpdate = null;
            }

            TimerHandleUpdate = RegisterTimer((_) => _timerHandleUpdate(), null,
               TimeSpan.FromMilliseconds(1000), TimeSpan.FromMilliseconds(1000));

            MyInfo my_info = new MyInfo();
            my_info.ListBlack = new List<string>();
            my_info.ListFriend = new List<string>();
            my_info.ListEventFriend = new List<EventFriend>();

            ClientEnterWorldResponse enterworld_response = new ClientEnterWorldResponse();
            enterworld_response.result = IMProtocolResult.Success;
            enterworld_response.my_info = my_info;

            return Task.FromResult(enterworld_response);
        }
        //---------------------------------------------------------------------
        async Task _c2sAccountRequest(AccountRequest account_request)
        {
            switch (account_request.id)
            {
                case AccountRequestId.LoginIM:// 请求登录IM
                    {
                        var loginim_request = EbTool.protobufDeserialize<ClientLoginIMRequest>(MemoryStream, account_request.data);

                        string info = string.Format("ClientLoginIM\nAccId={0}, AccName={1}, Token={2}",
                            loginim_request.acc_id, loginim_request.acc_name, loginim_request.token);
                        Logger.Info(info);

                        ClientLoginIMResponse loginim_response = new ClientLoginIMResponse();
                        loginim_response.result = IMProtocolResult.Failed;

                        AccountLoginAppInfo acc_login_app_info = new AccountLoginAppInfo();
                        acc_login_app_info.AppId = UCenterAppId;
                        acc_login_app_info.AppSecret = UCenterAppSecret;
                        acc_login_app_info.AccountId = loginim_request.acc_id;
                        acc_login_app_info.AccountToken = loginim_request.token;

                        // 去UCenter验证Account
                        //AccountLoginAppResponse acc_login_app_response = null;
                        //try
                        //{
                        //    acc_login_app_response = await IMContext.Instance.UCenterSDK.AccountLoginAppAsync(acc_login_app_info);
                        //}
                        //catch (Exception ex)
                        //{
                        //    Logger.Info(ex.ToString());
                        //    loginim_response.result = IMProtocolResult.LoginAccountVerifyFailed;
                        //    goto EndLoginIM;
                        //}

                        // 检测Token是否过期
                        //TimeSpan ts = app_verifyaccount_response.now_dt - app_verifyaccount_response.last_login_dt;
                        // if (ts.TotalSeconds > 60)
                        // {
                        //     enterworld_response.result = ProtocolResult.EnterWorldTokenExpire;
                        //     goto End;
                        // }

                        loginim_response.result = IMProtocolResult.Success;

                        //EndLoginIM:
                        AccId = loginim_request.acc_id;
                        Token = loginim_request.token;
                        AccName = loginim_request.acc_name;
                        GrainPlayerKey = string.Empty;

                        //if (loginim_response.result == IMProtocolResult.Success)
                        //{
                        //    AccId = loginim_request.acc_id;
                        //    Token = loginim_request.token;
                        //    AccName = loginim_request.acc_name;
                        //    GrainPlayerGuid = Guid.Empty;
                        //}
                        //else
                        //{
                        //    AccId = string.Empty;
                        //    Token = string.Empty;
                        //    AccName = string.Empty;
                        //    GrainPlayerGuid = Guid.Empty;
                        //}

                        AccountNotify account_notify;
                        account_notify.id = AccountNotifyId.LoginIM;
                        account_notify.data = EbTool.protobufSerialize<ClientLoginIMResponse>(MemoryStream, loginim_response);

                        MethodInfo methodInfo;
                        methodInfo.id = (ushort)IMMethodType.AccountNotify;
                        methodInfo.data = EbTool.protobufSerialize<AccountNotify>(MemoryStream, account_notify);

                        ((IGrainClientProxy)this).Notify(methodInfo);
                    }
                    break;
                case AccountRequestId.EnterWorld:// 请求进入游戏世界
                    {
                        ClientEnterWorldResponse enterworld_response = null;

                        if (string.IsNullOrEmpty(AccId))
                        {
                            Logger.Error((int)IMErrorCode.ClientEnterWorld, "ClientEnterWorld Error Not Login!");

                            enterworld_response = new ClientEnterWorldResponse();
                            enterworld_response.result = IMProtocolResult.Failed;
                            goto EndEnterWorld;
                        }

                        var enterworld_request = EbTool.protobufDeserialize<ClientEnterWorldRequest>(MemoryStream, account_request.data);

                        string info = string.Format("ClientEnterWorld\nAccId={0}, IMAppId={1}, IMAppChannel={2}",
                            enterworld_request.acc_id, enterworld_request.imapp_id, enterworld_request.imapp_channel);
                        Logger.Info(info);

                        if (AccId != enterworld_request.acc_id || Token != enterworld_request.token)
                        {
                            Logger.Error((int)IMErrorCode.ClientEnterWorld, "ClientEnterWorld Error AccId or Token!");

                            enterworld_response = new ClientEnterWorldResponse();
                            enterworld_response.result = IMProtocolResult.Failed;
                            goto EndEnterWorld;
                        }

                        // 检测IM中存贮的IMAppID+AccId对应的IMAppAccountData
                        var grain_service_appproxy = GrainFactory.GetGrain<IGrainAppProxyService>(0);
                        string player_guid = await grain_service_appproxy.GetPlayer(enterworld_request.imapp_id, enterworld_request.imapp_channel, enterworld_request.acc_id);

                        if (string.IsNullOrEmpty(player_guid))
                        {
                            Logger.Error((int)IMErrorCode.ClientEnterWorld, "ClientEnterWorld Error Not Create Player!");

                            enterworld_response = new ClientEnterWorldResponse();
                            enterworld_response.result = IMProtocolResult.EnterWorldNotExistPlayer;
                            goto EndEnterWorld;
                        }

                        // 角色进入游戏
                        GrainPlayerKey = string.Format("{0}_{1}", IMAppId, player_guid);
                        var grain_player = GrainFactory.GetGrain<IGrainPlayer>(GrainPlayerKey);
                        enterworld_response = await grain_player.ClientEnterWorld(GrainClientKey);
                        if (enterworld_response.result == IMProtocolResult.Success)
                        {
                            IMAppId = enterworld_request.imapp_id;
                            IMAppChannel = enterworld_request.imapp_channel;
                        }
                        else
                        {
                            Logger.Error((int)IMErrorCode.ClientEnterWorld, "ClientEnterWorld Error EnterWorld Failed!");

                            IMAppId = string.Empty;
                            IMAppChannel = string.Empty;
                            GrainPlayerKey = string.Empty;
                        }

                    EndEnterWorld:
                        AccountNotify account_notify;
                        account_notify.id = AccountNotifyId.EnterWorld;
                        account_notify.data = EbTool.protobufSerialize<ClientEnterWorldResponse>(MemoryStream, enterworld_response);

                        MethodInfo methodInfo;
                        methodInfo.id = (ushort)IMMethodType.AccountNotify;
                        methodInfo.data = EbTool.protobufSerialize<AccountNotify>(MemoryStream, account_notify);

                        ((IGrainClientProxy)this).Notify(methodInfo);
                    }
                    break;
                default:
                    break;
            }
        }