Beispiel #1
0
 protected override void Parse(EndianBinaryReader r)
 {
     Position = CoordInt.Read(r);
     try
     {
         Text1 = ChatJson.Parse(ReadString8(r));
         Text2 = ChatJson.Parse(ReadString8(r));
         Text3 = ChatJson.Parse(ReadString8(r));
         Text4 = ChatJson.Parse(ReadString8(r));
     } 
     #if !DEBUG
     catch (Exception ex)
     {
     Log.WriteServer (ex);
     }
     #endif
     finally
     {
     }      	
 }
 //Only parsed so we can block it
 protected override void Parse(EndianBinaryReader r)
 {
     Header = ChatJson.Parse(ReadString8(r));
     Footer = ChatJson.Parse(ReadString8(r));
 }
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            if (objectType == typeof(List<ChatJson>))
            {
                if (reader.TokenType != JsonToken.StartArray)
                    throw new InvalidOperationException();

                var l = new List<ChatJson>();
                while (true)
                {
                    if (!reader.Read())
                        break;
                    if (reader.TokenType == JsonToken.EndArray)
                        break;
                    l.Add((ChatJson)ReadJson(reader, typeof(ChatJson), null, serializer));
                }    
                return l;
            }

            if (reader.TokenType == JsonToken.String)
            {
                var a = new ChatJson();
                a.Raw = true;
                a.Text = (string)reader.Value;
                return a;
            }

            if (reader.TokenType != JsonToken.StartObject)
                throw new InvalidOperationException();
            var x = new ChatJson();
            while (true)
            {
                if (!reader.Read())
                    break;
                if (reader.TokenType == JsonToken.EndObject)
                    break;
                if (reader.TokenType != JsonToken.PropertyName)
                    throw new NotImplementedException(reader.TokenType.ToString());

                string key = (string)reader.Value;
                if (!reader.Read())
                    break;

                switch (key)
                {
                    case "color":
                        x.Color = (string)reader.Value;
                        break;
                    case "italic":
                        x.Italic = (bool)reader.Value;
                        break;
                    case "translate":
                        x.Translate = (string)reader.Value;
                        break;
                    case "with":
                            //x.With = (List<ChatJson>)serializer.Deserialize(reader, typeof(List<ChatJson>));
                        x.With = (List<ChatJson>)ReadJson(reader, typeof(List<ChatJson>), null, serializer);
                        break;
                    case "clickEvent":
                        x.ClickEvent = (ChatEvent)serializer.Deserialize(reader, typeof(ChatEvent));
                        break;
                    case "hoverEvent":
                        x.HoverEvent = (ChatEvent)serializer.Deserialize(reader, typeof(ChatEvent));
                        break;
                    case "text":
                        x.Text = (string)reader.Value;
                        break;
                    case "extra":
                        x.Extra = (List<ChatJson>)ReadJson(reader, typeof(List<ChatJson>), null, serializer);
                        break;
                    case "insertion":
                        x.Insertion = (string)reader.Value;
                        break;
                    default:
                        throw new NotImplementedException(key);
                }
            }
            return x;
        }
