From fe00e837e42f6ba1d55addf2a38c54fc5afac942 Mon Sep 17 00:00:00 2001 From: AURUMVORXX Date: Tue, 26 Aug 2025 18:27:01 +0500 Subject: [PATCH] =?UTF-8?q?feat:=20=D0=9C=D0=BE=D0=B4=D0=B8=D1=84=D0=B8?= =?UTF-8?q?=D1=86=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=B0=20Squirrel=20?= =?UTF-8?q?=D1=81=D1=82=D0=BE=D1=80=D0=BE=D0=BD=D0=B0=20=D0=BF=D0=BE=D0=B4?= =?UTF-8?q?=20=D0=BD=D0=BE=D0=B2=D1=8B=D0=B9=20=D1=84=D0=BE=D1=80=D0=BC?= =?UTF-8?q?=D0=B0=D1=82=20=D1=81=D0=BE=D0=BE=D0=B1=D1=89=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/events.nut | 96 +++++++++++++++++++++++----------------------- include/main.nut | 30 ++------------- 2 files changed, 52 insertions(+), 74 deletions(-) diff --git a/include/events.nut b/include/events.nut index f7196d4..fb9f66e 100644 --- a/include/events.nut +++ b/include/events.nut @@ -8,7 +8,7 @@ addEventHandler("onPlayerUseCheat", function(playerid, type) } if (_globalInstance != -1) - _globalInstance._send("event", data); + _globalInstance._send(data); }); addEventHandler("onBan", function(banInfo) @@ -25,7 +25,7 @@ addEventHandler("onBan", function(banInfo) } if (_globalInstance != -1) - _globalInstance._send("event", data); + _globalInstance._send(data); }); addEventHandler("onExit", function() @@ -35,7 +35,7 @@ addEventHandler("onExit", function() } if (_globalInstance != -1) - _globalInstance._send("event", data); + _globalInstance._send(data); }); addEventHandler("onTick", function() @@ -45,7 +45,7 @@ addEventHandler("onTick", function() } if (_globalInstance != -1) - _globalInstance._send("event", data); + _globalInstance._send(data); }); addEventHandler("onTime", function(day, hour, min) @@ -58,7 +58,7 @@ addEventHandler("onTime", function(day, hour, min) } if (_globalInstance != -1) - _globalInstance._send("event", data); + _globalInstance._send(data); }); addEventHandler("onUnban", function(banInfo) @@ -75,7 +75,7 @@ addEventHandler("onUnban", function(banInfo) } if (_globalInstance != -1) - _globalInstance._send("event", data); + _globalInstance._send(data); }); addEventHandler("onNpcActionFinished", function(npc_id, action_type, action_id, result) @@ -89,7 +89,7 @@ addEventHandler("onNpcActionFinished", function(npc_id, action_type, action_id, } if (_globalInstance != -1) - _globalInstance._send("event", data); + _globalInstance._send(data); }); addEventHandler("onNpcActionSent", function(npc_id, action_type, action_id) @@ -102,7 +102,7 @@ addEventHandler("onNpcActionSent", function(npc_id, action_type, action_id) } if (_globalInstance != -1) - _globalInstance._send("event", data); + _globalInstance._send(data); }); addEventHandler("onNpcChangeHostPlayer", function(npc_id, current_id, previous_id) @@ -115,7 +115,7 @@ addEventHandler("onNpcChangeHostPlayer", function(npc_id, current_id, previous_i } if (_globalInstance != -1) - _globalInstance._send("event", data); + _globalInstance._send(data); }); addEventHandler("onNpcCreated", function(npc_id) @@ -126,7 +126,7 @@ addEventHandler("onNpcCreated", function(npc_id) } if (_globalInstance != -1) - _globalInstance._send("event", data); + _globalInstance._send(data); }); addEventHandler("onNpcDestroyed", function(npc_id) @@ -137,7 +137,7 @@ addEventHandler("onNpcDestroyed", function(npc_id) } if (_globalInstance != -1) - _globalInstance._send("event", data); + _globalInstance._send(data); }); addEventHandler("onPlayerChangeColor", function(playerid, r, g, b) @@ -151,7 +151,7 @@ addEventHandler("onPlayerChangeColor", function(playerid, r, g, b) } if (_globalInstance != -1) - _globalInstance._send("event", data); + _globalInstance._send(data); }); addEventHandler("onPlayerChangeFocus", function(playerid, oldFocusId, newFocusId) @@ -164,7 +164,7 @@ addEventHandler("onPlayerChangeFocus", function(playerid, oldFocusId, newFocusId } if (_globalInstance != -1) - _globalInstance._send("event", data); + _globalInstance._send(data); }); addEventHandler("onPlayerChangeHealth", function(playerid, previous, current) @@ -177,7 +177,7 @@ addEventHandler("onPlayerChangeHealth", function(playerid, previous, current) } if (_globalInstance != -1) - _globalInstance._send("event", data); + _globalInstance._send(data); }); addEventHandler("onPlayerChangeMana", function(playerid, previous, current) @@ -190,7 +190,7 @@ addEventHandler("onPlayerChangeMana", function(playerid, previous, current) } if (_globalInstance != -1) - _globalInstance._send("event", data); + _globalInstance._send(data); }); addEventHandler("onPlayerChangeMaxHealth", function(playerid, previous, current) @@ -203,7 +203,7 @@ addEventHandler("onPlayerChangeMaxHealth", function(playerid, previous, current) } if (_globalInstance != -1) - _globalInstance._send("event", data); + _globalInstance._send(data); }); addEventHandler("onPlayerChangeMaxMana", function(playerid, previous, current) @@ -216,7 +216,7 @@ addEventHandler("onPlayerChangeMaxMana", function(playerid, previous, current) } if (_globalInstance != -1) - _globalInstance._send("event", data); + _globalInstance._send(data); }); addEventHandler("onPlayerChangeWeaponMode", function(playerid, previous, current) @@ -229,7 +229,7 @@ addEventHandler("onPlayerChangeWeaponMode", function(playerid, previous, current } if (_globalInstance != -1) - _globalInstance._send("event", data); + _globalInstance._send(data); }); addEventHandler("onPlayerChangeWorld", function(playerid, previous, current) @@ -242,7 +242,7 @@ addEventHandler("onPlayerChangeWorld", function(playerid, previous, current) } if (_globalInstance != -1) - _globalInstance._send("event", data); + _globalInstance._send(data); }); addEventHandler("onPlayerCommand", function(playerid, command, params) @@ -255,7 +255,7 @@ addEventHandler("onPlayerCommand", function(playerid, command, params) } if (_globalInstance != -1) - _globalInstance._send("event", data); + _globalInstance._send(data); }); addEventHandler("onPlayerDamage", function(playerid, killerid, description) @@ -271,7 +271,7 @@ addEventHandler("onPlayerDamage", function(playerid, killerid, description) } if (_globalInstance != -1) - _globalInstance._send("event", data); + _globalInstance._send(data); }); addEventHandler("onPlayerDead", function(playerid, killerid) @@ -283,7 +283,7 @@ addEventHandler("onPlayerDead", function(playerid, killerid) } if (_globalInstance != -1) - _globalInstance._send("event", data); + _globalInstance._send(data); }); addEventHandler("onPlayerDisconnect", function(playerid, reason) @@ -295,7 +295,7 @@ addEventHandler("onPlayerDisconnect", function(playerid, reason) } if (_globalInstance != -1) - _globalInstance._send("event", data); + _globalInstance._send(data); }); addEventHandler("onPlayerDropItem", function(playerid, itemGround) @@ -310,7 +310,7 @@ addEventHandler("onPlayerDropItem", function(playerid, itemGround) } if (_globalInstance != -1) - _globalInstance._send("event", data); + _globalInstance._send(data); }); addEventHandler("onPlayerEnterWorld", function(playerid, world) @@ -322,7 +322,7 @@ addEventHandler("onPlayerEnterWorld", function(playerid, world) } if (_globalInstance != -1) - _globalInstance._send("event", data); + _globalInstance._send(data); }); addEventHandler("onPlayerEquipAmulet", function(playerid, instance) @@ -334,7 +334,7 @@ addEventHandler("onPlayerEquipAmulet", function(playerid, instance) } if (_globalInstance != -1) - _globalInstance._send("event", data); + _globalInstance._send(data); }); addEventHandler("onPlayerEquipArmor", function(playerid, instance) @@ -346,7 +346,7 @@ addEventHandler("onPlayerEquipArmor", function(playerid, instance) } if (_globalInstance != -1) - _globalInstance._send("event", data); + _globalInstance._send(data); }); addEventHandler("onPlayerEquipBelt", function(playerid, instance) @@ -358,7 +358,7 @@ addEventHandler("onPlayerEquipBelt", function(playerid, instance) } if (_globalInstance != -1) - _globalInstance._send("event", data); + _globalInstance._send(data); }); addEventHandler("onPlayerEquipHandItem", function(playerid, hand, instance) @@ -371,7 +371,7 @@ addEventHandler("onPlayerEquipHandItem", function(playerid, hand, instance) } if (_globalInstance != -1) - _globalInstance._send("event", data); + _globalInstance._send(data); }); addEventHandler("onPlayerEquipHelmet", function(playerid, instance) @@ -383,7 +383,7 @@ addEventHandler("onPlayerEquipHelmet", function(playerid, instance) } if (_globalInstance != -1) - _globalInstance._send("event", data); + _globalInstance._send(data); }); addEventHandler("onPlayerEquipMeleeWeapon", function(playerid, instance) @@ -395,7 +395,7 @@ addEventHandler("onPlayerEquipMeleeWeapon", function(playerid, instance) } if (_globalInstance != -1) - _globalInstance._send("event", data); + _globalInstance._send(data); }); addEventHandler("onPlayerEquipRangedWeapon", function(playerid, instance) @@ -407,7 +407,7 @@ addEventHandler("onPlayerEquipRangedWeapon", function(playerid, instance) } if (_globalInstance != -1) - _globalInstance._send("event", data); + _globalInstance._send(data); }); addEventHandler("onPlayerEquipRing", function(playerid, handId, instance) @@ -420,7 +420,7 @@ addEventHandler("onPlayerEquipRing", function(playerid, handId, instance) } if (_globalInstance != -1) - _globalInstance._send("event", data); + _globalInstance._send(data); }); addEventHandler("onPlayerEquipShield", function(playerid, instance) @@ -432,7 +432,7 @@ addEventHandler("onPlayerEquipShield", function(playerid, instance) } if (_globalInstance != -1) - _globalInstance._send("event", data); + _globalInstance._send(data); }); addEventHandler("onPlayerEquipSpell", function(playerid, slotId, instance) @@ -445,7 +445,7 @@ addEventHandler("onPlayerEquipSpell", function(playerid, slotId, instance) } if (_globalInstance != -1) - _globalInstance._send("event", data); + _globalInstance._send(data); }); addEventHandler("onPlayerJoin", function(playerid) @@ -456,7 +456,7 @@ addEventHandler("onPlayerJoin", function(playerid) } if (_globalInstance != -1) - _globalInstance._send("event", data); + _globalInstance._send(data); }); addEventHandler("onPlayerMessage", function(playerid, message) @@ -468,7 +468,7 @@ addEventHandler("onPlayerMessage", function(playerid, message) } if (_globalInstance != -1) - _globalInstance._send("event", data); + _globalInstance._send(data); }); addEventHandler("onPlayerMobInteract", function(playerid, from, to) @@ -481,7 +481,7 @@ addEventHandler("onPlayerMobInteract", function(playerid, from, to) } if (_globalInstance != -1) - _globalInstance._send("event", data); + _globalInstance._send(data); }); addEventHandler("onPlayerRespawn", function(playerid) @@ -492,7 +492,7 @@ addEventHandler("onPlayerRespawn", function(playerid) } if (_globalInstance != -1) - _globalInstance._send("event", data); + _globalInstance._send(data); }); addEventHandler("onPlayerShoot", function(playerid, munition) @@ -504,7 +504,7 @@ addEventHandler("onPlayerShoot", function(playerid, munition) } if (_globalInstance != -1) - _globalInstance._send("event", data); + _globalInstance._send(data); }); addEventHandler("onPlayerSpellCast", function(playerid, instance, spellLevel) @@ -517,7 +517,7 @@ addEventHandler("onPlayerSpellCast", function(playerid, instance, spellLevel) } if (_globalInstance != -1) - _globalInstance._send("event", data); + _globalInstance._send(data); }); addEventHandler("onPlayerSpellSetup", function(playerid, instance) @@ -529,7 +529,7 @@ addEventHandler("onPlayerSpellSetup", function(playerid, instance) } if (_globalInstance != -1) - _globalInstance._send("event", data); + _globalInstance._send(data); }); addEventHandler("onPlayerTakeItem", function(playerid, itemGround) @@ -544,7 +544,7 @@ addEventHandler("onPlayerTakeItem", function(playerid, itemGround) } if (_globalInstance != -1) - _globalInstance._send("event", data); + _globalInstance._send(data); }); addEventHandler("onPlayerTeleport", function(playerid, vobName) @@ -556,7 +556,7 @@ addEventHandler("onPlayerTeleport", function(playerid, vobName) } if (_globalInstance != -1) - _globalInstance._send("event", data); + _globalInstance._send(data); }); addEventHandler("onPlayerToggleFaceAni", function(playerid, aniName, toggle) @@ -569,7 +569,7 @@ addEventHandler("onPlayerToggleFaceAni", function(playerid, aniName, toggle) } if (_globalInstance != -1) - _globalInstance._send("event", data); + _globalInstance._send(data); }); addEventHandler("onPlayerSpawnForPlayer", function(playerid, spawnid) @@ -581,7 +581,7 @@ addEventHandler("onPlayerSpawnForPlayer", function(playerid, spawnid) } if (_globalInstance != -1) - _globalInstance._send("event", data); + _globalInstance._send(data); }); addEventHandler("onPlayerUnspawnForPlayer", function(playerid, spawnid) @@ -593,7 +593,7 @@ addEventHandler("onPlayerUnspawnForPlayer", function(playerid, spawnid) } if (_globalInstance != -1) - _globalInstance._send("event", data); + _globalInstance._send(data); }); addEventHandler("onPlayerChangeChunk", function(playerid, chunk_index) @@ -605,5 +605,5 @@ addEventHandler("onPlayerChangeChunk", function(playerid, chunk_index) } if (_globalInstance != -1) - _globalInstance._send("event", data); + _globalInstance._send(data); }); diff --git a/include/main.nut b/include/main.nut index e1d3a9c..ddfd714 100644 --- a/include/main.nut +++ b/include/main.nut @@ -10,14 +10,12 @@ class PyG2O _max_reconnect_attempts = 0; _constantsInitialized = false; - _messageHandlers = null; constructor(url, silent = false, max_reconnect_attempts = 0) { _url = url; _max_reconnect_attempts = max_reconnect_attempts; _silent = silent; - _messageHandlers = {}; _connection = WebsocketClient(); _connection.silent = _silent; @@ -27,8 +25,6 @@ class PyG2O _connection.onClose = _onClose.bindenv(this); _connection.onMessage = _onMessage.bindenv(this); - _registerMessage("call", _message_call.bindenv(this)); - if (_globalInstance == -1) _globalInstance = this; } @@ -47,28 +43,11 @@ class PyG2O print("[PyG2O] Stopped connection"); } - function _registerMessage(type, handler) - { - if (type in _messageHandlers) - return; - - _messageHandlers[type] <- handler; - } - - function _callMessage(type, data) - { - if(!(type in _messageHandlers)) - return; - - _messageHandlers[type](data); - } - function _send(type, data, uuid = "none") { local sendData = { - "type": type, - "data": data, - "uuid": uuid + "uuid": uuid, + "data": data } _connection.send(JSON.dump_ansi(sendData, 2)); @@ -147,11 +126,10 @@ class PyG2O function _onMessage(url, message) { local request = JSON.parse_ansi(message); - if (!("type" in request) || - !("uuid" in request) || + if (!("uuid" in request) || !("data" in request)) return; - _callMessage(request["type"], request); + _message_call.bindenv(this)(request["data"]); } }