Exemplo n.º 1
0
        public void InternalResponse <TId, TResultType>(ProtocolResult <TId, TResultType> result)
            where TId : IProtocolIdentifier
        {
            Logger.LogTrace($"Protocol {result.From} returned result");
            if (_terminated)
            {
                Logger.LogTrace($"Era {_era} is already finished, skipping InternalResponse");
                return;
            }

            if (_callback.TryGetValue(result.From, out var senderId))
            {
                if (!_registry.TryGetValue(senderId, out var cbProtocol))
                {
                    Logger.LogWarning($"There is no protocol registered to get result from {senderId}");
                }
                else
                {
                    cbProtocol?.ReceiveMessage(new MessageEnvelope(result, GetMyId()));
                    Logger.LogTrace($"Result from protocol {result.From} delivered to {senderId}");
                }
            }

            // message is also delivered to self
            //    Logger.LogTrace($"Result from protocol {result.From} delivered to itself");
            if (_registry.TryGetValue(result.From, out var protocol))
            {
                protocol?.ReceiveMessage(new MessageEnvelope(result, GetMyId()));
            }
        }
Exemplo n.º 2
0
        public void InternalResponse <TId, TResultType>(ProtocolResult <TId, TResultType> result)
            where TId : IProtocolIdentifier
        {
            if (_callback.TryGetValue(result.From, out var senderId))
            {
                Registry[senderId]?.ReceiveMessage(new MessageEnvelope(result, GetMyId()));
            }

            // message is also delivered to self
            Registry[result.From]?.ReceiveMessage(new MessageEnvelope(result, GetMyId()));
        }
