<commit_before>// For conditions of distribution and use, see copyright notice in license.txt

#include "StableHeaders.h"

#include "MumbleVoipModule.h"
#include "LinkPlugin.h"
#include "ServerInfoProvider.h"
#include "ModuleManager.h"
#include "EC_OgrePlaceable.h"
#include "WorldLogicInterface.h"
#include "Entity.h"
#include "ConsoleCommandServiceInterface.h"
#include "EventManager.h"
#include "LinkPlugin.h"
#include "Provider.h"
#include "ApplicationManager.h"
#include "DebugOperatorNew.h" 
#include "MemoryLeakCheck.h" 
#include "MumbleLibrary.h"

namespace MumbleVoip
{
    std::string MumbleVoipModule::module_name_ = "MumbleVoipModule";

    MumbleVoipModule::MumbleVoipModule()
        : ModuleInterface(module_name_),
          link_plugin_(0),
          server_info_provider_(0),
          in_world_voice_provider_(0),
          time_from_last_update_ms_(0),
          use_camera_position_(false),
          use_native_mumble_client_(false)
    {
        QStringList arguments = QCoreApplication::arguments();
        foreach(QString arg, arguments)
        {
            if (arg == "--use_native_mumble_client")
                use_native_mumble_client_ = true;
        }
    }

    MumbleVoipModule::~MumbleVoipModule()
    {
        SAFE_DELETE(link_plugin_);
        SAFE_DELETE(server_info_provider_);
        SAFE_DELETE(in_world_voice_provider_);
    }

    void MumbleVoipModule::Load()
    {
        if (use_native_mumble_client_)
        {
            server_info_provider_ = new ServerInfoProvider(framework_);
            connect(server_info_provider_, SIGNAL(MumbleServerInfoReceived(ServerInfo)), SLOT(StartMumbleClient(ServerInfo)));
        }
        else
        {
            in_world_voice_provider_ = new InWorldVoice::Provider(framework_);
        }

        link_plugin_ = new LinkPlugin();
    }

    void MumbleVoipModule::Unload()
    {
    }

    void MumbleVoipModule::Initialize()
    {
        InitializeConsoleCommands();
    }

    void MumbleVoipModule::PostInitialize()
    {
        event_category_framework_ = framework_->GetEventManager()->QueryEventCategory("Framework");
        if (event_category_framework_ == 0)
            LogError("Unable to find event category for Framework");
    }

    void MumbleVoipModule::Uninitialize()
    {
        SAFE_DELETE(link_plugin_);
        SAFE_DELETE(server_info_provider_);
        SAFE_DELETE(in_world_voice_provider_);

        if (use_native_mumble_client_)
        {
            if (ApplicationManager::StartCount() > 0)
            {
                // Hack will disconnect from server and trying to connect new one
                ApplicationManager::StartMumbleClient("mumble://user@0.0.0.0?version=1.2.2"); 
            }<commit_msg>Moved Mumble console command initialization to PostInitialize. Otherwise they fail since Console service is not up yet.<commit_after>// For conditions of distribution and use, see copyright notice in license.txt

#include "StableHeaders.h"

#include "MumbleVoipModule.h"
#include "LinkPlugin.h"
#include "ServerInfoProvider.h"
#include "ModuleManager.h"
#include "EC_OgrePlaceable.h"
#include "WorldLogicInterface.h"
#include "Entity.h"
#include "ConsoleCommandServiceInterface.h"
#include "EventManager.h"
#include "LinkPlugin.h"
#include "Provider.h"
#include "ApplicationManager.h"
#include "DebugOperatorNew.h" 
#include "MemoryLeakCheck.h" 
#include "MumbleLibrary.h"

namespace MumbleVoip
{
    std::string MumbleVoipModule::module_name_ = "MumbleVoipModule";

    MumbleVoipModule::MumbleVoipModule()
        : ModuleInterface(module_name_),
          link_plugin_(0),
          server_info_provider_(0),
          in_world_voice_provider_(0),
          time_from_last_update_ms_(0),
          use_camera_position_(false),
          use_native_mumble_client_(false)
    {
        QStringList arguments = QCoreApplication::arguments();
        foreach(QString arg, arguments)
        {
            if (arg == "--use_native_mumble_client")
                use_native_mumble_client_ = true;
        }
    }

    MumbleVoipModule::~MumbleVoipModule()
    {
        SAFE_DELETE(link_plugin_);
        SAFE_DELETE(server_info_provider_);
        SAFE_DELETE(in_world_voice_provider_);
    }

    void MumbleVoipModule::Load()
    {
        if (use_native_mumble_client_)
        {
            server_info_provider_ = new ServerInfoProvider(framework_);
            connect(server_info_provider_, SIGNAL(MumbleServerInfoReceived(ServerInfo)), SLOT(StartMumbleClient(ServerInfo)));
        }
        else
        {
            in_world_voice_provider_ = new InWorldVoice::Provider(framework_);
        }

        link_plugin_ = new LinkPlugin();
    }

    void MumbleVoipModule::Unload()
    {
    }

    void MumbleVoipModule::Initialize()
    {
    }

    void MumbleVoipModule::PostInitialize()
    {
        InitializeConsoleCommands();
        
        event_category_framework_ = framework_->GetEventManager()->QueryEventCategory("Framework");
        if (event_category_framework_ == 0)
            LogError("Unable to find event category for Framework");
    }

    void MumbleVoipModule::Uninitialize()
    {
        SAFE_DELETE(link_plugin_);
        SAFE_DELETE(server_info_provider_);
        SAFE_DELETE(in_world_voice_provider_);

        if (use_native_mumble_client_)
        {
            if (ApplicationManager::StartCount() > 0)
            {
                // Hack will disconnect from server and trying to connect new one
                ApplicationManager::StartMumbleClient("mumble://user@0.0.0.0?version=1.2.2"); 
            }
{'fraction_non_alphanumeric': 0.09733404902487028, 'fraction_numerical': 0.0046519949901592415, 'mean_word_length': 3.010043041606887, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5920466', 'n_tokens_mistral': 1659, 'n_tokens_neox': 1630, 'n_words': 276}