예제 #1
0
void CWebCore::LoadListsFromXML ( bool bWhitelist, bool bBlacklist, bool bCustomLists )
{
    if ( !m_pXmlConfig )
        return;

    CXMLNode* pRootNode = m_pXmlConfig->GetRootNode ();
    if ( !pRootNode )
        return;

    if ( bWhitelist )
    {
        CXMLNode* pWhiteSubNode = pRootNode->FindSubNode ( "globalwhitelist" );
        if ( pWhiteSubNode )
        {
            for ( std::list<CXMLNode*>::iterator iter = pWhiteSubNode->ChildrenBegin (); iter != pWhiteSubNode->ChildrenEnd (); ++iter )
            {
                AddAllowedPage ( (*iter)->GetTagContent (), eWebFilterType::WEBFILTER_DYNAMIC );
            }
        }
    }
    
    if ( bBlacklist )
    {
        CXMLNode* pBlackSubNode = pRootNode->FindSubNode ( "globalblacklist" );
        if ( pBlackSubNode )
        {
            for ( std::list<CXMLNode*>::iterator iter = pBlackSubNode->ChildrenBegin (); iter != pBlackSubNode->ChildrenEnd (); ++iter )
            {
                AddBlockedPage ( (*iter)->GetTagContent (), eWebFilterType::WEBFILTER_DYNAMIC );
            }
        }
    }

    if ( bCustomLists )
    {
        CXMLNode* pBlackSubNode = pRootNode->FindSubNode ( "customblacklist" );
        if ( pBlackSubNode )
        {
            for ( std::list<CXMLNode*>::iterator iter = pBlackSubNode->ChildrenBegin (); iter != pBlackSubNode->ChildrenEnd (); ++iter )
            {
                AddBlockedPage ( (*iter)->GetTagContent (), eWebFilterType::WEBFILTER_USER );
            }
        }
        CXMLNode* pWhiteSubNode = pRootNode->FindSubNode ( "customwhitelist" );
        if ( pWhiteSubNode )
        {
            for ( std::list<CXMLNode*>::iterator iter = pWhiteSubNode->ChildrenBegin (); iter != pWhiteSubNode->ChildrenEnd (); ++iter )
            {
                AddAllowedPage ( (*iter)->GetTagContent (), eWebFilterType::WEBFILTER_USER );
            }
        }
    }
}
예제 #2
0
void CServerBrowser::SetServerPassword ( std::string strHost, std::string strPassword )
{
    CXMLNode* pConfig = CCore::GetSingletonPtr ()->GetConfig ();
    CXMLNode* pServerPasswords = pConfig->FindSubNode ( CONFIG_NODE_SERVER_SAVED );
    if ( !pServerPasswords )
    {
        pServerPasswords = pConfig ->CreateSubNode ( CONFIG_NODE_SERVER_SAVED );
    }
    //Check if the server password already exists
    for ( unsigned int i = 0 ; i < pServerPasswords->GetSubNodeCount() ; i++ )
    {    
        CXMLAttributes* pAttributes = &(pServerPasswords->GetSubNode(i)->GetAttributes());
        if ( pAttributes->Find( "host" ) )
        {
            if ( CXMLAttribute* pHost = pAttributes->Find ( "host" ) )
            {
                std::string strXMLHost = pHost->GetValue();
                if ( strXMLHost == strHost )
                {
                    CXMLAttribute* pPassword = pAttributes->Create( "password" );
                    pPassword->SetValue(strPassword.c_str());
                    return;
                }
            }
        }
        
    }

    // Otherwise create the node from scratch
    CXMLNode* pNode = pServerPasswords->CreateSubNode( "server" );
    CXMLAttribute* pHostAttribute = pNode->GetAttributes().Create ( "host" );
    pHostAttribute->SetValue(strHost.c_str());
    CXMLAttribute* pPasswordAttribute = pNode->GetAttributes().Create ( "password" );
    pPasswordAttribute->SetValue(strPassword.c_str());
}
예제 #3
0
int CLuaXMLDefs::xmlNodeFindChild ( lua_State* luaVM )
{
    // xmlNode*, node name, index
    if ( lua_type ( luaVM, 1 ) != LUA_TLIGHTUSERDATA ||
         lua_type ( luaVM, 2 ) != LUA_TSTRING ||
         lua_type ( luaVM, 3 ) != LUA_TNUMBER )
    {
        m_pScriptDebugging->LogBadType ( luaVM, "xmlNodeFindChild" );

        lua_pushboolean ( luaVM, false );
        return 1;
    }
    else
    {
        CXMLNode* pNode = lua_toxmlnode ( luaVM, 1 );
        if ( pNode )
        {
            const char * szTagName = lua_tostring ( luaVM, 2 );
            unsigned int iIndex = static_cast < unsigned int > ( lua_tonumber ( luaVM, 3 ) );
            CXMLNode * pFoundNode = pNode->FindSubNode ( szTagName, iIndex );
            if ( pFoundNode )
            {
                lua_pushxmlnode ( luaVM, pFoundNode );
                return 1;
            }
        }
    }

    lua_pushboolean ( luaVM, false );
    return 1;
}
예제 #4
0
void CWebCore::WriteCustomList ( const SString& strListName, const std::vector<SString>& customList, bool bReset )
{
    if ( !m_pXmlConfig || !MakeSureXMLNodesExist () )
        return;

    CXMLNode* pRootNode = m_pXmlConfig->GetRootNode ();
    if ( !pRootNode )
        return;

    CXMLNode* pCustomListNode = pRootNode->FindSubNode ( strListName );
    if ( !pCustomListNode )
        return;

    pCustomListNode->DeleteAllSubNodes();
    for ( std::vector<SString>::const_iterator iter = customList.begin (); iter != customList.end (); ++iter )
    {
        CXMLNode* pNode = pCustomListNode->CreateSubNode ( "url" );
        if ( pNode )
            pNode->SetTagContent ( *iter );
    }

    // Write custom blacklist and reload from XML
    m_pXmlConfig->Write ();
    if ( bReset )
        ResetFilter ( false );
}
예제 #5
0
int CLuaXMLDefs::xmlNodeFindChild ( lua_State* luaVM )
{
    CXMLNode* pNode;
    SString strTagName;
    unsigned int uiIndex;

    CScriptArgReader argStream ( luaVM );
    argStream.ReadUserData ( pNode );
    argStream.ReadString ( strTagName );
    argStream.ReadNumber ( uiIndex );

    if ( !argStream.HasErrors () )
    {
        CXMLNode * pFoundNode = pNode->FindSubNode ( strTagName, uiIndex );
        if ( pFoundNode )
        {
            lua_pushxmlnode ( luaVM, pFoundNode );
            return 1;
        }
    }
    else
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );

    lua_pushboolean ( luaVM, false );
    return 1;
}
예제 #6
0
std::string CServerBrowser::GetServerPassword ( std::string strHost )
{
    CXMLNode* pConfig = CCore::GetSingletonPtr ()->GetConfig ();
    CXMLNode* pServerPasswords = pConfig->FindSubNode ( CONFIG_NODE_SERVER_SAVED );
    if ( !pServerPasswords )
    {
        pServerPasswords = pConfig ->CreateSubNode ( CONFIG_NODE_SERVER_SAVED );
    }
    //Check if the server password already exists
    for ( unsigned int i = 0 ; i < pServerPasswords->GetSubNodeCount() ; i++ )
    {    
        CXMLAttributes* pAttributes = &(pServerPasswords->GetSubNode(i)->GetAttributes());
        if ( pAttributes->Find( "host" ) )
        {
            if ( CXMLAttribute* pHost = pAttributes->Find ( "host" ) )
            {
                std::string strXMLHost = pHost->GetValue();
                if ( strXMLHost == strHost )
                {
                    CXMLAttribute* pPassword = pAttributes->Create( "password" );
                    std::string strPassword = pPassword->GetValue();
                    return strPassword;
                }
            }
        }
        
    }
    return "";
}
예제 #7
0
bool CWebCore::UpdateListsFromMaster ()
{
    if ( !m_pXmlConfig )
        return false;

    CXMLNode* pRootNode = m_pXmlConfig->GetRootNode ();
    if ( !pRootNode || !MakeSureXMLNodesExist () )
        return false;

    // Fetch white- and blacklist revision from config
    CXMLNode* pWhiteRevNode = pRootNode->FindSubNode ( "whitelistrev" );
    if ( !pWhiteRevNode || !pWhiteRevNode->GetTagContent ( m_iWhitelistRevision ) )
    {
       m_iWhitelistRevision = 0;
    }
    CXMLNode* pBlackRevNode = pRootNode->FindSubNode ( "blacklistrev" );
    if ( !pBlackRevNode || !pBlackRevNode->GetTagContent ( m_iBlacklistRevision ) )
    {
       m_iBlacklistRevision = 0;
    }

    // Get last update timestamp and compare with current time
    CXMLNode* pLastUpdateNode = pRootNode->FindSubNode ( "lastupdate" );
    if ( pLastUpdateNode )
    {
        SString lastUpdateTime = pLastUpdateNode->GetTagContent ();

        time_t currentTime;
        time ( &currentTime );

        if ( lastUpdateTime < SString ( "%d", (long long)currentTime - BROWSER_LIST_UPDATE_INTERVAL ) )
        {
        #ifdef MTA_DEBUG
            OutputDebugLine ( "Updating white- and blacklist..." );
        #endif
            g_pCore->GetNetwork ()->GetHTTPDownloadManager ( EDownloadModeType::WEBBROWSER_LISTS )->QueueFile ( SString("%s?type=getrev", BROWSER_UPDATE_URL),
                NULL, 0, NULL, 0, false, this, &CWebCore::StaticFetchRevisionProgress, false, 3 );

            pLastUpdateNode->SetTagContent ( SString ( "%d", (long long)currentTime ) );
            m_pXmlConfig->Write ();
        }
    }

    return true;
}
예제 #8
0
bool CWebCore::StaticFetchBlacklistProgress ( double dDownloadNow, double dDownloadTotal, char* pCompletedData, size_t completedLength, void *pObj, bool bComplete, int iError )
{
    if ( !bComplete )
        return false;

    CWebCore* pWebCore = static_cast < CWebCore* > ( pObj );
    if ( !pWebCore->m_pXmlConfig )
        return false;

    if ( !pWebCore->MakeSureXMLNodesExist () )
        return false;

    CXMLNode* pRootNode = pWebCore->m_pXmlConfig->GetRootNode ();
    std::vector<SString> blacklist;
    SString strData = pCompletedData;
    strData.Split ( ";", blacklist );
    CXMLNode* pListNode = pRootNode->FindSubNode ( "globalblacklist" );
    if ( !pListNode )
        return false;
    pListNode->DeleteAllSubNodes ();

    for ( std::vector<SString>::const_iterator iter = blacklist.begin (); iter != blacklist.end (); ++iter )
    {
        CXMLNode* pNode = pListNode->CreateSubNode ( "url" );
        pNode->SetTagContent ( *iter );
    }

    // Set blacklist revision
    CXMLNode* pNode = pRootNode->FindSubNode ( "blacklistrev" );
    if ( !pNode )
        return false;
    pNode->SetTagContent ( pWebCore->m_iBlacklistRevision );

    // Write changes to the XML file
    pWebCore->m_pXmlConfig->Write ();

    pWebCore->LoadListsFromXML ( false, true, false );

#ifdef MTA_DEBUG
    OutputDebugLine ( "Updated browser blacklist!" );
#endif
    return true;
}
예제 #9
0
void CServerBrowser::ClearServerPasswords ()
{
    CXMLNode* pConfig = CCore::GetSingletonPtr ()->GetConfig ();
    CXMLNode* pServerPasswords = pConfig->FindSubNode ( CONFIG_NODE_SERVER_SAVED );
    if ( pServerPasswords )
    {
        pServerPasswords->DeleteAllSubNodes();
        pConfig->DeleteSubNode ( pServerPasswords );
    }
}
예제 #10
0
bool CLocalServer::Load ( void )
{
    // Get server module root
    SString strServerPath = CalcMTASAPath( PathJoin ( "server", "mods", "deathmatch" ) );

    m_pConfig = g_pCore->GetXML ()->CreateXML ( PathJoin ( strServerPath, m_strConfig ) );
    if ( m_pConfig && m_pConfig->Parse() )
    {
        CXMLNode* pRoot = m_pConfig->GetRootNode();
        CXMLNode* pServerName = pRoot->FindSubNode ( "servername", 0 );
        if ( pServerName ) m_pEditName->SetText ( pServerName->GetTagContent().c_str() );
        CXMLNode* pServerPass = pRoot->FindSubNode ( "password", 0 );
        if ( pServerPass ) m_pEditPass->SetText ( pServerPass->GetTagContent().c_str() );
        CXMLNode* pServerPlayers = pRoot->FindSubNode ( "maxplayers", 0 );
        if ( pServerPlayers ) m_pEditPlayers->SetText ( pServerPlayers->GetTagContent().c_str() );

        // Read the startup resources
        list < CXMLNode* > ::const_iterator iter = pRoot->ChildrenBegin ();
        for ( ; iter != pRoot->ChildrenEnd (); iter++ )
        {
            CXMLNode* pNode = reinterpret_cast < CXMLNode* > ( *iter );
            if ( pNode->GetTagName ().compare ( "resource" ) == 0 )
            {
                CXMLAttribute* src = pNode->GetAttributes().Find ( "src" );
                if ( src && src->GetValue()[1] )
                {
                    m_pResourcesCur->SetItemText ( m_pResourcesCur->AddRow (), m_hResourcesCur, src->GetValue().c_str() );
                }
            }
        }
    }

    // Get list of resource names
    std::vector < SString > resourceNameList;
    GetResourceNameList ( resourceNameList, strServerPath );

    // Put resource names into the GUI
    for ( std::vector < SString >::iterator iter = resourceNameList.begin () ; iter != resourceNameList.end () ; ++iter )
        HandleResource ( *iter );

    return true;
}
예제 #11
0
void CWebCore::StaticFetchWhitelistFinished ( char* pCompletedData, size_t completedLength, void *pObj, bool bSuccess, int iErrorCode )
{
    if ( !bSuccess )
        return;

    CWebCore* pWebCore = static_cast < CWebCore* > ( pObj );
    if ( !pWebCore->m_pXmlConfig )
        return;

    if ( !pWebCore->MakeSureXMLNodesExist () )
        return;

    CXMLNode* pRootNode = pWebCore->m_pXmlConfig->GetRootNode ();
    std::vector<SString> whitelist;
    SString strData = pCompletedData;
    strData.Split ( ";", whitelist );
    CXMLNode* pListNode = pRootNode->FindSubNode ( "globalwhitelist" );
    if ( !pListNode )
        return;
    pListNode->DeleteAllSubNodes ();

    for ( std::vector<SString>::const_iterator iter = whitelist.begin (); iter != whitelist.end (); ++iter )
    {
        CXMLNode* pNode = pListNode->CreateSubNode ( "url" );
        pNode->SetTagContent ( *iter );
    }

    // Set whitelist revision
    CXMLNode* pNode = pRootNode->FindSubNode ( "whitelistrev" );
    if ( !pNode )
        return;
    pNode->SetTagContent ( pWebCore->m_iWhitelistRevision );

    // Write changes to the XML file
    pWebCore->m_pXmlConfig->Write ();

    pWebCore->LoadListsFromXML ( true, false, false );

#ifdef MTA_DEBUG
    OutputDebugLine ( "Updated whitelist!" );
#endif
}
예제 #12
0
void CLocalServer::StoreConfigValue ( const char* szNode, const char* szValue )
{
    CXMLNode* pRoot = m_pConfig->GetRootNode();
    CXMLNode* pNode = pRoot->FindSubNode ( szNode, 0 );
    if ( pNode )
    {
        pNode->SetTagContent ( szValue );
    }
    else
    {
        pNode = pRoot->CreateSubNode ( szNode );
        pNode->SetTagContent ( szValue );
    }
}
예제 #13
0
bool CClientVariables::Load ( void )
{
    // Get the root node
    CXMLNode *pRoot = CCore::GetSingleton ().GetConfig ();
    if ( !pRoot )
        return false;
    m_iRevision++;

    // Load the cvars
    m_pStorage = pRoot->FindSubNode ( CONFIG_NODE_CVARS );
    if ( !m_pStorage ) {
        // Non-existant, create a new node
        m_pStorage = pRoot->CreateSubNode ( CONFIG_NODE_CVARS );
    }

    // Verify that at least all the defaults are in
    LoadDefaults ();

    return true;
}
예제 #14
0
////////////////////////////////////////////////////
//
//  CNewsBrowser::InitNewsItemList
//
//
//
////////////////////////////////////////////////////
void CNewsBrowser::InitNewsItemList(void)
{
    m_NewsitemList.clear();

    // Find all sub-directories in 'news' directory
    SString              strAllNewsDir = PathJoin(GetMTADataPath(), "news");
    std::vector<SString> directoryList = FindFiles(strAllNewsDir + "\\*", false, true);
    std::sort(directoryList.begin(), directoryList.end());

    // Get news settings
    SString strOldestPost;
    uint    uiMaxHistoryLength;
    GetVersionUpdater()->GetNewsSettings(strOldestPost, uiMaxHistoryLength);

    // Process each sub-directory
    for (uint i = 0; i < directoryList.size(); i++)
    {
        SString strItemDir = directoryList[directoryList.size() - 1 - i];
        if (strItemDir < strOldestPost)
            continue;            // Post too old
        if (m_NewsitemList.size() >= uiMaxHistoryLength)
            continue;            // Post count too high

        SNewsItem newsItem;
        newsItem.strContentFullDir = PathJoin(strAllNewsDir, strItemDir);

        // Get filenames from XML file
        CXMLFile* pFile = g_pCore->GetXML()->CreateXML(PathJoin(newsItem.strContentFullDir, "files.xml"));
        if (pFile)
        {
            pFile->Parse();
            CXMLNode* pRoot = pFile->GetRootNode();

            if (pRoot)
            {
                // Headline text
                CXMLNode* pHeadline = pRoot->FindSubNode("headline", 0);
                if (pHeadline)
                    newsItem.strHeadline = pHeadline->GetTagContent();

                // Date text
                CXMLNode* pDate = pRoot->FindSubNode("date", 0);
                if (pDate)
                    newsItem.strDate = pDate->GetTagContent();
                else
                    newsItem.strHeadline.Split(" - ", &newsItem.strHeadline, &newsItem.strDate, true);

                // Layout filename
                CXMLNode* pLayout = pRoot->FindSubNode("layout", 0);
                if (pLayout)
                    newsItem.strLayoutFilename = pLayout->GetTagContent();

                // Imageset filenames
                CXMLNode* pImages = pRoot->FindSubNode("imagesetlist", 0);
                if (pImages)
                    for (uint i = 0; i < pImages->GetSubNodeCount(); i++)
                        newsItem.imagesetFilenameList.push_back(pImages->GetSubNode(i)->GetTagContent());
            }

            delete pFile;
        }

        // Add to news item list if valid
        if (!newsItem.strHeadline.empty() && !newsItem.strLayoutFilename.empty())
            m_NewsitemList.push_back(newsItem);
    }
}
예제 #15
0
///////////////////////////////////////////////////////////////
//
// CJoystickManager::GetConfigNode
//
// Get the main node for load/saving data for the current joypad.
//
///////////////////////////////////////////////////////////////
CXMLNode* CJoystickManager::GetConfigNode ( bool bCreateIfRequired )
{
    // Get the root node
    CXMLNode *pRoot = CCore::GetSingleton ().GetConfig ();
    if ( !pRoot )
        return NULL;

    // Get the top joypad config node
    CXMLNode* pSectionNode = pRoot->FindSubNode ( CONFIG_NODE_JOYPAD );
    if ( !pSectionNode )
    {
        if ( !bCreateIfRequired )
            return NULL;

        // Non-existant, create a new node
        pSectionNode = pRoot->CreateSubNode ( CONFIG_NODE_JOYPAD );
    }

    // Get the node for this joystick's GUID

    CXMLNode* pItemNode = NULL;
    // Find existing node
    for( int i=0; true; i++ )
    {
        CXMLNode* pNode = pSectionNode->FindSubNode ( "product", i );

        if ( !pNode )
            break;

        CXMLAttributes* pAttributes = &pNode->GetAttributes ();

        if ( CXMLAttribute* pA = pAttributes->Find ( "guid" ) )
        {
            string value = pA->GetValue ();
            if ( value == m_DevInfo.strGuid )
            {
                pItemNode = pNode;
                break;
            }
        }   
    }

    if ( !pItemNode )
    {
        if ( !bCreateIfRequired )
            return NULL;

        // Non-existant, create a new node
        pItemNode = pSectionNode->CreateSubNode ( "product" );

        if ( pItemNode )
        {
            CXMLAttributes* pAttributes = &pItemNode->GetAttributes ();

            CXMLAttribute* pA = NULL;
            pA = pAttributes->Create ( "guid" );
            pA->SetValue ( m_DevInfo.strGuid.c_str () );
        }

    }

    return pItemNode;
}
예제 #16
0
bool CWebCore::MakeSureXMLNodesExist ()
{
    // Check xml file
    if ( !m_pXmlConfig )
    {
        SString browserDataPath = CalcMTASAPath ( MTA_BROWSERDATA_PATH );
        bool exists = FileExists ( browserDataPath );

        m_pXmlConfig = g_pCore->GetXML ()->CreateXML ( browserDataPath );

        if ( !m_pXmlConfig || ( exists && !m_pXmlConfig->Parse () ) )
            return false;
    }

    CXMLNode* pRootNode = m_pXmlConfig->GetRootNode ();
    if ( !pRootNode )
    {
        pRootNode = m_pXmlConfig->CreateRootNode ( "browserdata" );
        if ( !pRootNode )
            return false;
    }

    if ( !pRootNode->FindSubNode ( "lastupdate" ) )
    {
        CXMLNode* pNode = pRootNode->CreateSubNode ( "lastupdate" );
        if ( !pNode )
            return false;

        pNode->SetTagContent ( 0 );
    }

    if ( !pRootNode->FindSubNode ( "whitelistrev" ) )
    {
        if ( !pRootNode->CreateSubNode ( "whitelistrev" ) )
            return false;
    }

    if ( !pRootNode->FindSubNode ( "blacklistrev" ) )
    {
        if ( !pRootNode->CreateSubNode ( "blacklistrev" ) )
            return false;
    }

    if ( !pRootNode->FindSubNode ( "globalwhitelist" ) )
    {
        if ( !pRootNode->CreateSubNode ( "globalwhitelist" ) )
            return false;
    }

    if ( !pRootNode->FindSubNode ( "globalblacklist" ) )
    {
        if ( !pRootNode->CreateSubNode ( "globalblacklist" ) )
            return false;
    }

    if ( !pRootNode->FindSubNode ( "customblacklist" ) )
    {
        if ( !pRootNode->CreateSubNode ( "customblacklist" ) )
            return false;
    }

    if ( !pRootNode->FindSubNode ( "customwhitelist" ) )
    {
        if ( !pRootNode->CreateSubNode ( "customwhitelist" ) )
            return false;
    }

    return true;
}
예제 #17
0
CMainMenu::CMainMenu(CGUI* pManager)
{
    m_pNewsBrowser = new CNewsBrowser();

    ulPreviousTick = GetTickCount32();
    m_pHoveredItem = NULL;
    m_iMoveStartPos = 0;

    // Initialize
    m_pManager = pManager;
    m_bIsVisible = false;
    m_bIsFullyVisible = false;
    m_bIsIngame = true;
    //    m_bIsInSubWindow = false;
    m_bStarted = false;
    m_fFader = 0;
    m_ucFade = FADE_INVISIBLE;

    // Adjust window size to resolution
    CVector2D ScreenSize = m_pManager->GetResolution();
    m_ScreenSize = ScreenSize;

    int iBackgroundX = 0;
    int iBackgroundY = 0;
    int iBackgroundSizeX = ScreenSize.fX;
    int iBackgroundSizeY;

    // First let's work out our x and y offsets
    if (ScreenSize.fX > ScreenSize.fY)            // If the monitor is a normal landscape one
    {
        float iRatioSizeY = ScreenSize.fY / NATIVE_RES_Y;
        m_iMenuSizeX = NATIVE_RES_X * iRatioSizeY;
        m_iMenuSizeY = ScreenSize.fY;
        m_iXOff = (ScreenSize.fX - m_iMenuSizeX) * 0.5f;
        m_iYOff = 0;

        float iRatioSizeX = ScreenSize.fX / NATIVE_RES_X;
        iBackgroundSizeX = ScreenSize.fX;
        iBackgroundSizeY = NATIVE_BG_Y * iRatioSizeX;
    }
    else            // Otherwise our monitor is in a portrait resolution, so we cant fill the background by y
    {
        float iRatioSizeX = ScreenSize.fX / NATIVE_RES_X;
        m_iMenuSizeY = NATIVE_RES_Y * iRatioSizeX;
        m_iMenuSizeX = ScreenSize.fX;
        m_iXOff = 0;
        m_iYOff = (ScreenSize.fY - m_iMenuSizeY) * 0.5f;

        iBackgroundY = m_iYOff;
        iBackgroundSizeX = m_iMenuSizeX;
        iBackgroundSizeY = NATIVE_BG_Y * iRatioSizeX;
    }
    // First create our filler black background image, which covers the whole screen
    m_pFiller = reinterpret_cast<CGUIStaticImage*>(pManager->CreateStaticImage());
    m_pFiller->LoadFromFile(CORE_MTA_FILLER);
    m_pFiller->SetVisible(false);
    m_pFiller->MoveToBack();
    m_pFiller->SetZOrderingEnabled(false);
    m_pFiller->SetAlwaysOnTop(true);
    m_pFiller->MoveToBack();
    m_pFiller->SetSize(CVector2D(ScreenSize.fX, iBackgroundY), false);

    // Background image
    m_pBackground = reinterpret_cast<CGUIStaticImage*>(pManager->CreateStaticImage());
    m_pBackground->LoadFromFile(CORE_MTA_STATIC_BG);
    m_pBackground->SetProperty("InheritsAlpha", "False");
    m_pBackground->SetPosition(CVector2D(iBackgroundX, iBackgroundY), false);
    m_pBackground->SetSize(CVector2D(iBackgroundSizeX, iBackgroundSizeY), false);
    m_pBackground->SetZOrderingEnabled(false);
    m_pBackground->SetAlwaysOnTop(true);
    m_pBackground->MoveToBack();
    m_pBackground->SetAlpha(0);
    m_pBackground->SetVisible(false);

    m_pFiller2 = reinterpret_cast<CGUIStaticImage*>(pManager->CreateStaticImage());
    m_pFiller2->LoadFromFile(CORE_MTA_FILLER);
    m_pFiller2->SetVisible(false);
    m_pFiller2->SetZOrderingEnabled(false);
    m_pFiller2->SetAlwaysOnTop(true);
    m_pFiller2->MoveToBack();
    m_pFiller2->SetPosition(CVector2D(0, iBackgroundY + iBackgroundSizeY));
    m_pFiller2->SetSize(ScreenSize, false);

    m_pCanvas = reinterpret_cast<CGUIScrollPane*>(pManager->CreateScrollPane());
    m_pCanvas->SetProperty("ContentPaneAutoSized", "False");
    m_pCanvas->SetPosition(CVector2D(m_iXOff, m_iYOff), false);
    m_pCanvas->SetSize(CVector2D(m_iMenuSizeX, m_iMenuSizeY), false);
    m_pCanvas->SetZOrderingEnabled(false);
    m_pCanvas->SetAlwaysOnTop(true);
    m_pCanvas->MoveToBack();
    m_pCanvas->SetVisible(false);

    // Create our MTA logo
    CVector2D logoSize = CVector2D((NATIVE_LOGO_X / NATIVE_RES_X) * m_iMenuSizeX, (NATIVE_LOGO_Y / NATIVE_RES_Y) * m_iMenuSizeY);
    m_pLogo = reinterpret_cast<CGUIStaticImage*>(pManager->CreateStaticImage(m_pCanvas));
    m_pLogo->LoadFromFile(CORE_MTA_LOGO);
    m_pLogo->SetProperty("InheritsAlpha", "False");
    m_pLogo->SetSize(logoSize, false);
    m_pLogo->SetPosition(CVector2D(0.5f * m_iMenuSizeX - logoSize.fX / 2, 0.365f * m_iMenuSizeY - logoSize.fY / 2), false);
    m_pLogo->SetZOrderingEnabled(false);

    // Create the image showing the version number
    m_pVersion = reinterpret_cast<CGUIStaticImage*>(pManager->CreateStaticImage());
    m_pVersion->LoadFromFile(CORE_MTA_VERSION);
    m_pVersion->SetParent(m_pCanvas);
    m_pVersion->SetPosition(CVector2D(0.845f, 0.528f), true);
    m_pVersion->SetSize(CVector2D((32 / NATIVE_RES_X) * m_iMenuSizeX, (32 / NATIVE_RES_Y) * m_iMenuSizeY), false);
    m_pVersion->SetProperty("InheritsAlpha", "False");

    float fBase = 0.613f;
    float fGap = 0.043f;
    // Our disconnect item is shown/hidden dynamically, so we store it seperately
    m_pDisconnect = CreateItem(MENU_ITEM_DISCONNECT, "menu_disconnect.png", CVector2D(0.168f, fBase + fGap * 0));
    m_pDisconnect->image->SetVisible(false);

    // Create the menu items
    // Filepath, Relative position, absolute native size
    // And the font for the graphics is ?
    m_menuItems.push_back(CreateItem(MENU_ITEM_QUICK_CONNECT, "menu_quick_connect.png", CVector2D(0.168f, fBase + fGap * 0)));
    m_menuItems.push_back(CreateItem(MENU_ITEM_BROWSE_SERVERS, "menu_browse_servers.png", CVector2D(0.168f, fBase + fGap * 1)));
    m_menuItems.push_back(CreateItem(MENU_ITEM_HOST_GAME, "menu_host_game.png", CVector2D(0.168f, fBase + fGap * 2)));
    m_menuItems.push_back(CreateItem(MENU_ITEM_MAP_EDITOR, "menu_map_editor.png", CVector2D(0.168f, fBase + fGap * 3)));
    m_menuItems.push_back(CreateItem(MENU_ITEM_SETTINGS, "menu_settings.png", CVector2D(0.168f, fBase + fGap * 4)));
    m_menuItems.push_back(CreateItem(MENU_ITEM_ABOUT, "menu_about.png", CVector2D(0.168f, fBase + fGap * 5)));
    m_menuItems.push_back(CreateItem(MENU_ITEM_QUIT, "menu_quit.png", CVector2D(0.168f, fBase + fGap * 6)));

    // We store the position of the top item, and the second item.  These will be useful later
    float fFirstItemSize = m_menuItems.front()->image->GetSize(false).fY;
    float fSecondItemSize = m_menuItems[1]->image->GetSize(false).fY;

    m_iFirstItemCentre = (m_menuItems.front()->image)->GetPosition().fY + fFirstItemSize * 0.5f;
    m_iSecondItemCentre = (m_menuItems[1]->image)->GetPosition().fY + fSecondItemSize * 0.5f;

    // Store some mouse over bounding box positions
    m_menuAX = (0.168f * m_iMenuSizeX) + m_iXOff;                                                                      // Left side of the items
    m_menuAY = m_iFirstItemCentre - fFirstItemSize * (CORE_MTA_HOVER_SCALE / CORE_MTA_NORMAL_SCALE) * 0.5f;            // Top side of the items
    m_menuBX = m_menuAX + ((390 / NATIVE_RES_X) * m_iMenuSizeX);            // Right side of the items. We add the longest picture (browse_servers)
    m_menuAY += BODGE_FACTOR_1;

    m_pMenuArea = reinterpret_cast<CGUIStaticImage*>(pManager->CreateStaticImage(m_pCanvas));
    m_pMenuArea->LoadFromFile(CORE_MTA_FILLER);
    m_pMenuArea->SetPosition(CVector2D(m_menuAX - m_iXOff, m_menuAY - m_iYOff) + BODGE_FACTOR_5, false);
    m_pMenuArea->SetSize(CVector2D(m_menuBX - m_menuAX, m_menuBY - m_menuAY) + BODGE_FACTOR_6, false);
    m_pMenuArea->SetAlpha(0);
    m_pMenuArea->SetZOrderingEnabled(false);
    m_pMenuArea->SetClickHandler(GUI_CALLBACK(&CMainMenu::OnMenuClick, this));
    m_pMenuArea->SetMouseEnterHandler(GUI_CALLBACK(&CMainMenu::OnMenuEnter, this));
    m_pMenuArea->SetMouseLeaveHandler(GUI_CALLBACK(&CMainMenu::OnMenuExit, this));

    float fDrawSizeX = (365 / NATIVE_RES_X) * m_iMenuSizeX;            // Right aligned
    float fDrawSizeY = (52 / NATIVE_RES_Y) * m_iMenuSizeY;
    float fDrawPosX = 0.83f * m_iMenuSizeX - fDrawSizeX;
    float fDrawPosY = 0.60f * m_iMenuSizeY;
    m_pLatestNews = reinterpret_cast<CGUIStaticImage*>(pManager->CreateStaticImage());
    m_pLatestNews->LoadFromFile(CORE_MTA_LATEST_NEWS);
    m_pLatestNews->SetParent(m_pCanvas);
    m_pLatestNews->SetPosition(CVector2D(fDrawPosX, fDrawPosY), false);
    m_pLatestNews->SetSize(CVector2D(fDrawSizeX, fDrawSizeY), false);
    m_pLatestNews->SetProperty("InheritsAlpha", "False");
    m_pLatestNews->SetVisible(false);

    // Create news item stuff
    fDrawPosX -= 25;
    fDrawPosY += fDrawSizeY - 8;
    for (uint i = 0; i < CORE_MTA_NEWS_ITEMS; i++)
    {
        fDrawPosY += 20;
        // Create our shadow and item
        CGUILabel* pItemShadow = reinterpret_cast<CGUILabel*>(m_pManager->CreateLabel(m_pCanvas, " "));
        CGUILabel* pItem = reinterpret_cast<CGUILabel*>(m_pManager->CreateLabel(m_pCanvas, " "));

        pItem->SetFont("sans");
        pItemShadow->SetFont("sans");
        pItem->SetHorizontalAlign(CGUI_ALIGN_RIGHT);
        pItemShadow->SetHorizontalAlign(CGUI_ALIGN_RIGHT);

        pItem->SetSize(CVector2D(fDrawSizeX, 14), false);
        pItemShadow->SetSize(CVector2D(fDrawSizeX, 15), false);

        pItem->SetPosition(CVector2D(fDrawPosX, fDrawPosY), false);
        pItemShadow->SetPosition(CVector2D(fDrawPosX + 1, fDrawPosY + 1), false);

        pItemShadow->SetTextColor(112, 112, 112);

        // Set the handlers
        pItem->SetClickHandler(GUI_CALLBACK(&CMainMenu::OnNewsButtonClick, this));

        // Store the item in the array
        m_pNewsItemLabels[i] = pItem;
        m_pNewsItemShadowLabels[i] = pItemShadow;

        // Create our date label
        fDrawPosY += 15;
        CGUILabel* pItemDate = reinterpret_cast<CGUILabel*>(m_pManager->CreateLabel(m_pCanvas, " "));

        pItemDate->SetFont("default-small");
        pItemDate->SetHorizontalAlign(CGUI_ALIGN_RIGHT);

        pItemDate->SetSize(CVector2D(fDrawSizeX, 13), false);
        pItemDate->SetPosition(CVector2D(fDrawPosX, fDrawPosY), false);

        m_pNewsItemDateLabels[i] = pItemDate;

        // Create 'NEW' sticker
        CGUILabel*& pLabel = m_pNewsItemNEWLabels[i];
        pLabel = reinterpret_cast<CGUILabel*>(pManager->CreateLabel(m_pCanvas, "NEW"));
        pLabel->SetFont("default-small");
        pLabel->SetTextColor(255, 0, 0);
        pLabel->AutoSize(pLabel->GetText().c_str());
        pLabel->SetAlpha(0.7f);
        pLabel->SetVisible(false);
    }

    m_pLogo->MoveToBack();

    // Submenus
    m_QuickConnect.SetVisible(false);
    m_ServerBrowser.SetVisible(false);
    m_ServerInfo.Hide();
    m_Settings.SetVisible(false);
    m_Credits.SetVisible(false);
    m_pNewsBrowser->SetVisible(false);

    // We're not ingame
    SetIsIngame(false);

    // Store the pointer to the graphics subsystem
    m_pGraphics = CGraphics::GetSingletonPtr();

    // Load the server lists
    CXMLNode* pConfig = CCore::GetSingletonPtr()->GetConfig();
    m_ServerBrowser.LoadServerList(pConfig->FindSubNode(CONFIG_NODE_SERVER_FAV), CONFIG_FAVOURITE_LIST_TAG, m_ServerBrowser.GetFavouritesList());
    m_ServerBrowser.LoadServerList(pConfig->FindSubNode(CONFIG_NODE_SERVER_REC), CONFIG_RECENT_LIST_TAG, m_ServerBrowser.GetRecentList());
    m_ServerBrowser.LoadServerList(pConfig->FindSubNode(CONFIG_NODE_SERVER_HISTORY), CONFIG_HISTORY_LIST_TAG, m_ServerBrowser.GetHistoryList());

    // Remove unused node
    if (CXMLNode* pOldNode = pConfig->FindSubNode(CONFIG_NODE_SERVER_INT))
        pConfig->DeleteSubNode(pOldNode);

#ifdef CI_BUILD
    // Add feature branch alert
    m_pFeatureBranchAlertTexture.reset(reinterpret_cast<CGUITexture*>(m_pManager->CreateTexture()));
    std::int32_t buffer = 0xFFFF0000;
    m_pFeatureBranchAlertTexture->LoadFromMemory(&buffer, 1, 1);            // HACK: Load red dot

    m_pFeatureBranchAlertImage.reset(reinterpret_cast<CGUIStaticImage*>(m_pManager->CreateStaticImage(m_pBackground)));
    m_pFeatureBranchAlertImage->LoadFromTexture(m_pFeatureBranchAlertTexture.get());
    m_pFeatureBranchAlertImage->SetPosition({0.0f, 0.0f}, false);
    m_pFeatureBranchAlertImage->SetSize({ScreenSize.fX, 35.0f});

    m_pFeatureBranchAlertLabel.reset(reinterpret_cast<CGUILabel*>(m_pManager->CreateLabel(m_pFeatureBranchAlertImage.get())));
    m_pFeatureBranchAlertLabel->SetText(
        _("You are using a feature-branch build! This is a test build only which cannot be used to connect to public servers!"));
    m_pFeatureBranchAlertLabel->SetPosition({0.0f, 0.0f}, false);
    m_pFeatureBranchAlertLabel->SetSize({ScreenSize.fX, 35.0f});
    m_pFeatureBranchAlertLabel->SetFont("clear-normal");
    m_pFeatureBranchAlertLabel->SetHorizontalAlign(CGUI_ALIGN_HORIZONTALCENTER);
    m_pFeatureBranchAlertLabel->SetVerticalAlign(CGUI_ALIGN_VERTICALCENTER);
#endif
}
예제 #18
0
bool CLocalServer::Load ( void )
{
    // Get server module root
    SString strServerPath = g_pCore->GetInstallRoot ();
    strServerPath += "/server/mods/deathmatch";

    SString strConfigPath ( "%s/%s", strServerPath.c_str (), m_strConfig.c_str () );
    m_pConfig = g_pCore->GetXML ()->CreateXML ( strConfigPath );
    if ( m_pConfig && m_pConfig->Parse() )
    {
        CXMLNode* pRoot = m_pConfig->GetRootNode();
        CXMLNode* pServerName = pRoot->FindSubNode ( "servername", 0 );
        if ( pServerName ) m_pEditName->SetText ( pServerName->GetTagContent().c_str() );
        CXMLNode* pServerPass = pRoot->FindSubNode ( "password", 0 );
        if ( pServerPass ) m_pEditPass->SetText ( pServerPass->GetTagContent().c_str() );
        CXMLNode* pServerPlayers = pRoot->FindSubNode ( "maxplayers", 0 );
        if ( pServerPlayers ) m_pEditPlayers->SetText ( pServerPlayers->GetTagContent().c_str() );

        // Read the startup resources
        list < CXMLNode* > ::const_iterator iter = pRoot->ChildrenBegin ();
        for ( ; iter != pRoot->ChildrenEnd (); iter++ )
        {
            CXMLNode* pNode = reinterpret_cast < CXMLNode* > ( *iter );
            if ( pNode->GetTagName ().compare ( "resource" ) == 0 )
            {
                CXMLAttribute* src = pNode->GetAttributes().Find ( "src" );
                if ( src && src->GetValue()[1] )
                {
                    m_pResourcesCur->SetItemText ( m_pResourcesCur->AddRow (), m_hResourcesCur, src->GetValue().c_str() );
                }
            }
        }
    }
    //

    SString strResourceDirectoryPath ( "%s/resources/*", strServerPath.c_str () );

    unsigned int uiCount = 0;

    #ifdef WIN32

        // Find all .map files in the maps folder
        WIN32_FIND_DATA FindData;
        HANDLE hFind = FindFirstFile ( strResourceDirectoryPath, &FindData );
        if ( hFind != INVALID_HANDLE_VALUE )
        {
            // Remove the extension and store the time
            FindData.cFileName [ strlen ( FindData.cFileName ) - 4 ] = 0;
            // Add each file
            do
            {
                if ( strcmp ( FindData.cFileName, ".." ) != 0 && strcmp ( FindData.cFileName, "." ) != 0 )
                {
                    char * extn = NULL;
                    if ( ( FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) != FILE_ATTRIBUTE_DIRECTORY )
                    {
                        extn = &FindData.cFileName [ strlen ( FindData.cFileName ) - 3 ];
                        FindData.cFileName [ strlen ( FindData.cFileName ) - 4 ] = 0;
                    }

                    if ( extn == NULL || strcmp ( extn, "zip" ) == 0 )
                    {
                        // Add the resource
                        HandleResource ( FindData.cFileName );

                        // Increment the counter
                        uiCount++;
                    }
                }
            } while ( FindNextFile ( hFind, &FindData ) );

            // Close the search
            FindClose ( hFind );
        }
    #else
        DIR *Dir;
		struct dirent *DirEntry;
		time_t llHighestTime = 0;
		char szPath[MAX_PATH] = {0};

		if ( ( Dir = opendir ( strResourceDirectoryPath ) ) )
		{
			while ( ( DirEntry = readdir ( Dir ) ) != NULL )
			{
                // Skip . and .. entry
                if ( strcmp ( DirEntry->d_name, "." ) != 0 && 
                     strcmp ( DirEntry->d_name, ".." ) != 0 )
                {
				    struct stat Info;
				    bool bDir = false;

				    // Get the path
				    if ( strlen(szBuffer) + strlen(DirEntry->d_name) < MAX_PATH )
                    {
					    strcpy ( szPath, szBuffer );
					    unsigned long ulPathLength = strlen ( szPath );

					    if ( szPath [ ulPathLength-1 ] != '/') strcat ( szPath, "/" );

					    strcat ( szPath, DirEntry->d_name );

					    // Determine the file stats
					    if ( lstat ( szPath, &Info ) != -1 )
						    bDir = S_ISDIR ( Info.st_mode );
					    else
						    CLogger::ErrorPrintf ( "Unable to stat %s\n", szPath );

				        // Chop off the extension if it's not a dir
				        char * extn = NULL;
				        if ( !bDir )
                        {
					        extn = &(DirEntry->d_name [ strlen ( DirEntry->d_name ) - 3 ]);
					        DirEntry->d_name [ strlen ( DirEntry->d_name ) - 4 ] = 0;
				        }
                        if ( extn == NULL || strcmp ( extn, "zip" ) == 0 )
                        {
                            // Add the resource
                            HandleResource ( DirEntry->d_name );

                            // Increment the counter
                            uiCount++;
                        }

				    }
                }


			}

			// Close the directory handle
			closedir ( Dir );
		}
    #endif
    return true;
}
예제 #19
0
///////////////////////////////////////////////////////////////
//
// CJoystickManager::LoadFromXML
//
// Load axes mapping for the current joypad.
//
///////////////////////////////////////////////////////////////
bool CJoystickManager::LoadFromXML ( void )
{
    m_SettingsRevision++;

    // Try load
    CXMLNode* pMainNode = GetConfigNode ( false );

    if ( !pMainNode )
        return false;

    int iErrors = 0;

    {
        // Find the 'info' node
        CXMLNode* pNode = pMainNode->FindSubNode ( "info" );

        // If it was found
        if ( pNode )
        {
            CXMLAttributes* pAttributes = &pNode->GetAttributes ();

            CXMLAttribute* pA = NULL;
            if ( pA = pAttributes->Find( "deadzone" ) )
                m_DevInfo.iDeadZone = Clamp ( 0, atoi ( pA->GetValue ().c_str () ), 49 );
            else
                iErrors++;

            if ( pA = pAttributes->Find( "saturation" ) )
                m_DevInfo.iSaturation = Clamp ( 51, atoi ( pA->GetValue ().c_str () ), 100 );
            else
                iErrors++;
        }
        else
            iErrors++;

    }

    // Iterate the binds reading them from the XML tree
    for ( int i = 0 ; i < NUMELMS(m_currentMapping) ; i++ )
    {
        SMappingLine& line = m_currentMapping[i];

        // Find the 'axis' node
        CXMLNode* pNode = pMainNode->FindSubNode( "axis", i );

        // If it was found
        if ( pNode )
        {
            CXMLAttributes* pAttributes = &pNode->GetAttributes ();

            CXMLAttribute* pA = NULL;
            if ( pA = pAttributes->Find( "source_index" ) )
                line.SourceAxisIndex = (eJoy)Clamp < int > ( 0, atoi ( pA->GetValue ().c_str () ), eJoyMax );
            else
                iErrors++;

            if ( pA = pAttributes->Find( "source_dir" ) )
                line.SourceAxisDir = (eDir)Clamp < int > ( 0, atoi ( pA->GetValue ().c_str () ), eDirMax );
            else
                iErrors++;

            if ( pA = pAttributes->Find( "output_index" ) )
                line.OutputAxisIndex = (eStick)Clamp < int > ( 0, atoi ( pA->GetValue ().c_str () ), eStickMax );
            else
                iErrors++;

            if ( pA = pAttributes->Find( "output_dir" ) )
                line.OutputAxisDir = (eDir)Clamp < int > ( 0, atoi ( pA->GetValue ().c_str () ), eDirMax );
            else
                iErrors++;

            if ( pA = pAttributes->Find( "enabled" ) )
                line.bEnabled = atoi ( pA->GetValue ().c_str () ) ? true : false;
            else
                iErrors++;

            if ( pA = pAttributes->Find( "max_value" ) )
                line.MaxValue = atoi ( pA->GetValue ().c_str () );
            else
                iErrors++;

        }
        else
            iErrors++;
    }

    if ( iErrors )
        if ( CCore::GetSingleton ().GetConsole () )
            CCore::GetSingleton ().GetConsole ()->Printf( "Warning: %d errors reading joypad configuration.", iErrors );
        

    return true;
}