diff --git a/HorseIsleServer/HISPd/Properties/AssemblyInfo.cs b/HorseIsleServer/HISPd/Properties/AssemblyInfo.cs index 47ac989..347d0ac 100644 --- a/HorseIsleServer/HISPd/Properties/AssemblyInfo.cs +++ b/HorseIsleServer/HISPd/Properties/AssemblyInfo.cs @@ -31,5 +31,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.7.11.0")] -[assembly: AssemblyFileVersion("1.7.11.0")] +[assembly: AssemblyVersion("1.7.20.0")] +[assembly: AssemblyFileVersion("1.7.20.0")] diff --git a/HorseIsleServer/HISPd/Resources/DEBIAN/control b/HorseIsleServer/HISPd/Resources/DEBIAN/control index 1d9f8e1..67cb8c8 100644 --- a/HorseIsleServer/HISPd/Resources/DEBIAN/control +++ b/HorseIsleServer/HISPd/Resources/DEBIAN/control @@ -1,5 +1,5 @@ Package: hisp -Version: 1.7.11 +Version: 1.7.20 Depends: coreutils,systemd,mariadb-server,libsqlite3-dev,zlib1g-dev,libicu-dev,libkrb5-dev Maintainer: Li Homepage: https://islehorse.com diff --git a/HorseIsleServer/LibHISP/Game/Chat/Command.cs b/HorseIsleServer/LibHISP/Game/Chat/Command.cs index 62ea29a..058b8c7 100644 --- a/HorseIsleServer/LibHISP/Game/Chat/Command.cs +++ b/HorseIsleServer/LibHISP/Game/Chat/Command.cs @@ -1,33 +1,33 @@ -using HISP.Player; -using HISP.Server; -using HISP.Game.Items; -using HISP.Game.Events; -using HISP.Game.Horse; -using HISP.Game.Inventory; - -using System.Linq; -using System; -using System.Collections.Generic; +using HISP.Player; +using HISP.Server; +using HISP.Game.Items; +using HISP.Game.Events; +using HISP.Game.Horse; +using HISP.Game.Inventory; -namespace HISP.Game.Chat -{ - public class Command - { - private static User findNamePartial(string name) - { - foreach (GameClient client in GameClient.ConnectedClients) - { - if (client == null) - continue; - if (client.LoggedIn) - { - if (client.LoggedinUser.Username.ToLower().StartsWith(name.ToLower())) - { - return client.LoggedinUser; - } - } - } - throw new KeyNotFoundException("name not found"); +using System.Linq; +using System; +using System.Collections.Generic; + +namespace HISP.Game.Chat +{ + public class Command + { + private static User findNamePartial(string name) + { + foreach (GameClient client in GameClient.ConnectedClients) + { + if (client == null) + continue; + if (client.LoggedIn) + { + if (client.LoggedinUser.Username.ToLower().StartsWith(name.ToLower())) + { + return client.LoggedinUser; + } + } + } + throw new KeyNotFoundException("name not found"); } public static void RegisterCommands() @@ -56,17 +56,17 @@ namespace HISP.Game.Chat // User commands new CommandRegister('!', "MUTE", "ALL\nGLOBAL\nISLAND\nNEAR\nHERE\nBUDDY\nPM\nBR\nSOCIALS\nLOGINS", Command.Mute); new CommandRegister('!', "UNMUTE", "ALL\nGLOBAL\nISLAND\nNEAR\nHERE\nBUDDY\nPM\nBR\nSOCIALS\nLOGINS", Command.UnMute); - new CommandRegister('!', "HEAR", "ALL\nGLOBAL\nISLAND\nNEAR\nHERE\nBUDDY\nPM\nBR\nSOCIALS\nLOGINS", Command.UnMute); + new CommandRegister('!', "HEAR", "ALL\nGLOBAL\nISLAND\nNEAR\nHERE\nBUDDY\nPM\nBR\nSOCIALS\nLOGINS", Command.UnMute); new CommandRegister('!', "AUTOREPLY", "[message]", Command.AutoReply); new CommandRegister('!', "QUIZ", "", Command.Quiz); new CommandRegister('!', "WARP", "", Command.Warp); new CommandRegister('!', "DANCE", "", Command.Dance); - new CommandRegister('!', "VERSION", "", Command.Version); + new CommandRegister('!', "VERSION", "", Command.Version); } - public static bool Message(string message, string[] args, User user) - { - if (!user.Administrator) + public static bool Message(string message, string[] args, User user) + { + if (!user.Administrator) return false; string serverAnnoucement = String.Join(" ", args); @@ -82,709 +82,709 @@ namespace HISP.Game.Chat client.SendPacket(chatRightPacket); } } - - return true; - } - public static bool Shutdown(string message, string[] args, User user) - { - if (!user.Administrator) - return false; - - byte[] chatPacket = PacketBuilder.CreateChat(Messages.FormatAdminCommandCompleteMessage(message), PacketBuilder.CHAT_BOTTOM_LEFT); - user.LoggedinClient.SendPacket(chatPacket); - GameServer.ShutdownServer(); - - return true; - } - public static bool Give(string message, string[] args, User user) - { - if (args.Length <= 0) - return false; - if (!user.Administrator) - return false; - if(args[0].ToUpper() == "OBJECT") - { - int itemId = 0; - try - { - if(args[1] != "RANDOM") - { - itemId = int.Parse(args[1]); - } - else - { - itemId = Item.GetRandomItem().Id; - } - - Item.GetItemById(itemId); // Calling this makes sure this item id exists. - - ItemInstance newItemInstance = new ItemInstance(itemId); - - if (itemId == Item.Present) - newItemInstance.Data = Item.GetRandomItem().Id; - - if (args.Length >= 3) - { - if(args[2] == "ALL") - { - foreach (GameClient client in GameClient.ConnectedClients) - { - if (client.LoggedIn) - { - ItemInstance itmInstance = new ItemInstance(itemId); - - if (itemId == Item.Present) - itmInstance.Data = Item.GetRandomItem().Id; - - client.LoggedinUser.Inventory.AddIgnoringFull(itmInstance); - } - } - } - else - { - findNamePartial(args[2]).Inventory.AddIgnoringFull(newItemInstance); - } - } - else - { - user.Inventory.AddIgnoringFull(newItemInstance); - } - } - catch(Exception) - { - return false; - } - } - else if (args[0].ToUpper() == "HORSE") - { - int horseId = 0; - try - { - horseId = int.Parse(args[1]); - HorseInstance horse = new HorseInstance(HorseInfo.GetBreedById(horseId)); - - if (args.Length >= 3) - { - findNamePartial(args[2]).HorseInventory.AddHorse(horse); - } - else - { - user.HorseInventory.AddHorse(horse); - } - } - catch (Exception) - { - return false; - } - } - else if(args[0].ToUpper() == "AWARD") - { - int awardId = 0; - try - { - awardId = int.Parse(args[1]); - if (args.Length >= 3) - { - findNamePartial(args[2]).Awards.AddAward(Award.GetAwardById(awardId)); - } - else - { - user.Awards.AddAward(Award.GetAwardById(awardId)); - } - - } - catch (Exception) - { - return false; - } - } - else if (args[0].ToUpper() == "MONEY") - { - int money = 0; - try - { - money = int.Parse(args[1]); - if (args.Length >= 3) - { - findNamePartial(args[2]).AddMoney(money); - } - else - { - user.AddMoney(money); - } - } - catch (Exception) - { - return false; - } - } - else if (args[0].ToUpper() == "QUEST") - { - int questId = 0; - try - { - questId = int.Parse(args[1]); - if(args.Length >= 3) - { - if (args[2].ToUpper() == "FORCE") - { - Quest.CompleteQuest(user, Quest.GetQuestById(questId)); - goto msg; - } - } - Quest.ActivateQuest(user, Quest.GetQuestById(questId)); - } - catch (Exception) - { - return false; - } - } - else - { - return false; - } - msg:; - byte[] chatPacket = PacketBuilder.CreateChat(Messages.FormatAdminCommandCompleteMessage(message), PacketBuilder.CHAT_BOTTOM_LEFT); - user.LoggedinClient.SendPacket(chatPacket); - return true; - } - - public static bool Swf(string message, string[] args, User user) - { - if (args.Length <= 0) - return false; - - if (!user.Administrator && !user.Moderator) - return false; - - try - { - string swfName = args[0]; - string swfUser = user.Username; + + return true; + } + public static bool Shutdown(string message, string[] args, User user) + { + if (!user.Administrator) + return false; + + byte[] chatPacket = PacketBuilder.CreateChat(Messages.FormatAdminCommandCompleteMessage(message), PacketBuilder.CHAT_BOTTOM_LEFT); + user.LoggedinClient.SendPacket(chatPacket); + GameServer.ShutdownServer(); + + return true; + } + public static bool Give(string message, string[] args, User user) + { + if (args.Length <= 0) + return false; + if (!user.Administrator) + return false; + if(args[0].ToUpper() == "OBJECT") + { + int itemId = 0; + try + { + if(args[1] != "RANDOM") + { + itemId = int.Parse(args[1]); + } + else + { + itemId = Item.GetRandomItem().Id; + } + + Item.GetItemById(itemId); // Calling this makes sure this item id exists. + + ItemInstance newItemInstance = new ItemInstance(itemId); + + if (itemId == Item.Present) + newItemInstance.Data = Item.GetRandomItem().Id; + + if (args.Length >= 3) + { + if(args[2] == "ALL") + { + foreach (GameClient client in GameClient.ConnectedClients) + { + if (client.LoggedIn) + { + ItemInstance itmInstance = new ItemInstance(itemId); + + if (itemId == Item.Present) + itmInstance.Data = Item.GetRandomItem().Id; + + client.LoggedinUser.Inventory.AddIgnoringFull(itmInstance); + } + } + } + else + { + findNamePartial(args[2]).Inventory.AddIgnoringFull(newItemInstance); + } + } + else + { + user.Inventory.AddIgnoringFull(newItemInstance); + } + } + catch(Exception) + { + return false; + } + } + else if (args[0].ToUpper() == "HORSE") + { + int horseId = 0; + try + { + horseId = int.Parse(args[1]); + HorseInstance horse = new HorseInstance(HorseInfo.GetBreedById(horseId)); + + if (args.Length >= 3) + { + findNamePartial(args[2]).HorseInventory.AddHorse(horse); + } + else + { + user.HorseInventory.AddHorse(horse); + } + } + catch (Exception) + { + return false; + } + } + else if(args[0].ToUpper() == "AWARD") + { + int awardId = 0; + try + { + awardId = int.Parse(args[1]); + if (args.Length >= 3) + { + findNamePartial(args[2]).Awards.AddAward(Award.GetAwardById(awardId)); + } + else + { + user.Awards.AddAward(Award.GetAwardById(awardId)); + } + + } + catch (Exception) + { + return false; + } + } + else if (args[0].ToUpper() == "MONEY") + { + int money = 0; + try + { + money = int.Parse(args[1]); + if (args.Length >= 3) + { + findNamePartial(args[2]).AddMoney(money); + } + else + { + user.AddMoney(money); + } + } + catch (Exception) + { + return false; + } + } + else if (args[0].ToUpper() == "QUEST") + { + int questId = 0; + try + { + questId = int.Parse(args[1]); + if(args.Length >= 3) + { + if (args[2].ToUpper() == "FORCE") + { + Quest.CompleteQuest(user, Quest.GetQuestById(questId)); + goto msg; + } + } + Quest.ActivateQuest(user, Quest.GetQuestById(questId)); + } + catch (Exception) + { + return false; + } + } + else + { + return false; + } + msg:; + byte[] chatPacket = PacketBuilder.CreateChat(Messages.FormatAdminCommandCompleteMessage(message), PacketBuilder.CHAT_BOTTOM_LEFT); + user.LoggedinClient.SendPacket(chatPacket); + return true; + } + + public static bool Swf(string message, string[] args, User user) + { + if (args.Length <= 0) + return false; + + if (!user.Administrator && !user.Moderator) + return false; + + try + { + string swfName = args[0]; + string swfUser = user.Username; if (args.Length <= 2) - swfUser = args[1]; - - byte[] packetBytes = PacketBuilder.CreateSwfModulePacket(swfName, PacketBuilder.PACKET_SWF_MODULE_FORCE); - if (swfUser.ToUpper() == "ALL") - { - foreach (GameClient client in GameClient.ConnectedClients) - { - if (client.LoggedIn) - client.SendPacket(packetBytes); - } - } - else - { - User player = findNamePartial(swfUser); - player.LoggedinClient.SendPacket(packetBytes); - } - } - catch (Exception) - { - return false; - } - - byte[] chatPacket = PacketBuilder.CreateChat(Messages.FormatAdminCommandCompleteMessage(message), PacketBuilder.CHAT_BOTTOM_LEFT); - user.LoggedinClient.SendPacket(chatPacket); - - return true; - } - - public static bool UnBan(string message, string[] args, User user) - { - if(args.Length <= 0) - return false; - if(!user.Administrator && !user.Moderator) - return false; - - try{ - string userName = args[0]; - int id = Database.GetUserid(userName); - Database.UnBanUser(id); - } - catch(Exception e) - { - Logger.ErrorPrint(e.Message); - return false; - } - - byte[] chatPacket = PacketBuilder.CreateChat(Messages.FormatAdminCommandCompleteMessage(message), PacketBuilder.CHAT_BOTTOM_LEFT); - user.LoggedinClient.SendPacket(chatPacket); - - return true; - } - - public static bool Version(string message, string[] args, User user) - { - // Get current version and send to client - byte[] versionPacket = PacketBuilder.CreateChat(ServerVersion.GetBuildString(), PacketBuilder.CHAT_BOTTOM_LEFT); + swfUser = args[1]; + + byte[] packetBytes = PacketBuilder.CreateSwfModulePacket(swfName, PacketBuilder.PACKET_SWF_MODULE_FORCE); + if (swfUser.ToUpper() == "ALL") + { + foreach (GameClient client in GameClient.ConnectedClients) + { + if (client.LoggedIn) + client.SendPacket(packetBytes); + } + } + else + { + User player = findNamePartial(swfUser); + player.LoggedinClient.SendPacket(packetBytes); + } + } + catch (Exception) + { + return false; + } + + byte[] chatPacket = PacketBuilder.CreateChat(Messages.FormatAdminCommandCompleteMessage(message), PacketBuilder.CHAT_BOTTOM_LEFT); + user.LoggedinClient.SendPacket(chatPacket); + + return true; + } + + public static bool UnBan(string message, string[] args, User user) + { + if(args.Length <= 0) + return false; + if(!user.Administrator && !user.Moderator) + return false; + + try{ + string userName = args[0]; + int id = Database.GetUserid(userName); + Database.UnBanUser(id); + } + catch(Exception e) + { + Logger.ErrorPrint(e.Message); + return false; + } + + byte[] chatPacket = PacketBuilder.CreateChat(Messages.FormatAdminCommandCompleteMessage(message), PacketBuilder.CHAT_BOTTOM_LEFT); + user.LoggedinClient.SendPacket(chatPacket); + + return true; + } + + public static bool Version(string message, string[] args, User user) + { + // Get current version and send to client + byte[] versionPacket = PacketBuilder.CreateChat(ServerVersion.GetBuildString(), PacketBuilder.CHAT_BOTTOM_LEFT); user.LoggedinClient.SendPacket(versionPacket); - byte[] chatPacket = PacketBuilder.CreateChat(Messages.FormatPlayerCommandCompleteMessage(message), PacketBuilder.CHAT_BOTTOM_LEFT); - user.LoggedinClient.SendPacket(chatPacket); - return true; - } - public static bool Ban(string message, string[] args, User user) - { - if (args.Length <= 0) - return false; - if (!user.Administrator && !user.Moderator) - return false; - try - { - string userName = args[0]; - int id = Database.GetUserid(userName); - string ip = Database.GetIpAddress(id); - string reason = "NONE SPECIFIED"; - if (args.Length >= 2) - { - reason = string.Join(" ", args, 1, args.Length - 1); - } - - Database.BanUser(id, ip, reason); - } - catch(Exception) - { - return false; - } - try{ - User bannedUser = GameServer.GetUserByName(args[0]); - bannedUser.LoggedinClient.Kick(Messages.KickReasonBanned); - } - catch(KeyNotFoundException){}; - - byte[] chatPacket = PacketBuilder.CreateChat(Messages.FormatAdminCommandCompleteMessage(message), PacketBuilder.CHAT_BOTTOM_LEFT); - user.LoggedinClient.SendPacket(chatPacket); - - return true; - } - public static bool Escape(string message, string[] args, User user) - { - if (!user.Administrator && !user.Moderator) - return false; - - user.Teleport(Map.ModIsleX, Map.ModIsleY); - - byte[] chatPacket = PacketBuilder.CreateChat(Messages.FormatAdminCommandCompleteMessage(message) + Messages.ModIsleMessage, PacketBuilder.CHAT_BOTTOM_LEFT); - user.LoggedinClient.SendPacket(chatPacket); - return true; - } - - public static bool Stealth(string message, string[] args, User user) - { - if (!user.Administrator && !user.Moderator) - return false; - - user.Stealth = !user.Stealth; - byte[] chatPacket = PacketBuilder.CreateChat(Messages.FormatAdminCommandCompleteMessage(message), PacketBuilder.CHAT_BOTTOM_LEFT); - user.LoggedinClient.SendPacket(chatPacket); - return true; - } - public static bool NoClip(string message, string[] args, User user) - { - if (!user.Administrator) - return false; - - user.NoClip = !user.NoClip; - byte[] chatPacket = PacketBuilder.CreateChat(Messages.FormatAdminCommandCompleteMessage(message), PacketBuilder.CHAT_BOTTOM_LEFT); - user.LoggedinClient.SendPacket(chatPacket); - return true; - } - - public static bool Rules(string message, string[] args, User user) - { - if (!user.Administrator && !user.Moderator) - return false; - - if (args.Length <= 0) - return false; - - try - { - User toSend = GameServer.GetUserByName(args[0]); - - toSend.Teleport(Map.RulesIsleX, Map.RulesIsleY); - byte[] studyTheRulesMsg = PacketBuilder.CreateChat(Messages.RulesIsleSentMessage, PacketBuilder.CHAT_BOTTOM_RIGHT); - toSend.LoggedinClient.SendPacket(studyTheRulesMsg); - } - catch (KeyNotFoundException) - { - return false; - } - - byte[] chatPacket = PacketBuilder.CreateChat(Messages.FormatAdminCommandCompleteMessage(message)+Messages.FormatRulesCommandMessage(args[0]), PacketBuilder.CHAT_BOTTOM_LEFT); - user.LoggedinClient.SendPacket(chatPacket); - return true; - } - - public static bool Prison(string message, string[] args, User user) - { - if (!user.Administrator && !user.Moderator) - return false; - - if (args.Length <= 0) - return false; - - try - { - User toSend = GameServer.GetUserByName(args[0]); - - toSend.Teleport(Map.PrisonIsleX, Map.PrisonIsleY); - byte[] dontDoTheTime = PacketBuilder.CreateChat(Messages.PrisonIsleSentMessage, PacketBuilder.CHAT_BOTTOM_RIGHT); - toSend.LoggedinClient.SendPacket(dontDoTheTime); - } - catch (KeyNotFoundException) - { - return false; - } - - byte[] chatPacket = PacketBuilder.CreateChat(Messages.FormatAdminCommandCompleteMessage(message) + Messages.FormatPrisonCommandMessage(args[0]), PacketBuilder.CHAT_BOTTOM_LEFT); - user.LoggedinClient.SendPacket(chatPacket); - return true; - - } - public static bool Kick(string message, string[] args, User user) - { - if (!user.Administrator && !user.Moderator) - return false; - - if (args.Length <= 0) - return false; - - try - { - User toKick = GameServer.GetUserByName(args[0]); - - if (args.Length >= 2) - { - string reason = string.Join(" ", args, 1, args.Length - 1); - toKick.LoggedinClient.Kick(reason); - } - else - { - toKick.LoggedinClient.Kick(Messages.KickReasonKicked); - } - } - catch (KeyNotFoundException) - { - return false; - } - - byte[] chatPacket = PacketBuilder.CreateChat(Messages.FormatAdminCommandCompleteMessage(message), PacketBuilder.CHAT_BOTTOM_LEFT); - user.LoggedinClient.SendPacket(chatPacket); - return true; - } - - public static bool Jump(string message, string[] args, User user) - { - if (args.Length <= 2) - return false; - if (!user.Administrator) - return false; - - - try - { - User tp = findNamePartial(args[0]); - if (args[1].ToUpper() == "HERE") - tp.Teleport(user.X, user.Y); - } - catch (KeyNotFoundException) - { - return false; - } - - byte[] chatPacket = PacketBuilder.CreateChat(Messages.FormatAdminCommandCompleteMessage(message), PacketBuilder.CHAT_BOTTOM_LEFT); - user.LoggedinClient.SendPacket(chatPacket); - return true; - } - - public static bool DelItem(string message, string[] args, User user) - { - if (args.Length <= 0) - return false; - if (!user.Administrator) - return false; - - int itemId = 0; - try - { - itemId = int.Parse(args[0]); - User target = user; - if (args.Length > 1) - target = findNamePartial(args[1]); - - if (target.Inventory.HasItemId(itemId)) - { - InventoryItem itm = target.Inventory.GetItemByItemId(itemId); - - foreach (ItemInstance instance in itm.ItemInstances) - { - target.Inventory.Remove(instance); - } - } - } - catch (Exception) - { - return false; - } - - byte[] chatPacket = PacketBuilder.CreateChat(Messages.FormatAdminCommandCompleteMessage(message), PacketBuilder.CHAT_BOTTOM_LEFT); - user.LoggedinClient.SendPacket(chatPacket); - - return true; - } - public static bool Goto(string message, string[] args, User user) - { - if (args.Length <= 0) - return false; - if (!user.Administrator) - return false; - if(args[0].ToUpper() == "PLAYER") - { - if(args.Length < 2) - return false; - try - { - User tpTo = findNamePartial(args[1]); - user.Teleport(tpTo.X, tpTo.Y); - } - catch (KeyNotFoundException) - { - return false; - } - } - else if(args[0].ToUpper() == "AREA") - { - if (args.Length < 2) - return false; - - try - { - string area = string.Join(" ", args, 1, args.Length - 1); - bool teleported = false; - foreach(World.Waypoint waypnt in World.Waypoints) - { - if(waypnt.Name.ToLower().StartsWith(area.ToLower())) - { - user.Teleport(waypnt.PosX, waypnt.PosY); - teleported = true; - break; - } - } - if(!teleported) - return false; - } - catch(Exception) - { - return false; - } - } - else if(args[0].ToUpper() == "NPC") - { - if (args.Length < 2) - return false; - - try - { - string npcName = string.Join(" ", args, 1, args.Length - 1); - bool teleported = false; - foreach (Npc.NpcEntry npc in Npc.NpcList) - { - if (npc.Name.ToLower().StartsWith(npcName.ToLower())) - { - user.Teleport(npc.X, npc.Y); - teleported = true; - break; - } - } - if (!teleported) - return false; - } - catch (Exception) - { - return false; - } - } - else if(args[0].Contains(",")) - { - try - { - string[] xy = args[0].Split(','); - int x = int.Parse(xy[0]); - int y = int.Parse(xy[1]); - user.Teleport(x, y); - } - catch(FormatException) - { - return false; - } - } - else - { - return false; - } - - - - byte[] chatPacket = PacketBuilder.CreateChat(Messages.FormatAdminCommandCompleteMessage(message), PacketBuilder.CHAT_BOTTOM_LEFT); - user.LoggedinClient.SendPacket(chatPacket); - - return true; - } - - public static bool ModHorse(string message, string[] args, User user) - { - if (!user.Administrator) - return false; - - if (args.Length < 3) - return false; - - - int id = 0; - int amount = 0; - try - { - id = int.Parse(args[0]); - if(args[1].ToUpper() != "COLOR") - amount = int.Parse(args[2]); - } - catch (Exception) - { - return false; - } - - - int i = 0; - foreach (HorseInfo.Category category in HorseInfo.HorseCategories) - { - HorseInstance[] horsesInCategory = user.HorseInventory.GetHorsesInCategory(category).OrderBy(o => o.Name).ToArray(); - if (horsesInCategory.Length > 0) - { - foreach (HorseInstance instance in horsesInCategory) - { - i++; - - if(i == id) - { - switch (args[1].ToUpper()) - { - case "INTELLIGENCE": - instance.AdvancedStats.Inteligence = amount; - break; - case "PERSONALITY": - instance.AdvancedStats.Personality = amount; - break; - case "HEIGHT": - instance.AdvancedStats.Height = amount; - break; - case "COLOR": - instance.Color = args[2].ToLower(); - break; - case "EXPERIENCE": - instance.BasicStats.Experience = amount; - break; - case "SPEED": - instance.AdvancedStats.Speed = amount; - break; - case "STRENGTH": - instance.AdvancedStats.Strength = amount; - break; - case "CONFORMATION": - instance.AdvancedStats.Conformation = amount; - break; - case "ENDURANCE": - instance.AdvancedStats.Endurance = amount; - break; - case "AGILITY": - instance.AdvancedStats.Agility = amount; - break; - } - } - } - } - } - - - byte[] chatPacket = PacketBuilder.CreateChat(Messages.FormatAdminCommandCompleteMessage(message), PacketBuilder.CHAT_BOTTOM_LEFT); - user.LoggedinClient.SendPacket(chatPacket); - return true; - } - - public static bool Warp(string message, string[] args, User user) - { - - string formattedmessage = Messages.FormatPlayerCommandCompleteMessage(message); - - if (user.CurrentlyRidingHorse == null) - goto onlyRiddenUnicorn; - - if (user.CurrentlyRidingHorse.Breed.Type == "unicorn") - goto doCommand; - - goto onlyRiddenUnicorn; - - onlyRiddenUnicorn:; - formattedmessage = Messages.OnlyUnicornCanWarp; - goto sendText; - - - cantUnderstandCommand:; - formattedmessage += Messages.FailedToUnderstandLocation; - goto sendText; - - - doCommand:; - - string areaName = string.Join(" ", args).ToLower(); - areaName = areaName.Trim(); - if (args.Length <= 0) - areaName = "horse isle"; - try - { - User tp = GameServer.GetUserByName(areaName); - - user.Teleport(tp.X, tp.Y); - formattedmessage += Messages.SuccessfullyWarpedToPlayer; - goto playSwf; - - } - catch (KeyNotFoundException) - { - foreach (World.Waypoint waypoint in World.Waypoints) - { - if (waypoint.Name.ToLower().StartsWith(areaName)) - { - user.Teleport(waypoint.PosX, waypoint.PosY); - formattedmessage += Messages.SuccessfullyWarpedToLocation; - goto playSwf; - } - } - - goto cantUnderstandCommand; - } - - playSwf:; - byte[] swfPacket = PacketBuilder.CreateSwfModulePacket("warpcutscene", PacketBuilder.PACKET_SWF_CUTSCENE); - user.LoggedinClient.SendPacket(swfPacket); - - - sendText:; - byte[] chatPacket = PacketBuilder.CreateChat(formattedmessage, PacketBuilder.CHAT_BOTTOM_LEFT); - user.LoggedinClient.SendPacket(chatPacket); - - return true; - } - - public static bool CallHorse(string message, string[] args, User user) - { - if (!user.Administrator) - return false; - - if (args.Length <= 0) - return false; - string formattedmessage = ""; + byte[] chatPacket = PacketBuilder.CreateChat(Messages.FormatPlayerCommandCompleteMessage(message), PacketBuilder.CHAT_BOTTOM_LEFT); + user.LoggedinClient.SendPacket(chatPacket); + return true; + } + public static bool Ban(string message, string[] args, User user) + { + if (args.Length <= 0) + return false; + if (!user.Administrator && !user.Moderator) + return false; + try + { + string userName = args[0]; + int id = Database.GetUserid(userName); + string ip = Database.GetIpAddress(id); + string reason = "NONE SPECIFIED"; + if (args.Length >= 2) + { + reason = string.Join(" ", args, 1, args.Length - 1); + } + + Database.BanUser(id, ip, reason); + } + catch(Exception) + { + return false; + } + try{ + User bannedUser = GameServer.GetUserByName(args[0]); + bannedUser.LoggedinClient.Kick(Messages.KickReasonBanned); + } + catch(KeyNotFoundException){}; + + byte[] chatPacket = PacketBuilder.CreateChat(Messages.FormatAdminCommandCompleteMessage(message), PacketBuilder.CHAT_BOTTOM_LEFT); + user.LoggedinClient.SendPacket(chatPacket); + + return true; + } + public static bool Escape(string message, string[] args, User user) + { + if (!user.Administrator && !user.Moderator) + return false; + + user.Teleport(Map.ModIsleX, Map.ModIsleY); + + byte[] chatPacket = PacketBuilder.CreateChat(Messages.FormatAdminCommandCompleteMessage(message) + Messages.ModIsleMessage, PacketBuilder.CHAT_BOTTOM_LEFT); + user.LoggedinClient.SendPacket(chatPacket); + return true; + } + + public static bool Stealth(string message, string[] args, User user) + { + if (!user.Administrator && !user.Moderator) + return false; + + user.Stealth = !user.Stealth; + byte[] chatPacket = PacketBuilder.CreateChat(Messages.FormatAdminCommandCompleteMessage(message), PacketBuilder.CHAT_BOTTOM_LEFT); + user.LoggedinClient.SendPacket(chatPacket); + return true; + } + public static bool NoClip(string message, string[] args, User user) + { + if (!user.Administrator) + return false; + + user.NoClip = !user.NoClip; + byte[] chatPacket = PacketBuilder.CreateChat(Messages.FormatAdminCommandCompleteMessage(message), PacketBuilder.CHAT_BOTTOM_LEFT); + user.LoggedinClient.SendPacket(chatPacket); + return true; + } + + public static bool Rules(string message, string[] args, User user) + { + if (!user.Administrator && !user.Moderator) + return false; + + if (args.Length <= 0) + return false; + + try + { + User toSend = GameServer.GetUserByName(args[0]); + + toSend.Teleport(Map.RulesIsleX, Map.RulesIsleY); + byte[] studyTheRulesMsg = PacketBuilder.CreateChat(Messages.RulesIsleSentMessage, PacketBuilder.CHAT_BOTTOM_RIGHT); + toSend.LoggedinClient.SendPacket(studyTheRulesMsg); + } + catch (KeyNotFoundException) + { + return false; + } + + byte[] chatPacket = PacketBuilder.CreateChat(Messages.FormatAdminCommandCompleteMessage(message)+Messages.FormatRulesCommandMessage(args[0]), PacketBuilder.CHAT_BOTTOM_LEFT); + user.LoggedinClient.SendPacket(chatPacket); + return true; + } + + public static bool Prison(string message, string[] args, User user) + { + if (!user.Administrator && !user.Moderator) + return false; + + if (args.Length <= 0) + return false; + + try + { + User toSend = GameServer.GetUserByName(args[0]); + + toSend.Teleport(Map.PrisonIsleX, Map.PrisonIsleY); + byte[] dontDoTheTime = PacketBuilder.CreateChat(Messages.PrisonIsleSentMessage, PacketBuilder.CHAT_BOTTOM_RIGHT); + toSend.LoggedinClient.SendPacket(dontDoTheTime); + } + catch (KeyNotFoundException) + { + return false; + } + + byte[] chatPacket = PacketBuilder.CreateChat(Messages.FormatAdminCommandCompleteMessage(message) + Messages.FormatPrisonCommandMessage(args[0]), PacketBuilder.CHAT_BOTTOM_LEFT); + user.LoggedinClient.SendPacket(chatPacket); + return true; + + } + public static bool Kick(string message, string[] args, User user) + { + if (!user.Administrator && !user.Moderator) + return false; + + if (args.Length <= 0) + return false; + + try + { + User toKick = GameServer.GetUserByName(args[0]); + + if (args.Length >= 2) + { + string reason = string.Join(" ", args, 1, args.Length - 1); + toKick.LoggedinClient.Kick(reason); + } + else + { + toKick.LoggedinClient.Kick(Messages.KickReasonKicked); + } + } + catch (KeyNotFoundException) + { + return false; + } + + byte[] chatPacket = PacketBuilder.CreateChat(Messages.FormatAdminCommandCompleteMessage(message), PacketBuilder.CHAT_BOTTOM_LEFT); + user.LoggedinClient.SendPacket(chatPacket); + return true; + } + + public static bool Jump(string message, string[] args, User user) + { + if (args.Length <= 2) + return false; + if (!user.Administrator) + return false; + + + try + { + User tp = findNamePartial(args[0]); + if (args[1].ToUpper() == "HERE") + tp.Teleport(user.X, user.Y); + } + catch (KeyNotFoundException) + { + return false; + } + + byte[] chatPacket = PacketBuilder.CreateChat(Messages.FormatAdminCommandCompleteMessage(message), PacketBuilder.CHAT_BOTTOM_LEFT); + user.LoggedinClient.SendPacket(chatPacket); + return true; + } + + public static bool DelItem(string message, string[] args, User user) + { + if (args.Length <= 0) + return false; + if (!user.Administrator) + return false; + + int itemId = 0; + try + { + itemId = int.Parse(args[0]); + User target = user; + if (args.Length > 1) + target = findNamePartial(args[1]); + + if (target.Inventory.HasItemId(itemId)) + { + InventoryItem itm = target.Inventory.GetItemByItemId(itemId); + + foreach (ItemInstance instance in itm.ItemInstances) + { + target.Inventory.Remove(instance); + } + } + } + catch (Exception) + { + return false; + } + + byte[] chatPacket = PacketBuilder.CreateChat(Messages.FormatAdminCommandCompleteMessage(message), PacketBuilder.CHAT_BOTTOM_LEFT); + user.LoggedinClient.SendPacket(chatPacket); + + return true; + } + public static bool Goto(string message, string[] args, User user) + { + if (args.Length <= 0) + return false; + if (!user.Administrator) + return false; + if(args[0].ToUpper() == "PLAYER") + { + if(args.Length < 2) + return false; + try + { + User tpTo = findNamePartial(args[1]); + user.Teleport(tpTo.X, tpTo.Y); + } + catch (KeyNotFoundException) + { + return false; + } + } + else if(args[0].ToUpper() == "AREA") + { + if (args.Length < 2) + return false; + + try + { + string area = string.Join(" ", args, 1, args.Length - 1); + bool teleported = false; + foreach(World.Waypoint waypnt in World.Waypoints) + { + if(waypnt.Name.ToLower().StartsWith(area.ToLower())) + { + user.Teleport(waypnt.PosX, waypnt.PosY); + teleported = true; + break; + } + } + if(!teleported) + return false; + } + catch(Exception) + { + return false; + } + } + else if(args[0].ToUpper() == "NPC") + { + if (args.Length < 2) + return false; + + try + { + string npcName = string.Join(" ", args, 1, args.Length - 1); + bool teleported = false; + foreach (Npc.NpcEntry npc in Npc.NpcList) + { + if (npc.Name.ToLower().StartsWith(npcName.ToLower())) + { + user.Teleport(npc.X, npc.Y); + teleported = true; + break; + } + } + if (!teleported) + return false; + } + catch (Exception) + { + return false; + } + } + else if(args[0].Contains(",")) + { + try + { + string[] xy = args[0].Split(','); + int x = int.Parse(xy[0]); + int y = int.Parse(xy[1]); + user.Teleport(x, y); + } + catch(FormatException) + { + return false; + } + } + else + { + return false; + } + + + + byte[] chatPacket = PacketBuilder.CreateChat(Messages.FormatAdminCommandCompleteMessage(message), PacketBuilder.CHAT_BOTTOM_LEFT); + user.LoggedinClient.SendPacket(chatPacket); + + return true; + } + + public static bool ModHorse(string message, string[] args, User user) + { + if (!user.Administrator) + return false; + + if (args.Length < 3) + return false; + + + int id = 0; + int amount = 0; + try + { + id = int.Parse(args[0]); + if(args[1].ToUpper() != "COLOR") + amount = int.Parse(args[2]); + } + catch (Exception) + { + return false; + } + + + int i = 0; + foreach (HorseInfo.Category category in HorseInfo.HorseCategories) + { + HorseInstance[] horsesInCategory = user.HorseInventory.GetHorsesInCategory(category).OrderBy(o => o.Name).ToArray(); + if (horsesInCategory.Length > 0) + { + foreach (HorseInstance instance in horsesInCategory) + { + i++; + + if(i == id) + { + switch (args[1].ToUpper()) + { + case "INTELLIGENCE": + instance.AdvancedStats.Inteligence = amount; + break; + case "PERSONALITY": + instance.AdvancedStats.Personality = amount; + break; + case "HEIGHT": + instance.AdvancedStats.Height = amount; + break; + case "COLOR": + instance.Color = args[2].ToLower(); + break; + case "EXPERIENCE": + instance.BasicStats.Experience = amount; + break; + case "SPEED": + instance.AdvancedStats.Speed = amount; + break; + case "STRENGTH": + instance.AdvancedStats.Strength = amount; + break; + case "CONFORMATION": + instance.AdvancedStats.Conformation = amount; + break; + case "ENDURANCE": + instance.AdvancedStats.Endurance = amount; + break; + case "AGILITY": + instance.AdvancedStats.Agility = amount; + break; + } + } + } + } + } + + + byte[] chatPacket = PacketBuilder.CreateChat(Messages.FormatAdminCommandCompleteMessage(message), PacketBuilder.CHAT_BOTTOM_LEFT); + user.LoggedinClient.SendPacket(chatPacket); + return true; + } + + public static bool Warp(string message, string[] args, User user) + { + + string formattedmessage = Messages.FormatPlayerCommandCompleteMessage(message); + + if (user.CurrentlyRidingHorse == null) + goto onlyRiddenUnicorn; + + if (user.CurrentlyRidingHorse.Breed.Type == "unicorn") + goto doCommand; + + goto onlyRiddenUnicorn; + + onlyRiddenUnicorn:; + formattedmessage = Messages.OnlyUnicornCanWarp; + goto sendText; + + + cantUnderstandCommand:; + formattedmessage += Messages.FailedToUnderstandLocation; + goto sendText; + + + doCommand:; + + string areaName = string.Join(" ", args).ToLower(); + areaName = areaName.Trim(); + if (args.Length <= 0) + areaName = "horse isle"; + try + { + User tp = GameServer.GetUserByName(areaName); + + user.Teleport(tp.X, tp.Y); + formattedmessage += Messages.SuccessfullyWarpedToPlayer; + goto playSwf; + + } + catch (KeyNotFoundException) + { + foreach (World.Waypoint waypoint in World.Waypoints) + { + if (waypoint.Name.ToLower().StartsWith(areaName)) + { + user.Teleport(waypoint.PosX, waypoint.PosY); + formattedmessage += Messages.SuccessfullyWarpedToLocation; + goto playSwf; + } + } + + goto cantUnderstandCommand; + } + + playSwf:; + byte[] swfPacket = PacketBuilder.CreateSwfModulePacket("warpcutscene", PacketBuilder.PACKET_SWF_CUTSCENE); + user.LoggedinClient.SendPacket(swfPacket); + + + sendText:; + byte[] chatPacket = PacketBuilder.CreateChat(formattedmessage, PacketBuilder.CHAT_BOTTOM_LEFT); + user.LoggedinClient.SendPacket(chatPacket); + + return true; + } + + public static bool CallHorse(string message, string[] args, User user) + { + if (!user.Administrator) + return false; + + if (args.Length <= 0) + return false; + string formattedmessage = ""; try { if (args[0].ToUpper() != "HORSE") @@ -801,109 +801,109 @@ namespace HISP.Game.Chat catch (Exception) { return false; - } - - - byte[] chatPacket = PacketBuilder.CreateChat(formattedmessage, PacketBuilder.CHAT_BOTTOM_LEFT); - user.LoggedinClient.SendPacket(chatPacket); - return true; - - } - - public static bool AutoReply(string message, string[] args, User user) - { - string replyMessage = string.Join(" ", args); - string formattedmessage = Messages.FormatPlayerCommandCompleteMessage(message); - replyMessage = replyMessage.Trim(); - - if (replyMessage.Length > 1024) - { - byte[] tooLong = PacketBuilder.CreateChat(Messages.AutoReplyTooLong, PacketBuilder.CHAT_BOTTOM_RIGHT); - user.LoggedinClient.SendPacket(tooLong); - - return false; - } - - Object violationReason = Chat.FilterMessage(replyMessage); - if (violationReason != null) - { - byte[] hasVios = PacketBuilder.CreateChat(Messages.AutoReplyHasViolations, PacketBuilder.CHAT_BOTTOM_RIGHT); - user.LoggedinClient.SendPacket(hasVios); - - return false; - } - - user.AutoReplyText = replyMessage; - - byte[] chatPacket = PacketBuilder.CreateChat(formattedmessage, PacketBuilder.CHAT_BOTTOM_LEFT); - user.LoggedinClient.SendPacket(chatPacket); - return true; - } - public static bool Dance(string message, string[] args, User user) - { - string moves = string.Join(" ", args).ToLower(); - string formattedmessage = Messages.FormatPlayerCommandCompleteMessage(message); - - if (user.ActiveDance != null) - user.ActiveDance.Dispose(); - - user.ActiveDance = new Dance(user, moves); - - byte[] chatPacket = PacketBuilder.CreateChat(formattedmessage, PacketBuilder.CHAT_BOTTOM_LEFT); - user.LoggedinClient.SendPacket(chatPacket); - return true; - - } - - public static bool Quiz(string message, string[] args, User user) - { - bool quizActive = (GameServer.QuizEvent != null); - if(user.InRealTimeQuiz) - { - byte[] cantEnterRealTimeQuiz = PacketBuilder.CreateChat(Messages.EventAlreadyEnteredRealTimeQuiz, PacketBuilder.CHAT_BOTTOM_RIGHT); - user.LoggedinClient.SendPacket(cantEnterRealTimeQuiz); - return false; - } - if (quizActive) - { - string formattedmessage = Messages.FormatPlayerCommandCompleteMessage(message); - - RealTimeQuiz.Participent participent = GameServer.QuizEvent.JoinEvent(user); - - if(participent.Quit) - { - byte[] quizQuit = PacketBuilder.CreateChat(Messages.EventQuitRealTimeQuiz, PacketBuilder.CHAT_BOTTOM_RIGHT); - user.LoggedinClient.SendPacket(quizQuit); - - return false; - } - - participent.UpdateParticipent(); - byte[] enteredRealTimeQuiz = PacketBuilder.CreateChat(Messages.EventEnteredRealTimeQuiz, PacketBuilder.CHAT_BOTTOM_RIGHT); - user.LoggedinClient.SendPacket(enteredRealTimeQuiz); - - byte[] chatPacket = PacketBuilder.CreateChat(formattedmessage, PacketBuilder.CHAT_BOTTOM_LEFT); - user.LoggedinClient.SendPacket(chatPacket); - return true; - - } - else - { - byte[] quizUnavailable = PacketBuilder.CreateChat(Messages.EventUnavailableRealTimeQuiz, PacketBuilder.CHAT_BOTTOM_RIGHT); - user.LoggedinClient.SendPacket(quizUnavailable); - return false; - } - - } - - public static bool Mute(string message, string[] args, User user) - { - string formattedmessage = Messages.FormatPlayerCommandCompleteMessage(message); - - if (args.Length <= 0) - { - formattedmessage += Messages.MuteHelp; - } + } + + + byte[] chatPacket = PacketBuilder.CreateChat(formattedmessage, PacketBuilder.CHAT_BOTTOM_LEFT); + user.LoggedinClient.SendPacket(chatPacket); + return true; + + } + + public static bool AutoReply(string message, string[] args, User user) + { + string replyMessage = string.Join(" ", args); + string formattedmessage = Messages.FormatPlayerCommandCompleteMessage(message); + replyMessage = replyMessage.Trim(); + + if (replyMessage.Length > 1024) + { + byte[] tooLong = PacketBuilder.CreateChat(Messages.AutoReplyTooLong, PacketBuilder.CHAT_BOTTOM_RIGHT); + user.LoggedinClient.SendPacket(tooLong); + + return false; + } + + Object violationReason = Chat.FilterMessage(replyMessage); + if (violationReason != null) + { + byte[] hasVios = PacketBuilder.CreateChat(Messages.AutoReplyHasViolations, PacketBuilder.CHAT_BOTTOM_RIGHT); + user.LoggedinClient.SendPacket(hasVios); + + return false; + } + + user.AutoReplyText = replyMessage; + + byte[] chatPacket = PacketBuilder.CreateChat(formattedmessage, PacketBuilder.CHAT_BOTTOM_LEFT); + user.LoggedinClient.SendPacket(chatPacket); + return true; + } + public static bool Dance(string message, string[] args, User user) + { + string moves = string.Join(" ", args).ToLower(); + string formattedmessage = Messages.FormatPlayerCommandCompleteMessage(message); + + if (user.ActiveDance != null) + user.ActiveDance.Dispose(); + + user.ActiveDance = new Dance(user, moves); + + byte[] chatPacket = PacketBuilder.CreateChat(formattedmessage, PacketBuilder.CHAT_BOTTOM_LEFT); + user.LoggedinClient.SendPacket(chatPacket); + return true; + + } + + public static bool Quiz(string message, string[] args, User user) + { + bool quizActive = (GameServer.QuizEvent != null); + if(user.InRealTimeQuiz) + { + byte[] cantEnterRealTimeQuiz = PacketBuilder.CreateChat(Messages.EventAlreadyEnteredRealTimeQuiz, PacketBuilder.CHAT_BOTTOM_RIGHT); + user.LoggedinClient.SendPacket(cantEnterRealTimeQuiz); + return false; + } + if (quizActive) + { + string formattedmessage = Messages.FormatPlayerCommandCompleteMessage(message); + + RealTimeQuiz.Participent participent = GameServer.QuizEvent.JoinEvent(user); + + if(participent.Quit) + { + byte[] quizQuit = PacketBuilder.CreateChat(Messages.EventQuitRealTimeQuiz, PacketBuilder.CHAT_BOTTOM_RIGHT); + user.LoggedinClient.SendPacket(quizQuit); + + return false; + } + + participent.UpdateParticipent(); + byte[] enteredRealTimeQuiz = PacketBuilder.CreateChat(Messages.EventEnteredRealTimeQuiz, PacketBuilder.CHAT_BOTTOM_RIGHT); + user.LoggedinClient.SendPacket(enteredRealTimeQuiz); + + byte[] chatPacket = PacketBuilder.CreateChat(formattedmessage, PacketBuilder.CHAT_BOTTOM_LEFT); + user.LoggedinClient.SendPacket(chatPacket); + return true; + + } + else + { + byte[] quizUnavailable = PacketBuilder.CreateChat(Messages.EventUnavailableRealTimeQuiz, PacketBuilder.CHAT_BOTTOM_RIGHT); + user.LoggedinClient.SendPacket(quizUnavailable); + return false; + } + + } + + public static bool Mute(string message, string[] args, User user) + { + string formattedmessage = Messages.FormatPlayerCommandCompleteMessage(message); + + if (args.Length <= 0) + { + formattedmessage += Messages.MuteHelp; + } else { @@ -966,22 +966,22 @@ namespace HISP.Game.Chat { formattedmessage += Messages.MuteHelp; } - } - - byte[] chatPacket = PacketBuilder.CreateChat(formattedmessage, PacketBuilder.CHAT_BOTTOM_LEFT); - user.LoggedinClient.SendPacket(chatPacket); - - return true; - } - - public static bool UnMute(string message, string[] args, User user) - { - string formattedmessage = Messages.FormatPlayerCommandCompleteMessage(message); - - if (args.Length <= 0) - { - formattedmessage += Messages.UnMuteHelp; - } + } + + byte[] chatPacket = PacketBuilder.CreateChat(formattedmessage, PacketBuilder.CHAT_BOTTOM_LEFT); + user.LoggedinClient.SendPacket(chatPacket); + + return true; + } + + public static bool UnMute(string message, string[] args, User user) + { + string formattedmessage = Messages.FormatPlayerCommandCompleteMessage(message); + + if (args.Length <= 0) + { + formattedmessage += Messages.UnMuteHelp; + } else { string muteType = args[0]; @@ -1043,13 +1043,13 @@ namespace HISP.Game.Chat { formattedmessage += Messages.UnMuteHelp; } - } - - - byte[] chatPacket = PacketBuilder.CreateChat(formattedmessage, PacketBuilder.CHAT_BOTTOM_LEFT); - user.LoggedinClient.SendPacket(chatPacket); - - return true; - } - } -} + } + + + byte[] chatPacket = PacketBuilder.CreateChat(formattedmessage, PacketBuilder.CHAT_BOTTOM_LEFT); + user.LoggedinClient.SendPacket(chatPacket); + + return true; + } + } +} diff --git a/HorseIsleServer/LibHISP/Properties/AssemblyInfo.cs b/HorseIsleServer/LibHISP/Properties/AssemblyInfo.cs index 51a53f4..95bbc15 100644 --- a/HorseIsleServer/LibHISP/Properties/AssemblyInfo.cs +++ b/HorseIsleServer/LibHISP/Properties/AssemblyInfo.cs @@ -30,5 +30,5 @@ using System.Runtime.InteropServices; // // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: -[assembly: AssemblyVersion("1.7.11.0")] -[assembly: AssemblyFileVersion("1.7.11.0")] +[assembly: AssemblyVersion("1.7.20.0")] +[assembly: AssemblyFileVersion("1.7.20.0")] diff --git a/HorseIsleServer/LibHISP/Server/DataFixerUpper.cs b/HorseIsleServer/LibHISP/Server/DataFixerUpper.cs new file mode 100644 index 0000000..c2d73a3 --- /dev/null +++ b/HorseIsleServer/LibHISP/Server/DataFixerUpper.cs @@ -0,0 +1,63 @@ +using System; + +namespace HISP.Server +{ + static class DataFixerUpper + { + private static void fixupVersion1_0() + { + // Add total logins column to UserExt + Database.TryExecuteSqlQuery("ALTER TABLE UserExt ADD COLUMN TotalLogins INT;"); + Database.TryExecuteSqlQuery("UPDATE UserExt SET TotalLogins=0;"); + + // Add New column to OnlineUsers. + Database.TryExecuteSqlQuery("ALTER TABLE OnlineUsers ADD COLUMN New TEXT(3);"); + Database.TryExecuteSqlQuery("UPDATE OnlineUsers SET New=\"NO\";"); + + // Alter sizes + Database.TryExecuteSqlQuery("ALTER TABLE UserExt CHANGE COLUMN ProfilePage ProfilePage TEXT(4000);"); + Database.TryExecuteSqlQuery("ALTER TABLE UserExt CHANGE COLUMN PrivateNotes PrivateNotes TEXT(65535);"); + Database.TryExecuteSqlQuery("ALTER TABLE MailBox CHANGE COLUMN Subject Subject TEXT(100);"); + Database.TryExecuteSqlQuery("ALTER TABLE MailBox CHANGE COLUMN Message Message TEXT(65535);"); + Database.TryExecuteSqlQuery("ALTER TABLE Horses CHANGE COLUMN description description TEXT(4000);"); + Database.TryExecuteSqlQuery("ALTER TABLE WildHorse CHANGE COLUMN description description TEXT(4000);"); + Database.TryExecuteSqlQuery("ALTER TABLE Ranches CHANGE COLUMN title title TEXT(50);"); + Database.TryExecuteSqlQuery("ALTER TABLE Ranches CHANGE COLUMN description description TEXT(250);"); + } + + private static void fixupVersion1_1() + { + // Add data column to shop to ShopInventory + Database.TryExecuteSqlQuery("ALTER TABLE ShopInventory ADD COLUMN Data INT;"); + Database.TryExecuteSqlQuery("UPDATE ShopInventory SET Data=0;"); + } + + private static void fixupVersion1_7_20() + { + // Add LastLoadedInVersion column to World. + Database.TryExecuteSqlQuery("ALTER TABLE World ADD COLUMN LastLoadedInVersion TEXT(64)"); + Database.TryExecuteSqlQuery("UPDATE World SET LastLoadedInVersion=\"v1.7.20\";"); + } + + + public static void FixUpDb() + { + string lastVersionStr = Database.GetLastLoadedVersion(); + string currentVersionStr = ServerVersion.GetVersionString(); + + int lastVersion = Convert.ToInt32(Int32.Parse(lastVersionStr.ToLower().Replace("v", "").Replace(".", ""))); + int currentVersion = Convert.ToInt32(Int32.Parse(currentVersionStr.ToLower().Replace("v", "").Replace(".", ""))); + + if(currentVersion > lastVersion) + { + Logger.WarnPrint("Migrating Database from " + lastVersionStr + " to " + currentVersionStr); + + if (lastVersion <= 10) fixupVersion1_0(); + if (lastVersion <= 11) fixupVersion1_1(); + if (lastVersion <= 1720) fixupVersion1_7_20(); + + Database.SetLastLoadedVersion(ServerVersion.GetVersionString()); + } + } + } +} diff --git a/HorseIsleServer/LibHISP/Server/Database.cs b/HorseIsleServer/LibHISP/Server/Database.cs index 8702785..6901494 100644 --- a/HorseIsleServer/LibHISP/Server/Database.cs +++ b/HorseIsleServer/LibHISP/Server/Database.cs @@ -46,6 +46,24 @@ namespace HISP.Server SqliteConnection.ClearAllPools(); } + public static bool TryExecuteSqlQuery(string query) + { + using (DbConnection db = connectDb()) + { + db.Open(); + DbCommand sqlCommand = db.CreateCommand(); + sqlCommand.CommandText = query; + try + { + sqlCommand.ExecuteNonQuery(); + return true; + } + catch (Exception e) + { + return false; + }; + } + } public static void OpenDatabase() { if (!ConfigReader.SqlLite) @@ -53,7 +71,8 @@ namespace HISP.Server else ConnectionString = "Data Source=\"" + ConfigReader.DatabaseName + ".db\";"; - + DataFixerUpper.FixUpDb(); + using (DbConnection db = connectDb()) { @@ -74,7 +93,7 @@ namespace HISP.Server string MailTable = "CREATE TABLE IF NOT EXISTS Mailbox(RandomId INT, IdTo INT, IdFrom INT, Subject TEXT(100), Message Text(65535), TimeSent INT, BeenRead TEXT(3))"; string BuddyTable = "CREATE TABLE IF NOT EXISTS BuddyList(Id INT, IdFriend INT)"; string MessageQueue = "CREATE TABLE IF NOT EXISTS MessageQueue(Id INT, Message TEXT(1028))"; - string WorldTable = "CREATE TABLE World(Time INT, Day INT, Year INT, StartTime INT)"; + string WorldTable = "CREATE TABLE IF NOT EXISTS World(Time INT, Day INT, Year INT, StartTime INT, LastLoadedInVersion TEXT(64))"; string WeatherTable = "CREATE TABLE IF NOT EXISTS Weather(Area TEXT(1028), Weather TEXT(64))"; string InventoryTable = "CREATE TABLE IF NOT EXISTS Inventory(PlayerID INT, RandomID INT, ItemID INT, Data INT)"; string ShopInventory = "CREATE TABLE IF NOT EXISTS ShopInventory(ShopID INT, RandomID INT, ItemID INT, Data INT)"; @@ -550,18 +569,16 @@ namespace HISP.Server try { - DbCommand sqlCommand = db.CreateCommand(); sqlCommand.CommandText = WorldTable; sqlCommand.ExecuteNonQuery(); sqlCommand = db.CreateCommand(); - sqlCommand.CommandText = "INSERT INTO World VALUES(0,0,0,@startDate)"; - addWithValue(sqlCommand, "@startDate", (int)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds); + sqlCommand.CommandText = "INSERT INTO World VALUES(0,0,0,@startDate,@version)"; + addWithValue(sqlCommand, "@startDate", (UInt32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds); + addWithValue(sqlCommand, "@version", ServerVersion.GetVersionString()); sqlCommand.Prepare(); sqlCommand.ExecuteNonQuery(); - - } catch (Exception e) { @@ -2598,6 +2615,80 @@ namespace HISP.Server } } + public static void SetLastLoadedVersion(string version) + { + using (DbConnection db = connectDb()) + { + db.Open(); + DbCommand sqlCommand = db.CreateCommand(); + sqlCommand.CommandText = "UPDATE World SET LastLoadedInVersion=@version"; + addWithValue(sqlCommand, "@version", version); + sqlCommand.Prepare(); + sqlCommand.ExecuteNonQuery(); + + } + } + + // Tests if the game was previously loaded in 1.0 + public static bool TestFor1_0() + { + try + { + using (DbConnection db = connectDb()) + { + db.Open(); + DbCommand sqlCommand = db.CreateCommand(); + sqlCommand.CommandText = "SELECT TotalLogins FROM UserExt LIMIT 1;"; + sqlCommand.ExecuteNonQuery(); + } + return false; + } + catch (Exception e) + { + return true; + }; + } + //Tests if game was previously loaded in v1.1 + public static bool TestFor1_1() + { + try + { + using (DbConnection db = connectDb()) + { + db.Open(); + DbCommand sqlCommand = db.CreateCommand(); + sqlCommand.CommandText = "SELECT Data FROM ShopInventory LIMIT 1;"; + sqlCommand.ExecuteNonQuery(); + } + return false; + } + catch (Exception e) + { + return true; + } + } + + public static string GetLastLoadedVersion() + { + try + { + using (DbConnection db = connectDb()) + { + db.Open(); + DbCommand sqlCommand = db.CreateCommand(); + sqlCommand.CommandText = "SELECT LastLoadedInVersion FROM World"; + string lastVersion = sqlCommand.ExecuteScalar().ToString(); + + return lastVersion; + } + } + catch (Exception) // table not found? must have been before v1.7.20. + { + if (TestFor1_0()) return "v1.0"; + if (TestFor1_1()) return "v1.1"; + return "v1.7.20"; + } + } public static void SetStartTime(int startTime) { diff --git a/HorseIsleServer/N00BS/Properties/AssemblyInfo.cs b/HorseIsleServer/N00BS/Properties/AssemblyInfo.cs index 2d772e8..7a35e92 100644 --- a/HorseIsleServer/N00BS/Properties/AssemblyInfo.cs +++ b/HorseIsleServer/N00BS/Properties/AssemblyInfo.cs @@ -31,5 +31,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.7.11.0")] -[assembly: AssemblyFileVersion("1.7.11.0")] +[assembly: AssemblyVersion("1.7.20.0")] +[assembly: AssemblyFileVersion("1.7.20.0")]