Beispiel #4
0
        /// <summary>
        /// Pure chat messages
        /// </summary>
        public static void ParseClientChat(Client player, string message)
        {
            //Block unknown prevent mistype
            if (message.StartsWith(",") || message.StartsWith(">"))
            {
                player.TellSystem(Chat.Red, "unknown start symbol, begin with a space to ignore");
                return;
            }

            //remove links from new players

            /*
             * if (player.Uptime.TotalDays < 2)
             * {
             *  player.Tell(Chat.Purple, "New players can't send links");
             *  message = message.Replace("http://", "");
             *  message = message.Replace("https://", "");
             *  var mp = message.Split();
             *  foreach(var m in mp)
             *  {
             *      if(m.StartsWith("http://") ||  m.StartsWith("https://"))
             *  }
             * }*/

            //Short /tell
            if (message.StartsWith("."))
            {
                string[] parts = message.Substring(1).Split(' ');
                if (parts.Length < 2)
                {
                    player.TellSystem(Chat.Red, "Usage: .username message");
                    return;
                }
                message = FormatSpell(player, parts.JoinFrom(1));
                Chatting.Parser.SendPrivateMessage(player, parts [0], message);
                return;
            }

            //Short reply
            if (message.StartsWith("<"))
            {
                if (player.LastInTell == null)
                {
                    player.TellSystem(Chat.Red, "You must have received a private message before replying");
                    return;
                }
                message = FormatSpell(player, message.Substring(1));
                Chatting.Parser.SendPrivateMessage(player, player.LastInTell, message);
                return;
            }

            //Short /t
            if (message.StartsWith("-"))
            {
                if (player.LastOutTell == null)
                {
                    player.TellSystem(Chat.Red, "Use \".username message\" one time first");
                    return;
                }
                message = FormatSpell(player, message.Substring(1));
                Chatting.Parser.SendPrivateMessage(player, player.LastOutTell, message);
                return;
            }

            //CAPS block
            if (message.Length > 3)
            {
                string caps = message.ToUpperInvariant();
                if (caps == message)
                {
                    message = message.ToLowerInvariant();
                }
            }

            //Shout !
            if (message == "!")
            {
                message = "!!";
            }
            bool shout = message.StartsWith("!");

            if (shout)
            {
                message = message.Substring(1);
            }
            if (player.Session.CurrentRegion != null && player.Session.CurrentRegion.Type == "spawn" && player.ChatChannel == null)
            {
                shout = true;
            }

            int receivers = 0;

            //No shouting for banned
            if (shout && Banned.CheckBanned(player) != null)
            {
                player.TellSystem(Chat.Red, "No shouting for the banned!");
                return;
            }

            //Format Translate Spell for all other
            message = FormatSpell(player, message);

            //War chat
            if (!shout)
            {
                if (WarChat(player, message))
                {
                    return;
                }
            }
            if (player.Settings.Cloaked != null || player.Session is PossessSession)
            {
                player.TellSystem(Chat.Red, "no chat while cloaked, pm still works");
                return;
            }


            foreach (Client p in  PlayerList.List)
            {
                if (shout)
                {
                    p.TellSystem(Chat.Gold + player.Name + " " + Chat.White + (p.Settings.Help ? "[shout] " : ""), message);
                    receivers += 1;
                    continue;
                }

                if (player.ChatChannel != null)
                {
                    //Channel chat
                    if (player.ChatChannel == p.ChatChannel)
                    {
                        p.TellSystem(Chat.Blue + player.Name + " " + Chat.Green + "[" + p.ChatChannel + "] ", message);
                        receivers += 1;
                    }
                    continue;
                }

                double distance = player.Session.Position.DistanceTo(p.Session.Position);

                //residents always hear
                if (distance >= DistanceMax && TalkingToResident(player, p))
                {
                    p.TellSystem(Chat.Blue + player.Name + " " + Chat.Aqua + "[" + player.Session.CurrentRegion.Name + "] " + Chat.Gray, message);
                    receivers += 1;
                    continue;
                }

                if (p.Settings.Firehose == false)
                {
                    if (player.Session.World != p.Session.World)
                    {
                        continue;
                    }
                    if (player.Session.Dimension != p.Session.Dimension)
                    {
                        continue;
                    }
                }
                else
                {
                    if (player.Session.World != p.Session.World)
                    {
                        distance = DistanceMax + 1;
                    }
                    if (player.Session.Dimension != p.Session.Dimension)
                    {
                        distance = DistanceMax + 1;
                    }

                    //firehose does not hear banned
                    if ((p.Session is HellSession == false) && Banned.CheckBanned(player) != null)
                    {
                        continue;
                    }
                }

                var chatText = new ChatJson()
                {
                    Text  = message,
                    Color = "gray",
                    //HoverEvent = ChatEvent.HoverShowText("that's what " + player.Name + " said"),
                };
                var c = new ChatJson();
                c.Translate = "%1$s %2$s";
                c.With      = new List <ChatJson>()
                {
                    new ChatJson()
                    {
                        Text       = player.Name,
                        Color      = "blue",
                        ClickEvent = ChatEvent.ClickSuggestCommand("." + player.Name + " "),
                        HoverEvent = ChatEvent.HoverShowText("send private message"),
                    },
                    chatText
                };

                if (distance < DistanceClose && p != player)
                {
                    chatText.Color = "yellow";
                }
                else if (distance < DistanceFar || p.Settings.Firehose && distance < DistanceMax)
                {
                    chatText.Color = "white";
                }
                else if (distance < DistanceMax || p.Settings.Firehose)
                {
                    chatText.Color = "gray";
                }
                else
                {
                    continue;
                }

                var packet = new ChatMessageServer();
                packet.Json = c;

                //Send message
                p.Queue.Queue(packet);

                if (p.Settings.Cloaked != null) //Dont count cloaked players
                {
                    continue;
                }

                if (p != player)
                {
                    receivers += 1;
                }
            }

            if (receivers == 0)
            {
                player.TellSystem(Chat.Blue, "No one heard you, " + Chat.Gray + "see /help");
            }

            Log.WriteChat(player, player.ChatChannel, receivers, message);

            player.ChatEntry = new Entry(player.ChatChannel, message);
        }
