public CommandResult Steal(User user1, User user2, long currency)
 {
     if (user2.LevelID != 0)
     {
         if (currency > 0)
         {
             if (user2.Balance >= currency)
             {
                 user2.Balance -= currency;
                 user1.Balance += currency;
                 return new CommandResult(true, String.Format("{0} has stolen §6{1} {2} §{3}from {4}.", user1.Name, currency, MinecraftHandler.Config.CurrencySymbol, MinecraftHandler.Config.ResponseColorChar, user2.Name));
             }
             else
             {
                 return new CommandResult(true, String.Format("{0} has not enough money", user1.Name));
             }
         }
         else
         {
             return new CommandResult(true, String.Format("The amount must be over 0"));
         }
     }
     else
     {
         return new CommandResult(true, String.Format("{0} has no giro account",user2.Name));
     }
 }
 public WebActionCommand(int id, WebActionType type, String message,User user, ZmaSQLConnection sql)
 {
     this.Id = id;
     this.Type = type;
     this.Message = message;
     this.User = user;
 }
 public void Add(User user)
 {
     if (!this.IsInlist(user.Name))
     {
         this.Items.Add(user);
     }
 }
 private CommandResult GiveMoney(User u, long money)
 {
     if (u.LevelID != 0)
     {
         u.Balance += money;
         return new CommandResult(true, String.Format("{0} has given {1} §6{2} {3}.", TriggerPlayer,u.Name, money, MinecraftHandler.Config.CurrencySymbol));
     }
     return new CommandResult(true, String.Format("{0} execute by {1}", Name, TriggerPlayer));
 }
