static void SaveUserPass(LoginDialogParam *pLoginParam, char *password) { plString theUser = pLoginParam->username; plString thePass = password; HKEY hKey; RegCreateKeyEx(HKEY_CURRENT_USER, plFormat("Software\\Cyan, Inc.\\{}\\{}", plProduct::LongName(), GetServerDisplayName()).c_str(), 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL); RegSetValueEx(hKey, "LastAccountName", NULL, REG_SZ, (LPBYTE) pLoginParam->username, kMaxAccountNameLength); RegSetValueEx(hKey, "RememberPassword", NULL, REG_DWORD, (LPBYTE) &(pLoginParam->remember), sizeof(LPBYTE)); RegCloseKey(hKey); // If the password field is the fake string // then we've already loaded the hash. if (thePass.Compare(FAKE_PASS_STRING) != 0) { StoreHash(theUser, thePass, pLoginParam); pfPasswordStore* store = pfPasswordStore::Instance(); if (pLoginParam->remember) store->SetPassword(pLoginParam->username, thePass); else store->SetPassword(pLoginParam->username, plString::Null); } NetCommSetAccountUsernamePassword(theUser, pLoginParam->namePassHash); // FIXME: Real OS detection NetCommSetAuthTokenAndOS(nil, L"win"); }
static void SaveUserPass (LoginDialogParam *pLoginParam, char *password) { uint32_t cryptKey[4]; memset(cryptKey, 0, sizeof(cryptKey)); GetCryptKey(cryptKey, arrsize(cryptKey)); plString theUser = pLoginParam->username; plString thePass = plString(password).Left(kMaxPasswordLength); // if the password field is the fake string then we've already // loaded the namePassHash from the file if (thePass.Compare(FAKE_PASS_STRING) != 0) { // Regex search for primary email domain std::vector<plString> match = theUser.RESearch("[^@]+@([^.]+\\.)*([^.]+)\\.[^.]+"); if (match.empty() || match[2].CompareI("gametap") == 0) { plSHA1Checksum shasum(StrLen(password) * sizeof(password[0]), (uint8_t*)password); uint32_t* dest = reinterpret_cast<uint32_t*>(pLoginParam->namePassHash); const uint32_t* from = reinterpret_cast<const uint32_t*>(shasum.GetValue()); // I blame eap for this ass shit dest[0] = hsToBE32(from[0]); dest[1] = hsToBE32(from[1]); dest[2] = hsToBE32(from[2]); dest[3] = hsToBE32(from[3]); dest[4] = hsToBE32(from[4]); } else { CryptHashPassword(theUser, thePass, pLoginParam->namePassHash); } } NetCommSetAccountUsernamePassword(theUser.ToWchar(), pLoginParam->namePassHash); // FIXME: Real OS detection NetCommSetAuthTokenAndOS(nil, L"win"); plFileName loginDat = plFileName::Join(plFileSystem::GetInitPath(), "login.dat"); #ifndef PLASMA_EXTERNAL_RELEASE // internal builds can use the local init directory plFileName local("init\\login.dat"); if (plFileInfo(local).Exists()) loginDat = local; #endif hsStream* stream = plEncryptedStream::OpenEncryptedFileWrite(loginDat, cryptKey); if (stream) { stream->Write(sizeof(cryptKey), cryptKey); stream->WriteSafeString(pLoginParam->username); stream->WriteBool(pLoginParam->remember); if (pLoginParam->remember) stream->Write(sizeof(pLoginParam->namePassHash), pLoginParam->namePassHash); stream->Close(); delete stream; } }
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nCmdShow) { PF_CONSOLE_INIT_ALL() // Set global handle gHInst = hInst; CCmdParser cmdParser(s_cmdLineArgs, arrsize(s_cmdLineArgs)); cmdParser.Parse(); bool doIntroDialogs = true; #ifndef PLASMA_EXTERNAL_RELEASE if (cmdParser.IsSpecified(kArgSkipLoginDialog)) doIntroDialogs = false; if (cmdParser.IsSpecified(kArgLocalData)) { gDataServerLocal = true; gSkipPreload = true; } if (cmdParser.IsSpecified(kArgSkipPreload)) gSkipPreload = true; #endif plFileName serverIni = "server.ini"; if (cmdParser.IsSpecified(kArgServerIni)) serverIni = plString::FromWchar(cmdParser.GetString(kArgServerIni)); // check to see if we were launched from the patcher bool eventExists = false; // we check to see if the event exists that the patcher should have created HANDLE hPatcherEvent = CreateEventW(nil, TRUE, FALSE, L"UruPatcherEvent"); if (hPatcherEvent != NULL) { // successfully created it, check to see if it was already created if (GetLastError() == ERROR_ALREADY_EXISTS) { // it already existed, so the patcher is waiting, signal it so the patcher can die SetEvent(hPatcherEvent); eventExists = true; } } #ifdef PLASMA_EXTERNAL_RELEASE // if the client was started directly, run the patcher, and shutdown STARTUPINFOW si; PROCESS_INFORMATION pi; memset(&si, 0, sizeof(si)); memset(&pi, 0, sizeof(pi)); si.cb = sizeof(si); const char** addrs; if (!eventExists) // if it is missing, assume patcher wasn't launched { plStringStream cmdLine; GetAuthSrvHostnames(&addrs); if (strlen(addrs[0])) cmdLine << " /AuthSrv=" << addrs[0]; GetFileSrvHostnames(&addrs); if (strlen(addrs[0])) cmdLine << " /FileSrv=" << addrs[0]; GetGateKeeperSrvHostnames(&addrs); if (strlen(addrs[0])) cmdLine << " /GateKeeperSrv=" << addrs[0]; if(!CreateProcessW(s_patcherExeName, (LPWSTR)cmdLine.GetString().ToUtf16().GetData(), NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) { hsMessageBox("Failed to launch patcher", "Error", hsMessageBoxNormal); } CloseHandle( pi.hThread ); CloseHandle( pi.hProcess ); return PARABLE_NORMAL_EXIT; } #endif // Load an optional general.ini plFileName gipath = plFileName::Join(plFileSystem::GetInitPath(), "general.ini"); FILE *generalini = plFileSystem::Open(gipath, "rb"); if (generalini) { fclose(generalini); pfConsoleEngine tempConsole; tempConsole.ExecuteFile(gipath); } #ifdef PLASMA_EXTERNAL_RELEASE // If another instance is running, exit. We'll automatically release our // lock on the mutex when our process exits HANDLE hOneInstance = CreateMutex(nil, FALSE, "UruExplorer"); if (WaitForSingleObject(hOneInstance,0) != WAIT_OBJECT_0) { switch (plLocalization::GetLanguage()) { case plLocalization::kFrench: hsMessageBox("Une autre copie d'URU est déjà en cours d'exécution", "Erreur", hsMessageBoxNormal); break; case plLocalization::kGerman: hsMessageBox("URU wird bereits in einer anderen Instanz ausgeführt", "Fehler", hsMessageBoxNormal); break; case plLocalization::kSpanish: hsMessageBox("En estos momentos se está ejecutando otra copia de URU", "Error", hsMessageBoxNormal); break; case plLocalization::kItalian: hsMessageBox("Un'altra copia di URU è già aperta", "Errore", hsMessageBoxNormal); break; // default is English default: hsMessageBox("Another copy of URU is already running", "Error", hsMessageBoxNormal); break; } return PARABLE_NORMAL_EXIT; } #endif FILE *serverIniFile = plFileSystem::Open(serverIni, "rb"); if (serverIniFile) { fclose(serverIniFile); pfConsoleEngine tempConsole; tempConsole.ExecuteFile(serverIni); } else { hsMessageBox("No server.ini file found. Please check your URU installation.", "Error", hsMessageBoxNormal); return PARABLE_NORMAL_EXIT; } NetCliAuthAutoReconnectEnable(false); NetCommSetReadIniAccountInfo(!doIntroDialogs); InitNetClientComm(); curl_global_init(CURL_GLOBAL_ALL); bool needExit = false; LoginDialogParam loginParam; memset(&loginParam, 0, sizeof(loginParam)); LoadUserPass(&loginParam); if (!doIntroDialogs && loginParam.remember) { ENetError auth; NetCommSetAccountUsernamePassword(loginParam.username, loginParam.namePassHash); bool cancelled = AuthenticateNetClientComm(&auth, NULL); if (IS_NET_ERROR(auth) || cancelled) { doIntroDialogs = true; loginParam.authError = auth; if (cancelled) { NetCommDisconnect(); } } } if (doIntroDialogs) { needExit = ::DialogBoxParam( hInst, MAKEINTRESOURCE( IDD_URULOGIN_MAIN ), NULL, UruLoginDialogProc, (LPARAM)&loginParam ) <= 0; } if (doIntroDialogs && !needExit) { HINSTANCE hRichEdDll = LoadLibrary("RICHED20.DLL"); INT_PTR val = ::DialogBoxParam( hInst, MAKEINTRESOURCE( IDD_URULOGIN_EULA ), NULL, UruTOSDialogProc, (LPARAM)hInst); FreeLibrary(hRichEdDll); if (val <= 0) { DWORD error = GetLastError(); needExit = true; } } curl_global_cleanup(); if (needExit) { DeInitNetClientComm(); return PARABLE_NORMAL_EXIT; } NetCliAuthAutoReconnectEnable(true); // VERY VERY FIRST--throw up our splash screen HWND splashDialog = ::CreateDialog( hInst, MAKEINTRESOURCE( IDD_LOADING ), NULL, SplashDialogProc ); // Install our unhandled exception filter for trapping all those nasty crashes in release build #ifndef HS_DEBUGGING LPTOP_LEVEL_EXCEPTION_FILTER oldFilter; oldFilter = SetUnhandledExceptionFilter( plCustomUnhandledExceptionFilter ); #endif // // Set up to log errors by using hsDebugMessage // DebugInit(); DebugMsgF("Plasma 2.0.%i.%i - %s", PLASMA2_MAJOR_VERSION, PLASMA2_MINOR_VERSION, plProduct::ProductString().c_str()); for (;;) { // Create Window if (!WinInit(hInst, nCmdShow) || gClient->GetDone()) break; // Done with our splash now ::DestroyWindow( splashDialog ); if (!gClient) break; // Show the main window ShowWindow(gClient->GetWindowHandle(), SW_SHOW); // Be really REALLY forceful about being in the front BringWindowToTop( gClient->GetWindowHandle() ); // Update the window UpdateWindow(gClient->GetWindowHandle()); // // Init Application here // if( !gClient->StartInit() ) break; // I want it on top! I mean it! BringWindowToTop( gClient->GetWindowHandle() ); // initialize dinput here: if (gClient && gClient->GetInputManager()) gClient->GetInputManager()->InitDInput(hInst, (HWND)gClient->GetWindowHandle()); // Seriously! BringWindowToTop( gClient->GetWindowHandle() ); // // Main loop // MSG msg; do { gClient->MainLoop(); if( gClient->GetDone() ) break; // Look for a message while (PeekMessage( &msg, NULL, 0, 0, PM_REMOVE )) { // Handle the message TranslateMessage( &msg ); DispatchMessage( &msg ); } } while (WM_QUIT != msg.message); break; } // // Cleanup // if (gClient) { gClient->Shutdown(); // shuts down PhysX for us gClient = nil; } hsAssert(hsgResMgr::ResMgr()->RefCnt()==1, "resMgr has too many refs, expect mem leaks"); hsgResMgr::Shutdown(); // deletes fResMgr DeInitNetClientComm(); // Uninstall our unhandled exception filter, if we installed one #ifndef HS_DEBUGGING SetUnhandledExceptionFilter( oldFilter ); #endif // Exit WinMain and terminate the app.... return PARABLE_NORMAL_EXIT; }