Beispiel #5
0
 protected override void Parse(EndianBinaryReader r)
 {
     Reason = ChatJson.Parse(ReadString8(r));
     Debug.WriteLine(this);
 }
Beispiel #6
0
 public Disconnect(string message)
 {
     this.Reason = new ChatJson();
     this.Reason.Text = message;
 }
Beispiel #7
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            if (objectType == typeof(List <ChatJson>))
            {
                if (reader.TokenType != JsonToken.StartArray)
                {
                    throw new InvalidOperationException();
                }

                var l = new List <ChatJson>();
                while (true)
                {
                    if (!reader.Read())
                    {
                        break;
                    }
                    if (reader.TokenType == JsonToken.EndArray)
                    {
                        break;
                    }
                    l.Add((ChatJson)ReadJson(reader, typeof(ChatJson), null, serializer));
                }
                return(l);
            }

            if (reader.TokenType == JsonToken.String)
            {
                var a = new ChatJson();
                a.Raw  = true;
                a.Text = (string)reader.Value;
                return(a);
            }

            if (reader.TokenType != JsonToken.StartObject)
            {
                throw new InvalidOperationException();
            }
            var x = new ChatJson();

            while (true)
            {
                if (!reader.Read())
                {
                    break;
                }
                if (reader.TokenType == JsonToken.EndObject)
                {
                    break;
                }
                if (reader.TokenType != JsonToken.PropertyName)
                {
                    throw new NotImplementedException(reader.TokenType.ToString());
                }

                string key = (string)reader.Value;
                if (!reader.Read())
                {
                    break;
                }

                switch (key)
                {
                case "color":
                    x.Color = (string)reader.Value;
                    break;

                case "italic":
                    x.Italic = (bool)reader.Value;
                    break;

                case "translate":
                    x.Translate = (string)reader.Value;
                    break;

                case "with":
                    //x.With = (List<ChatJson>)serializer.Deserialize(reader, typeof(List<ChatJson>));
                    x.With = (List <ChatJson>)ReadJson(reader, typeof(List <ChatJson>), null, serializer);
                    break;

                case "clickEvent":
                    x.ClickEvent = (ChatEvent)serializer.Deserialize(reader, typeof(ChatEvent));
                    break;

                case "hoverEvent":
                    x.HoverEvent = (ChatEvent)serializer.Deserialize(reader, typeof(ChatEvent));
                    break;

                case "text":
                    x.Text = (string)reader.Value;
                    break;

                case "extra":
                    x.Extra = (List <ChatJson>)ReadJson(reader, typeof(List <ChatJson>), null, serializer);
                    break;

                case "insertion":
                    x.Insertion = (string)reader.Value;
                    break;

                default:
                    throw new NotImplementedException(key);
                }
            }
            return(x);
        }
