MCPcopy Create free account
hub / github.com/dhewm/dhewm3 / Session_PromptKey_f

Function Session_PromptKey_f

neo/framework/Session.cpp:251–310  ·  view source on GitHub ↗

=================== Session_PromptKey_f =================== */

Source from the content-addressed store, hash-verified

249===================
250*/
251static void Session_PromptKey_f( const idCmdArgs &args ) {
252 const char *retkey;
253 bool valid[ 2 ];
254 static bool recursed = false;
255
256 if ( recursed ) {
257 common->Warning( "promptKey recursed - aborted" );
258 return;
259 }
260 recursed = true;
261
262 do {
263 // in case we're already waiting for an auth to come back to us ( may happen exceptionally )
264 if ( sessLocal.MaybeWaitOnCDKey() ) {
265 if ( sessLocal.CDKeysAreValid( true ) ) {
266 recursed = false;
267 return;
268 }
269 }
270 // the auth server may have replied and set an error message, otherwise use a default
271 const char *prompt_msg = sessLocal.GetAuthMsg();
272 if ( prompt_msg[ 0 ] == '\0' ) {
273 prompt_msg = common->GetLanguageDict()->GetString( "#str_04308" );
274 }
275 retkey = sessLocal.MessageBox( MSG_CDKEY, prompt_msg, common->GetLanguageDict()->GetString( "#str_04305" ), true, NULL, NULL, true );
276 if ( retkey ) {
277 if ( sessLocal.CheckKey( retkey, false, valid ) ) {
278 // if all went right, then we may have sent an auth request to the master ( unless the prompt is used during a net connect )
279 bool canExit = true;
280 if ( sessLocal.MaybeWaitOnCDKey() ) {
281 // wait on auth reply, and got denied, prompt again
282 if ( !sessLocal.CDKeysAreValid( true ) ) {
283 // server says key is invalid - MaybeWaitOnCDKey was interrupted by a CDKeysAuthReply call, which has set the right error message
284 // the invalid keys have also been cleared in the process
285 sessLocal.MessageBox( MSG_OK, sessLocal.GetAuthMsg(), common->GetLanguageDict()->GetString( "#str_04310" ), true, NULL, NULL, true );
286 canExit = false;
287 }
288 }
289 if ( canExit ) {
290 // make sure that's saved on file
291 sessLocal.WriteCDKey();
292 sessLocal.MessageBox( MSG_OK, common->GetLanguageDict()->GetString( "#str_04307" ), common->GetLanguageDict()->GetString( "#str_04305" ), true, NULL, NULL, true );
293 break;
294 }
295 } else {
296 // offline check sees key invalid
297 // build a message about keys being wrong. do not attempt to change the current key state though
298 // ( the keys may be valid, but user would have clicked on the dialog anyway, that kind of thing )
299 idStr msg;
300 idAsyncNetwork::BuildInvalidKeyMsg( msg, valid );
301 sessLocal.MessageBox( MSG_OK, msg, common->GetLanguageDict()->GetString( "#str_04310" ), true, NULL, NULL, true );
302 }
303 } else if ( args.Argc() == 2 && idStr::Icmp( args.Argv(1), "force" ) == 0 ) {
304 // cancelled in force mode
305 cmdSystem->BufferCommandText( CMD_EXEC_APPEND, "quit\n" );
306 cmdSystem->ExecuteCommandBuffer();
307 }
308 } while ( retkey );

Callers

nothing calls this directly

Calls 13

MaybeWaitOnCDKeyMethod · 0.80
CDKeysAreValidMethod · 0.80
GetAuthMsgMethod · 0.80
CheckKeyMethod · 0.80
WriteCDKeyMethod · 0.80
ArgcMethod · 0.80
ArgvMethod · 0.80
BufferCommandTextMethod · 0.80
ExecuteCommandBufferMethod · 0.80
WarningMethod · 0.45
GetStringMethod · 0.45
GetLanguageDictMethod · 0.45

Tested by

no test coverage detected