예제 #1
0
파일: Tools.cs 프로젝트: tyrdom/hang_up
        public static CharactersGetResponse GenCharactersGetResponseByPlayerCharacters(
            PlayerCharacters playerCharacters)
        {
            var characters = playerCharacters.CharactersIdToStatus.Select(pair => new CharactersGetResponse.Character
            {
                Id = pair.Key, characterStatus = pair.Value
            });

            return(new CharactersGetResponse
            {
                Characters = characters.ToList(), inBattleIds = playerCharacters.inBattle.ToArray()
            });
        }
예제 #2
0
파일: LinkActor.cs 프로젝트: tyrdom/hang_up
        private void OnLine()
        {
            FamousActors.MongodbPlayerStatusActor.Tell(new InitStatus(_accountId));

            // ICancelable scheduleTellRepeatedlyCancelable = Context.System.Scheduler.ScheduleTellRepeatedlyCancelable(
            //     TimeSpan.FromMinutes(10),
            //     TimeSpan.FromMinutes(10),
            //     Self, SavePlayerDB.Instance
            //     , ActorRefs.Nobody);
            void ReallyLoginOk()
            {
                _temp.bankBaseResponse      = Tools.GenBankBaseResponseByPlayBank(_myWallet);
                _temp.charactersGetResponse = Tools.GenCharactersGetResponseByPlayerCharacters(_myCharacters);
                var aMsg = new AMsg
                {
                    type        = AMsg.Type.ResponseMsg,
                    responseMsg = { head = ResponseMsg.Head.LoginResponse, loginResponse = _temp }
                };

                _tcpActorRef.Tell(GenTcpWrite(aMsg));
            }

            Receive <PlayerStatus>(status =>
            {
                _myWallet     = status.PlayerBank;
                _myGames      = status.PlayerGames;
                _myCharacters = status.PlayerCharacters;
                ReallyLoginOk();
            });


            Receive <ErrorResponse>(response =>
                                    _tcpActorRef.Tell(GenTcpWrite(
                                                          new AMsg
            {
                type        = AMsg.Type.ResponseMsg,
                responseMsg = { head = ResponseMsg.Head.ErrorResponse, errorResponse = response }
            }
                                                          ))
                                    );
            Receive <Tcp.ConnectionClosed>(closed =>
            {
                OffLineSave(OutReason.Drop);
                _log.Info($"Stopped, remote connection [{_remote}] closed");
                Context.Stop(Self);
            });
            Receive <Terminated>(terminated =>
            {
                OffLineSave(OutReason.Drop);
                _log.Info($"Stopped, remote connection [{_remote}] died");

                Context.Stop(Self);
            });

            Receive <LogoutResponse>(response =>
            {
                _tcpActorRef.Tell(GenTcpWrite(new AMsg
                {
                    type        = AMsg.Type.ResponseMsg,
                    responseMsg = { head = ResponseMsg.Head.LogoutResponse, logoutResponse = response }
                }));
            });
            Receive <Tcp.Received>(received =>
            {
                var aMsg     = ProtoTool.DeSerialize <AMsg>(received.Data.ToArray());
                var aMsgType = aMsg.type;

                if (aMsgType == AMsg.Type.RequestMsg && _gameState == GameState.Online && _accountId != null)
                {
                    var aMsgRequestMsg = aMsg.requestMsg;
                    switch (aMsgRequestMsg.head)
                    {
                    case RequestMsg.Head.BankBaseRequest:

                        var genBankBaseResponseByPlayBank = Tools.GenBankBaseResponseByPlayBank(_myWallet);
                        Sender.Tell(GenTcpWrite(new AMsg()
                        {
                            type        = AMsg.Type.ResponseMsg,
                            responseMsg = new ResponseMsg()
                            {
                                head             = ResponseMsg.Head.BankBaseResponse,
                                bankBaseResponse = genBankBaseResponseByPlayBank
                            }
                        }));
                        break;

                    case RequestMsg.Head.BankItemAllRequest:

                        var genBankItemAllResponseByPlayBank = Tools.GenBankItemResponseByPlayBank(_myWallet);
                        Sender.Tell(GenTcpWrite(new AMsg()
                        {
                            type        = AMsg.Type.ResponseMsg,
                            responseMsg = new ResponseMsg()
                            {
                                head             = ResponseMsg.Head.BankItemResponse,
                                bankItemResponse = genBankItemAllResponseByPlayBank
                            }
                        }));
                        break;

                    case RequestMsg.Head.BankItemCustomRequest:
                        var genBankItemResponseByPlayBank =
                            Tools.GenBankItemResponseByPlayBank(_myWallet,
                                                                aMsgRequestMsg.bankCustomItemRequest.itemIds);
                        Sender.Tell(GenTcpWrite(new AMsg()
                        {
                            type        = AMsg.Type.ResponseMsg,
                            responseMsg = new ResponseMsg()
                            {
                                head             = ResponseMsg.Head.BankItemResponse,
                                bankItemResponse = genBankItemResponseByPlayBank
                            }
                        }));
                        break;


                    case RequestMsg.Head.LogoutRequest:

                        OffLineSave(OutReason.LogOut);
                        _gameState = GameState.OffLine;
                        Become(OffLine);
                        break;

                    default:
                        _tcpActorRef.Tell(Tcp.Close.Instance);
                        throw new ArgumentOutOfRangeException();
                    }
                }
                else
                {
                    _tcpActorRef.Tell(Tcp.Close.Instance);
                    throw new ArgumentOutOfRangeException();
                }
            });
        }
예제 #3
0
 public SaveCharacters(PlayerCharacters playerCharacters)
 {
     PlayerCharacters = playerCharacters;
 }
예제 #4
0
 public PlayerStatus(PlayerBank playerBank, PlayerGames playerGames, PlayerCharacters playerCharacters)
 {
     PlayerBank       = playerBank;
     PlayerGames      = playerGames;
     PlayerCharacters = playerCharacters;
 }