Exemple #1
0
        protected override bool OnHandleMessage(IMessage message, PhotonServerPeer serverPeer)
        {
            var para = new Dictionary <byte, object>()
            {
                { (byte)ClientParameterCode.PeerId, message.Parameters[(byte)ClientParameterCode.PeerId] },
                { (byte)ClientParameterCode.SubOperationCode, MessageSubCode.PullQueue },
            };

            var operation = new CreateQueueOperation(serverPeer.Protocol, message);

            if (!operation.IsValid)
            {
                serverPeer.SendOperationResponse(new OperationResponse
                                                     (message.Code, para)
                {
                    ReturnCode = (int)ErrorCode.OperationInvalid, DebugMessage = "Create queue operation invalid"
                }, new SendParameters());
            }

            var instance = Util.GetCPlayerInstance(Server, message);

            var queueItemRequest = SerializeUtil.Deserialize <FightQueueListItem>(operation.fightInit);

            queueItemRequest.Creator = instance.Name;

            Fight newFight           = instance.CurrentFight;
            bool  wasAllowedNewFight = false;

            if (instance.CurrentFight == null)
            {
                newFight           = _fightManager.AddFight(queueItemRequest);
                wasAllowedNewFight = newFight.addPlayer(1, instance);                 //1 - red, 2 - blue teams
//			    IEffect effect = EffectCache.GetEffect(EffectEnum.INJURY);
//                Log.DebugFormat("Fetched effect of type: {0}", effect.GetType());
//                instance.Effects.Apply(effect);
            }

            //send response with refreshed queue list

            if (wasAllowedNewFight)
            {
                instance.SendPacket(new PulledQueuesPacket(_fightManager));
                foreach (var player in newFight.getPlayers.Values)
                {
                    player.SendPacket(new FightQueueParticipantsPacket(newFight));
                    Log.Debug(CLASSNAME + " - OnHandleMessage:: sending queue info back to client");
                }
            }
            else
            {
                serverPeer.SendOperationResponse(new OperationResponse(message.Code)
                {
                    ReturnCode   = (int)ErrorCode.AlreadyInFight,
                    DebugMessage = "Already queued/engaged in a fight",
                    Parameters   = para,
                }, new SendParameters());
                Log.Debug(CLASSNAME + " - OnHandleMessage:: was not allowed a new fight");
            }
            return(true);
        }