Example #1
0
        public bool InsertPlayerData(TSPlayer player, int acctid)
        {
            PlayerData playerData = player.PlayerData;

            if (!GetPlayerData(player, acctid).exists)
            {
                try
                {
                    database.Query("INSERT INTO Inventory (Account, MaxHealth, MaxMana, Inventory) VALUES (@0, @1, @2, @3);", acctid, playerData.maxHealth, playerData.maxMana, NetItem.ToString(playerData.inventory));
                    return true;
                }
                catch (Exception ex)
                {
                    Log.Error(ex.ToString());
                }
            }
            else
            {
                try
                {
                    database.Query("UPDATE Inventory SET MaxHealth = @0, MaxMana = @1, Inventory = @2 WHERE Account = @3;", playerData.maxHealth, playerData.maxMana, NetItem.ToString(playerData.inventory), acctid);
                    return true;
                }
                catch (Exception ex)
                {
                    Log.Error(ex.ToString());
                }
            }
            return false;
        }
Example #2
0
        public bool InsertPlayerData(TSPlayer player)
        {
            PlayerData playerData = player.PlayerData;

            if (!player.IsLoggedIn)
                return false;

            if (!GetPlayerData(player, player.UserID).exists)
            {
                try
                {
                    database.Query("INSERT INTO Inventory (Account, MaxHealth, Inventory) VALUES (@0, @1, @2);", player.UserID,
                                   playerData.maxHealth, NetItem.ToString(playerData.inventory));
                    return true;
                }
                catch (Exception ex)
                {
                    Log.Error(ex.ToString());
                }
            }
            else
            {
                try
                {
                    database.Query("UPDATE Inventory SET MaxHealth = @0, Inventory = @1 WHERE Account = @2;", playerData.maxHealth,
                                   NetItem.ToString(playerData.inventory), player.UserID);
                    return true;
                }
                catch (Exception ex)
                {
                    Log.Error(ex.ToString());
                }
            }
            return false;
        }
