public void UpdatePlayerPermissions(string playerName, Perms permissions) { lock (playersByPlayerName) { playersByPlayerName[playerName].Permissions = permissions; } }
public void ProcessCommand(string msg, Optional <Player> player, Perms perms) { if (string.IsNullOrWhiteSpace(msg)) { return; } string[] parts = msg.Split() .Where(arg => !string.IsNullOrEmpty(arg)) .ToArray(); Command cmd; if (!commands.TryGetValue(parts[0], out cmd)) { string errorMessage = "Command Not Found: " + parts[0]; Log.Info(errorMessage); if (player.IsPresent()) { player.Get().SendPacket(new ChatMessage(ChatMessage.SERVER_ID, errorMessage)); } return; } if (perms >= cmd.RequiredPermLevel) { RunCommand(cmd, parts, player); } else { cmd.SendServerMessageIfPlayerIsPresent(player, "You do not have the required permissions for this command!"); } }
public void AddPerm(String perm) { if (!Perms.Contains(perm.ToLower())) { Perms.Add(perm.ToLower()); } }
protected override void Execute(CallArgs args) { Player targetPlayer = args.Get <Player>(0); Perms permissions = args.Get <Perms>(1); if (args.SenderName == targetPlayer.Name) { SendMessage(args.Sender, "You can't promote yourself"); return; } //Allows a bounded permission hierarchy if (args.IsConsole || permissions < args.Sender.Value.Permissions) { targetPlayer.Permissions = permissions; // TODO: Send a packet to the player to acknowledge the permision level change SendMessage(args.Sender, $"Updated {targetPlayer.Name}\'s permissions to {permissions}"); SendMessageToPlayer(targetPlayer, $"You've been promoted to {permissions}"); } else { SendMessage(args.Sender, $"You're not allowed to update {targetPlayer.Name}\'s permissions"); } }
public void DelPerm(String perm) { if (Perms.Contains(perm.ToLower())) { Perms.Remove(perm.ToLower()); } }
public string GetSaveSummary(Perms viewerPerms = Perms.CONSOLE) { // TODO: Extend summary with more useful save file data // Note for later additions: order these lines by their length StringBuilder builder = new("\n"); if (viewerPerms is Perms.CONSOLE) { builder.AppendLine($" - Save location: {Path.GetFullPath(serverConfig.SaveName)}"); } builder.AppendLine($" - Aurora's state: {world.EventTriggerer.GetAuroraStateSummary()}"); builder.AppendLine($" - Current time: day {world.EventTriggerer.Day} ({Math.Floor(world.EventTriggerer.ElapsedSeconds)}s)"); builder.AppendLine($" - Scheduled goals stored: {world.GameData.StoryGoals.ScheduledGoals.Count}"); builder.AppendLine($" - Story goals completed: {world.GameData.StoryGoals.CompletedGoals.Count}"); builder.AppendLine($" - Radio messages stored: {world.GameData.StoryGoals.RadioQueue.Count}"); builder.AppendLine($" - World gamemode: {serverConfig.GameMode}"); builder.AppendLine($" - Story goals unlocked: {world.GameData.StoryGoals.GoalUnlocks.Count}"); builder.AppendLine($" - Encyclopedia entries: {world.GameData.PDAState.EncyclopediaEntries.Count}"); builder.AppendLine($" - Storage slot items: {world.InventoryManager.GetAllStorageSlotItems().Count}"); builder.AppendLine($" - Inventory items: {world.InventoryManager.GetAllInventoryItems().Count}"); builder.AppendLine($" - Progress tech: {world.GameData.PDAState.CachedProgress.Count}"); builder.AppendLine($" - Known tech: {world.GameData.PDAState.KnownTechTypes.Count}"); builder.AppendLine($" - Vehicles: {world.VehicleManager.GetVehicles().Count()}"); return(builder.ToString()); }
public void ProcessCommand(string msg, Optional <Player> player, Perms perms) { if (string.IsNullOrWhiteSpace(msg)) { return; } string[] parts = msg.Split(splitChar, StringSplitOptions.RemoveEmptyEntries); if (!commands.TryGetValue(parts[0], out Command cmd)) { string errorMessage = "Command Not Found: " + parts[0]; Log.Info(errorMessage); if (player.HasValue) { player.Value.SendPacket(new ChatMessage(ChatMessage.SERVER_ID, errorMessage)); } return; } if (perms >= cmd.RequiredPermLevel) { RunCommand(cmd, player, parts); } else { cmd.SendMessageToPlayer(player, "You do not have the required permissions for this command!"); } }
private List <string> GetHelpText(Perms perm) { // runtime query to avoid circular dependencies IEnumerable <Command> commands = NitroxModel.Core.NitroxServiceLocator.LocateService <IEnumerable <Command> >(); SortedSet <Command> sortedCommands = new SortedSet <Command>(commands.Where(cmd => cmd.RequiredPermLevel <= perm), new CommandComparer()); return(new List <string>(sortedCommands.Select(cmd => cmd.ToHelpText()))); }
private List <string> GetHelpText(Perms permThreshold, bool cropText) { //Runtime query to avoid circular dependencies IEnumerable <Command> commands = NitroxServiceLocator.LocateService <IEnumerable <Command> >(); return(new List <string>(commands.Where(cmd => cmd.CanExecute(permThreshold)) .OrderByDescending(cmd => cmd.Name) .Select(cmd => cmd.ToHelpText(cropText)))); }
private List <string> GetHelpText(Perms perm) { // runtime query to avoid circular dependencies IEnumerable <Command> commands = NitroxModel.Core.NitroxServiceLocator.LocateService <IEnumerable <Command> >(); return(new List <string>(commands.Where(cmd => cmd.RequiredPermLevel <= perm) .OrderByDescending(cmd => cmd.Name) .Select(cmd => cmd.ToHelpText()))); }
protected Command(string name, Perms perm, string description, bool allowedArgOveflow = false) { Validate.NotNull(name); Name = name; RequiredPermLevel = perm; Parameters = new List <IParameter <object> >(); AllowedArgOverflow = allowedArgOveflow; Description = string.IsNullOrEmpty(description) ? "No description provided" : description; }
protected Command(string name, Perms requiredPermLevel, string argsDescription, string description, string[] alias) { Validate.NotNull(name); Validate.NotNull(argsDescription); Name = name; Description = string.IsNullOrEmpty(description) ? "No description" : description; ArgsDescription = argsDescription; RequiredPermLevel = requiredPermLevel; Alias = alias ?? new string[0]; }
protected Command(string name, Perms requiredPermLevel, string argsDescription, string description, string[] alias) { Validate.NotNull(name); Validate.NotNull(argsDescription); Name = name; Description = description ?? ""; ArgsDescription = argsDescription; RequiredPermLevel = requiredPermLevel; Alias = alias ?? new string[0]; }
protected Command(string name, Perms perms, string description) { Validate.NotNull(name); Name = name; Flags = PermsFlag.NONE; RequiredPermLevel = perms; AllowedArgOverflow = false; Aliases = Array.Empty <string>(); Parameters = new List <IParameter <object> >(); Description = string.IsNullOrEmpty(description) ? "No description provided" : description; }
public Player(ushort id, string name, PlayerContext playerContext, NitroxConnection connection, Vector3 position, NitroxId playerId, Optional <NitroxId> subRootId, Perms perms, List <EquippedItemData> equippedItems, List <EquippedItemData> modules) { Id = id; Name = name; PlayerContext = playerContext; this.connection = connection; Position = position; SubRootId = subRootId; GameObjectId = playerId; Permissions = perms; this.equippedItems = equippedItems; this.modules = modules; }
public override void Process(PlayerJoiningMultiplayerSession packet, NitroxConnection connection) { bool wasBrandNewPlayer; Player player = playerManager.CreatePlayer(connection, packet.ReservationKey, out wasBrandNewPlayer); timeKeeper.SendCurrentTimePacket(player); Optional <EscapePodModel> newlyCreatedEscapePod; NitroxId assignedEscapePodId = world.EscapePodManager.AssignPlayerToEscapePod(player.Id, out newlyCreatedEscapePod); if (newlyCreatedEscapePod.IsPresent()) { AddEscapePod addEscapePod = new AddEscapePod(newlyCreatedEscapePod.Get()); playerManager.SendPacketToOtherPlayers(addEscapePod, player); } List <EquippedItemData> equippedItems = world.PlayerData.GetEquippedItemsForInitialSync(player.Name); List <TechType> techTypes = equippedItems.Select(equippedItem => equippedItem.TechType).ToList(); PlayerJoinedMultiplayerSession playerJoinedPacket = new PlayerJoinedMultiplayerSession(player.PlayerContext, techTypes); playerManager.SendPacketToOtherPlayers(playerJoinedPacket, player); // Make players on localhost admin by default. if (IPAddress.IsLoopback(connection.Endpoint.Address)) { world.PlayerData.SetPermissions(player.Name, Perms.ADMIN); } Perms initialPerms = world.PlayerData.GetPermissions(player.Name); InitialPlayerSync initialPlayerSync = new InitialPlayerSync(player.GameObjectId, wasBrandNewPlayer, world.EscapePodData.EscapePods, assignedEscapePodId, equippedItems, world.BaseData.GetBasePiecesForNewlyConnectedPlayer(), world.VehicleData.GetVehiclesForInitialSync(), world.InventoryData.GetAllItemsForInitialSync(), world.InventoryData.GetAllStorageItemsForInitialSync(), world.GameData.PDAState.GetInitialPdaData(), world.GameData.StoryGoals.GetInitialStoryGoalData(), world.PlayerData.GetPlayerSpawn(player.Name), world.PlayerData.GetSubRootId(player.Name), world.PlayerData.GetPlayerStats(player.Name), getRemotePlayerData(player), world.EntityData.GetGlobalRootEntities(), world.GameMode, initialPerms); player.SendPacket(initialPlayerSync); }
public Player(ushort id, string name, PlayerContext playerContext, NitroxConnection connection, Vector3 position, NitroxId playerId, Optional <NitroxId> subRootId, Perms perms, PlayerStatsData stats, IEnumerable <EquippedItemData> equippedItems, IEnumerable <EquippedItemData> modules) { Id = id; Name = name; PlayerContext = playerContext; this.connection = connection; Position = position; SubRootId = subRootId; GameObjectId = playerId; Permissions = perms; Stats = stats; this.equippedItems = new ThreadSafeCollection <EquippedItemData>(equippedItems); this.modules = new ThreadSafeCollection <EquippedItemData>(modules); }
public bool UpdatePlayerPermissions(string playerName, Perms permissions) { lock (playersByPlayerName) { PersistedPlayerData player; if (playersByPlayerName.TryGetValue(playerName, out player)) { player.Permissions = permissions; return(true); } } return(false); }
public static AprFile Open(string fname, Flags flag, Perms perm, AprPool pool) { IntPtr ptr; Debug.Write(String.Format("apr_file_open({0},{1},{2},{3})...", fname, flag, perm, pool)); int res = Apr.apr_file_open(out ptr, fname, (int)flag, (int)perm, pool); if (res != 0) { throw new AprException(res); } Debug.WriteLine(String.Format("Done({0:X})", ((Int32)ptr))); return(ptr); }
protected Command(string name, Perms requiredPermLevel, Optional <string> args, string description, string[] alias) { Validate.NotNull(name); Validate.NotNull(args); Name = name; if (args.IsEmpty()) { args = Optional <string> .Of(name); } Description = description ?? ""; Args = args; Alias = alias ?? new string[0]; }
public InitialPlayerSync(NitroxId playerGameObjectId, bool firstTimeConnecting, IEnumerable <EscapePodModel> escapePodsData, NitroxId assignedEscapePodId, IEnumerable <EquippedItemData> equipment, IEnumerable <EquippedItemData> modules, IEnumerable <BasePiece> basePieces, IEnumerable <VehicleModel> vehicles, IEnumerable <ItemData> inventoryItems, IEnumerable <ItemData> storageSlotItems, IEnumerable <NitroxTechType> usedItems, IEnumerable <string> quickSlotsBinding, InitialPDAData pdaData, InitialStoryGoalData storyGoalData, HashSet <string> completedGoals, NitroxVector3 playerSpawnData, Optional <NitroxId> playerSubRootId, PlayerStatsData playerStatsData, IEnumerable <InitialRemotePlayerData> remotePlayerData, IEnumerable <Entity> globalRootEntities, IEnumerable <NitroxId> initialSimulationOwnerships, ServerGameMode gameMode, Perms perms) { EscapePodsData = escapePodsData.ToList(); AssignedEscapePodId = assignedEscapePodId; PlayerGameObjectId = playerGameObjectId; FirstTimeConnecting = firstTimeConnecting; EquippedItems = equipment.ToList(); Modules = modules.ToList(); BasePieces = basePieces.ToList(); Vehicles = vehicles.ToList(); InventoryItems = inventoryItems.ToList(); StorageSlotItems = storageSlotItems.ToList(); UsedItems = usedItems.ToList(); QuickSlotsBinding = quickSlotsBinding.ToList(); PDAData = pdaData; StoryGoalData = storyGoalData; CompletedGoals = completedGoals; PlayerSpawnData = playerSpawnData; PlayerSubRootId = playerSubRootId; PlayerStatsData = playerStatsData; RemotePlayerData = remotePlayerData.ToList(); GlobalRootEntities = globalRootEntities.ToList(); InitialSimulationOwnerships = initialSimulationOwnerships.ToList(); GameMode = gameMode; Permissions = perms; }
public Admin(string username, string password, Perms perms = Perms.None) : this() { Username = username; Perms = perms; SHA256 sha = SHA256.Create(); byte[] hash = sha.ComputeHash(Encoding.UTF8.GetBytes(password)); StringBuilder builder = new StringBuilder(); for (int i = 0; i < hash.Length; i++) { builder.Append(hash[i].ToString("x2")); } Password = builder.ToString(); }
// [TypeFilter(typeof(CheckPermissionFilter), Arguments = new[] { PermissionsName.ManageACL, "" })] public virtual ActionResult PermissionsSave([FromBody] Perms perms) { JsonResultHelper result = new JsonResultHelper(); List <int> removeList = new List <int>(); List <int> addList = new List <int>(); List <int> unionList = new List <int>(); List <int> olddaa = _userRoleRepository.GetAllUserRolePermissionByUserRoleId(perms.UserRoleId); unionList = olddaa.Union(perms.Permissions.ToList()).ToList(); removeList = unionList.Except(perms.Permissions.ToList()).ToList(); addList = unionList.Except(olddaa).ToList(); UserRole tempUserRole = _userRoleRepository.GetById(perms.UserRoleId); if (!_permissionUser.CheckAccess(PermissionsName.PermissionAdd)) { return(AccessDeniedJson()); } //Add New Permission For Current User Role addList.ForEach(p => { PermUserRoleMap entity = new PermUserRoleMap(); entity.UserRole = tempUserRole; entity.Permission = _permissionUser.GetById(p); tempUserRole.fk_UserRolePermMap.Add(entity); }); if (!_permissionUser.CheckAccess(PermissionsName.PermissionDelete)) { return(AccessDeniedJson()); } //Remove Permission For Current User Role removeList.ForEach(p => { var tempPerm = tempUserRole.fk_UserRolePermMap.Where(a => a.PermId == p && a.UserRoleId == tempUserRole.Id).FirstOrDefault(); tempUserRole.fk_UserRolePermMap.Remove(tempPerm); }); _userRoleRepository.Update(tempUserRole); //RemoveList = unionList.RemoveAll(i => perms.Contains(i)); //AddList = unionList.RemoveAll(j => olddaa.Contains(j)); result.Access = true; //result.Msg.Add(_localizationService.GetResource("Admin.Configuration.ACL.Updated")); result.success = true; result.url = perms.continueEditing ? string.Empty : Url.Action("Index", "Dashboard"); return(Json(result)); }
public Player(ushort id, string name, bool isPermaDeath, PlayerContext playerContext, NitroxConnection connection, Vector3 position, NitroxId playerId, Optional <NitroxId> subRootId, Perms perms, PlayerStatsData stats, IEnumerable <EquippedItemData> equippedItems, IEnumerable <EquippedItemData> modules) { Id = id; Name = name; IsPermaDeath = isPermaDeath; PlayerContext = playerContext; this.connection = connection; Position = position; SubRootId = subRootId; GameObjectId = playerId; Permissions = perms; Stats = stats; LastStoredPosition = null; this.equippedItems = new ThreadSafeCollection <EquippedItemData>(equippedItems); this.modules = new ThreadSafeCollection <EquippedItemData>(modules); visibleCells = new ThreadSafeCollection <AbsoluteEntityCell>(new HashSet <AbsoluteEntityCell>(), false); }
public void ProcessCommand(string msg, Player player, Perms perms) { if (string.IsNullOrWhiteSpace(msg)) { return; } Optional <Player> optionalPlayer = Optional <Player> .OfNullable(player); string[] parts = msg.Split() .Where(arg => !string.IsNullOrEmpty(arg)) .ToArray(); Command cmd; if (!commands.TryGetValue(parts[0], out cmd)) { if (optionalPlayer.IsPresent()) { optionalPlayer.Get().SendPacket(new ChatMessage(ChatMessage.SERVER_ID, "Command not found!")); } else { Log.Info(string.Format("Command not found!")); } return; } if (perms >= cmd.RequiredPermLevel) { RunCommand(cmd, parts, optionalPlayer); } else { if (optionalPlayer.IsPresent()) { optionalPlayer.Get().SendPacket(new ChatMessage(ChatMessage.SERVER_ID, "You do not have the required permissions for this command!")); } else { Log.Info(string.Format("You do not have the required permissions for this command!")); } } }
private List <string> GetHelpText(Perms permThreshold, bool cropText, string singleCommand) { //Runtime query to avoid circular dependencies IEnumerable <Command> commands = NitroxServiceLocator.LocateService <IEnumerable <Command> >(); if (singleCommand != null && !commands.Any(cmd => cmd.Name.Equals(singleCommand))) { return(new List <string> { "Command does not exist" }); } List <string> cmdsText = new(); cmdsText.Add(singleCommand != null ? $"=== Showing help for {singleCommand} ===" : "=== Showing command list ==="); cmdsText.AddRange(commands.Where(cmd => cmd.CanExecute(permThreshold) && (singleCommand == null || cmd.Name.Equals(singleCommand))) .OrderByDescending(cmd => cmd.Name) .Select(cmd => cmd.ToHelpText(singleCommand != null, cropText))); return(cmdsText); }
public InitialPlayerSync(string playerGuid, bool firstTimeConnecting, List <EscapePodModel> escapePodsData, string assignedEscapePodGuid, List <EquippedItemData> equipment, List <BasePiece> basePieces, List <VehicleModel> vehicles, List <ItemData> inventoryItems, InitialPdaData pdaData, Vector3 playerSpawnData, Optional <string> playerSubRootGuid, PlayerStatsData playerStatsData, List <InitialRemotePlayerData> remotePlayerData, List <Entity> globalRootEntities, GameModeOption gameMode, Perms perms) { EscapePodsData = escapePodsData; AssignedEscapePodGuid = assignedEscapePodGuid; PlayerGuid = playerGuid; FirstTimeConnecting = firstTimeConnecting; EquippedItems = equipment; BasePieces = basePieces; Vehicles = vehicles; InventoryItems = inventoryItems; PDAData = pdaData; PlayerSpawnData = playerSpawnData; PlayerSubRootGuid = playerSubRootGuid; PlayerStatsData = playerStatsData; RemotePlayerData = remotePlayerData; GlobalRootEntities = globalRootEntities; GameMode = gameMode; Permissions = perms; }
/// <summary> /// The API Build method for BinPerms /// </summary> public void Build(MetricDB db, MetricDB refs, int maxcand=1024, double mod=0.5, bool permcenter=true, Perms idxperms=null) { this.DB = db; this.REFS = refs; this.MAXCAND = maxcand; if (mod < 1) { this.MOD = (int)Math.Ceiling (mod * this.REFS.Count); } else { this.MOD = (int)mod; } this.permcenter = permcenter; var DATA = new List<byte[]>(); if (idxperms == null) { // base.Build (name, spaceClass, spaceName, spacePerms, maxcand); int onepercent = 1 + (this.DB.Count / 100); for (int docID = 0; docID < this.DB.Count; ++docID) DATA.Add (null); int I = 0; var build_one = new Action<int> ((int docID) => { if ((I % onepercent) == 0) { Console.WriteLine ("Generating {0}, db: {1}, num_refs: {2}, docID: {3}, advance {4:0.00}%, timestamp: {5}", this, db.Name, refs.Count, I, I * 100.0 / DATA.Count, DateTime.Now); } var inv = this.ComputeInverse (docID); DATA[docID] = this.Encode(inv); ++I; }); var ops = new ParallelOptions (); ops.MaxDegreeOfParallelism = -1; Parallel.For (0, this.DB.Count, ops, build_one); } else { for (int docid = 0; docid < this.DB.Count; docid++) { var inv = idxperms.GetComputedInverse (docid); DATA.Add(this.Encode(inv)); } } var binperms = new MemMinkowskiVectorDB<byte> (); binperms.Build ("", DATA, 1); var seq = new Sequential (); seq.Build(binperms); this.IndexHamming = seq; }
public InitialPlayerSync(NitroxId playerGameObjectId, bool firstTimeConnecting, List <EscapePodModel> escapePodsData, NitroxId assignedEscapePodId, List <EquippedItemData> equipment, List <BasePiece> basePieces, List <VehicleModel> vehicles, List <ItemData> inventoryItems, List <ItemData> storageSlots, InitialPdaData pdaData, InitialStoryGoalData storyGoalData, Vector3 playerSpawnData, Optional <NitroxId> playerSubRootId, PlayerStatsData playerStatsData, List <InitialRemotePlayerData> remotePlayerData, List <Entity> globalRootEntities, string gameMode, Perms perms) { EscapePodsData = escapePodsData; AssignedEscapePodId = assignedEscapePodId; PlayerGameObjectId = playerGameObjectId; FirstTimeConnecting = firstTimeConnecting; EquippedItems = equipment; BasePieces = basePieces; Vehicles = vehicles; InventoryItems = inventoryItems; StorageSlots = storageSlots; PDAData = pdaData; StoryGoalData = storyGoalData; PlayerSpawnData = playerSpawnData; PlayerSubRootId = playerSubRootId; PlayerStatsData = playerStatsData; RemotePlayerData = remotePlayerData; GlobalRootEntities = globalRootEntities; GameMode = gameMode; Permissions = perms; }
public Player(ushort id, string name, bool isPermaDeath, PlayerContext playerContext, NitroxConnection connection, NitroxVector3 position, NitroxId playerId, Optional <NitroxId> subRootId, Perms perms, PlayerStatsData stats, IEnumerable <NitroxTechType> usedItems, IEnumerable <string> quickSlotsBinding, IEnumerable <EquippedItemData> equippedItems, IEnumerable <EquippedItemData> modules) { Id = id; Name = name; IsPermaDeath = isPermaDeath; PlayerContext = playerContext; Connection = connection; Position = position; SubRootId = subRootId; GameObjectId = playerId; Permissions = perms; Stats = stats; LastStoredPosition = null; LastStoredSubRootID = Optional.Empty; UsedItems = new ThreadSafeList <NitroxTechType>(usedItems); QuickSlotsBinding = new ThreadSafeList <string>(quickSlotsBinding); this.equippedItems = new ThreadSafeList <EquippedItemData>(equippedItems); this.modules = new ThreadSafeList <EquippedItemData>(modules); visibleCells = new ThreadSafeSet <AbsoluteEntityCell>(); }
/// <summary> /// new /// </summary> /// <param name="perms"></param> /// <param name="id"></param> public ACL(Perms perms, ZookID id) { this.Perms = perms; this.ID = id; }
public static AprFile Open(string fname, Flags flag, Perms perm, AprPool pool) { IntPtr ptr; Debug.Write(String.Format("apr_file_open({0},{1},{2},{3})...",fname,flag,perm,pool)); int res = Apr.apr_file_open(out ptr, fname, (int)flag, (int)perm, pool); if(res != 0 ) throw new AprException(res); Debug.WriteLine(String.Format("Done({0:X})",((Int32)ptr))); return(ptr); }
public bool CanExecute(Perms treshold) { return(RequiredPermLevel <= treshold); }