Example #1
0
    void onStream(AgentPrivate agent, string medialUrl)
    {
        bool throttled = false;

        try
        {
            ScenePrivate.OverrideAudioStream(medialUrl);
            agent.SendChat("Audio Stream URL successfully updated to " + medialUrl);
            if (DebugLogging)
            {
                Log.Write("New audio stream URL: " + medialUrl);
            }
        } catch
        {
            throttled = true;
            if (DebugLogging)
            {
                Log.Write("Throttled: Unable to update audio stream URL.");
            }
        }

        if (throttled)
        {
            try
            {
                agent.SendChat("Audio stream URL update was throttled.  Try again.");
            }
            catch
            {
                // Agent left
            }
        }
    }
    void OnChat(ChatData data)
    {
        AgentPrivate agent = ScenePrivate.FindAgent(data.SourceId);

        if (!IsAccessAllowed(agent))
        {
            return;
        }

        string[] chatWords = data.Message.Split(' ');

        if (chatWords.Length < 1)
        {
            return;
        }

        string command = chatWords[0];

        if (!_commandsUsage.ContainsKey(command))
        {
            return;
        }

        if (command == "/help")
        {
            string helpMessage = "AudioStreamChatCommand usage:";
            foreach (var kvp in _commandsUsage)
            {
                helpMessage += "\n" + kvp.Key + " " + kvp.Value;
            }
            agent.SendChat(helpMessage);
            return;
        }

        // if (command == "/stream")
        string medialUrl = (chatWords.Length < 2 ? "" : chatWords[1]);

        bool throttled = false;

        try
        {
            ScenePrivate.OverrideAudioStream(medialUrl);

            agent.SendChat("Audio Stream URL successfully updated to " + medialUrl);
            Log.Write("New audio stream URL: " + medialUrl);
        }
        catch (ThrottleException)
        {
            throttled = true;
            Log.Write("Throttled: Unable to update audio stream URL.");
        }
        catch
        {
            // Agent left
        }

        if (throttled)
        {
            try
            {
                agent.SendChat("Audio stream URL update was throttled.  Try again.");
            }
            catch
            {
                // Agent left
            }
        }
    }