void plClipboard::SetClipboardText(const plString& text) { if (text.IsEmpty()) return; #ifdef HS_BUILD_FOR_WIN32 plStringBuffer<wchar_t> buf = text.ToWchar(); size_t len = buf.GetSize(); if (len == 0) return; std::unique_ptr<void, HGLOBAL(WINAPI*)(HGLOBAL)> copy(::GlobalAlloc(GMEM_MOVEABLE, (len + 1) * sizeof(wchar_t)), ::GlobalFree); if (!copy) return; if (!::OpenClipboard(NULL)) return; ::EmptyClipboard(); wchar_t* target = (wchar_t*)::GlobalLock(copy.get()); memcpy(target, buf.GetData(), (len + 1) * sizeof(wchar_t)); target[len] = '\0'; ::GlobalUnlock(copy.get()); ::SetClipboardData(CF_UNICODETEXT, copy.get()); ::CloseClipboard(); #endif }
/***************************************************************************** ** pfMacPasswordStore ** *****************************************************************************/ const plString pfMacPasswordStore::GetPassword(const plString& username) { plString service = GetServerDisplayName(); void* passwd = nullptr; uint32_t passwd_len = 0; if (SecKeychainFindGenericPassword(nullptr, service.GetSize(), service.c_str(), username.GetSize(), username.c_str(), &passwd_len, &passwd, nullptr) != errSecSuccess) { return plString::Null; } plString ret(reinterpret_cast<const char*>(passwd), size_t(passwd_len)); SecKeychainItemFreeContent(nullptr, passwd); return ret; }
void plMouseDevice::AddNameToCursor(const plString& name) { if (fInstance && !name.IsNull()) { plDebugText &txt = plDebugText::Instance(); txt.DrawString(fInstance->fWXPos + 12 ,fInstance->fWYPos - 7,name.c_str()); } }
// // support for a single leading tab in statusLog strings // const char* ProcessTab(const char* fmt) { static plString s; if (fmt && *fmt=='\t') { s = plFormat(" {}", fmt); return s.c_str(); } return fmt; }
plKey plAvatarMgr::LoadAvatar(plString name, plString accountName, bool isPlayer, plKey spawnPoint, plAvTask *initialTask, const plString &userStr, const plFileName &clothingFile) { // *** account is currently unused. the idea is that eventually an NPC will // *** be able to use a customization account plKey result = nullptr; plKey requestor = GetKey(); // avatar manager is always the requestor for avatar loads plNetClientMgr *netMgr = plNetClientMgr::GetInstance(); if(netMgr) // can't clone without the net manager { hsAssert(!name.IsEmpty(), "name required by LoadPlayer fxn"); netMgr->DebugMsg("Local: Loading player %s", name.c_str()); // look up player by key name provided by user. // this string search should be replaced with some other method of // avatar selection and key lookup. // Get the location for the player first plKey playerKey = nullptr; const plLocation& globalLoc = plKeyFinder::Instance().FindLocation("GlobalAvatars", name); const plLocation& maleLoc = plKeyFinder::Instance().FindLocation("GlobalAvatars", "Male"); const plLocation& custLoc = plKeyFinder::Instance().FindLocation("CustomAvatars", name); #ifdef PLASMA_EXTERNAL_RELEASE // Try global. If that doesn't work, players default to male. // If not a player, try custLoc. If that doesn't work, fall back to male const plLocation& loc = (globalLoc.IsValid() ? globalLoc : isPlayer ? maleLoc : custLoc.IsValid() ? custLoc : maleLoc); #else // Try global. If that doesn't work try custom. Otherwise fall back to male const plLocation& loc = (globalLoc.IsValid() ? globalLoc : custLoc.IsValid() ? custLoc : maleLoc); #endif if (loc == maleLoc) name = "Male"; if (loc.IsValid()) { plUoid uID(loc, plSceneObject::Index(), name); plLoadAvatarMsg *cloneMsg = new plLoadAvatarMsg(uID, requestor, 0, isPlayer, spawnPoint, initialTask, userStr); if (clothingFile.IsValid()) { plLoadClothingMsg *clothingMsg = new plLoadClothingMsg(clothingFile); cloneMsg->SetTriggerMsg(clothingMsg); } result = cloneMsg->GetCloneKey(); // the clone message is automatically addressed to the net client manager // we'll receive the message back (or a similar message) when the clone is loaded cloneMsg->Send(); } } return result; }
unsigned plNetClientMgr::GetPlayerIdByName (const plString & name) const { // local case if (name.CompareI(NetCommGetPlayer()->playerName) == 0) return NetCommGetPlayer()->playerInt; unsigned n = TransportMgr().GetNumMembers(); for (unsigned i = 0; i < n; ++i) if (plNetTransportMember * member = TransportMgr().GetMember(i)) if (0 == name.Compare(member->GetPlayerName())) return member->GetPlayerID(); return 0; }
uint32_t pnAuthClient::sendFileListRequest(const plString& directory, const plString& ext) { const pnNetMsg* desc = GET_Cli2Auth(kCli2Auth_FileListRequest); msgparm_t* msg = NCAllocMessage(desc); uint32_t transId = nextTransId(); msg[0].fUint = transId; msg[1].fString = plwcsdup(directory.wstr()); msg[2].fString = plwcsdup(ext.wstr()); fSock->sendMsg(msg, desc); NCFreeMessage(msg, desc); return transId; }
plKey plKeyFinder::StupidSearch(const plString & age, const plString & rm, uint16_t classType, const plString &obName, bool subString) { if (obName.IsNull()) return nil; plUoid newOid; fLastError = kOk; uint16_t maxClasses = plFactory::GetNumClasses(); uint16_t ty = classType; if (ty == maxClasses) // error { fLastError = kInvalidClass; return nil; } if (!age.IsNull() && !rm.IsNull()) { const plLocation &loc = IGetResMgr()->FindLocation( age, rm ); if( !loc.IsValid() ) { fLastError = kPageNotFound; return nil; } plKeyFinderIter keyFinder( classType, obName, subString ); if( !IGetResMgr()->IterateKeys( &keyFinder, loc ) ) // Return value of false means it stopped somewhere, i.e. found something return keyFinder.GetFoundKey(); } else if (!age.IsNull()) { plKeyFinderIter keyFinder(classType, obName, subString, age); if( !IGetResMgr()->IterateAllPages( &keyFinder ) ) return keyFinder.GetFoundKey(); } else { plKeyFinderIter keyFinder( classType, obName, subString ); if( !IGetResMgr()->IterateKeys( &keyFinder ) ) // Return value of false means it stopped somewhere, i.e. found something return keyFinder.GetFoundKey(); } fLastError = kObjectNotFound; return nil; }
bool pfMacPasswordStore::SetPassword(const plString& username, const plString& password) { plString service = GetServerDisplayName(); return SecKeychainAddGenericPassword(nullptr, service.GetSize(), service.c_str(), username.GetSize(), username.c_str(), password.GetSize(), password.c_str(), nullptr) == errSecSuccess; }
plLocation plPluginResManager::ICreateLocation(const plString& age, const plString& page, int32_t seqNum, bool itinerant) { bool willBeReserved = age.CompareI("global") == 0; int32_t oldNum = seqNum; seqNum = VerifySeqNumber(seqNum, age, page); if (seqNum != oldNum) { hsAssert(false, "Conflicting page sequence number. Somebody called NameToLoc without verifying their seq# first!"); } if (seqNum < 0) { willBeReserved = true; seqNum = -seqNum; } plLocation newLoc; if (willBeReserved) newLoc = plLocation::MakeReserved(seqNum); else newLoc = plLocation::MakeNormal(seqNum); // Flag common pages for (int i = 0; i < plAgeDescription::kNumCommonPages; i++) { if (page.Compare(plAgeDescription::GetCommonPage(i)) == 0) { newLoc.SetFlags(plLocation::kBuiltIn); break; } } // If we have an age description file for the age we're creating a location // for, grab some extra flags from it plAgeDescription* ageDesc = plPageInfoUtils::GetAgeDesc(age.c_str()); plAgePage* agePage = ageDesc ? ageDesc->FindPage(page.c_str()) : nil; if (agePage) { if (agePage->GetFlags() & plAgePage::kIsLocalOnly) newLoc.SetFlags(plLocation::kLocalOnly); if (agePage->GetFlags() & plAgePage::kIsVolatile) newLoc.SetFlags(plLocation::kVolatile); } if (itinerant) newLoc.SetFlags(plLocation::kItinerant); delete ageDesc; return newLoc; }
uint32_t pnAuthClient::sendFriendInviteRequest(const plUuid& invite, const plString& email, const plString& sendTo) { const pnNetMsg* desc = GET_Cli2Auth(kCli2Auth_SendFriendInviteRequest); msgparm_t* msg = NCAllocMessage(desc); uint32_t transId = nextTransId(); msg[0].fUint = transId; invite.write(msg[1].fData); msg[2].fString = plwcsdup(email.wstr()); msg[3].fString = plwcsdup(sendTo.wstr()); fSock->sendMsg(msg, desc); NCFreeMessage(msg, desc); return transId; }
uint32_t pnAuthClient::sendPlayerCreateRequest(const plString& playerName, const plString& playerShape, const plString& friendInvite) { const pnNetMsg* desc = GET_Cli2Auth(kCli2Auth_PlayerCreateRequest); msgparm_t* msg = NCAllocMessage(desc); uint32_t transId = nextTransId(); msg[0].fUint = transId; msg[1].fString = plwcsdup(playerName.wstr()); msg[2].fString = plwcsdup(playerShape.wstr()); msg[3].fString = plwcsdup(friendInvite.wstr()); fSock->sendMsg(msg, desc); NCFreeMessage(msg, desc); return transId; }
uint32_t pnAuthClient::sendAcctLoginRequest(uint32_t serverChallenge, uint32_t clientChallenge, const plString& acctName, const plString& password, const plString& authToken, const plString& os) { const pnNetMsg* desc = GET_Cli2Auth(kCli2Auth_AcctLoginRequest); msgparm_t* msg = NCAllocMessage(desc); uint32_t transId = nextTransId(); msg[0].fUint = transId; msg[1].fUint = clientChallenge; msg[2].fString = plwcsdup(acctName.wstr()); pnSha1Hash hash; if (acctName.find('@') != -1 && acctName.find("@gametap") == -1 && acctName.find("@magiquest") == -1) { hash = NCHashLoginInfo(acctName, password, serverChallenge, clientChallenge); } else { hash = pnSha1Hash::Sha1(password.cstr(), password.len()); hash.swapBytes(); // Cyan uses a different byte order for this case } memcpy(msg[3].fData, &hash, sizeof(hash)); msg[4].fString = plwcsdup(authToken.wstr()); msg[5].fString = plwcsdup(os.wstr()); fSock->sendMsg(msg, desc); NCFreeMessage(msg, desc); return transId; }
plUoid plNetClientMgr::GetAgeSDLObjectUoid(const plString& ageName) const { hsAssert(!ageName.IsEmpty(), "nil ageName"); // if age sdl hook is loaded if (fAgeSDLObjectKey) return fAgeSDLObjectKey->GetUoid(); // if age is loaded plLocation loc = plKeyFinder::Instance().FindLocation(ageName,plAgeDescription::GetCommonPage(plAgeDescription::kGlobal)); if (!loc.IsValid()) { // check current age des if (plAgeLoader::GetInstance()->GetCurrAgeDesc().GetAgeName() == ageName) loc=plAgeLoader::GetInstance()->GetCurrAgeDesc().CalcPageLocation("BuiltIn"); if (!loc.IsValid()) { // try to load age desc hsStream* stream=plAgeLoader::GetAgeDescFileStream(ageName); if (stream) { plAgeDescription ad; ad.Read(stream); loc=ad.CalcPageLocation("BuiltIn"); stream->Close(); } delete stream; } } return plUoid(loc, plSceneObject::Index(), plSDL::kAgeSDLObjectName); }
virtual bool EatPage( plRegistryPageNode *node ) { const plPageInfo &info = node->GetPageInfo(); // Are we searching by age/page? if (!fAgeString.IsNull()) { if (info.GetAge().CompareI(fAgeString) == 0 && info.GetPage().CompareI(fFindString) == 0) { *fPagePtr = node; return false; } return true; } // Try for page only if (info.GetPage().CompareI(fFindString) == 0) { *fPagePtr = node; return false; } // Try for full location if (plString::Format("%s_%s", info.GetAge().c_str(), info.GetPage().c_str()).CompareI(fFindString) == 0) { *fPagePtr = node; return false; } return true; // Keep searching }
std::vector<plFileName> plStreamSource::GetListOfNames(const plFileName& dir, const plString& ext) { plFileName sDir = dir.Normalize('/'); hsAssert(ext.CharAt(0) != '.', "Don't add a dot"); std::lock_guard<std::mutex> lock(fMutex); // loop through all the file data records, and create the list std::vector<plFileName> retVal; for (auto curData = fFileData.begin(); curData != fFileData.end(); curData++) { if ((curData->second.fDir.AsString().CompareI(sDir.AsString()) == 0) && (curData->second.fExt.CompareI(ext) == 0)) retVal.push_back(curData->second.fFilename); } #ifndef PLASMA_EXTERNAL_RELEASE // in internal releases, we can use on-disk files if they exist // Build the search string as "dir/*.ext" std::vector<plFileName> files = plFileSystem::ListDir(sDir, ("*." + ext).c_str()); for (auto iter = files.begin(); iter != files.end(); ++iter) { plFileName norm = iter->Normalize('/'); if (fFileData.find(norm) == fFileData.end()) // we haven't added it yet retVal.push_back(norm); } #endif // PLASMA_EXTERNAL_RELEASE return retVal; }
void pnAuthClient::sendLogStackDump(const plString& stackdump) { const pnNetMsg* desc = GET_Cli2Auth(kCli2Auth_LogStackDump); msgparm_t* msg = NCAllocMessage(desc); msg[0].fString = plwcsdup(stackdump.wstr()); fSock->sendMsg(msg, desc); NCFreeMessage(msg, desc); }
void pnAuthClient::sendLogPythonTraceback(const plString& traceback) { const pnNetMsg* desc = GET_Cli2Auth(kCli2Auth_LogPythonTraceback); msgparm_t* msg = NCAllocMessage(desc); msg[0].fString = plwcsdup(traceback.wstr()); fSock->sendMsg(msg, desc); NCFreeMessage(msg, desc); }
uint32_t hsStream::WriteSafeStringLong(const plString &string) { uint32_t len = string.GetSize(); WriteLE32(len); if (len > 0) { const char *buffp = string.c_str(); uint32_t i; for (i = 0; i < len; i++) { WriteByte(~buffp[i]); } return i; } else return 0; }
static int ISearchLayerRecur(hsGMaterial* mat, const plString &segName, hsTArray<plKey>& keys) { plString name = ( segName.Compare( ENTIRE_ANIMATION_NAME ) == 0 ) ? "" : segName; int i; for( i = 0; i < mat->GetNumLayers(); i++ ) ISearchLayerRecur(mat->GetLayer(i), name, keys); return keys.GetCount(); }
static void writeString(const plString& v, unsigned char*& buffer, size_t& size) { plString::Wide ws = v.wstr(); size_t len = (ws.len() + 1) * sizeof(pl_wchar_t); writeU32(len, buffer, size); memcpy(buffer, ws.data(), len); // Includes the '\0' buffer += len; size -= len; }
void SecureFiles(const plFileName& dir, const plString& ext, uint32_t* key) { std::vector<plFileName> files = plFileSystem::ListDir(dir, ext.c_str()); for (auto iter = files.begin(); iter != files.end(); ++iter) { printf("securing: %s\n", iter->GetFileName().c_str()); plSecureStream::FileEncrypt(*iter, key); } }
virtual bool EatPage( plRegistryPageNode *page ) { if ( !fAge.IsEmpty() && page->GetPageInfo().GetAge().CompareI(fAge) == 0 ) { fPages.Append( page ); } return true; }
plKey plPluginResManager::NameToLoc(const plString& age, const plString& page, int32_t sequenceNumber, bool itinerant) { // Get or create our page plRegistryPageNode* pageNode = INameToPage(age, page, sequenceNumber, itinerant); hsAssert(pageNode != nil, "No page returned from INameToPage(), shouldn't be possible"); // Go find the sceneNode now, since we know the page exists (go through our normal channels, though) plString keyName = plString::Format("%s_%s", age.c_str(), page.c_str()); plUoid nodeUoid(pageNode->GetPageInfo().GetLocation(), plSceneNode::Index(), keyName); plKey snKey = FindKey(nodeUoid); if (snKey == nil) { // Not found, create a new one plSceneNode *newSceneNode = new plSceneNode; snKey = NewKey(keyName, newSceneNode, pageNode->GetPageInfo().GetLocation()); // Call init after it gets a key newSceneNode->Init(); // Add to our list of exported nodes fExportedNodes.Append(newSceneNode); newSceneNode->GetKey()->RefObject(); } else { hsAssert(snKey->ObjectIsLoaded() != nil, "Somehow we still have the key for a sceneNode that hasn't been loaded."); // Force load, or attempt to at least plSceneNode* node = plSceneNode::ConvertNoRef(snKey->VerifyLoaded()); // Add to our list if necessary if (fExportedNodes.Find(node) == fExportedNodes.kMissingIndex) { fExportedNodes.Append(node); node->GetKey()->RefObject(); } } // Return the key return snKey; }
bool pyStatusLog::Write(plString text) { if (fLog) { fLog->AddLine(text.c_str()); return true; } return false; }
// AddAnim ---------------------------------------------- // -------- void plAGAnim::AddAnim(const plString & name, plAGAnim *anim) { // Only register the animation if it's got a "real" name. Unnamed animations // all get the same standard name. if(name.Compare(ENTIRE_ANIMATION_NAME) != 0) { hsAssert(anim, "registering nil anim"); fAllAnims[name] = anim; } }
uint32_t pnAuthClient::sendGetPublicAgeList(const plString& filename) { const pnNetMsg* desc = GET_Cli2Auth(kCli2Auth_GetPublicAgeList); msgparm_t* msg = NCAllocMessage(desc); uint32_t transId = nextTransId(); msg[0].fUint = transId; msg[1].fString = plwcsdup(filename.wstr()); fSock->sendMsg(msg, desc); NCFreeMessage(msg, desc); return transId; }
virtual bool EatKey( const plKey& key ) { if( key->GetUoid().GetClassType() == fClassType && NameMatches( fObjName.c_str(), key->GetUoid().GetObjectName().c_str(), fSubstr ) ) { fFoundKey = key; return false; } return true; }
uint32_t hsStream::WriteSafeString(const plString &string) { int len = string.GetSize(); hsAssert(len<0xf000, plString::Format("string len of %d is too long for WriteSafeString %s, use WriteSafeStringLong", len, string.c_str()).c_str() ); WriteLE16(len | 0xf000); if (len > 0) { uint32_t i; const char *buffp = string.c_str(); for (i = 0; i < len; i++) { WriteByte(~buffp[i]); } return i; } else return 0; }
uint32_t pnAuthClient::sendAcctExistsRequest(const plString& acctName) { const pnNetMsg* desc = GET_Cli2Auth(kCli2Auth_AcctExistsRequest); msgparm_t* msg = NCAllocMessage(desc); uint32_t transId = nextTransId(); msg[0].fUint = transId; msg[1].fString = plwcsdup(acctName.wstr()); fSock->sendMsg(msg, desc); NCFreeMessage(msg, desc); return transId; }