Esempio n. 1
0
        internal void HandleRequest(ClientMessage request)
        {
            if (ButterflyEnvironment.diagPackets)
            {
                DateTime start = DateTime.Now;
                this.Request = request;
                StaticClientMessageHandler.HandlePacket(this, request);

                TimeSpan spent = DateTime.Now - start;
                if (spent.TotalMilliseconds > ButterflyEnvironment.timeout)
                {
                    Console.WriteLine("Packet " + request.Id + " took " + spent.Milliseconds + "ms to run. Packetdata: " + request.ToString());
                }
            }
            else
            {
                this.Request = request;
                StaticClientMessageHandler.HandlePacket(this, request);
            }
            //RequestHandler handler;

            //if (RequestHandlers.TryGetValue(pRequest.Id, out handler))
            //{
            //    //Console.ForegroundColor = ConsoleColor.Green;
            //    //Console.WriteLine(string.Format("Processing packetID => [{0}]", pRequest.Id));
            //    //DateTime start = DateTime.Now;
            //    handler.Invoke();

            //    //TimeSpan spent = DateTime.Now - start;

            //    //int msSpent = (int)spent.TotalMilliseconds;

            //    //if (msSpent > timeOut)
            //    //{
            //    //    Logging.LogCriticalException(start.ToString() +  " PacketID: " + pRequest.Id + ", total time: " + msSpent);
            //    //}

            //    //Console.WriteLine(string.Format("[{0}] => Invoked [{1} ticks]", pRequest.Id, spent.Ticks));

            //}
            //else
            //{
            //    //Console.ForegroundColor = ConsoleColor.Red;
                //Console.WriteLine(string.Format("Unknown packetID => [{0}] data: [{1}]", pRequest.Id, pRequest.Header));
            //}

            //TimeSpan TimeUsed = DateTime.Now - start;
            //if (TimeUsed.Milliseconds > 0 || TimeUsed.Seconds > 0)
            //    Console.WriteLine("Total used time: " + TimeUsed.Seconds + "s, " + TimeUsed.Milliseconds + "ms");
        }
Esempio n. 2
0
        internal void HandleRequest(ClientMessage request, int messageID)
        {
			//Console.WriteLine("In -> {0}", messageID);
            if (ButterflyEnvironment.diagPackets)
            {
                DateTime start = DateTime.Now;
                this.Request = request;
                StaticClientMessageHandler.HandlePacket(this, request, messageID);

                TimeSpan spent = DateTime.Now - start;
                if (spent.TotalMilliseconds > ButterflyEnvironment.timeout)
                {
                    Console.WriteLine("Packet " + messageID + " took " + spent.Milliseconds + "ms to run. Packetdata: " + request.ToString());
                }
            }
            else
            {
                this.Request = request;
                StaticClientMessageHandler.HandlePacket(this, request, messageID);
            }
        }
Esempio n. 3
0
 void parser_onNewPacket(ClientMessage Message)
 {
     try
     {
         MessageHandler.HandleRequest(Message);
     }
     catch (Exception e) { Logging.LogPacketException(Message.ToString(), e.ToString()); }
 }