Beispiel #8
0
        /// <summary>
        /// Pure chat messages
        /// </summary>
        public static void ParseClientChat(Client player, string message)
        {
            //Block unknown prevent mistype
            if (message.StartsWith(",") || message.StartsWith(">"))
            {
                player.TellSystem(Chat.Red, "unknown start symbol, begin with a space to ignore");
                return;
            }
            
            //remove links from new players
            /*
            if (player.Uptime.TotalDays < 2)
            {
                player.Tell(Chat.Purple, "New players can't send links");
                message = message.Replace("http://", "");
                message = message.Replace("https://", "");
                var mp = message.Split();
                foreach(var m in mp)
                {
                    if(m.StartsWith("http://") ||  m.StartsWith("https://"))
                }
            }*/

            //Short /tell
            if (message.StartsWith("."))
            {
                string[] parts = message.Substring(1).Split(' ');
                if (parts.Length < 2)
                {
                    player.TellSystem(Chat.Red, "Usage: .username message");
                    return;
                }
                message = FormatSpell(player, parts.JoinFrom(1));
                Chatting.Parser.SendPrivateMessage(player, parts [0], message);
                return;
            }
            
            //Short reply
            if (message.StartsWith("<"))
            {
                if (player.LastInTell == null)
                {
                    player.TellSystem(Chat.Red, "You must have received a private message before replying");
                    return;
                }
                message = FormatSpell(player, message.Substring(1));
                Chatting.Parser.SendPrivateMessage(player, player.LastInTell, message);
                return;
            }
            
            //Short /t
            if (message.StartsWith("-"))
            {
                if (player.LastOutTell == null)
                {
                    player.TellSystem(Chat.Red, "Use \".username message\" one time first");
                    return;
                }
                message = FormatSpell(player, message.Substring(1));
                Chatting.Parser.SendPrivateMessage(player, player.LastOutTell, message);
                return;
            }

            //CAPS block
            if (message.Length > 3)
            {
                string caps = message.ToUpperInvariant();
                if (caps == message)
                    message = message.ToLowerInvariant();
            }
            
            //Shout !
            if (message == "!")
                message = "!!";
            bool shout = message.StartsWith("!");
            if (shout)
                message = message.Substring(1);
            if (player.Session.CurrentRegion != null && player.Session.CurrentRegion.Type == "spawn" && player.ChatChannel == null)
                shout = true;
            
            int receivers = 0;
            
            //No shouting for banned
            if (shout && Banned.CheckBanned(player) != null)
            {
                player.TellSystem(Chat.Red, "No shouting for the banned!");
                return;
            }

            //Format Translate Spell for all other
            message = FormatSpell(player, message);

            //War chat
            if (!shout)
            {
                if (WarChat(player, message))
                    return;
            }
            if (player.Settings.Cloaked != null || player.Session is PossessSession)
            {
                player.TellSystem(Chat.Red, "no chat while cloaked, pm still works");
                return;
            }
            
            
            foreach (Client p in  PlayerList.List)
            {
                if (shout)
                {
                    p.TellSystem(Chat.Gold + player.Name + " " + Chat.White + (p.Settings.Help ? "[shout] " : ""), message);
                    receivers += 1;
                    continue;
                }
                
                if (player.ChatChannel != null)
                {
                    //Channel chat
                    if (player.ChatChannel == p.ChatChannel)
                    {
                        p.TellSystem(Chat.Blue + player.Name + " " + Chat.Green + "[" + p.ChatChannel + "] ", message);
                        receivers += 1;
                    }
                    continue;
                }
                
                double distance = player.Session.Position.DistanceTo(p.Session.Position);
                
                //residents always hear
                if (distance >= DistanceMax && TalkingToResident(player, p))
                {
                    p.TellSystem(Chat.Blue + player.Name + " " + Chat.Aqua + "[" + player.Session.CurrentRegion.Name + "] " + Chat.Gray, message);
                    receivers += 1;
                    continue;
                }
                
                if (p.Settings.Firehose == false)
                {
                    if (player.Session.World != p.Session.World)
                        continue;
                    if (player.Session.Dimension != p.Session.Dimension)
                        continue;
                } else
                {
                    if (player.Session.World != p.Session.World)
                        distance = DistanceMax + 1;
                    if (player.Session.Dimension != p.Session.Dimension)
                        distance = DistanceMax + 1;
                    
                    //firehose does not hear banned
                    if ((p.Session is HellSession == false) && Banned.CheckBanned(player) != null)
                        continue;
                }

                var chatText = new ChatJson()
                {
                    Text = message,
                    Color = "gray",
                    //HoverEvent = ChatEvent.HoverShowText("that's what " + player.Name + " said"),
                };
                var c = new ChatJson();
                c.Translate = "%1$s %2$s";
                c.With = new List<ChatJson>()
                {
                    new ChatJson()
                    {
                        Text = player.Name,
                        Color = "blue",
                        ClickEvent = ChatEvent.ClickSuggestCommand("." + player.Name + " "),
                        HoverEvent = ChatEvent.HoverShowText("send private message"),
                    },
                    chatText
                };

                if (distance < DistanceClose && p != player)
                    chatText.Color = "yellow";
                else if (distance < DistanceFar || p.Settings.Firehose && distance < DistanceMax)
                    chatText.Color = "white";
                else if (distance < DistanceMax || p.Settings.Firehose)
                    chatText.Color = "gray";
                else
                    continue;

                var packet = new ChatMessageServer();
                packet.Json = c;

                //Send message
                p.Queue.Queue(packet);

                if (p.Settings.Cloaked != null) //Dont count cloaked players
                    continue;
                
                if (p != player)
                    receivers += 1;
            }
            
            if (receivers == 0)
                player.TellSystem(Chat.Blue, "No one heard you, " + Chat.Gray + "see /help");
            
            Log.WriteChat(player, player.ChatChannel, receivers, message);
            
            player.ChatEntry = new Entry(player.ChatChannel, message);
        }
 public DisconnectHandshake(string message)
 {
     var msg = ChatMessageServer.CreateText(message);
     this.Message = msg.Json;
     this.Message.Color = "red";
 }