Exemple #5
0
 private void btAdd_Click(object sender, EventArgs e)
 {
     if (_userCollection.GetUserByName(comboSelectedPlayer.Text).Generated)
     {
         User user = new User(comboSelectedPlayer.Text);
         try
         {
             user.LevelID = (comboBoxLevel.SelectedValue as Group).Id;
         }
         catch { }
         _userCollection.Add(user);
     }
     else
     {
         MessageBox.Show("The user is allready in the list", "User allready in list!",
             MessageBoxButtons.OK,MessageBoxIcon.Information);
     }
 }
        public override CommandResult Execute(String arg1, String arg2, String arg3, String arg4)
        {
            ZoneCollectionSingletone coll = ZoneCollectionSingletone.GetInstance();

            Zone zone = EasyGuess.GetMatchedZone(coll,arg1);
            if (zone != null)
            {
                String match = EasyGuess.GetMatchedString(MinecraftHandler.Player, arg2);
                User user = UserCollectionSingletone.GetInstance().GetUserByName(match);
                if (user.Generated)
                {
                    user = new User(TriggerPlayer, false);
                    user.LevelID = 0;
                    UserCollectionSingletone.GetInstance().Add(user);
                    UserCollectionSingletone.GetInstance().Save();
                }
                if (TriggerPlayer == zone.Owner || ClientUser.LevelID > zone.LevelID)
                {
                    if (!MinecraftHandler.IsStringInList(user.Name, zone.Whitelist))
                    {
                        zone.Whitelist.Add(user.Name);
                        return new CommandResult(true, String.Format("{0} has added user {1} to Zone {2}", TriggerPlayer, user.Name, zone.Name));
                    }
                    else
                    {
                        return new CommandResult(true, String.Format("User {0} is allready in Zone {1}", user.Name, zone.Name));
                    }
                }
                else
                {
                    return new CommandResult(true, String.Format("You cannot whitelist, you need to be the owner or have an higher id"));
                }
            }
            else
            {
                return new CommandResult(true, String.Format("Zone not found: {0}",arg1));
            }
        }
        void MinecraftHandler_PlayerJoined(object sender, string player)
        {
            User user = UserCollectionSingletone.GetInstance().GetUserByName(player);
            if (user.Generated)
            {
                user = new User(player, false);
                user.LevelID = 0;
                UserCollectionSingletone.GetInstance().Add(user);
                UserCollectionSingletone.GetInstance().Save();
            }

            List<Channel> channels = Channels.FindAll(x => x.User.IsInlist(player));
            if (channels.Count <= 0)
            {
                defaultChannel.User.Add(user);
                if (Tunnel.MinecraftHandler.Config.ChannelModeChat)
                {
                    SendExecuteResponse(player, "You joined the default channel");
                }
            }
        }
        public CommandResult ActionCommand(String message, User user, String remoteName)
        {
            bool tunnelMessage = true;
            string text = message;
            MinecraftHandler mc = Tunnel.MinecraftHandler;
            String name = user.Name;
            List<String> players = mc.Player;
            UserCollectionSingletone userCollection = UserCollectionSingletone.GetInstance();
            CommandResult cmdResult = new CommandResult(false, "");
            if (text.Length > 0)
            {
                if (text[0] == mc.Config.CommandChar[0])
                {
                    string commandRegexPattern = String.Format(@"{0}(?<cmd>[a-zA-Z]+) ?(?<arg1>.+)?", mc.Config.CommandChar);
                    Regex commandRegex = new Regex(commandRegexPattern);
                    Match match = commandRegex.Match(text);

                    string regCommand = "";
                    string regArg1 = "";

                    if (match.Success)
                    {
                        try
                        {
                            tunnelMessage = false;
                            regCommand = match.Groups["cmd"].Value;
                            regArg1 = match.Groups["arg1"].Value;

                            if (mc != null && mc.Started)
                            {
                                cmdResult = mc.CommandHandlerExternal(name, regCommand, regArg1, null, this);
                                if (cmdResult != null && cmdResult.HasResult)
                                {
                                    if (mc.Config.CommandExecutedResponse)
                                    {
                                        if (user.Level.OwnExecuteResponse)
                                        {
                                            SendExecuteResponse(user.Name, cmdResult.Message);
                                        }
                                        foreach (User u in userCollection.Items)
                                        {
                                            if (user != u)
                                            {
                                                if (u.Level.OtherExecuteResponse)
                                                {
                                                    if (mc.IsStringInList(u.Name, players))
                                                    {
                                                        SendExecuteResponse(u.Name, cmdResult.Message);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    SendExecuteResponse(name, String.Format("Unknown command {0}", text));
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            SendExecuteResponse(name, String.Format("Exception while executing ask Zicore :)", text));
                            Log.AppendText(ex.Message, Log.ExceptionsLog);
                        }
                    }
                }

            }

            if (tunnelMessage && text[0] != '/')
            {
                tunnelMessage = false;
                char lineColor = 'f';
                if (FirstLine)
                {
                    lineColor = mc.Config.LineFirstColorKey;
                }
                else
                {
                    lineColor = mc.Config.LineSecondColorKey;
                }

                FirstLine = !FirstLine;

                SendServerMessage(String.Format("§f<§{0}{1}§{2} [§6{3}§f]> §{4}{5}", user.Level.GroupColor, name, 'F', remoteName, lineColor, text));

                //ZmaSQLConnection sql = new ZmaSQLConnection();
                //sql.AddChatMessage(name, text, mc);
            }
            return cmdResult;
        }
        public override CommandResult Execute(String chan,String pw, String arg3, String arg4)
        {
            if (!String.IsNullOrEmpty(chan))
            {
                if (chan.Length <= 12 && chan.Length >= 3 || chan.Length == 1 && chan[0] == '*')
                {
                    ServerSocket server = (ServerSocket)Server;
                    if (ClientUser.Generated)
                    {
                        ClientUser = new User(TriggerPlayer, false);
                        UserCollectionSingletone.GetInstance().Add(ClientUser);
                        UserCollectionSingletone.GetInstance().Save();
                    }

                    Channel channel = server.Channels.Find(chan); // check if a channel exists or creates a new
                    if (channel == null)
                    {
                        if (String.IsNullOrEmpty(pw)) // if has a password creates a channel with password :)
                        {
                            channel = new Channel(chan);
                            // create new without password
                        }
                        else
                        {
                            channel = new Channel(chan, pw);
                            // create with password
                        }
                        server.Channels.AddChannel(channel);
                        // add user to channel
                    }

                    if (channel.User.IsInlist(ClientUser))
                    {
                        return new CommandResult(false, String.Format("You're already in this channel", TriggerPlayer, channel.Name), true);
                    }

                    if (channel.RequiresPassword)
                    {
                        if (String.IsNullOrEmpty(pw))
                        {
                            return new CommandResult(true, String.Format("{0} requires a password", channel.Name),true);
                            // no pw as argument so we are out here :)
                        }
                        else
                        {
                            // we have a password lets check it
                            if (channel.Password == pw)
                            {
                                channel.User.Add(ClientUser);
                                return new CommandResult(true, String.Format("{0} joined channel {1}", TriggerPlayer, channel.Name));
                            }
                            else
                            {
                                // password is wrong :(
                                return new CommandResult(true, String.Format("Password for channel {0} is wrong", channel.Name), true);
                            }
                        }
                    }
                    else
                    {
                        // no pw so we are ok
                        //ClientUser.Channels.AddChannel(channel);

                        if (!channel.User.IsInlist(ClientUser))
                        {
                            channel.User.Add(ClientUser);
                            return new CommandResult(true, String.Format("{0} joined channel {1}", TriggerPlayer, channel.Name));
                        }
                        else
                        {
                            return new CommandResult(true, String.Format("You're already in this channel", TriggerPlayer, channel.Name), true);
                            //return new CommandResult(true, null);
                        }
                    }

                }
                else
                {
                    // channel name length must be between 3 and 12
                    return new CommandResult(true, String.Format("Channel name length must be between 3 and 12"), true);
                }
            }
            else
            {
                return new CommandResult(true, String.Format("Unknown Argument"), true);
            }
        }
 public void Remove(User user)
 {
     this.Items.Remove(user);
 }
 public bool Login(String userName, String password, out User user)
 {
     foreach (User  u in this.Items)
     {
         if (u.HasWebAccess && u.WebUsername == userName && u.PasswordHash == password)
         {
             user = u;
             return true;
         }
     }
     user = null;
     return false;
 }
        public void ExecuteKits(User user)
        {
            StringBuilder builder = new StringBuilder();

            List<Kit> kitlist = KitReader.GetKitlist(Config.ConfigFolder + KitReader.File);

            foreach (Kit kit in kitlist)
            {

                 builder.AppendFormat("<{0}> ", kit.Name);

            }

            ExecuteCommand("say", builder.ToString());
        }
        public void ExecuteCommands(User user)
        {
            try
            {
                Group g = user.Level;

                StringBuilder builder = new StringBuilder();

                foreach (String str in user.Level.Commands)
                {
                    builder.AppendFormat("<{0}> ",str);
                }

                ExecuteCommand("say", builder.ToString());
            }
            catch
            {

            }
        }
        public CommandResult CommandHandlerExternal(String userName, String command, String args,ClientSocket client,ServerSocket server)
        {
            if (String.IsNullOrEmpty(userName) || String.IsNullOrEmpty(command))
            {
                return null;
            }

            string username = userName;

            try
            {
                CommandManager helper = CommandManager.GetInstance(this);

                String commandMatch = EasyGuess.GetMatchedCommand(helper, command);
                if (String.IsNullOrEmpty(commandMatch))
                {
                    return null;
                }

                Command c = helper.Items[commandMatch];
                if (c != null)
                {
                    UserCollectionSingletone userCollection = UserCollectionSingletone.GetInstance();
                    User user = userCollection.GetUserByName(userName);
                    if (user == null)
                    {
                        user = new User(userName);
                    }

                    if (user != null && user.Level.IsCommandInList(commandMatch))
                    {
                        string arg1 = "", arg2 = "", arg3 = "";
                        GetArgs(args, out arg1, out arg2, out arg3);
                        c.ClientUser = user;
                        c.RegArg = args;
                        c.Client = client;
                        c.Server = server;
                        c.TriggerPlayer = userName;
                        CommandResult result;

                        if(arg1.Length>0&&arg1[0]=='?')
                            result = c.ExecuteHelp();
                        else
                            result = c.Execute(arg1, arg2, arg3, userName);

                        return result;
                    }
                }
            }
            catch
            {}
            return new CommandResult();
        }
 public UpdateWebUser(User user)
 {
     InitializeComponent();
     this.user = user;
 }
        private void ExternalThread()
        {
            bool flag = false;
            byte[] buffer = new byte[0x100];
            while (this.internalSock.Connected && this.externalSock.Connected)
            {
                try
                {
                    if (!flag)
                    {
                        buffer = new byte[1];
                        if (this.externalSock.Receive(buffer) > 0)
                        {
                            string str;
                            byte fByte = buffer[0];
                            this.extBuffer = new byte[] { fByte };
                            //int bytes = -2;
                            // Client to server
                            PacketBytes firstByte = (PacketBytes)fByte;
                            PacketSizes bytes = PacketSizes.Minus_2;

                            bytes = MinecraftEnums.GetPacketSize(firstByte);

                            //if (bytes == PacketSizes.Minus_2)
                            //{
                            //    databaseWorker.AddAction(new DatabaseAction(() =>
                            //    {
                            //        Log.Append(this, "Unkown Packet logged " + ((int)firstByte).ToString(), Log.PacketsLog);
                            //    }));
                            //    bytes = PacketSizes.Minus_1;
                            //}

                            bool forwardPacket = true;
                            if (bytes != PacketSizes.String)
                            {
                                if ((int)bytes > 0)
                                {
                                    buffer = this.ReceiveBytes(this.externalSock, (int)bytes);
                                    switch (firstByte)
                                    {
                                        case PacketBytes._0x0E_BlockDig_0x0E:
                                            {
                                                //DB.AddAction(new DatabaseAction(() =>
                                                //{
                                                //    if (ChatMessageReceived != null)
                                                //    {
                                                //        ChatMessageReceived(this, this, "Digged Block");
                                                //    }
                                                //}));

                                                byte Status = ByteArythmetic.GetByte(this.extBuffer, 1);
                                                int X = ByteArythmetic.GetInt32(extBuffer, 2);
                                                byte Y = ByteArythmetic.GetByte(extBuffer, 6);
                                                int Z = ByteArythmetic.GetInt32(extBuffer, 7);
                                                byte Direction = ByteArythmetic.GetByte(extBuffer, 11);
                                                forwardPacket = true;
                                                try
                                                {
                                                    XPosition blockPos = new XPosition((double)X, (double)Y, (double)Z, 0, 0, 0, false);

                                                    ZoneCollectionSingletone zones = ZoneCollectionSingletone.GetInstance();
                                                    Zone zone = zones.GetZoneByPosition(blockPos);
                                                    UserCollectionSingletone userCollection = UserCollectionSingletone.GetInstance();
                                                    User user = userCollection.GetUserByName(name);
                                                    if (user == null)
                                                    {
                                                        user = new User();
                                                    }

                                                    MinecraftHandler mc = serverSocket.Tunnel.MinecraftHandler;

                                                    //flag2 = user.Level.AllowDestroy;

                                                    if (zone != null)
                                                    {
                                                        if (zone.FixToGroup)
                                                        {
                                                            forwardPacket = zone.Owner == user.Name ||
                                                                user.LevelID == zone.LevelID && zone.AllowDestroy ||
                                                                mc.IsStringInList(user.Name, zone.Whitelist) ;
                                                        }
                                                        else
                                                        {
                                                            forwardPacket = zone.Owner == user.Name  ||
                                                                user.LevelID > zone.LevelID && zone.AllowDestroy ||
                                                                mc.IsStringInList(user.Name, zone.Whitelist) ;
                                                        }
                                                    }

                                                    forwardPacket = forwardPacket && user.Level.AllowDestroy;
                                                }
                                                catch
                                                {

                                                }

                                                //if (!flag2)
                                                //{
                                                //    int stat = 0;
                                                //    if (Status == 1 || Status == 3)
                                                //    {

                                                //    }
                                                //    else
                                                //    {
                                                //        //stat = 2;
                                                //        //PacketGenerator p = new PacketGenerator();
                                                //        //p.Add((byte)firstByte);
                                                //        //p.Add((byte)stat);
                                                //        //p.Add(X);
                                                //        //p.Add(Y);
                                                //        //p.Add(Z);
                                                //        //p.Add(Direction);
                                                //        //byte[] instantDetroy = p.ToByteArray();
                                                //        //extBuffer = instantDetroy;
                                                //        //flag2 = true;
                                                //    }
                                                //}
                                                //else
                                                //{
                                                //    PacketGenerator p = new PacketGenerator();
                                                //    p.Add((byte)firstByte);
                                                //    p.Add((byte)0x00);
                                                //    p.Add(X);
                                                //    p.Add(Y);
                                                //    p.Add(Z);
                                                //    p.Add(Direction);
                                                //    byte[] instantDetroy = p.ToByteArray();
                                                //    extBuffer = instantDetroy;
                                                //    flag2 = true;
                                                //}
                                            }
                                            break;

                                        case PacketBytes._0x0B_PlayerPosition_0x0B://
                                            {
                                                position.X = ByteArythmetic.GetDouble(extBuffer, 1);
                                                position.Y = ByteArythmetic.GetDouble(extBuffer, 9);
                                                position.Stance = ByteArythmetic.GetDouble(extBuffer, 17);
                                                position.Z = ByteArythmetic.GetDouble(extBuffer, 25);
                                                position.Unkown = ByteArythmetic.GetBoolean(extBuffer, 33);

                                                positionCounter++;
                                                if (positionCounter >= positionCounterMax)
                                                {
                                                    positionCounter = 0;

                                                    XPosition pos = new XPosition(position.X, position.Y, position.Z, 0.0, 0.0f, 0.0f, false);
                                                    if (ticker >= tickerMax)
                                                    {
                                                        ZoneCollectionSingletone zones = ZoneCollectionSingletone.GetInstance();
                                                        Zone zone = zones.GetZoneByPosition(Position);

                                                        if (zone != null)
                                                        {
                                                            if (!hasEnteredZone)
                                                            {
                                                                if (!String.IsNullOrEmpty(zone.WelcomeMessage))
                                                                {
                                                                    serverSocket.SendMessageToClient(name, zone.WelcomeMessage);
                                                                }
                                                            }
                                                            hasEnteredZone = true;
                                                        }
                                                        else
                                                        {
                                                            hasEnteredZone = false;
                                                        }
                                                        ticker = 0;
                                                    }
                                                    ticker++;
                                                    MinecraftHandler mc = serverSocket.Tunnel.MinecraftHandler;

                                                    foreach (IPlugin plugin in mc.Plugins)
                                                    {
                                                        try
                                                        {
                                                            if (plugin.Enabled)
                                                            {
                                                                plugin.OnPlayerMove(serverSocket, this, pos);
                                                            }
                                                        }
                                                        catch (Exception ex)
                                                        {
                                                            Log.AppendText("Error Executing Plugin OnPlayerMove() " + ex.Message, Log.PluginLog);
                                                        }
                                                    }

                                                }

                                                // 31 Bytes
                                            }
                                            break;

                                        case PacketBytes._0x0C_PlayerLook_0x0C:
                                            {
                                                position.Rotation = ByteArythmetic.GetFloat(extBuffer, 1);
                                                position.Pitch = ByteArythmetic.GetFloat(extBuffer, 5);
                                                position.Unkown = ByteArythmetic.GetBoolean(extBuffer, 9);
                                                // 31 Bytes
                                            }
                                            break;

                                        case PacketBytes._0x0D_PlayerMoveAndLook_0x0D:
                                            {
                                                position.X = Util.AtoD(buffer, 0);
                                                position.Stance = Util.AtoD(buffer, 8);
                                                position.Y = Util.AtoD(buffer, 16);
                                                position.Z = Util.AtoD(buffer, 24);
                                                position.Rotation = Util.AtoF(buffer, 32);
                                                position.Pitch = Util.AtoF(buffer, 36);
                                                //41
                                            }
                                            break;
                                    }
                                    buffer.CopyTo(this.extBuffer, 1);
                                }
                                else
                                {

                                }
                            }
                            else
                            {
                                switch (firstByte)
                                {
                                    case PacketBytes._0x01_Login_0x01:
                                        this.ReceiveBytes(this.externalSock, 4);
                                        this.name = this.ReceiveString(this.externalSock);

                                        if (!nameSet)
                                        {
                                            //serverSocket.Tunnel.MinecraftHandler.AddPlayer(name);
                                            nameSet = true;
                                            //serverSocket.Tunnel.MinecraftHandler.ExecuteMOTD(serverSocket.Tunnel.MinecraftHandler.Config.Modt, name);
                                        }
                                        Match m = new Regex("<§[0-9a-f](?<username>[^>]+)§[0-9a-f]>").Match(name);
                                        if (m.Success)
                                        {
                                            name = m.Groups["username"].Value;
                                        }

                                        if (!ByteArythmetic.ContainsInvalidChars(this.name, true))
                                        {
                                            //this.ReceiveString(this.externalSock); // Update 1.5 removed string
                                            //break;
                                        }
                                        else
                                        {
                                            this.Disconnect("Invalid Name");
                                            return;
                                        }

                                        //ReceiveBytes(this.externalSock, 8);
                                        //ReceiveBytes(this.externalSock, 1);
                                        break;

                                    case PacketBytes._0x02_Handshake_0x02:
                                        str = this.ReceiveString(this.externalSock);
                                        if (!(this.name != "") || !(str.ToLower() != this.name.ToLower()))
                                        {
                                            this.name = str;
                                        }
                                        else
                                        {
                                            this.Disconnect("Invalid Name");
                                            return;
                                        }
                                        break;

                                    case PacketBytes._0x03_Chat_0x03:
                                        {
                                            string chatMessage = this.ReceiveString(this.externalSock);
                                            MinecraftHandler mc = this.serverSocket.Tunnel.MinecraftHandler;
                                            bool unkownCommand = false;
                                            List<String> players = mc.Player;
                                            UserCollectionSingletone userCollection = UserCollectionSingletone.GetInstance();
                                            User user = userCollection.GetUserByName(name);

                                            if (chatMessage.Length > 0)
                                            {
                                                if (chatMessage[0] == mc.Config.CommandChar[0])
                                                {
                                                    string commandRegexPattern = String.Format(@"{0}(?<cmd>[a-zA-Z]+) ?(?<arg1>.+)?", mc.Config.CommandChar);
                                                    Regex commandRegex = new Regex(commandRegexPattern);
                                                    Match match = commandRegex.Match(chatMessage);

                                                    string commandName = "";
                                                    string arguments = "";

                                                    if (match.Success)
                                                    {
                                                        try
                                                        {
                                                            forwardPacket = false;
                                                            commandName = match.Groups["cmd"].Value;
                                                            arguments = match.Groups["arg1"].Value;

                                                            if (mc != null && mc.Started)
                                                            {
                                                                CommandResult cmdResult = mc.CommandHandlerExternal(name, commandName, arguments, this, serverSocket);
                                                                if (cmdResult != null && cmdResult.HasResult)
                                                                {
                                                                    if (mc.Config.CommandExecutedResponse)
                                                                    {

                                                                        if (user.Level.OwnExecuteResponse)
                                                                        {
                                                                            serverSocket.SendExecuteResponse(user.Name, cmdResult.Message);
                                                                        }

                                                                        if (!cmdResult.IsPrivate)
                                                                        {
                                                                            foreach (User u in userCollection.Items)
                                                                            {
                                                                                if (user != u)
                                                                                {
                                                                                    if (u.Level.OtherExecuteResponse)
                                                                                    {
                                                                                        if (mc.IsStringInList(u.Name, players))
                                                                                        {
                                                                                            serverSocket.SendExecuteResponse(u.Name, cmdResult.Message);
                                                                                        }
                                                                                    }
                                                                                }
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                                else
                                                                {
                                                                    unkownCommand = true;
                                                                    if (mc.Config.SendUnkownCommandResponse)
                                                                    {
                                                                        serverSocket.SendExecuteResponse(name, String.Format("Unknown command {0}", chatMessage));
                                                                    }
                                                                }
                                                            }
                                                        }
                                                        catch (Exception ex)
                                                        {
                                                            serverSocket.SendExecuteResponse(name, String.Format("Exception while executing", chatMessage));
                                                            Log.AppendText(ex.Message, Log.ExceptionsLog);
                                                        }
                                                    }
                                                }
                                            }
                                            bool tunnelMessage = true;
                                            foreach (IPlugin plugin in mc.Plugins)
                                            {
                                                try
                                                {
                                                    if (plugin.Enabled)
                                                    {
                                                        plugin.OnChatMessage(serverSocket, this, chatMessage, ref tunnelMessage);
                                                    }
                                                }
                                                catch
                                                {
                                                    Log.AppendText("Error Executing Plugin OnChatMessage()", Log.PluginLog);
                                                }
                                            }

                                            if (ChatMessageReceived != null)
                                            {
                                                ChatMessageReceived(this, this, chatMessage);
                                            }

                                            if (tunnelMessage)
                                            {
                                                if (!unkownCommand)
                                                {
                                                    if (forwardPacket && chatMessage[0] != '/')
                                                    {
                                                        forwardPacket = false;
                                                        char lineColor = 'f';
                                                        if (serverSocket.FirstLine)
                                                        {
                                                            lineColor = mc.Config.LineFirstColorKey;
                                                        }
                                                        else
                                                        {
                                                            lineColor = mc.Config.LineSecondColorKey;
                                                        }

                                                        serverSocket.FirstLine = !serverSocket.FirstLine;
                                                        if (user.Level.AllowChat && user.AllowChat)
                                                        {
                                                            if (mc.Config.ChannelModeChat)
                                                            {
                                                                serverSocket.SendChannelMessage(String.Format("§f<§{0}{1}§{2}> §{3}{4}", user.Level.GroupColor, name, 'F', lineColor, chatMessage),this);
                                                            }
                                                            else
                                                            {
                                                                serverSocket.SendServerMessage(String.Format("§f<§{0}{1}§{2}> §{3}{4}", user.Level.GroupColor, name, 'F', lineColor, chatMessage));
                                                            }
                                                        }
                                                        else
                                                        {
                                                            serverSocket.SendExecuteResponse(name, "You have no permissions to chat");
                                                        }

                                                        //ZmaSQLConnection sql = new ZmaSQLConnection();
                                                        //sql.AddChatMessage(name, text, mc);
                                                    }
                                                }
                                                else
                                                {
                                                    if (mc.Config.ForwardUnkownCommands)
                                                    {
                                                        forwardPacket = true;
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                forwardPacket = false;
                                            }
                                        }
                                        break;
                                    //case PacketBytes._0x22_EntityTeleport_0x22:
                                    //    int uid = ByteArythmetic.GetInt32(buffer, 0);
                                    //    //int x = ByteArythmetic.GetInt32(buffer, 4);
                                    //    //int y = ByteArythmetic.GetInt32(buffer, 8);
                                    //    //int z = ByteArythmetic.GetInt32(buffer, 12);

                                    //    //byte rotation = ByteArythmetic.GetByte(buffer, 13);
                                    //    //byte pitch = ByteArythmetic.GetByte(buffer, 14);
                                    //    break;

                                        // 2010-01-13 Minecraft 1.2

                                    case PacketBytes._0x18_MobSpawn_0x18:
                                        {
                                            ReceiveBytes(externalSock, 19);
                                            HandleInsanity(externalSock);
                                        }
                                        break;

                                    case PacketBytes._0x19_NewPacket_0x19:
                                        {
                                            ReceiveBytes(externalSock, 4);
                                            ReceiveString(externalSock);
                                            ReceiveBytes(externalSock, 16);
                                        }
                                        break;

                                    case PacketBytes._0x28_NewPacket_0x28:
                                        {
                                            ReceiveBytes(externalSock, 4);
                                            HandleInsanity(externalSock);
                                        }
                                        break;

                                    case PacketBytes._0x3C_Explosion_0x3C:
                                        ReceiveBytes(externalSock, 28); //8 + 8 + 8 + 4
                                        ReceiveBytes(externalSock, Util.AtoI(ReceiveBytes(externalSock, 4), 0) * 3);
                                        break;

                                    case PacketBytes._0x64_OpenWindow_0x64:
                                        {
                                            this.ReceiveBytes(this.ExternalSock, 2);
                                            this.ReceiveStringUtf8(this.externalSock);
                                            this.ReceiveBytes(this.ExternalSock, 1);
                                        }
                                        break;

                                    case PacketBytes._0x66_WindowClick_0x66:
                                        {
                                            ReceiveBytes(externalSock, 7); // Update 1.5 + 1 bool
                                            if (Util.AtoN(ReceiveBytes(externalSock, 2), 0) >= 0) ReceiveBytes(externalSock, 3);
                                        }
                                        break;

                                    case PacketBytes._0x67_SetSlot_0x67:
                                        {
                                            ReceiveBytes(externalSock, 3);
                                            if (Util.AtoN(ReceiveBytes(externalSock, 2), 0) >= 0) ReceiveBytes(externalSock, 3);
                                        }
                                        break;

                                    case PacketBytes._0x68_WindowItems_0x68:
                                             short xmax = Util.AtoN(ReceiveBytes(externalSock, 3), 1);
                                            for (short cx = 0; cx < xmax; cx++)
                                            {
                                                if (Util.AtoN(ReceiveBytes(externalSock, 2), 0) >= 0)
                                                {
                                                    ReceiveBytes(externalSock, 3);
                                                }
                                            }
                                            break;

                                    case PacketBytes._0x82_UpdateSign_0x82:
                                        {
                                            ReceiveBytes(externalSock, 10);
                                            ReceiveString(externalSock);
                                            ReceiveString(externalSock);
                                            ReceiveString(externalSock);
                                            ReceiveString(externalSock);
                                        }
                                        break;

                                    case PacketBytes._0xFF_Disconnect_0xFF:
                                        this.Disconnect(this.ReceiveString(this.externalSock));
                                        break;

                                    case PacketBytes._0x0F_PlaceBlock_0x0F:
                                        {
                                            ReceiveBytes(externalSock, 10);
                                            if (Util.AtoN(ReceiveBytes(externalSock, 2), 0) >= 0) ReceiveBytes(externalSock, 3);

                                            BlockCollection badBlocks = BlockCollection.Load(Config.ConfigFolder + BlockCollection.BadBlocksFile);
                                            ItemDictonary items = ItemDictonary.GetInstance();

                                            int blockX = Util.AtoI(extBuffer, 1);
                                            byte blockY = ByteArythmetic.GetByte(extBuffer, 5);
                                            int blockZ = ByteArythmetic.GetInt32(extBuffer, 6);
                                            byte blockDirection = ByteArythmetic.GetByte(extBuffer, 10);
                                            short num4 = ByteArythmetic.GetInt16(extBuffer, 11);

                                            XPosition blockPos = new XPosition(blockX , blockY, blockZ, 0, 0, 0, false);

                                            UserCollectionSingletone userCollection = UserCollectionSingletone.GetInstance();
                                            User user = userCollection.GetUserByName(name);
                                            if (user == null)
                                            {
                                                user = new User();
                                            }
                                            BlockItem block = badBlocks.GetBlockById(num4);
                                            ZoneCollectionSingletone zones = ZoneCollectionSingletone.GetInstance();

                                            Zone zone = zones.GetZoneByPosition(blockPos);
                                            MinecraftHandler mc = serverSocket.Tunnel.MinecraftHandler;

                                            forwardPacket = (user.Level.BlockLevel == 0 && num4 != -1) && user.Level.AllowBuild;
                                            if (block != null)
                                            {
                                                forwardPacket = (user.Level.BlockLevel >= block.BlockLevel) && user.Level.AllowBuild;
                                                if (zone != null)
                                                {
                                                    if (zone.FixToGroup)
                                                    {
                                                        forwardPacket = user.LevelID == zone.LevelID && zone.BlockLevel >= block.BlockLevel && user.Level.BlockLevel >= block.BlockLevel && zone.AllowBuild ||
                                                            mc.IsStringInList(user.Name, zone.Whitelist) && user.Level.BlockLevel >= block.BlockLevel  ||
                                                                zone.Owner == user.Name && user.Level.BlockLevel >= block.BlockLevel;
                                                    }
                                                    else
                                                    {
                                                        forwardPacket = user.LevelID > zone.LevelID && zone.BlockLevel >= block.BlockLevel && user.Level.BlockLevel >= block.BlockLevel &&  zone.AllowBuild ||
                                                            mc.IsStringInList(user.Name, zone.Whitelist) && user.Level.BlockLevel >= block.BlockLevel ||
                                                            zone.Owner == user.Name && user.Level.BlockLevel >= block.BlockLevel;
                                                    }
                                                }
                                            }

                                            foreach (IPlugin plugin in serverSocket.Tunnel.MinecraftHandler.Plugins)
                                            {
                                                try
                                                {
                                                    if (plugin.Enabled)
                                                    {
                                                        plugin.OnBlockPlacing(serverSocket, this, num4, ref forwardPacket);
                                                    }
                                                }
                                                catch
                                                {
                                                    Log.AppendText("Error Executing Plugin OnBlockPlacing()", Log.PluginLog);
                                                }
                                            }

                                            if (!forwardPacket)
                                            {
                                                if (num4 != -1)
                                                {
                                                    string str4 = "";
                                                    KeyValuePair<String, String> item;
                                                    if (items.GetKeyValuePairByValue(out item, num4.ToString()))
                                                    {
                                                        str4 = String.Format("{0}", item.ToString());
                                                    }
                                                    else
                                                    {
                                                        str4 = String.Format("Unkown ID: {0}", item.Value);
                                                    }

                                                    if (mc.Config.CommandExecutedResponse)
                                                    {
                                                        //Log.Append(this, this.name + " tried to spawn illegal block " + str4, Log.ExceptionsLog);
                                                        //serverSocket.SendExecuteResponse(this.name, this.name + " tried to spawn illegal block " + str4);
                                                    }
                                                }
                                            }

                                            if (forwardPacket)
                                            {
                                                //ByteArythmetic.NinA(num4, buffer, 0);
                                            }
                                        }
                                        break;

                                    default:
                                        bytes = PacketSizes.Minus_2;
                                        break;
                                }
                            }

                            if (bytes == PacketSizes.Minus_2)
                            {
                                //this.fwl.parent.SendServerMessage("Client \"" + this.name + "\" (IP: " + this.ip + ") sent unknown packet. Disabled firewalling!!!", '4');
                                //this.fwl.parent.AddRTLine(Color.Orange, "Invalid packet ID: " + ((int)num2) + "\r\n", false);
                                this.internalSock.Send(this.extBuffer);
                                flag = true;
                                buffer = new byte[0x100];
                                continue;
                            }
                            if (forwardPacket)
                            {
                                this.internalSock.Send(this.extBuffer);
                            }

                            try
                            {
                                while (this.packetQueueInt.Count > 0)
                                {
                                    byte[] data;
                                    if (this.packetQueueInt.Dequeue(out data))
                                    {
                                        this.internalSock.Send(data);
                                    }
                                }
                                continue;
                            }
                            catch (SocketException)
                            {
                                this.Disconnect();
                                continue;
                            }
                            catch
                            {
                                continue;
                            }

                        }
                        Thread.Sleep(5);
                    }
                    else
                    {
                        int size = this.externalSock.Receive(buffer);
                        if (size > 0)
                        {
                            this.internalSock.Send(buffer, 0, size, SocketFlags.None);
                        }
                        else
                        {
                            Thread.Sleep(5);
                        }
                    }
                }
                catch (SocketException ex)
                {
                    this.Disconnect();
                    Log.AppendText("\nClientSocket 511\n" + ex.Message, Log.ExceptionsLog);
                }
                catch
                {
                }
            }

            this.Disconnect();
        }