public static List <NetObject> Include(this List <NetObject> List, Database.GroupDB.Group.Rank IncludeThis) { IEnumerable <NetObject> Iterable = Server.AllClients.ToArray().ToList().Where(x => x.UserObject.Groups.Select(y => y.Rank).Contains(IncludeThis)); foreach (NetObject ThisNetObj in Iterable) { if (!(List.Contains(ThisNetObj))) { List.Add(ThisNetObj); } } return(List); }
public static List <NetObject> Except(this List <NetObject> List, Database.GroupDB.Group.Rank ExceptThis) { IEnumerable <NetObject> Iterable = List.ToArray().ToList().Where(x => x.UserObject.Groups.Select(y => y.Rank).Contains(ExceptThis)); foreach (NetObject ThisNetObj in Iterable) { while (true) { if (List.Contains(ThisNetObj)) { List.Remove(ThisNetObj); } else { break; } } } return(List); }
public static bool Orb_Command_Maintenence_Group_Ranks_Decrement_Method(Server.NetObject NetObj, CommandReader Command) { string TargetRankName = ""; Database.GroupDB.Group.Rank TargetRank = Database.GroupDB.NoRank; Database.GroupDB.Group TargetGroup = Database.GroupDB.NoGroup; #region FindTargetGroup if (Database.GroupDB.FindGroup(Command._CmdElements()[1]) == Database.GroupDB.NoGroup) { NetObj.ClientObject.SendMessage("Group not found: \"" + Command._CmdElements()[1] + "\"."); return(false); } TargetGroup = Database.GroupDB.FindGroup(Command._CmdElements()[1]); #endregion #region FindTargetRank if (Command._CmdArguments.Count() < 1) { NetObj.ClientObject.SendMessage("No rank specified to be decremented in the group."); return(false); } else { TargetRankName = Command._CmdArguments[1].ToUpperInvariant(); if (!(TargetGroup.Ranks.Select(x => x.Name.ToUpperInvariant()).Contains(TargetRankName))) { NetObj.ClientObject.SendMessage("Rank: \"" + TargetRankName + "\" not found in Group: \"" + TargetGroup.Name + "\"."); return(false); } else { TargetRank = TargetGroup.Ranks.First(x => x.Name.ToUpperInvariant() == TargetRankName); } } #endregion #region SuperUser Override if (NetObj.UserObject == Database.UserDB.SuperUser || NetObj.UserObject == TargetGroup.Founder) { //Continue } #endregion #region Standard Testing if (NetObj.UserObject.Groups.Select(x => x.Group).Contains(TargetGroup)) { //THIS User is a member of the group. (Required to be able to modify the group. Database.UserDB.User.GroupReference ThisGroupReference = NetObj.UserObject.Groups.Where(x => x.Group == TargetGroup).ToArray()[0]; if (ThisGroupReference.Rank.Permissions.Group_ManageMembers <= 0) { NetObj.ClientObject.SendMessage("Your rank does not have permission to manage group ranks in this group."); return(false); } //Continue } else { NetObj.ClientObject.SendMessage("You need to be a member of the group yourself in order to move ranks. (Group founders are excepted from this rule.)"); return(false); } #endregion if (TargetGroup.Ranks.IndexOf(TargetRank) == 0) { NetObj.ClientObject.SendMessage("Unable to decrement Rank: \"" + TargetRank.Name + "\" in Group: \"" + TargetGroup.Name + "\" any lower. It is the lowest rank already."); return(false); } int CurrentPosition = TargetGroup.Ranks.IndexOf(TargetRank); int NextPosition = CurrentPosition - 1; Database.GroupDB.Group.Rank SwapContainer = TargetGroup.Ranks[NextPosition]; TargetGroup.Ranks[NextPosition] = TargetRank; TargetGroup.Ranks[CurrentPosition] = SwapContainer; TargetGroup.SaveAll(); Server.EmptyClientList.Include(NetObj).SendMessage("Rank: \"" + TargetRank.Name + "\" in Group: \"" + TargetGroup.Name + "\" decremented to position " + NextPosition.ToString() + "."); Server.AllClients.Except(NetObj).SendMessage("User: \"" + NetObj.UserObject.Name + "\" decremented Rank: \"" + TargetRank.Name + "\" in Group: \"" + TargetGroup.Name + "\" to position " + NextPosition.ToString() + "."); return(true); }
static void Main(string[] args) { //PRE OPERATION EVENTS try { Console.Title = "Orb for YSFlight"; Console.CursorVisible = false; Server.ConsoleMode = true; Logger.Console.LockInput(true); } catch { Database.Settings.Set(Database.Settings.Strings.GUIMode, true); Server.ConsoleMode = false; //Console is not enabled } //LOAD SETTINGS Database.Settings.LoadAll(); //GUI LOADING #region Disable Console if (Database.Settings.GUIMode == true) { var handle = GetConsoleWindow(); // Hide ShowWindow(handle, SW_HIDE); Server.ConsoleMode = false; // Show //ShowWindow(handle, SW_SHOW); } #endregion //Database.Settings.Set(Database.Settings.Strings.GUIMode, true); //Database.Settings.Set(Database.Settings.Strings.ProxyMode, true); Logger.Console.Initialise(); //Logger.Console.WriteLine(DateTime.Now.ToString()); ServerGUI.Start(); ServerGUI.LockInput(true); //DATABASE LOADING Logger.Log.Silent = false; Logger.Log.SystemMessage("LOADING DATABASE"); Logger.Console.WriteLine("&9LOADING DATABASE..."); Logger.Log.SystemMessage("Loading Salt."); Logger.Console.WriteLine("&5 Loading Salt..."); Database.LoadSalt(); Logger.Log.SystemMessage("Loading Settings."); Logger.Console.WriteLine("&5 Loading Settings..."); Database.Settings.LoadAll(); Database.Security.StartLock.Run(); Logger.Log.SystemMessage("Loading Groups, Ranks, and their Permissions."); Logger.Console.WriteLine("&5 Loading Groups, Ranks, and their Permissions...."); Database.GroupDB.LoadAll(); Logger.Log.SystemMessage("Loading Users, Group References and their Permissions."); Logger.Console.WriteLine("&5 Loading Users, Group References and their Permissions..."); Database.UserDB.LoadAll(); Logger.Console.WriteLine("&5 Loading Commands."); Commands.LoadAll(); if (Database.NewSaltGenerated) { foreach (Database.UserDB.User ThisUser in Database.UserDB.List) { ThisUser.Password = ""; ThisUser.UsePassword = false; ThisUser.SaveAll(); } if (Database.UserDB.List.Count() > 0) { Logger.Console.WriteLine("&d Because new Salt was generated, all passwords for all users have been reset!"); } else { if (Database.UserDB.List.Count() == 0 && Database.GroupDB.List.Count() == 0) { #region Create Defaults //No Users or Groups in the database, and no orb.dll? sound like a first launch to me! //Create The ADMIN Database.UserDB.User AdminUser = Database.UserDB.New("Admin"); Database.UserDB.User ModUser = Database.UserDB.New("Mod"); Database.GroupDB.Group ServerGroup = Database.GroupDB.New("SERVER"); Database.GroupDB.Group.Rank AdminRank = ServerGroup.NewRank("ADMIN"); Database.GroupDB.Group.Rank ModRank = ServerGroup.NewRank("MOD"); AdminRank.Permissions.MakeSuper(); ModRank.Permissions.MakeModerator(); Database.UserDB.User.GroupReference AdminUserGR = AdminUser.AddToGroup(ServerGroup); Database.UserDB.User.GroupReference ModUserGR = ModUser.AddToGroup(ServerGroup); AdminUserGR.Rank = AdminRank; ModUserGR.Rank = ModRank; AdminUser.GroupRepresented = ServerGroup; ModUser.GroupRepresented = ServerGroup; AdminUser.SaveAll(); ModUser.SaveAll(); ServerGroup.Founder = AdminUser; ServerGroup.SaveAll(); #endregion Logger.Console.WriteLine("&d Default Groups/Users instated!"); Version.WriteNewToOrbHelpFile(); } } } Logger.Console.WriteLine("&5 Loading Complete!"); Utilities.WelcomeFile.WriteDefault(); //Thread.Sleep(5000); //Logger.Console.WriteLine(DateTime.Now.ToString()); //DISPLAY DATABASE RESULTS //Logger.Console.Write(Utilities.IO.GetAllGroupsRanks()); //Logger.Console.WriteLine(); //Logger.Console.Write(Utilities.IO.GetAllUsersGroups()); //Logger.Console.WriteLine(); //Database.PermissionDB.PermissionsCore.CheckPermission(Database.UserDB.Find("BAWB"), "Default"); //SAVE DATABASE //Database.GroupDB.SaveAll(); //Database.UserDB.SaveAll(); //Database.Settings.SaveAll(); //RUN SERVER //ServerGUI.ClearLog(); //Logger.Console.WriteLine("&bLAGSWITCH100SECONDSIMPLEMENTED"); //Thread.Sleep(100000); #if !DEBUG Logger.Log.SystemMessage("STARTING SERVER"); Logger.Console.WriteLine("&9STARTING SERVER."); Thread.Sleep(1000); Logger.Console.ClearLine(); Logger.Console.WriteLine("&9STARTING SERVER.."); Thread.Sleep(1000); Logger.Console.ClearLine(); Logger.Console.WriteLine("&9STARTING SERVER..."); Thread.Sleep(1000); Logger.Console.ClearLine(); //Thread.Sleep(50000); #endif Logger.Console.Clear(); //Logger.Console.WriteLine(Database.Settings.ServerIP.ToString()); //Logger.Console.WriteLine(Database.Settings.ServerPort.ToString()); Server.Start(); //SHUTDOWN //Server.Shutdown.MasterClose("Test Complete", 10); }
public static bool Orb_Command_Maintenence_Group_Users_Demote_Method(Server.NetObject NetObj, CommandReader Command) { Database.UserDB.User TargetUser = Database.UserDB.Nobody; Database.GroupDB.Group TargetGroup = Database.GroupDB.NoGroup; Database.GroupDB.Group.Rank TargetRank = Database.GroupDB.NoRank; Database.GroupDB.Group.Rank CurrentRank = Database.GroupDB.NoRank; int CurrentRankInt; int TargetRankInt; string Reason = ""; #region FindTargetUser if (Command._CmdArguments.Count() < 1) { NetObj.ClientObject.SendMessage("No user specified to demote."); return(false); } if (Command._CmdArguments[0] == "-") { if (NetObj.CommandHandling.PreviousUser == Database.UserDB.Nobody) { NetObj.ClientObject.SendMessage("No previous users iterated over."); return(false); } else { TargetUser = NetObj.CommandHandling.PreviousUser; } } else { if (Database.UserDB.Find(Command._CmdArguments[0]) != Database.UserDB.Nobody) { TargetUser = Database.UserDB.Find(Command._CmdArguments[0]); } else { NetObj.ClientObject.SendMessage("User not found: \"" + Command._CmdArguments[0] + "\"."); return(false); } } #endregion #region FindTargetGroup if (Command._CmdElements()[1] == "-") { if (NetObj.CommandHandling.PreviousGroup == Database.GroupDB.NoGroup) { NetObj.ClientObject.SendMessage("No previous groups iterated over."); return(false); } else { TargetGroup = NetObj.CommandHandling.PreviousGroup; } } else { if (Database.GroupDB.FindGroup(Command._CmdElements()[1]) == Database.GroupDB.NoGroup) { NetObj.ClientObject.SendMessage("Group not found: \"" + Command._CmdElements()[1] + "\"."); return(false); } TargetGroup = Database.GroupDB.FindGroup(Command._CmdElements()[1]); } #endregion #region TargetIsInGroup? if (!(TargetUser.Groups.Select(x => x.Group).Contains(TargetGroup))) { //User NOT in the group. NetObj.ClientObject.SendMessage("User \"" + TargetUser.Name + "\" is not a member of Group \"" + TargetGroup.Name + "\". They cannot be promoted without being a member first."); return(false); } CurrentRank = TargetUser.Groups.First(x => x.Group == TargetGroup).Rank; CurrentRankInt = TargetGroup.Ranks.IndexOf(TargetUser.Groups.First(y => y.Group == TargetGroup).Rank); #endregion #region FindTargetRank if (Command._CmdArguments.Count() < 2) { //TargetUser.Groups.First(x => x.Group == TargetGroup).Group.Ranks.IndexOf(TargetUser.Groups.First(x => x.Group == TargetGroup).Rank); //USERS CURRENT RANK; //Logger.Console.WriteLine(CurrentRankInt.ToString()); //Logger.Console.WriteLine((TargetUser.Groups.First(x => x.Group == TargetGroup).Group.Ranks.Count() - 1).ToString()); if (CurrentRankInt <= 0) { //Users current rank IS the lowest rank, cannot demote any lower. TargetRank = Database.GroupDB.NoRank; NetObj.ClientObject.SendMessage("User \"" + TargetUser.Name + "\" is already the lowest rank of Group \"" + TargetGroup.Name + "\". They cannot be demoted any lower."); return(false); } else { //There is a rank below this one, set that as the target. TargetRank = TargetUser.Groups.First(x => x.Group == TargetGroup).Group.Ranks[CurrentRankInt - 1]; TargetRankInt = CurrentRankInt - 1; } } else { if (TargetGroup.FindRank(Command._CmdArguments[1]) == Database.GroupDB.NoRank) { NetObj.ClientObject.SendMessage("Rank \"" + Command._CmdArguments[1] + "\" not found in Group: \"" + TargetGroup.Name + "\"."); return(false); } TargetRank = TargetGroup.FindRank(Command._CmdArguments[1]); TargetRankInt = TargetGroup.Ranks.IndexOf(TargetRank); } if (TargetRank == Database.GroupDB.NoRank) { NetObj.ClientObject.SendMessage("Rank \"" + Command._CmdArguments[1] + "\" not found in Group: \"" + TargetGroup.Name + "\"."); return(false); } if (TargetRankInt > CurrentRankInt) { NetObj.ClientObject.SendMessage("Rank: \"" + TargetRank.Name + "\" is higher then Rank: \"" + CurrentRank.Name + "\" in Group: \"" + TargetGroup.Name + "\". Use the /Promote Command instead."); return(false); } #endregion #region RankReason? if (Command._CmdArguments.Count() >= 3) { Reason = Command._CmdRawArguments.Split(new string[] { " " }, 3, StringSplitOptions.None)[2]; } #endregion #region SuperUser Override if (NetObj.UserObject == Database.UserDB.SuperUser || NetObj.UserObject == TargetGroup.Founder) { //continue } #endregion #region Standard Testing else { if (NetObj.UserObject.Groups.Select(x => x.Group).Contains(TargetGroup)) { //THIS User is a member of the group. (Required to be able to modify the group. Database.UserDB.User.GroupReference ThisGroupReference = NetObj.UserObject.Groups.First(x => x.Group == TargetGroup); if (ThisGroupReference.Rank.Permissions.Group_ManageMembers <= 0) { NetObj.ClientObject.SendMessage("Your rank does not have permission to manage group memebers in this group."); return(false); } if (ThisGroupReference.Rank.Permissions.Group_DemoteableRank < 0) { NetObj.ClientObject.SendMessage("You are not able to demote members in the group as you do not have permission to demote from the lowest rank in the group."); return(false); } if (ThisGroupReference.Rank.Permissions.Group_DemoteableRank < CurrentRankInt) //<0 No Member. { NetObj.ClientObject.SendMessage("You are not able to demote User: \"" + TargetUser.Name + "\" as your Rank: \"" + NetObj.UserObject.Groups.First(x => x.Group == TargetGroup).Rank.Name + "\" is unable to demote Rank: \"" + TargetRank.Name + "\" in Group: \"" + TargetGroup.Name + "\"."); return(false); } //continue } else { NetObj.ClientObject.SendMessage("You need to be a member of the group yourself in order to demote members. (Group founders are excepted from this rule.)"); return(false); } } #endregion Orb_Command_Maintenence_Group_Users_Rank_Common_Method(NetObj, TargetUser, TargetGroup, TargetRank, Reason); return(true); }
public static bool Orb_Command_Maintenence_Group_Ranks_Remove_Method(Server.NetObject NetObj, CommandReader Command) { Database.GroupDB.Group TargetGroup = Database.GroupDB.NoGroup; Database.GroupDB.Group.Rank TargetRank = Database.GroupDB.NoRank; string TargetRankName = ""; #region FindTargetGroup if (Command._CmdElements()[1] == "-") { if (NetObj.CommandHandling.PreviousGroup == Database.GroupDB.NoGroup) { NetObj.ClientObject.SendMessage("No previous groups iterated over."); return(false); } else { TargetGroup = NetObj.CommandHandling.PreviousGroup; } } else { if (Database.GroupDB.FindGroup(Command._CmdElements()[1]) == Database.GroupDB.NoGroup) { NetObj.ClientObject.SendMessage("Group not found: \"" + Command._CmdElements()[1] + "\"."); return(false); } TargetGroup = Database.GroupDB.FindGroup(Command._CmdElements()[1]); } #endregion #region FindTargetRank if (Command._CmdArguments.Count() < 1) { NetObj.ClientObject.SendMessage("No rank specified to be removed from the group."); return(false); } else { if (TargetGroup.Ranks.Select(x => x.Name.ToUpperInvariant()).Contains(Command._CmdArguments[0].ToUpperInvariant())) { TargetRank = TargetGroup.Ranks.First(x => x.Name.ToUpperInvariant() == Command._CmdArguments[0].ToUpperInvariant()); } else { NetObj.ClientObject.SendMessage("Rank not found: \"" + Command._CmdArguments[0] + "\"."); return(false); } } #endregion #region SuperUser Override if (NetObj.UserObject == Database.UserDB.SuperUser || NetObj.UserObject == TargetGroup.Founder) { //continue } #endregion #region Standard Testing if (NetObj.UserObject.Groups.Select(x => x.Group).Contains(TargetGroup)) { //THIS User is a member of the group. (Required to be able to modify the group. Database.UserDB.User.GroupReference ThisGroupReference = NetObj.UserObject.Groups.Where(x => x.Group == TargetGroup).ToArray()[0]; if (ThisGroupReference.Rank.Permissions.Group_ManageMembers <= 0) { NetObj.ClientObject.SendMessage("Your rank does not have permission to manage group ranks in this group."); return(false); } //continue } else { NetObj.ClientObject.SendMessage("You need to be a member of the group yourself in order to remove ranks. (Group founders are excepted from this rule.)"); return(false); } #endregion TargetRankName = TargetRank.Name; if (!(TargetGroup.Ranks.Contains(TargetRank))) { NetObj.ClientObject.SendMessage("Rank: \"" + TargetRank.Name + "\" not found in Group: \"" + TargetGroup.Name + "\"."); return(false); } NetObj.ClientObject.SendMessage("You are about to remove Rank: \"" + TargetRank.Name + "\" from Group: \"" + TargetGroup.Name + "\"."); NetObj.ClientObject.SendMessage("THIS IS NOT REVERSABLE!"); NetObj.ClientObject.SendMessage("Please confirm this action by typing \"/OK\"."); if (!NetObj.GetCommandConfirmation(5000)) { NetObj.ClientObject.SendMessage("No response, command cancelled."); return(false); } TargetGroup.RemoveRankFromGroup(TargetRank); TargetGroup.SaveAll(); Server.EmptyClientList.Include(NetObj).SendMessage("You removed Rank: \"" + TargetRankName + "\" from Group: \"" + TargetGroup.Name + "\"."); Server.AllClients.Except(NetObj).SendMessage("Rank: \"" + TargetRankName + "\" was removed from Group: \"" + TargetGroup.Name + "\" by \"" + NetObj.UserObject.Name + "\"."); return(true); }
private static void Orb_Command_Maintenence_Group_Users_Rank_Common_Method(Server.NetObject NetObj, Database.UserDB.User TargetUser, Database.GroupDB.Group TargetGroup, Database.GroupDB.Group.Rank TargetRank, string Reason) { if (TargetUser.Groups.First(x => x.Group == TargetGroup).Rank == TargetRank) { NetObj.ClientObject.SendMessage("User: \"" + TargetUser.Name + "\" is already Rank \"" + TargetRank.Name + "\" in Group: \"" + TargetGroup.Name + "\"."); return; } TargetUser.Groups.First(x => x.Group == TargetGroup).PreviousRank = TargetUser.Groups.First(x => x.Group == TargetGroup).Rank; TargetUser.Groups.First(x => x.Group == TargetGroup).Rank = TargetRank; TargetUser.Groups.First(x => x.Group == TargetGroup).RankDate = DateTime.Now; TargetUser.Groups.First(x => x.Group == TargetGroup).RankedBy = NetObj.UserObject; TargetUser.Groups.First(x => x.Group == TargetGroup).RankReason = Reason; TargetUser.SaveAll(); string RankType; if (TargetUser.Groups.First(x => x.Group == TargetGroup).Group.Ranks.IndexOf(TargetUser.Groups.First(y => y.Group == TargetGroup).PreviousRank) < TargetUser.Groups.First(a => a.Group == TargetGroup).Group.Ranks.IndexOf(TargetUser.Groups.First(y => y.Group == TargetGroup).Rank)) { //Complex Lamba Much? This just menas if previous rank was lower then current rank... RankType = "Promoted"; } else { RankType = "Demoted"; } Server.EmptyClientList.Include(TargetUser).SendMessage("You were " + RankType + " from Rank: \"" + TargetUser.Groups.First(x => x.Group == TargetGroup).PreviousRank.Name + "\" to Rank: \"" + TargetUser.Groups.First(x => x.Group == TargetGroup).Rank.Name + "\" in Group: \"" + TargetGroup.Name + "\" by \"" + NetObj.UserObject.Name + "\"."); Server.AllClients.Except(TargetUser).SendMessage("User: \"" + TargetUser.Name + "\" was " + RankType + " from Rank: \"" + TargetUser.Groups.First(x => x.Group == TargetGroup).PreviousRank.Name + "\" to Rank: \"" + TargetUser.Groups.First(x => x.Group == TargetGroup).Rank.Name + "\" in Group: \"" + TargetGroup.Name + "\" by \"" + NetObj.UserObject.Name + "\"."); if (Reason.Length > 0) { Server.EmptyClientList.Include(TargetUser).SendMessage("Reason: \"" + Reason + "\"."); Server.AllClients.Except(TargetUser).SendMessage("Reason: \"" + Reason + "\"."); } return; }