Esempio n. 4
0
        internal static void HandleSave(uint itemID, Room room, ClientMessage clientMessage)
        {
            RoomItem item = room.GetRoomItemHandler().GetItem(itemID);
            if (item == null)
                return;

            if (item.wiredHandler != null)
            {
                item.wiredHandler.Dispose();
                item.wiredHandler = null;
            }

            InteractionType type = item.GetBaseItem().InteractionType;
            switch (type)
            {
                case InteractionType.actiongivescore:
                    {
                        clientMessage.AdvancePointer(1);
                        int points = clientMessage.PopWiredInt32();
                        int games = clientMessage.PopWiredInt32();

                        IWiredTrigger action = new GiveScore(games, points, room.GetGameManager(), itemID);
                        HandleTriggerSave(action, room.GetWiredHandler(), room, itemID);

                        break;
                    }

                case InteractionType.actionmoverotate:
                    {
                        clientMessage.AdvancePointer(1);
                        MovementState movement = (MovementState)clientMessage.PopWiredInt32();
                        RotationState rotation = (RotationState)clientMessage.PopWiredInt32();

                        clientMessage.AdvancePointer(2);
                        int furniCount;
                        List<RoomItem> items = GetItems(clientMessage, room, out furniCount);
                        int delay = clientMessage.PopWiredInt32();

                        IWiredTrigger action = new MoveRotate(movement, rotation, items, delay, room, room.GetWiredHandler(), itemID);
                        HandleTriggerSave(action, room.GetWiredHandler(), room, itemID);

                        break;
                    }

                case InteractionType.actionposreset:
                    {

                        clientMessage.AdvancePointer(3);
                        int furniCount;
                        List<RoomItem> items = GetItems(clientMessage, room, out furniCount);
                        int delay = clientMessage.PopWiredInt32();

                        IWiredTrigger action = new PositionReset(items, delay, room.GetRoomItemHandler(), room.GetWiredHandler(), itemID);
                        HandleTriggerSave(action, room.GetWiredHandler(), room, itemID);

                        break;
                    }

                case InteractionType.actionresettimer:
                    {

                        clientMessage.AdvancePointer(3);
                        int furniCount;
                        List<RoomItem> items = GetItems(clientMessage, room, out furniCount);
                        int delay = clientMessage.PopWiredInt32();

                        IWiredTrigger action = new TimerReset(room, room.GetWiredHandler(), items, delay, itemID);
                        HandleTriggerSave(action, room.GetWiredHandler(), room, itemID);

                        break;
                    }

                case InteractionType.actionshowmessage:
                    {
                        clientMessage.AdvancePointer(1);
                        string message = clientMessage.PopFixedString();

                        IWiredTrigger action = new ShowMessage(message, room.GetWiredHandler(), itemID);
                        HandleTriggerSave(action, room.GetWiredHandler(), room, itemID);
                        break;
                    }

                case InteractionType.actionteleportto:
                    {
                        clientMessage.AdvancePointer(3);
                        int furniCount;
                        List<RoomItem> items = GetItems(clientMessage, room, out furniCount);
                        int delay = clientMessage.PopWiredInt32();

                        IWiredTrigger action = new TeleportToItem(room.GetGameMap(), room.GetWiredHandler(), items, delay, itemID);
                        HandleTriggerSave(action, room.GetWiredHandler(), room, itemID);

                        break;
                    }

                case InteractionType.actiontogglestate:
                    {
                        clientMessage.AdvancePointer(3);
                        int furniCount;
                        List<RoomItem> items = GetItems(clientMessage, room, out furniCount);
                        int delay = clientMessage.PopWiredInt32();

                        IWiredTrigger action = new ToggleItemState(room.GetGameMap(), room.GetWiredHandler(), items, delay, itemID);
                        HandleTriggerSave(action, room.GetWiredHandler(), room, itemID);

                        break;
                    }

                case InteractionType.conditionfurnishaveusers:
                    {
                        clientMessage.AdvancePointer(1);
                        bool a = clientMessage.PopWiredBoolean();
                        bool b = clientMessage.PopWiredBoolean();
                        bool c = clientMessage.PopWiredBoolean();
                        clientMessage.AdvancePointer(2);

                        int furniCount;
                        List<RoomItem> items = GetItems(clientMessage, room, out furniCount);

                        // WTF?
                        //if (a)
                        //{
                        //    int a1 = 2;
                        //}

                        break;
                    }

                case InteractionType.conditionstatepos:
                    {

                        break;
                    }

                case InteractionType.conditiontimelessthan:
                    {

                        break;
                    }

                case InteractionType.conditiontimemorethan:
                    {

                        break;
                    }

                case InteractionType.conditiontriggeronfurni:
                    {

                        break;
                    }

                case InteractionType.specialrandom:
                    {

                        break;
                    }

                case InteractionType.specialunseen:
                    {

                        break;
                    }

                case InteractionType.triggergameend:
                    {
                        IWiredTrigger handler = new GameEnds(item, room.GetWiredHandler(), room.GetGameManager());
                        HandleTriggerSave(handler, room.GetWiredHandler(), room, itemID);
                        break;
                    }

                case InteractionType.triggergamestart:
                    {
                        IWiredTrigger handler = new GameStarts(item, room.GetWiredHandler(), room.GetGameManager());
                        HandleTriggerSave(handler, room.GetWiredHandler(), room, itemID);
                        break;
                    }

                case InteractionType.triggeronusersay:
                    {
                        clientMessage.AdvancePointer(1);
                        bool isOnlyOwner = clientMessage.PopWiredBoolean();
                        clientMessage.AdvancePointer(0);
                        string message = clientMessage.PopFixedString();
                        string stuff = clientMessage.ToString();

                        IWiredTrigger handler = new UserSays(item, room.GetWiredHandler(), isOnlyOwner, message, room);
                        HandleTriggerSave(handler, room.GetWiredHandler(), room, itemID);

                        break;
                    }

                case InteractionType.triggerrepeater:
                    {
                        clientMessage.AdvancePointer(1);
                        int cycleTimes = clientMessage.PopWiredInt32();

                        IWiredTrigger handler = new Repeater(room.GetWiredHandler(), item, cycleTimes);
                        HandleTriggerSave(handler, room.GetWiredHandler(), room, itemID);

                        break;
                    }

                case InteractionType.triggerroomenter:
                    {
                        clientMessage.AdvancePointer(1);
                        string users = clientMessage.PopFixedString();

                        IWiredTrigger handler = new EntersRoom(item, room.GetWiredHandler(), room.GetRoomUserManager(), !string.IsNullOrEmpty(users), users);
                        HandleTriggerSave(handler, room.GetWiredHandler(), room, itemID);
                        break;
                    }

                case InteractionType.triggerscoreachieved:
                    {
                        clientMessage.AdvancePointer(1);
                        int score = clientMessage.PopWiredInt32();

                        IWiredTrigger handler = new ScoreAchieved(item, room.GetWiredHandler(), score, room.GetGameManager());
                        HandleTriggerSave(handler, room.GetWiredHandler(), room, itemID);

                        break;
                    }

                case InteractionType.triggertimer:
                    {
                        clientMessage.AdvancePointer(1);
                        int cycles = clientMessage.PopWiredInt32();

                        IWiredTrigger handler = new Timer(item, room.GetWiredHandler(), cycles, room.GetGameManager());
                        HandleTriggerSave(handler, room.GetWiredHandler(), room, itemID);

                        break;
                    }

                case InteractionType.triggerstatechanged:
                    {
                        clientMessage.AdvancePointer(3);

                        int furniAmount;
                        List<RoomItem> items = GetItems(clientMessage, room, out furniAmount);
                        int delay = clientMessage.PopWiredInt32();

                        IWiredTrigger handler = new SateChanged(room.GetWiredHandler(), item, items, delay);
                        HandleTriggerSave(handler, room.GetWiredHandler(), room, itemID);

                        break;
                    }

                case InteractionType.triggerwalkofffurni:
                    {
                        clientMessage.AdvancePointer(3);

                        int furniAmount;
                        List<RoomItem> items = GetItems(clientMessage, room, out furniAmount);

                        int delay = clientMessage.PopWiredInt32();

                        IWiredTrigger handler = new WalksOffFurni(item, room.GetWiredHandler(), items, delay);
                        HandleTriggerSave(handler, room.GetWiredHandler(), room, itemID);
                        break;
                    }

                case InteractionType.triggerwalkonfurni:
                    {
                        clientMessage.AdvancePointer(3);
                        int furniAmount;
                        List<RoomItem> items = GetItems(clientMessage, room, out furniAmount);

                        int delay = clientMessage.PopWiredInt32();

                        IWiredTrigger handler = new WalksOnFurni(item, room.GetWiredHandler(), items, delay);
                        HandleTriggerSave(handler, room.GetWiredHandler(), room, itemID);

                        break;
                    }
            }
        }
