Esempio n. 1
0
        /// <summary>
        /// Sets the permissions for a specific player (checks server side, sends event to client side).
        /// </summary>
        /// <param name="player"></param>
        public static void SetPermissionsForPlayer([FromSource] Player player)
        {
            if (player == null)
            {
                return;
            }

            Dictionary <Permission, bool> perms = new Dictionary <Permission, bool>();

            // If enabled in the permissions.cfg (disabled by default) then this will give me (only me) the option to trigger some debug commands and
            // try out menu options. This only works if I'm in-game on your server, and you have enabled server debugging mode, this way I will never
            // be able to do something without you actually allowing it.
            if (player.Identifiers.ToList().Any(id => id == "4510587c13e0b645eb8d24bc104601792277ab98") && IsPlayerAceAllowed(player.Handle, "vMenu.Dev") && ConfigManager.DebugMode)
            {
                perms.Add(Permission.Everything, true);
            }

            if (!ConfigManager.GetSettingsBool(ConfigManager.Setting.vmenu_use_permissions))
            {
                foreach (var p in Enum.GetValues(typeof(Permission)))
                {
                    Permission permission = (Permission)p;
                    switch (permission)
                    {
                    // don't allow any of the following permissions if perms are ignored.
                    case Permission.Everything:
                    case Permission.OPAll:
                    case Permission.OPKick:
                    case Permission.OPKill:
                    case Permission.OPPermBan:
                    case Permission.OPTempBan:
                    case Permission.OPUnban:
                    case Permission.OPIdentifiers:
                    case Permission.OPViewBannedPlayers:
                        break;

                    // do allow the rest
                    default:
                        perms.Add(permission, true);
                        break;
                    }
                }
            }
            else
            {
                // Loop through all permissions and check if they're allowed.
                foreach (var p in Enum.GetValues(typeof(Permission)))
                {
                    Permission permission = (Permission)p;
                    if (!perms.ContainsKey(permission))
                    {
                        perms.Add(permission, IsAllowed(permission, player)); // triggers IsAllowedServer
                    }
                }
            }

            // Send the permissions to the client.
            player.TriggerEvent("vMenu:SetPermissions", Newtonsoft.Json.JsonConvert.SerializeObject(perms));

            // Also tell the client to do the addons setup.
            player.TriggerEvent("vMenu:SetAddons");
            player.TriggerEvent("vMenu:UpdateTeleportLocations", Newtonsoft.Json.JsonConvert.SerializeObject(ConfigManager.GetTeleportLocationsData()));
        }
Esempio n. 2
0
        /// <summary>
        /// Sets the permissions for a specific player (checks server side, sends event to client side).
        /// </summary>
        /// <param name="player"></param>
        public static void SetPermissionsForPlayer([FromSource] Player player)
        {
            if (player == null)
            {
                return;
            }

            Dictionary <Permission, bool> perms = new Dictionary <Permission, bool>();

            if (!ConfigManager.GetSettingsBool(ConfigManager.Setting.vmenu_use_permissions))
            {
                foreach (var p in Enum.GetValues(typeof(Permission)))
                {
                    Permission permission = (Permission)p;
                    switch (permission)
                    {
                    // don't allow any of the following permissions if perms are ignored.
                    case Permission.Everything:
                    case Permission.OPAll:
                    case Permission.OPKick:
                    case Permission.OPKill:
                    case Permission.OPPermBan:
                    case Permission.OPTempBan:
                    case Permission.OPUnban:
                    case Permission.OPIdentifiers:
                    case Permission.OPViewBannedPlayers:
                        break;

                    // do allow the rest
                    default:
                        perms.Add(permission, true);
                        break;
                    }
                }
            }
            else
            {
                // Loop through all permissions and check if they're allowed.
                foreach (var p in Enum.GetValues(typeof(Permission)))
                {
                    Permission permission = (Permission)p;
                    if (!perms.ContainsKey(permission))
                    {
                        perms.Add(permission, IsAllowed(permission, player)); // triggers IsAllowedServer
                    }
                }
            }

            // Send the permissions to the client.
            player.TriggerEvent("vMenu:SetPermissions", Newtonsoft.Json.JsonConvert.SerializeObject(perms));

            // Also tell the client to do the addons setup.
            player.TriggerEvent("vMenu:SetAddons");
            player.TriggerEvent("vMenu:UpdateTeleportLocations", Newtonsoft.Json.JsonConvert.SerializeObject(ConfigManager.GetTeleportLocationsData()));
        }