Example #3
0
        public PlayerData GetPlayerData(TSPlayer player, int acctid)
        {
            PlayerData playerData = new PlayerData(player);

            try
            {
                using (var reader = database.QueryReader("SELECT * FROM tsCharacter WHERE [email protected]", acctid))
                {
                    if (reader.Read())
                    {
                        playerData.exists = true;
                        playerData.health = reader.Get<int>("Health");
                        playerData.maxHealth = reader.Get<int>("MaxHealth");
                        playerData.mana = reader.Get<int>("Mana");
                        playerData.maxMana = reader.Get<int>("MaxMana");
                        playerData.inventory = NetItem.Parse(reader.Get<string>("Inventory"));
                        playerData.spawnX = reader.Get<int>("spawnX");
                        playerData.spawnY = reader.Get<int>("spawnY");
                        return playerData;
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex.ToString());
            }

            return playerData;
        }
Example #4
0
        public static void OnReloadEvent(TSPlayer ply)
        {
            if(ReloadEvent == null)
                return;

            ReloadEvent(new ReloadEventArgs(ply));
        }
Example #5
0
        public static void OnRegionEntered(TSPlayer player, Region region)
        {
            if (RegionEntered == null)
            {
                return;
            }

            RegionEntered(new RegionEnteredEventArgs(player, region));
        }
Example #6
0
        public static void OnRegionLeft(TSPlayer player, Region region)
        {
            if (RegionLeft == null)
            {
                return;
            }

            RegionLeft(new RegionLeftEventArgs(player, region));
        }
Example #7
0
        public static void OnPlayerLogin(TSPlayer ply)
        {
            if(PlayerLogin == null)
            {
                return;
            }

            PlayerLoginEventArgs args = new PlayerLoginEventArgs(ply);
            PlayerLogin(args);
        }
Example #8
0
        public PlayerData GetPlayerData(TSPlayer player, int acctid)
        {
            PlayerData playerData = new PlayerData(player);

            try
            {
                using (var reader = database.QueryReader("SELECT * FROM tsCharacter WHERE [email protected]", acctid))
                {
                    if (reader.Read())
                    {
                        playerData.exists = true;
                        playerData.health = reader.Get<int>("Health");
                        playerData.maxHealth = reader.Get<int>("MaxHealth");
                        playerData.mana = reader.Get<int>("Mana");
                        playerData.maxMana = reader.Get<int>("MaxMana");
                        List<NetItem> inventory = reader.Get<string>("Inventory").Split('~').Select(NetItem.Parse).ToList();
                        if (inventory.Count < NetItem.MaxInventory)
                        {
                            //TODO: unhardcode this - stop using magic numbers and use NetItem numbers
                            //Set new armour slots empty
                            inventory.InsertRange(67, new NetItem[2]);
                            //Set new vanity slots empty
                            inventory.InsertRange(77, new NetItem[2]);
                            //Set new dye slots empty
                            inventory.InsertRange(87, new NetItem[2]);
                            //Set the rest of the new slots empty
                            inventory.AddRange(new NetItem[NetItem.MaxInventory - inventory.Count]);
                        }
                        playerData.inventory = inventory.ToArray();
                        playerData.extraSlot = reader.Get<int>("extraSlot");
                        playerData.spawnX = reader.Get<int>("spawnX");
                        playerData.spawnY = reader.Get<int>("spawnY");
                        playerData.skinVariant = reader.Get<int>("skinVariant");
                        playerData.hair = reader.Get<int?>("hair");
                        playerData.hairDye = (byte)reader.Get<int>("hairDye");
                        playerData.hairColor = TShock.Utils.DecodeColor(reader.Get<int?>("hairColor"));
                        playerData.pantsColor = TShock.Utils.DecodeColor(reader.Get<int?>("pantsColor"));
                        playerData.shirtColor = TShock.Utils.DecodeColor(reader.Get<int?>("shirtColor"));
                        playerData.underShirtColor = TShock.Utils.DecodeColor(reader.Get<int?>("underShirtColor"));
                        playerData.shoeColor = TShock.Utils.DecodeColor(reader.Get<int?>("shoeColor"));
                        playerData.hideVisuals = TShock.Utils.DecodeBoolArray(reader.Get<int?>("hideVisuals"));
                        playerData.skinColor = TShock.Utils.DecodeColor(reader.Get<int?>("skinColor"));
                        playerData.eyeColor = TShock.Utils.DecodeColor(reader.Get<int?>("eyeColor"));
                        playerData.questsCompleted = reader.Get<int>("questsCompleted");
                        return playerData;
                    }
                }
            }
            catch (Exception ex)
            {
                TShock.Log.Error(ex.ToString());
            }

            return playerData;
        }
Example #9
0
        public static bool OnPlayerCommand(TSPlayer player, string cmdName, string cmdText, List<string> args)
        {
            if (PlayerCommand == null)
            {
                return false;
            }
            PlayerCommandEventArgs playerCommandEventArgs = new PlayerCommandEventArgs()
            {
                Player = player,
                CommandName = cmdName,
                CommandText = cmdText,
                Parameters = args

            };
            PlayerCommand(playerCommandEventArgs);
            return playerCommandEventArgs.Handled;
        }
Example #10
0
 public RegionLeftEventArgs(TSPlayer ply, Region region)
 {
     Player = ply;
     Region = region;
 }
Example #11
0
        public bool InsertPlayerData(TSPlayer player)
        {
            PlayerData playerData = player.PlayerData;

            if (!player.IsLoggedIn)
                return false;

            if (!GetPlayerData(player, player.UserID).exists)
            {
                try
                {
                    database.Query("INSERT INTO tsCharacter (Account, Health, MaxHealth, Mana, MaxMana, Inventory, spawnX, spawnY) VALUES (@0, @1, @2, @3, @4, @5, @6, @7);", player.UserID,
                                   playerData.health, playerData.maxHealth, playerData.mana, playerData.maxMana, NetItem.ToString(playerData.inventory), player.TPlayer.SpawnX, player.TPlayer.SpawnY);
                    return true;
                }
                catch (Exception ex)
                {
                    Log.Error(ex.ToString());
                }
            }
            else
            {
                try
                {
                    database.Query("UPDATE tsCharacter SET Health = @0, MaxHealth = @1, Mana = @2, MaxMana = @3, Inventory = @4, spawnX = @6, spawnY = @7 WHERE Account = @5;", playerData.health, playerData.maxHealth,
                                   playerData.mana, playerData.maxMana, NetItem.ToString(playerData.inventory), player.UserID, player.TPlayer.SpawnX, player.TPlayer.SpawnY);
                    return true;
                }
                catch (Exception ex)
                {
                    Log.Error(ex.ToString());
                }
            }
            return false;
        }
Example #12
0
        /// <summary>
        /// Checks if a given player can build in a region at the given (x, y) coordinate
        /// </summary>
        /// <param name="x">X coordinate</param>
        /// <param name="y">Y coordinate</param>
        /// <param name="ply">Player to check permissions with</param>
        /// <returns>Whether the player can build at the given (x, y) coordinate</returns>
        public bool CanBuild(int x, int y, TSPlayer ply)
        {
            if (!ply.HasPermission(Permissions.canbuild))
            {
                return false;
            }
            Region top = null;

            foreach (Region region in Regions.ToList())
            {
                if (region.InArea(x, y))
                {
                    if (top == null || region.Z > top.Z)
                        top = region;
                }
            }
            return top == null || top.HasPermissionToBuildInRegion(ply);
        }
Example #13
0
 public RegionEnteredEventArgs(TSPlayer ply, Region region)
 {
     Player = ply;
     Region = region;
 }
Example #14
0
 public PlayerPostLoginEventArgs(TSPlayer ply)
 {
     Player = ply;
 }
Example #15
0
        public bool NewPlayer(TSPlayer player)
        {
            string[] inv, bank1, bank2, armor;
            inv = new string[49];
            bank1 = new string[21];
            bank2 = new string[21];
            armor = new string[12];
            for (int i = 0; i < 48; i++)
            {
                inv[i] = player.TPlayer.inventory[i].name + ":" + player.TPlayer.inventory[i].stack;
            }
            for (int k = 0; k < 20; k++)
            {
                    bank1[k] = player.TPlayer.bank[k].name + ":" + player.TPlayer.bank[k].stack;
                    bank2[k] = player.TPlayer.bank2[k].name + ":" + player.TPlayer.bank2[k].stack;
            }

                if ("Copper Shortsword:1" == inv[0] && "Copper Pickaxe:1" == inv[1] && "Copper Axe:1" == inv[2])
                {
                }
                else
                {
                    return false;
                }

                if ("Carrot:1" == inv[3])
                {
                    for (int i = 4; i < 48; i++)
                    {
                        if (":0" != inv[i])
                        {
                            return false;
                        }
                    }
                }
                else
                {
                    for (int i = 3; i < 48; i++)
                    {
                        if (":0" != inv[i])
                        {
                            return false;
                        }
                    }
                }
            for (int i = 0; i < 20; i++)
            {
                bank1[i] = player.TPlayer.bank[i].name + ":" + player.TPlayer.bank[i].stack;
                bank2[i] = player.TPlayer.bank2[i].name + ":" + player.TPlayer.bank2[i].stack;
                if (":0" != bank1[i] || ":0" != bank2[i])
                {
                    return false;
                }
            }
            for (int i = 0; i < 11; i++)
            {
                armor[i] = player.TPlayer.armor[i].name;
                if ("" != armor[i])
                {
                    return false;
                }

            }
            return true;
        }
Example #16
0
        /// <summary>
        /// Inserts player data to the tsCharacter database table
        /// </summary>
        /// <param name="player">player to take data from</param>
        /// <returns>true if inserted successfully</returns>
        public bool InsertPlayerData(TSPlayer player)
        {
            PlayerData playerData = player.PlayerData;

            if (!player.IsLoggedIn)
                return false;

                if ((player.tempGroup != null && player.tempGroup.HasPermission(Permissions.bypassssc)) || player.Group.HasPermission(Permissions.bypassssc))
                {
                    TShock.Log.ConsoleInfo("Skipping SSC Backup for " + player.User.Name); // Debug code
                        return true;
                    }

            if (!GetPlayerData(player, player.User.ID).exists)
            {
                try
                {
                    database.Query(
                        "INSERT INTO tsCharacter (Account, Health, MaxHealth, Mana, MaxMana, Inventory, extraSlot, spawnX, spawnY, skinVariant, hair, hairDye, hairColor, pantsColor, shirtColor, underShirtColor, shoeColor, hideVisuals, skinColor, eyeColor, questsCompleted) VALUES (@0, @1, @2, @3, @4, @5, @6, @7, @8, @9, @10, @11, @12, @13, @14, @15, @16, @17, @18, @19, @20);",
                        player.User.ID, playerData.health, playerData.maxHealth, playerData.mana, playerData.maxMana, String.Join("~", playerData.inventory), playerData.extraSlot, player.TPlayer.SpawnX, player.TPlayer.SpawnY, player.TPlayer.skinVariant, player.TPlayer.hair, player.TPlayer.hairDye, TShock.Utils.EncodeColor(player.TPlayer.hairColor), TShock.Utils.EncodeColor(player.TPlayer.pantsColor),TShock.Utils.EncodeColor(player.TPlayer.shirtColor), TShock.Utils.EncodeColor(player.TPlayer.underShirtColor), TShock.Utils.EncodeColor(player.TPlayer.shoeColor), TShock.Utils.EncodeBoolArray(player.TPlayer.hideVisual), TShock.Utils.EncodeColor(player.TPlayer.skinColor),TShock.Utils.EncodeColor(player.TPlayer.eyeColor), player.TPlayer.anglerQuestsFinished);
                    return true;
                }
                catch (Exception ex)
                {
                    TShock.Log.Error(ex.ToString());
                }
            }
            else
            {
                try
                {
                    database.Query(
                        "UPDATE tsCharacter SET Health = @0, MaxHealth = @1, Mana = @2, MaxMana = @3, Inventory = @4, spawnX = @6, spawnY = @7, hair = @8, hairDye = @9, hairColor = @10, pantsColor = @11, shirtColor = @12, underShirtColor = @13, shoeColor = @14, hideVisuals = @15, skinColor = @16, eyeColor = @17, questsCompleted = @18, skinVariant = @19, extraSlot = @20 WHERE Account = @5;",
                        playerData.health, playerData.maxHealth, playerData.mana, playerData.maxMana, String.Join("~", playerData.inventory), player.User.ID, player.TPlayer.SpawnX, player.TPlayer.SpawnY, player.TPlayer.hair, player.TPlayer.hairDye, TShock.Utils.EncodeColor(player.TPlayer.hairColor), TShock.Utils.EncodeColor(player.TPlayer.pantsColor), TShock.Utils.EncodeColor(player.TPlayer.shirtColor), TShock.Utils.EncodeColor(player.TPlayer.underShirtColor), TShock.Utils.EncodeColor(player.TPlayer.shoeColor), TShock.Utils.EncodeBoolArray(player.TPlayer.hideVisual), TShock.Utils.EncodeColor(player.TPlayer.skinColor), TShock.Utils.EncodeColor(player.TPlayer.eyeColor), player.TPlayer.anglerQuestsFinished, player.TPlayer.skinVariant, player.TPlayer.extraAccessory ? 1 : 0);
                    return true;
                }
                catch (Exception ex)
                {
                    TShock.Log.Error(ex.ToString());
                }
            }
            return false;
        }
Example #17
0
        public bool HasPermissionToBuildInRegion(TSPlayer ply)
        {
            if (!ply.IsLoggedIn)
            {
                if (!ply.HasBeenNaggedAboutLoggingIn)
                {
                    ply.SendMessage("You must be logged in to take advantage of protected regions.", Color.Red);
                    ply.HasBeenNaggedAboutLoggingIn = true;
                }
                return false;
            }
            if (!DisableBuild)
            {
                return true;
            }

            for (int i = 0; i < AllowedIDs.Count; i++)
            {
                if (AllowedIDs[i] == ply.UserID)
                {
                    return true;
                }
            }
            return false;
        }
Example #18
0
        /// <summary>
        /// Inserts player data to the tsCharacter database table
        /// </summary>
        /// <param name="player">player to take data from</param>
        /// <returns>true if inserted successfully</returns>
        public bool InsertPlayerData(TSPlayer player)
        {
            PlayerData playerData = player.PlayerData;

            if (!player.IsLoggedIn)
                return false;

            if (!GetPlayerData(player, player.User.ID).exists)
            {
                try
                {
                    database.Query(
                        "INSERT INTO tsCharacter (Account, Health, MaxHealth, Mana, MaxMana, Inventory, spawnX, spawnY, hair, hairDye, hairColor, pantsColor, shirtColor, underShirtColor, shoeColor, hideVisuals, skinColor, eyeColor, questsCompleted) VALUES (@0, @1, @2, @3, @4, @5, @6, @7, @8, @9, @10, @11, @12, @13, @14, @15, @16, @17, @18);",
                        player.User.ID, playerData.health, playerData.maxHealth, playerData.mana, playerData.maxMana, String.Join("~", playerData.inventory), player.TPlayer.SpawnX, player.TPlayer.SpawnY, player.TPlayer.hair, player.TPlayer.hairDye, TShock.Utils.EncodeColor(player.TPlayer.hairColor), TShock.Utils.EncodeColor(player.TPlayer.pantsColor),TShock.Utils.EncodeColor(player.TPlayer.shirtColor), TShock.Utils.EncodeColor(player.TPlayer.underShirtColor), TShock.Utils.EncodeColor(player.TPlayer.shoeColor), TShock.Utils.EncodeBoolArray(player.TPlayer.hideVisual), TShock.Utils.EncodeColor(player.TPlayer.skinColor),TShock.Utils.EncodeColor(player.TPlayer.eyeColor), player.TPlayer.anglerQuestsFinished);
                    return true;
                }
                catch (Exception ex)
                {
                    TShock.Log.Error(ex.ToString());
                }
            }
            else
            {
                try
                {
                    database.Query(
                        "UPDATE tsCharacter SET Health = @0, MaxHealth = @1, Mana = @2, MaxMana = @3, Inventory = @4, spawnX = @6, spawnY = @7, hair = @8, hairDye = @9, hairColor = @10, pantsColor = @11, shirtColor = @12, underShirtColor = @13, shoeColor = @14, hideVisuals = @15, skinColor = @16, eyeColor = @17, questsCompleted = @18 WHERE Account = @5;",
                        playerData.health, playerData.maxHealth, playerData.mana, playerData.maxMana, String.Join("~", playerData.inventory), player.User.ID, player.TPlayer.SpawnX, player.TPlayer.SpawnY, player.TPlayer.hair, player.TPlayer.hairDye, TShock.Utils.EncodeColor(player.TPlayer.hairColor), TShock.Utils.EncodeColor(player.TPlayer.pantsColor), TShock.Utils.EncodeColor(player.TPlayer.shirtColor), TShock.Utils.EncodeColor(player.TPlayer.underShirtColor), TShock.Utils.EncodeColor(player.TPlayer.shoeColor), TShock.Utils.EncodeBoolArray(player.TPlayer.hideVisual), TShock.Utils.EncodeColor(player.TPlayer.skinColor), TShock.Utils.EncodeColor(player.TPlayer.eyeColor), player.TPlayer.anglerQuestsFinished);
                    return true;
                }
                catch (Exception ex)
                {
                    TShock.Log.Error(ex.ToString());
                }
            }
            return false;
        }
Example #19
0
 public ReloadEventArgs(TSPlayer ply)
 {
     Player = ply;
 }
Example #20
0
        public bool CheckInventory(TSPlayer player)
        {
            string[] inv;
            inv = new string[41];
            QueryResult result;
            for (int i = 0; i < 40; i++)
            {
                inv[i] = player.TPlayer.inventory[i].name + ":" + player.TPlayer.inventory[i].stack;
            }
            try
            {
                result = database.QueryReader("SELECT * FROM Inventory WHERE LOWER (Username) = @0", player.Name.ToLower());
                using (var reader = result)
                {
                    if (reader.Read())
                    {
                        string slot0 = reader.Get<string>("Slot0"); string slot1 = reader.Get<string>("Slot1");
                        string slot2 = reader.Get<string>("Slot2"); string slot3 = reader.Get<string>("Slot3");
                        string slot4 = reader.Get<string>("Slot4"); string slot5 = reader.Get<string>("Slot5");
                        string slot6 = reader.Get<string>("Slot6"); string slot7 = reader.Get<string>("Slot7");
                        string slot8 = reader.Get<string>("Slot8"); string slot9 = reader.Get<string>("Slot9");
                        string slot10 = reader.Get<string>("Slot10"); string slot11 = reader.Get<string>("Slot11");
                        string slot12 = reader.Get<string>("Slot12"); string slot13 = reader.Get<string>("Slot13");
                        string slot14 = reader.Get<string>("Slot14"); string slot15 = reader.Get<string>("Slot15");
                        string slot16 = reader.Get<string>("Slot16"); string slot17 = reader.Get<string>("Slot17");
                        string slot18 = reader.Get<string>("Slot18"); string slot19 = reader.Get<string>("Slot19");
                        string slot20 = reader.Get<string>("Slot20"); string slot21 = reader.Get<string>("Slot21");
                        string slot22 = reader.Get<string>("Slot22"); string slot23 = reader.Get<string>("Slot23");
                        string slot24 = reader.Get<string>("Slot24"); string slot25 = reader.Get<string>("Slot25");
                        string slot26 = reader.Get<string>("Slot26"); string slot27 = reader.Get<string>("Slot27");
                        string slot28 = reader.Get<string>("Slot28"); string slot29 = reader.Get<string>("Slot29");
                        string slot30 = reader.Get<string>("Slot30"); string slot31 = reader.Get<string>("Slot31");
                        string slot32 = reader.Get<string>("Slot32"); string slot33 = reader.Get<string>("Slot33");
                        string slot34 = reader.Get<string>("Slot34"); string slot35 = reader.Get<string>("Slot35");
                        string slot36 = reader.Get<string>("Slot36"); string slot37 = reader.Get<string>("Slot37");
                        string slot38 = reader.Get<string>("Slot38"); string slot39 = reader.Get<string>("Slot39");

                        if (slot0 == inv[0] && slot1 == inv[1] && slot2 == inv[2] && slot3 == inv[3] && slot4 == inv[4] &&
                            slot5 == inv[5] && slot6 == inv[6] && slot7 == inv[7] && slot8 == inv[8] && slot9 == inv[9] &&
                            slot10 == inv[10] && slot11 == inv[11] && slot12 == inv[12] && slot13 == inv[13] && slot14 == inv[14] &&
                            slot15 == inv[15] && slot16 == inv[16] && slot17 == inv[17] && slot18 == inv[18] && slot19 == inv[19] &&
                            slot20 == inv[20] && slot21 == inv[21] && slot22 == inv[22] && slot23 == inv[23] && slot24 == inv[24] &&
                            slot25 == inv[25] && slot26 == inv[26] && slot27 == inv[27] && slot28 == inv[28] && slot29 == inv[29] &&
                            slot30 == inv[30] && slot31 == inv[31] && slot32 == inv[32] && slot33 == inv[33] && slot34 == inv[34] &&
                            slot35 == inv[35] && slot36 == inv[36] && slot37 == inv[37] && slot38 == inv[38] && slot39 == inv[39])
                        {
                            return true;
                        }
                        else
                        {
                            return false;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex.ToString());
            }
            return false;
        }
Example #21
0
 public bool UserExist(TSPlayer player)
 {
     try
     {
         QueryResult result;
         result = database.QueryReader("SELECT * FROM Inventory WHERE LOWER (Username) = @0", player.Name.ToLower());
         using (var reader = result)
             {
                 if (reader.Read())
                     {
                         return true;
                     }
             }
         return false;
     }
     catch
     {
         return false;
     }
 }
Example #22
0
 public void UpdateInventory(TSPlayer player)
 {
     string[] inv;
     inv = new string[41];
     for (int i = 0; i < 40; i++)
     {
         inv[i] = player.TPlayer.inventory[i].name + ":" + player.TPlayer.inventory[i].stack;
     }
     try
     {
         database.Query("UPDATE Inventory SET Slot0 = @0, Slot1 = @1, Slot2 = @2, Slot3 = @3, Slot4 = @4, " +
                                               "Slot5 = @5, Slot6 = @6, Slot7 = @7, Slot8 = @8, Slot9 = @9, " +
                                               "Slot10 = @10, Slot11 = @11, Slot12 = @12, Slot13 = @13, Slot14 = @14, " +
                                               "Slot15 = @15, Slot16 = @16, Slot17 = @17, Slot18 = @18, Slot19 = @19, " +
                                               "Slot20 = @20, Slot21 = @21, Slot22 = @22, Slot23 = @23, Slot24 = @24, " +
                                               "Slot25 = @25, Slot26 = @26, Slot27 = @27, Slot28 = @28, Slot29 = @29, " +
                                               "Slot30 = @30, Slot31 = @31, Slot32 = @32, Slot33 = @33, Slot34 = @34, " +
                                               "Slot35 = @35, Slot36 = @36, Slot37 = @37, Slot38 = @38, Slot39 = @39 " +
                                               "WHERE LOWER (Username) = @40;", inv[0], inv[1], inv[2], inv[3], inv[4],
                                                          inv[5], inv[6], inv[7], inv[8], inv[9], inv[10], inv[11],
                                                          inv[12], inv[13], inv[14], inv[15], inv[16], inv[17],
                                                          inv[18], inv[19], inv[20], inv[21], inv[22], inv[23],
                                                          inv[24], inv[25], inv[26], inv[27], inv[28], inv[29],
                                                          inv[30], inv[31], inv[32], inv[33], inv[34], inv[35],
                                                          inv[36], inv[37], inv[38], inv[39], player.Name.ToLower());
         return;
     }
     catch (Exception ex)
     {
         Log.Error(ex.ToString());
     }
 }
Example #23
0
        /// <summary>
        /// Show the top of players
        /// </summary>
        /// <param name="player">Tsplayer player</param>
        public void Top(TSPlayer player, bool rc = true)
        {
            string playername = string.Empty;
            int playingtime = 0;
            int count = 0;
            double rcoins = 0;
            var user = TShock.Users.GetUserByName(player.Name);
            try
            {
                if (rc == true)
                {
                    using (var reader = database.QueryReader("SELECT * FROM Users ORDER BY RCoins DESC LIMIT 3"))
                            while (reader.Read())
                        {
                            count++;
                            playername = reader.Get<string>("Username");
                            playingtime = reader.Get<int>("PlayingTime");
                            rcoins = reader.Get<double>("RCoins");

                                if (count == 1)
                                player.SendMessage(string.Format("{0} place - <{1}>. Have {2} RCoins. Total played time is {3} minutes.", count, playername, Math.Round(rcoins, 2), playingtime), Color.LightPink);
                            if (count == 2)
                                player.SendMessage(string.Format("{0} place - <{1}>. Have {2} RCoins. Total played time is {3} minutes.", count, playername, Math.Round(rcoins, 2), playingtime), Color.LightGreen);
                            if (count == 3)
                                player.SendMessage(string.Format("{0} place - <{1}>. Have {2} RCoins. Total played time is {3} minutes.", count, playername, Math.Round(rcoins, 2), playingtime), Color.LightBlue);
                        }
                }
                else
                {
                    using (var reader = database.QueryReader("SELECT * FROM Users ORDER BY PlayingTime DESC LIMIT 3"))
                        while (reader.Read())
                        {
                            count++;
                            playername = reader.Get<string>("Username");
                            playingtime = reader.Get<int>("PlayingTime");
                            rcoins = reader.Get<double>("RCoins");

                            if (count == 1)
                                player.SendMessage(string.Format("{0} place - <{1}>. Have {2} RCoins. Total played time is {3} minutes.", count, playername, Math.Round(rcoins, 2), playingtime), Color.LightPink);
                            if (count == 2)
                                player.SendMessage(string.Format("{0} place - <{1}>. Have {2} RCoins. Total played time is {3} minutes.", count, playername, Math.Round(rcoins, 2), playingtime), Color.LightGreen);
                            if (count == 3)
                                player.SendMessage(string.Format("{0} place - <{1}>. Have {2} RCoins. Total played time is {3} minutes.", count, playername, Math.Round(rcoins, 2), playingtime), Color.LightBlue);
                        }
                }

            }
            catch (Exception ex)
            {
                throw new UserManagerException("Top SQL returned an error", ex);
            }
            player.SendMessage("You have " + Math.Round(user.RCoins, 2) + " Rcoins. Total played time is " + user.PlayingTime + " minutes", Color.Yellow);
        }
Example #24
0
 public bool CanBuild(int x, int y, TSPlayer ply)
 {
     if (!ply.Group.HasPermission(Permissions.canbuild))
     {
         return false;
     }
     Region top = null;
     for (int i = 0; i < Regions.Count; i++)
     {
         if (Regions[i].InArea(x,y) )
         {
             if (top == null)
                 top = Regions[i];
             else
             {
                 if (Regions[i].Z > top.Z)
                     top = Regions[i];
             }
         }
     }
     return top == null || top.HasPermissionToBuildInRegion(ply);
 }
Example #25
0
 public bool CanBuild(int x, int y, TSPlayer ply)
 {
     if (!ply.Group.HasPermission(Permissions.canbuild))
     {
         return false;
     }
     for (int i = 0; i < Regions.Count; i++)
     {
         if (Regions[i].InArea(new Rectangle(x, y, 0, 0)) && !Regions[i].HasPermissionToBuildInRegion(ply))
         {
             return false;
         }
     }
     return true;
 }
Example #26
0
 public RegionEnteredEventArgs(TSPlayer ply)
 {
     Player = ply;
 }
Example #27
0
        public static bool OnPlayerPreLogin(TSPlayer ply, string name, string pass)
        {
            if (PlayerPreLogin == null)
                return false;

            var args = new PlayerPreLoginEventArgs {Player = ply, LoginName = name, Password = pass};
            PlayerPreLogin(args);
            return args.Handled;
        }
Example #28
0
        /// <summary>
        /// Checks if a given player has permission to build in the region
        /// </summary>
        /// <param name="ply">Player to check permissions with</param>
        /// <returns>Whether the player has permission</returns>
        public bool HasPermissionToBuildInRegion(TSPlayer ply)
        {
            if (!DisableBuild)
            {
                return true;
            }
            if (!ply.IsLoggedIn)
            {
                if (!ply.HasBeenNaggedAboutLoggingIn)
                {
                    ply.SendMessage("You must be logged in to take advantage of protected regions.", Color.Red);
                    ply.HasBeenNaggedAboutLoggingIn = true;
                }
                return false;
            }

            return ply.HasPermission(Permissions.editregion) || AllowedIDs.Contains(ply.User.ID) || AllowedGroups.Contains(ply.Group.Name) || Owner == ply.User.Name;
        }
Example #29
0
        public bool HasPermissionToBuildInRegion(TSPlayer ply, out string CoOwner)
        {
            CoOwner = string.Empty;

            if (!ply.IsLoggedIn)
            {
                    ply.SendMessage("You must be logged in to take advantage of protected regions.", Color.Red);
                return false;
            }
            if (!DisableBuild)
            {
                return true;
            }

            try
            {
                for (int i = 0; i < AllowedIDs.Count; i++)
                {
                    CoOwner = string.Format("{0} {1}", CoOwner, TShock.Users.GetNameForID((int)AllowedIDs[i]));
                }
                CoOwner = CoOwner.Remove(0, 1);
            }
            catch
            {
                CoOwner = "";
                return false;
            }

            for (int i = 0; i < AllowedIDs.Count; i++)
            {
                if (AllowedIDs[i] == ply.UserID)
                {
                    return true;
                }
            }
            return false;
        }
Example #30
0
        public void NewInventory(TSPlayer player)
        {
            string[] inv;
            inv = new string[41];
            for (int i = 0; i < 40; i++)
            {
                inv[i] = player.TPlayer.inventory[i].name + ":" + player.TPlayer.inventory[i].stack;
            }
            try
            {
                database.Query("INSERT INTO Inventory (Username, Slot0, Slot1, Slot2, Slot3, Slot4, " +
                                                                 "Slot5, Slot6, Slot7, Slot8, Slot9, "+
                                                                 "Slot10, Slot11, Slot12, Slot13, Slot14, " +
                                                                 "Slot15, Slot16, Slot17, Slot18, Slot19, "+
                                                                 "Slot20, Slot21, Slot22, Slot23, Slot24, " +
                                                                 "Slot25, Slot26, Slot27, Slot28, Slot29, "+
                                                                 "Slot30, Slot31, Slot32, Slot33, Slot34, " +
                                                                 "Slot35, Slot36, Slot37, Slot38, Slot39"+
                                                                 ") VALUES (@40, @0, @1, @2, @3, @4, @5, "+
                                                                 "@6, @7, @8, @9, @10, @11, @12, @13, "+
                                                                 "@14, @15, @16, @17, @18, @19, @20, "+
                                                                 "@21, @22, @23, @24, @25, @26, @27, "+
                                                                 "@28, @29, @30, @31, @32, @33, @34, @35, @36, "+
                                                                 "@37, @38, @39);", inv[0], inv[1], inv[2], inv[3], inv[4],
                                                                 inv[5], inv[6], inv[7], inv[8], inv[9], inv[10], inv[11],
                                                                 inv[12], inv[13], inv[14], inv[15], inv[16], inv[17],
                                                                 inv[18], inv[19], inv[20], inv[21], inv[22], inv[23],
                                                                 inv[24], inv[25], inv[26], inv[27], inv[28], inv[29],
                                                                 inv[30], inv[31], inv[32], inv[33], inv[34], inv[35],
                                                                 inv[36], inv[37], inv[38], inv[39], player.Name);

            }
            catch (Exception ex)
            {
                Log.Error(ex.ToString());
            }
        }