Esempio n. 5
0
        internal void HandleRequest(ClientMessage request)
        {
            if (ButterflyEnvironment.diagPackets)
            {
                DateTime start = DateTime.Now;
                this.Request = request;
                StaticClientMessageHandler.HandlePacket(this, request);

                TimeSpan spent = DateTime.Now - start;
                if (spent.TotalMilliseconds > ButterflyEnvironment.timeout)
                {
                    Console.WriteLine("Packet " + request.Id + " took " + spent.Milliseconds + "ms to run. Packetdata: " + request.ToString());
                }
            }
            else
            {
                this.Request = request;
                StaticClientMessageHandler.HandlePacket(this, request);
            }
            //RequestHandler handler;

            //if (RequestHandlers.TryGetValue(pRequest.Id, out handler))
            //{
            //    //Console.ForegroundColor = ConsoleColor.Green;
            //    //Console.WriteLine(string.Format("Processing packetID => [{0}]", pRequest.Id));
            //    //DateTime start = DateTime.Now;
            //    handler.Invoke();

            //    //TimeSpan spent = DateTime.Now - start;

            //    //int msSpent = (int)spent.TotalMilliseconds;

            //    //if (msSpent > timeOut)
            //    //{
            //    //    Logging.LogCriticalException(start.ToString() +  " PacketID: " + pRequest.Id + ", total time: " + msSpent);
            //    //}

            //    //Console.WriteLine(string.Format("[{0}] => Invoked [{1} ticks]", pRequest.Id, spent.Ticks));


            //}
            //else
            //{
            //    //Console.ForegroundColor = ConsoleColor.Red;
            //Console.WriteLine(string.Format("Unknown packetID => [{0}] data: [{1}]", pRequest.Id, pRequest.Header));
            //}

            //TimeSpan TimeUsed = DateTime.Now - start;
            //if (TimeUsed.Milliseconds > 0 || TimeUsed.Seconds > 0)
            //    Console.WriteLine("Total used time: " + TimeUsed.Seconds + "s, " + TimeUsed.Milliseconds + "ms");
        }