// // main update fxn for net client code, return hsFail on err // int plNetClientMgr::Update(double secs) { int ret=hsOK; // ret code is unchecked, but what the hay if (GetFlagsBit(kDisableOnNextUpdate)) { SetFlagsBit(kDisableOnNextUpdate, false); IDisableNet(); } // Pump net messages NetCommUpdate(); static double lastUpdateTime=0; double curTime=hsTimer::GetSeconds(); if (curTime-lastUpdateTime > 1.f) { DebugMsg("NetClient hasn't updated for %f secs", curTime-lastUpdateTime); } lastUpdateTime=curTime; if (GetFlagsBit(kPlayingGame) ) { MaybeSendPendingPagingRoomMsgs(); ICheckPendingStateLoad(secs); ISendDirtyState(secs); IUpdateListenList(secs); if (GetFlagsBit(plNetClientApp::kShowLists)) IShowLists(); if (GetFlagsBit(plNetClientApp::kShowRooms)) IShowRooms(); if (GetFlagsBit(plNetClientApp::kShowAvatars)) IShowAvatars(); if (GetFlagsBit(plNetClientApp::kShowRelevanceRegions)) IShowRelevanceRegions(); } // Send dirty nodes, deliver vault callbacks, etc. VaultUpdate(); plNetLinkingMgr::GetInstance()->Update(); return ret; }
BOOL CALLBACK AuthDialogProc( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam ) { static bool* cancelled = NULL; switch( uMsg ) { case WM_INITDIALOG: cancelled = (bool*)lParam; SetTimer(hwndDlg, AUTH_LOGIN_TIMER, 10, NULL); return TRUE; case WM_TIMER: if (wParam == AUTH_LOGIN_TIMER) { if (NetCommIsLoginComplete()) EndDialog(hwndDlg, 1); else NetCommUpdate(); return TRUE; } return FALSE; case WM_NCHITTEST: SetWindowLongPtr(hwndDlg, DWL_MSGRESULT, (LONG_PTR)HTCAPTION); return TRUE; case WM_DESTROY: KillTimer(hwndDlg, AUTH_LOGIN_TIMER); return TRUE; case WM_COMMAND: if (HIWORD(wParam) == BN_CLICKED && LOWORD(wParam) == IDCANCEL) { *cancelled = true; EndDialog(hwndDlg, 1); } return TRUE; } return DefWindowProc(hwndDlg, uMsg, wParam, lParam); }
BOOL CALLBACK UruLoginDialogProc( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam ) { static LoginDialogParam* pLoginParam; static bool showAuthFailed = false; switch( uMsg ) { case WM_INITDIALOG: { s_loginDlgRunning = true; _beginthread(StatusCallback, 0, hwndDlg); pLoginParam = (LoginDialogParam*)lParam; SetWindowText(hwndDlg, "Login"); SendMessage(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)LoadIcon(gHInst, MAKEINTRESOURCE(IDI_ICON_DIRT))); EnableWindow(GetDlgItem(hwndDlg, IDOK), FALSE); SetDlgItemText(hwndDlg, IDC_URULOGIN_USERNAME, pLoginParam->username); CheckDlgButton(hwndDlg, IDC_URULOGIN_REMEMBERPASS, pLoginParam->remember ? BST_CHECKED : BST_UNCHECKED); if (pLoginParam->remember) SetDlgItemText(hwndDlg, IDC_URULOGIN_PASSWORD, FAKE_PASS_STRING); SetFocus(GetDlgItem(hwndDlg, pLoginParam->focus)); if (IS_NET_ERROR(pLoginParam->authError)) { showAuthFailed = true; } SendMessage(GetDlgItem(hwndDlg, IDC_PRODUCTSTRING), WM_SETTEXT, 0, (LPARAM)plProduct::ProductString().c_str()); for (int i = 0; i < plLocalization::GetNumLocales(); i++) { SendMessage(GetDlgItem(hwndDlg, IDC_LANGUAGE), CB_ADDSTRING, 0, (LPARAM)plLocalization::GetLanguageName((plLocalization::Language)i)); } SendMessage(GetDlgItem(hwndDlg, IDC_LANGUAGE), CB_SETCURSEL, (WPARAM)plLocalization::GetLanguage(), 0); SetTimer(hwndDlg, AUTH_LOGIN_TIMER, 10, NULL); return FALSE; } case WM_USER_SETSTATUSMSG: SendMessage(GetDlgItem(hwndDlg, IDC_STATUS_TEXT), WM_SETTEXT, 0, lParam); return TRUE; case WM_DESTROY: { s_loginDlgRunning = false; s_statusEvent.Wait(); KillTimer(hwndDlg, AUTH_LOGIN_TIMER); return TRUE; } case WM_NCHITTEST: { SetWindowLongPtr(hwndDlg, DWL_MSGRESULT, (LONG_PTR)HTCAPTION); return TRUE; } case WM_PAINT: { if (showAuthFailed) { SetTimer(hwndDlg, AUTH_FAILED_TIMER, 10, NULL); showAuthFailed = false; } return FALSE; } case WM_COMMAND: { if (HIWORD(wParam) == BN_CLICKED && (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)) { bool ok = (LOWORD(wParam) == IDOK); if (ok) { char password[kMaxPasswordLength]; GetDlgItemText(hwndDlg, IDC_URULOGIN_USERNAME, pLoginParam->username, kMaxAccountNameLength); GetDlgItemText(hwndDlg, IDC_URULOGIN_PASSWORD, password, kMaxPasswordLength); pLoginParam->remember = (IsDlgButtonChecked(hwndDlg, IDC_URULOGIN_REMEMBERPASS) == BST_CHECKED); plLocalization::Language new_language = (plLocalization::Language)SendMessage(GetDlgItem(hwndDlg, IDC_LANGUAGE), CB_GETCURSEL, 0, 0L); plLocalization::SetLanguage(new_language); SaveUserPass (pLoginParam, password); // Welcome to HACKland, population: Branan // The code to write general.ini really doesn't belong here, but it works... for now. // When general.ini gets expanded, this will need to find a proper home somewhere. { plFileName gipath = plFileName::Join(plFileSystem::GetInitPath(), "general.ini"); plString ini_str = plFormat("App.SetLanguage {}\n", plLocalization::GetLanguageName(new_language)); hsStream* gini = plEncryptedStream::OpenEncryptedFileWrite(gipath); gini->WriteString(ini_str); gini->Close(); delete gini; } memset(&pLoginParam->authError, 0, sizeof(pLoginParam->authError)); bool cancelled = AuthenticateNetClientComm(&pLoginParam->authError, hwndDlg); if (IS_NET_SUCCESS(pLoginParam->authError) && !cancelled) EndDialog(hwndDlg, ok); else { if (!cancelled) ::DialogBoxParam(gHInst, MAKEINTRESOURCE( IDD_AUTHFAILED ), hwndDlg, AuthFailedDialogProc, (LPARAM)pLoginParam); else { NetCommDisconnect(); } } } else EndDialog(hwndDlg, ok); return TRUE; } else if (HIWORD(wParam) == EN_CHANGE && LOWORD(wParam) == IDC_URULOGIN_USERNAME) { char username[kMaxAccountNameLength]; GetDlgItemText(hwndDlg, IDC_URULOGIN_USERNAME, username, kMaxAccountNameLength); if (StrLen(username) == 0) EnableWindow(GetDlgItem(hwndDlg, IDOK), FALSE); else EnableWindow(GetDlgItem(hwndDlg, IDOK), TRUE); return TRUE; } else if (HIWORD(wParam) == BN_CLICKED && LOWORD(wParam) == IDC_URULOGIN_NEWACCTLINK) { plString signupurl = GetServerSignupUrl(); ShellExecuteW(NULL, L"open", signupurl.ToWchar(), NULL, NULL, SW_SHOWNORMAL); return TRUE; } break; } case WM_TIMER: { switch(wParam) { case AUTH_FAILED_TIMER: KillTimer(hwndDlg, AUTH_FAILED_TIMER); ::DialogBoxParam(gHInst, MAKEINTRESOURCE( IDD_AUTHFAILED ), hwndDlg, AuthFailedDialogProc, (LPARAM)pLoginParam); return TRUE; case AUTH_LOGIN_TIMER: NetCommUpdate(); return TRUE; } return FALSE; } } return FALSE; }