From 58ec459ea5afdd00785b964035e18c85881136a2 Mon Sep 17 00:00:00 2001 From: AURUMVORXX Date: Sat, 9 Nov 2024 03:09:07 +0300 Subject: [PATCH] feat: Added server-side functions --- CMakeLists.txt | 2 + docs/comparing.md | 27 ++++- src/NoNut/core/CustomTypes.cpp | 41 ++++++++ src/NoNut/core/CustomTypes.h | 6 ++ src/bind.cpp | 140 +++++++++++++++++++++++++ src/classes/sq/Daedalus.h | 2 +- src/events/sqevents_player.cpp | 60 +++++++---- src/functions/pyfunctions.cpp | 185 +++++++++++++++++++++++++++++++++ src/functions/pyfunctions.h | 146 ++++++++++++++++++++++++++ src/functions/sqfunctions.cpp | 154 +++++++++++++++++++++++++++ src/functions/sqfunctions.h | 160 ++++++++++++++++++++++++++++ src/main.cpp | 2 +- 12 files changed, 897 insertions(+), 28 deletions(-) create mode 100644 src/functions/pyfunctions.cpp create mode 100644 src/functions/pyfunctions.h create mode 100644 src/functions/sqfunctions.cpp create mode 100644 src/functions/sqfunctions.h diff --git a/CMakeLists.txt b/CMakeLists.txt index b8ac43d..96aae29 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -74,6 +74,8 @@ file(GLOB_RECURSE SOURCE "src/classes/py/*.cpp" "src/constants/*.h" "src/constants/*.cpp" + "src/functions/*.h" + "src/functions/*.cpp" "src/*.h" "src/*.cpp" "src/events/*.h" diff --git a/docs/comparing.md b/docs/comparing.md index 89065f8..9b0241a 100644 --- a/docs/comparing.md +++ b/docs/comparing.md @@ -11,7 +11,7 @@ def evtInitSecond(**kwargs): print('World') ``` --- -* Positional arguments replaced with keyword arguments (see names of all keywords on the each event page) +* Positional arguments inside event handles replaced with keyword arguments (see names of all keywords on the each event page) ```python @g2o.event('onPlayerChangeColor') def evtColor(**kwargs): @@ -49,5 +49,26 @@ def evtDrop(**kwargs): print(evtDrop.cancelled) print(evtDrop.eventName) ``` ---- -* `eventValue` has been removed (RIP) \ No newline at end of file +----- +* Following functions have been removed RIP :( + + * `md5` + * `sha1` + * `sha256` + * `sha384` + * `sha512` + * `setReloadCallback` + * `setUnloadCallback` + * `getTimerExecuteTimes` + * `getTimerInterval` + * `killTimer` + * `setTimer` + * `setTimerExecuteTimes` + * `setTimerInterval` + * `sscanf` + * `hexToRgb` + * `rgbToHex` + * `getTickCount` + * `eventValue` + * `getPlayerMagicLevel` + * `setPlayerMagicLevel` \ No newline at end of file diff --git a/src/NoNut/core/CustomTypes.cpp b/src/NoNut/core/CustomTypes.cpp index 13e6e68..1c34372 100644 --- a/src/NoNut/core/CustomTypes.cpp +++ b/src/NoNut/core/CustomTypes.cpp @@ -135,6 +135,47 @@ namespace nonut result.convert(value); data[sq_objtostring(&key)] = result.data; } + else if (value._type == OT_ARRAY) + { + SqList result = SqList(); + result.convert(value); + data[sq_objtostring(&key)] = result.data; + } + } + } + + void SqList::convert(SQObject object) + { + Sqrat::Array tab = Sqrat::Array(object); + Sqrat::Object::iterator arrIterator; + int i = 0; + + while (tab.Next(arrIterator)) + { + HSQOBJECT key = arrIterator.getKey(); + HSQOBJECT value = arrIterator.getValue(); + + if (key._type != OT_INTEGER) + continue; + + if (value._type == OT_STRING) + data.insert(sq_objtointeger(&key), sq_objtofloat(&value)); + else if (value._type == OT_INTEGER) + data.insert(sq_objtointeger(&key), sq_objtointeger(&value)); + else if (value._type == OT_FLOAT) + data.insert(sq_objtointeger(&key), sq_objtofloat(&value)); + else if (value._type == OT_TABLE) + { + SqDict result = SqDict(); + result.convert(value); + data.insert(sq_objtointeger(&key), result.data); + } + else if (value._type == OT_ARRAY) + { + SqList result = SqList(); + result.convert(value); + data.insert(sq_objtointeger(&key), result.data); + } } } } diff --git a/src/NoNut/core/CustomTypes.h b/src/NoNut/core/CustomTypes.h index 2bd004f..5756f05 100644 --- a/src/NoNut/core/CustomTypes.h +++ b/src/NoNut/core/CustomTypes.h @@ -172,5 +172,11 @@ namespace nonut void convert(SQObject object) override; py::dict data{}; }; + + struct SqList : CustomType + { + void convert(SQObject object) override; + py::list data{}; + }; } #endif // NONUT_G2O_SHARED_CUSTOM_TYPES_H diff --git a/src/bind.cpp b/src/bind.cpp index 8365620..7fde6a3 100644 --- a/src/bind.cpp +++ b/src/bind.cpp @@ -1,10 +1,14 @@ #include + #include "classes/py/Packet.h" #include "classes/py/DamageDescription.h" #include "classes/py/ItemGround.h" #include "classes/py/Daedalus.h" #include "classes/py/Sky.h" #include "classes/py/ItemsGround.h" + +#include "functions/pyfunctions.h" + #include namespace py = pybind11; @@ -95,4 +99,140 @@ PYBIND11_EMBEDDED_MODULE(sqg2o, m) { .def_static("getById", [](int value){ return PyItemsGround::getById(value); }) .def_static("create", [](py::dict value){ return PyItemsGround::create(value); }) .def_static("destroy", [](int value){ return PyItemsGround::destroy(value); }); + +// ------------------------------------------------------------------------- + + m.def("getHostname", &py_getHostname); + m.def("getMaxSlots", &py_getMaxSlots); + m.def("getPlayersCount", &py_getPlayersCount); + + m.def("getDistance2d", &py_getDistance2d); + m.def("getDistance3d", &py_getDistance3d); + m.def("getVectorAngle", &py_getVectorAngle); + + m.def("exit", &py_exit, py::arg() = 0); + m.def("getDayLength", &py_getDayLength); + m.def("getServerDescription", &py_getServerDescription); + m.def("getServerWorld", &py_getServerWorld); + m.def("getTime", &py_getTime); + m.def("serverLog", &py_serverLog); + m.def("setDayLength", &py_setDayLength); + m.def("setServerDescription", &py_setServerDescription); + m.def("setServerWorld", &py_setServerWorld); + m.def("setTime", &py_setTime, py::arg(), py::arg(), py::arg() = 0); + + m.def("clearNpcActions", &py_clearNpcActions); + m.def("createNpc", &py_createNpc, py::arg(), py::arg() = "PC_HERO"); + m.def("destroyNpc", &py_destroyNpc); + m.def("getNpcAction", &py_getNpcAction); + // m.def("getNpcActionType", &py_getNpcActionType); + m.def("getNpcActtions", &py_getNpcActions); + m.def("getNpcActtionsCount", &py_getNpcActionsCount); + m.def("getNpcHostPlayer", &py_getNpcHostPlayer); + m.def("getNpcLastActionId", &py_getNpcLastActionId); + m.def("isNpc", &py_isNpc); + m.def("isNpcActionFinished", &py_isNpcActionFinished); + m.def("npcAttackMelee", &py_npcAttackMelee); + m.def("npcAttackRanged", &py_npcAttackRanged); + m.def("npcSpellCast", &py_npcSpellCast); + m.def("npcUseClosestMob", &py_npcUseClosestMob); + // m.def("pushNpcAction", &py_pushNpcAction); + m.def("setNpcHostPlayer", &py_setNpcHostPlayer); + + m.def("addBan", &py_addBan); + m.def("applyPlayerOverlay", &py_applyPlayerOverlay); + m.def("ban", &py_ban, py::arg(), py::arg() = 0, py::arg()); + m.def("drawWeapon", &py_drawWeapon); + m.def("equipItem", &py_equipItem, py::arg(), py::arg(), py::arg() = -1); + m.def("getPlayerAmulet", &py_getPlayerAmulet); + m.def("getPlayerAngle", &py_getPlayerAngle); + m.def("getPlayerAni", &py_getPlayerAni); + m.def("getPlayerArmor", &py_getPlayerArmor); + m.def("getPlayerAtVector", &py_getPlayerAtVector); + m.def("getPlayerBelt", &py_getPlayerBelt); + m.def("getPlayerCameraPosition",&py_getPlayerCameraPosition); + m.def("getPlayerCollision", &py_getPlayerCollision); + m.def("getPlayerColor", &py_getPlayerColor); + m.def("getPlayerContext", &py_getPlayerContext); + m.def("getPlayerDexterity", &py_getPlayerDexterity); + m.def("getPlayerFaceAnis", &py_getPlayerFaceAnis); + m.def("getPlayerFatness", &py_getPlayerFatness); + m.def("getPlayerFocus", &py_getPlayerFocus); + m.def("getPlayerHealth", &py_getPlayerHealth); + m.def("getPlayerHelmet", &py_getPlayerHelmet); + m.def("getPlayerIP", &py_getPlayerIP); + m.def("getPlayerInstance", &py_getPlayerInstance); + m.def("getPlayerMacAddr", &py_getPlayerMacAddr); + m.def("getPlayerMana", &py_getPlayerMana); + m.def("getPlayerMaxHealth", &py_getPlayerMaxHealth); + m.def("getPlayerMaxMana", &py_getPlayerMaxMana); + m.def("getPlayerMeleeWeapon", &py_getPlayerMeleeWeapon); + m.def("getPlayerName", &py_getPlayerName); + m.def("getPlayerPing", &py_getPlayerPing); + m.def("getPlayerPosition", &py_getPlayerPosition); + m.def("getPlayerRangedWeapon", &py_getPlayerRangedWeapon); + m.def("getPlayerRespawnTime", &py_getPlayerRespawnTime); + m.def("getPlayerRing", &py_getPlayerRing); + m.def("getPlayerScale", &py_getPlayerScale); + m.def("getPlayerSerial", &py_getPlayerSerial); + m.def("getPlayerShield", &py_getPlayerShield); + m.def("getPlayerSkillWeapon", &py_getPlayerSkillWeapon); + m.def("getPlayerSpell", &py_getPlayerSpell); + m.def("getPlayerStrength", &py_getPlayerStrength); + m.def("getPlayerTalent", &py_getPlayerTalent); + m.def("getPlayerVirtualWorld", &py_getPlayerVirtualWorld); + m.def("getPlayerVisual", &py_getPlayerVisual); + m.def("getPlayerWeaponMode", &py_getPlayerWeaponMode); + m.def("getPlayerWorld", &py_getPlayerWorld); + m.def("giveItem", &py_giveItem); + m.def("hitPlayer", &py_hitPlayer); + m.def("isPlayerConnected", &py_isPlayerConnected); + m.def("isPlayerDead", &py_isPlayerDead); + m.def("isPlayerUnconscious", &py_isPlayerUnconscious); + m.def("kick", &py_kick); + m.def("playAni", &py_playAni); + m.def("playFaceAni", &py_playFaceAni); + m.def("readySpell", &py_readySpell); + m.def("removeItem", &py_removeItem); + m.def("removePlayerOverlay", &py_removePlayerOverlay); + m.def("removeWeapon", &py_removeWeapon); + m.def("respawnPlayer", &py_respawnPlayer); + m.def("setPlayerAngle", &py_setPlayerAngle); + m.def("setPlayerCollision", &py_setPlayerCollision); + m.def("setPlayerColor", &py_setPlayerColor); + m.def("setPlayerContext", &py_setPlayerContext); + m.def("setPlayerDexterity", &py_setPlayerDexterity); + m.def("setPlayerFatness", &py_setPlayerFatness); + m.def("setPlayerHealth", &py_setPlayerHealth); + m.def("setPlayerInstance", &py_setPlayerInstance); + m.def("setPlayerInvisible", &py_setPlayerInvisible); + m.def("setPlayerMana", &py_setPlayerMana); + m.def("setPlayerMaxHealth", &py_setPlayerMaxHealth); + m.def("setPlayerMaxMana", &py_setPlayerMaxMana); + m.def("setPlayerName", &py_setPlayerName); + m.def("setPlayerPosition", &py_setPlayerPosition); + m.def("setPlayerRespawnTime", &py_setPlayerRespawnTime); + m.def("setPlayerScale", &py_setPlayerScale); + m.def("setPlayerSkillWeapon", &py_setPlayerSkillWeapon); + m.def("setPlayerStrength", &py_setPlayerStrength); + m.def("setPlayerTalent", &py_setPlayerTalent); + m.def("setPlayerVirtualWorld", &py_setPlayerVirtualWorld); + m.def("setPlayerVisual", &py_setPlayerVisual); + m.def("setPlayerWeaponMode", &py_setPlayerWeaponMode); + m.def("setPlayerWorld", &py_setPlayerWorld); + m.def("spawnPlayer", &py_spawnPlayer); + m.def("stopAni", &py_stopAni, py::arg(), py::arg() = ""); + m.def("stopFaceAni", &py_stopFaceAni, py::arg(), py::arg() = ""); + m.def("unequipItem", &py_unequipItem); + m.def("unreadySpell", &py_unreadySpell); + m.def("unspawnPlayer", &py_unspawnPlayer); + m.def("useItem", &py_useItem); + m.def("useItemToState", &py_useItemToState); + + m.def("findNearbyPlayers", &py_findNearbyPlayers); + m.def("getSpawnedPlayersForPlayer", &py_getSpawnedPlayersForPlayer); + m.def("getStreamedPlayersByPlayer", &py_getStreamedPlayersByPlayer); + + m.def("getNearestWaypoint", &py_getNearestWaypoint); + m.def("getWaypoint", &py_getWaypoint); } \ No newline at end of file diff --git a/src/classes/sq/Daedalus.h b/src/classes/sq/Daedalus.h index bb80d5d..6c6145b 100644 --- a/src/classes/sq/Daedalus.h +++ b/src/classes/sq/Daedalus.h @@ -14,7 +14,7 @@ namespace nonut Function index; Function symbol; - Function instance; + Function instance; private: diff --git a/src/events/sqevents_player.cpp b/src/events/sqevents_player.cpp index c30593e..8f261fd 100644 --- a/src/events/sqevents_player.cpp +++ b/src/events/sqevents_player.cpp @@ -270,7 +270,9 @@ SQInteger sq_onPlayerShoot(HSQUIRRELVM vm) const SQChar* munition; nonut::sqGetValue(vm, 2, &playerid); - nonut::sqGetValue(vm, 3, &munition); + if (sq_gettype(vm, 3) != OT_NULL) + nonut::sqGetValue(vm, 3, &munition); + py::dict kwargs = py::dict("playerid"_a=playerid, "munition"_a=munition); callEvent("onPlayerShoot", kwargs); @@ -284,7 +286,8 @@ SQInteger sq_onPlayerSpellCast(HSQUIRRELVM vm) const SQChar* instance; nonut::sqGetValue(vm, 2, &playerid); - nonut::sqGetValue(vm, 3, &instance); + if (sq_gettype(vm, 3) != OT_NULL) + nonut::sqGetValue(vm, 3, &instance); py::dict kwargs = py::dict("playerid"_a=playerid, "instance"_a=instance); callEvent("onPlayerSpellCast", kwargs); @@ -298,7 +301,8 @@ SQInteger sq_onPlayerSpellSetup(HSQUIRRELVM vm) const SQChar* instance; nonut::sqGetValue(vm, 2, &playerid); - nonut::sqGetValue(vm, 3, &instance); + if (sq_gettype(vm, 3) != OT_NULL) + nonut::sqGetValue(vm, 3, &instance); py::dict kwargs = py::dict("playerid"_a=playerid, "instance"_a=instance); callEvent("onPlayerSpellSetup", kwargs); @@ -355,10 +359,11 @@ SQInteger sq_onPlayerToggleFaceAni(HSQUIRRELVM vm) SQInteger sq_onPlayerEquipAmulet(HSQUIRRELVM vm) { SQInteger playerid; - const SQChar* instance; + const SQChar* instance = ""; nonut::sqGetValue(vm, 2, &playerid); - nonut::sqGetValue(vm, 3, &instance); + if (sq_gettype(vm, 3) != OT_NULL) + nonut::sqGetValue(vm, 3, &instance); py::dict kwargs = py::dict("playerid"_a=playerid, "instance"_a=instance); callEvent("onPlayerEquipAmulet", kwargs); @@ -369,10 +374,11 @@ SQInteger sq_onPlayerEquipAmulet(HSQUIRRELVM vm) SQInteger sq_onPlayerEquipArmor(HSQUIRRELVM vm) { SQInteger playerid; - const SQChar* instance; + const SQChar* instance = ""; nonut::sqGetValue(vm, 2, &playerid); - nonut::sqGetValue(vm, 3, &instance); + if (sq_gettype(vm, 3) != OT_NULL) + nonut::sqGetValue(vm, 3, &instance); py::dict kwargs = py::dict("playerid"_a=playerid, "instance"_a=instance); callEvent("onPlayerEquipArmor", kwargs); @@ -383,10 +389,11 @@ SQInteger sq_onPlayerEquipArmor(HSQUIRRELVM vm) SQInteger sq_onPlayerEquipBelt(HSQUIRRELVM vm) { SQInteger playerid; - const SQChar* instance; + const SQChar* instance = ""; nonut::sqGetValue(vm, 2, &playerid); - nonut::sqGetValue(vm, 3, &instance); + if (sq_gettype(vm, 3) != OT_NULL) + nonut::sqGetValue(vm, 3, &instance); py::dict kwargs = py::dict("playerid"_a=playerid, "instance"_a=instance); callEvent("onPlayerEquipBelt", kwargs); @@ -397,11 +404,12 @@ SQInteger sq_onPlayerEquipBelt(HSQUIRRELVM vm) SQInteger sq_onPlayerEquipHandItem(HSQUIRRELVM vm) { SQInteger playerid, hand; - const SQChar* instance; + const SQChar* instance = ""; nonut::sqGetValue(vm, 2, &playerid); nonut::sqGetValue(vm, 3, &hand); - nonut::sqGetValue(vm, 4, &instance); + if (sq_gettype(vm, 4) != OT_NULL) + nonut::sqGetValue(vm, 4, &instance); py::dict kwargs = py::dict("playerid"_a=playerid, "hand"_a = hand, "instance"_a=instance); callEvent("onPlayerEquipHandItem", kwargs); @@ -412,10 +420,11 @@ SQInteger sq_onPlayerEquipHandItem(HSQUIRRELVM vm) SQInteger sq_onPlayerEquipHelmet(HSQUIRRELVM vm) { SQInteger playerid; - const SQChar* instance; + const SQChar* instance = ""; nonut::sqGetValue(vm, 2, &playerid); - nonut::sqGetValue(vm, 3, &instance); + if (sq_gettype(vm, 3) != OT_NULL) + nonut::sqGetValue(vm, 3, &instance); py::dict kwargs = py::dict("playerid"_a=playerid, "instance"_a=instance); callEvent("onPlayerEquipHelmet", kwargs); @@ -426,10 +435,11 @@ SQInteger sq_onPlayerEquipHelmet(HSQUIRRELVM vm) SQInteger sq_onPlayerEquipMeleeWeapon(HSQUIRRELVM vm) { SQInteger playerid; - const SQChar* instance; + const SQChar* instance = ""; nonut::sqGetValue(vm, 2, &playerid); - nonut::sqGetValue(vm, 3, &instance); + if (sq_gettype(vm, 3) != OT_NULL) + nonut::sqGetValue(vm, 3, &instance); py::dict kwargs = py::dict("playerid"_a=playerid, "instance"_a=instance); callEvent("onPlayerEquipMeleeWeapon", kwargs); @@ -440,10 +450,11 @@ SQInteger sq_onPlayerEquipMeleeWeapon(HSQUIRRELVM vm) SQInteger sq_onPlayerEquipRangedWeapon(HSQUIRRELVM vm) { SQInteger playerid; - const SQChar* instance; + const SQChar* instance = ""; nonut::sqGetValue(vm, 2, &playerid); - nonut::sqGetValue(vm, 3, &instance); + if (sq_gettype(vm, 3) != OT_NULL) + nonut::sqGetValue(vm, 3, &instance); py::dict kwargs = py::dict("playerid"_a=playerid, "instance"_a=instance); callEvent("onPlayerEquipRangedWeapon", kwargs); @@ -454,11 +465,12 @@ SQInteger sq_onPlayerEquipRangedWeapon(HSQUIRRELVM vm) SQInteger sq_onPlayerEquipRing(HSQUIRRELVM vm) { SQInteger playerid, hand; - const SQChar* instance; + const SQChar* instance = ""; nonut::sqGetValue(vm, 2, &playerid); nonut::sqGetValue(vm, 3, &hand); - nonut::sqGetValue(vm, 4, &instance); + if (sq_gettype(vm, 4) != OT_NULL) + nonut::sqGetValue(vm, 4, &instance); py::dict kwargs = py::dict("playerid"_a=playerid, "hand"_a = hand, "instance"_a=instance); callEvent("onPlayerEquipRing", kwargs); @@ -469,10 +481,11 @@ SQInteger sq_onPlayerEquipRing(HSQUIRRELVM vm) SQInteger sq_onPlayerEquipShield(HSQUIRRELVM vm) { SQInteger playerid; - const SQChar* instance; + const SQChar* instance = ""; nonut::sqGetValue(vm, 2, &playerid); - nonut::sqGetValue(vm, 3, &instance); + if (sq_gettype(vm, 3) != OT_NULL) + nonut::sqGetValue(vm, 3, &instance); py::dict kwargs = py::dict("playerid"_a=playerid, "instance"_a=instance); callEvent("onPlayerEquipShield", kwargs); @@ -483,11 +496,12 @@ SQInteger sq_onPlayerEquipShield(HSQUIRRELVM vm) SQInteger sq_onPlayerEquipSpell(HSQUIRRELVM vm) { SQInteger playerid, slotId; - const SQChar* instance; + const SQChar* instance = ""; nonut::sqGetValue(vm, 2, &playerid); nonut::sqGetValue(vm, 3, &slotId); - nonut::sqGetValue(vm, 4, &instance); + if (sq_gettype(vm, 4) != OT_NULL) + nonut::sqGetValue(vm, 4, &instance); py::dict kwargs = py::dict("playerid"_a=playerid, "slotId"_a = slotId, "instance"_a=instance); callEvent("onPlayerEquipSpell", kwargs); diff --git a/src/functions/pyfunctions.cpp b/src/functions/pyfunctions.cpp new file mode 100644 index 0000000..828144e --- /dev/null +++ b/src/functions/pyfunctions.cpp @@ -0,0 +1,185 @@ +#include +#include +#include "pyfunctions.h" +#include "sqfunctions.h" +#include "classes/Dictionary.h" +#include +namespace py = pybind11; +#define SERVERFUNC nonut::ServerFunctions::getInstance() + +std::string py_getHostname() { return SERVERFUNC->getHostname(); } +int py_getMaxSlots() { return SERVERFUNC->getMaxSlots(); } +int py_getPlayersCount() { return SERVERFUNC->getPlayersCount(); } + +float py_getDistance2d(float x1, float y1, float x2, float y2) { return SERVERFUNC->getDistance2d(x1, y1, x2, y2); } +float py_getDistance3d(float x1, float y1, float z1, float x2, float y2, float z2) { return SERVERFUNC->getDistance3d(x1, y1, z1, x2, y2, z2); } +float py_getVectorAngle(float x1, float y1, float x2, float y2) { return SERVERFUNC->getVectorAngle(x1, y1, x2, y2); } + +void py_sendMessageToAll(int r, int g, int b, std::string text) { return SERVERFUNC->sendMessageToAll(r, g, b, text); } +void py_sendMessageToPlayer(int id, int r, int g, int b, std::string text) { return SERVERFUNC->sendMessageToPlayer(id, r, g, b, text); } +void py_sendPlayerMessageToAll(int id, int r, int g, int b, std::string text) { return SERVERFUNC->sendPlayerMessageToAll(id, r, g, b, text); } +void py_sendPlayerMessageToPlayer(int id, int to, int r, int g, int b, std::string text) { return SERVERFUNC->sendPlayerMessageToPlayer(id, to, r, g, b, text); } + +void py_exit(int code) { return SERVERFUNC->exit(code); } +float py_getDayLength() { return SERVERFUNC->getDayLength(); } +std::string py_getServerDescription() { return SERVERFUNC->getServerDescription(); } +std::string py_getServerWorld() { return SERVERFUNC->getServerWorld(); } +py::dict py_getTime() { return SERVERFUNC->getTime().data; } +void py_serverLog(std::string text) { return SERVERFUNC->serverLog(text); } +void py_setDayLength(float ms) { return SERVERFUNC->setDayLength(ms); } +bool py_setServerDescription(std::string text) { return SERVERFUNC->setServerDescription(text); } +void py_setServerWorld(std::string text) { return SERVERFUNC->setServerWorld(text); } +void py_setTime(int h, int m, int d) { return SERVERFUNC->setTime(h, m, d); } + +void py_clearNpcActions(int npc_id) { return SERVERFUNC->clearNpcActions(npc_id); } +int py_createNpc(std::string name, std::string instance) { return SERVERFUNC->createNpc(name, instance); } +bool py_destroyNpc(int npc_id) { return SERVERFUNC->destroyNpc(npc_id); } +py::dict py_getNpcAction(int npc_id, int index) { return SERVERFUNC->getNpcAction(npc_id, index).data; } +// ??? py_getNpcActionType +py::list py_getNpcActions(int npc_id) { return SERVERFUNC->getNpcActions(npc_id).data; } +int py_getNpcActionsCount(int npc_id) { return SERVERFUNC->getNpcActionsCount(npc_id); } +int py_getNpcHostPlayer(int npc_id) { return SERVERFUNC->getNpcHostPlayer(npc_id); } +int py_getNpcLastActionId(int npc_id) { return SERVERFUNC->getNpcLastActionId(npc_id); } +bool py_isNpc(int npc_id) { return SERVERFUNC->isNpc(npc_id); } +bool py_isNpcActionFinished(int npc_id, int action_id) { return SERVERFUNC->isNpcActionFinished(npc_id, action_id); } +void py_npcAttackMelee(int a_id, int e_id, int a_type, int combo) { return SERVERFUNC->npcAttackMelee(a_id, e_id, a_type, combo); } +void py_npcAttackRanged(int a_id, int e_id) { return SERVERFUNC->npcAttackRanged(a_id, e_id); } +void py_npcSpellCast(int a_id, int e_id) { return SERVERFUNC->npcSpellCast(a_id, e_id); } +void py_npcUseClosestMob(int npc_id, std::string sceme, int target_state) { return SERVERFUNC->npcUseClosestMob(npc_id, sceme, target_state); } +//??? py_pushNpcAction +bool py_setNpcHostPlayer(int npc_id, int host_id) { return SERVERFUNC->setNpcHostPlayer(npc_id, host_id); } + +bool py_addBan(py::dict info) +{ + Sqrat::Table* pTable = PyDictionary::toSqObject(info); + nonut::Int result = SERVERFUNC->addBan(pTable->GetObject()); + delete pTable; + return result; +} +bool py_applyPlayerOverlay(int id, int overlayId) { return SERVERFUNC->applyPlayerOverlay(id, overlayId); } +void py_ban(int id, int minutes, std::string reason) { return SERVERFUNC->ban(id, minutes, reason); } +void py_drawWeapon(int id, int weaponMode) { return SERVERFUNC->drawWeapon(id, weaponMode); } +void py_equipItem(int id, std::string instance, int slotId) { return SERVERFUNC->equipItem(id, instance, slotId); } +std::string py_getPlayerAmulet(int id) { return SERVERFUNC->getPlayerAmulet(id); } +float py_getPlayerAngle(int id) { return SERVERFUNC->getPlayerAngle(id); } +std::string py_getPlayerAni(int id) { return SERVERFUNC->getPlayerAni(id); } +std::string py_getPlayerArmor(int id) { return SERVERFUNC->getPlayerArmor(id); } +py::dict py_getPlayerAtVector(int id) +{ + py::dict result; + nonut::Position3d pos = SERVERFUNC->getPlayerAtVector(id); + + result["x"] = pos.x; + result["y"] = pos.y; + result["z"] = pos.z; + return result; +} +std::string py_getPlayerBelt(int id) { return SERVERFUNC->getPlayerBelt(id); } +py::dict py_getPlayerCameraPosition(int id) +{ + py::dict result; + nonut::Position3d pos = SERVERFUNC->getPlayerCameraPosition(id); + + result["x"] = pos.x; + result["y"] = pos.y; + result["z"] = pos.z; + return result; +} +bool py_getPlayerCollision(int id) { return SERVERFUNC->getPlayerCollision(id); } +py::dict py_getPlayerColor(int id) +{ + py::dict result; + nonut::Color pos = SERVERFUNC->getPlayerColor(id); + + result["r"] = pos.r; + result["g"] = pos.g; + result["b"] = pos.b; + return result; +} +int py_getPlayerContext(int id, int type) { return SERVERFUNC->getPlayerContext(id, type); } +int py_getPlayerDexterity(int id) { return SERVERFUNC->getPlayerDexterity(id); } +py::list py_getPlayerFaceAnis(int id) { return SERVERFUNC->getPlayerFaceAnis(id).data; } +float py_getPlayerFatness(int id) { return SERVERFUNC->getPlayerFatness(id); } +int py_getPlayerFocus(int id) { return SERVERFUNC->getPlayerFocus(id); } +int py_getPlayerHealth(int id) { return SERVERFUNC->getPlayerHealth(id); } +std::string py_getPlayerHelmet(int id) { return SERVERFUNC->getPlayerHelmet(id); } +std::string py_getPlayerIP(int id) { return SERVERFUNC->getPlayerIP(id); } +std::string py_getPlayerInstance(int id) { return SERVERFUNC->getPlayerInstance(id); } +std::string py_getPlayerMacAddr(int id) { return SERVERFUNC->getPlayerMacAddr(id); } +int py_getPlayerMana(int id) { return SERVERFUNC->getPlayerMana(id); } +int py_getPlayerMaxHealth(int id) { return SERVERFUNC->getPlayerMaxHealth(id); } +int py_getPlayerMaxMana(int id) { return SERVERFUNC->getPlayerMaxMana(id); } +std::string py_getPlayerMeleeWeapon(int id) { return SERVERFUNC->getPlayerMeleeWeapon(id); } +std::string py_getPlayerName(int id) { return SERVERFUNC->getPlayerName(id); } +int py_getPlayerPing(int id) { return SERVERFUNC->getPlayerPing(id); } +py::dict py_getPlayerPosition(int id) { return SERVERFUNC->getPlayerPosition(id).data; } +std::string py_getPlayerRangedWeapon(int id) { return SERVERFUNC->getPlayerRangedWeapon(id); } +int py_getPlayerRespawnTime(int id) { return SERVERFUNC->getPlayerRespawnTime(id); } +std::string py_getPlayerRing(int id, int handId) { return SERVERFUNC->getPlayerRing(id, handId); } +py::dict py_getPlayerScale(int id) { return SERVERFUNC->getPlayerScale(id).data; } +std::string py_getPlayerSerial(int id) { return SERVERFUNC->getPlayerSerial(id); } +std::string py_getPlayerShield(int id) { return SERVERFUNC->getPlayerShield(id); } +int py_getPlayerSkillWeapon(int id, int skillId) { return SERVERFUNC->getPlayerSkillWeapon(id, skillId); } +std::string py_getPlayerSpell(int id, int slotId) { return SERVERFUNC->getPlayerSpell(id, slotId); } +int py_getPlayerStrength(int id) { return SERVERFUNC->getPlayerStrength(id); } +int py_getPlayerTalent(int id, int talentId) { return SERVERFUNC->getPlayerTalent(id, talentId); } +int py_getPlayerVirtualWorld(int id) { return SERVERFUNC->getPlayerVirtualWorld(id); } +py::dict py_getPlayerVisual(int id) { return SERVERFUNC->getPlayerVisual(id).data; } +int py_getPlayerWeaponMode(int id) { return SERVERFUNC->getPlayerWeaponMode(id); } +std::string py_getPlayerWorld(int id) { return SERVERFUNC->getPlayerWorld(id); } +void py_giveItem(int id, std::string instance, int amount) { return SERVERFUNC->giveItem(id, instance, amount); } +bool py_hitPlayer(int id, int targetid) { return SERVERFUNC->hitPlayer(id, targetid); } +bool py_isPlayerConnected(int id) { return SERVERFUNC->isPlayerConnected(id); } +bool py_isPlayerDead(int id) { return SERVERFUNC->isPlayerDead(id); } +bool py_isPlayerUnconscious(int id) { return SERVERFUNC->isPlayerUnconscious(id); } +void py_kick(int id, std::string reason) { return SERVERFUNC->kick(id, reason); } +void py_playAni(int id, std::string aniName) { return SERVERFUNC->playAni(id, aniName); } +void py_playFaceAni(int id, std::string aniName) { return SERVERFUNC->playFaceAni(id, aniName); } +void py_readySpell(int id, int slotId, int manaInvested) { return SERVERFUNC->readySpell(id, slotId, manaInvested); } +void py_removeItem(int id, std::string instance, int amount) { return SERVERFUNC->removeItem(id, instance, amount); } +bool py_removePlayerOverlay(int id, int overlayId) { return SERVERFUNC->removePlayerOverlay(id, overlayId); } +void py_removeWeapon(int id) { return SERVERFUNC->removeWeapon(id); } +void py_respawnPlayer(int id) { return SERVERFUNC->respawnPlayer(id); } +void py_setPlayerAngle(int id, float angle) { return SERVERFUNC->setPlayerAngle(id, angle); } +void py_setPlayerCollision(int id, bool collision) { return SERVERFUNC->setPlayerCollision(id, collision); } +void py_setPlayerColor(int id, int r, int g, int b) { return SERVERFUNC->setPlayerColor(id, r, g, b); } +void py_setPlayerContext(int id, int type, int value) { return SERVERFUNC->setPlayerContext(id, type, value); } +void py_setPlayerDexterity(int id, int dexterity) { return SERVERFUNC->setPlayerDexterity(id, dexterity); } +void py_setPlayerFatness(int id, float fatness) { return SERVERFUNC->setPlayerFatness(id, fatness); } +void py_setPlayerHealth(int id, int health) { return SERVERFUNC->setPlayerHealth(id, health); } +void py_setPlayerInstance(int id, std::string instance) { return SERVERFUNC->setPlayerInstance(id, instance); } +void py_setPlayerInvisible(int id, bool toggle) { return SERVERFUNC->setPlayerInvisible(id, toggle); } +void py_setPlayerMana(int id, int mana) { return SERVERFUNC->setPlayerMana(id, mana); } +void py_setPlayerMaxHealth(int id, int maxHealth) { return SERVERFUNC->setPlayerMaxHealth(id, maxHealth); } +void py_setPlayerMaxMana(int id, int maxMana) { return SERVERFUNC->setPlayerMaxMana(id, maxMana); } +void py_setPlayerName(int id, std::string name) { return SERVERFUNC->setPlayerName(id, name); } +void py_setPlayerPosition(int id, float x, float y, float z) { return SERVERFUNC->setPlayerPosition(id, x, y, z); } +void py_setPlayerRespawnTime(int id, int respawnTime) { return SERVERFUNC->setPlayerRespawnTime(id, respawnTime); } +void py_setPlayerScale(int id, float x, float y, float z) { return SERVERFUNC->setPlayerScale(id, x, y, z); } +void py_setPlayerSkillWeapon(int id, int skillId, int percentage) { return SERVERFUNC->setPlayerSkillWeapon(id, skillId, percentage); } +void py_setPlayerStrength(int id, int strength) { return SERVERFUNC->setPlayerStrength(id, strength); } +void py_setPlayerTalent(int id, int talentId, int talentValue) { return SERVERFUNC->setPlayerTalent(id, talentId, talentValue); } +void py_setPlayerVirtualWorld(int id, int virtualWorld) { return SERVERFUNC->setPlayerVirtualWorld(id, virtualWorld); } +void py_setPlayerVisual(int id, std::string bMdl, int bTxt, std::string hMdl, int hTxt) { return SERVERFUNC->setPlayerVisual(id, bMdl, bTxt, hMdl, hTxt); } +void py_setPlayerWeaponMode(int id, int weaponMode) { return SERVERFUNC->setPlayerWeaponMode(id, weaponMode); } +void py_setPlayerWorld(int id, std::string world, std::string startPointName) { return SERVERFUNC->setPlayerWorld(id, world, startPointName); } +void py_spawnPlayer(int id) { return SERVERFUNC->spawnPlayer(id); } +void py_stopAni(int id, std::string aniName) { return SERVERFUNC->stopAni(id, aniName); } +void py_stopFaceAni(int id, std::string aniName) { return SERVERFUNC->stopFaceAni(id, aniName); } +void py_unequipItem(int id, std::string instance) { return SERVERFUNC->unequipItem(id, instance); } +void py_unreadySpell(int id) { return SERVERFUNC->unreadySpell(id); } +void py_unspawnPlayer(int id) { return SERVERFUNC->unspawnPlayer(id); } +void py_useItem(int id, std::string instance) { return SERVERFUNC->useItem(id, instance); } +void py_useItemToState(int id, std::string instance, int state) { return SERVERFUNC->useItemToState(id, instance, state); } + +py::list py_findNearbyPlayers(py::dict position, int radius, std::string world, int vWorld) +{ + Sqrat::Table* pTable = PyDictionary::toSqObject(position); + py::list result = SERVERFUNC->findNearbyPlayers(pTable->GetObject(), radius, world, vWorld).data; + delete pTable; + return result; +} +py::list py_getSpawnedPlayersForPlayer(int id) { return SERVERFUNC->getSpawnedPlayersForPlayer(id).data; } +py::list py_getStreamedPlayersByPlayer(int id) { return SERVERFUNC->getStreamedPlayersByPlayer(id).data; } +py::dict py_getNearestWaypoint(std::string world, int x, int y, int z) { return SERVERFUNC->getNearestWaypoint(world, x, y, z).data; } +py::dict py_getWaypoint(std::string world, std::string name) { return SERVERFUNC->getWaypoint(world, name).data; } \ No newline at end of file diff --git a/src/functions/pyfunctions.h b/src/functions/pyfunctions.h new file mode 100644 index 0000000..539d686 --- /dev/null +++ b/src/functions/pyfunctions.h @@ -0,0 +1,146 @@ +#ifndef _PYFUNCTIONS_ +#define _PYFUNCTIONS_ + +#include +namespace py = pybind11; + +// Shared functions +std::string py_getHostname(); +int py_getMaxSlots(); +int py_getPlayersCount(); + +float py_getDistance2d(float, float, float, float); +float py_getDistance3d(float, float, float, float, float, float); +float py_getVectorAngle(float, float, float, float); + +void py_sendMessageToAll(int, int, int, std::string); +void py_sendMessageToPlayer(int, int, int, int, std::string); +void py_sendPlayerMessageToAll(int, int, int, int, std::string); +void py_sendPlayerMessageToPlayer(int, int, int, int, int, std::string); + +void py_exit(int); +float py_getDayLength(); +std::string py_getServerDescription(); +std::string py_getServerWorld(); +py::dict py_getTime(); +void py_serverLog(std::string); +void py_setDayLength(float); +bool py_setServerDescription(std::string); +void py_setServerWorld(std::string); +void py_setTime(int, int, int); + +void py_clearNpcActions(int); +int py_createNpc(std::string, std::string); +bool py_destroyNpc(int); +py::dict py_getNpcAction(int, int); +// ??? py_getNpcActionType +py::list py_getNpcActions(int); +int py_getNpcActionsCount(int); +int py_getNpcHostPlayer(int); +int py_getNpcLastActionId(int); +bool py_isNpc(int); +bool py_isNpcActionFinished(int, int); +void py_npcAttackMelee(int, int, int, int); +void py_npcAttackRanged(int, int); +void py_npcSpellCast(int, int); +void py_npcUseClosestMob(int, std::string, int); +//??? py_pushNpcAction +bool py_setNpcHostPlayer(int, int); + +bool py_addBan(py::dict); +bool py_applyPlayerOverlay(int, int); +void py_ban(int, int, std::string); +void py_drawWeapon(int, int); +void py_equipItem(int, std::string, int); +std::string py_getPlayerAmulet(int); +float py_getPlayerAngle(int); +std::string py_getPlayerAni(int); +std::string py_getPlayerArmor(int); +py::dict py_getPlayerAtVector(int); +std::string py_getPlayerBelt(int); +py::dict py_getPlayerCameraPosition(int); +bool py_getPlayerCollision(int); +py::dict py_getPlayerColor(int); +int py_getPlayerContext(int, int); +int py_getPlayerDexterity(int); +py::list py_getPlayerFaceAnis(int); +float py_getPlayerFatness(int); +int py_getPlayerFocus(int); +int py_getPlayerHealth(int); +std::string py_getPlayerHelmet(int); +std::string py_getPlayerIP(int); +std::string py_getPlayerInstance(int); +std::string py_getPlayerMacAddr(int); +int py_getPlayerMana(int); +int py_getPlayerMaxHealth(int); +int py_getPlayerMaxMana(int); +std::string py_getPlayerMeleeWeapon(int); +std::string py_getPlayerName(int); +int py_getPlayerPing(int); +py::dict py_getPlayerPosition(int); +std::string py_getPlayerRangedWeapon(int); +int py_getPlayerRespawnTime(int); +std::string py_getPlayerRing(int, int); +py::dict py_getPlayerScale(int); +std::string py_getPlayerSerial(int); +std::string py_getPlayerShield(int); +int py_getPlayerSkillWeapon(int, int); +std::string py_getPlayerSpell(int, int); +int py_getPlayerStrength(int); +int py_getPlayerTalent(int, int); +int py_getPlayerVirtualWorld(int); +py::dict py_getPlayerVisual(int); +int py_getPlayerWeaponMode(int); +std::string py_getPlayerWorld(int); +void py_giveItem(int, std::string, int); +bool py_hitPlayer(int, int); +bool py_isPlayerConnected(int); +bool py_isPlayerDead(int); +bool py_isPlayerUnconscious(int); +void py_kick(int, std::string); +void py_playAni(int, std::string); +void py_playFaceAni(int, std::string); +void py_readySpell(int, int, int); +void py_removeItem(int, std::string, int); +bool py_removePlayerOverlay(int, int); +void py_removeWeapon(int); +void py_respawnPlayer(int); +void py_setPlayerAngle(int, float); +void py_setPlayerCollision(int, bool); +void py_setPlayerColor(int, int, int, int); +void py_setPlayerContext(int, int, int); +void py_setPlayerDexterity(int, int); +void py_setPlayerFatness(int, float); +void py_setPlayerHealth(int, int); +void py_setPlayerInstance(int, std::string); +void py_setPlayerInvisible(int, bool); +void py_setPlayerMana(int, int); +void py_setPlayerMaxHealth(int, int); +void py_setPlayerMaxMana(int, int); +void py_setPlayerName(int, std::string); +void py_setPlayerPosition(int, float, float, float); +void py_setPlayerRespawnTime(int, int); +void py_setPlayerScale(int, float, float, float); +void py_setPlayerSkillWeapon(int, int, int); +void py_setPlayerStrength(int, int); +void py_setPlayerTalent(int, int, int); +void py_setPlayerVirtualWorld(int, int); +void py_setPlayerVisual(int, std::string, int, std::string, int); +void py_setPlayerWeaponMode(int, int); +void py_setPlayerWorld(int, std::string, std::string); +void py_spawnPlayer(int); +void py_stopAni(int, std::string); +void py_stopFaceAni(int, std::string); +void py_unequipItem(int, std::string); +void py_unreadySpell(int); +void py_unspawnPlayer(int); +void py_useItem(int, std::string); +void py_useItemToState(int, std::string, int); + +py::list py_findNearbyPlayers(py::dict, int, std::string, int); +py::list py_getSpawnedPlayersForPlayer(int); +py::list py_getStreamedPlayersByPlayer(int); +py::dict py_getNearestWaypoint(std::string, int, int, int); +py::dict py_getWaypoint(std::string, std::string); + +#endif \ No newline at end of file diff --git a/src/functions/sqfunctions.cpp b/src/functions/sqfunctions.cpp new file mode 100644 index 0000000..f5a43cb --- /dev/null +++ b/src/functions/sqfunctions.cpp @@ -0,0 +1,154 @@ +#include +#include "sqfunctions.h" + +namespace nonut +{ + ServerFunctions::ServerFunctions() : + FUNCTION_CTOR(getMaxSlots), + FUNCTION_CTOR(getHostname), + FUNCTION_CTOR(getPlayersCount), + + FUNCTION_CTOR(getDistance2d), + FUNCTION_CTOR(getDistance3d), + FUNCTION_CTOR(getVectorAngle), + + FUNCTION_CTOR(sendMessageToAll), + FUNCTION_CTOR(sendMessageToPlayer), + FUNCTION_CTOR(sendPlayerMessageToAll), + FUNCTION_CTOR(sendPlayerMessageToPlayer), + + FUNCTION_CTOR(exit), + FUNCTION_CTOR(getDayLength), + FUNCTION_CTOR(getServerDescription), + FUNCTION_CTOR(getServerWorld), + FUNCTION_CTOR(getTime), + FUNCTION_CTOR(serverLog), + FUNCTION_CTOR(setDayLength), + FUNCTION_CTOR(setServerDescription), + FUNCTION_CTOR(setServerWorld), + FUNCTION_CTOR(setTime), + + FUNCTION_CTOR(clearNpcActions), + FUNCTION_CTOR(createNpc), + FUNCTION_CTOR(destroyNpc), + FUNCTION_CTOR(getNpcAction), + //FUNCTION_CTOR(getNpcActionType), + FUNCTION_CTOR(getNpcActions), + FUNCTION_CTOR(getNpcActionsCount), + FUNCTION_CTOR(getNpcHostPlayer), + FUNCTION_CTOR(getNpcLastActionId), + FUNCTION_CTOR(isNpc), + FUNCTION_CTOR(isNpcActionFinished), + FUNCTION_CTOR(npcAttackMelee), + FUNCTION_CTOR(npcAttackRanged), + FUNCTION_CTOR(npcSpellCast), + FUNCTION_CTOR(npcUseClosestMob), + //FUNCTION_CTOR(pushNpcAction), + FUNCTION_CTOR(setNpcHostPlayer), + FUNCTION_CTOR(addBan), + FUNCTION_CTOR(applyPlayerOverlay), + FUNCTION_CTOR(ban), + FUNCTION_CTOR(drawWeapon), + FUNCTION_CTOR(equipItem), + FUNCTION_CTOR(getPlayerAmulet), + FUNCTION_CTOR(getPlayerAngle), + FUNCTION_CTOR(getPlayerAni), + FUNCTION_CTOR(getPlayerArmor), + FUNCTION_CTOR(getPlayerAtVector), + FUNCTION_CTOR(getPlayerBelt), + FUNCTION_CTOR(getPlayerCameraPosition), + FUNCTION_CTOR(getPlayerCollision), + FUNCTION_CTOR(getPlayerColor), + FUNCTION_CTOR(getPlayerContext), + FUNCTION_CTOR(getPlayerDexterity), + FUNCTION_CTOR(getPlayerFaceAnis), + FUNCTION_CTOR(getPlayerFatness), + FUNCTION_CTOR(getPlayerFocus), + FUNCTION_CTOR(getPlayerHealth), + FUNCTION_CTOR(getPlayerHelmet), + FUNCTION_CTOR(getPlayerIP), + FUNCTION_CTOR(getPlayerInstance), + FUNCTION_CTOR(getPlayerMacAddr), + FUNCTION_CTOR(getPlayerMana), + FUNCTION_CTOR(getPlayerMaxHealth), + FUNCTION_CTOR(getPlayerMaxMana), + FUNCTION_CTOR(getPlayerMeleeWeapon), + FUNCTION_CTOR(getPlayerName), + FUNCTION_CTOR(getPlayerPing), + FUNCTION_CTOR(getPlayerPosition), + FUNCTION_CTOR(getPlayerRangedWeapon), + FUNCTION_CTOR(getPlayerRespawnTime), + FUNCTION_CTOR(getPlayerRing), + FUNCTION_CTOR(getPlayerScale), + FUNCTION_CTOR(getPlayerSerial), + FUNCTION_CTOR(getPlayerShield), + FUNCTION_CTOR(getPlayerSkillWeapon), + FUNCTION_CTOR(getPlayerSpell), + FUNCTION_CTOR(getPlayerStrength), + FUNCTION_CTOR(getPlayerTalent), + FUNCTION_CTOR(getPlayerVirtualWorld), + FUNCTION_CTOR(getPlayerVisual), + FUNCTION_CTOR(getPlayerWeaponMode), + FUNCTION_CTOR(getPlayerWorld), + FUNCTION_CTOR(giveItem), + FUNCTION_CTOR(hitPlayer), + FUNCTION_CTOR(isPlayerConnected), + FUNCTION_CTOR(isPlayerDead), + FUNCTION_CTOR(isPlayerUnconscious), + FUNCTION_CTOR(kick), + FUNCTION_CTOR(playAni), + FUNCTION_CTOR(playFaceAni), + FUNCTION_CTOR(readySpell), + FUNCTION_CTOR(removeItem), + FUNCTION_CTOR(removePlayerOverlay), + FUNCTION_CTOR(removeWeapon), + FUNCTION_CTOR(respawnPlayer), + FUNCTION_CTOR(setPlayerAngle), + FUNCTION_CTOR(setPlayerCollision), + FUNCTION_CTOR(setPlayerColor), + FUNCTION_CTOR(setPlayerContext), + FUNCTION_CTOR(setPlayerDexterity), + FUNCTION_CTOR(setPlayerFatness), + FUNCTION_CTOR(setPlayerHealth), + FUNCTION_CTOR(setPlayerInstance), + FUNCTION_CTOR(setPlayerInvisible), + FUNCTION_CTOR(setPlayerMana), + FUNCTION_CTOR(setPlayerMaxHealth), + FUNCTION_CTOR(setPlayerMaxMana), + FUNCTION_CTOR(setPlayerName), + FUNCTION_CTOR(setPlayerPosition), + FUNCTION_CTOR(setPlayerRespawnTime), + FUNCTION_CTOR(setPlayerScale), + FUNCTION_CTOR(setPlayerSkillWeapon), + FUNCTION_CTOR(setPlayerStrength), + FUNCTION_CTOR(setPlayerTalent), + FUNCTION_CTOR(setPlayerVirtualWorld), + FUNCTION_CTOR(setPlayerVisual), + FUNCTION_CTOR(setPlayerWeaponMode), + FUNCTION_CTOR(setPlayerWorld), + FUNCTION_CTOR(spawnPlayer), + FUNCTION_CTOR(stopAni), + FUNCTION_CTOR(stopFaceAni), + FUNCTION_CTOR(unequipItem), + FUNCTION_CTOR(unreadySpell), + FUNCTION_CTOR(unspawnPlayer), + FUNCTION_CTOR(useItem), + FUNCTION_CTOR(useItemToState), + + FUNCTION_CTOR(findNearbyPlayers), + FUNCTION_CTOR(getSpawnedPlayersForPlayer), + FUNCTION_CTOR(getStreamedPlayersByPlayer), + FUNCTION_CTOR(getNearestWaypoint), + FUNCTION_CTOR(getWaypoint) + {} + + ServerFunctions* ServerFunctions::getInstance() + { + if (instance == nullptr) + { + instance = new ServerFunctions(); + } + return instance; + } + +} \ No newline at end of file diff --git a/src/functions/sqfunctions.h b/src/functions/sqfunctions.h new file mode 100644 index 0000000..8fb2b6d --- /dev/null +++ b/src/functions/sqfunctions.h @@ -0,0 +1,160 @@ +#ifndef _SQFUNCTIONS_ +#define _SQFUNCTIONS_ + +#include +#include + +namespace nonut +{ + class ServerFunctions + { + protected: + ServerFunctions(); + static inline ServerFunctions* instance = nullptr; + public: + ServerFunctions(ServerFunctions& other) = delete; + void operator=(const ServerFunctions&) = delete; + static ServerFunctions* getInstance(); + + Function getHostname; + Function getMaxSlots; + Function getPlayersCount; + + Function getDistance2d; + Function getDistance3d; + Function getVectorAngle; + + Function sendMessageToAll; + Function sendMessageToPlayer; + Function sendPlayerMessageToAll; + Function sendPlayerMessageToPlayer; + + Function exit; + Function getDayLength; + Function getServerDescription; + Function getServerWorld; + Function getTime; + Function serverLog; + Function setDayLength; + Function setServerDescription; + Function setServerWorld; + Function setTime; + + Function clearNpcActions; + Function createNpc; + Function destroyNpc; + Function getNpcAction; + //Function getNpcActionType; + Function getNpcActions; + Function getNpcActionsCount; + Function getNpcHostPlayer; + Function getNpcLastActionId; + Function isNpc; + Function isNpcActionFinished; + Function npcAttackMelee; + Function npcAttackRanged; + Function npcSpellCast; + Function npcUseClosestMob; + //Function pushNpcAction; + Function setNpcHostPlayer; + + Function addBan; + Function applyPlayerOverlay; + Function ban; + Function drawWeapon; + Function equipItem; + Function getPlayerAmulet; + Function getPlayerAngle; + Function getPlayerAni; + Function getPlayerArmor; + Function getPlayerAtVector; + Function getPlayerBelt; + Function getPlayerCameraPosition; + Function getPlayerCollision; + Function getPlayerColor; + Function getPlayerContext; + Function getPlayerDexterity; + Function getPlayerFaceAnis; + Function getPlayerFatness; + Function getPlayerFocus; + Function getPlayerHealth; + Function getPlayerHelmet; + Function getPlayerIP; + Function getPlayerInstance; + Function getPlayerMacAddr; + Function getPlayerMana; + Function getPlayerMaxHealth; + Function getPlayerMaxMana; + Function getPlayerMeleeWeapon; + Function getPlayerName; + Function getPlayerPing; + Function getPlayerPosition; + Function getPlayerRangedWeapon; + Function getPlayerRespawnTime; + Function getPlayerRing; + Function getPlayerScale; + Function getPlayerSerial; + Function getPlayerShield; + Function getPlayerSkillWeapon; + Function getPlayerSpell; + Function getPlayerStrength; + Function getPlayerTalent; + Function getPlayerVirtualWorld; + Function getPlayerVisual; + Function getPlayerWeaponMode; + Function getPlayerWorld; + Function giveItem; + Function hitPlayer; + Function isPlayerConnected; + Function isPlayerDead; + Function isPlayerUnconscious; + Function kick; + Function playAni; + Function playFaceAni; + Function readySpell; + Function removeItem; + Function removePlayerOverlay; + Function removeWeapon; + Function respawnPlayer; + Function setPlayerAngle; + Function setPlayerCollision; + Function setPlayerColor; + Function setPlayerContext; + Function setPlayerDexterity; + Function setPlayerFatness; + Function setPlayerHealth; + Function setPlayerInstance; + Function setPlayerInvisible; + Function setPlayerMana; + Function setPlayerMaxHealth; + Function setPlayerMaxMana; + Function setPlayerName; + Function setPlayerPosition; + Function setPlayerRespawnTime; + Function setPlayerScale; + Function setPlayerSkillWeapon; + Function setPlayerStrength; + Function setPlayerTalent; + Function setPlayerVirtualWorld; + Function setPlayerVisual; + Function setPlayerWeaponMode; + Function setPlayerWorld; + Function spawnPlayer; + Function stopAni; + Function stopFaceAni; + Function unequipItem; + Function unreadySpell; + Function unspawnPlayer; + Function useItem; + Function useItemToState; + + Function findNearbyPlayers; + Function getSpawnedPlayersForPlayer; + Function getStreamedPlayersByPlayer; + + Function getNearestWaypoint; + Function getWaypoint; + }; +} + +#endif \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 3e30e7a..c5ef662 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,6 +2,7 @@ #include #include "events/sqevents.h" #include "constants/sqconstants.h" +#include "functions/sqfunctions.h" namespace py = pybind11; py::scoped_interpreter guard{}; @@ -10,7 +11,6 @@ py::module_ pysys = py::module_::import("sys"); py::module_ g2o; py::module_ scripts; - extern "C" SQRESULT SQRAT_API sqmodule_load(HSQUIRRELVM vm, HSQAPI api) { SqModule::Initialize(vm, api);