Exemplo n.º 1
0
        protected virtual OperationResponse HandleJoinLobby(MasterClientPeer peer, JoinLobbyRequest operation, SendParameters sendParameters)
        {
            try
            {
                // special handling for game properties send by AS3/Flash (Amf3 protocol) clients
                if (peer.Protocol.ProtocolType == ProtocolType.Amf3V152 || peer.Protocol.ProtocolType == ProtocolType.Json)
                {
                    Utilities.ConvertAs3WellKnownPropertyKeys(operation.GameProperties, null);
                }

                peer.GameChannelSubscription = null;

                var subscription = this.GameList.AddSubscription(peer, operation.GameProperties, operation.GameListCount);
                peer.GameChannelSubscription = subscription;
                peer.SendOperationResponse(new OperationResponse(operation.OperationRequest.OperationCode), sendParameters);


                // publish game list to peer after the response has been sent
                var gameList = subscription.GetGameList();
                var e        = new GameListEvent {
                    Data = gameList
                };
                var eventData = new EventData((byte)EventCode.GameList, e);
                peer.SendEvent(eventData, new SendParameters());

                return(null);
            }
            catch (Exception ex)
            {
                log.Error(ex);
                return(null);
            }
        }
Exemplo n.º 2
0
        protected virtual OperationResponse HandleJoinLobby(MasterClientPeer peer, OperationRequest operationRequest, SendParameters sendParameters)
        {
            // validate operation
            var operation = new JoinLobbyRequest(peer.Protocol, operationRequest);
            OperationResponse response;

            if (OperationHelper.ValidateOperation(operation, log, out response) == false)
            {
                return(response);
            }

            // special handling for game properties send by AS3/Flash (Amf3 protocol) clients
            if (peer.Protocol.ProtocolType == ProtocolType.Amf3V151 || peer.Protocol.ProtocolType == ProtocolType.Amf3V152)
            {
                Utilities.ConvertAs3WellKnownPropertyKeys(operation.GameProperties, null);
            }

            peer.GameChannelSubscription = null;

            var subscription = this.GameList.AddSubscription(peer, operation.GameProperties, operation.GameListCount);

            peer.GameChannelSubscription = subscription;
            peer.SendOperationResponse(new OperationResponse(operationRequest.OperationCode), sendParameters);

            // publish game list to peer after the response has been sent
            var gameList = subscription.GetGameList();
            var e        = new GameListEvent {
                Data = gameList
            };
            var eventData = new EventData((byte)EventCode.GameList, e);

            peer.SendEvent(eventData, new SendParameters());

            return(null);
        }
Exemplo n.º 3
0
        public static void SendUpdatePlayerProfileEvent(this MasterClientPeer peer)
        {
            // Update profile event
            var currentPlayer = peer.GetCurrentPlayer();
            var profileEvent  = new UpdateProfileEvent {
                ProfileData = currentPlayer.ToBson()
            };
            var profileEventData = new EventData((byte)EventCode.PlayerProfile, profileEvent);

            peer.SendEvent(profileEventData, new SendParameters());
        }
Exemplo n.º 4
0
        protected virtual OperationResponse HandleJoinLobby(MasterClientPeer peer, JoinLobbyRequest operation, SendParameters sendParameters)
        {
            try
            {
                peer.GameChannelSubscription = null;

                if (operation.GameListCount > 0 && this.gameListLimit > 0)
                {
                    if (operation.GameListCount > this.gameListLimit)
                    {
                        operation.GameListCount = this.gameListLimit;
                    }
                }

                var subscription = this.GameList.AddSubscription(peer, operation.GameProperties, operation.GameListCount);
                peer.GameChannelSubscription = subscription;
                peer.SendOperationResponse(new OperationResponse(operation.OperationRequest.OperationCode), sendParameters);


                if (subscription != null)
                {
                    // publish game list to peer after the response has been sent
                    var gameList = subscription.GetGameList();

                    if (gameList.Count != 0)
                    {
                        var sb = new StringBuilder();
                        foreach (var game in gameList.Keys)
                        {
                            sb.AppendFormat("{0};", game);
                        }

                        if (log.IsDebugEnabled)
                        {
                            log.DebugFormat("Game list is: {0}", sb.ToString());
                        }
                    }

                    var e = new GameListEvent {
                        Data = gameList
                    };
                    var eventData = new EventData((byte)EventCode.GameList, e);
                    peer.SendEvent(eventData, new SendParameters());
                }

                this.peers.Add(peer);
                return(null);
            }
            catch (Exception ex)
            {
                log.Error(ex);
                return(null);
            }
        }
Exemplo n.º 5
0
        public static void SendDomainConfigurationEvent(this MasterClientPeer peer)
        {
            var domainConfigBytes = MasterApplication.DomainConfiguration.ToBson();

            LogManager.GetCurrentClassLogger().Warn($"DomainConfigBytes: {domainConfigBytes.Length}");
            var e = new UpdateDomainConfigurationEvent {
                DomainConfiguration = domainConfigBytes
            };
            var eventData = new EventData((byte)EventCode.UpdateDomainConfiguration, e);

            peer.SendEvent(eventData, new SendParameters());
        }
Exemplo n.º 6
0
        public static void SendUpdateCurrency(this MasterClientPeer peer)
        {
            // Update profile event
            var currentPlayer       = peer.GetCurrentPlayer();
            var changeCurrencyEvent =
                new UpdateCurrencyEvent
            {
                Gold    = currentPlayer.Gold,
                Crystal = currentPlayer.Crystals,
                Keys    = currentPlayer.Keys,
                HealBox = currentPlayer.HealBox
            };
            var currencyEvenData = new EventData((byte)EventCode.UpdateCurrency, changeCurrencyEvent);

            peer.SendEvent(currencyEvenData, new SendParameters());
        }
Exemplo n.º 7
0
        protected virtual OperationResponse HandleJoinLobby(MasterClientPeer peer, JoinLobbyRequest operation, SendParameters sendParameters)
        {
            try
            {
                // special handling for game properties send by AS3/Flash (Amf3 protocol) clients
                if (peer.Protocol.ProtocolType == ProtocolType.Amf3V152 || peer.Protocol.ProtocolType == ProtocolType.Json)
                {
                    Utilities.ConvertAs3WellKnownPropertyKeys(operation.GameProperties, null);
                }

                peer.GameChannelSubscription = null;

                var subscription = this.GameList.AddSubscription(peer, operation.GameProperties, operation.GameListCount);
                peer.GameChannelSubscription = subscription;
                peer.SendOperationResponse(new OperationResponse(operation.OperationRequest.OperationCode), sendParameters);


                // publish game list to peer after the response has been sent
                var gameList = subscription.GetGameList();
                var e = new GameListEvent { Data = gameList };
                var eventData = new EventData((byte)EventCode.GameList, e);
                peer.SendEvent(eventData, new SendParameters());

                return null;
            }
            catch (Exception ex)
            {
                log.Error(ex);
                return null;
            }
        }