AuthKeyWindow::AuthKeyWindow() : InterfaceWindow( "Authentication", "dialog_authoptions", true ), m_keyCheckTimer(0.0f), m_timeOutTimer(0.0f) { SetSize( 700, 250 ); Centralise(); Authentication_GetKey( m_key ); }
void Render( int realX, int realY, bool highlighted, bool clicked ) { AuthKeyWindow *parent = (AuthKeyWindow *)m_parent; char realKey[256]; Authentication_GetKey( realKey ); if( strcmp( realKey, parent->m_key ) != 0 ) { InterfaceButton::Render( realX, realY, highlighted, clicked ); } }
bool PlayDemoButton::IsVisible() { if( m_forceVisible ) { return true; } char authKey[256]; Authentication_GetKey( authKey ); int authStatus = Authentication_GetStatus(authKey); return( authStatus != AuthenticationAccepted && authStatus != AuthenticationUnknown ); }
void AuthKeyWindow::Create() { InterfaceWindow::Create(); InvertedBox *invert = new InvertedBox(); invert->SetProperties( "invert", 10, 30, m_w-20, m_h - 70, " ", " ", false, false ); RegisterButton( invert ); AuthInputField *input = new AuthInputField(); input->SetProperties( "Key", 40, 50, 620, 30, " ", " ", false, false ); input->RegisterString( m_key ); RegisterButton( input ); // Only show the paste button on platforms with a paste implementation #if defined(TARGET_MSVC) || defined(TARGET_OS_MACOSX) PasteKeyButton *paste = new PasteKeyButton(); paste->SetProperties( "Paste", 10, m_h-30, 100, 20, "dialog_paste", "dialog_paste_tooltip", true, true ); RegisterButton( paste ); #endif ApplyKeyButton *apply = new ApplyKeyButton(); apply->SetProperties( "Apply", m_w-220, m_h-30, 100, 20, "dialog_apply", " ", true, false ); RegisterButton( apply ); PlayDemoButton *demo = new PlayDemoButton(); demo->SetProperties( "Play Demo", m_w/2-50, m_h-30, 100, 20, "dialog_play_demo", " ", true, false ); demo->m_forceVisible = false; RegisterButton( demo ); CloseButton *close = new CloseButton(); close->SetProperties( "Close", m_w-110, m_h-30, 100, 20, "dialog_close", " ", true, false ); RegisterButton(close); // // Auto-select the chat box if the key is empty char authKey[256]; Authentication_GetKey( authKey ); if( stricmp(authKey, "authkey not found") == 0 || strlen(authKey) < 3 ) { input->MouseUp(); } }
void Authentication_GetKeyHash( char *_key ) { char keyTemp[256]; Authentication_GetKey(keyTemp); Authentication_GetKeyHash( keyTemp, _key, s_hashToken ); }
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 ProcessServerLetters( Directory *letter ) { if( strcmp( letter->m_name, NET_DEFCON_MESSAGE ) != 0 || !letter->HasData( NET_DEFCON_COMMAND ) ) { AppDebugOut( "Client received bogus message, discarded (4)\n" ); return true; } char *cmd = letter->GetDataString( NET_DEFCON_COMMAND ); if( strcmp( cmd, NET_DEFCON_CLIENTHELLO ) == 0 ) { int clientId = letter->GetDataInt(NET_DEFCON_CLIENTID); if( clientId == g_app->GetClientToServer()->m_clientId ) { g_app->GetClientToServer()->m_connectionState = ClientToServer::StateConnected; AppDebugOut( "CLIENT : Received HelloClient from Server\n" ); if( !g_app->GetTutorial() ) { g_app->GetClientToServer()->RequestTeam( Team::TypeLocalPlayer ); } } // If this is a Demo client, make a note of that if( letter->HasData( NET_DEFCON_CLIENTISDEMO ) ) { g_app->GetClientToServer()->SetClientDemo( clientId ); } // This might be a client rejoining the game // Need to give him his teams back g_app->GetWorld()->ReassignTeams( clientId ); return true; } else if( strcmp( cmd, NET_DEFCON_CLIENTGOODBYE ) == 0 ) { int clientId = letter->GetDataInt(NET_DEFCON_CLIENTID); int reason = letter->GetDataInt(NET_DEFCON_DISCONNECT); AppDebugOut( "CLIENT : Client %d left the game\n", clientId ); g_app->GetWorld()->RemoveTeams( clientId, reason ); g_app->GetWorld()->RemoveSpectator( clientId ); g_app->GetClientToServer()->SetSyncState( clientId, true ); return true; } else if( strcmp( cmd, NET_DEFCON_CLIENTID ) == 0 ) { int clientId = letter->GetDataInt(NET_DEFCON_CLIENTID); AppDebugOut( "CLIENT : Received ClientID of %d\n", clientId ); if( g_app->GetClientToServer()->m_clientId != -1 ) { AppAssert( g_app->GetClientToServer()->m_clientId == clientId ); return true; } g_app->GetClientToServer()->m_clientId = clientId; g_app->GetClientToServer()->m_connectionState = ClientToServer::StateHandshaking; g_lastProcessedSequenceId = -1; if( letter->HasData( NET_DEFCON_VERSION, DIRECTORY_TYPE_STRING ) ) { char *serverVersion = letter->GetDataString( NET_DEFCON_VERSION ); strcpy( g_app->GetClientToServer()->m_serverVersion, serverVersion ); AppDebugOut( "CLIENT : Server version is %s\n", serverVersion ); } if( !VersionManager::DoesSupportModSystem( g_app->GetClientToServer()->m_serverVersion ) ) { // This server is too old to support Mods, so make sure we de-activate any critical ones g_modSystem->DeActivateAllCriticalMods(); if( g_modSystem->CommitRequired() ) { g_modSystem->Commit(); g_app->RestartAmbienceMusic(); } } return true; } else if( strcmp( cmd, NET_DEFCON_TEAMASSIGN ) == 0 ) { int clientId = letter->GetDataInt(NET_DEFCON_CLIENTID); int teamId = letter->GetDataInt(NET_DEFCON_TEAMID); int teamType = letter->GetDataInt(NET_DEFCON_TEAMTYPE); if( teamType != Team::TypeAI && clientId != g_app->GetClientToServer()->m_clientId ) { teamType = Team::TypeRemotePlayer; } g_app->GetWorld()->InitialiseTeam(teamId, teamType, clientId ); return true; } else if( strcmp( cmd, NET_DEFCON_SPECTATORASSIGN ) == 0 ) { int clientId = letter->GetDataInt(NET_DEFCON_CLIENTID); g_app->GetWorld()->InitialiseSpectator(clientId); if( clientId == g_app->GetClientToServer()->m_clientId ) { AppDebugOut( "CLIENT: I am a spectator\n" ); } return true; } else if( strcmp( cmd, NET_DEFCON_NETSYNCERROR ) == 0 ) { int clientId = letter->GetDataInt(NET_DEFCON_CLIENTID); AppDebugOut( "SYNCERROR Server informed us that Client %d is out of Sync\n", clientId ); g_app->GetClientToServer()->SetSyncState( clientId, false ); char *syncId = letter->GetDataString( NET_DEFCON_SYNCERRORID ); DumpSyncLogs(syncId); return true; } else if( strcmp( cmd, NET_DEFCON_NETSYNCFIXED ) == 0 ) { int clientId = letter->GetDataInt(NET_DEFCON_CLIENTID); AppDebugOut( "SYNCFIXED Server informed us that Client %d has repaired his Sync Error\n", clientId ); g_app->GetClientToServer()->SetSyncState( clientId, true ); return true; } else if( strcmp( cmd, NET_DEFCON_DISCONNECT ) == 0 ) { if( g_app->GetClientToServer()->m_connectionState > ClientToServer::StateDisconnected ) { g_app->ShutdownCurrentGame(); if ( EclGetWindow("LOBBY") ) EclRemoveWindow( "LOBBY" ); if ( EclGetWindow("Comms Window") ) EclRemoveWindow( "Comms Window" ); if ( EclGetWindow("Preparing Game...") ) EclRemoveWindow("Preparing Game..." ); g_app->GetInterface()->OpenSetupWindows(); char *reason; char *reasonLanguagePhrase; int reasonDisconnectInt = letter->GetDataInt(NET_DEFCON_DISCONNECT); switch( reasonDisconnectInt ) { case Disconnect_ClientLeave: reason = "You have left the game"; reasonLanguagePhrase = "dialog_disconnect_client_leave"; break; case Disconnect_ServerShutdown: reason = "The server has shutdown"; reasonLanguagePhrase = "dialog_disconnect_server_shutdown"; break; case Disconnect_InvalidKey: reason = "You are using an invalid key"; reasonLanguagePhrase = "dialog_disconnect_invalid_key"; break; case Disconnect_DuplicateKey: reason = "You are using a duplicate key"; reasonLanguagePhrase = "dialog_disconnect_duplicate_key"; break; case Disconnect_KeyAuthFailed: reason = "Key authentication failed"; reasonLanguagePhrase = "dialog_disconnect_key_auth_failed"; break; case Disconnect_BadPassword: reason = "Invalid Password Entered"; reasonLanguagePhrase = "dialog_disconnect_bad_password"; break; case Disconnect_GameFull: reason = "Game is already full"; reasonLanguagePhrase = "dialog_disconnect_game_full"; break; case Disconnect_KickedFromGame: reason = "Kicked by the Server"; reasonLanguagePhrase = "dialog_disconnect_kicked_from_game"; break; case Disconnect_DemoFull: reason = "Too many Demo Players already"; reasonLanguagePhrase = "dialog_disconnect_demo_full"; break; default: reason = "Unknown"; reasonLanguagePhrase = "dialog_disconnect_unknown"; break; } if( reasonDisconnectInt == Disconnect_KeyAuthFailed || reasonDisconnectInt == Disconnect_InvalidKey || reasonDisconnectInt == Disconnect_DuplicateKey ) { char authKey[256]; if( Authentication_IsKeyFound() ) { Authentication_GetKey( authKey ); } else { sprintf( authKey, LANGUAGEPHRASE("dialog_authkey_not_found") ); } BadKeyWindow *badKey = new BadKeyWindow(); sprintf( badKey->m_extraMessage, LANGUAGEPHRASE("dialog_auth_error") ); LPREPLACESTRINGFLAG( 'E', LANGUAGEPHRASE(reasonLanguagePhrase), badKey->m_extraMessage ); LPREPLACESTRINGFLAG( 'K', authKey, badKey->m_extraMessage ); EclRegisterWindow(badKey); } else if( reasonDisconnectInt == Disconnect_DemoFull ) { int maxGameSize; int maxDemoPlayers; bool allowDemoServers; g_app->GetClientToServer()->GetDemoLimitations( maxGameSize, maxDemoPlayers, allowDemoServers ); BadKeyWindow *badKey = new BadKeyWindow(); sprintf( badKey->m_extraMessage, LANGUAGEPHRASE("dialog_server_demo_restricted") ); LPREPLACEINTEGERFLAG( 'N', maxDemoPlayers, badKey->m_extraMessage ); badKey->m_offerDemo = false; EclRegisterWindow(badKey); } else { MessageDialog *dialog = new MessageDialog( "Disconnected", reasonLanguagePhrase, true, "dialog_disconnected", true ); EclRegisterWindow( dialog ); } AppDebugOut( "CLIENT : Received Disconnect from server : %s\n", reason ); #ifdef TESTBED if( letter->GetDataInt(NET_DEFCON_DISCONNECT) == Disconnect_ServerShutdown ) { RestartTestBed(1, "Client Disconnect"); } #endif } return true; } else if( strcmp( cmd, NET_DEFCON_SETMODPATH ) == 0 ) { char *modPath = letter->GetDataString( NET_DEFCON_SETMODPATH ); AppDebugOut( "Server has set the MOD path: '%s'\n", modPath ); if( !g_modSystem->IsCriticalModPathSet( modPath ) ) { if( g_modSystem->CanSetModPath( modPath ) ) { g_modSystem->DeActivateAllCriticalMods(); g_modSystem->SetModPath( modPath ); } else { char reason[8192]; sprintf( reason, LANGUAGEPHRASE("dialog_error_mod_path_caption") ); char modPathCopy[4096]; strcpy( modPathCopy, modPath ); LList<char *> *tokens = g_modSystem->ParseModPath( modPathCopy ); for( int i = 0; i < tokens->Size(); i+=2 ) { char *modName = tokens->GetData(i); char *version = tokens->GetData(i+1); strcat( reason, modName ); strcat( reason, " " ); strcat( reason, version ); if( !g_modSystem->IsModInstalled( modName, version ) ) { strcat( reason, " " ); strcat( reason, LANGUAGEPHRASE("dialog_mod_not_installed") ); } strcat( reason, "\n" ); } delete tokens; MessageDialog *dialog = new MessageDialog( "Error setting MOD path", reason, false, "dialog_error_mod_path_title", true ); EclRegisterWindow( dialog ); } } return true; } else { return false; } }
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; }