Пример #1
0
 bool TryKillSign(int X, int Y, int plr)
 {
     Sign sign = null;
     using (QueryResult reader = Database.QueryReader("SELECT Account, Text FROM Signs WHERE X = @0 AND Y = @1 AND WorldID = @2",
         X, Y, Main.worldID))
     {
         if (reader.Read())
         {
             sign = new Sign { account = reader.Get<string>("Account"), text = reader.Get<string>("Text") };
         }
     }
     if (sign != null)
     {
         if (sign.account != TShock.Players[plr].UserAccountName && sign.account != "")
             return false;
         else
         {
             if (SignKill != null)
             {
                 SignEventArgs signargs = new SignEventArgs(X, Y, sign.text, sign.account);
                 SignKill(signargs);
                 if (signargs.Handled)
                     return false;
             }
         }
     }
     Database.Query("DELETE FROM Signs WHERE X = @0 AND Y = @1 AND WorldID = @2", X, Y, Main.worldID);
     return true;
 }
Пример #2
0
        void GetSign(int X, int Y, int plr)
        {
            Sign sign = null;
            using (QueryResult reader = Database.QueryReader("SELECT Account, Text FROM Signs WHERE X = @0 AND Y = @1 AND WorldID = @2",
                X, Y, Main.worldID))
            {
                if (reader.Read())
                {
                    sign = new Sign { account = reader.Get<string>("Account"), text = reader.Get<string>("Text") };
                }
            }
            TSPlayer player = TShock.Players[plr];

            if (sign != null)
            {
                switch (Action[plr])
                {
                    case SignAction.INFO:
                        player.SendMessage(string.Format("X: {0} Y: {1} Account: {2}", X, Y, sign.account == "" ? "N/A" : sign.account), Color.Yellow);
                        break;
                    case SignAction.PROTECT:
                        if (sign.account != "")
                        {
                            player.SendMessage("This sign is protected.", Color.Red);
                            break;
                        }
                        Database.Query("UPDATE Signs SET Account = @0 WHERE X = @1 AND Y = @2 AND WorldID = @3",
                            player.UserAccountName, X, Y, Main.worldID);
                        player.SendMessage("This sign is now protected.");
                        break;
                    case SignAction.UNPROTECT:
                        if (sign.account == "")
                        {
                            player.SendMessage("This sign is not protected.", Color.Red);
                            break;
                        }
                        if (sign.account != player.UserAccountName && !player.Group.HasPermission("removesignprotection"))
                        {
                            player.SendMessage("This sign is not yours.", Color.Red);
                            break;
                        }
                        Database.Query("UPDATE Signs SET Account = '' WHERE X = @0 AND Y = @1 AND WorldID = @2",
                            X, Y, Main.worldID);
                        player.SendMessage("This sign is now unprotected.");
                        break;
                    default:
                        if (sign.text.Length > 0 && sign.text[sign.text.Length - 1] == '\0')
                        {
                            sign.text = sign.text.Substring(0, sign.text.Length - 1);
                        }
                        byte[] utf8 = Encoding.UTF8.GetBytes(sign.text);
                        byte[] raw = new byte[15 + utf8.Length];
                        Buffer.BlockCopy(BitConverter.GetBytes(utf8.Length + 11), 0, raw, 0, 4);
                        if (SignNum[plr])
                        {
                            raw[5] = 1;
                        }
                        raw[4] = 47;
                        Buffer.BlockCopy(BitConverter.GetBytes(X), 0, raw, 7, 4);
                        Buffer.BlockCopy(BitConverter.GetBytes(Y), 0, raw, 11, 4);
                        Buffer.BlockCopy(utf8, 0, raw, 15, utf8.Length);
                        SignNum[plr] = !SignNum[plr];
                        SignEventArgs signargs = new SignEventArgs(X, Y, sign.text, sign.account);
                        if (SignRead != null)
                            SignRead(signargs);
                        if (!signargs.Handled)
                            player.SendRawData(raw);
                        break;
                }
                Action[plr] = SignAction.NONE;
            }
        }