Beispiel #10
0
        /// <summary>
        /// What the Server sends to the client
        /// </summary>
        protected virtual void FromServerGaming(PacketFromServer packet)
        {
            try
            {
                byte pid = packet.PacketID;

                if (pid == PassThrough.ID)
                {
                    Player.SendToClient(packet);
                    return;
                }

                //Before we rewrite the eid
                //Record all presented mobs, so far we have no method of cleaning this up so hold your thumbs
                if (pid == SpawnMob.ID)
                    World.Main.UpdateEntity((SpawnMob)packet);              
                if (pid == EntityMetadata.ID)
                    World.Main.UpdateEntity((EntityMetadata)packet);
                //if (pid == SpawnPlayer.ID)
                //World.Main.UpdateEntity((SpawnPlayer)packet);
                if (pid == SpawnObject.ID)
                    World.Main.UpdateEntity((SpawnObject)packet);
                if (pid == SpawnPainting.ID)
                    World.Main.UpdateEntity((SpawnPainting)packet);

                //Rewrite own EID, Fix eid to client eid player
                if (packet is IEntity)
                {
                    IEntity ie = (IEntity)packet;
                    if (ie.EID == EID)
                    {
                        ie.EID = Player.EntityID;
                        packet.SetPacketBuffer(null);
                    }
                }
                if (pid == SpawnObject.ID)
                {
                    var so = (SpawnObject)packet;
                    if (so.SourceEntity == EID)
                    {
                        so.SourceEntity = Player.EntityID;
                        packet.SetPacketBuffer(null);
                    }
                }

                //Region filters
                if (CurrentRegion != null && CurrentRegion.FilterServer(this, packet))
                    return;
                
                //Cloak and Nick
                if (Cloak.Filter(this, packet))
                    return;

                switch (pid)
                {
                    case SpawnPlayer.ID:
                        //Change reported uuid from offline to the known with names
                        var sp = (SpawnPlayer)packet;
                        var p = PlayerList.GetPlayerBySpawn(sp);
                        if (p != null)
                        {
                            Debug.WriteLine("SpawnPlayer changed from " + sp.PlayerUUID);
                            Debug.WriteLine("SpawnPlayer changed to   " + p.UUID);
                            sp.PlayerUUID = p.UUID;
                            sp.SetPacketBuffer(null);

                            //Naive attempt
                            sp = new SpawnPlayer(sp.EID, p);
                            sp.Position = sp.Position;
                            sp.Pitch = sp.Pitch;
                            sp.Yaw = sp.Yaw;
                        }
                        else
                            Debug.WriteLine("SpawnPlayer not changed: " + sp.PlayerUUID);

                        break;

                    case ChangeGameState.ID:
                        ChangeGameState ns = packet as ChangeGameState;
                        if (ns.Reason == GameState.BeginRaining || ns.Reason == GameState.EndRaining)
                            World.Main.Weather = ns;
                        if (ns.Reason == GameState.ChangeGameMode)
                            Mode = (GameMode)ns.Value;
                        break;

                    case SpawnObject.ID:
                        var so = (SpawnObject)packet;
                        if (so.Type != Vehicles.Item)
                            break;
                        OreTracker.Spawn(so, Position);
                        break;
                    case EntityMetadata.ID:
                        OreTracker.Track((EntityMetadata)packet);
                        break;

                    case EntityEffect.ID:
                        EntityEffect ee = (EntityEffect)packet;
                        if (ee.Effect == PlayerEffects.MoveSpeed)
                        {
                            EffectSpeed.Active = true;
                            EffectSpeed.Amplifier = ee.Amplifier;
                        }
                        if (ee.Effect == PlayerEffects.MoveSlowdown)
                        {
                            EffectSlow.Active = true;
                            EffectSlow.Amplifier = ee.Amplifier;
                        }
                        break;

                    case RemoveEntityEffect.ID:
                        RemoveEntityEffect re = (RemoveEntityEffect)packet;
                        if (re.Effect == PlayerEffects.MoveSpeed)
                            EffectSpeed.Active = false;
                        if (re.Effect == PlayerEffects.MoveSlowdown)
                            EffectSlow.Active = false;
                        break;
                
                    case TimeUpdate.ID:
                        World.Main.Time = packet as TimeUpdate;
                        break;

                    case UseBed.ID:
                        UseBed ub = (UseBed)packet;
                        if (ub.EID == Player.EntityID)
                            Sleeping = true;
                        break;

                //Waking up, among other things
                    case Animation.ID:
                        Animation a = (Animation)packet;
                        if (a.EID == Player.EntityID)
                        {
                            if (a.Animate == Animations.LeaveBed)
                                Sleeping = false;
                        }
                        break;
                                
#region Position and speed
                
                //Regions and player position
                    case PlayerPositionLookServer.ID:
                        var pp = (PlayerPositionLookServer)packet;
                        if (pp.Position.Y % 1 > 0.95)
                        {
                            //Console.WriteLine(pp.Position.ToString("0.00") + " " + pp.HeadY);
                            pp.Position.Y = Math.Ceiling(Position.Y);
                            //pp.HeadPosition = Position.Y + 1.62;
                            //Console.WriteLine(pp.Position.ToString("0.00") + " " + pp.Stance);
                            packet.SetPacketBuffer(null);
                        }
                        SetPosition(pp.Position, false);
                        break;

                    case Respawn.ID:
                        Dimension = ((Respawn)packet).Dimension;
                        SetPosition(Position, false);
                        break;                

                //Boats and carts
                    case AttachEntity.ID:
                        AttachEntity ae = (AttachEntity)packet;
                        if (ae.EID == Player.EntityID)
                        {
                            AttachedEntity = ae.VehicleID;
                        }
                        break;
                
                    case UpdateBlockEntity.ID:
                        if (Player.Admin())
                        {
                            var ute = (UpdateBlockEntity)packet;
                            if (ute.Action == UpdateBlockEntity.Actions.MobSpawner)
                            {
                                if (Spawners.Contains(ute.Pos) == false)
                                    Spawners.Add(ute.Pos);
                            }
                        }
                        break;

                    case EntityTeleport.ID:
                        if (AttachedEntity != 0)
                        {
                            EntityTeleport et = (EntityTeleport)packet;
                            if (et.EID == AttachedEntity)
                            {
                                SetPosition(et.Position, false);
                            }
                        }
                        break;

                    case EntityRelativeMove.ID:
                        if (AttachedEntity != 0)
                        {
                            EntityRelativeMove er = (EntityRelativeMove)packet;
                            if (er.EID == AttachedEntity)
                            {
                                SetPosition(Position + er.Delta, false);
                            }
                        }
                        break;                
#endregion

                    case ChatMessageServer.ID:
                        if (ServerParser.ParseServer(this.Player, (ChatMessageServer)packet))
                            return;
                        break;
                
                //Inventory
                    case WindowItems.ID:
                        var wi = (WindowItems)packet;
                        for (int n = 0; n < wi.Items.Length; n++)
                        {
                            if (wi.Items[n] == null)
                                continue;
                            if (wi.Items[n].Count > 64)
                            {
                                wi.Items[n] = null;
                                packet.SetPacketBuffer(null);
                            }
                        }
                        break;

                    case SetSlot.ID:
                        //Debug.WriteLine(packet);
                        SetSlot ss = (SetSlot)packet;

                        if (0 <= ss.Slot && ss.Slot < Inventory.Length)
                            Inventory[ss.Slot] = ss.Item;
                        break;

                //Tab player list items: Block Player, managed in PlayerList thread
                    case PlayerListItem.ID:
                        return;

                    case HeldItemServer.ID:
                //Active item
                        var hc = (HeldItemServer)packet;
                        if (hc.SlotID >= 0 && hc.SlotID <= 8)
                            ActiveInventoryIndex = hc.SlotID;
                        else
                            Log.Write(
                                new InvalidOperationException("Invalid holding slot id: " + hc.SlotID),
                                this.Player
                            );
                        break;

                //Keep a record of what window is open
                    case WindowOpen.ID:
                        WorldRegion r = LastClickRegion ?? CurrentRegion;
                        var wo = (WindowOpen)packet;
                        if (OpenWindows.ContainsKey(wo.WindowID))
                            OpenWindows.Remove(wo.WindowID);
                        OpenWindows.Add(wo.WindowID, new OpenWindowRegion(wo, r));

                        if (r == null || (Player.Admin() == false) && (Mode == GameMode.Creative))
                        {
                            //Leave unmodified
                        }
                        else
                        {
                            if (r.Type == Protected.Type &&
                                r.IsResident(Player) == false &&
                                wo.InventoryType != "CraftingTable" &&
                                wo.InventoryType != "Enchant" &&
                                wo.WindowTitle != "container.enderchest")
                            {
                                var cj = new ChatJson();
                                cj.Text = "Locked: " + r.Name;
                                wo.WindowTitle = cj.Serialize();
                                wo.SetPacketBuffer(null);
                            }
                        }
                        break;
                    
                //Turn off pvp when you die
                    case UpdateHealth.ID:
                        UpdateHealth uh = (UpdateHealth)packet;
                        if (Player.PvP && uh.Health <= 0)
                        {
                            Player.PvP = false;
                            Player.TellSystem(Chat.Purple, "PvP off");
                        }
                        break;
                
                
                    case WindowCloseServer.ID:
                        WindowClose((WindowCloseServer)packet);
                        break;

                //Disconnect while running the game
                //For disconnect at login see the handshake part
                    case Disconnect.ID:
                        Disconnect d = (Disconnect)packet;
                        if (d.Reason.Text == "Flying is not enabled on this server")
                        {
                            #if !DEBUG
                            Player.BanByServer(DateTime.Now.AddMinutes(2), d.Reason.Text);
                            #else
                            Chatting.Parser.Say(Chat.Yellow + Player.Name + Chat.Blue, " was kicked for flying");
                            #endif
                            return;
                        }
                        if (d.Reason.Text == "Internal server error")
                        {
                            Log.WritePlayer(
                                this.Player,
                                "Backend: Internal error - Restarting connection"
                            );
                            Player.SetWorld(World.Main);
                            return;
                        }
                        Player.SetWorld(World.Construct);
                        return;
                }
                //////////////Sending packet
                Player.SendToClient(packet);
                //////////////
                
#if !DEBUG
            } catch (Exception e)
            {
                thread.State = "ServerGamingException: " + e.Message;
                    
                Log.Write(e, this.Player);
                Player.Queue.Queue(packet);
#endif
            }
            finally
            {
            }
        }