void Authentication_SetKey( char *_key ) { strcpy( s_authKey, _key ); // Trim end whitespace int keyLen = strlen(s_authKey); for( int i = keyLen-1; i >= 0; --i ) { if( s_authKey[i] == ' ' || s_authKey[i] == '\r' || s_authKey[i] == '\n' ) { s_authKey[i] = '\x0'; } else { break; } } if( s_enforceDemo && !Authentication_IsDemoKey(s_authKey) ) { strcpy( s_authKey, "authkey not found" ); } AppDebugOut( "Authentication key set : " ); AppDebugOut( "'%s'\n", s_authKey ); }
int Authentication_SimpleKeyCheck( char *_key ) { if( Authentication_IsHashKey(_key) ) { // This is a hash of a key // No way to perform a simple check, so much assume its ok return AuthenticationAccepted; } if( strlen(_key) > AUTHENTICATION_KEYLEN ) { return AuthenticationKeyInvalid; } int counter = 0; int total = 0; for( int i = 0; i < AUTHENTICATION_KEYLEN; ++i ) { if( i == AUTHENTICATION_KEYLEN-2 ) { // The last byte is a checking byte int requiredValue = 'A' + (total % 26); if( _key[i] != requiredValue ) { return AuthenticationKeyInvalid; } } else if( counter == 6 ) { // Every 6th byte must be a dash if( _key[i] != '-' ) { return AuthenticationKeyInvalid; } counter = 0; } else { counter++; } total += _key[i]; } // // Platform specific key restrictions: // Ambrosia keys dont work on PC // PC keys dont work on Ambrosia's Mac versiqon if( !Authentication_IsDemoKey(_key) ) { } return AuthenticationAccepted; }
bool Authentication_IsKeyFound() { if( s_enforceDemo && !Authentication_IsDemoKey(s_authKey) ) { return false; } return true; }
void Authentication_LoadKey( char *_key, const char *_filename ) { FILE *file = fopen(_filename, "rt" ); if( file ) { fscanf( file, "%s", _key ); fclose(file); } else { AppDebugOut( "Failed to load AuthKey : '%s'\n", _filename ); sprintf( _key, "authkey not found" ); } if( s_enforceDemo && !Authentication_IsDemoKey(_key) ) { strcpy( _key, "authkey not found" ); } }
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; }
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 } } }
bool Game::IsOptionEditable( int _optionId ) { // // If we are a demo, nothing is editable // Except the server name char authKey[256]; Authentication_GetKey( authKey ); if( Authentication_IsDemoKey(authKey) ) { if( stricmp(m_options[_optionId]->m_name, "ServerName" ) == 0 ) { return true; } return false; } int mode = GetOptionValue("GameMode"); char *optionName = m_options[_optionId]->m_name; if( stricmp(optionName, "TeamSwitching" ) == 0 && mode != GAMEMODE_CUSTOM ) { return false; } switch( mode ) { case GAMEMODE_STANDARD: return( stricmp(optionName, "GameSpeed") != 0 && stricmp(optionName, "RadarSharing" ) != 0 && stricmp(optionName, "VariableUnitCounts" ) != 0 && stricmp(optionName, "WorldScale" ) != 0 ); case GAMEMODE_OFFICEMODE: return( stricmp(optionName, "GameSpeed" ) != 0 && stricmp(optionName, "SlowestSpeed" ) != 0 && stricmp(optionName, "MaxGameRealTime" ) != 0 && stricmp(optionName, "VictoryTimer" ) != 0 ); case GAMEMODE_SPEEDDEFCON: return( stricmp(optionName, "GameSpeed" ) != 0 && stricmp(optionName, "MaxGameRealTime" ) != 0 && stricmp(optionName, "SlowestSpeed" ) != 0 ); case GAMEMODE_BIGWORLD: return( stricmp(optionName, "WorldScale" ) != 0 && stricmp(optionName, "CitiesPerTerritory" ) != 0 ); case GAMEMODE_DIPLOMACY: return( stricmp(optionName, "PermitDefection" ) != 0 && stricmp(optionName, "RadarSharing" ) != 0 && stricmp(optionName, "ScoreMode" ) != 0 ); case GAMEMODE_TOURNAMENT: return( stricmp(optionName, "GameMode" ) == 0 || stricmp(optionName, "TerritoriesPerTeam") == 0 || stricmp(optionName, "ServerName") == 0 ); } return true; }