Пример #3
0
        void ModSign(int X, int Y, int plr, string text)
        {
            Sign sign = null;
            using (QueryResult reader = Database.QueryReader("SELECT Account FROM Signs WHERE X = @0 AND Y = @1 AND WorldID = @2",
                X, Y, Main.worldID))
            {
                if (reader.Read())
                {
                    sign = new Sign { account = reader.Get<string>("Account") };
                }
            }
            TSPlayer player = TShock.Players[plr];

            if (sign != null)
            {
                if (sign.account != player.UserAccountName && sign.account != "" && !player.Group.HasPermission("editallsigns"))
                {
                    player.SendMessage("This sign is protected.", Color.Red);
                }
                else
                {
                    SignEventArgs signargs = new SignEventArgs(X, Y, sign.text, sign.account);
                    if (SignEdit != null)
                        SignEdit(signargs);
                    if (signargs.Handled)
                        player.SendMessage("Another plugin is preventing the sign to be edited.", Color.Red);
                    else
                        Database.Query("UPDATE Signs SET Text = @0 WHERE X = @1 AND Y = @2 AND WorldID = @3", text, X, Y, Main.worldID);
                }
            }
        }
Пример #4
0
 void OnGetData(GetDataEventArgs e)
 {
     if (!e.Handled)
     {
         switch (e.MsgID)
         {
             case PacketTypes.SignNew:
                 {
                     int X = BitConverter.ToInt32(e.Msg.readBuffer, e.Index + 2);
                     int Y = BitConverter.ToInt32(e.Msg.readBuffer, e.Index + 6);
                     string text = Encoding.UTF8.GetString(e.Msg.readBuffer, e.Index + 10, e.Length - 11);
                     ModSign(X, Y, e.Msg.whoAmI, text);
                     e.Handled = true;
                 }
                 break;
             case PacketTypes.SignRead:
                 {
                     int X = BitConverter.ToInt32(e.Msg.readBuffer, e.Index);
                     int Y = BitConverter.ToInt32(e.Msg.readBuffer, e.Index + 4);
                     GetSign(X, Y, e.Msg.whoAmI);
                     e.Handled = true;
                 }
                 break;
             case PacketTypes.Tile:
                 {
                     int X = BitConverter.ToInt32(e.Msg.readBuffer, e.Index + 1);
                     int Y = BitConverter.ToInt32(e.Msg.readBuffer, e.Index + 5);
                     if (X < 0 || Y < 0 || X >= Main.maxTilesX || Y >= Main.maxTilesY)
                     {
                         return;
                     }
                     if (e.Msg.readBuffer[e.Index] == 0 && Main.tile[X, Y].IsSign())
                     {
                         if (SignHit != null)
                         {
                             Sign sign = null;
                             var signPos = Sign.GetSign(X, Y);
                             using (QueryResult reader = Database.QueryReader("SELECT Account, Text FROM Signs WHERE X = @0 AND Y = @1 AND WorldID = @2", signPos.X, signPos.Y, Main.worldID))
                             {
                                 if (reader.Read())
                                     sign = new Sign { account = reader.Get<string>("Account"), text = reader.Get<string>("Text") };
                             }
                             if (sign != null)
                             {
                                 SignEventArgs signargs = new SignEventArgs(X, Y, sign.text, sign.account);
                                 SignHit(signargs);
                             }
                         }
                     }
                     if (e.Msg.readBuffer[e.Index] == 0 && e.Msg.readBuffer[e.Index + 9] == 0)
                     {
                         if (Sign.Nearby(X, Y))
                         {
                             KillSign(X, Y, e.Msg.whoAmI);
                             e.Handled = true;
                         }
                     }
                     else if (e.Msg.readBuffer[e.Index] == 1 && (e.Msg.readBuffer[e.Index + 9] == 55 || e.Msg.readBuffer[e.Index + 9] == 85))
                     {
                         if (TShock.Regions.CanBuild(X, Y, TShock.Players[e.Msg.whoAmI]))
                         {
                             WorldGen.PlaceSign(X, Y, e.Msg.readBuffer[e.Index + 9]);
                             if (Main.tile[X, Y].frameY != 0)
                             {
                                 Y--;
                             }
                             if (Main.tile[X, Y].frameX % 36 != 0)
                             {
                                 X--;
                             }
                             PlaceSign(X, Y, e.Msg.whoAmI);
                             e.Handled = true;
                         }
                     }
                 }
                 break;
         }
     }
 }