public static void LoadExps(object object1) { using (DatabaseConnection dbConnection = new DatabaseConnection(DatabaseID.Data)) { try { MySql database = dbConnection.Database; string query = "SELECT * " + "FROM experience"; foreach (DataColumnCollection columnCollection in database.RetrieveRowsEnumerable(query)) { int level = columnCollection["level_num"].ValueString.ToInt(); exp[level - 1] = columnCollection["med_slow"].ValueString.ToUlng(); if (LoadUpdate != null) LoadUpdate(null, new LoadingUpdateEventArgs(level, exp.MaxLevels)); } if (LoadComplete != null) LoadComplete(null, null); } catch (Exception ex) { Exceptions.ErrorLogger.WriteToErrorLog(ex); } } }
public static void RunTest(Client client) { Messenger.PlayerMsg(client, client.IP.ToString(), Text.BrightRed); return; int playerCount = 0; PacketHitList hitlist = null; PacketHitList.MethodStart(ref hitlist); IMap map = client.Player.Map; Stopwatch watch = new Stopwatch(); watch.Start(); using (DatabaseConnection db = new DatabaseConnection(DatabaseID.Players)) { PlayerManager.RetrieveCharacterID(db, "luigiDUDE"); } //Messenger.PlayerWarp(client, map.MapID, 0, 25); watch.Stop(); PacketHitList.MethodEnded(ref hitlist); Messenger.PlayerMsg(client, "Time: " + watch.ElapsedMilliseconds + "\nPlayer Count: " + playerCount, Text.BrightGreen); Messenger.PlayerMsg(client, "RNG: " + Server.Math.Rand(0, 1000), Text.BrightGreen); Messenger.PlayerMsg(client, "Tick Count: " + Server.Core.GetTickCount().Tick, Text.BrightGreen); //exPlayer.Get(client).EvolutionActive = !exPlayer.Get(client).EvolutionActive; //Messenger.PlayerMsg(client, "Evolution active: " + exPlayer.Get(client).EvolutionActive, Text.Yellow); //BossBattles.StartBossBattle(client, "CliffsideRelic"); //map.SetTile(9, 3, 3, 0, 4, 3); //map.SetAttribute(9, 3, Server.Enums.TileType.Scripted, 46, 0, 0, "2", "1015", "25:25"); //Messenger.SendTile(9, 3, map); }
public static void DumpStatistics() { int playerCount = 0; int staffCount = 0; foreach (Client i in ClientManager.GetClients()) { if (i.Player != null) { if (i.IsPlaying()) { playerCount++; if (Players.Ranks.IsAllowed(i, Enums.Rank.Moniter)) { staffCount++; } } } } int partyCount = Server.Players.Parties.PartyManager.CountActiveParties(); int activeMapCount = Server.Maps.MapManager.CountActiveMaps(); int activeNetworkClients = Server.Network.ClientManager.CountActiveClients(); Process serverProcess = Process.GetCurrentProcess(); long workingSet = serverProcess.WorkingSet64; long elapsedHours = (long)Globals.LiveTime.Elapsed.TotalHours; using (DatabaseConnection dbConnection = new DatabaseConnection(DatabaseID.Data)) { dbConnection.Database.AddRow("stats_performance", new IDataColumn[] { dbConnection.Database.CreateColumn(false, "Time", DateTime.UtcNow.ToString()), dbConnection.Database.CreateColumn(false, "PlayerCount", playerCount.ToString()), dbConnection.Database.CreateColumn(false, "StaffCount", staffCount.ToString()), dbConnection.Database.CreateColumn(false, "ActiveNetworkClients", activeNetworkClients.ToString()), dbConnection.Database.CreateColumn(false, "ActiveMaps", activeMapCount.ToString()), dbConnection.Database.CreateColumn(false, "ActiveParties", partyCount.ToString()), dbConnection.Database.CreateColumn(false, "WorkingSet", workingSet.ToString()), dbConnection.Database.CreateColumn(false, "ElapsedHours", elapsedHours.ToString()) }); } }
/* public static int FindMoveName(string moveName){ for (int i = 1; i <= moves.MaxMoves; i++) { if (Moves.Moves[i].Name == moveName) { return i; } } return -1; } */ public static void Initialize() { using (DatabaseConnection dbConnection = new DatabaseConnection(DatabaseID.Data)) { //method for getting count string query = "SELECT COUNT(num) FROM move"; DataColumnCollection row = dbConnection.Database.RetrieveRow(query); int count = row["COUNT(num)"].ValueString.ToInt(); moves = new MoveCollection(count); } standardAttack = new Move(); //Set standard attack standardAttack.Name = "its regular attack"; standardAttack.RangeType = Enums.MoveRange.FrontOfUser; standardAttack.Range = 1; standardAttack.Accuracy = 90; standardAttack.TargetType = Enums.MoveTarget.Foes; standardAttack.Element = Enums.PokemonType.None; standardAttack.MoveCategory = Enums.MoveCategory.Physical; standardAttack.EffectType = Enums.MoveType.SubHP; standardAttack.HitTime = 900; standardAttack.HitFreeze = false; standardAttack.Data1 = Server.Constants.STANDARDATTACKBASEPOWER; standardAttack.AttackerAnim.AnimationIndex = -1; standardAttack.TravelingAnim.AnimationIndex = -1; standardAttack.DefenderAnim.AnimationIndex = -1; standardAttack.Sound = -1; }
public static bool AccountExists(DatabaseConnection dbConnection, string accountName) { if (!string.IsNullOrEmpty(accountName)) { return PlayerDataManager.IsAccountNameTaken(dbConnection.Database, accountName); } else { return false; } }
public static bool CharacterNameExists(DatabaseConnection dbConnection, string characterName) { string retrievedCharID = RetrieveCharacterID(dbConnection, characterName); if (!string.IsNullOrEmpty(retrievedCharID)) { return true; } else { return false; } }
public Party(string partyID, Client leader) { PartyID = partyID; Members = new List<string>(); Members.Add(leader.Player.CharID); using (DatabaseConnection dbConnection = new DatabaseConnection(DatabaseID.Players)) { PartyManager.SaveParty(dbConnection.Database, this); } }
public static void Initialize() { using (DatabaseConnection dbConnection = new DatabaseConnection(DatabaseID.Data)) { //method for getting count string query = "SELECT COUNT(num) FROM item"; DataColumnCollection row = dbConnection.Database.RetrieveRow(query); int count = row["COUNT(num)"].ValueString.ToInt(); items = new ItemCollection(count); } }
/// <summary> /// Creates a new account. Return codes: -1: Unknown error, 0: Success, 1: Account already exists /// </summary> /// <param name="accountName">Name of the account.</param> /// <param name="encryptedPassword">The encrypted password.</param> /// <returns></returns> public static int CreateNewAccount(DatabaseConnection dbConnection, string accountName, string encryptedPassword, string email) { int result = -1; if (PlayerDataManager.IsAccountNameTaken(dbConnection.Database, accountName) == false) { PlayerDataManager.CreateNewAccount(dbConnection.Database, accountName, encryptedPassword, email); result = 0; } else { result = 1; } return result; }
public bool AddToParty(Client client) { if (CanAddToParty(client)) { Add(client.Player.CharID); //SwitchOutExtraMembers(); using (DatabaseConnection dbConnection = new DatabaseConnection(DatabaseID.Players)) { PartyManager.SaveParty(dbConnection.Database, this); } return true; } else { return false; } }
// Bans a player public static void BanPlayer(DatabaseConnection dbConnection, string ip, string bannedID, string bannedAccount, string bannedMac, string bannerID, string bannerIP, string unbanDate, Enums.BanType banType) { IDataColumn[] columns = new IDataColumn[] { dbConnection.Database.CreateColumn(true, "BannedPlayerID", bannedID), dbConnection.Database.CreateColumn(false, "BannedPlayerAccount", bannedAccount), dbConnection.Database.CreateColumn(false, "BannedPlayerIP", ip), dbConnection.Database.CreateColumn(false, "BannedPlayerMac", bannedMac), dbConnection.Database.CreateColumn(false, "BannerPlayerID", bannerID), dbConnection.Database.CreateColumn(false, "BannerPlayerIP",bannerIP), dbConnection.Database.CreateColumn(false, "BannedDate", DateTime.Now.ToString()), dbConnection.Database.CreateColumn(false, "UnbanDate", unbanDate), dbConnection.Database.CreateColumn(false, "BanType", ((int)banType).ToString()) }; dbConnection.Database.AddRow("bans", columns); }
public static void LoadMissionPool(DatabaseConnection dbConnection, int difficulty) { MissionPool missionPool = new MissionPool(); MySql database = dbConnection.Database; string query = "SELECT mission_client.DexNum, mission_client.FormNum " + "FROM mission_client " + "WHERE mission_client.Rank = \'" + difficulty + "\' " + "ORDER BY mission_client.ClientIndex"; foreach (DataColumnCollection column in database.RetrieveRowsEnumerable(query)) { MissionClientData data = new MissionClientData(); data.Species = column["DexNum"].ValueString.ToInt(); data.Form = column["FormNum"].ValueString.ToInt(); missionPool.MissionClients.Add(data); } query = "SELECT mission_enemy.NpcNum " + "FROM mission_enemy " + "WHERE mission_enemy.Rank = \'" + difficulty + "\' " + "ORDER BY mission_enemy.EnemyIndex"; foreach (DataColumnCollection column in database.RetrieveRowsEnumerable(query)) { MissionEnemyData data = new MissionEnemyData(); data.NpcNum = column["NpcNum"].ValueString.ToInt(); missionPool.Enemies.Add(data); } query = "SELECT mission_reward.ItemNum, mission_reward.ItemAmount, mission_reward.ItemTag " + "FROM mission_reward " + "WHERE mission_reward.Rank = \'" + difficulty + "\' " + "ORDER BY mission_reward.RewardIndex"; foreach (DataColumnCollection column in database.RetrieveRowsEnumerable(query)) { MissionRewardData data = new MissionRewardData(); data.ItemNum = column["ItemNum"].ValueString.ToInt(); data.Amount = column["ItemAmount"].ValueString.ToInt(); data.Tag = column["ItemTag"].ValueString; missionPool.Rewards.Add(data); } missionPools.MissionPools.Add(missionPool); }
public static void DumpStatistics() { using (DatabaseConnection dbConnection = new DatabaseConnection(DatabaseID.Data)) { dbConnection.Database.ExecuteNonQuery("TRUNCATE TABLE packet_statistics"); foreach (string key in statistics.Keys) { PacketStatistic stats; if (statistics.TryGetValue(key, out stats)) { dbConnection.Database.UpdateOrInsert("packet_statistics", new IDataColumn[] { dbConnection.Database.CreateColumn(true, "Header", key), dbConnection.Database.CreateColumn(false, "Amount", stats.TimesReceived.ToString()), dbConnection.Database.CreateColumn(false, "AverageTime", (stats.TotalProcessTime / stats.TimesReceived * 1000 / (double)System.Diagnostics.Stopwatch.Frequency).ToString()), dbConnection.Database.CreateColumn(false, "AverageDataSplittingTime", (stats.TotalDataSplittingTime / stats.TimesReceived * 1000 / (double)System.Diagnostics.Stopwatch.Frequency).ToString()), dbConnection.Database.CreateColumn(false, "AverageCPUUsage", (stats.CPUUsage / stats.TimesReceived).ToString()) }); } } } }
public static void LoadStories(object object1) { try { using (DatabaseConnection dbConnection = new DatabaseConnection(DatabaseID.Data)) { for (int i = 0; i <= stories.MaxStories; i++) { LoadStory(i, dbConnection.Database); if (LoadUpdate != null) LoadUpdate(null, new LoadingUpdateEventArgs(i, stories.MaxStories)); } if (LoadComplete != null) LoadComplete(null, null); } } catch (Exception ex) { Exceptions.ErrorLogger.WriteToErrorLog(ex); } }
public static void DisbandGuild(Client client) { if (client.Player.GuildAccess < Enums.GuildRank.Founder) { Messenger.PlayerMsg(client, "You are not the owner of this guild!", Text.BrightRed); return; } string guildName = client.Player.GuildName; using (DatabaseConnection dbConnection = new DatabaseConnection(DatabaseID.Players)) { DataManager.Players.PlayerDataManager.RemoveGuild(dbConnection.Database, guildName); } foreach (Client member in ClientManager.GetClients()) { if (member.Player.GuildName == guildName) { member.Player.GuildName = ""; member.Player.GuildAccess = Enums.GuildRank.None; Messenger.SendPlayerGuild(member); Messenger.PlayerMsg(client, "Your guild has been disbanded.", Text.BrightRed); } } }
public static Enums.BanType IsBanned(DatabaseConnection dbConnection, string column, string value) { IDataColumn[] columns = RetrieveField(dbConnection, "UnbanDate", column, value); IDataColumn[] dataColumns = RetrieveField(dbConnection, "BanType", column, value); if (columns != null) { string unbanDate = (string)columns[0].Value; if (unbanDate == "-----") { // It's a permanent ban. return (Enums.BanType)((int)dataColumns[0].Value); } else { // It's a temp ban DateTime dtUnbanDate = DateTime.Parse(unbanDate); if (DateTime.Now > dtUnbanDate) { RemoveBan(dbConnection, column, value); return Enums.BanType.None; } else { return (Enums.BanType)((int)dataColumns[0].Value); } } } else { // columns was null, which means their entry was not found return Enums.BanType.None; } }
public int GetTotalDungeonCompletionCount() { // On demand loading! if (playerData.DungeonCompletionCountsLoaded == false) { using (DatabaseConnection dbConnection = new DatabaseConnection(DatabaseID.Players)) { PlayerDataManager.LoadPlayerDungeonCompletionCounts(dbConnection.Database, playerData); } } int total = 0; for (int i = 0; i < DungeonCompletionCounts.Count; i++) { total += DungeonCompletionCounts.ValueByIndex(i); } return total; }
public bool GetStoryState(int storyNum) { int index = StoryChapters.IndexOfKey(storyNum); if (index > -1) { return StoryChapters.ValueByIndex(index); } else { // Load on demand and cache bool state; using (DatabaseConnection dbConnection = new DatabaseConnection(DatabaseID.Players)) { state = PlayerDataManager.RetrievePlayerStoryChapterState(dbConnection.Database, CharID, storyNum); } StoryChapters.Add(storyNum, state); return state; } }
public Enums.PokedexStat GetPokedexStatus(int pokemonID) { int index = RecruitList.IndexOfKey(pokemonID); if (index > -1) { return (Enums.PokedexStat)RecruitList.ValueByIndex(index); } else { byte status; using (DatabaseConnection dbConnection = new DatabaseConnection(DatabaseID.Players)) { status = PlayerDataManager.RetrievePlayerRecruitListStatus(dbConnection.Database, CharID, pokemonID); } RecruitList.Add(pokemonID, status); return (Enums.PokedexStat)status; } }
public int GetDungeonCompletionCount(int dungeonIndex) { // On demand loading! if (playerData.DungeonCompletionCountsLoaded == false) { using (DatabaseConnection dbConnection = new DatabaseConnection(DatabaseID.Players)) { PlayerDataManager.LoadPlayerDungeonCompletionCounts(dbConnection.Database, playerData); } } int index = DungeonCompletionCounts.IndexOfKey(dungeonIndex); if (index > -1) { return DungeonCompletionCounts.ValueByIndex(index); } else { return -1; } }
public void EndTempStatMode() { PacketHitList hitlist = null; PacketHitList.MethodStart(ref hitlist); using (DatabaseConnection dbConnection = new DatabaseConnection(DatabaseID.Players)) { for (int i = 0; i < Team.Length; i++) { if (Team[i].Loaded && Team[i].InTempMode) { int recruitIndex = Team[i].RecruitIndex; Team[i] = new Recruit(client); RecruitData recruitData = PlayerDataManager.LoadPlayerRecruit(dbConnection.Database, CharID, recruitIndex, false); Team[i].LoadFromRecruitData(recruitData, recruitIndex); PlayerDataManager.DeletePlayerRecruit(dbConnection.Database, CharID, recruitIndex, true); } } } PacketBuilder.AppendPlayerData(client, hitlist); PacketBuilder.AppendStats(client, hitlist); PacketBuilder.AppendEXP(client, hitlist); PacketBuilder.AppendPlayerMoves(client, hitlist); PacketBuilder.AppendActiveTeam(client, hitlist); }
public void DeleteFromRecruitmentBank(DatabaseConnection dbConnection, int recruitIndex, bool RemoveFromTeamSlot) { if (recruitIndex > 0) { if (RemoveFromTeamSlot) { for (int i = 0; i < Constants.MAX_ACTIVETEAM; i++) { if (Team[i].RecruitIndex == recruitIndex) { RemoveFromTeam(i); } } } // Delete both the normal version, and the temp stat mode copy PlayerDataManager.DeletePlayerRecruit(dbConnection.Database, CharID, recruitIndex, false); PlayerDataManager.DeletePlayerRecruit(dbConnection.Database, CharID, recruitIndex, true); } else if (recruitIndex == 0) { Messenger.PlayerMsg(client, "You can't release your starter Pokémon!", Text.BrightRed); } else { Messenger.PlayerMsg(client, "Error: Unable to release selected Pokémon", Text.BrightRed); } }
public void CreateCharacter(DatabaseConnection dbConnection, string name, Enums.Sex sex, int slot, bool silent) { PlayerData characterData = new PlayerData(PlayerID.GeneratePlayerID()); characterData.Name = name; characterData.Map = MapManager.GenerateMapID(Settings.StartMap); characterData.X = Settings.StartX; characterData.Y = Settings.StartY; characterData.MaxInv = 20; characterData.MaxBank = 100; RecruitData leaderData = new RecruitData(); leaderData.Name = name; leaderData.Sex = (byte)sex; leaderData.Species = 0; leaderData.Form = 1; leaderData.Level = 1; leaderData.HP = -1; Scripting.ScriptManager.InvokeSub("CharacterCreated", accountName, slot, characterData, leaderData); PlayerDataManager.CreateNewCharacter(dbConnection.Database, accountName, slot, characterData); //PlayerDataManager.SavePlayerAvailableExpKitModules(client.Database, playerData); //PlayerDataManager.SavePlayerCharacteristics(client.Database, playerData); //PlayerDataManager.SavePlayerGuild(client.Database, playerData); //PlayerDataManager.SavePlayerItemGenerals(client.Database, playerData); //PlayerDataManager.SavePlayerJobList(client.Database, playerData); //PlayerDataManager.SavePlayerLocation(client.Database, playerData); //PlayerDataManager.SavePlayerMissionBoardGenerals(client.Database, playerData); //PlayerDataManager.SavePlayerMissionBoardMissions(client.Database, playerData); //PlayerDataManager.SavePlayerMissionGenerals(client.Database, playerData); //PlayerDataManager.SavePlayerStoryGenerals(client.Database, playerData); //PlayerDataManager.SavePlayerStoryHelperStateSettings(client.Database, playerData); //// Save inventory //ListPair<int, PlayerDataInventoryItem> updatedInventory = new ListPair<int, PlayerDataInventoryItem>(); //for (int i = 1; i <= Inventory.Count; i++) { // if (Inventory[i].Updated) { // updatedInventory.Add(i, Inventory[i].BaseInventoryItem); // Inventory[i].Updated = false; // } //} //PlayerDataManager.SavePlayerInventoryUpdates(client.Database, CharID, updatedInventory); //// Save bank //ListPair<int, PlayerDataInventoryItem> updatedBank = new ListPair<int, PlayerDataInventoryItem>(); //for (int i = 1; i <= Bank.Count; i++) { // if (Bank[i].Updated) { // updatedBank.Add(i, Bank[i].BaseInventoryItem); // Bank[i].Updated = false; // } //} //PlayerDataManager.SavePlayerBankUpdates(client.Database, CharID, updatedBank); //// Save trigger events //playerData.TriggerEvents.Clear(); //for (int i = 0; i < triggerEvents.Count; i++) { // PlayerDataTriggerEvent triggerEvent = new PlayerDataTriggerEvent(); // triggerEvents[i].Save(triggerEvent); // playerData.TriggerEvents.Add(triggerEvent); //} //PlayerDataManager.SavePlayerTriggerEvents(client.Database, playerData); //// Save team //for (int i = 0; i < team.Length; i++) { // playerData.TeamMembers[i].RecruitIndex = team[i].RecruitIndex; // playerData.TeamMembers[i].UsingTempStats = team[i].InTempMode; // if (team[i].Loaded) { // team[i].Save(); // } //} //PlayerDataManager.SavePlayerTeam(client.Database, playerData); PlayerDataManager.SavePlayerRecruit(dbConnection.Database, characterData.CharID, 0, leaderData); if (silent == false) { Messenger.SendChars(dbConnection, client); Messenger.PlainMsg(client, "Character has been created!", Enums.PlainMsgType.Chars); } }
public bool CharacterExists(DatabaseConnection dbConnection, int slot) { return !PlayerDataManager.IsCharacterSlotEmpty(dbConnection.Database, accountName, slot); }
public void BeginTempStatMode(int level, bool keepMoves) { PacketHitList hitlist = null; PacketHitList.MethodStart(ref hitlist); // Save the current team using (DatabaseConnection dbConnection = new DatabaseConnection(DatabaseID.Players)) { for (int i = 0; i < Team.Length; i++) { if (Team[i].Loaded) { Team[i].Save(dbConnection); } } } // Now that the team is saved, change the levels! for (int i = 0; i < Team.Length; i++) { if (Team[i].Loaded) { Team[i].InTempMode = true; Team[i].Level = level; Team[i].Exp = 0; Team[i].CalculateOriginalStats(); Team[i].HP = Team[i].MaxHP; if (!keepMoves) { for (int move = 0; move < Team[i].Moves.Length; move++) { Team[i].Moves[move] = new RecruitMove(); } Team[i].GenerateMoveset(); } } } PacketBuilder.AppendPlayerData(client, hitlist); PacketBuilder.AppendStats(client, hitlist); PacketBuilder.AppendEXP(client, hitlist); PacketBuilder.AppendPlayerMoves(client, hitlist); PacketBuilder.AppendActiveTeam(client, hitlist); PacketHitList.MethodEnded(ref hitlist); }
//public int GetTeamSize() { // int total = 0; // for (int i = 0; i < Constants.MAX_ACTIVETEAM; i++) { // if (team[i].Loaded) { // if (team[i].RecruitIndex > -1 || team[i].RecruitBoost == -2) { // total += team[i].Size; // } // } // } // return total; //} public void AddToTeam(int recruitIndex, int teamSlot) { using (DatabaseConnection dbConnection = new DatabaseConnection(DatabaseID.Players)) { if (((recruitIndex > -1 && IsInTeam(recruitIndex) == false && RecruitExists(dbConnection, recruitIndex)) || recruitIndex == -2) && (!(teamSlot < 0) || !(teamSlot > 3))) { Recruit recruit = new Recruit(client); recruit.LoadFromRecruitData(PlayerDataManager.LoadPlayerRecruit(dbConnection.Database, CharID, recruitIndex, false), recruitIndex); team[teamSlot] = recruit; for (int i = 0; i < team.Length; i++) { if (team[i].RecruitIndex != -1) { team[i].LoadActiveItemList(); } } if (recruitIndex != -2) { ScriptManager.InvokeSub("RecruitAddedToTeam", client, teamSlot, recruitIndex); } } } }
public int AddToRecruitmentBank(DatabaseConnection dbConnection, Recruit requestedRecruit) { int index = FindOpenRecruitmentSlot(dbConnection); if (index > -1 && index <= Constants.MAX_RECRUITMENTS) { PokemonCaught(requestedRecruit.Species); Recruit recruit = new Recruit(client); recruit.RecruitIndex = index; recruit.Level = requestedRecruit.Level; recruit.Species = requestedRecruit.Species; recruit.Form = requestedRecruit.Form; recruit.Sex = requestedRecruit.Sex; recruit.CalculateOriginalStats(); recruit.Exp = requestedRecruit.Exp; recruit.IQ = requestedRecruit.IQ; //recruit.HP = recruit.MaxHP; recruit.Name = requestedRecruit.Name; recruit.NpcBase = requestedRecruit.NpcBase; recruit.AtkBonus = requestedRecruit.AtkBonus; recruit.DefBonus = requestedRecruit.DefBonus; recruit.SpclAtkBonus = requestedRecruit.SpclAtkBonus; recruit.SpclDefBonus = requestedRecruit.SpclDefBonus; recruit.SpdBonus = requestedRecruit.SpdBonus; recruit.MaxHPBonus = requestedRecruit.MaxHPBonus; for (int i = 0; i < Constants.MAX_PLAYER_MOVES; i++) { recruit.Moves[i].MoveNum = requestedRecruit.Moves[i].MoveNum; recruit.Moves[i].MaxPP = requestedRecruit.Moves[i].MaxPP; recruit.Moves[i].CurrentPP = recruit.Moves[i].MaxPP; recruit.Moves[i].Sealed = false; } recruit.Save(dbConnection); //Return the index of the recruited player return index; } //Return -1 so we know we're full return -1; }
private int FindOpenRecruitmentSlot(DatabaseConnection dbConnection) { int slot = PlayerDataManager.FindOpenRecruitmentSlot(dbConnection.Database, CharID); if (slot > Constants.MAX_RECRUITMENTS) { slot = -1; } return slot; }
internal void ChangePassword(DatabaseConnection dbConnection, string currentPassword, string newPassword) { if (!string.IsNullOrEmpty(accountName)) { PlayerDataManager.ChangePassword(dbConnection.Database, accountName, currentPassword, newPassword); } }
public void AddFriend(string friendName) { Client pIndex = ClientManager.FindClient(friendName.Trim()); string pName; if (pIndex != null) { pName = pIndex.Player.Name.Trim(); if (pName.Trim().ToLower() == Name.Trim().ToLower()) { Messenger.PlayerMsg(client, "You can't add yourself!", Text.BrightRed); return; } } else { Messenger.PlayerMsg(client, "Player is not online", Text.White); return; } if (Friends.Count < 20) { int result; using (DatabaseConnection dbConnection = new DatabaseConnection(DatabaseID.Players)) { result = Friends.AddFriend(dbConnection.Database, pName); } if (result == 0) { SendFriendsList(); Messenger.PlayerMsg(client, pName + " has been added!", Text.Yellow); ScriptManager.InvokeSub("FriendAdded", client, pName); } else if (result == 1) { Messenger.PlayerMsg(client, "Player is already on your friends list!", Text.BrightRed); } } else { Messenger.PlayerMsg(client, "Friends list full", Text.BrightRed); } }
public void ProcessCommandCallback(object obj) { int activeLine = (int)((ParamObject)obj).Param[0]; string command = (string)((ParamObject)obj).Param[1]; Command fullCommand = Server.CommandProcessor.ParseCommand(command); string fullArgs = CommandProcessor.JoinArgs(fullCommand.CommandArgs.ToArray()); switch (fullCommand.CommandArgs[0].ToLower()) { case "/help": { DisplayHelp(); } break; case "/clear": { } break; case "/global": { Messenger.GlobalMsg(fullArgs, Text.White); ServerConsole.WriteLine("Global: " + fullArgs); } break; case "/masskick": { foreach (Client i in ClientManager.GetClients()) { if (i.IsPlaying() && Ranks.IsDisallowed(i, Enums.Rank.Monitor)) { Messenger.GlobalMsg(i.Player.Name + " has been kicked by the server!", Text.White); Messenger.AlertMsg(i, "You have been kicked by the server!"); } } ServerConsole.WriteLine("Everyone has been kicked."); } break; case "/dumpstats": { Statistics.PacketStatistics.DumpStatistics(); ServerConsole.WriteLine("Packet statistics dumped to database."); } break; case "/clearstats": { Statistics.PacketStatistics.ClearStatistics(); ServerConsole.WriteLine("Packet statistics cleared."); } break; case "/masswarp": { if (fullCommand.CommandArgs.Count == 4) { int map = fullCommand.CommandArgs[1].ToInt(-1); int x = fullCommand.CommandArgs[2].ToInt(-1); int y = fullCommand.CommandArgs[3].ToInt(-1); if (map <= 0) { ServerConsole.WriteLine("Invalid Map."); break; } else if (x == -1) { ServerConsole.WriteLine("Invalid X coordinate."); break; } else if (y == -1) { ServerConsole.WriteLine("Invalid Y coordinate."); break; } // TODO: Mass Warp //if (x > MapManager.Maps[map].MaxX) { // ServerConsole.WriteLine("Invalid X coordinate."); // break; //} //if (y > MapManager.Maps[map].MaxY) { // ServerConsole.WriteLine("Invalid Y coordinate."); // break; //} foreach (Client i in ClientManager.GetClients()) { if (i.IsPlaying() && Ranks.IsDisallowed(i, Enums.Rank.Monitor)) { Messenger.GlobalMsg("The server has warped everyone!", Text.White); Messenger.PlayerWarp(i, map, x, y); } } ServerConsole.WriteLine("Everyone has been warped."); } else { ServerConsole.WriteLine("Invalid arguments."); } } break; case "/kick": { if (fullCommand.CommandArgs.Count == 2) { Client client = ClientManager.FindClient(fullCommand.CommandArgs[1]); if (client == null) { ServerConsole.WriteLine("Player is offline."); } else { Messenger.GlobalMsg(client.Player.Name + " has been kicked by the server!", Text.White); Messenger.AlertMsg(client, "You have been kicked by the server!"); ServerConsole.WriteLine(client.Player.Name + " has been kicked!"); } } else { ServerConsole.WriteLine("Invalid arguments."); } } break; case "/warp": { if (fullCommand.CommandArgs.Count == 5) { Client client = ClientManager.FindClient(fullCommand.CommandArgs[1]); if (client == null) { ServerConsole.WriteLine("Player is offline."); } else { int mapNum = fullCommand.CommandArgs[2].ToInt(-1); int x = fullCommand.CommandArgs[3].ToInt(-1); int y = fullCommand.CommandArgs[4].ToInt(-1); if (mapNum <= 0) { ServerConsole.WriteLine("Invalid Map."); break; } else if (x == -1) { ServerConsole.WriteLine("Invalid X coordinate."); break; } else if (y == -1) { ServerConsole.WriteLine("Invalid Y coordinate."); break; } IMap map; if (MapManager.IsMapActive(MapManager.GenerateMapID(mapNum))) { map = MapManager.RetrieveActiveMap(MapManager.GenerateMapID(mapNum)); } else { using (Database.DatabaseConnection dbConnection = new Database.DatabaseConnection(Database.DatabaseID.Data)) { map = MapManager.LoadStandardMap(dbConnection, MapManager.GenerateMapID(mapNum)); } } if (x > map.MaxX) { ServerConsole.WriteLine("Invalid X coordinate."); break; } if (y > map.MaxY) { ServerConsole.WriteLine("Invalid Y coordinate."); break; } Messenger.PlayerMsg(client, "You have been warped by the server!", Text.White); Messenger.PlayerWarp(client, mapNum, x, y); ServerConsole.WriteLine(client.Player.Name + " has been warped."); } } else { ServerConsole.WriteLine("Invalid arguments."); } } break; case "/mapmsg": { if (fullCommand.CommandArgs.Count == 3) { string map = fullCommand.CommandArgs[1]; // Check if the map is active if (!MapManager.IsMapActive(map)) { ServerConsole.WriteLine("Invalid Map."); break; } Messenger.MapMsg(map, fullCommand.CommandArgs[2], Text.DarkGrey); ServerConsole.WriteLine("Map Msg (Map " + map.ToString() + "): " + fullCommand.CommandArgs[2]); } else { ServerConsole.WriteLine("Invalid arguments."); } } break; case "/reloadscripts": { Scripting.ScriptManager.Reload(); ServerConsole.WriteLine("Scripts reloaded."); } break; case "/players": { string players = ""; int count = 0; foreach (Client i in ClientManager.GetClients()) { if (i.IsPlaying()) { count++; players += i.Player.Name + "\r\n"; } } ServerConsole.WriteLine("Players online: \r\n" + players); ServerConsole.WriteLine("There are " + count.ToString() + " players online"); } break; case "/test": { //Email.Email.SendEmail("test"); //ServerConsole.WriteLine("Mail sent!"); //ServerConsole.WriteLine("There are currently no benchmarking tests"); //System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch(); //watch.Start(); //MapGeneralInfo genInfo = MapManager.RetrieveMapGeneralInfo(10); //watch.Stop(); //ServerConsole.WriteLine("Elapsed, New: " + watch.Elapsed.ToString()); //watch.Reset(); //watch.Start(); //Map map = MapManager.LoadMap(10); //watch.Stop(); //ServerConsole.WriteLine("Elapsed, Old: " + watch.Elapsed.ToString()); //ServerConsole.WriteLine("Name: " + genInfo.Name); } break; case "/finditem": { int itemsFound = 0; for (int i = 0; i < Server.Items.ItemManager.Items.MaxItems; i++) { if (ItemManager.Items[i].Name.ToLower().StartsWith(fullCommand.CommandArgs[1].ToLower())) { ServerConsole.WriteLine(ItemManager.Items[i].Name + "'s number is " + i.ToString()); itemsFound++; //return; } } if (itemsFound == 0) { ServerConsole.WriteLine("Unable to find an item that starts with '" + fullCommand.CommandArgs[1] + "'"); } } break; case "/finditemc": { int itemsFound = 0; for (int i = 0; i < Server.Items.ItemManager.Items.MaxItems; i++) { if (ItemManager.Items[i].Name.ToLower().Contains(fullCommand.CommandArgs[1].ToLower())) { ServerConsole.WriteLine(ItemManager.Items[i].Name + "'s number is " + i.ToString()); itemsFound++; //return; } } if (itemsFound == 0) { ServerConsole.WriteLine("Unable to find an item that starts with '" + fullCommand.CommandArgs[1] + "'"); } } break; case "/calcwm": { ServerConsole.WriteLine("Factorial: " + Server.Math.CalculateFactorial(fullCommand.CommandArgs[1].ToInt()).ToString("R")); } break; case "/gmmode": { Globals.GMOnly = !Globals.GMOnly; ServerConsole.WriteLine("GM Only Mode Active: " + Globals.GMOnly); } break; default: { Scripting.ScriptManager.InvokeSub("ProcessServerCommand", fullCommand, fullArgs); } break; } }