uint32 CScreenMulti::HandleCallback(uint32 dwParam1, uint32 dwParam2) { switch (dwParam2) { case CMD_UPDATE: { //following notification of new version, continue validation process RequestValidate(); } break; case CMD_EDIT_CDKEY : { IServerDirectory *pServerDir = g_pClientMultiplayerMgr->GetServerDir(); if (pServerDir->SetCDKey((const char *)dwParam1)) { m_sCurCDKey = ((const char *)dwParam1); pServerDir->SetCDKey(m_sCurCDKey.c_str()); bool bResult = pServerDir->QueueRequest(IServerDirectory::eRequest_Validate_CDKey); if (bResult) { g_pLTClient->CPrint( "QueueRequest(IServerDirectory::eRequest_Validate_CDKey)"); m_pCDKeyCtrl->SetString(1,m_sCurCDKey.c_str()); m_eCurState = eState_ValidateCDKey; m_pWait->Show(LTTRUE); SetCapture(m_pWait); } } if (m_eCurState != eState_ValidateCDKey) { MBCreate mb; g_pInterfaceMgr->ShowMessageBox(IDS_CDKEY_INVALID,&mb); std::string str = pServerDir->GetLastRequestResultString( ); g_pLTClient->CPrint( "CDKey validation error: %s", str.c_str( )); m_pWait->Show(LTFALSE); if (GetCapture() == m_pWait) SetCapture(NULL); m_pCDKeyCtrl->SetString(1,m_sLastValidCDKey.c_str()); m_pJoin->Enable(!m_sLastValidCDKey.empty()); m_pHost->Enable(!m_sLastValidCDKey.empty()); m_sCurCDKey = m_sLastValidCDKey; pServerDir->SetCDKey(m_sCurCDKey.c_str()); if (m_sLastValidCDKey.empty()) m_eCurState = eState_NoCDKey; } break; } } return 1; }
void CScreenMulti::Update() { if (g_bLAN) return; IServerDirectory *pServerDir = g_pClientMultiplayerMgr->GetServerDir(); char aTempBuffer[256]; FormatString(IDS_STATUS_STRING,aTempBuffer,sizeof(aTempBuffer),g_pClientMultiplayerMgr->GetServerDir()->GetCurStatusString()); m_pStatusCtrl->SetString(aTempBuffer); // Are we still waiting? switch (pServerDir->GetCurStatus()) { case IServerDirectory::eStatus_Processing : return; case IServerDirectory::eStatus_Waiting : { switch (m_eCurState) { case eState_Startup: { //completed startup... check version m_eCurState = eState_VersionCheck; bool bResult = pServerDir->QueueRequest(IServerDirectory::eRequest_Validate_Version); if (bResult) { g_pLTClient->CPrint( "QueueRequest(IServerDirectory::eRequest_Validate_Version)"); } else { g_pLTClient->CPrint( "QueueRequest(IServerDirectory::eRequest_Validate_Version) : FAILED"); ASSERT(0); MBCreate mb; g_pInterfaceMgr->ShowMessageBox(IDS_VALIDATION_FAILED,&mb); m_pWait->Show(LTFALSE); SetCapture(NULL); Escape(); return; } } break; case eState_VersionCheck: { m_pWait->Show(LTFALSE); SetCapture(NULL); if (pServerDir->IsVersionNewest()) { //passed version check... check CDKey } else if (pServerDir->IsVersionValid()) { //enable updater MBCreate mb; mb.pFn = NewVersionCallBack; g_pInterfaceMgr->ShowMessageBox(IDS_NEW_VERSION,&mb); m_pUpdate->Show(LTTRUE); return; } else { //error state... bail MBCreate mb; g_pInterfaceMgr->ShowMessageBox(IDS_VALIDATION_FAILED,&mb); Escape(); return; } RequestValidate(); } break; case eState_ValidateCDKey: { //completed validation... check MOTD; m_pWait->Show(LTFALSE); SetCapture(NULL); m_sLastValidCDKey = m_sCurCDKey; RequestMOTD(); }break; case eState_MOTD: { //completed system MOTD... check game MOTD if ((m_sSysMOTD.empty() && pServerDir->IsMOTDNew(IServerDirectory::eMOTD_System)) || (m_sGameMOTD.empty() && pServerDir->IsMOTDNew(IServerDirectory::eMOTD_Game))) { //deal with new system motd MBCreate mb; //add callback g_pInterfaceMgr->ShowMessageBox(IDS_NEW_MOTD,&mb); } std::string sTemp = pServerDir->GetMOTD(IServerDirectory::eMOTD_System); if (sTemp.length() > 512) m_sSysMOTD.assign(sTemp.c_str(),512); else m_sSysMOTD = sTemp; sTemp = pServerDir->GetMOTD(IServerDirectory::eMOTD_Game); if (sTemp.length() > 512) m_sGameMOTD.assign(sTemp.c_str(),512); else m_sGameMOTD = sTemp; m_pSysMOTD->SetString(m_sSysMOTD.c_str()); m_pGameMOTD->SetString(m_sGameMOTD.c_str()); m_pJoin->Enable(LTTRUE); m_pHost->Enable(LTTRUE); m_eCurState = eState_Ready; } break; } break; } case IServerDirectory::eStatus_Error : { g_pLTClient->CPrint( "ServerDir request error: %s", pServerDir->GetLastRequestResultString( )); // Ignore errors in the MOTD/Version queries for now... // NYI IServerDirectory::ERequest eErrorRequest = pServerDir->GetLastErrorRequest(); if (eErrorRequest == IServerDirectory::eRequest_Validate_CDKey) { MBCreate mb; g_pInterfaceMgr->ShowMessageBox(IDS_CDKEY_INVALID,&mb); if (m_sLastValidCDKey.empty()) { m_pJoin->Enable(LTFALSE); m_pHost->Enable(LTFALSE); } else { m_pCDKeyCtrl->SetString(1,m_sLastValidCDKey.c_str()); m_pJoin->Enable(LTTRUE); m_pHost->Enable(LTTRUE); } m_sCurCDKey = m_sLastValidCDKey; pServerDir->SetCDKey(m_sCurCDKey.c_str()); m_eCurState = eState_Ready; m_pWait->Show(LTFALSE); if (GetCapture() == m_pWait) SetCapture(NULL); } else if ((eErrorRequest == IServerDirectory::eRequest_MOTD) ) { g_pLTClient->CPrint( "QueueRequest(IServerDirectory::eRequest_MOTD) : FAILED"); m_eCurState = eState_Ready; m_sSysMOTD = ""; m_sGameMOTD = ""; m_pSysMOTD->SetString(m_sSysMOTD.c_str()); m_pGameMOTD->SetString(m_sGameMOTD.c_str()); m_pJoin->Enable(LTTRUE); m_pHost->Enable(LTTRUE); } else { // Whoops, something went wrong. // Drop out of this screen with an error MBCreate mb; g_pInterfaceMgr->ShowMessageBox(pServerDir->GetLastRequestResultString(),&mb); Escape(); } pServerDir->ProcessRequestList(); break; } default : { ASSERT(!"Unknown directory status encountered"); break; } } }