Esempio n. 1
0
        private void OnCreateScreen([FromSource] Player p, string jsonScreen)
        {
            if (!this.IsPlayerAllowed(p))
            {
                this.AddChatMessage(
                    p,
                    $"Error: You don't have permissions for: command.{this.cmdName}",
                    new[] { 255, 0, 0 });
                return;
            }

            var screen = JsonConvert.DeserializeObject <Screen>(jsonScreen);

            try
            {
                this.screenCollection.EnsureIndex(s => s.Name, true);
                this.screenCollection.EnsureIndex(s => s.AlwaysOn);

                var id = this.screenCollection.Insert(screen);
                screen.Id = id;

                p.TriggerEvent(ClientEvents.CreatedScreen, JsonConvert.SerializeObject(screen));
            }
            catch (Exception e)
            {
                Logger.WriteLine($"failed to create screen. Message: {e.Message}", Logger.LogLevel.Error);
                this.AddChatMessage(p, "Failed to create screen. See server-log for info");
                throw;
            }
        }
Esempio n. 2
0
 private static void RegisterCommand(string cmdName, InputArgument handler, bool restricted)
 {
     try
     {
         API.RegisterCommand(cmdName, handler, restricted);
     }
     catch (Exception e)
     {
         Logger.WriteLine(
             $"failed to register the command {cmdName}. Error: {e.Message}",
             Logger.LogLevel.Error);
         throw;
     }
 }
Esempio n. 3
0
        private void OpenDatabase()
        {
            try
            {
                this.database         = new LiteDatabase(this.connectionString);
                this.screenCollection = this.database.GetCollection <Screen>("screens");

                this.screenCollection.EnsureIndex(s => s.Name, true);
            }
            catch (Exception e)
            {
                Logger.Error($"Failed to open database. error: {e.Message}");
                throw;
            }
        }
Esempio n. 4
0
        private void OnResourceStart(string resourceName)
        {
            if (API.GetCurrentResourceName() != resourceName)
            {
                return;
            }

            this.connectionString = ConfigReader.GetConfigKeyValue(
                resourceName,
                "hypnonema_db_connString",
                0,
                this.connectionString);
            this.cmdName = ConfigReader.GetConfigKeyValue(resourceName, "hypnonema_command_name", 0, this.cmdName)
                           .Replace(" ", string.Empty);
            this.syncInterval        = ConfigReader.GetConfigKeyValue(resourceName, "hypnonema_sync_interval", 0, this.syncInterval);
            this.isCommandRestricted = ConfigReader.GetConfigKeyValue(resourceName, "hypnonema_restrict_command", 0,
                                                                      this.isCommandRestricted);
            IsLoggingEnabled = ConfigReader.GetConfigKeyValue(resourceName, "hypnonema_logging_enabled", 0, IsLoggingEnabled);

            try
            {
                this.database         = new LiteDatabase(this.connectionString);
                this.screenCollection = this.database.GetCollection <Screen>("screens");
            }
            catch (Exception e)
            {
                Logger.WriteLine($"failed to open database. error: {e.Message}", Logger.LogLevel.Error);
                throw;
            }

            // Create Example Screen if Database is empty
            this.PopulateDatabaseIfEmpty();

            if (this.cmdName != "hypnonema")
            {
                Logger.WriteLine(
                    $"Using '{this.cmdName}' as command name. Type /{this.cmdName} to open the NUI window.",
                    Logger.LogLevel.Information);
            }

            if (!this.isCommandRestricted)
            {
                Logger.WriteLine($"Command '{this.cmdName}' is NOT restricted", Logger.LogLevel.Information);
            }

            RegisterCommand(this.cmdName, new Action <int, List <object>, string>(this.OnHypnonemaCommand), this.isCommandRestricted);
        }
