コード例 #1
0
        private void LookingUpPlayer()
        {
            // Spend at most 10 seconds to lookup a player
            Context.SetReceiveTimeout(null);
            Context.SetReceiveTimeout(TimeSpan.FromSeconds(10.0));

            Receive <PlayerLoginEvt>(e => Stash.Stash());

            Receive <PlayerIdMap>(map =>
            {
                // put in local state
                _currentLookupPlayer = map;

                // create player actor by checking if player actor is around
                _playerManagerBroadcaster.Tell(new DoYouHaveThisPlayerReq(map));

                var managerMembers = _playerManagerBroadcaster.Ask <Routees>(
                    new GetRoutees()).Result.Members.ToList();
                OutstandingPlayerActorLookupAcks = managerMembers.Count();

                _logger.Info($"OutstandingPlayerActorLookupAcks: {OutstandingPlayerActorLookupAcks}");
            });

            Receive <DoYouHaveThisPlayerReq>(HandlePlayerLookupRequest);
            Receive <PlayerFoundEvt>(HandlePlayerFoundEvt);

            Receive <PlayerNotFoundEvt>(evt =>
            {
                if (evt.Player.Id == _currentLookupPlayer.Id)
                {
                    // Indicates this node is the one who sent out request to lookup player
                    OutstandingPlayerActorLookupAcks--;

                    if (OutstandingPlayerActorLookupAcks <= 0)
                    {
                        // Since no one has this player (including myself)
                        // We will create this player actor here

                        var player = Context.ActorOf(
                            PlayerActor.Props(evt.Player), evt.Player.Id.ToString());

                        _playerManagerBroadcaster.Tell(new PlayerFoundEvt(evt.Player, player));

                        _logger.Debug($"Player {player.Path} created in {Self.Path}");
                    }
                }
            });

            Receive <ReceiveTimeout>(timeout =>
            {
                _logger.Debug(
                    $"[{Self.Path}]: Waited for 10secs without Playerbook response, player may not have registered..");
                BecomeReady();
            });
        }
コード例 #2
0
        public PlayerActor(PlayerIdMap playerIdMap)
        {
            _playerIdMap = playerIdMap;

            // TODO: We might want to store some more interesting information of this player
            // they can be stored in other storage rather then in memory so f**k that for now
            _profile = new PlayerProfile(_playerIdMap.Id, null, _playerIdMap.Email);

            Recover <DepositEvt>(d => _profile.Deposit(d.Amt));
            Recover <WithdrawalEvt>(w => _profile.Withdrawal(w.Amt));


            Command <RecoveryCompleted>(completed => _log.Info($"Recovery completed."));

            Command <DepositEvt>(d => Persist(d, c => _profile.Deposit(c.Amt)));
            Command <WithdrawalEvt>(w => Persist(w, c => _profile.Deposit(c.Amt)));

            Command <GetBalanceEvt>(_ =>
            {
                Sender.Tell(this._profile.Balance, Self);
            });
        }
コード例 #3
0
 public static Props Props(PlayerIdMap profile)
 {
     return(Akka.Actor.Props.Create(() => new PlayerActor(profile)));
 }