Exemplo n.º 3
0
        public bool MatchProtocolVersion(uint protocolVersion)
        {
            bool flag = this.protocolVersion == protocolVersion;

            if (!flag)
            {
                string         message = string.Format("Protocol version mismatch. Client: {0}, Server: {1}", this.protocolVersion, protocolVersion);
                ProtocolResult result  = (this.protocolVersion <= protocolVersion) ? ProtocolResult.Lower : ProtocolResult.Higher;
                this.desyncHandler(message, 0u, result);
            }
            return(flag);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Shallow copy.
        /// </summary>
        public ProtocolResult ConvertFromArchived(ArchivedProtocolResult aProtocolResult)
        {
            var protocolResult = new ProtocolResult();

            protocolResult.ResultNumber = aProtocolResult.ResultNumber;
            protocolResult.Results      = aProtocolResult.Results;

            var converter = new ProductTestsConverter();

            protocolResult.ProductTest = converter.ConvertFromArchived(aProtocolResult.ArchivedProductTest);

            return(protocolResult);
        }
Exemplo n.º 5
0
        public async Task <ActionResult <List <ProtocolResult> > > GetAllProtocols()
        {
            var results    = new List <ProtocolResult>();
            var department = await _departmentsService.GetDepartmentByIdAsync(DepartmentId, false);


            var protocols = await _protocolsService.GetAllProtocolsForDepartmentAsync(DepartmentId);

            foreach (var p in protocols)
            {
                results.Add(ProtocolResult.Convert(p));
            }

            return(Ok(results));
        }
Exemplo n.º 6
0
        public List <ProtocolResult> GetAllProtocols()
        {
            var results    = new List <ProtocolResult>();
            var department = _departmentsService.GetDepartmentById(DepartmentId, false);


            var protocols = _protocolsService.GetAllProtocolsForDepartment(DepartmentId);

            foreach (var p in protocols)
            {
                results.Add(ProtocolResult.Convert(p));
            }

            return(results);
        }
Exemplo n.º 7
0
        private void HandleReliableBroadcast(ProtocolResult <ReliableBroadcastId, EncryptedShare> result)
        {
            if (result.Result == null)
            {
                return;
            }

            var j = result.Id.SenderId;

            _reliableBroadcastResult[j] = result.Result;
            if (_binaryAgreementInput[j] == null)
            {
                _binaryAgreementInput[j] = true;
                SendInputToBinaryAgreement(j);
            }

            CheckCompletion();
        }
Exemplo n.º 8
0
        public async Task <ActionResult> GetProtocol(int protocolId)
        {
            var protocol = await _protocolsService.GetProtocolByIdAsync(protocolId);

            if (protocol == null)
            {
                return(NotFound());
            }

            if (protocol.DepartmentId != DepartmentId)
            {
                return(Unauthorized());
            }

            var result = ProtocolResult.Convert(protocol);


            return(Ok(JsonConvert.SerializeObject(result)));
        }
Exemplo n.º 9
0
        private void HandleCommonSubset(ProtocolResult <CommonSubsetId, ISet <EncryptedShare> > result)
        {
            Logger.LogTrace($"Common subset finished {result.From}");
            foreach (var share in result.Result)
            {
                var dec = _privateKey.Decrypt(share);
                _taken[share.Id]          = true;
                _receivedShares[share.Id] = share;
                // todo think about async access to protocol method. This may pose threat to protocol internal invariants
                CheckDecryptedShares(share.Id);
                Broadcaster.Broadcast(CreateDecryptedMessage(dec));
            }

            _takenSet = true;

            foreach (var share in result.Result)
            {
                CheckDecryptedShares(share.Id);
            }

            CheckResult();
        }
Exemplo n.º 10
0
        private void DisplayUpdateWindow()
        {
            Lang           lang           = Service.Get <Lang>();
            ProtocolResult protocolResult = this.protocolResult;

            if (protocolResult != ProtocolResult.Higher)
            {
                if (protocolResult == ProtocolResult.Lower)
                {
                    string title   = lang.Get("FORCED_UPDATE_TITLE", new object[0]);
                    string message = lang.Get("FORCED_UPDATE_MESSAGE", new object[0]);
                    UpdateClientScreen.ShowModal(title, message, new OnScreenModalResult(this.OnUpdateWindowClosed), null);
                }
            }
            else
            {
                string title   = lang.Get("UPDATE_COMING_TITLE", new object[0]);
                string message = lang.Get("UPDATE_COMING_MESSAGE", new object[0]);
                AlertScreen.ShowModal(true, title, message, null, null);
            }
            this.KillStartup();
        }
Exemplo n.º 11
0
        private void HandleBinaryAgreementResult(ProtocolResult <BinaryAgreementId, bool> result)
        {
            if (_binaryAgreementResult[result.Id.AssociatedValidatorId] == null)
            {
                ++_cntBinaryAgreementsCompleted;
            }
            _binaryAgreementResult[result.Id.AssociatedValidatorId] = result.Result;

            if (!_filledBinaryAgreements && _cntBinaryAgreementsCompleted >= N - F)
            {
                Logger.LogDebug($"Sending 0 to all remaining BA, _cntBinaryAgreementsCompleted: {_cntBinaryAgreementsCompleted}; N: {N}");
                _filledBinaryAgreements = true;
                for (var i = 0; i < N; ++i)
                {
                    if (_binaryAgreementInput[i] == null)
                    {
                        _binaryAgreementInput[i] = false;
                        SendInputToBinaryAgreement(i);
                    }
                }
            }

            CheckCompletion();
        }
Exemplo n.º 12
0
 /// <summary>
 /// Shallow copy.
 /// </summary>
 public ArchivedProtocolResult ConvertToArchived(ProtocolResult productTest)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 13
0
        private void RunWorkerTask()
        {
            switch (_State)
            {
            case AutoCompleteTestState.WriteMsgKarteBitte:
                // clear image
                _Cmd    = _protocol.CreateDisplayDeleteCommand(1, DisplayCommand.Image);
                _Result = _ProtocolManager.EncryptSendReceiveAck(_Cmd);

                // write text
                _Cmd    = _protocol.CreateDisplayTextCommand(2, new ColorInfo(_TextColorWhite.R, _TextColorWhite.G, _TextColorWhite.B), 140, 200, 33, "Ihre Karte bitte");
                _Result = _ProtocolManager.EncryptSendReceiveAck(_Cmd);
                if (_Result == ProtocolResult.Ack || _Result == ProtocolResult.AckAck)
                {
                    _Cmd    = _protocol.CreateDisplayInvalidateCommand();
                    _Result = _ProtocolManager.EncryptSendReceiveAck(_Cmd);
                    if (_Result == ProtocolResult.Ack || _Result == ProtocolResult.AckAck)
                    {
                        // ok
                        //Thread.Sleep(1000);
                        SetNextState(AutoCompleteTestState.WriteMediacode);
                    }
                    else
                    {
                        LogError($"WriteMsgKarteBitte failed: {_Result}");
                    }
                }
                else
                {
                    LogError($"WriteMsgKarteBitte failed: {_Result}");
                }
                break;

            case AutoCompleteTestState.WriteMediacode:
                if (_UsePhysicalMedia)
                {
                    SetNextState(AutoCompleteTestState.CheckMediacode);
                }
                else
                {
                    var data = GetNextMediacode();
                    if (_serial.IsOpen)
                    {
                        _ViewModel.Auto_BarcodeToWrite = Encoding.UTF8.GetString(data).ToString().Trim('\r');
                        _LastSentMediacode             = _ViewModel.Auto_BarcodeToWrite;
                        _serial.Write(data, 0, data.Length);
                        SetNextState(AutoCompleteTestState.CheckMediacode);
                    }
                    else
                    {
                        LogError("SerialPort is not open");
                    }
                }
                break;

            case AutoCompleteTestState.CheckMediacode:

                if (_ViewModel.ReadMediaRaw == _LastReadMediacode)
                {
                    if (_UsePhysicalMedia)
                    {
                        ;     // just wait
                    }
                    else
                    {
                        // wait
                        _WaitCounter++;
                        if (_WaitCounter > 50)
                        {
                            LogError("CheckMediacode Timeout");
                            SetNextState(AutoCompleteTestState.WriteMediacode);
                        }
                    }
                }
                else
                {
                    if (_UsePhysicalMedia)
                    {
                        if (_ViewModel.ReadMediaRaw.Length > 10)
                        {
                            SetNextState(AutoCompleteTestState.WriteOutput);
                        }
                    }
                    else
                    {
                        // check
                        if (_ViewModel.ReadMediaRaw == _LastSentMediacode)
                        {
                            SetNextState(AutoCompleteTestState.WriteOutput);
                        }
                        else
                        {
                            LogError("Mediacode not match, try again");
                            SetNextState(AutoCompleteTestState.WriteMediacode);
                        }
                    }
                }
                break;

            case AutoCompleteTestState.WriteOutput:
                _Result = base.SendRelais(ref _OuputMask, 1, true);
                if (_Result == ProtocolResult.Ack || _Result == ProtocolResult.AckAck)
                {
                    // clear text
                    _Cmd    = _protocol.CreateDisplayTextCommand(2, new ColorInfo(_TextColorGreen.R, _TextColorGreen.G, _TextColorGreen.B), 180, 200, 33, "");
                    _Result = _ProtocolManager.EncryptSendReceiveAck(_Cmd);

                    // image
                    _Cmd    = _protocol.CreateDisplayImageCommand(1, 280, 160, "check_200_191.png");
                    _Result = _ProtocolManager.EncryptSendReceiveAck(_Cmd);

                    // text
                    //_Cmd = _protocol.CreateDisplayTextCommand(2, new ColorInfo(_TextColorGreen.R, _TextColorGreen.G, _TextColorGreen.B), 180, 200, 33, "Eingang Frei");
                    //_Result = _ProtocolManager.EncryptSendReceiveAck(_Cmd);

                    if (_Result == ProtocolResult.Ack || _Result == ProtocolResult.AckAck)
                    {
                        _Cmd    = _protocol.CreateDisplayInvalidateCommand();
                        _Result = _ProtocolManager.EncryptSendReceiveAck(_Cmd);
                        if (_Result == ProtocolResult.Ack || _Result == ProtocolResult.AckAck)
                        {
                            // ok
                            Thread.Sleep(1000);
                            SetNextState(AutoCompleteTestState.WaitInputForTrue);
                        }
                        else
                        {
                            LogError($"WriteMsgEingangFrei failed: {_Result}");
                        }
                    }
                    else
                    {
                        LogError($"WriteMsgEingangFrei failed: {_Result}");
                    }
                }
                else
                {
                    LogError($"WriteOutput failed: {_Result}");
                }
                break;

            case AutoCompleteTestState.WriteMsgEingangFrei:
                //var cmdWriteEingangFrei = _protocol.CreateDisplayTextCommand(2, new ColorInfo(_TextColorGreen.R, _TextColorGreen.G, _TextColorGreen.B), 180, 200, 33, "Eingang Frei");
                //var resultMsgFrei = _ProtocolManager.EncryptSendReceiveAck(cmdWriteEingangFrei);
                //if (resultMsgFrei == ProtocolResult.Ack || resultMsgFrei == ProtocolResult.AckAck)
                //{
                //    // ok
                //    Thread.Sleep(1000);
                //    SetNextState(AutoCompleteTestState.WaitInputForTrue);
                //}
                //else
                //{
                //    LogError($"WriteMsgEingangFrei failed: {resultMsgFrei}");
                //}
                break;

            case AutoCompleteTestState.WaitInputForTrue:
                if (_ViewModel.InputState1)
                {
                    // ok
                    SetNextState(AutoCompleteTestState.ResetOutput);
                }
                else
                {
                    // wait
                    _WaitCounter++;
                    if (_WaitCounter > 50)
                    {
                        LogError("WaitInputForTrue Timeout");
                        SetNextState(AutoCompleteTestState.WriteOutput);
                    }
                }
                break;

            case AutoCompleteTestState.ResetOutput:
                var resultReset = base.SendRelais(ref _OuputMask, 1, false);
                if (resultReset == ProtocolResult.Ack || resultReset == ProtocolResult.AckAck)
                {
                    // ok
                    SetNextState(AutoCompleteTestState.WaitInputForFalse);
                }
                else
                {
                    LogError($"WriteOutput failed: {resultReset}");
                }
                break;

            case AutoCompleteTestState.WaitInputForFalse:
                if (_ViewModel.InputState1 == false)
                {
                    if (_UsePhysicalMedia)
                    {
                        _LastReadMediacode      = "";
                        _ViewModel.ReadMediaRaw = "";
                    }

                    // finish
                    Log($"Test finish");
                    SetNextState(AutoCompleteTestState.WriteMsgKarteBitte);
                }
                else
                {
                    // wait
                    _WaitCounter++;
                    if (_WaitCounter > 50)
                    {
                        LogError("WaitInputForFalse Timeout");
                        SetNextState(AutoCompleteTestState.ResetOutput);
                    }
                }
                break;

            default:
                break;
            }
        }
Exemplo n.º 14
0
        private void OnDesync(string message, uint status, ProtocolResult result)
        {
            ServerAPI serverAPI = Service.ServerAPI;

            if (result == ProtocolResult.Match)
            {
                string title = null;
                Lang   lang  = Service.Lang;
                if (this.hasSecondary && serverAPI.GetDispatcher().Url.StartsWith("https://starts-integration-prod.disney.io/starts") && message.StartsWith(lang.Get(LangUtils.DESYNC_BATCH_MAX_RETRY, new object[0])))
                {
                    title   = lang.Get("UPDATE_COMING_TITLE", new object[0]);
                    message = lang.Get("UPDATE_COMING_MESSAGE", new object[0]);
                    Service.Logger.Warn("Maintenance message shown due to client update before server deploy");
                }
                if (status != 1999u)
                {
                    AlertScreen.ShowModalWithBI(true, title, message, message);
                }
                this.KillStartup();
                return;
            }
            if (this.isHandlingMismatch)
            {
                return;
            }
            this.isHandlingMismatch = true;
            this.protocolResult     = result;
            if (result == ProtocolResult.Higher && !serverAPI.GetDispatcher().Url.StartsWith("https://starts-integration-prod.disney.io/starts") && this.hasSecondary && this.isAttemptingAuth)
            {
                Service.Logger.WarnFormat("Trying secondary API due to higher protocol", new object[0]);
                if (this.getAuthTokenCommand != null)
                {
                    this.getAuthTokenCommand.RemoveAllCallbacks();
                }
                if (this.generatePlayerCommand != null)
                {
                    this.generatePlayerCommand.RemoveAllCallbacks();
                }
                serverAPI.SetDispatcher("https://starts-integration-prod.disney.io/starts", Service.Engine);
                this.GetOrCreatePlayer();
                return;
            }
            IState currentState = Service.GameStateMachine.CurrentState;

            if (currentState is BattleStartState || currentState is BattlePlayState || currentState is BattleEndState)
            {
                this.isHandlingMismatch = false;
                return;
            }
            if (result != ProtocolResult.Higher)
            {
                if (result == ProtocolResult.Lower)
                {
                    Service.Logger.Warn(message);
                }
            }
            else
            {
                Service.Logger.Error(message);
            }
            this.DisplayUpdateWindow();
        }
Exemplo n.º 15
0
        //-------------------------------------------------------------------------
        public async Task <MethodData> c2sPlayerFriendRequest(MethodData method_data)
        {
            MethodData result = new MethodData();

            result.method_id = MethodType.None;

            var playerfriend_request = EbTool.protobufDeserialize <PlayerFriendRequest>(method_data.param1);

            switch (playerfriend_request.id)
            {
            case PlayerFriendRequestId.GetPlayerInfoFriend:    // 请求获取好友玩家信息
            {
                var player_etguid = EbTool.protobufDeserialize <string>(playerfriend_request.data);

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

                PlayerFriendResponse playerfriend_response;
                playerfriend_response.id   = PlayerFriendResponseId.GetPlayerInfoFriend;
                playerfriend_response.data = EbTool.protobufSerialize <PlayerInfoFriend>(player_info);

                result.method_id = MethodType.s2cPlayerFriendResponse;
                result.param1    = EbTool.protobufSerialize <PlayerFriendResponse>(playerfriend_response);
            }
            break;

            case PlayerFriendRequestId.RequestAddFriend:    // 请求添加为好友
            {
                var et_player_guid = EbTool.protobufDeserialize <string>(playerfriend_request.data);

                ProtocolResult r = ProtocolResult.Failed;

                // 不可以添加自己为好友
                if (et_player_guid == Entity.Guid)
                {
                    r = ProtocolResult.FriendIsMe;
                    goto End;
                }

                // 不可以重复添加好友
                PlayerInfo current_friend = null;
                Dictionary <string, PlayerInfo> map_friend = Def.mPropMapFriend.get();
                if (map_friend.TryGetValue(et_player_guid, out current_friend))
                {
                    r = ProtocolResult.FriendExistFriend;
                    goto End;
                }

                // 请求添加好友。由于加好友是双向的,需要告知被加的好友
                var grain             = Entity.getUserData <GrainCellPlayer>();
                var grain_playerproxy = grain.GF.GetGrain <ICellPlayerProxy>(new Guid(et_player_guid));
                grain_playerproxy.s2sRequestAddFriend(Entity.Guid);
                r = ProtocolResult.Success;

End:
                PlayerFriendResponse playerfriend_response;
                playerfriend_response.id   = PlayerFriendResponseId.RequestAddFriend;
                playerfriend_response.data = EbTool.protobufSerialize <ProtocolResult>(r);

                result.method_id = MethodType.s2cPlayerFriendResponse;
                result.param1    = EbTool.protobufSerialize <PlayerFriendResponse>(playerfriend_response);
            }
            break;

            case PlayerFriendRequestId.AgreeAddFriend:    // 请求是否同意添加好友
            {
                var addfriend_agree = EbTool.protobufDeserialize <AddFriendAgree>(playerfriend_request.data);

                ProtocolResult r           = ProtocolResult.Failed;
                PlayerInfo     friend_item = null;
                Dictionary <string, PlayerInfo> map_friend = Def.mPropMapFriend.get();

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

                if (player_info != null && !string.IsNullOrEmpty(player_info.player_etguid))
                {
                    //friend_item = new FriendItem();
                    //friend_item.et_guid = player_info.player_etguid;
                    //friend_item.nick_name = player_info.nick_name;
                    //friend_item.icon = player_info.icon;
                    //friend_item.level = player_info.level;
                    //friend_item.exp = player_info.exp;
                    //friend_item.chip = player_info.chip;
                    //friend_item.gold = player_info.gold;
                    //friend_item.individual_signature = player_info.individual_signature;// 个性签名
                    //friend_item.ip_address = player_info.ip_address;// ip所在地
                    //friend_item.is_vip = false;// 是否是VIP
                    //friend_item.vip_level = 0;// VIP等级
                    //friend_item.vip_point = 0;// VIP积分
                    //friend_item.status = FriendOnlineStatus.Offline;// 好友在线状态
                    //friend_item.last_online_dt = DateTime.Now;// 好友最后在线时间
                    //friend_item.desktop_etguid = "";// 如果好友正在牌桌中,该牌桌的EtGuid

                    r = ProtocolResult.Success;

                    if (addfriend_agree.agree)
                    {
                        // 好友数据添加到好友列表
                        map_friend[addfriend_agree.player_etguid] = friend_item;

                        // 通知本地客户端添加好友
                        PlayerFriendNotify friend_notify;
                        friend_notify.id   = PlayerFriendNotifyId.AddFriend;
                        friend_notify.data = EbTool.protobufSerialize(friend_item);
                        _onFriendNotify(friend_notify);

                        // 由于加好友是双向的,需要告知被加的好友
                        var grain_playerproxy = grain.GF.GetGrain <ICellPlayerProxy>(new Guid(addfriend_agree.player_etguid));
                        grain_playerproxy.s2sResponseAddFriend(Entity.Guid, addfriend_agree.agree);
                    }
                }

End:
                PlayerFriendResponse playerfriend_response;
                playerfriend_response.id   = PlayerFriendResponseId.AgreeAddFriend;
                playerfriend_response.data = EbTool.protobufSerialize <ProtocolResult>(r);

                result.method_id = MethodType.s2cPlayerFriendResponse;
                result.param1    = EbTool.protobufSerialize <PlayerFriendResponse>(playerfriend_response);
            }
            break;

            case PlayerFriendRequestId.DeleteFriend:    // 请求删除好友
            {
                var et_player_guid = EbTool.protobufDeserialize <string>(playerfriend_request.data);

                ProtocolResult r = ProtocolResult.Failed;
                PlayerInfo     current_friend = null;
                Dictionary <string, PlayerInfo> map_friend = Def.mPropMapFriend.get();
                if (map_friend.TryGetValue(et_player_guid, out current_friend))
                {
                    map_friend.Remove(current_friend.player_etguid);
                    r = ProtocolResult.Success;
                }
                else
                {
                    goto End;
                }

                // 通知本地客户端删除好友
                PlayerFriendNotify friend_notify;
                friend_notify.id   = PlayerFriendNotifyId.DeleteFriend;
                friend_notify.data = EbTool.protobufSerialize(et_player_guid);
                _onFriendNotify(friend_notify);

                // 告知被删的好友
                var grain             = Entity.getUserData <GrainCellPlayer>();
                var grain_playerproxy = grain.GF.GetGrain <ICellPlayerProxy>(new Guid(et_player_guid));
                grain_playerproxy.s2sDeleteFriend(Entity.Guid);

End:
                PlayerFriendResponse playerfriend_response;
                playerfriend_response.id   = PlayerFriendResponseId.DeleteFriend;
                playerfriend_response.data = EbTool.protobufSerialize <ProtocolResult>(r);

                result.method_id = MethodType.s2cPlayerFriendResponse;
                result.param1    = EbTool.protobufSerialize <PlayerFriendResponse>(playerfriend_response);
            }
            break;

            case PlayerFriendRequestId.FindFriend:    // 请求查找好友
            {
                var find_info = EbTool.protobufDeserialize <string>(playerfriend_request.data);

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

                var list_playerinfo = await grain_playerservice.findPlayers(find_info);

                //List<FriendItem> list_frienditem = new List<FriendItem>();
                //foreach (var i in list_playerinfo)
                //{
                //    PlayerInfo player_info = i;
                //    if (string.IsNullOrEmpty(player_info.player_etguid)) continue;
                //    FriendItem friend_item = new FriendItem();
                //    friend_item.et_guid = player_info.player_etguid;
                //    friend_item.nick_name = player_info.nick_name;
                //    friend_item.icon = player_info.icon;
                //    friend_item.level = player_info.level;
                //    friend_item.exp = player_info.exp;
                //    friend_item.chip = player_info.chip;
                //    friend_item.gold = player_info.gold;
                //    friend_item.individual_signature = player_info.individual_signature;// 个性签名
                //    friend_item.ip_address = player_info.ip_address;// ip所在地
                //    friend_item.is_vip = false;// 是否是VIP
                //    friend_item.vip_level = 0;// VIP等级
                //    friend_item.vip_point = 0;// VIP积分
                //    friend_item.status = FriendOnlineStatus.Offline;// 好友在线状态
                //    friend_item.last_online_dt = DateTime.Now;// 好友最后在线时间
                //    friend_item.desktop_etguid = "";// 如果好友正在牌桌中,该牌桌的EtGuid

                //    list_frienditem.Add(friend_item);
                //}

                PlayerFriendResponse playerfriend_response;
                playerfriend_response.id   = PlayerFriendResponseId.FindFriend;
                playerfriend_response.data = EbTool.protobufSerialize <List <PlayerInfo> >(list_playerinfo);

                result.method_id = MethodType.s2cPlayerFriendResponse;
                result.param1    = EbTool.protobufSerialize <PlayerFriendResponse>(playerfriend_response);
            }
            break;

            default:
                break;
            }

            return(result);
        }
Exemplo n.º 16
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);
    }