diff --git a/Sources/Plasma/FeatureLib/pfPython/CMakeLists.txt b/Sources/Plasma/FeatureLib/pfPython/CMakeLists.txt index b390708f..e0881746 100644 --- a/Sources/Plasma/FeatureLib/pfPython/CMakeLists.txt +++ b/Sources/Plasma/FeatureLib/pfPython/CMakeLists.txt @@ -37,6 +37,7 @@ set(pfPython_SOURCES pyDynamicText.cpp pyEnum.cpp pyGameScore.cpp + pyGameScoreMsg.cpp pyGeometry3.cpp pyGlueHelpers.cpp pyGrassShader.cpp @@ -68,7 +69,6 @@ set(pfPython_SOURCES pyNotify.cpp pyPlayer.cpp pySceneObject.cpp - pyScoreMgr.cpp pySDL.cpp pySpawnPointInfo.cpp pyStatusLog.cpp @@ -125,6 +125,7 @@ set(pfPython_HEADERS pyDynamicText.h pyEnum.h pyGameScore.h + pyGameScoreMsg.h pyGeometry3.h pyGrassShader.h pyGUIControl.h @@ -155,7 +156,6 @@ set(pfPython_HEADERS pyNotify.h pyPlayer.h pySceneObject.h - pyScoreMgr.h pySDL.h pySpawnPointInfo.h pyStatusLog.h @@ -208,6 +208,7 @@ set(pfPython_GLUE pyDrawControlGlue.cpp pyDynamicTextGlue.cpp pyGameScoreGlue.cpp + pyGameScoreMsgGlue.cpp pyGeometry3Glue.cpp pyGlueHelpers.h pyGrassShaderGlue.cpp @@ -239,7 +240,6 @@ set(pfPython_GLUE pyNotifyGlue.cpp pyPlayerGlue.cpp pySceneObjectGlue.cpp - pyScoreMgrGlue.cpp pySDLGlue.cpp pySpawnPointInfoGlue.cpp pyStatusLogGlue.cpp diff --git a/Sources/Plasma/FeatureLib/pfPython/cyPythonInterface.cpp b/Sources/Plasma/FeatureLib/pfPython/cyPythonInterface.cpp index a5fcf5f7..045eaee8 100644 --- a/Sources/Plasma/FeatureLib/pfPython/cyPythonInterface.cpp +++ b/Sources/Plasma/FeatureLib/pfPython/cyPythonInterface.cpp @@ -154,8 +154,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "pyCluster.h" #include "pyGrassShader.h" -#include "pyScoreMgr.h" #include "pyGameScore.h" +#include "pyGameScoreMsg.h" #include "pyCritterBrain.h" @@ -1494,13 +1494,16 @@ void PythonInterface::AddPlasmaClasses() // Shaders pyGrassShader::AddPlasmaClasses(plasmaMod); - // Game Scores - pyScoreMgr::AddPlasmaClasses(plasmaMod); - pyGameScore::AddPlasmaClasses(plasmaMod); - // AI pyCritterBrain::AddPlasmaClasses(plasmaMod); + // Game Scores + pyGameScore::AddPlasmaClasses(plasmaMod); + pyGameScoreMsg::AddPlasmaClasses(plasmaMod); + pyGameScoreListMsg::AddPlasmaClasses(plasmaMod); + pyGameScoreTransferMsg::AddPlasmaClasses(plasmaMod); + pyGameScoreUpdateMsg::AddPlasmaClasses(plasmaMod); + // Stupid thing ptImportHook_AddPlasmaClasses(plasmaMod); } @@ -1523,6 +1526,7 @@ void PythonInterface::AddPlasmaConstantsClasses() //pyDrawControl::AddPlasmaConstantsClasses(plasmaConstantsMod); pyDynamicText::AddPlasmaConstantsClasses(plasmaConstantsMod); + pyGameScore::AddPlasmaConstantsClasses(plasmaConstantsMod); pyGUIControlButton::AddPlasmaConstantsClasses(plasmaConstantsMod); pyGUIControlMultiLineEdit::AddPlasmaConstantsClasses(plasmaConstantsMod); pyJournalBook::AddPlasmaConstantsClasses(plasmaConstantsMod); @@ -1531,7 +1535,6 @@ void PythonInterface::AddPlasmaConstantsClasses() pyNotify::AddPlasmaConstantsClasses(plasmaConstantsMod); pySDL::AddPlasmaConstantsClasses(plasmaConstantsMod); pyStatusLog::AddPlasmaConstantsClasses(plasmaConstantsMod); - pyScoreMgr::AddPlasmaConstantsClasses(plasmaConstantsMod); pyAIMsg::AddPlasmaConstantsClasses(plasmaConstantsMod); diff --git a/Sources/Plasma/FeatureLib/pfPython/plPythonFileMod.cpp b/Sources/Plasma/FeatureLib/pfPython/plPythonFileMod.cpp index c658cf2a..0c54f2f1 100644 --- a/Sources/Plasma/FeatureLib/pfPython/plPythonFileMod.cpp +++ b/Sources/Plasma/FeatureLib/pfPython/plPythonFileMod.cpp @@ -95,6 +95,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "pfGameMgr/pfGameMgr.h" #include "plMessage/plAIMsg.h" #include "plAvatar/plAvBrainCritter.h" +#include "pfMessage/pfGameScoreMsg.h" #include "plProfile.h" @@ -136,6 +137,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com // Game manager #include "Games/pyGameMgrMsg.h" #include "Games/pyGameCliMsg.h" +#include "pyGameScoreMsg.h" #include @@ -189,6 +191,7 @@ const char* plPythonFileMod::fFunctionNames[] = "OnGameMgrMsg", // kfunc_OnGameMgrMsg "OnGameCliMsg", // kfunc_OnGameCliMsg "OnAIMsg", // kfunc_OnAIMsg + "OnGameScoreMsg", // kfunc_OnGameScoreMsg nil }; @@ -2821,6 +2824,36 @@ hsBool plPythonFileMod::MsgReceive(plMessage* msg) } } + if (fPyFunctionInstances[kfunc_OnGameScoreMsg]) + { + pfGameScoreMsg* pScoreMsg = pfGameScoreMsg::ConvertNoRef(msg); + if (pScoreMsg) + { + plProfile_BeginTiming(PythonUpdate); + + // Creates the final ptGameScoreMsg and ships it off to OnGameScoreMsg + PyObject* pyMsg = pyGameScoreMsg::CreateFinal(pScoreMsg); + PyObject* retVal = PyObject_CallMethod( + fPyFunctionInstances[kfunc_OnGameScoreMsg], + (char*)fFunctionNames[kfunc_OnGameScoreMsg], + "O", pyMsg + ); + Py_DECREF(pyMsg); + + if (retVal == nil) + { +#ifndef PLASMA_EXTERNAL_RELEASE + // for some reason this function didn't, remember that and not call it again + fPyFunctionInstances[kfunc_OnGameScoreMsg] = nil; +#endif //PLASMA_EXTERNAL_RELEASE + // if there was an error make sure that the stderr gets flushed so it can be seen + ReportError(); + } + plProfile_EndTiming(PythonUpdate); + return true; + } + } + return plModifier::MsgReceive(msg); } diff --git a/Sources/Plasma/FeatureLib/pfPython/plPythonFileMod.h b/Sources/Plasma/FeatureLib/pfPython/plPythonFileMod.h index aeeb6f82..bb7ed26d 100644 --- a/Sources/Plasma/FeatureLib/pfPython/plPythonFileMod.h +++ b/Sources/Plasma/FeatureLib/pfPython/plPythonFileMod.h @@ -202,6 +202,7 @@ public: kfunc_OnGameMgrMsg, kfunc_OnGameCliMsg, kfunc_OnAIMsg, + kfunc_OnGameScoreMsg, kfunc_lastone }; // array of matching Python instance where the functions are, if defined diff --git a/Sources/Plasma/FeatureLib/pfPython/pyGameScore.cpp b/Sources/Plasma/FeatureLib/pfPython/pyGameScore.cpp index c454a589..50e4c413 100644 --- a/Sources/Plasma/FeatureLib/pfPython/pyGameScore.cpp +++ b/Sources/Plasma/FeatureLib/pfPython/pyGameScore.cpp @@ -40,98 +40,147 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com *==LICENSE==*/ #include "pyGameScore.h" - #include "pfGameScoreMgr/pfGameScoreMgr.h" +#include "pyKey.h" +#include "plVault/plVault.h" -pyGameScore::pyGameScore() : fScore(nil) -{ -} +pyGameScore::pyGameScore() + : fScore(nil) +{ } -pyGameScore::pyGameScore(pfGameScore * score) : fScore(score) +pyGameScore::pyGameScore(pfGameScore * score) + : fScore(score) { - fScore->IncRef(); + hsRefCnt_SafeRef(score); } pyGameScore::~pyGameScore() { - if (fScore) - fScore->DecRef(); + hsRefCnt_SafeUnRef(fScore); } -int pyGameScore::GetScoreID() +uint32_t pyGameScore::GetOwnerID() const { if (fScore) - return fScore->scoreId; - + return fScore->GetOwner(); return 0; } -uint32_t pyGameScore::GetCreatedTime() +int32_t pyGameScore::GetGameType() const { if (fScore) - return fScore->createdTime; - + return fScore->GetGameType(); return 0; } -int pyGameScore::GetOwnerID() +int32_t pyGameScore::GetPoints() const { if (fScore) - return fScore->ownerId; - + return fScore->GetPoints(); return 0; } -int pyGameScore::GetGameType() +plString pyGameScore::GetGameName() const { if (fScore) - return fScore->gameType; - - return 0; + return fScore->GetGameName(); + return plString::Null; } -int pyGameScore::GetValue() +void pyGameScore::AddPoints(int32_t numPoints, pyKey& rcvr) { if (fScore) - return fScore->value; - - return 0; + fScore->AddPoints(numPoints, rcvr.getKey()); } -const char* pyGameScore::GetGameName() +void pyGameScore::Delete() { if (fScore) - return fScore->gameName; + { + fScore->Delete(); + fScore = nil; + } +} - return ""; +void pyGameScore::TransferPoints(pyGameScore* dest, pyKey& rcvr) +{ + if (fScore && dest->fScore) + fScore->TransferPoints(dest->fScore, rcvr.getKey()); } -bool pyGameScore::AddPoints(int numPoints) +void pyGameScore::TransferPoints(pyGameScore* dest, int32_t numPoints, pyKey& rcvr) { - ENetError result = kNetErrScoreWrongType; + if (fScore && dest->fScore) + fScore->TransferPoints(dest->fScore, numPoints, rcvr.getKey()); +} - if (fScore && fScore->gameType != kScoreTypeFixed) - result = pfGameScoreMgr::GetInstance()->AddPoints(fScore->scoreId, numPoints); +void pyGameScore::SetPoints(int32_t numPoints, pyKey& rcvr) +{ + if (fScore) + fScore->SetPoints(numPoints, rcvr.getKey()); +} - return IS_NET_SUCCESS(result); +void pyGameScore::CreateAgeScore(const plString& name, uint32_t type, int32_t points, pyKey& rcvr) +{ + if (RelVaultNode* ageInfo = VaultGetAgeInfoNodeIncRef()) + { + uint32_t ownerId = ageInfo->nodeId; + pfGameScore::Create(ownerId, name, type, points, rcvr.getKey()); + ageInfo->DecRef(); + } else + hsAssert(false, "Age has no vault... Need to rewrite score python script?"); } -bool pyGameScore::TransferPoints(unsigned destination, int numPoints) +void pyGameScore::CreateGlobalScore(const plString& name, uint32_t type, int32_t points, pyKey& rcvr) { - ENetError result = kNetErrScoreWrongType; + pfGameScore::Create(0, name, type, points, rcvr.getKey()); +} + +void pyGameScore::CreatePlayerScore(const plString& name, uint32_t type, int32_t points, pyKey& rcvr) +{ + if (RelVaultNode* node = VaultGetPlayerInfoNodeIncRef()) + { + uint32_t ownerId = node->nodeId; + pfGameScore::Create(ownerId, name, type, points, rcvr.getKey()); + node->DecRef(); + } else + hsAssert(false, "No PlayerInfo node... Need to rewrite python script?"); +} - if (fScore && fScore->gameType != kScoreTypeFixed) - result = pfGameScoreMgr::GetInstance()->TransferPoints(fScore->scoreId, destination, numPoints); +void pyGameScore::CreateScore(uint32_t ownerId, const plString& name, uint32_t type, int32_t points, pyKey& rcvr) +{ + pfGameScore::Create(ownerId, name, type, points, rcvr.getKey()); +} - return IS_NET_SUCCESS(result); +void pyGameScore::FindAgeScores(const plString& name, pyKey& rcvr) +{ + if (RelVaultNode* ageInfo = VaultGetAgeInfoNodeIncRef()) + { + uint32_t ownerId = ageInfo->nodeId; + pfGameScore::Find(ownerId, name, rcvr.getKey()); + ageInfo->DecRef(); + } else + hsAssert(false, "Age has no vault... Need to rewrite score python script?"); } -bool pyGameScore::SetPoints(int numPoints) +void pyGameScore::FindGlobalScores(const plString& name, pyKey& rcvr) { - ENetError result = kNetErrScoreWrongType; + pfGameScore::Find(0, name, rcvr.getKey()); +} - if (fScore && fScore->gameType != kScoreTypeFixed) - result = pfGameScoreMgr::GetInstance()->SetPoints(fScore->scoreId, numPoints); +void pyGameScore::FindPlayerScores(const plString& name, pyKey& rcvr) +{ + if (RelVaultNode* node = VaultGetPlayerInfoNodeIncRef()) + { + uint32_t ownerId = node->nodeId; + pfGameScore::Find(ownerId, name, rcvr.getKey()); + node->DecRef(); + } + else + hsAssert(false, "No PlayerInfo node.. Need to rewrite python script?"); +} - return IS_NET_SUCCESS(result); +void pyGameScore::FindScores(uint32_t ownerId, const plString& name, pyKey& rcvr) +{ + pfGameScore::Find(ownerId, name, rcvr.getKey()); } diff --git a/Sources/Plasma/FeatureLib/pfPython/pyGameScore.h b/Sources/Plasma/FeatureLib/pfPython/pyGameScore.h index bf0bca76..42becdb4 100644 --- a/Sources/Plasma/FeatureLib/pfPython/pyGameScore.h +++ b/Sources/Plasma/FeatureLib/pfPython/pyGameScore.h @@ -39,8 +39,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com Mead, WA 99021 *==LICENSE==*/ -#ifndef pyGameScore_h -#define pyGameScore_h +#ifndef _pyGameScore_h_ +#define _pyGameScore_h_ ///////////////////////////////////////////////////////////////////////////// // @@ -52,10 +52,12 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include #include "HeadSpin.h" #include "hsStlUtils.h" +#include "plString.h" #include "pyGlueHelpers.h" -struct pfGameScore; +class pfGameScore; +class pyKey; class pyGameScore { @@ -74,17 +76,28 @@ public: PYTHON_CLASS_CONVERT_FROM_DEFINITION(pyGameScore); // converts a PyObject to a pyGameScore (throws error if not correct type) static void AddPlasmaClasses(PyObject *m); - - int GetScoreID(); - uint32_t GetCreatedTime(); - int GetOwnerID(); - int GetGameType(); - int GetValue(); - const char* GetGameName(); - - bool AddPoints(int numPoints); - bool TransferPoints(unsigned destination, int numPoints); - bool SetPoints(int numPoints); + static void AddPlasmaConstantsClasses(PyObject *m); + + uint32_t GetOwnerID() const; + int32_t GetGameType() const; + int32_t GetPoints() const; + plString GetGameName() const; + + void AddPoints(int32_t numPoints, pyKey& rcvr); + void Delete(); + void TransferPoints(pyGameScore* dest, pyKey& rcvr); + void TransferPoints(pyGameScore* dest, int32_t numPoints, pyKey& rcvr); + void SetPoints(int32_t numPoints, pyKey& rcvr); + + static void CreateAgeScore(const plString& name, uint32_t type, int32_t points, pyKey& rcvr); + static void CreateGlobalScore(const plString& name, uint32_t type, int32_t points, pyKey& rcvr); + static void CreatePlayerScore(const plString& name, uint32_t type, int32_t points, pyKey& rcvr); + static void CreateScore(uint32_t ownerId, const plString& name, uint32_t type, int32_t points, pyKey& rcvr); + + static void FindAgeScores(const plString& name, pyKey& rcvr); + static void FindGlobalScores(const plString& name, pyKey& rcvr); + static void FindPlayerScores(const plString& name, pyKey& rcvr); + static void FindScores(uint32_t ownerId, const plString& name, pyKey& rcvr); }; #endif diff --git a/Sources/Plasma/FeatureLib/pfPython/pyGameScoreGlue.cpp b/Sources/Plasma/FeatureLib/pfPython/pyGameScoreGlue.cpp index 1bfa4e0c..6157efaa 100644 --- a/Sources/Plasma/FeatureLib/pfPython/pyGameScoreGlue.cpp +++ b/Sources/Plasma/FeatureLib/pfPython/pyGameScoreGlue.cpp @@ -40,8 +40,9 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com *==LICENSE==*/ #include "pyGameScore.h" - +#include "pyEnum.h" #include "pfGameScoreMgr/pfGameScoreMgr.h" +#include "pyKey.h" // glue functions PYTHON_CLASS_DEFINITION(ptGameScore, pyGameScore); @@ -51,97 +52,309 @@ PYTHON_DEFAULT_DEALLOC_DEFINITION(ptGameScore) PYTHON_NO_INIT_DEFINITION(ptGameScore) -PYTHON_METHOD_DEFINITION_NOARGS(ptGameScore, getScoreID) +PYTHON_METHOD_DEFINITION_NOARGS(ptGameScore, getOwnerID) { - return PyInt_FromLong(self->fThis->GetScoreID()); + return PyLong_FromLong(self->fThis->GetOwnerID()); } -PYTHON_METHOD_DEFINITION_NOARGS(ptGameScore, getCreatedTime) +PYTHON_METHOD_DEFINITION_NOARGS(ptGameScore, getPoints) { - return PyLong_FromUnsignedLong(self->fThis->GetCreatedTime()); + return PyLong_FromLong(self->fThis->GetPoints()); } -PYTHON_METHOD_DEFINITION_NOARGS(ptGameScore, getOwnerID) +PYTHON_METHOD_DEFINITION_NOARGS(ptGameScore, getGameType) { - return PyInt_FromLong(self->fThis->GetOwnerID()); + return PyInt_FromLong(self->fThis->GetGameType()); } -PYTHON_METHOD_DEFINITION_NOARGS(ptGameScore, getValue) +PYTHON_METHOD_DEFINITION_NOARGS(ptGameScore, getName) { - return PyInt_FromLong(self->fThis->GetValue()); + return PyUnicode_FromStringEx(self->fThis->GetGameName()); } -PYTHON_METHOD_DEFINITION_NOARGS(ptGameScore, getGameType) +PYTHON_METHOD_DEFINITION_NOARGS(ptGameScore, remove) { - return PyInt_FromLong(self->fThis->GetGameType()); + self->fThis->Delete(); + PYTHON_RETURN_NONE; // who cares about a result? } -PYTHON_METHOD_DEFINITION_NOARGS(ptGameScore, getGameName) +PYTHON_METHOD_DEFINITION(ptGameScore, addPoints, args) { - return PyString_FromString(self->fThis->GetGameName()); + int32_t numPoints = 0; + PyObject* keyObj = nil; + if (!PyArg_ParseTuple(args, "i|O", &numPoints, &keyObj)) + { + PyErr_SetString(PyExc_TypeError, "addPoints expects an int and an optional key"); + PYTHON_RETURN_ERROR; + } + if (!pyKey::Check(keyObj)) + { + PyErr_SetString(PyExc_TypeError, "addPoints expects an int and an optional key"); + PYTHON_RETURN_ERROR; + } + + pyKey* rcvr = pyKey::ConvertFrom(keyObj); + self->fThis->AddPoints(numPoints, *rcvr); + PYTHON_RETURN_NONE; // get result in callback } -PYTHON_METHOD_DEFINITION(ptGameScore, addPoints, args) +PYTHON_METHOD_DEFINITION_WKEY(ptGameScore, transferPoints, args, kwargs) { - int numPoints = 0; - if (!PyArg_ParseTuple(args, "i", &numPoints)) + char* kwlist[] = { "dest", "points", "key", nil }; + PyObject* destObj = nil; + int32_t points = 0; // Hmmm... Evil? + PyObject* keyObj = nil; + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|iO", kwlist, &destObj, &points, &keyObj)) { - PyErr_SetString(PyExc_TypeError, "addPoints expects an int"); + PyErr_SetString(PyExc_TypeError, "transferPoints expects a ptGameScore, an optional int, and an optional ptKey"); + PYTHON_RETURN_ERROR; + } + if (!(pyGameScore::Check(destObj) && pyKey::Check(keyObj))) + { + PyErr_SetString(PyExc_TypeError, "transferPoints expects a ptGameScore, an optional int, and an optional ptKey"); PYTHON_RETURN_ERROR; } - PYTHON_RETURN_BOOL(self->fThis->AddPoints(numPoints)); + pyGameScore* dest = pyGameScore::ConvertFrom(destObj); + pyKey* rcvr = pyKey::ConvertFrom(keyObj); + if (points) + self->fThis->TransferPoints(dest, points, *rcvr); + else + self->fThis->TransferPoints(dest, *rcvr); + PYTHON_RETURN_NONE; // get result in callback } -PYTHON_METHOD_DEFINITION(ptGameScore, transferPoints, args) +PYTHON_METHOD_DEFINITION(ptGameScore, setPoints, args) { - unsigned destination = 0; - int numPoints = 0; - if (!PyArg_ParseTuple(args, "Ii", &destination, &numPoints)) + int32_t numPoints = 0; + PyObject* keyObj = nil; + if (!PyArg_ParseTuple(args, "i|O", &numPoints)) { - PyErr_SetString(PyExc_TypeError, "transferPoints expects an unsigned int and an int"); + PyErr_SetString(PyExc_TypeError, "setPoints expects an int and an optional ptKey"); + PYTHON_RETURN_ERROR; + } + if (!pyKey::Check(keyObj)) + { + PyErr_SetString(PyExc_TypeError, "setPoints expects an int and an optional ptKey"); PYTHON_RETURN_ERROR; } - PYTHON_RETURN_BOOL(self->fThis->TransferPoints(destination, numPoints)); + pyKey* rcvr = pyKey::ConvertFrom(keyObj); + self->fThis->SetPoints(numPoints, *rcvr); + PYTHON_RETURN_NONE; // get result in callback } -PYTHON_METHOD_DEFINITION(ptGameScore, setPoints, args) +PYTHON_METHOD_DEFINITION_STATIC_WKEY(ptGameScore, createAgeScore, args, kwargs) +{ + char* kwlist[] = { "scoreName", "type", "points", "key", nil }; + PyObject* nameObj = nil; + uint32_t type = 0; + int32_t points = 0; + PyObject* keyObj = nil; + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OI|iO", kwlist, &nameObj, &type, &points, &keyObj)) + { + PyErr_SetString(PyExc_TypeError, "createAgeScore expects a string, an int, an optional int, and an optional ptKey"); + PYTHON_RETURN_ERROR; + } + if (!(PyString_CheckEx(nameObj) && pyKey::Check(keyObj))) + { + PyErr_SetString(PyExc_TypeError, "createAgeScore expects a string, an int, an optional int, and an optional ptKey"); + PYTHON_RETURN_ERROR; + } + + plString name = PyString_AsStringEx(nameObj); + pyKey* rcvr = pyKey::ConvertFrom(keyObj); + pyGameScore::CreateAgeScore(name, type, points, *rcvr); + PYTHON_RETURN_NONE; // get result in callback +} + +PYTHON_METHOD_DEFINITION_STATIC_WKEY(ptGameScore, createGlobalScore, args, kwargs) +{ + char* kwlist[] = { "scoreName", "type", "points", "key", nil }; + PyObject* nameObj = nil; + uint32_t type = 0; + int32_t points = 0; + PyObject* keyObj = nil; + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OI|iO", kwlist, &nameObj, &type, &points, &keyObj)) + { + PyErr_SetString(PyExc_TypeError, "createGlobalScore expects a string, an int, an optional int, and an optional ptKey"); + PYTHON_RETURN_ERROR; + } + if (!(PyString_CheckEx(nameObj) && pyKey::Check(keyObj))) + { + PyErr_SetString(PyExc_TypeError, "createGlobalScore expects a string, an int, an optional int, and an optional ptKey"); + PYTHON_RETURN_ERROR; + } + + plString name = PyString_AsStringEx(nameObj); + pyKey* rcvr = pyKey::ConvertFrom(keyObj); + pyGameScore::CreateGlobalScore(name, type, points, *rcvr); + PYTHON_RETURN_NONE; // get result in callback +} + +PYTHON_METHOD_DEFINITION_STATIC_WKEY(ptGameScore, createPlayerScore, args, kwargs) +{ + char* kwlist[] = { "scoreName", "type", "points", "key", nil }; + PyObject* nameObj = nil; + uint32_t type = 0; + int32_t points = 0; + PyObject* keyObj = nil; + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OI|iO", kwlist, &nameObj, &type, &points, &keyObj)) + { + PyErr_SetString(PyExc_TypeError, "createPlayerScore expects a string, an int, an optional int, and an optional ptKey"); + PYTHON_RETURN_ERROR; + } + if (!(PyString_CheckEx(nameObj) && pyKey::Check(keyObj))) + { + PyErr_SetString(PyExc_TypeError, "createPlayerScore expects a string, an int, an optional int, and an optional ptKey"); + PYTHON_RETURN_ERROR; + } + + plString name = PyString_AsStringEx(nameObj); + pyKey* rcvr = pyKey::ConvertFrom(keyObj); + pyGameScore::CreatePlayerScore(name, type, points, *rcvr); + PYTHON_RETURN_NONE; // get result in callback +} + +PYTHON_METHOD_DEFINITION_STATIC_WKEY(ptGameScore, createScore, args, kwargs) +{ + char* kwlist[] = { "ownerID", "scoreName", "type", "points", "key", nil }; + uint32_t ownerID = 0; + PyObject* nameObj = nil; + uint32_t type = 0; + int32_t points = 0; + PyObject* keyObj = nil; + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "IOI|iO", kwlist, &ownerID, &nameObj, &type, &points, &keyObj)) + { + PyErr_SetString(PyExc_TypeError, "createScore expects an int, a string, an int, an optional int, and an optional ptKey"); + PYTHON_RETURN_ERROR; + } + if (!(PyString_CheckEx(nameObj) && pyKey::Check(keyObj))) + { + PyErr_SetString(PyExc_TypeError, "createScore expects an int, a string, an int, an optional int, and an optional ptKey"); + PYTHON_RETURN_ERROR; + } + + plString name = PyString_AsStringEx(nameObj); + pyKey* rcvr = pyKey::ConvertFrom(keyObj); + pyGameScore::CreateScore(ownerID, name, type, points, *rcvr); + PYTHON_RETURN_NONE; // get result in callback +} + +PYTHON_METHOD_DEFINITION_STATIC(ptGameScore, findAgeScores, args) { - int numPoints = 0; - if (!PyArg_ParseTuple(args, "i", &numPoints)) + PyObject* nameObj = nil; + PyObject* keyObj = nil; + if (!PyArg_ParseTuple(args, "OO", &nameObj, &keyObj)) + { + PyErr_SetString(PyExc_TypeError, "findAgeScores expects a string and a ptKey"); + PYTHON_RETURN_ERROR; + } + if (!(PyString_CheckEx(nameObj) && pyKey::Check(keyObj))) + { + PyErr_SetString(PyExc_TypeError, "findAgeScores expects a string and a ptKey"); + PYTHON_RETURN_ERROR; + } + + plString name = PyString_AsStringEx(nameObj); + pyKey* rcvr = pyKey::ConvertFrom(keyObj); + pyGameScore::FindAgeScores(name, *rcvr); + PYTHON_RETURN_NONE; // get result in callback +} + +PYTHON_METHOD_DEFINITION_STATIC(ptGameScore, findGlobalScores, args) +{ + PyObject* nameObj = nil; + PyObject* keyObj = nil; + if (!PyArg_ParseTuple(args, "OO", &nameObj, &keyObj)) + { + PyErr_SetString(PyExc_TypeError, "findGlobalScores expects a string and a ptKey"); + PYTHON_RETURN_ERROR; + } + if (!(PyString_CheckEx(nameObj) && pyKey::Check(keyObj))) { - PyErr_SetString(PyExc_TypeError, "setPoints expects an int"); + PyErr_SetString(PyExc_TypeError, "findGlobalScores expects a string and a ptKey"); PYTHON_RETURN_ERROR; } - PYTHON_RETURN_BOOL(self->fThis->SetPoints(numPoints)); + plString name = PyString_AsStringEx(nameObj); + pyKey* rcvr = pyKey::ConvertFrom(keyObj); + pyGameScore::FindGlobalScores(name, *rcvr); + PYTHON_RETURN_NONE; // get result in callback +} + +PYTHON_METHOD_DEFINITION_STATIC(ptGameScore, findPlayerScores, args) +{ + PyObject* nameObj = nil; + PyObject* keyObj = nil; + if (!PyArg_ParseTuple(args, "OO", &nameObj, &keyObj)) + { + PyErr_SetString(PyExc_TypeError, "findPlayerScores expects a string and a ptKey"); + PYTHON_RETURN_ERROR; + } + if (!(PyString_CheckEx(nameObj) && pyKey::Check(keyObj))) + { + PyErr_SetString(PyExc_TypeError, "findPlayerScores expects a string and a ptKey"); + PYTHON_RETURN_ERROR; + } + + plString name = PyString_AsStringEx(nameObj); + pyKey* rcvr = pyKey::ConvertFrom(keyObj); + pyGameScore::FindPlayerScores(name, *rcvr); + PYTHON_RETURN_NONE; // get result in callback +} + +PYTHON_METHOD_DEFINITION_STATIC(ptGameScore, findScores, args) +{ + uint32_t ownerId = 0; + PyObject* nameObj = nil; + PyObject* keyObj = nil; + if (!PyArg_ParseTuple(args, "IOO", &ownerId, &nameObj, &keyObj)) + { + PyErr_SetString(PyExc_TypeError, "findScore expects an int, a string, and a ptKey"); + PYTHON_RETURN_ERROR; + } + if (!(PyString_CheckEx(nameObj) && pyKey::Check(keyObj))) + { + PyErr_SetString(PyExc_TypeError, "findScore expects an int, a string, and a ptKey"); + PYTHON_RETURN_ERROR; + } + + plString name = PyString_AsStringEx(nameObj); + pyKey* rcvr = pyKey::ConvertFrom(keyObj); + pyGameScore::FindScores(ownerId, name, *rcvr); + PYTHON_RETURN_NONE; // get result in callback } PYTHON_START_METHODS_TABLE(ptGameScore) - PYTHON_METHOD_NOARGS(ptGameScore, getScoreID, "Returns the score id."), - PYTHON_METHOD_NOARGS(ptGameScore, getOwnerID, "Returns a the score owner id."), - PYTHON_METHOD_NOARGS(ptGameScore, getCreatedTime, "Returns a the score creation time."), - PYTHON_METHOD_NOARGS(ptGameScore, getValue, "Returns a the score owner value."), - PYTHON_METHOD_NOARGS(ptGameScore, getGameType, "Returns a the score game type."), - PYTHON_METHOD_NOARGS(ptGameScore, getGameName, "Returns a the score game name."), - PYTHON_METHOD(ptGameScore, addPoints, "Params: numPoints\nAdds points to the score"), - PYTHON_METHOD(ptGameScore, transferPoints, "Params: dest, numPoints\nTransfers points from one score to another"), - PYTHON_METHOD(ptGameScore, setPoints, "Params: numPoints\nSets the number of points in the score\nDon't use to add/remove points, use only to reset values!"), + PYTHON_METHOD_NOARGS(ptGameScore, getGameType, "Returns the score game type."), + PYTHON_METHOD_NOARGS(ptGameScore, getName, "Returns the score game name."), + PYTHON_METHOD_NOARGS(ptGameScore, getOwnerID, "Returns the score owner."), + PYTHON_METHOD_NOARGS(ptGameScore, getPoints, "Returns the number of points in this score"), + PYTHON_METHOD_NOARGS(ptGameScore, remove, "Removes this score from the server"), + PYTHON_METHOD(ptGameScore, addPoints, "Params: points, key\nAdds points to the score"), + PYTHON_METHOD_WKEY(ptGameScore, transferPoints, "Params: dest, points, key\nTransfers points from this score to another"), + PYTHON_METHOD(ptGameScore, setPoints, "Params: numPoints, key\nSets the number of points in the score\nDon't use to add/remove points, use only to reset values!"), + PYTHON_METHOD_STATIC_WKEY(ptGameScore, createAgeScore, "Params: scoreName, type, points, key\nCreates a new score associated with this age"), + PYTHON_METHOD_STATIC_WKEY(ptGameScore, createGlobalScore, "Params: scoreName, type, points, key\nCreates a new global score"), + PYTHON_METHOD_STATIC_WKEY(ptGameScore, createPlayerScore, "Params: scoreName, type, points, key\nCreates a new score associated with this player"), + PYTHON_METHOD_STATIC_WKEY(ptGameScore, createScore, "Params: ownerID, scoreName, type, points, key\nCreates a new score for an arbitrary owner"), + PYTHON_METHOD_STATIC(ptGameScore, findAgeScores, "Params: scoreName, key\nFinds matching scores for this age"), + PYTHON_METHOD_STATIC(ptGameScore, findGlobalScores, "Params: scoreName, key\nFinds matching global scores"), + PYTHON_METHOD_STATIC(ptGameScore, findPlayerScores, "Params: scoreName, key\nFinds matching player scores"), + PYTHON_METHOD_STATIC(ptGameScore, findScores, "Params: ownerID, scoreName, key\nFinds matching scores for an arbitrary owner"), PYTHON_END_METHODS_TABLE; // Type structure definition -PLASMA_DEFAULT_TYPE(ptGameScore, "Game score manager"); +PLASMA_DEFAULT_TYPE(ptGameScore, "Plasma Game Score"); // required functions for PyObject interoperability PyObject* pyGameScore::New(pfGameScore* score) { ptGameScore* newObj = (ptGameScore*)ptGameScore_type.tp_new(&ptGameScore_type, NULL, NULL); - if (newObj->fThis->fScore) - newObj->fThis->fScore->DecRef(); + hsRefCnt_SafeUnRef(newObj->fThis->fScore); newObj->fThis->fScore = score; - if (newObj->fThis->fScore) - newObj->fThis->fScore->IncRef(); + hsRefCnt_SafeRef(newObj->fThis->fScore); return (PyObject*)newObj; } @@ -158,3 +371,24 @@ void pyGameScore::AddPlasmaClasses(PyObject *m) PYTHON_CLASS_IMPORT(m, ptGameScore); PYTHON_CLASS_IMPORT_END(m); } + +void pyGameScore::AddPlasmaConstantsClasses(PyObject *m) +{ + PYTHON_ENUM_START(PtGameScoreTypes); + PYTHON_ENUM_ELEMENT(PtGameScoreTypes, kFixed, kScoreTypeFixed); + PYTHON_ENUM_ELEMENT(PtGameScoreTypes, kAccumulative, kScoreTypeAccumulative); + PYTHON_ENUM_ELEMENT(PtGameScoreTypes, kAccumAllowNegative, kScoreTypeAccumAllowNegative); + PYTHON_ENUM_END(m, PtGameScoreTypes); + + PYTHON_ENUM_START(PtScoreRankGroups); + PYTHON_ENUM_ELEMENT(PtScoreRankGroups, kIndividual, kScoreRankGroupIndividual); + PYTHON_ENUM_ELEMENT(PtScoreRankGroups, kNeighborhood, kScoreRankGroupNeighborhood); + PYTHON_ENUM_END(m, PtScoreRankGroups); + + PYTHON_ENUM_START(PtScoreTimePeriods); + PYTHON_ENUM_ELEMENT(PtScoreTimePeriods, kOverall, kScoreTimePeriodOverall); + PYTHON_ENUM_ELEMENT(PtScoreTimePeriods, kYear, kScoreTimePeriodYear); + PYTHON_ENUM_ELEMENT(PtScoreTimePeriods, kMonth, kScoreTimePeriodMonth); + PYTHON_ENUM_ELEMENT(PtScoreTimePeriods, kDay, kScoreTimePeriodDay); + PYTHON_ENUM_END(m, PtScoreTimePeriods); +} diff --git a/Sources/Plasma/FeatureLib/pfPython/pyGameScoreMsg.cpp b/Sources/Plasma/FeatureLib/pfPython/pyGameScoreMsg.cpp new file mode 100644 index 00000000..77128aa3 --- /dev/null +++ b/Sources/Plasma/FeatureLib/pfPython/pyGameScoreMsg.cpp @@ -0,0 +1,118 @@ +/*==LICENSE==* + +CyanWorlds.com Engine - MMOG client, server and tools +Copyright (C) 2011 Cyan Worlds, Inc. + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . + +Additional permissions under GNU GPL version 3 section 7 + +If you modify this Program, or any covered work, by linking or +combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, +NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent +JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK +(or a modified version of those libraries), +containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, +PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG +JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the +licensors of this Program grant you additional +permission to convey the resulting work. Corresponding Source for a +non-source form of such a combination shall include the source code for +the parts of OpenSSL and IJG JPEG Library used as well as that of the covered +work. + +You can contact Cyan Worlds, Inc. by email legal@cyan.com + or by snail mail at: + Cyan Worlds, Inc. + 14617 N Newport Hwy + Mead, WA 99021 + +*==LICENSE==*/ + +#include "pyGameScoreMsg.h" +#include "pyGameScore.h" + +PyObject* pyGameScoreMsg::CreateFinal(pfGameScoreMsg* msg) +{ + if (pfGameScoreListMsg* l = pfGameScoreListMsg::ConvertNoRef(msg)) + return pyGameScoreListMsg::New(l); + if (pfGameScoreTransferMsg* t = pfGameScoreTransferMsg::ConvertNoRef(msg)) + return pyGameScoreTransferMsg::New(t); + if (pfGameScoreUpdateMsg* u = pfGameScoreUpdateMsg::ConvertNoRef(msg)) + return pyGameScoreUpdateMsg::New(u); + return nil; +} + +plString pyGameScoreMsg::GetError() const +{ + if (fMsg) + return _TEMP_CONVERT_FROM_WCHAR_T(NetErrorToString(fMsg->GetResult())); + return _TEMP_CONVERT_FROM_LITERAL("pfGameScoreMsg is NULL"); +} + +bool pyGameScoreMsg::IsValid() const +{ + if (fMsg) + return IS_NET_SUCCESS(fMsg->GetResult()); + return false; +} + +plString pyGameScoreListMsg::GetName() const +{ + if (pfGameScoreListMsg* pList = pfGameScoreListMsg::ConvertNoRef(fMsg)) + return pList->GetName(); + return plString::Null; +} + +uint32_t pyGameScoreListMsg::GetOwnerID() const +{ + if (pfGameScoreListMsg* pList = pfGameScoreListMsg::ConvertNoRef(fMsg)) + return pList->GetOwnerID(); + return 0; +} + +size_t pyGameScoreListMsg::GetNumScores() const +{ + if (pfGameScoreListMsg* pList = pfGameScoreListMsg::ConvertNoRef(fMsg)) + return pList->GetNumScores(); + return 0; +} + +PyObject* pyGameScoreListMsg::GetScore(size_t idx) const +{ + if (pfGameScoreListMsg* pList = pfGameScoreListMsg::ConvertNoRef(fMsg)) + return pyGameScore::New(pList->GetScore(idx)); + return nil; +} + +PyObject* pyGameScoreTransferMsg::GetDestinationScore() const +{ + if (pfGameScoreTransferMsg* pTrans = pfGameScoreTransferMsg::ConvertNoRef(fMsg)) + return pyGameScore::New(pTrans->GetDestination()); + return nil; +} + +PyObject* pyGameScoreTransferMsg::GetSourceScore() const +{ + if (pfGameScoreTransferMsg* pTrans = pfGameScoreTransferMsg::ConvertNoRef(fMsg)) + return pyGameScore::New(pTrans->GetSource()); + return nil; +} + +PyObject* pyGameScoreUpdateMsg::GetScore() const +{ + if (pfGameScoreUpdateMsg* pUp = pfGameScoreUpdateMsg::ConvertNoRef(fMsg)) + return pyGameScore::New(pUp->GetScore()); + return nil; +} diff --git a/Sources/Plasma/FeatureLib/pfPython/pyGameScoreMsg.h b/Sources/Plasma/FeatureLib/pfPython/pyGameScoreMsg.h new file mode 100644 index 00000000..6fabaf5a --- /dev/null +++ b/Sources/Plasma/FeatureLib/pfPython/pyGameScoreMsg.h @@ -0,0 +1,149 @@ +/*==LICENSE==* + +CyanWorlds.com Engine - MMOG client, server and tools +Copyright (C) 2011 Cyan Worlds, Inc. + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . + +Additional permissions under GNU GPL version 3 section 7 + +If you modify this Program, or any covered work, by linking or +combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, +NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent +JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK +(or a modified version of those libraries), +containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, +PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG +JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the +licensors of this Program grant you additional +permission to convey the resulting work. Corresponding Source for a +non-source form of such a combination shall include the source code for +the parts of OpenSSL and IJG JPEG Library used as well as that of the covered +work. + +You can contact Cyan Worlds, Inc. by email legal@cyan.com + or by snail mail at: + Cyan Worlds, Inc. + 14617 N Newport Hwy + Mead, WA 99021 + +*==LICENSE==*/ +#ifndef _pyGameScoreMsg_h_ +#define _pyGameScoreMsg_h_ + +#include "pyGlueHelpers.h" +#include "pfMessage/pfGameScoreMsg.h" + +class pyGameScoreMsg +{ +protected: + pfGameScoreMsg* fMsg; + + pyGameScoreMsg() + : fMsg(nil) + { } + + pyGameScoreMsg(pfGameScoreMsg* msg) + : fMsg(msg) + { + hsRefCnt_SafeRef(msg); + } + +public: + virtual ~pyGameScoreMsg() + { + hsRefCnt_SafeUnRef(fMsg); + } + + // required functions for PyObject interoperability + PYTHON_EXPOSE_TYPE; // so we can subclass + PYTHON_CLASS_NEW_FRIEND(ptGameScoreMsg); + static PyObject* CreateFinal(pfGameScoreMsg* msg); // returns the proper descendant. Note there is no New + PYTHON_CLASS_CHECK_DEFINITION; // returns true if the PyObject is a pyGameScoreMsg object + PYTHON_CLASS_CONVERT_FROM_DEFINITION(pyGameScoreMsg); // converts a PyObject to a pyGameScoreMsg (throws error if not correct type) + + plString GetError() const; + bool IsValid() const; + + static void AddPlasmaClasses(PyObject* m); +}; + +class pyGameScoreListMsg : public pyGameScoreMsg +{ + pyGameScoreListMsg() + : pyGameScoreMsg() + { } + + pyGameScoreListMsg(pfGameScoreListMsg* msg) + : pyGameScoreMsg(msg) + { } + +public: + PYTHON_CLASS_NEW_FRIEND(ptGameScoreListMsg); + static PyObject* New(pfGameScoreListMsg* msg); + PYTHON_CLASS_CHECK_DEFINITION; // returns true if the PyObject is a pyGameScoreListMsg object + PYTHON_CLASS_CONVERT_FROM_DEFINITION(pyGameScoreListMsg); // converts a PyObject to a pyGameScoreListMsg (throws error if not correct type) + + static void AddPlasmaClasses(PyObject* m); + + plString GetName() const; + uint32_t GetOwnerID() const; + size_t GetNumScores() const; + PyObject* GetScore(size_t idx) const; +}; + +class pyGameScoreTransferMsg : public pyGameScoreMsg +{ + pyGameScoreTransferMsg() + : pyGameScoreMsg() + { } + + pyGameScoreTransferMsg(pfGameScoreTransferMsg* msg) + : pyGameScoreMsg(msg) + { } + +public: + PYTHON_CLASS_NEW_FRIEND(ptGameScoreTransferMsg); + static PyObject* New(pfGameScoreTransferMsg* msg); + PYTHON_CLASS_CHECK_DEFINITION; // returns true if the PyObject is a pyGameScoreTransferMsg object + PYTHON_CLASS_CONVERT_FROM_DEFINITION(pyGameScoreTransferMsg); // converts a PyObject to a pyGameScoreTransferMsg (throws error if not correct type) + + static void AddPlasmaClasses(PyObject* m); + + PyObject* GetDestinationScore() const; + PyObject* GetSourceScore() const; +}; + +class pyGameScoreUpdateMsg : public pyGameScoreMsg +{ + pyGameScoreUpdateMsg() + : pyGameScoreMsg() + { } + + pyGameScoreUpdateMsg(pfGameScoreUpdateMsg* msg) + : pyGameScoreMsg(msg) + { } + +public: + PYTHON_CLASS_NEW_FRIEND(ptGameScoreUpdateMsg); + static PyObject* New(pfGameScoreUpdateMsg* msg); + PYTHON_CLASS_CHECK_DEFINITION; // returns true if the PyObject is a pyGameScoreUpdateMsg object + PYTHON_CLASS_CONVERT_FROM_DEFINITION(pyGameScoreUpdateMsg); // converts a PyObject to a pyGameScoreUpdateMsg (throws error if not correct type) + + static void AddPlasmaClasses(PyObject* m); + + PyObject* GetScore() const; +}; + +#endif // _pyGameScoreMsg_h_ diff --git a/Sources/Plasma/FeatureLib/pfPython/pyGameScoreMsgGlue.cpp b/Sources/Plasma/FeatureLib/pfPython/pyGameScoreMsgGlue.cpp new file mode 100644 index 00000000..4e5a6c86 --- /dev/null +++ b/Sources/Plasma/FeatureLib/pfPython/pyGameScoreMsgGlue.cpp @@ -0,0 +1,251 @@ +/*==LICENSE==* + +CyanWorlds.com Engine - MMOG client, server and tools +Copyright (C) 2011 Cyan Worlds, Inc. + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . + +Additional permissions under GNU GPL version 3 section 7 + +If you modify this Program, or any covered work, by linking or +combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, +NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent +JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK +(or a modified version of those libraries), +containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, +PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG +JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the +licensors of this Program grant you additional +permission to convey the resulting work. Corresponding Source for a +non-source form of such a combination shall include the source code for +the parts of OpenSSL and IJG JPEG Library used as well as that of the covered +work. + +You can contact Cyan Worlds, Inc. by email legal@cyan.com + or by snail mail at: + Cyan Worlds, Inc. + 14617 N Newport Hwy + Mead, WA 99021 + +*==LICENSE==*/ + +#include "pyGameScoreMsg.h" + +// Maybe we need a better exception? Seems to be the best built in one though +#define PFGS_PYERR PyExc_RuntimeError + +// ================================================================= + +PYTHON_CLASS_DEFINITION(ptGameScoreMsg, pyGameScoreMsg); + +PYTHON_DEFAULT_NEW_DEFINITION(ptGameScoreMsg, pyGameScoreMsg); +PYTHON_DEFAULT_DEALLOC_DEFINITION(ptGameScoreMsg); + +PYTHON_NO_INIT_DEFINITION(ptGameScoreMsg); + +PYTHON_START_METHODS_TABLE(ptGameScoreMsg) + // We have no methods, but our helpers want a table... + // Eh. Not the end of the world. +PYTHON_END_METHODS_TABLE; + +// Type structure definition +PLASMA_DEFAULT_TYPE(ptGameScoreMsg, "Game Score operation callback message"); +PYTHON_EXPOSE_TYPE_DEFINITION(ptGameScoreMsg, pyGameScoreMsg); + +PYTHON_CLASS_CHECK_IMPL(ptGameScoreMsg, pyGameScoreMsg) +PYTHON_CLASS_CONVERT_FROM_IMPL(ptGameScoreMsg, pyGameScoreMsg) + +// Module and method definitions +void pyGameScoreMsg::AddPlasmaClasses(PyObject* m) +{ + PYTHON_CLASS_IMPORT_START(m); + PYTHON_CLASS_IMPORT(m, ptGameScoreMsg); + PYTHON_CLASS_IMPORT_END(m); +} + +// ================================================================= + +PYTHON_CLASS_DEFINITION(ptGameScoreListMsg, pyGameScoreListMsg); + +PYTHON_DEFAULT_NEW_DEFINITION(ptGameScoreListMsg, pyGameScoreListMsg); +PYTHON_DEFAULT_DEALLOC_DEFINITION(ptGameScoreListMsg); + +PYTHON_NO_INIT_DEFINITION(ptGameScoreListMsg); + +PYTHON_METHOD_DEFINITION_NOARGS(ptGameScoreListMsg, getName) +{ + return PyUnicode_FromStringEx(self->fThis->GetName()); +} + +PYTHON_METHOD_DEFINITION_NOARGS(ptGameScoreListMsg, getOwnerID) +{ + return PyInt_FromLong(self->fThis->GetOwnerID()); +} + +PYTHON_METHOD_DEFINITION_NOARGS(ptGameScoreListMsg, getScores) +{ + if (self->fThis->IsValid()) + { + size_t count = self->fThis->GetNumScores(); + PyObject* tup = PyTuple_New(count); + for (size_t i = 0; i < count; ++i) + PyTuple_SetItem(tup, i, self->fThis->GetScore(i)); + return tup; + } + + PyErr_SetString(PFGS_PYERR, self->fThis->GetError().c_str()); + PYTHON_RETURN_ERROR; +} + +PYTHON_START_METHODS_TABLE(ptGameScoreListMsg) + PYTHON_METHOD_NOARGS(ptGameScoreListMsg, getName, "Returns the template score name"), + PYTHON_METHOD_NOARGS(ptGameScoreListMsg, getOwnerID, "Returns the template score ownerID"), + PYTHON_METHOD_NOARGS(ptGameScoreListMsg, getScores, "Returns a list of scores found by the server"), +PYTHON_END_METHODS_TABLE; + +// Type structure definition +PLASMA_DEFAULT_TYPE_WBASE(ptGameScoreListMsg, pyGameScoreMsg, "Game Score message for scores found on the server"); + +// PyObject interop +PyObject* pyGameScoreListMsg::New(pfGameScoreListMsg* msg) +{ + ptGameScoreListMsg* newObj = (ptGameScoreListMsg*)ptGameScoreListMsg_type.tp_new(&ptGameScoreListMsg_type, NULL, NULL); + hsRefCnt_SafeUnRef(newObj->fThis->fMsg); + newObj->fThis->fMsg = msg; + hsRefCnt_SafeRef(newObj->fThis->fMsg); + return (PyObject*)newObj; +} + +PYTHON_CLASS_CHECK_IMPL(ptGameScoreListMsg, pyGameScoreListMsg) +PYTHON_CLASS_CONVERT_FROM_IMPL(ptGameScoreListMsg, pyGameScoreListMsg) + +// Module and method definitions +void pyGameScoreListMsg::AddPlasmaClasses(PyObject* m) +{ + PYTHON_CLASS_IMPORT_START(m); + PYTHON_CLASS_IMPORT(m, ptGameScoreListMsg); + PYTHON_CLASS_IMPORT_END(m); +} + +// ================================================================= + +PYTHON_CLASS_DEFINITION(ptGameScoreTransferMsg, pyGameScoreTransferMsg); + +PYTHON_DEFAULT_NEW_DEFINITION(ptGameScoreTransferMsg, pyGameScoreTransferMsg); +PYTHON_DEFAULT_DEALLOC_DEFINITION(ptGameScoreTransferMsg); + +PYTHON_NO_INIT_DEFINITION(ptGameScoreTransferMsg); + +PYTHON_METHOD_DEFINITION_NOARGS(ptGameScoreTransferMsg, getDestination) +{ + if (self->fThis->IsValid()) + { + return self->fThis->GetDestinationScore(); + } + + PyErr_SetString(PFGS_PYERR, self->fThis->GetError().c_str()); + PYTHON_RETURN_ERROR; +} + +PYTHON_METHOD_DEFINITION_NOARGS(ptGameScoreTransferMsg, getSource) +{ + if (self->fThis->IsValid()) + { + return self->fThis->GetSourceScore(); + } + + PyErr_SetString(PFGS_PYERR, self->fThis->GetError().c_str()); + PYTHON_RETURN_ERROR; +} + +PYTHON_START_METHODS_TABLE(ptGameScoreTransferMsg) + PYTHON_METHOD_NOARGS(ptGameScoreTransferMsg, getDestination, "Returns the score points were transferred to"), + PYTHON_METHOD_NOARGS(ptGameScoreTransferMsg, getSource, "Returns the score points were transferred from"), +PYTHON_END_METHODS_TABLE; + +// Type structure definition +PLASMA_DEFAULT_TYPE_WBASE(ptGameScoreTransferMsg, pyGameScoreMsg, "Game Score message indicating a score point transfer"); + +// PyObject interop +PyObject* pyGameScoreTransferMsg::New(pfGameScoreTransferMsg* msg) +{ + ptGameScoreTransferMsg* newObj = (ptGameScoreTransferMsg*)ptGameScoreTransferMsg_type.tp_new(&ptGameScoreTransferMsg_type, NULL, NULL); + hsRefCnt_SafeUnRef(newObj->fThis->fMsg); + newObj->fThis->fMsg = msg; + hsRefCnt_SafeRef(newObj->fThis->fMsg); + return (PyObject*)newObj; +} + +PYTHON_CLASS_CHECK_IMPL(ptGameScoreTransferMsg, pyGameScoreTransferMsg) +PYTHON_CLASS_CONVERT_FROM_IMPL(ptGameScoreTransferMsg, pyGameScoreTransferMsg) + +// Module and method definitions +void pyGameScoreTransferMsg::AddPlasmaClasses(PyObject* m) +{ + PYTHON_CLASS_IMPORT_START(m); + PYTHON_CLASS_IMPORT(m, ptGameScoreTransferMsg); + PYTHON_CLASS_IMPORT_END(m); +} + +// ================================================================= + +PYTHON_CLASS_DEFINITION(ptGameScoreUpdateMsg, pyGameScoreUpdateMsg); + +PYTHON_DEFAULT_NEW_DEFINITION(ptGameScoreUpdateMsg, pyGameScoreUpdateMsg); +PYTHON_DEFAULT_DEALLOC_DEFINITION(ptGameScoreUpdateMsg); + +PYTHON_NO_INIT_DEFINITION(ptGameScoreUpdateMsg); + +PYTHON_METHOD_DEFINITION_NOARGS(ptGameScoreUpdateMsg, getScore) +{ + if (self->fThis->IsValid()) + { + return self->fThis->GetScore(); + } + + PyErr_SetString(PFGS_PYERR, self->fThis->GetError().c_str()); + PYTHON_RETURN_ERROR; +} + +PYTHON_START_METHODS_TABLE(ptGameScoreUpdateMsg) + PYTHON_METHOD_NOARGS(ptGameScoreUpdateMsg, getScore, "Returns the updated game score"), +PYTHON_END_METHODS_TABLE; + +// Type structure definition +PLASMA_DEFAULT_TYPE_WBASE(ptGameScoreUpdateMsg, pyGameScoreMsg, "Game Score message for a score update operation"); + +// PyObject interop +PyObject* pyGameScoreUpdateMsg::New(pfGameScoreUpdateMsg* msg) +{ + ptGameScoreUpdateMsg* newObj = (ptGameScoreUpdateMsg*)ptGameScoreUpdateMsg_type.tp_new(&ptGameScoreUpdateMsg_type, NULL, NULL); + hsRefCnt_SafeUnRef(newObj->fThis->fMsg); + newObj->fThis->fMsg = msg; + hsRefCnt_SafeRef(newObj->fThis->fMsg); + return (PyObject*)newObj; +} + +PYTHON_CLASS_CHECK_IMPL(ptGameScoreUpdateMsg, pyGameScoreUpdateMsg) +PYTHON_CLASS_CONVERT_FROM_IMPL(ptGameScoreUpdateMsg, pyGameScoreUpdateMsg) + +// Module and method definitions +void pyGameScoreUpdateMsg::AddPlasmaClasses(PyObject* m) +{ + PYTHON_CLASS_IMPORT_START(m); + PYTHON_CLASS_IMPORT(m, ptGameScoreUpdateMsg); + PYTHON_CLASS_IMPORT_END(m); +} + +// ================================================================= + +#undef PFGS_PYERR diff --git a/Sources/Plasma/FeatureLib/pfPython/pyScoreMgr.cpp b/Sources/Plasma/FeatureLib/pfPython/pyScoreMgr.cpp deleted file mode 100644 index d2562f4d..00000000 --- a/Sources/Plasma/FeatureLib/pfPython/pyScoreMgr.cpp +++ /dev/null @@ -1,354 +0,0 @@ -/*==LICENSE==* - -CyanWorlds.com Engine - MMOG client, server and tools -Copyright (C) 2011 Cyan Worlds, Inc. - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . - -Additional permissions under GNU GPL version 3 section 7 - -If you modify this Program, or any covered work, by linking or -combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, -NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent -JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK -(or a modified version of those libraries), -containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, -PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG -JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the -licensors of this Program grant you additional -permission to convey the resulting work. Corresponding Source for a -non-source form of such a combination shall include the source code for -the parts of OpenSSL and IJG JPEG Library used as well as that of the covered -work. - -You can contact Cyan Worlds, Inc. by email legal@cyan.com - or by snail mail at: - Cyan Worlds, Inc. - 14617 N Newport Hwy - Mead, WA 99021 - -*==LICENSE==*/ -#include "pyScoreMgr.h" - -#include "pfGameScoreMgr/pfGameScoreMgr.h" -#include "plVault/plVault.h" -#include "plNetCommon/plNetCommon.h" -#include "pyGameScore.h" - -pyScoreMgr::pyScoreMgr() -{ -} - -pyScoreMgr::~pyScoreMgr() -{ -} - -bool pyScoreMgr::DeleteScore(unsigned scoreId) -{ - return IS_NET_SUCCESS(pfGameScoreMgr::GetInstance()->DeleteScore(scoreId)); -} - -PyObject* pyScoreMgr::CreateGlobalScore( - const char * gameName, - unsigned gameType, - int value -) { - pfGameScore * score = NEWZERO(pfGameScore); - score->IncRef(); - - pfGameScoreMgr::GetInstance()->CreateScore(0, gameName, gameType, value, *score); - - if (score) - { - if (score->scoreId > 0) - { - PyObject* pyScore = pyGameScore::New(score); - score->DecRef(); - - return pyScore; - } - - score->DecRef(); - } - - PYTHON_RETURN_NONE; -} - -PyObject* pyScoreMgr::GetGlobalScores(const char* gameName) -{ - pfGameScore** scoreList = nil; - int scoreListCount = 0; - ENetError result = pfGameScoreMgr::GetInstance()->GetScoresIncRef(0, gameName, scoreList, scoreListCount); - - if (IS_NET_SUCCESS(result) && scoreListCount > 0) - { - PyObject* pyScoreList = PyList_New(scoreListCount); - for (int i = 0; i < scoreListCount; ++i) - { - PyObject* pyScore = pyGameScore::New(scoreList[i]); - PyList_SetItem(pyScoreList, i, pyScore); - scoreList[i]->DecRef(); - } - - delete [] scoreList; - - return pyScoreList; - } - - PYTHON_RETURN_NONE; -} - -PyObject* pyScoreMgr::CreatePlayerScore( - const char * gameName, - unsigned gameType, - int value -) { - pfGameScore * score = nil; - - if (RelVaultNode * rvn = VaultGetPlayerInfoNodeIncRef()) { - unsigned ownerId = rvn->nodeId; - rvn->DecRef(); - - score = NEWZERO(pfGameScore); - score->IncRef(); - pfGameScoreMgr::GetInstance()->CreateScore(ownerId, gameName, gameType, value, *score); - } - - if (score) - { - if (score->scoreId > 0) - { - PyObject* pyScore = pyGameScore::New(score); - score->DecRef(); - - return pyScore; - } - - score->DecRef(); - } - - PYTHON_RETURN_NONE; -} - -PyObject* pyScoreMgr::GetPlayerScores(const char* gameName) -{ - if (RelVaultNode * rvn = VaultGetPlayerInfoNodeIncRef()) { - unsigned ownerId = rvn->nodeId; - rvn->DecRef(); - - pfGameScore** scoreList = nil; - int scoreListCount = 0; - ENetError result = pfGameScoreMgr::GetInstance()->GetScoresIncRef(ownerId, gameName, scoreList, scoreListCount); - - if (IS_NET_SUCCESS(result) && scoreListCount > 0) - { - PyObject* pyScoreList = PyList_New(scoreListCount); - for (int i = 0; i < scoreListCount; ++i) - { - PyObject* pyScore = pyGameScore::New(scoreList[i]); - PyList_SetItem(pyScoreList, i, pyScore); - scoreList[i]->DecRef(); - } - - delete [] scoreList; - - return pyScoreList; - } - } - - PYTHON_RETURN_NONE; -} - -PyObject* pyScoreMgr::CreateNeighborhoodScore( - const char * gameName, - unsigned gameType, - int value -) { - pfGameScore * score = nil; - - plAgeInfoStruct info; - info.SetAgeFilename(kNeighborhoodAgeFilename); - - if (RelVaultNode * rvn = VaultGetOwnedAgeInfoIncRef(&info)) { - unsigned ownerId = rvn->nodeId; - rvn->DecRef(); - - score = NEWZERO(pfGameScore); - score->IncRef(); - pfGameScoreMgr::GetInstance()->CreateScore(ownerId, gameName, gameType, value, *score); - } - - if (score) - { - if (score->scoreId > 0) - { - PyObject* pyScore = pyGameScore::New(score); - score->DecRef(); - - return pyScore; - } - - score->DecRef(); - } - - PYTHON_RETURN_NONE; -} - -PyObject* pyScoreMgr::GetNeighborhoodScores(const char* gameName) -{ - plAgeInfoStruct info; - info.SetAgeFilename(kNeighborhoodAgeFilename); - - if (RelVaultNode * rvn = VaultGetOwnedAgeInfoIncRef(&info)) { - unsigned ownerId = rvn->nodeId; - rvn->DecRef(); - - pfGameScore** scoreList = nil; - int scoreListCount = 0; - ENetError result = pfGameScoreMgr::GetInstance()->GetScoresIncRef(ownerId, gameName, scoreList, scoreListCount); - - if (IS_NET_SUCCESS(result) && scoreListCount > 0) - { - PyObject* pyScoreList = PyList_New(scoreListCount); - for (int i = 0; i < scoreListCount; ++i) - { - PyObject* pyScore = pyGameScore::New(scoreList[i]); - PyList_SetItem(pyScoreList, i, pyScore); - scoreList[i]->DecRef(); - } - - delete [] scoreList; - - return pyScoreList; - } - } - - PYTHON_RETURN_NONE; -} - -PyObject* pyScoreMgr::CreateCurrentAgeScore( - const char * gameName, - unsigned gameType, - int value -) { - pfGameScore * score = nil; - - if (RelVaultNode * rvn = VaultGetAgeInfoNodeIncRef()) { - unsigned ownerId = rvn->nodeId; - rvn->DecRef(); - - score = NEWZERO(pfGameScore); - score->IncRef(); - pfGameScoreMgr::GetInstance()->CreateScore(ownerId, gameName, gameType, value, *score); - } - - if (score) - { - if (score->scoreId > 0) - { - PyObject* pyScore = pyGameScore::New(score); - score->DecRef(); - - return pyScore; - } - - score->DecRef(); - } - - PYTHON_RETURN_NONE; -} - -PyObject* pyScoreMgr::GetCurrentAgeScores(const char* gameName) -{ - if (RelVaultNode * rvn = VaultGetAgeInfoNodeIncRef()) { - unsigned ownerId = rvn->nodeId; - rvn->DecRef(); - - pfGameScore** scoreList = nil; - int scoreListCount = 0; - ENetError result = pfGameScoreMgr::GetInstance()->GetScoresIncRef(ownerId, gameName, scoreList, scoreListCount); - - if (IS_NET_SUCCESS(result) && scoreListCount > 0) - { - PyObject* pyScoreList = PyList_New(scoreListCount); - for (int i = 0; i < scoreListCount; ++i) - { - PyObject* pyScore = pyGameScore::New(scoreList[i]); - PyList_SetItem(pyScoreList, i, pyScore); - scoreList[i]->DecRef(); - } - - delete [] scoreList; - - return pyScoreList; - } - } - - PYTHON_RETURN_NONE; -} - -PyObject * pyScoreMgr::GetRankList( - unsigned scoreGroup, - unsigned parentFolderId, - const char * gameName, - unsigned timePeriod, - unsigned numResults, - unsigned pageNumber, - bool sortDesc -) { - if (RelVaultNode * rvn = VaultGetPlayerInfoNodeIncRef()) { - unsigned ownerId = rvn->nodeId; - rvn->DecRef(); - - NetGameRank** rankList = nil; - int rankListCount = 0; - ENetError result = pfGameScoreMgr::GetInstance()->GetRankList( - ownerId, - scoreGroup, - parentFolderId, - gameName, - timePeriod, - numResults, - pageNumber, - sortDesc, - rankList, - rankListCount - ); - - if (IS_NET_SUCCESS(result) && rankListCount > 0) - { - PyObject* pyRankList = PyList_New(rankListCount); - for (int i = 0; i < rankListCount; ++i) - { - char tempStr[kMaxPlayerNameLength]; - StrToAnsi(tempStr, rankList[i]->name, arrsize(tempStr)); - - PyObject* pyRank = PyTuple_New(3); - PyTuple_SetItem(pyRank, 0, PyInt_FromLong(rankList[i]->rank)); - PyTuple_SetItem(pyRank, 1, PyString_FromString(tempStr)); - PyTuple_SetItem(pyRank, 2, PyInt_FromLong(rankList[i]->score)); - - PyList_SetItem(pyRankList, i, pyRank); - - delete rankList[i]; - } - - delete [] rankList; - - return pyRankList; - } - } - - PYTHON_RETURN_NONE; -} diff --git a/Sources/Plasma/FeatureLib/pfPython/pyScoreMgr.h b/Sources/Plasma/FeatureLib/pfPython/pyScoreMgr.h deleted file mode 100644 index 8cafbff0..00000000 --- a/Sources/Plasma/FeatureLib/pfPython/pyScoreMgr.h +++ /dev/null @@ -1,115 +0,0 @@ -/*==LICENSE==* - -CyanWorlds.com Engine - MMOG client, server and tools -Copyright (C) 2011 Cyan Worlds, Inc. - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . - -Additional permissions under GNU GPL version 3 section 7 - -If you modify this Program, or any covered work, by linking or -combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, -NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent -JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK -(or a modified version of those libraries), -containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, -PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG -JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the -licensors of this Program grant you additional -permission to convey the resulting work. Corresponding Source for a -non-source form of such a combination shall include the source code for -the parts of OpenSSL and IJG JPEG Library used as well as that of the covered -work. - -You can contact Cyan Worlds, Inc. by email legal@cyan.com - or by snail mail at: - Cyan Worlds, Inc. - 14617 N Newport Hwy - Mead, WA 99021 - -*==LICENSE==*/ -#ifndef pyScoreMgr_h -#define pyScoreMgr_h - -///////////////////////////////////////////////////////////////////////////// -// -// NAME: pyScoreMgr -// -// PURPOSE: a wrapper class to provide an interface to the scoring system -// -#include - -#include "HeadSpin.h" -#include "hsStlUtils.h" - -#include "pyGlueHelpers.h" - - -class pyScoreMgr -{ -public: - pyScoreMgr(); - ~pyScoreMgr(); - - // required functions for PyObject interoperability - PYTHON_CLASS_NEW_FRIEND(ptScoreMgr); - PYTHON_CLASS_NEW_DEFINITION; - PYTHON_CLASS_CHECK_DEFINITION; // returns true if the PyObject is a pyScoreMgr object - PYTHON_CLASS_CONVERT_FROM_DEFINITION(pyScoreMgr); // converts a PyObject to a pyScoreMgr (throws error if not correct type) - - static void AddPlasmaClasses(PyObject *m); - static void AddPlasmaConstantsClasses(PyObject *m); - - bool DeleteScore(unsigned scoreId); - - PyObject* CreateGlobalScore( - const char * gameName, - unsigned gameType, - int value - ); - PyObject* GetGlobalScores(const char* gameName); - - PyObject* CreatePlayerScore( - const char * gameName, - unsigned gameType, - int value - ); - PyObject* GetPlayerScores(const char* gameName); - - PyObject* CreateNeighborhoodScore( - const char * gameName, - unsigned gameType, - int value - ); - PyObject* GetNeighborhoodScores(const char* gameName); - - PyObject* CreateCurrentAgeScore( - const char * gameName, - unsigned gameType, - int value - ); - PyObject* GetCurrentAgeScores(const char* gameName); - - PyObject * GetRankList( - unsigned scoreGroup, - unsigned parentFolderId, - const char * gameName, - unsigned timePeriod, - unsigned numResults, - unsigned pageNumber, - bool sortDesc - ); -}; - -#endif diff --git a/Sources/Plasma/FeatureLib/pfPython/pyScoreMgrGlue.cpp b/Sources/Plasma/FeatureLib/pfPython/pyScoreMgrGlue.cpp deleted file mode 100644 index 70a4b58a..00000000 --- a/Sources/Plasma/FeatureLib/pfPython/pyScoreMgrGlue.cpp +++ /dev/null @@ -1,235 +0,0 @@ -/*==LICENSE==* - -CyanWorlds.com Engine - MMOG client, server and tools -Copyright (C) 2011 Cyan Worlds, Inc. - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . - -Additional permissions under GNU GPL version 3 section 7 - -If you modify this Program, or any covered work, by linking or -combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, -NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent -JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK -(or a modified version of those libraries), -containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, -PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG -JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the -licensors of this Program grant you additional -permission to convey the resulting work. Corresponding Source for a -non-source form of such a combination shall include the source code for -the parts of OpenSSL and IJG JPEG Library used as well as that of the covered -work. - -You can contact Cyan Worlds, Inc. by email legal@cyan.com - or by snail mail at: - Cyan Worlds, Inc. - 14617 N Newport Hwy - Mead, WA 99021 - -*==LICENSE==*/ -#include "pyScoreMgr.h" - -#include "pyEnum.h" -#include "pfGameScoreMgr/pfGameScoreMgr.h" - -// glue functions -PYTHON_CLASS_DEFINITION(ptScoreMgr, pyScoreMgr); - -PYTHON_DEFAULT_NEW_DEFINITION(ptScoreMgr, pyScoreMgr) -PYTHON_DEFAULT_DEALLOC_DEFINITION(ptScoreMgr) - -PYTHON_INIT_DEFINITION(ptScoreMgr, args, keywords) -{ - PYTHON_RETURN_INIT_OK; -} - -PYTHON_METHOD_DEFINITION(ptScoreMgr, deleteScore, args) -{ - int scoreId; - if (!PyArg_ParseTuple(args, "i", &scoreId)) - { - PyErr_SetString(PyExc_TypeError, "deleteScore expects an int"); - PYTHON_RETURN_ERROR; - } - PYTHON_RETURN_BOOL(self->fThis->DeleteScore(scoreId)); -} - -PYTHON_METHOD_DEFINITION(ptScoreMgr, createGlobalScore, args) -{ - char* gameName; - int gameType; - int value; - if (!PyArg_ParseTuple(args, "sii", &gameName, &gameType, &value)) - { - PyErr_SetString(PyExc_TypeError, "createGlobalScore expects a string, an int, and an int"); - PYTHON_RETURN_ERROR; - } - return self->fThis->CreateGlobalScore(gameName, gameType, value); -} - -PYTHON_METHOD_DEFINITION(ptScoreMgr, getGlobalScores, args) -{ - char* gameName; - if (!PyArg_ParseTuple(args, "s", &gameName)) - { - PyErr_SetString(PyExc_TypeError, "getGlobalScores expects a string"); - PYTHON_RETURN_ERROR; - } - return self->fThis->GetGlobalScores(gameName); -} - -PYTHON_METHOD_DEFINITION(ptScoreMgr, createPlayerScore, args) -{ - char* gameName; - int gameType; - int value; - if (!PyArg_ParseTuple(args, "sii", &gameName, &gameType, &value)) - { - PyErr_SetString(PyExc_TypeError, "createPlayerScore expects a string, an int, and an int"); - PYTHON_RETURN_ERROR; - } - return self->fThis->CreatePlayerScore(gameName, gameType, value); -} - -PYTHON_METHOD_DEFINITION(ptScoreMgr, getPlayerScores, args) -{ - char* gameName; - if (!PyArg_ParseTuple(args, "s", &gameName)) - { - PyErr_SetString(PyExc_TypeError, "getPlayerScores expects a string"); - PYTHON_RETURN_ERROR; - } - return self->fThis->GetPlayerScores(gameName); -} - -PYTHON_METHOD_DEFINITION(ptScoreMgr, createNeighborhoodScore, args) -{ - char* gameName; - int gameType; - int value; - if (!PyArg_ParseTuple(args, "sii", &gameName, &gameType, &value)) - { - PyErr_SetString(PyExc_TypeError, "createNeighborhoodScore expects a string, an int, and an int"); - PYTHON_RETURN_ERROR; - } - return self->fThis->CreateNeighborhoodScore(gameName, gameType, value); -} - -PYTHON_METHOD_DEFINITION(ptScoreMgr, getNeighborhoodScores, args) -{ - char* gameName; - if (!PyArg_ParseTuple(args, "s", &gameName)) - { - PyErr_SetString(PyExc_TypeError, "getNeighborhoodScores expects a string"); - PYTHON_RETURN_ERROR; - } - return self->fThis->GetNeighborhoodScores(gameName); -} - -PYTHON_METHOD_DEFINITION(ptScoreMgr, createCurrentAgeScore, args) -{ - char* gameName; - int gameType; - int value; - if (!PyArg_ParseTuple(args, "sii", &gameName, &gameType, &value)) - { - PyErr_SetString(PyExc_TypeError, "createCurrentAgeScore expects a string, an int, and an int"); - PYTHON_RETURN_ERROR; - } - return self->fThis->CreateCurrentAgeScore(gameName, gameType, value); -} - -PYTHON_METHOD_DEFINITION(ptScoreMgr, getCurrentAgeScores, args) -{ - char* gameName; - if (!PyArg_ParseTuple(args, "s", &gameName)) - { - PyErr_SetString(PyExc_TypeError, "getCurrentAgeScores expects a string"); - PYTHON_RETURN_ERROR; - } - return self->fThis->GetCurrentAgeScores(gameName); -} - -PYTHON_METHOD_DEFINITION(ptScoreMgr, getRankList, args) -{ - int scoreGroup; - int parentFolderId; - char* gameName; - int timePeriod; - int numResults; - int pageNumber; - int sortDesc; - if (!PyArg_ParseTuple(args, "iisiiii", &scoreGroup, &parentFolderId, &gameName, &timePeriod, &numResults, &pageNumber, &sortDesc)) - { - PyErr_SetString(PyExc_TypeError, "getRankList expects two ints, a string, and four more ints"); - PYTHON_RETURN_ERROR; - } - - return self->fThis->GetRankList(scoreGroup, parentFolderId, gameName, timePeriod, numResults, pageNumber, sortDesc != 0); -} - -PYTHON_START_METHODS_TABLE(ptScoreMgr) - PYTHON_METHOD(ptScoreMgr, deleteScore, "Params: scoreId\nDeletes the specified score"), - PYTHON_METHOD(ptScoreMgr, createGlobalScore, "Params: gameName, gameType, value\nCreates a score and returns it"), - PYTHON_METHOD(ptScoreMgr, getGlobalScores, "Params: gameName\nReturns a list of scores associated with the specified game."), - PYTHON_METHOD(ptScoreMgr, createPlayerScore, "Params: gameName, gameType, value\nCreates a score and returns it"), - PYTHON_METHOD(ptScoreMgr, getPlayerScores, "Params: gameName\nReturns a list of scores associated with the specified game."), - PYTHON_METHOD(ptScoreMgr, createNeighborhoodScore, "Params: gameName, gameType, value\nCreates a score and returns it"), - PYTHON_METHOD(ptScoreMgr, getNeighborhoodScores, "Params: gameName\nReturns a list of scores associated with the specified game."), - PYTHON_METHOD(ptScoreMgr, createCurrentAgeScore, "Params: gameName, gameType, value\nCreates a score and returns it"), - PYTHON_METHOD(ptScoreMgr, getCurrentAgeScores, "Params: gameName\nReturns a list of scores associated with the specified game."), - PYTHON_METHOD(ptScoreMgr, getRankList, "Params: ownerInfoId, scoreGroup, parentFolderId, gameName, timePeriod, numResults, pageNumber, sortDesc\nReturns a list of scores and rank"), -PYTHON_END_METHODS_TABLE; - -// Type structure definition -PLASMA_DEFAULT_TYPE(ptScoreMgr, "Game score manager"); - -// required functions for PyObject interoperability -PYTHON_CLASS_NEW_IMPL(ptScoreMgr, pyScoreMgr) - -PYTHON_CLASS_CHECK_IMPL(ptScoreMgr, pyScoreMgr) -PYTHON_CLASS_CONVERT_FROM_IMPL(ptScoreMgr, pyScoreMgr) - -/////////////////////////////////////////////////////////////////////////// -// -// AddPlasmaClasses - the python module definitions -// -void pyScoreMgr::AddPlasmaClasses(PyObject *m) -{ - PYTHON_CLASS_IMPORT_START(m); - PYTHON_CLASS_IMPORT(m, ptScoreMgr); - PYTHON_CLASS_IMPORT_END(m); -} - -void pyScoreMgr::AddPlasmaConstantsClasses(PyObject *m) -{ - PYTHON_ENUM_START(PtGameScoreTypes); - PYTHON_ENUM_ELEMENT(PtGameScoreTypes, kFixed, kScoreTypeFixed); - PYTHON_ENUM_ELEMENT(PtGameScoreTypes, kAccumulative, kScoreTypeAccumulative); - PYTHON_ENUM_ELEMENT(PtGameScoreTypes, kAccumAllowNegative, kScoreTypeAccumAllowNegative); - PYTHON_ENUM_END(m, PtGameScoreTypes); - - PYTHON_ENUM_START(PtScoreRankGroups); - PYTHON_ENUM_ELEMENT(PtScoreRankGroups, kIndividual, kScoreRankGroupIndividual); - PYTHON_ENUM_ELEMENT(PtScoreRankGroups, kNeighborhood, kScoreRankGroupNeighborhood); - PYTHON_ENUM_END(m, PtScoreRankGroups); - - PYTHON_ENUM_START(PtScoreTimePeriods); - PYTHON_ENUM_ELEMENT(PtScoreTimePeriods, kOverall, kScoreTimePeriodOverall); - PYTHON_ENUM_ELEMENT(PtScoreTimePeriods, kYear, kScoreTimePeriodYear); - PYTHON_ENUM_ELEMENT(PtScoreTimePeriods, kMonth, kScoreTimePeriodMonth); - PYTHON_ENUM_ELEMENT(PtScoreTimePeriods, kDay, kScoreTimePeriodDay); - PYTHON_ENUM_END(m, PtScoreTimePeriods); -}