AuthContextPtr WONAuthorize() { bool bSuccess = true; WONStatus nResult; CDKey cTheKey(g_sWONProduct); if (g_sWONCDKey.empty()) cTheKey.LoadFromRegistry(); else cTheKey.Init(g_sWONCDKey); if (!cTheKey.IsValid()) { g_pLTCSBase->CPrint("Warning! Invalid CD key : %s", g_sWONCDKey.c_str()); //return AuthContextPtr(0); } // Get the authentication server GetDirOpPtr cGetDir = new GetDirOp(WONGetCurrentServerContext(g_lWONServerList)); cGetDir->SetPath(L"/TitanServers/Auth"); cGetDir->SetFlags( DIR_GF_DECOMPSERVICES | DIR_GF_SERVADDNETADDR); nResult = cGetDir->Run(OP_MODE_BLOCK, OP_TIMEOUT_INFINITE); bSuccess &= (nResult == WS_Success); if (bSuccess) { bSuccess &= !cGetDir->GetDirEntityList().empty(); } if (!bSuccess) { g_pLTCSBase->CPrint("Unable to query authentication server: %s", WONStatusToString(nResult)); return AuthContextPtr(0); } // Authenticate AuthContextPtr cAuthorization = new AuthContext; HashFileList cFileCheckList; /* cFileCheckList.push_back("lithtech.exe"); cAuthorization->SetHashFileList(g_sWONCommunity, cFileCheckList); */ // Temporarily provide a user id and password // NYI cAuthorization->SetUserName(L"kevintest"); cAuthorization->SetPassword(L"kevintest"); cAuthorization->SetCommunity(g_sWONCommunity); cAuthorization->SetCDKey(g_sWONCommunity, cTheKey); cAuthorization->AddAddressesFromDir(cGetDir->GetDirEntityList()); GetCertOpPtr cCertOp = new GetCertOp(cAuthorization); nResult = cCertOp->Run(OP_MODE_BLOCK, OP_TIMEOUT_INFINITE); bSuccess &= (nResult == WS_Success); if (!bSuccess) { g_pLTCSBase->CPrint("Unable to retrieve certification: %s", WONStatusToString(nResult)); return AuthContextPtr(0); } return cAuthorization; }
void WONQueryDir(const char *pPath, bool bRecurse = false) { GetDirOpPtr cGetDir = new GetDirOp(WONGetCurrentServerContext(g_lWONServerList)); cGetDir->SetPath(g_sWONCurPath + Make_wstring("/") + Make_wstring(pPath)); cGetDir->SetFlags( DIR_GF_DECOMPSERVICES | DIR_GF_DECOMPSUBDIRS | ((bRecurse) ? DIR_GF_DECOMPRECURSIVE : 0) | DIR_GF_ADDTYPE | DIR_GF_ADDDISPLAYNAME | DIR_GF_DIRADDNAME | DIR_GF_DIRADDPATH | DIR_GF_SERVADDPATH | DIR_GF_SERVADDNAME); cGetDir->Run(OP_MODE_BLOCK, OP_TIMEOUT_INFINITE); if (cGetDir->GetStatus() != WS_Success) { g_pLTCSBase->CPrint("Directory not found (%s)", WONStatusToString(cGetDir->GetStatus())); return; } // Display everything const DirEntityList &cFullDir = cGetDir->GetDirEntityList(); DirEntityList::const_iterator iFullDirEntry = cFullDir.begin(); for (; iFullDirEntry != cFullDir.end(); ++iFullDirEntry) { const wchar_t *pName = (*iFullDirEntry)->mDisplayName.empty() ? (*iFullDirEntry)->mName.c_str() : (*iFullDirEntry)->mDisplayName.c_str(); g_pLTCSBase->CPrint(" %ls%s%ls (%c)", (*iFullDirEntry)->mPath.c_str(), (*iFullDirEntry)->mPath.length() == 1 ? "" : "/", pName, (*iFullDirEntry)->mType); } g_pLTCSBase->CPrint(" <END>"); return; }
void FindPatchOp::RunHook() { mPatchList.clear(); GetDirOpPtr anOp = new GetDirOp(mDirServers); anOp->SetPath(GetVersionDir()); DWORD aGetFlags = DIR_GF_DECOMPSERVICES | DIR_GF_SERVADDNAME | DIR_GF_ADDDISPLAYNAME | DIR_GF_SERVADDNETADDR | DIR_GF_ADDDATAOBJECTS | DIR_GF_ADDDOTYPE | DIR_GF_ADDDODATA; if(mValidVersionSet.empty()) aGetFlags |= DIR_GF_DECOMPROOT; anOp->SetFlags(aGetFlags); if(IsAsync()) { Track(anOp); anOp->RunAsync(OP_TIMEOUT_INFINITE); return; } anOp->RunBlock(TimeLeft()); DoFinish(anOp); }
void WONVerifyVersion(const char *pVersion, const char *pRegion) { if (!pVersion || !pVersion[0]) g_pLTCSBase->CPrint("You need to provide a version number."); bool bSuccess = true; WONStatus nResult; GetDirOpPtr cGetDir = new GetDirOp(WONGetCurrentServerContext(g_lWONServerList)); cGetDir->SetPath(L"/" + g_sWONCommunity + L"/Patch"); cGetDir->SetFlags( DIR_GF_DECOMPSERVICES | DIR_GF_SERVADDNETADDR); nResult = cGetDir->Run(OP_MODE_BLOCK, OP_TIMEOUT_INFINITE); bSuccess &= (nResult == WS_Success); if (bSuccess) { bSuccess &= !cGetDir->GetDirEntityList().empty(); } if (!bSuccess) { g_pLTCSBase->CPrint("Unable to query patch server: %s", WONStatusToString(nResult)); return; } ServerContextPtr cServerContext = new ServerContext; cServerContext->AddAddressesFromDir(cGetDir->GetDirEntityList()); CheckValidVersionOpPtr pVersionOp = new CheckValidVersionOp(g_sWONProduct, cServerContext); pVersionOp->SetVersion(pVersion); pVersionOp->SetConfigName(pRegion); pVersionOp->SetGetPatchList(false); nResult = pVersionOp->Run(OP_MODE_BLOCK, OP_TIMEOUT_INFINITE); bSuccess &= (nResult == WS_Success); if (!bSuccess) { switch (nResult) { case WS_DBProxyServ_OutOfDate : case WS_DBProxyServ_ValidNotLatest : g_pLTCSBase->CPrint("Version is out of date, and there's an update available: %s", WONStatusToString(nResult)); break; case WS_DBProxyServ_OutOfDateNoUpdate : g_pLTCSBase->CPrint("Version is out of date, no updates available: %s", WONStatusToString(nResult)); break; default : g_pLTCSBase->CPrint("Unable to retrieve version info: %s", WONStatusToString(nResult)); break; } return; } g_pLTCSBase->CPrint("That version is the current, valid version"); return; }
void WONVerifyCDKey(const char *pCDKey) { bool bSuccess = true; WONStatus nResult; // Check it locally CDKey cTheKey(g_sWONProduct); cTheKey.Init(pCDKey); if (!cTheKey.IsValid()) { g_pLTCSBase->CPrint("That CD key is not valid"); return; } // Get the authentication server GetDirOpPtr cGetDir = new GetDirOp(WONGetCurrentServerContext(g_lWONServerList)); cGetDir->SetPath(L"/TitanServers/Auth"); cGetDir->SetFlags( DIR_GF_DECOMPSERVICES | DIR_GF_SERVADDNETADDR); nResult = cGetDir->Run(OP_MODE_BLOCK, OP_TIMEOUT_INFINITE); bSuccess &= (nResult == WS_Success); if (bSuccess) { bSuccess &= !cGetDir->GetDirEntityList().empty(); } if (!bSuccess) { g_pLTCSBase->CPrint("Unable to query authentication server: %s", WONStatusToString(nResult)); return; } // Authenticate AuthContextPtr cAuthorization = new AuthContext; HashFileList cFileCheckList; cAuthorization->SetCommunity(g_sWONCommunity); cAuthorization->SetCDKey(g_sWONCommunity, cTheKey); cAuthorization->AddAddressesFromDir(cGetDir->GetDirEntityList()); GetCertOpPtr cCertOp = new GetCertOp(cAuthorization); nResult = cCertOp->Run(OP_MODE_BLOCK, OP_TIMEOUT_INFINITE); bSuccess &= (nResult == WS_Success); if (!bSuccess) { g_pLTCSBase->CPrint("Unable to retrieve certification: %s", WONStatusToString(nResult)); return; } g_pLTCSBase->CPrint("CD key valid"); return; }
void WONRemoveService(const char *pName) { if (WONAuthorize() == 0) return; bool bSuccess = true; // Go find the directory's IP address std::wstring sName = Make_wstring(pName); IPAddr cServiceAddr; GetDirOpPtr cGetDir = new GetDirOp(WONGetCurrentServerContext(g_lWONServerList)); cGetDir->SetPath(g_sWONCurPath); cGetDir->SetFlags( DIR_GF_DECOMPSERVICES | DIR_GF_SERVADDNAME | DIR_GF_SERVADDNETADDR); bSuccess &= (cGetDir->Run(OP_MODE_BLOCK, OP_TIMEOUT_INFINITE) == WS_Success); if (bSuccess) { bSuccess = false; DirEntityList::const_iterator iCurEntity = cGetDir->GetDirEntityList().begin(); for (; !bSuccess && iCurEntity != cGetDir->GetDirEntityList().end(); ++iCurEntity) { bSuccess |= ((*iCurEntity)->mName == sName); if (bSuccess) cServiceAddr = (*iCurEntity)->GetNetAddrAsIP(); } } if (!bSuccess) { g_pLTCSBase->CPrint("Unable to find service"); return; } // Remove the service RemoveServiceOpPtr cRemoveService = new RemoveServiceOp(WONGetCurrentServerContext(g_lWONServerList)); cRemoveService->SetNetAddr(cServiceAddr); cRemoveService->SetName(sName); cRemoveService->SetPath(g_sWONCurPath); WONStatus nResult = cRemoveService->Run(OP_MODE_BLOCK, OP_TIMEOUT_INFINITE); bSuccess &= (nResult == WS_Success); if (!bSuccess) { g_pLTCSBase->CPrint("Unable to remove service: %s", WONStatusToString(nResult)); return; } g_pLTCSBase->CPrint("Service %s removed successfully", pName); }
void WONQueryServices(const char *pPath) { GetDirOpPtr cGetDir = new GetDirOp(WONGetCurrentServerContext(g_lWONServerList)); cGetDir->SetPath(g_sWONCurPath + Make_wstring("/") + Make_wstring(pPath)); cGetDir->SetFlags( DIR_GF_DECOMPSERVICES | DIR_GF_DECOMPRECURSIVE | DIR_GF_ADDTYPE | DIR_GF_ADDDISPLAYNAME | DIR_GF_ADDCREATED | DIR_GF_ADDTOUCHED | DIR_GF_ADDLIFESPAN | DIR_GF_SERVADDPATH | DIR_GF_SERVADDNETADDR | DIR_GF_SERVADDNAME); cGetDir->Run(OP_MODE_BLOCK, OP_TIMEOUT_INFINITE); if (cGetDir->GetStatus() != WS_Success) { g_pLTCSBase->CPrint("Directory not found"); return; } // Display everything const DirEntityList &cFullDir = cGetDir->GetDirEntityList(); DirEntityList::const_iterator iFullDirEntry = cFullDir.begin(); for (; iFullDirEntry != cFullDir.end(); ++iFullDirEntry) { const wchar_t *pName = (*iFullDirEntry)->mDisplayName.empty() ? (*iFullDirEntry)->mName.c_str() : (*iFullDirEntry)->mDisplayName.c_str(); g_pLTCSBase->CPrint(" %ls%s%ls", (*iFullDirEntry)->mPath.c_str(), (*iFullDirEntry)->mPath.length() == 1 ? "" : "/", pName); g_pLTCSBase->CPrint(" Type : %s", (*iFullDirEntry)->IsService() ? "Service" : "Directory"); g_pLTCSBase->CPrint(" Display Name : %ls", (*iFullDirEntry)->mDisplayName.c_str()); g_pLTCSBase->CPrint(" Created : %d", (*iFullDirEntry)->mCreated); g_pLTCSBase->CPrint(" Touched : %d", (*iFullDirEntry)->mTouched); g_pLTCSBase->CPrint(" Lifespan : %d", (*iFullDirEntry)->mLifespan); g_pLTCSBase->CPrint(" Path : %ls", (*iFullDirEntry)->mPath.c_str()); g_pLTCSBase->CPrint(" Net Addr : %s", (*iFullDirEntry)->GetNetAddrAsIP().GetHostAndPortString().c_str()); g_pLTCSBase->CPrint(" Name : %ls", (*iFullDirEntry)->mName.c_str()); } g_pLTCSBase->CPrint(" <END>"); return; }