Esempio n. 5
0
        private void PopulateDatabaseIfEmpty()
        {
            if (this.screenCollection.Count() >= 1)
            {
                return;
            }

            var exampleScreen = new Screen()
            {
                AlwaysOn        = false,
                BrowserSettings = new DuiBrowserSettings()
                {
                    GlobalVolume     = 100f,
                    Is3DAudioEnabled = true,
                    SoundAttenuation = 10f,
                    SoundMaxDistance = 200f,
                    SoundMinDistance = 10f,
                },
                Is3DRendered       = true,
                Name               = "Hypnonema Example Screen",
                PositionalSettings = new PositionalSettings()
                {
                    PositionX = -1678.949f,
                    PositionY = -928.3431f,
                    PositionZ = 20.6290932f,
                    RotationX = 0f,
                    RotationY = 0f,
                    RotationZ = -140f,
                    ScaleX    = 0.969999969f,
                    ScaleY    = 0.484999985f,
                    ScaleZ    = -0.1f,
                }
            };

            try
            {
                this.screenCollection.Insert(exampleScreen);
            }
            catch (Exception e)
            {
                Logger.WriteLine($"Failed to create example screen: {e.Message}", Logger.LogLevel.Error);
                throw;
            }

            Logger.WriteLine($"Created example screen.", Logger.LogLevel.Information);
        }
Esempio n. 6
0
        private void OnOpen([FromSource] Player p)
        {
            var           isAceAllowed = true; //this.IsPlayerAllowed(p);
            List <Screen> screens;

            try
            {
                screens = this.screenCollection.FindAll().ToList();
            }
            catch (Exception e)
            {
                this.AddChatMessage(p, "Failed to read database. See server-log for more info");
                Logger.WriteLine($"Failed to read database. Error: {e.Message}", Logger.LogLevel.Error);
                throw;
            }

            p.TriggerEvent(ClientEvents.ShowNUI, isAceAllowed, JsonConvert.SerializeObject(screens));
            this.AddChatMessage(p, "Showing Window");
        }
Esempio n. 7
0
        private void OnResourceStart(string resourceName)
        {
            if (API.GetCurrentResourceName() != resourceName)
            {
                return;
            }

            this.connectionString = ConfigReader.GetConfigKeyValue(
                resourceName,
                "hypnonema_db_connString",
                0,
                this.connectionString);

            try
            {
                this.database         = new LiteDatabase(this.connectionString);
                this.screenCollection = this.database.GetCollection <Screen>("screens");
            }
            catch (Exception e)
            {
                Logger.WriteLine($"failed to open database. error: {e.Message}", Logger.LogLevel.Error);
                throw;
            }

            this.cmdName = ConfigReader.GetConfigKeyValue(resourceName, "hypnonema_command_name", 0, "hypnonema")
                           .Replace(" ", string.Empty);

            this.syncInterval = ConfigReader.GetConfigKeyValue(resourceName, "hypnonema_sync_interval", 0, 5000);

            if (this.cmdName != "hypnonema")
            {
                Logger.WriteLine(
                    $"Using {this.cmdName} as command name. Type /{this.cmdName} to open the NUI window.",
                    Logger.LogLevel.Information);
            }

            var loggingEnabled = ConfigReader.GetConfigKeyValue(resourceName, "hypnonema_logging_enabled", 0, false);

            IsLoggingEnabled = loggingEnabled;

            RegisterCommand(this.cmdName, new Action <int, List <object>, string>(this.OnHypnonemaCommand), true);
        }
Esempio n. 8
0
        private void OnHypnonemaCommand(int source, List <object> args, string raw)
        {
            var           p            = this.Players[source];
            var           isAceAllowed = this.IsPlayerAllowed(p);
            List <Screen> screens;

            try
            {
                screens = this.screenCollection.FindAll().ToList();
            }
            catch (Exception e)
            {
                this.AddChatMessage(p, "Failed to read database. See server-log for more info");
                Logger.WriteLine($"Failed to read database. Error: {e.Message}", Logger.LogLevel.Error);
                throw;
            }

            p.TriggerEvent(ClientEvents.ShowNUI, isAceAllowed, JsonConvert.SerializeObject(screens));
            this.AddChatMessage(p, "Showing Window");
        }
