public override void CDKeysAuthReply(bool valid, string auth_msg) { // close the wait box if (authWaitBox) { StopBox(); authWaitBox = false; } if (!valid) { common.DPrintf("auth key is invalid\n"); authMsg = auth_msg; if (cdkey_state == CDKEY.CHECKING) { cdkey_state = CDKEY.INVALID; } if (xpkey_state == CDKEY.CHECKING) { xpkey_state = CDKEY.INVALID; } } else { common.DPrintf("client is authed in\n"); if (cdkey_state == CDKEY.CHECKING) { cdkey_state = CDKEY.OK; } if (xpkey_state == CDKEY.CHECKING) { xpkey_state = CDKEY.OK; } } authEmitTimeout = 0; SetCDKeyGuiVars(); }
public override void ReadCDKey() { var buffer = stackalloc char[32]; cdkey_state = CDKEY.UNKNOWN; var filename = CDKEY_FILEPATH; var f = fileSystem.OpenExplicitFileRead(fileSystem.RelativePathToOSPath(filename, "fs_configpath")); // try the install path, which is where the cd installer and steam put it if (f == null) { f = fileSystem.OpenExplicitFileRead(fileSystem.RelativePathToOSPath(filename, "fs_basepath")); } if (f == null) { common.Printf($"Couldn't read {filename}.\n"); cdkey = string.Empty; } else { Unsafe.InitBlock(buffer, 0, 32); f.Read((byte *)buffer, CDKEY_BUF_LEN - 1); fileSystem.CloseFile(f); cdkey = new string(buffer, 0, CDKEY_BUF_LEN); } xpkey_state = CDKEY.UNKNOWN; filename = XPKEY_FILEPATH; f = fileSystem.OpenExplicitFileRead(fileSystem.RelativePathToOSPath(filename, "fs_configpath")); // try the install path, which is where the cd installer and steam put it if (f == null) { f = fileSystem.OpenExplicitFileRead(fileSystem.RelativePathToOSPath(filename, "fs_basepath")); } if (f == null) { common.Printf($"Couldn't read {filename}.\n"); xpkey = string.Empty; } else { Unsafe.InitBlock(buffer, 0, 32); f.Read((byte *)buffer, CDKEY_BUF_LEN - 1); fileSystem.CloseFile(f); xpkey = new string(buffer, 0, CDKEY_BUF_LEN); } }
public override void ClearCDKey(bool[] valid) { if (!valid[0]) { cdkey = ""; cdkey_state = CDKEY.UNKNOWN; } // if a key was in checking and not explicitely asked for clearing, put it back to ok else if (cdkey_state == CDKEY.CHECKING) { cdkey_state = CDKEY.OK; } if (!valid[1]) { xpkey = ""; xpkey_state = CDKEY.UNKNOWN; } else if (xpkey_state == CDKEY.CHECKING) { xpkey_state = CDKEY.OK; } WriteCDKey(); }
/// <summary> /// we toggled some key state to CDKEY_CHECKING. send a standalone auth packet to validate /// </summary> void EmitGameAuth() { // make sure the auth reply is empty, we use it to indicate an auth reply authMsg = string.Empty; if (AsyncNetwork.client.SendAuthCheck(cdkey_state == CDKEY.CHECKING ? cdkey : null, xpkey_state == CDKEY.CHECKING ? xpkey : null)) { authEmitTimeout = SysW.Milliseconds + CDKEY_AUTH_TIMEOUT; common.DPrintf("authing with the master..\n"); } // net is not available else { common.DPrintf("sendAuthCheck failed\n"); if (cdkey_state == CDKEY.CHECKING) { cdkey_state = CDKEY.OK; } if (xpkey_state == CDKEY.CHECKING) { xpkey_state = CDKEY.OK; } } }
/// <summary> /// checking that the key is present and uses only valid characters if d3xp is installed, check for a valid xpkey as well /// emit an auth packet to the master if possible and needed /// </summary> /// <param name="strict">if set to <c>true</c> [strict].</param> /// <returns></returns> public override bool CDKeysAreValid(bool strict) { int i; var emitAuth = false; if (cdkey_state == CDKEY.UNKNOWN) { if (cdkey.Length != CDKEY_BUF_LEN - 1) { cdkey_state = CDKEY.INVALID; } else { for (i = 0; i < CDKEY_BUF_LEN - 1; i++) { if (!CDKEY_DIGITS.Contains(cdkey[i])) { cdkey_state = CDKEY.INVALID; break; } } } if (cdkey_state == CDKEY.UNKNOWN) { cdkey_state = CDKEY.CHECKING; emitAuth = true; } } if (xpkey_state == CDKEY.UNKNOWN) { if (fileSystem.HasD3XP) { if (xpkey.Length != CDKEY_BUF_LEN - 1) { xpkey_state = CDKEY.INVALID; } else { for (i = 0; i < CDKEY_BUF_LEN - 1; i++) { if (!CDKEY_DIGITS.Contains(xpkey[i])) { xpkey_state = CDKEY.INVALID; } } } if (xpkey_state == CDKEY.UNKNOWN) { xpkey_state = CDKEY.CHECKING; emitAuth = true; } } else { xpkey_state = CDKEY.NA; } } if (emitAuth) { EmitGameAuth(); } // make sure to keep the mainmenu gui up to date in case we made state changes SetCDKeyGuiVars(); if (strict) { return(cdkey_state == CDKEY.OK && (xpkey_state == CDKEY.OK || xpkey_state == CDKEY.NA)); } else { return((cdkey_state == CDKEY.OK || cdkey_state == CDKEY.CHECKING) && (xpkey_state == CDKEY.OK || xpkey_state == CDKEY.CHECKING || xpkey_state == CDKEY.NA)); } }