From 07ddec2f791199585d351db269bacab773517c8e Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Fri, 25 Jan 2013 22:22:49 -0500 Subject: [PATCH] Expose to python --- .../FeatureLib/pfPython/pyNetLinkingMgr.cpp | 10 ++++- .../FeatureLib/pfPython/pyNetLinkingMgr.h | 2 +- .../pfPython/pyNetLinkingMgrGlue.cpp | 10 +++-- .../plNetClient/plNetLinkingMgr.cpp | 40 ++++++++++--------- .../PubUtilLib/plNetClient/plNetLinkingMgr.h | 35 ++++++++++++---- 5 files changed, 63 insertions(+), 34 deletions(-) diff --git a/Sources/Plasma/FeatureLib/pfPython/pyNetLinkingMgr.cpp b/Sources/Plasma/FeatureLib/pfPython/pyNetLinkingMgr.cpp index f71c5b40..c8474177 100644 --- a/Sources/Plasma/FeatureLib/pfPython/pyNetLinkingMgr.cpp +++ b/Sources/Plasma/FeatureLib/pfPython/pyNetLinkingMgr.cpp @@ -65,9 +65,15 @@ void pyNetLinkingMgr::SetEnabled( bool b ) const plNetLinkingMgr::GetInstance()->SetEnabled( b ); } -void pyNetLinkingMgr::LinkToAge( pyAgeLinkStruct & link, const char* linkAnim ) +void pyNetLinkingMgr::LinkToAge( pyAgeLinkStruct & link, const char* linkAnim, bool linkInSfx, bool linkOutSfx ) { - plNetLinkingMgr::GetInstance()->LinkToAge( link.GetAgeLink(), linkAnim ); + uint32_t sfx = plNetLinkingMgr::kPlayNone; + if (linkInSfx) + hsSetBits(sfx, plNetLinkingMgr::kPlayLinkIn); + if (linkOutSfx) + hsSetBits(sfx, plNetLinkingMgr::kPlayLinkOut); + + plNetLinkingMgr::GetInstance()->LinkToAge( link.GetAgeLink(), linkAnim, (plNetLinkingMgr::LinkSfx)sfx ); } void pyNetLinkingMgr::LinkToMyPersonalAge() diff --git a/Sources/Plasma/FeatureLib/pfPython/pyNetLinkingMgr.h b/Sources/Plasma/FeatureLib/pfPython/pyNetLinkingMgr.h index 39dec4e3..c49f1aa7 100644 --- a/Sources/Plasma/FeatureLib/pfPython/pyNetLinkingMgr.h +++ b/Sources/Plasma/FeatureLib/pfPython/pyNetLinkingMgr.h @@ -80,7 +80,7 @@ public: void SetEnabled( bool b ) const; // Link to a public instance. PLS will load balance. - void LinkToAge( pyAgeLinkStruct & link, const char* linkAnim ); + void LinkToAge( pyAgeLinkStruct & link, const char* linkAnim, bool linkInSfx, bool linkOutSfx ); // Link to my Personal Age void LinkToMyPersonalAge(); // link to my personal age with the YeehsaBook diff --git a/Sources/Plasma/FeatureLib/pfPython/pyNetLinkingMgrGlue.cpp b/Sources/Plasma/FeatureLib/pfPython/pyNetLinkingMgrGlue.cpp index 775e3370..6a2ffd5a 100644 --- a/Sources/Plasma/FeatureLib/pfPython/pyNetLinkingMgrGlue.cpp +++ b/Sources/Plasma/FeatureLib/pfPython/pyNetLinkingMgrGlue.cpp @@ -79,11 +79,13 @@ PYTHON_METHOD_DEFINITION(ptNetLinkingMgr, setEnabled, args) PYTHON_RETURN_NONE; } -PYTHON_METHOD_DEFINITION(ptNetLinkingMgr, linkToAge, args) +PYTHON_METHOD_DEFINITION_WKEY(ptNetLinkingMgr, linkToAge, args, kwargs) { + char* kwlist[] = { "ageLink", "anim", "linkInSfx", "linkOutSfx", nullptr }; PyObject* ageLinkObj = NULL; char* linkAnim = NULL; - if (!PyArg_ParseTuple(args, "O|s", &ageLinkObj, &linkAnim)) + bool linkInSfx, linkOutSfx = true; + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|sbb", kwlist, &ageLinkObj, &linkAnim, &linkInSfx, &linkOutSfx)) { PyErr_SetString(PyExc_TypeError, "linkToAge expects a ptAgeLinkStruct and an optional link anim name"); PYTHON_RETURN_ERROR; @@ -94,7 +96,7 @@ PYTHON_METHOD_DEFINITION(ptNetLinkingMgr, linkToAge, args) PYTHON_RETURN_ERROR; } pyAgeLinkStruct* ageLink = pyAgeLinkStruct::ConvertFrom(ageLinkObj); - self->fThis->LinkToAge(*ageLink, linkAnim); + self->fThis->LinkToAge(*ageLink, linkAnim, linkInSfx, linkOutSfx); PYTHON_RETURN_NONE; } @@ -158,7 +160,7 @@ PYTHON_METHOD_DEFINITION_NOARGS(ptNetLinkingMgr, getPrevAgeLink) PYTHON_START_METHODS_TABLE(ptNetLinkingMgr) PYTHON_METHOD_NOARGS(ptNetLinkingMgr, isEnabled, "True if linking is enabled."), PYTHON_METHOD(ptNetLinkingMgr, setEnabled, "Params: enable\nEnable/Disable linking."), - PYTHON_METHOD(ptNetLinkingMgr, linkToAge, "Params: ageLink, linkAnim\nLinks to ageLink (ptAgeLinkStruct, string)"), + PYTHON_METHOD_WKEY(ptNetLinkingMgr, linkToAge, "Params: ageLink, linkAnim\nLinks to ageLink (ptAgeLinkStruct, string)"), PYTHON_BASIC_METHOD(ptNetLinkingMgr, linkToMyPersonalAge, "Link to my Personal Age"), PYTHON_BASIC_METHOD(ptNetLinkingMgr, linkToMyPersonalAgeWithYeeshaBook, "Link to my Personal Age with the YeeshaBook"), PYTHON_BASIC_METHOD(ptNetLinkingMgr, linkToMyNeighborhoodAge, "Link to my Neighborhood Age"), diff --git a/Sources/Plasma/PubUtilLib/plNetClient/plNetLinkingMgr.cpp b/Sources/Plasma/PubUtilLib/plNetClient/plNetLinkingMgr.cpp index 2360d3d6..69559f4a 100644 --- a/Sources/Plasma/PubUtilLib/plNetClient/plNetLinkingMgr.cpp +++ b/Sources/Plasma/PubUtilLib/plNetClient/plNetLinkingMgr.cpp @@ -547,12 +547,14 @@ bool plNetLinkingMgr::IProcessVaultNotifyMsg(plVaultNotifyMsg* msg) //////////////////////////////////////////////////////////////////// -bool plNetLinkingMgr::IDispatchMsg( plMessage * msg, uint32_t playerID ) +bool plNetLinkingMgr::IDispatchMsg( plMessage* msg, LinkSfx sfx, uint32_t playerID ) { plNetClientMgr * nc = plNetClientMgr::GetInstance(); - msg->AddReceiver( plNetClientMgr::GetInstance()->GetKey() ); + plLinkToAgeMsg* linkToAge = plLinkToAgeMsg::ConvertNoRef(msg); + if (linkToAge) + linkToAge->PlayLinkSfx(hsTestBits(sfx, kPlayLinkIn), hsTestBits(sfx, kPlayLinkOut)); if ( playerID!=kInvalidPlayerID && playerID!=nc->GetPlayerID() ) { msg->SetBCastFlag( plMessage::kNetAllowInterAge ); @@ -563,17 +565,17 @@ bool plNetLinkingMgr::IDispatchMsg( plMessage * msg, uint32_t playerID ) msg->AddNetReceiver( playerID ); } - return ( msg->Send()!=0 ); + return msg->Send(); } //////////////////////////////////////////////////////////////////// -void plNetLinkingMgr::LinkToAge( plAgeLinkStruct * link, uint32_t playerID ) +void plNetLinkingMgr::LinkToAge( plAgeLinkStruct * link, LinkSfx sfx, uint32_t playerID ) { - LinkToAge(link, nil, playerID); + LinkToAge(link, nil, sfx, playerID); } -void plNetLinkingMgr::LinkToAge( plAgeLinkStruct * link, const char* linkAnim, uint32_t playerID ) +void plNetLinkingMgr::LinkToAge( plAgeLinkStruct * link, const char* linkAnim, LinkSfx sfx, uint32_t playerID ) { if ( !fLinkingEnabled ) { @@ -584,11 +586,11 @@ void plNetLinkingMgr::LinkToAge( plAgeLinkStruct * link, const char* linkAnim, u plLinkToAgeMsg* pMsg = new plLinkToAgeMsg( link ); if (linkAnim) pMsg->SetLinkInAnimName(linkAnim); - IDispatchMsg( pMsg, playerID ); + IDispatchMsg( pMsg, sfx, playerID ); } // link myself back to my last age -void plNetLinkingMgr::LinkToPrevAge( uint32_t playerID ) +void plNetLinkingMgr::LinkToPrevAge( LinkSfx sfx, uint32_t playerID ) { if ( !fLinkingEnabled ) { @@ -599,7 +601,7 @@ void plNetLinkingMgr::LinkToPrevAge( uint32_t playerID ) if (GetPrevAgeLink()->GetAgeInfo()->HasAgeFilename()) { plLinkToAgeMsg* pMsg = new plLinkToAgeMsg( GetPrevAgeLink() ); - IDispatchMsg( pMsg, playerID ); + IDispatchMsg( pMsg, sfx, playerID ); } else { @@ -607,7 +609,7 @@ void plNetLinkingMgr::LinkToPrevAge( uint32_t playerID ) } } -void plNetLinkingMgr::LinkToMyPersonalAge( uint32_t playerID ) +void plNetLinkingMgr::LinkToMyPersonalAge( LinkSfx sfx, uint32_t playerID ) { if ( !fLinkingEnabled ) { @@ -625,10 +627,10 @@ void plNetLinkingMgr::LinkToMyPersonalAge( uint32_t playerID ) link.SetSpawnPoint(hutSpawnPoint); plLinkToAgeMsg* pMsg = new plLinkToAgeMsg( &link ); - IDispatchMsg( pMsg, playerID ); + IDispatchMsg( pMsg, sfx, playerID ); } -void plNetLinkingMgr::LinkToMyNeighborhoodAge( uint32_t playerID ) +void plNetLinkingMgr::LinkToMyNeighborhoodAge( LinkSfx sfx, uint32_t playerID ) { if ( !fLinkingEnabled ) { @@ -644,10 +646,10 @@ void plNetLinkingMgr::LinkToMyNeighborhoodAge( uint32_t playerID ) link.SetLinkingRules( plNetCommon::LinkingRules::kOwnedBook ); plLinkToAgeMsg* pMsg = new plLinkToAgeMsg( &link ); - IDispatchMsg( pMsg, playerID ); + IDispatchMsg( pMsg, sfx, playerID ); } -void plNetLinkingMgr::LinkPlayerHere( uint32_t playerID ) +void plNetLinkingMgr::LinkPlayerHere( uint32_t playerID, LinkSfx sfx ) { if ( !fLinkingEnabled ) { @@ -659,10 +661,10 @@ void plNetLinkingMgr::LinkPlayerHere( uint32_t playerID ) // send the player our current age info so they can link here. plAgeLinkStruct link; link.GetAgeInfo()->CopyFrom( GetAgeLink()->GetAgeInfo() ); - LinkPlayerToAge( &link, playerID ); + LinkPlayerToAge( &link, playerID, sfx ); } -void plNetLinkingMgr::LinkPlayerToAge( plAgeLinkStruct * link, uint32_t playerID ) +void plNetLinkingMgr::LinkPlayerToAge( plAgeLinkStruct * link, uint32_t playerID, LinkSfx sfx ) { if ( !fLinkingEnabled ) { @@ -674,7 +676,7 @@ void plNetLinkingMgr::LinkPlayerToAge( plAgeLinkStruct * link, uint32_t playerID // send the player the age link so they can link there. link->SetLinkingRules( plNetCommon::LinkingRules::kBasicLink ); plLinkToAgeMsg* pMsg = new plLinkToAgeMsg( link ); - IDispatchMsg( pMsg, playerID ); + IDispatchMsg( pMsg, sfx, playerID ); } // @@ -693,7 +695,7 @@ void plNetLinkingMgr::LinkPlayerToPrevAge( uint32_t playerID ) plLinkingMgrMsg* pMsg = new plLinkingMgrMsg(); pMsg->SetCmd( kLinkPlayerToPrevAge); - IDispatchMsg( pMsg, playerID ); + IDispatchMsg( pMsg, kPlayBoth, playerID ); } void plNetLinkingMgr::LinkToPlayersAge( uint32_t playerID ) @@ -709,7 +711,7 @@ void plNetLinkingMgr::LinkToPlayersAge( uint32_t playerID ) plLinkingMgrMsg* pMsg = new plLinkingMgrMsg(); pMsg->SetCmd( kLinkPlayerHere ); pMsg->GetArgs()->AddInt( 0, NetCommGetPlayer()->playerInt ); // send them our id. - IDispatchMsg( pMsg, playerID ); + IDispatchMsg( pMsg, kPlayBoth, playerID ); } //////////////////////////////////////////////////////////////////// diff --git a/Sources/Plasma/PubUtilLib/plNetClient/plNetLinkingMgr.h b/Sources/Plasma/PubUtilLib/plNetClient/plNetLinkingMgr.h index e0322c1d..490f20f8 100644 --- a/Sources/Plasma/PubUtilLib/plNetClient/plNetLinkingMgr.h +++ b/Sources/Plasma/PubUtilLib/plNetClient/plNetLinkingMgr.h @@ -55,6 +55,16 @@ struct plNCAgeLeaver; class plNetLinkingMgr { +public: + enum LinkSfx + { + kPlayNone = 0, + kPlayLinkIn = 1<<0, + kPlayLinkOut = 1<<1, + kPlayBoth = (kPlayLinkIn | kPlayLinkOut) + }; + +private: static void NCAgeJoinerCallback ( plNCAgeJoiner * joiner, unsigned type, @@ -110,7 +120,7 @@ class plNetLinkingMgr void IDoLink(plLinkToAgeMsg* link); bool IProcessVaultNotifyMsg(plVaultNotifyMsg* msg); - bool IDispatchMsg( plMessage * msg, uint32_t playerID ); + bool IDispatchMsg( plMessage* msg, LinkSfx sfx, uint32_t playerID ); public: @@ -125,26 +135,35 @@ public: bool Linking () const { return !fLinkedIn && !fLinkingEnabled; } // Link to an age. - void LinkToAge( plAgeLinkStruct * link, uint32_t playerID=kInvalidPlayerID ); - void LinkToAge( plAgeLinkStruct * link, const char* linkAnim, uint32_t playerID=kInvalidPlayerID ); + void LinkToAge( plAgeLinkStruct * link, LinkSfx sfx=kPlayBoth, uint32_t playerID=kInvalidPlayerID ); + void LinkToAge( plAgeLinkStruct * link, const char* linkAnim, LinkSfx sfx=kPlayBoth, uint32_t playerID=kInvalidPlayerID ); + // Link to my last age. - void LinkToPrevAge( uint32_t playerID=kInvalidPlayerID ); + void LinkToPrevAge( LinkSfx sfx=kPlayBoth, uint32_t playerID=kInvalidPlayerID ); + // Link to my Personal Age - void LinkToMyPersonalAge( uint32_t playerID=kInvalidPlayerID ); + void LinkToMyPersonalAge( LinkSfx sfx=kPlayBoth, uint32_t playerID=kInvalidPlayerID ); + // Link to my Neighborhood Age - void LinkToMyNeighborhoodAge( uint32_t playerID=kInvalidPlayerID ); + void LinkToMyNeighborhoodAge( LinkSfx sfx=kPlayBoth, uint32_t playerID=kInvalidPlayerID ); + // Link a player here. - void LinkPlayerHere( uint32_t playerID ); + void LinkPlayerHere( uint32_t playerID, LinkSfx sfx=kPlayBoth ); + // Link player to specified age - void LinkPlayerToAge( plAgeLinkStruct * link, uint32_t playerID ); + void LinkPlayerToAge( plAgeLinkStruct * link, uint32_t playerID, LinkSfx sfx=kPlayBoth ); + // Link player back to his last age void LinkPlayerToPrevAge( uint32_t playerID ); + // Link us to a players age. void LinkToPlayersAge( uint32_t playerID ); + // Offer a link to player. void OfferLinkToPlayer( const plAgeLinkStruct * info, uint32_t playerID, plKey replyKey ); void OfferLinkToPlayer( const plAgeInfoStruct * info, uint32_t playerID ); void OfferLinkToPlayer( const plAgeLinkStruct * info, uint32_t playerID ); + // Leave the current age void LeaveAge (bool quitting);