From 118fd9a184b84137beec7ec76e5caea803f995d0 Mon Sep 17 00:00:00 2001 From: Bartek Bok Date: Wed, 27 Apr 2011 17:07:58 +0200 Subject: [PATCH 1/5] Net propagated PtAttach and cloning --- Sources/Plasma/FeatureLib/pfPython/cyMisc.cpp | 84 +++++++++++++++++-- Sources/Plasma/FeatureLib/pfPython/cyMisc.h | 14 ++-- .../Plasma/FeatureLib/pfPython/cyMiscGlue.cpp | 27 ++++++ .../FeatureLib/pfPython/cyMiscGlue2.cpp | 16 ++-- .../FeatureLib/pfPython/cyMiscGlue3.cpp | 26 +++--- 5 files changed, 136 insertions(+), 31 deletions(-) diff --git a/Sources/Plasma/FeatureLib/pfPython/cyMisc.cpp b/Sources/Plasma/FeatureLib/pfPython/cyMisc.cpp index b29a516d..4265ca48 100644 --- a/Sources/Plasma/FeatureLib/pfPython/cyMisc.cpp +++ b/Sources/Plasma/FeatureLib/pfPython/cyMisc.cpp @@ -42,6 +42,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include #include "plgDispatch.h" +#include "hsResMgr.h" #include "pyKey.h" #pragma hdrstop @@ -49,6 +50,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plResMgr/plKeyFinder.h" #include "pnKeyedObject/plKey.h" +#include "pnKeyedObject/plKeyImp.h" #include "pnKeyedObject/plFixedKey.h" #include "plMessage/plLinkToAgeMsg.h" #include "plMessage/plConsoleMsg.h" @@ -302,7 +304,7 @@ void cyMisc::ClearTimerCallbacks(pyKey& selfkey) // // PURPOSE : Attach an object to another object, knowing only their pyKeys // -void cyMisc::AttachObject(pyKey& ckey, pyKey& pkey) +void cyMisc::AttachObject(pyKey& ckey, pyKey& pkey, bool netForce) { plKey childKey = ckey.getKey(); plKey parentKey = pkey.getKey(); @@ -312,10 +314,16 @@ void cyMisc::AttachObject(pyKey& ckey, pyKey& pkey) { // create the attach message to attach the child plAttachMsg* pMsg = new plAttachMsg(parentKey, childKey->GetObjectPtr(), plRefMsg::kOnRequest); + + if (netForce) { + pMsg->SetBCastFlag(plMessage::kNetPropagate); + pMsg->SetBCastFlag(plMessage::kNetForce); + } + plgDispatch::MsgSend( pMsg ); } } -void cyMisc::AttachObjectSO(pySceneObject& cobj, pySceneObject& pobj) +void cyMisc::AttachObjectSO(pySceneObject& cobj, pySceneObject& pobj, bool netForce) { plKey childKey = cobj.getObjKey(); plKey parentKey = pobj.getObjKey(); @@ -325,6 +333,12 @@ void cyMisc::AttachObjectSO(pySceneObject& cobj, pySceneObject& pobj) { // create the attach message to attach the child plAttachMsg* pMsg = new plAttachMsg(parentKey, childKey->GetObjectPtr(), plRefMsg::kOnRequest); + + if (netForce) { + pMsg->SetBCastFlag(plMessage::kNetPropagate); + pMsg->SetBCastFlag(plMessage::kNetForce); + } + plgDispatch::MsgSend( pMsg ); } } @@ -338,7 +352,7 @@ void cyMisc::AttachObjectSO(pySceneObject& cobj, pySceneObject& pobj) // // PURPOSE : Attach an object to another object, knowing only their pyKeys // -void cyMisc::DetachObject(pyKey& ckey, pyKey& pkey) +void cyMisc::DetachObject(pyKey& ckey, pyKey& pkey, bool netForce) { plKey childKey = ckey.getKey(); plKey parentKey = pkey.getKey(); @@ -348,10 +362,16 @@ void cyMisc::DetachObject(pyKey& ckey, pyKey& pkey) { // create the attach message to detach the child plAttachMsg* pMsg = new plAttachMsg(parentKey, childKey->GetObjectPtr(), plRefMsg::kOnRemove); + + if (netForce) { + pMsg->SetBCastFlag(plMessage::kNetPropagate); + pMsg->SetBCastFlag(plMessage::kNetForce); + } + plgDispatch::MsgSend( pMsg ); } } -void cyMisc::DetachObjectSO(pySceneObject& cobj, pySceneObject& pobj) +void cyMisc::DetachObjectSO(pySceneObject& cobj, pySceneObject& pobj, bool netForce) { plKey childKey = cobj.getObjKey(); plKey parentKey = pobj.getObjKey(); @@ -361,6 +381,12 @@ void cyMisc::DetachObjectSO(pySceneObject& cobj, pySceneObject& pobj) { // create the attach message to detach the child plAttachMsg* pMsg = new plAttachMsg(parentKey, childKey->GetObjectPtr(), plRefMsg::kOnRemove); + + if (netForce) { + pMsg->SetBCastFlag(plMessage::kNetPropagate); + pMsg->SetBCastFlag(plMessage::kNetForce); + } + plgDispatch::MsgSend( pMsg ); } } @@ -1415,7 +1441,7 @@ int cyMisc::GetNumRemotePlayers() // PURPOSE : page in, hold or out a particular node // -void cyMisc::PageInNodes(const std::vector & nodeNames, const char* age) +void cyMisc::PageInNodes(const std::vector & nodeNames, const char* age, bool netForce) { if (hsgResMgr::ResMgr()) { @@ -1424,6 +1450,11 @@ void cyMisc::PageInNodes(const std::vector & nodeNames, const char* plKey clientKey = hsgResMgr::ResMgr()->FindKey(kClient_KEY); msg->AddReceiver(clientKey); + if (netForce) { + msg->SetBCastFlag(plMessage::kNetPropagate); + msg->SetBCastFlag(plMessage::kNetForce); + } + int numNames = nodeNames.size(); for (int i = 0; i < numNames; i++) msg->AddRoomLoc(plKeyFinder::Instance().FindLocation(age ? age : NetCommGetAge()->ageDatasetName, nodeNames[i].c_str())); @@ -1432,7 +1463,7 @@ void cyMisc::PageInNodes(const std::vector & nodeNames, const char* } } -void cyMisc::PageOutNode(const char* nodeName) +void cyMisc::PageOutNode(const char* nodeName, bool netForce) { if ( hsgResMgr::ResMgr() ) { @@ -1441,6 +1472,11 @@ void cyMisc::PageOutNode(const char* nodeName) plKey clientKey = hsgResMgr::ResMgr()->FindKey( kClient_KEY ); pMsg1->AddReceiver( clientKey ); pMsg1->AddRoomLoc(plKeyFinder::Instance().FindLocation("", nodeName)); + + if (netForce) { + pMsg1->SetBCastFlag(plMessage::kNetPropagate); + pMsg1->SetBCastFlag(plMessage::kNetForce); + } plgDispatch::MsgSend(pMsg1); } } @@ -2866,3 +2902,39 @@ void cyMisc::VaultDownload(unsigned nodeId) nil ); } + +PyObject* cyMisc::CloneKey(pyKey* object, bool netForce) { + + plKey obj = object->getKey(); + plUoid uoid = obj->GetUoid(); + plLoadCloneMsg* cloneMsg; + if (uoid.IsClone()) + cloneMsg = new plLoadCloneMsg(obj, plNetClientMgr::GetInstance()->GetKey(), 0, true); + else + cloneMsg = new plLoadCloneMsg(uoid, plNetClientMgr::GetInstance()->GetKey(), 0); + + if (netForce) { + cloneMsg->SetBCastFlag(plMessage::kNetPropagate); + cloneMsg->SetBCastFlag(plMessage::kNetForce); + } + + cloneMsg->Send(); + + return pyKey::New(cloneMsg->GetCloneKey()); +} + +PyObject* cyMisc::FindClones(pyKey* object) { + plKey obj = object->getKey(); + plUoid uoid = obj->GetUoid(); + + plKeyImp* imp = ((plKeyImp*)obj); + uint32_t cloneNum = imp->GetNumClones(); + PyObject* keyList = PyList_New(cloneNum); + + for (int i=0; i < cloneNum; i++) { + PyObject* key = pyKey::New(imp->GetCloneByIdx(i)); + PyList_SET_ITEM(keyList, i, key); + } + + return keyList; +} diff --git a/Sources/Plasma/FeatureLib/pfPython/cyMisc.h b/Sources/Plasma/FeatureLib/pfPython/cyMisc.h index 3f6f543c..ef0fc7a0 100644 --- a/Sources/Plasma/FeatureLib/pfPython/cyMisc.h +++ b/Sources/Plasma/FeatureLib/pfPython/cyMisc.h @@ -184,8 +184,8 @@ public: // // PURPOSE : Attach an object to another object, knowing only their pyKeys // - static void AttachObject(pyKey& ckey, pyKey& pkey); - static void AttachObjectSO(pySceneObject& cobj, pySceneObject& pobj); + static void AttachObject(pyKey& ckey, pyKey& pkey, bool netForce); + static void AttachObjectSO(pySceneObject& cobj, pySceneObject& pobj, bool netForce); ///////////////////////////////////////////////////////////////////////////// // @@ -195,8 +195,8 @@ public: // // PURPOSE : Attach an object to another object, knowing only their pyKeys // - static void DetachObject(pyKey& ckey, pyKey& pkey); - static void DetachObjectSO(pySceneObject& cobj, pySceneObject& pobj); + static void DetachObject(pyKey& ckey, pyKey& pkey, bool netForce); + static void DetachObjectSO(pySceneObject& cobj, pySceneObject& pobj, bool netForce); ///////////////////////////////////////////////////////////////////////////// // @@ -593,8 +593,8 @@ public: // // PURPOSE : page in, or out a paritcular node // - static void PageInNodes(const std::vector & nodeNames, const char* age); - static void PageOutNode(const char* nodeName); + static void PageInNodes(const std::vector & nodeNames, const char* age, bool netForce); + static void PageOutNode(const char* nodeName, bool netForce); ///////////////////////////////////////////////////////////////////////////// // @@ -954,6 +954,8 @@ public: static PyObject* GetAIAvatarsByModelName(const char* name); static void ForceVaultNodeUpdate(unsigned nodeId); static void VaultDownload(unsigned nodeId); + static PyObject* CloneKey(pyKey* object, bool netForce); + static PyObject* FindClones(pyKey* object); }; #endif // cyMisc_h diff --git a/Sources/Plasma/FeatureLib/pfPython/cyMiscGlue.cpp b/Sources/Plasma/FeatureLib/pfPython/cyMiscGlue.cpp index a01c13a5..43806e18 100644 --- a/Sources/Plasma/FeatureLib/pfPython/cyMiscGlue.cpp +++ b/Sources/Plasma/FeatureLib/pfPython/cyMiscGlue.cpp @@ -484,6 +484,31 @@ PYTHON_GLOBAL_METHOD_DEFINITION(PtDumpLogs, args, "Params: folder\nDumps all cur } } +PYTHON_GLOBAL_METHOD_DEFINITION(PtCloneKey, args, "Params: key, netForce=false\nCreates clone of key") +{ + PyObject* keyObj = NULL; + char netForce = 0; + if (!PyArg_ParseTuple(args, "O|b", &keyObj, &netForce) || !pyKey::Check(keyObj)) + { + PyErr_SetString(PyExc_TypeError, "PtCloneKey expects a ptKey and bool"); + PYTHON_RETURN_ERROR; + } + pyKey* key = pyKey::ConvertFrom(keyObj); + return cyMisc::CloneKey(key, netForce); +} + +PYTHON_GLOBAL_METHOD_DEFINITION(PtFindClones, args, "Params: key\nFinds all clones") +{ + PyObject* keyObj = NULL; + if (!PyArg_ParseTuple(args, "O", &keyObj) || !pyKey::Check(keyObj)) + { + PyErr_SetString(PyExc_TypeError, "PtFindClones expects a ptKey"); + PYTHON_RETURN_ERROR; + } + pyKey* key = pyKey::ConvertFrom(keyObj); + return cyMisc::FindClones(key); +} + /////////////////////////////////////////////////////////////////////////// // // AddPlasmaMethods - the python method definitions @@ -530,6 +555,8 @@ void cyMisc::AddPlasmaMethods(std::vector &methods) PYTHON_GLOBAL_METHOD(methods, PtGetLocalizedString); PYTHON_GLOBAL_METHOD(methods, PtDumpLogs); + PYTHON_GLOBAL_METHOD(methods, PtCloneKey); + PYTHON_GLOBAL_METHOD(methods, PtFindClones); AddPlasmaMethods2(methods); AddPlasmaMethods3(methods); diff --git a/Sources/Plasma/FeatureLib/pfPython/cyMiscGlue2.cpp b/Sources/Plasma/FeatureLib/pfPython/cyMiscGlue2.cpp index 53baabf8..a37485bb 100644 --- a/Sources/Plasma/FeatureLib/pfPython/cyMiscGlue2.cpp +++ b/Sources/Plasma/FeatureLib/pfPython/cyMiscGlue2.cpp @@ -183,11 +183,12 @@ PYTHON_GLOBAL_METHOD_DEFINITION_NOARGS(PtGetFrameDeltaTime, "Returns the amount return PyFloat_FromDouble(cyMisc::GetDelSysSeconds()); } -PYTHON_GLOBAL_METHOD_DEFINITION(PtPageInNode, args, "Params: nodeName, ageName=\"\"\nPages in node, or a list of nodes") +PYTHON_GLOBAL_METHOD_DEFINITION(PtPageInNode, args, "Params: nodeName, netForce=false, ageName=\"\"\nPages in node, or a list of nodes") { PyObject* nodeNameObj = NULL; char* ageName = NULL; - if (!PyArg_ParseTuple(args, "O|s", &nodeNameObj, &ageName)) + char netForce = 0; + if (!PyArg_ParseTuple(args, "O|bs", &nodeNameObj, &netForce, &ageName)) { PyErr_SetString(PyExc_TypeError, "PtPageInNode expects a string or list of strings, and optionally a string"); PYTHON_RETURN_ERROR; @@ -217,19 +218,20 @@ PYTHON_GLOBAL_METHOD_DEFINITION(PtPageInNode, args, "Params: nodeName, ageName=\ PYTHON_RETURN_ERROR; } - cyMisc::PageInNodes(nodeNames, ageName); + cyMisc::PageInNodes(nodeNames, ageName, netForce); PYTHON_RETURN_NONE; } -PYTHON_GLOBAL_METHOD_DEFINITION(PtPageOutNode, args, "Params: nodeName\nPages out a node") +PYTHON_GLOBAL_METHOD_DEFINITION(PtPageOutNode, args, "Params: nodeName, netForce = false\nPages out a node") { char* nodeName; - if (!PyArg_ParseTuple(args, "s", &nodeName)) + char netForce = 0; + if (!PyArg_ParseTuple(args, "s|b", &nodeName, &netForce)) { - PyErr_SetString(PyExc_TypeError, "PtPageOutNode expects a string"); + PyErr_SetString(PyExc_TypeError, "PtPageOutNode expects a string and bool"); PYTHON_RETURN_ERROR; } - cyMisc::PageOutNode(nodeName); + cyMisc::PageOutNode(nodeName, netForce); PYTHON_RETURN_NONE; } diff --git a/Sources/Plasma/FeatureLib/pfPython/cyMiscGlue3.cpp b/Sources/Plasma/FeatureLib/pfPython/cyMiscGlue3.cpp index 15016870..71313789 100644 --- a/Sources/Plasma/FeatureLib/pfPython/cyMiscGlue3.cpp +++ b/Sources/Plasma/FeatureLib/pfPython/cyMiscGlue3.cpp @@ -223,65 +223,67 @@ PYTHON_GLOBAL_METHOD_DEFINITION(PtWasLocallyNotified, args, "Params: selfKey\nRe PYTHON_RETURN_BOOL(cyMisc::WasLocallyNotified(*key)); } -PYTHON_GLOBAL_METHOD_DEFINITION(PtAttachObject, args, "Params: child,parent\nAttach child to parent based on ptKey or ptSceneobject\n" +PYTHON_GLOBAL_METHOD_DEFINITION(PtAttachObject, args, "Params: child,parent,netForce=false\nAttach child to parent based on ptKey or ptSceneobject\n" "- childKey is the ptKey or ptSceneobject of the one being attached\n" "- parentKey is the ptKey or ptSceneobject of the one being attached to\n" "(both arguments must be ptKeys or ptSceneobjects, you cannot mix types)") { PyObject* childObj = NULL; PyObject* parentObj = NULL; - if (!PyArg_ParseTuple(args, "OO", &childObj, &parentObj)) + char netForce = 0; + if (!PyArg_ParseTuple(args, "OO|b", &childObj, &parentObj, &netForce)) { - PyErr_SetString(PyExc_TypeError, "PtAttachObject expects either two ptKeys or two ptSceneobjects"); + PyErr_SetString(PyExc_TypeError, "PtAttachObject expects either two ptKeys or two ptSceneobjects and bool"); PYTHON_RETURN_ERROR; } if ((pyKey::Check(childObj)) && (pyKey::Check(parentObj))) { pyKey* child = pyKey::ConvertFrom(childObj); pyKey* parent = pyKey::ConvertFrom(parentObj); - cyMisc::AttachObject(*child, *parent); + cyMisc::AttachObject(*child, *parent, netForce); } else if ((pySceneObject::Check(childObj)) && (pySceneObject::Check(parentObj))) { pySceneObject* child = pySceneObject::ConvertFrom(childObj); pySceneObject* parent = pySceneObject::ConvertFrom(parentObj); - cyMisc::AttachObjectSO(*child, *parent); + cyMisc::AttachObjectSO(*child, *parent, netForce); } else { - PyErr_SetString(PyExc_TypeError, "PtAttachObject expects either two ptKeys or two ptSceneobjects"); + PyErr_SetString(PyExc_TypeError, "PtAttachObject expects either two ptKeys or two ptSceneobjects and bool"); PYTHON_RETURN_ERROR; } PYTHON_RETURN_NONE; } -PYTHON_GLOBAL_METHOD_DEFINITION(PtDetachObject, args, "Params: child,parent\nDetach child from parent based on ptKey or ptSceneobject\n" +PYTHON_GLOBAL_METHOD_DEFINITION(PtDetachObject, args, "Params: child,parent,netForce=false\nDetach child from parent based on ptKey or ptSceneobject\n" "- child is the ptKey or ptSceneobject of the one being detached\n" "- parent is the ptKey or ptSceneobject of the one being detached from\n" "(both arguments must be ptKeys or ptSceneobjects, you cannot mix types)") { PyObject* childObj = NULL; PyObject* parentObj = NULL; - if (!PyArg_ParseTuple(args, "OO", &childObj, &parentObj)) + char netForce = 0; + if (!PyArg_ParseTuple(args, "OO|b", &childObj, &parentObj, &netForce)) { - PyErr_SetString(PyExc_TypeError, "PtDetachObject expects either two ptKeys or two ptSceneobjects"); + PyErr_SetString(PyExc_TypeError, "PtDetachObject expects either two ptKeys or two ptSceneobjects and bool"); PYTHON_RETURN_ERROR; } if ((pyKey::Check(childObj)) && (pyKey::Check(parentObj))) { pyKey* child = pyKey::ConvertFrom(childObj); pyKey* parent = pyKey::ConvertFrom(parentObj); - cyMisc::DetachObject(*child, *parent); + cyMisc::DetachObject(*child, *parent, netForce); } else if ((pySceneObject::Check(childObj)) && (pySceneObject::Check(parentObj))) { pySceneObject* child = pySceneObject::ConvertFrom(childObj); pySceneObject* parent = pySceneObject::ConvertFrom(parentObj); - cyMisc::DetachObjectSO(*child, *parent); + cyMisc::DetachObjectSO(*child, *parent, netForce); } else { - PyErr_SetString(PyExc_TypeError, "PtDetachObject expects either two ptKeys or two ptSceneobjects"); + PyErr_SetString(PyExc_TypeError, "PtDetachObject expects either two ptKeys or two ptSceneobjects and bool"); PYTHON_RETURN_ERROR; } PYTHON_RETURN_NONE; From 57c600ce32e3108f1570a4de8d32b728afe8ffc8 Mon Sep 17 00:00:00 2001 From: Bartek Bok Date: Tue, 31 May 2011 17:32:50 +0200 Subject: [PATCH 2/5] Clone unloading --- Sources/Plasma/FeatureLib/pfPython/cyMisc.cpp | 12 +++++------- Sources/Plasma/FeatureLib/pfPython/cyMiscGlue.cpp | 8 ++++---- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/Sources/Plasma/FeatureLib/pfPython/cyMisc.cpp b/Sources/Plasma/FeatureLib/pfPython/cyMisc.cpp index 4265ca48..2d2b8fc3 100644 --- a/Sources/Plasma/FeatureLib/pfPython/cyMisc.cpp +++ b/Sources/Plasma/FeatureLib/pfPython/cyMisc.cpp @@ -2903,21 +2903,19 @@ void cyMisc::VaultDownload(unsigned nodeId) ); } -PyObject* cyMisc::CloneKey(pyKey* object, bool netForce) { +PyObject* cyMisc::CloneKey(pyKey* object, bool loading) { plKey obj = object->getKey(); plUoid uoid = obj->GetUoid(); + plLoadCloneMsg* cloneMsg; if (uoid.IsClone()) - cloneMsg = new plLoadCloneMsg(obj, plNetClientMgr::GetInstance()->GetKey(), 0, true); + cloneMsg = new plLoadCloneMsg(obj, plNetClientMgr::GetInstance()->GetKey(), 0, loading); else cloneMsg = new plLoadCloneMsg(uoid, plNetClientMgr::GetInstance()->GetKey(), 0); - if (netForce) { - cloneMsg->SetBCastFlag(plMessage::kNetPropagate); - cloneMsg->SetBCastFlag(plMessage::kNetForce); - } - + cloneMsg->SetBCastFlag(plMessage::kNetPropagate); + cloneMsg->SetBCastFlag(plMessage::kNetForce); cloneMsg->Send(); return pyKey::New(cloneMsg->GetCloneKey()); diff --git a/Sources/Plasma/FeatureLib/pfPython/cyMiscGlue.cpp b/Sources/Plasma/FeatureLib/pfPython/cyMiscGlue.cpp index 43806e18..852c8c31 100644 --- a/Sources/Plasma/FeatureLib/pfPython/cyMiscGlue.cpp +++ b/Sources/Plasma/FeatureLib/pfPython/cyMiscGlue.cpp @@ -484,17 +484,17 @@ PYTHON_GLOBAL_METHOD_DEFINITION(PtDumpLogs, args, "Params: folder\nDumps all cur } } -PYTHON_GLOBAL_METHOD_DEFINITION(PtCloneKey, args, "Params: key, netForce=false\nCreates clone of key") +PYTHON_GLOBAL_METHOD_DEFINITION(PtCloneKey, args, "Params: key, loading=false\nCreates clone of key") { PyObject* keyObj = NULL; - char netForce = 0; - if (!PyArg_ParseTuple(args, "O|b", &keyObj, &netForce) || !pyKey::Check(keyObj)) + char loading = 0; + if (!PyArg_ParseTuple(args, "O|b", &keyObj, &loading) || !pyKey::Check(keyObj)) { PyErr_SetString(PyExc_TypeError, "PtCloneKey expects a ptKey and bool"); PYTHON_RETURN_ERROR; } pyKey* key = pyKey::ConvertFrom(keyObj); - return cyMisc::CloneKey(key, netForce); + return cyMisc::CloneKey(key, loading); } PYTHON_GLOBAL_METHOD_DEFINITION(PtFindClones, args, "Params: key\nFinds all clones") From 0c1b6bb096c9aa7e4b8740aaf6df81a599e077a0 Mon Sep 17 00:00:00 2001 From: Bartek Bok Date: Tue, 31 May 2011 17:34:08 +0200 Subject: [PATCH 3/5] Some messages are useful --- .../plNetClient/plNetClientMsgScreener.cpp | 10 ++++--- .../plNetCommon/plNetMsgScreener.cpp | 27 ++----------------- 2 files changed, 8 insertions(+), 29 deletions(-) diff --git a/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMsgScreener.cpp b/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMsgScreener.cpp index aa9528ba..af34573d 100644 --- a/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMsgScreener.cpp +++ b/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMsgScreener.cpp @@ -144,13 +144,11 @@ bool plNetClientMsgScreener::AllowIncomingMessage(const plMessage* msg) const bool plNetClientMsgScreener::IScreenIncoming(const plMessage* msg) const { - // Why would you EVER send a RefMsg accross the network??? - if (plFactory::DerivesFrom(CLASS_INDEX_SCOPED(plRefMsg), msg->ClassIndex())) - return false; - // Blacklist some obvious hacks here... switch (msg->ClassIndex()) { + case CLASS_INDEX_SCOPED(plAttachMsg): + return true; case CLASS_INDEX_SCOPED(plAudioSysMsg): // This message has a flawed read/write return false; @@ -170,4 +168,8 @@ bool plNetClientMsgScreener::IScreenIncoming(const plMessage* msg) const // might break something that we really shouldn't... return true; } + + // Toss non-attach plRefMsgs + if (plFactory::DerivesFrom(CLASS_INDEX_SCOPED(plRefMsg), msg->ClassIndex())) + return false; } diff --git a/Sources/Plasma/PubUtilLib/plNetCommon/plNetMsgScreener.cpp b/Sources/Plasma/PubUtilLib/plNetCommon/plNetMsgScreener.cpp index ba49e33c..4afe7e2a 100644 --- a/Sources/Plasma/PubUtilLib/plNetCommon/plNetMsgScreener.cpp +++ b/Sources/Plasma/PubUtilLib/plNetCommon/plNetMsgScreener.cpp @@ -90,18 +90,6 @@ void plNetMsgScreener::IRejectLogMsg(const plMessage* msg, const char* desc, con // plNetMsgScreener::Answer plNetMsgScreener::IAllowMessageType(int16_t classIndex, const plNetGameMember* gm) const { - // Check based on baseclass - if (plFactory::DerivesFrom(plCCRMessage::Index(), classIndex)) - { - ILogCCRMessage(classIndex, gm); - Answer ans=IIsSenderCCR(gm) ? kYes : kNo; - if (ans==kNo) - { - IRejectLogMsg(classIndex, "Not a CCR", gm); - } - return ans; - } - // Check based on exact type switch(classIndex) { @@ -129,19 +117,8 @@ plNetMsgScreener::Answer plNetMsgScreener::IAllowMessageType(int16_t classIndex, case CLASS_INDEX_SCOPED(plLinkToAgeMsg): case CLASS_INDEX_SCOPED(plSubWorldMsg): return kYes; - - // definitely yes or no (based on whether sender is a CCR) - case CLASS_INDEX_SCOPED(plWarpMsg): - { - Answer ans=IIsSenderCCR(gm) ? kYes : kNo; - if (ans==kNo) - { - IRejectLogMsg(classIndex, "Not a CCR", gm); - } - return ans; - } - - // conditionally yes, requires further validation of msg contents + + // conditionally yes, requires further validation of msg contents case CLASS_INDEX_SCOPED(plAnimCmdMsg): case CLASS_INDEX_SCOPED(pfKIMsg): case CLASS_INDEX_SCOPED(plAvTaskMsg): From 6832881e32d22fadcd1fd570fb54a3413739c753 Mon Sep 17 00:00:00 2001 From: Bartek Bok Date: Sun, 23 Oct 2011 11:21:02 +0200 Subject: [PATCH 4/5] Enable plDynamicTextMsg sending --- .../PubUtilLib/plGImage/plDynamicTextMap.cpp | 16 ++++++------- .../PubUtilLib/plMessage/plDynamicTextMsg.cpp | 23 ++++++++----------- .../PubUtilLib/plMessage/plDynamicTextMsg.h | 8 ++++--- .../plNetCommon/plNetMsgScreener.cpp | 1 + 4 files changed, 23 insertions(+), 25 deletions(-) diff --git a/Sources/Plasma/PubUtilLib/plGImage/plDynamicTextMap.cpp b/Sources/Plasma/PubUtilLib/plGImage/plDynamicTextMap.cpp index f0e935a2..e862c6cf 100644 --- a/Sources/Plasma/PubUtilLib/plGImage/plDynamicTextMap.cpp +++ b/Sources/Plasma/PubUtilLib/plGImage/plDynamicTextMap.cpp @@ -815,8 +815,8 @@ bool plDynamicTextMap::MsgReceive( plMessage *msg ) if( textMsg->fCmd & plDynamicTextMsg::kSetTextColor ) SetTextColor( textMsg->fColor, textMsg->fBlockRGB ); - if( (textMsg->fCmd & plDynamicTextMsg::kSetFont ) && textMsg->fString) - SetFont( textMsg->fString, textMsg->fX, (uint8_t)(textMsg->fFlags) ); + if( (textMsg->fCmd & plDynamicTextMsg::kSetFont ) && !textMsg->fString.IsNull()) + SetFont( textMsg->fString.ToWchar(), textMsg->fX, (uint8_t)(textMsg->fFlags) ); if( textMsg->fCmd & plDynamicTextMsg::kSetLineSpacing ) SetLineSpacing( textMsg->fLineSpacing ); @@ -832,16 +832,16 @@ bool plDynamicTextMap::MsgReceive( plMessage *msg ) FrameRect( textMsg->fLeft, textMsg->fTop, textMsg->fRight - textMsg->fLeft + 1, textMsg->fBottom - textMsg->fTop + 1, textMsg->fColor ); - if( (textMsg->fCmd & plDynamicTextMsg::kDrawString ) && textMsg->fString) - DrawString( textMsg->fX, textMsg->fY, textMsg->fString ); + if( (textMsg->fCmd & plDynamicTextMsg::kDrawString ) && !textMsg->fString.IsNull()) + DrawString( textMsg->fX, textMsg->fY, textMsg->fString.ToWchar() ); - if( (textMsg->fCmd & plDynamicTextMsg::kDrawClippedString ) && textMsg->fString) - DrawClippedString( textMsg->fX, textMsg->fY, textMsg->fString, + if( (textMsg->fCmd & plDynamicTextMsg::kDrawClippedString ) && !textMsg->fString.IsNull()) + DrawClippedString( textMsg->fX, textMsg->fY, textMsg->fString.ToWchar(), textMsg->fLeft, textMsg->fTop, textMsg->fRight - textMsg->fLeft + 1, textMsg->fBottom - textMsg->fTop + 1 ); - if( (textMsg->fCmd & plDynamicTextMsg::kDrawWrappedString ) && textMsg->fString) - DrawWrappedString( textMsg->fX, textMsg->fY, textMsg->fString, textMsg->fRight, textMsg->fBottom ); + if( (textMsg->fCmd & plDynamicTextMsg::kDrawWrappedString ) && !textMsg->fString.IsNull()) + DrawWrappedString( textMsg->fX, textMsg->fY, textMsg->fString.ToWchar(), textMsg->fRight, textMsg->fBottom ); if( textMsg->fCmd & plDynamicTextMsg::kDrawImage ) { diff --git a/Sources/Plasma/PubUtilLib/plMessage/plDynamicTextMsg.cpp b/Sources/Plasma/PubUtilLib/plMessage/plDynamicTextMsg.cpp index 3b4861fc..ceebb8b4 100644 --- a/Sources/Plasma/PubUtilLib/plMessage/plDynamicTextMsg.cpp +++ b/Sources/Plasma/PubUtilLib/plMessage/plDynamicTextMsg.cpp @@ -65,7 +65,7 @@ void plDynamicTextMsg::SetFont( const char *face, int16_t size, bool isBold ) hsAssert( ( fCmd & ( kPosCmds | kStringCmds | kFlagCmds ) ) == 0, "Attempting to issue conflicting drawText commands" ); fCmd &= ~( kPosCmds | kStringCmds | kFlagCmds ); fCmd |= kSetFont; - fString = hsStringToWString( face ); + fString = face; fX = size; fFlags = (uint32_t)isBold; } @@ -123,9 +123,7 @@ void plDynamicTextMsg::DrawString( int16_t x, int16_t y, const wchar_t *text fCmd &= ~( kStringCmds | kPosCmds ); fCmd |= kDrawString; - fString = new wchar_t[wcslen(text)+1]; - wcscpy( fString, text ); - fString[wcslen(text)] = L'\0'; + fString = plString::FromWchar(text); fX = x; fY = y; } @@ -143,9 +141,7 @@ void plDynamicTextMsg::DrawClippedString( int16_t x, int16_t y, uint16_t clip fCmd &= ~( kStringCmds | kPosCmds | kRectCmds ); fCmd |= kDrawClippedString; - fString = new wchar_t[wcslen(text)+1]; - wcscpy( fString, text ); - fString[wcslen(text)] = L'\0'; + fString = plString::FromWchar(text); fX = x; fY = y; @@ -168,9 +164,7 @@ void plDynamicTextMsg::DrawWrappedString( int16_t x, int16_t y, uint16_t wrap fCmd &= ~( kStringCmds | kPosCmds | kRectCmds ); fCmd |= kDrawWrappedString; - fString = new wchar_t[wcslen(text)+1]; - wcscpy( fString, text ); - fString[wcslen(text)] = L'\0'; + fString = plString::FromWchar(text); fX = x; fY = y; @@ -222,7 +216,7 @@ void plDynamicTextMsg::Read( hsStream *s, hsResMgr *mgr ) fClearColor.Read( s ); fColor.Read( s ); - fString = s->ReadSafeWString(); + fString = s->ReadSafeWString_TEMP(); fImageKey = mgr->ReadKey( s ); s->ReadLE( &fFlags ); @@ -253,7 +247,8 @@ void plDynamicTextMsg::Write( hsStream *s, hsResMgr *mgr ) fClearColor.Write( s ); fColor.Write( s ); - s->WriteSafeWString( plString::FromWchar(fString) ); + s->WriteSafeWString(fString); + mgr->WriteKey( s, fImageKey ); s->WriteLE( fFlags ); @@ -306,7 +301,7 @@ void plDynamicTextMsg::ReadVersion(hsStream* s, hsResMgr* mgr) if (contentFlags.IsBitSet(kDynTextMsgColor)) fColor.Read( s ); if (contentFlags.IsBitSet(kDynTextMsgString)) - fString = s->ReadSafeWString(); + fString = s->ReadSafeWString_TEMP(); if (contentFlags.IsBitSet(kDynTextMsgImageKey)) fImageKey = mgr->ReadKey( s ); if (contentFlags.IsBitSet(kDynTextMsgFlags)) @@ -360,7 +355,7 @@ void plDynamicTextMsg::WriteVersion(hsStream* s, hsResMgr* mgr) fColor.Write( s ); // kDynTextMsgString - s->WriteSafeWString( plString::FromWchar(fString) ); + s->WriteSafeWString( fString ); // kDynTextMsgImageKey mgr->WriteKey( s, fImageKey ); diff --git a/Sources/Plasma/PubUtilLib/plMessage/plDynamicTextMsg.h b/Sources/Plasma/PubUtilLib/plMessage/plDynamicTextMsg.h index 9de28e8b..9f800450 100644 --- a/Sources/Plasma/PubUtilLib/plMessage/plDynamicTextMsg.h +++ b/Sources/Plasma/PubUtilLib/plMessage/plDynamicTextMsg.h @@ -72,7 +72,7 @@ protected: hsColorRGBA fColor; // String - wchar_t *fString; + plString fString; // Mipmap plKey fImageKey; @@ -84,8 +84,10 @@ protected: int16_t fLineSpacing; public: - plDynamicTextMsg() : plMessage( nil, nil, nil ) { fCmd = 0; fString = nil; fImageKey = nil; fFlags = 0; fBlockRGB = false; } - ~plDynamicTextMsg() { delete [] fString; } + plDynamicTextMsg() : + plMessage(nullptr, nullptr, nullptr), + fCmd(0), fImageKey(nullptr), fFlags(0), fBlockRGB(false) + { } CLASSNAME_REGISTER( plDynamicTextMsg ); GETINTERFACE_ANY( plDynamicTextMsg, plMessage ); diff --git a/Sources/Plasma/PubUtilLib/plNetCommon/plNetMsgScreener.cpp b/Sources/Plasma/PubUtilLib/plNetCommon/plNetMsgScreener.cpp index 4afe7e2a..a5e575a8 100644 --- a/Sources/Plasma/PubUtilLib/plNetCommon/plNetMsgScreener.cpp +++ b/Sources/Plasma/PubUtilLib/plNetCommon/plNetMsgScreener.cpp @@ -116,6 +116,7 @@ plNetMsgScreener::Answer plNetMsgScreener::IAllowMessageType(int16_t classIndex, case CLASS_INDEX_SCOPED(plEnableMsg): case CLASS_INDEX_SCOPED(plLinkToAgeMsg): case CLASS_INDEX_SCOPED(plSubWorldMsg): + case CLASS_INDEX_SCOPED(plDynamicTextMsg): return kYes; // conditionally yes, requires further validation of msg contents From 8261074f22fe92844cbbe22a0705bd445e363033 Mon Sep 17 00:00:00 2001 From: Bartek Bok Date: Wed, 25 Jul 2012 23:39:09 +0200 Subject: [PATCH 5/5] Better object searching --- Sources/Plasma/FeatureLib/pfPython/cyMisc.cpp | 17 +++++++++++++++++ Sources/Plasma/FeatureLib/pfPython/cyMisc.h | 1 + .../Plasma/FeatureLib/pfPython/cyMiscGlue3.cpp | 12 ++++++++++++ 3 files changed, 30 insertions(+) diff --git a/Sources/Plasma/FeatureLib/pfPython/cyMisc.cpp b/Sources/Plasma/FeatureLib/pfPython/cyMisc.cpp index 2d2b8fc3..33cef6d5 100644 --- a/Sources/Plasma/FeatureLib/pfPython/cyMisc.cpp +++ b/Sources/Plasma/FeatureLib/pfPython/cyMisc.cpp @@ -222,6 +222,23 @@ PyObject* cyMisc::FindSceneObject(const plString& name, const char* ageName) return pySceneObject::New(key); } +PyObject* cyMisc::FindSceneObjects(const plString& name) +{ + // assume that we won't find the sceneobject (key is equal to nil) + std::vector keys; + + if ( !name.IsNull() ) + plKeyFinder::Instance().ReallyStupidSubstringSearch(name, plSceneObject::Index(), keys); + + PyObject* result = PyList_New(keys.size()); + for (size_t i=0; i < keys.size(); i++) + PyList_SET_ITEM(result, i, pySceneObject::New(keys[i])); + + return result; +} + + + PyObject* cyMisc::FindActivator(const plString& name) { plKey key = nil; diff --git a/Sources/Plasma/FeatureLib/pfPython/cyMisc.h b/Sources/Plasma/FeatureLib/pfPython/cyMisc.h index ef0fc7a0..9f2c6024 100644 --- a/Sources/Plasma/FeatureLib/pfPython/cyMisc.h +++ b/Sources/Plasma/FeatureLib/pfPython/cyMisc.h @@ -147,6 +147,7 @@ public: // optionally propagate over the net // static PyObject* FindSceneObject(const plString& name, const char* ageName); // returns pySceneObject + static PyObject* FindSceneObjects(const plString& name); static PyObject* FindActivator(const plString& name); // returns pyKey ///////////////////////////////////////////////////////////////////////////// diff --git a/Sources/Plasma/FeatureLib/pfPython/cyMiscGlue3.cpp b/Sources/Plasma/FeatureLib/pfPython/cyMiscGlue3.cpp index 71313789..98710749 100644 --- a/Sources/Plasma/FeatureLib/pfPython/cyMiscGlue3.cpp +++ b/Sources/Plasma/FeatureLib/pfPython/cyMiscGlue3.cpp @@ -190,6 +190,17 @@ PYTHON_GLOBAL_METHOD_DEFINITION(PtFindSceneobject, args, "Params: name,ageName\n return cyMisc::FindSceneObject(plString::FromUtf8(name), ageName); } +PYTHON_GLOBAL_METHOD_DEFINITION(PtFindSceneobjects, args, "Params: name\nThis will try to find a any sceneobject containing string in name") +{ + char* name = NULL; + if (!PyArg_ParseTuple(args, "s", &name)) + { + PyErr_SetString(PyExc_TypeError, "PtFindSceneobject expects string"); + PYTHON_RETURN_ERROR; + } + return cyMisc::FindSceneObjects(plString::FromUtf8(name)); +} + PYTHON_GLOBAL_METHOD_DEFINITION(PtFindActivator, args, "Params: name\nThis will try to find an activator based on its name\n" "- it will return a ptKey if found" "- it will return None if not found") @@ -700,6 +711,7 @@ void cyMisc::AddPlasmaMethods3(std::vector &methods) PYTHON_GLOBAL_METHOD(methods, PtClearTimerCallbacks); PYTHON_GLOBAL_METHOD(methods, PtFindSceneobject); + PYTHON_GLOBAL_METHOD(methods, PtFindSceneobjects); PYTHON_GLOBAL_METHOD(methods, PtFindActivator); PYTHON_BASIC_GLOBAL_METHOD(methods, PtClearCameraStack); PYTHON_GLOBAL_METHOD(methods, PtWasLocallyNotified);