Example #1
0
void App::InitMetaServer()
{
    //
    // Load our Auth Key

#if defined(RETAIL_DEMO)
  // Anthentication_EnforceDemo();
#endif

    char authKey[256];
    Authentication_LoadKey( authKey, App::GetAuthKeyPath() );
    Authentication_SetKey( authKey );
    
    int result = Authentication_SimpleKeyCheck( authKey );
    Authentication_RequestStatus( authKey );

    if( result < 0 )
    {
#if defined(RETAIL_DEMO)
      //  char authKeyNew[256];
      //  Authentication_GenerateKey( authKeyNew, true );
       // Authentication_SetKey( authKeyNew );
       // Authentication_SaveKey( authKeyNew, App::GetAuthKeyPath() );
    
       // EclRegisterWindow( new WelcomeToDemoWindow() );
#else
        AuthKeyWindow *window = new AuthKeyWindow();
        EclRegisterWindow( window );
#endif
    }

    //
    // Connect to the MetaServer

    char *metaServerLocation = "metaserver.introversion.co.uk";
    //metaServerLocation = "10.0.0.4";
    int port = g_preferences->GetInt( PREFS_NETWORKMETASERVER );

    MetaServer_Initialise();

    MetaServer_Connect( metaServerLocation, PORT_METASERVER_LISTEN, port );

    MatchMaker_LocateService( metaServerLocation, PORT_METASERVER_LISTEN );
}
Example #2
0
static NetCallBackRetType AuthenticationThread(void *ignored)
{
#ifdef WAN_PLAY_ENABLED

    //
    // Every few seconds request the next key to be authenticated

    while( true )
    {
        NetSleep( PERIOD_AUTHENTICATION_RETRY );

        if( MetaServer_IsConnected() )
        {
            char unknownKey[256];
            char clientIp[256];
            int  keyId = -1;
            bool unknownKeyFound = false;

            //
            // Look for a key that isnt yet authenticated

            s_authResultsMutex.Lock();
            for( int i = 0; i < s_authResults.Size(); ++i )
            {
                AuthenticationResult *authResult = s_authResults[i];
                if( authResult->m_authResult == AuthenticationUnknown &&
                    authResult->m_numTries < 5 )
                {
                    strcpy( unknownKey, authResult->m_authKey );
                    strcpy( clientIp, authResult->m_ip );
                    keyId = authResult->m_keyId;
                    authResult->m_numTries++;
                    unknownKeyFound = true;
                    break;
                }
            }        
            s_authResultsMutex.Unlock();
    
        
            //
            // Check the key out

            if( unknownKeyFound )
            {
                int basicResult = Authentication_SimpleKeyCheck(unknownKey);
                if( basicResult < 0 )
                {
                    // The key is in the wrong format
                    Authentication_SetStatus( unknownKey, keyId, basicResult );
                    char *resultString = Authentication_GetStatusString(basicResult);
                    AppDebugOut( "Key failed basic check : %s (result=%s)\n", unknownKey, resultString );
                }
                else if( Authentication_IsDemoKey(unknownKey) )
                {
                    // This is a demo key, and has passed the simple check
                    // Assume its valid from now on
                    Authentication_SetStatus( unknownKey, -1, AuthenticationAccepted );
                    AppDebugOut( "Auth Key accepted as DEMOKEY : %s\n", unknownKey );
                }
                else
                {
                    // Request a proper auth check from the metaserver
                    Directory directory;
                    directory.SetName( NET_METASERVER_MESSAGE );
                    directory.CreateData( NET_METASERVER_COMMAND, NET_METASERVER_REQUEST_AUTH );
                    directory.CreateData( NET_METASERVER_AUTHKEY, unknownKey );
                    directory.CreateData( NET_METASERVER_AUTHKEYID, keyId );
                    directory.CreateData( NET_METASERVER_GAMENAME, APP_NAME );
                    directory.CreateData( NET_METASERVER_GAMEVERSION, APP_VERSION );
                    
                    if( strcmp(clientIp, "unknown") != 0 )
                    {
                        directory.CreateData( NET_METASERVER_IP, clientIp );
                    }

                    MetaServer_SendToMetaServer( &directory );

                    AppDebugOut( "Requesting authentication of key %s\n", unknownKey );
                }
            }
        }
    }

#endif
    
    return 0;
}
Example #3
0
void AuthKeyWindow::Render( bool _hasFocus )
{
    InterfaceWindow::Render( _hasFocus );
    
    char authKey[256];
    Authentication_GetKey( authKey );
    

    //
    // Render results of our Auth Check

    int simpleResult = Authentication_SimpleKeyCheck(authKey);

    if( stricmp( authKey, "authkey not found" ) == 0 ||
        strlen(authKey) < 3 )
    {
        g_renderer->TextCentreSimple( m_x + m_w/2, m_y + 130, White, 18, LANGUAGEPHRASE("dialog_type_authkey_or_demo_1") );
        g_renderer->TextCentreSimple( m_x + m_w/2, m_y + 160, White, 18, LANGUAGEPHRASE("dialog_type_authkey_or_demo_2") );
    }
    else
    {
        double timeNow = GetHighResTime();
        if( timeNow > m_keyCheckTimer )
        {
            Authentication_RequestStatus( authKey );
            m_keyCheckTimer = timeNow + 1.0f;
        }

        Colour mainText = White;
        Colour subtext = White;

        int authStatus = Authentication_GetStatus(authKey);
        char authStatusString[256];
        sprintf( authStatusString,"%s", LANGUAGEPHRASE(Authentication_GetStatusStringLanguagePhrase(authStatus)) );
        strupr( authStatusString );

        if( authStatus == AuthenticationUnknown )
        {
            if( m_timeOutTimer == 0.0f )
            {
                m_timeOutTimer = timeNow + 5.0f;
            }
            else if( timeNow > m_timeOutTimer )
            {
                sprintf( authStatusString, LANGUAGEPHRASE("dialog_auth_status_unknown") );
            }
            else
            {
                sprintf( authStatusString, LANGUAGEPHRASE("dialog_auth_status_checking") );
                if( fmodf(timeNow*2,2) < 1 ) subtext.m_a *= 0.5f;
            }            
        }
        else
        {
            m_timeOutTimer = 0.0f;
        }

        if( Authentication_IsDemoKey(authKey) &&
            authStatus == AuthenticationAccepted )
        {
            sprintf( authStatusString, LANGUAGEPHRASE("dialog_auth_status_demo_user") );
        }

        g_renderer->SetFont( "kremlin" );
        g_renderer->TextCentreSimple( m_x+m_w/2, m_y+140, mainText, 20, LANGUAGEPHRASE("dialog_auth_status") );
        g_renderer->TextCentreSimple( m_x+m_w/2, m_y+160, subtext, 30, authStatusString );
        g_renderer->SetFont();

        if( authStatus == AuthenticationWrongPlatform )
        {
        #if defined TARGET_MSVC
			g_renderer->TextCentreSimple( m_x+m_w/2, m_y+195, subtext, 14, LANGUAGEPHRASE("dialog_cannot_use_mac_key_on_pc") );
        #endif

        }

    }
}