Esempio n. 9
0
        /// <summary>
        /// CalculateMaxActiveScaleforms is used to specify how many scaleforms can be active at the same time.
        /// The limit of max. active scaleforms is limited by number of *.gfx files in resource's stream directory.
        /// </summary>
        private void CalculateMaxActiveScaleforms()
        {
            var resourcePath = API.GetResourcePath(API.GetCurrentResourceName());

            var streamDirectory = Path.Combine(resourcePath, "stream");

            if (Directory.Exists(streamDirectory))
            {
                var regExp = new Regex(@"hypnonema_texture_renderer\d+\.+gfx");

                this.maxActiveScaleforms = Directory.GetFiles(streamDirectory, "*.gfx")
                                           .Where(path => regExp.IsMatch(path)).ToList().Count;

                Logger.Debug($"maxActiveScaleforms: {this.maxActiveScaleforms}");
            }
            else
            {
                Logger.Error($"Failed to read stream directory. Path: {streamDirectory}");
            }
        }
Esempio n. 10
0
        private void PopulateDatabaseIfEmpty()
        {
            if (this.screenCollection.Count() >= 1)
            {
                return;
            }

            var exampleScreen = Screen.CreateExampleScreen();

            try
            {
                this.screenCollection.Insert(exampleScreen);
            }
            catch (Exception e)
            {
                Logger.Error($"Failed to create example screen: {e.Message}");
                throw;
            }

            Logger.Verbose($"Created example screen: \"{exampleScreen.Name}\".");
        }
Esempio n. 11
0
        private void OnClientInitialize([FromSource] Player p)
        {
            try
            {
                var filesCount      = 0;
                var streamDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "stream");

                if (Directory.Exists(streamDirectory))
                {
                    var regExp = new Regex(@"hypnonema_texture_renderer\d+\.+gfx");
                    filesCount = Directory.GetFiles(streamDirectory, "*.gfx").Where(path => regExp.IsMatch(path))
                                 .ToList().Count;
                }
                else
                {
                    Logger.WriteLine(
                        $"Failed to read stream directory at path \"{streamDirectory}\".",
                        Logger.LogLevel.Warning);
                }

                var q = this.screenCollection.Find(s => s.AlwaysOn);

                // if we didn't receive a syncInterval for 3 times, we flush the lastKnownState
                if (DateTime.UtcNow > this.lastKnownState.Timestamp + new TimeSpan(0, 0, 0, 0, this.syncInterval * 3))
                {
                    this.lastKnownState = new ScreenDuiStateList();
                }

                p.TriggerEvent(
                    ClientEvents.Initialize,
                    JsonConvert.SerializeObject(q),
                    filesCount,
                    this.IsPlayerAllowed(p),
                    JsonConvert.SerializeObject(this.lastKnownState.StateList));
            }
            catch (Exception e)
            {
                Logger.WriteLine($"failed to query database. error: {e.Message}");
            }
        }
Esempio n. 12
0
        private void OnPlaybackReceived([FromSource] Player p, string videoUrl, string screenName)
        {
            if (!this.IsPlayerAllowed(p))
            {
                this.AddChatMessage(
                    p,
                    $"Error: You don't have permissions for: command.{this.cmdName}",
                    new[] { 255, 0, 0 });
                return;
            }

            Screen screen;

            try
            {
                screen = this.screenCollection.FindOne(s => s.Name == screenName);
            }
            catch (Exception e)
            {
                Logger.WriteLine(
                    $"playback attempt failed because of failing to query database. Error: ${e.Message}",
                    Logger.LogLevel.Error);
                return;
            }

            if (screen == null)
            {
                this.AddChatMessage(p, $"screen {screenName} not found. aborting playback");
                Logger.WriteLine($"screen {screenName} not found. aborting playback", Logger.LogLevel.Error);
                return;
            }

            TriggerClientEvent(ClientEvents.PlayVideo, videoUrl, JsonConvert.SerializeObject(screen));

            Logger.WriteLine($"playing {videoUrl} on screen {screenName}", Logger.LogLevel.Information);
        }