feat: Модифицирована Squirrel сторона под новый формат сообщений

This commit is contained in:
AURUMVORXX
2025-08-26 18:27:01 +05:00
parent 2300f98b04
commit fe00e837e4
2 changed files with 52 additions and 74 deletions

View File

@@ -8,7 +8,7 @@ addEventHandler("onPlayerUseCheat", function(playerid, type)
} }
if (_globalInstance != -1) if (_globalInstance != -1)
_globalInstance._send("event", data); _globalInstance._send(data);
}); });
addEventHandler("onBan", function(banInfo) addEventHandler("onBan", function(banInfo)
@@ -25,7 +25,7 @@ addEventHandler("onBan", function(banInfo)
} }
if (_globalInstance != -1) if (_globalInstance != -1)
_globalInstance._send("event", data); _globalInstance._send(data);
}); });
addEventHandler("onExit", function() addEventHandler("onExit", function()
@@ -35,7 +35,7 @@ addEventHandler("onExit", function()
} }
if (_globalInstance != -1) if (_globalInstance != -1)
_globalInstance._send("event", data); _globalInstance._send(data);
}); });
addEventHandler("onTick", function() addEventHandler("onTick", function()
@@ -45,7 +45,7 @@ addEventHandler("onTick", function()
} }
if (_globalInstance != -1) if (_globalInstance != -1)
_globalInstance._send("event", data); _globalInstance._send(data);
}); });
addEventHandler("onTime", function(day, hour, min) addEventHandler("onTime", function(day, hour, min)
@@ -58,7 +58,7 @@ addEventHandler("onTime", function(day, hour, min)
} }
if (_globalInstance != -1) if (_globalInstance != -1)
_globalInstance._send("event", data); _globalInstance._send(data);
}); });
addEventHandler("onUnban", function(banInfo) addEventHandler("onUnban", function(banInfo)
@@ -75,7 +75,7 @@ addEventHandler("onUnban", function(banInfo)
} }
if (_globalInstance != -1) if (_globalInstance != -1)
_globalInstance._send("event", data); _globalInstance._send(data);
}); });
addEventHandler("onNpcActionFinished", function(npc_id, action_type, action_id, result) 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) if (_globalInstance != -1)
_globalInstance._send("event", data); _globalInstance._send(data);
}); });
addEventHandler("onNpcActionSent", function(npc_id, action_type, action_id) 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) if (_globalInstance != -1)
_globalInstance._send("event", data); _globalInstance._send(data);
}); });
addEventHandler("onNpcChangeHostPlayer", function(npc_id, current_id, previous_id) 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) if (_globalInstance != -1)
_globalInstance._send("event", data); _globalInstance._send(data);
}); });
addEventHandler("onNpcCreated", function(npc_id) addEventHandler("onNpcCreated", function(npc_id)
@@ -126,7 +126,7 @@ addEventHandler("onNpcCreated", function(npc_id)
} }
if (_globalInstance != -1) if (_globalInstance != -1)
_globalInstance._send("event", data); _globalInstance._send(data);
}); });
addEventHandler("onNpcDestroyed", function(npc_id) addEventHandler("onNpcDestroyed", function(npc_id)
@@ -137,7 +137,7 @@ addEventHandler("onNpcDestroyed", function(npc_id)
} }
if (_globalInstance != -1) if (_globalInstance != -1)
_globalInstance._send("event", data); _globalInstance._send(data);
}); });
addEventHandler("onPlayerChangeColor", function(playerid, r, g, b) addEventHandler("onPlayerChangeColor", function(playerid, r, g, b)
@@ -151,7 +151,7 @@ addEventHandler("onPlayerChangeColor", function(playerid, r, g, b)
} }
if (_globalInstance != -1) if (_globalInstance != -1)
_globalInstance._send("event", data); _globalInstance._send(data);
}); });
addEventHandler("onPlayerChangeFocus", function(playerid, oldFocusId, newFocusId) addEventHandler("onPlayerChangeFocus", function(playerid, oldFocusId, newFocusId)
@@ -164,7 +164,7 @@ addEventHandler("onPlayerChangeFocus", function(playerid, oldFocusId, newFocusId
} }
if (_globalInstance != -1) if (_globalInstance != -1)
_globalInstance._send("event", data); _globalInstance._send(data);
}); });
addEventHandler("onPlayerChangeHealth", function(playerid, previous, current) addEventHandler("onPlayerChangeHealth", function(playerid, previous, current)
@@ -177,7 +177,7 @@ addEventHandler("onPlayerChangeHealth", function(playerid, previous, current)
} }
if (_globalInstance != -1) if (_globalInstance != -1)
_globalInstance._send("event", data); _globalInstance._send(data);
}); });
addEventHandler("onPlayerChangeMana", function(playerid, previous, current) addEventHandler("onPlayerChangeMana", function(playerid, previous, current)
@@ -190,7 +190,7 @@ addEventHandler("onPlayerChangeMana", function(playerid, previous, current)
} }
if (_globalInstance != -1) if (_globalInstance != -1)
_globalInstance._send("event", data); _globalInstance._send(data);
}); });
addEventHandler("onPlayerChangeMaxHealth", function(playerid, previous, current) addEventHandler("onPlayerChangeMaxHealth", function(playerid, previous, current)
@@ -203,7 +203,7 @@ addEventHandler("onPlayerChangeMaxHealth", function(playerid, previous, current)
} }
if (_globalInstance != -1) if (_globalInstance != -1)
_globalInstance._send("event", data); _globalInstance._send(data);
}); });
addEventHandler("onPlayerChangeMaxMana", function(playerid, previous, current) addEventHandler("onPlayerChangeMaxMana", function(playerid, previous, current)
@@ -216,7 +216,7 @@ addEventHandler("onPlayerChangeMaxMana", function(playerid, previous, current)
} }
if (_globalInstance != -1) if (_globalInstance != -1)
_globalInstance._send("event", data); _globalInstance._send(data);
}); });
addEventHandler("onPlayerChangeWeaponMode", function(playerid, previous, current) addEventHandler("onPlayerChangeWeaponMode", function(playerid, previous, current)
@@ -229,7 +229,7 @@ addEventHandler("onPlayerChangeWeaponMode", function(playerid, previous, current
} }
if (_globalInstance != -1) if (_globalInstance != -1)
_globalInstance._send("event", data); _globalInstance._send(data);
}); });
addEventHandler("onPlayerChangeWorld", function(playerid, previous, current) addEventHandler("onPlayerChangeWorld", function(playerid, previous, current)
@@ -242,7 +242,7 @@ addEventHandler("onPlayerChangeWorld", function(playerid, previous, current)
} }
if (_globalInstance != -1) if (_globalInstance != -1)
_globalInstance._send("event", data); _globalInstance._send(data);
}); });
addEventHandler("onPlayerCommand", function(playerid, command, params) addEventHandler("onPlayerCommand", function(playerid, command, params)
@@ -255,7 +255,7 @@ addEventHandler("onPlayerCommand", function(playerid, command, params)
} }
if (_globalInstance != -1) if (_globalInstance != -1)
_globalInstance._send("event", data); _globalInstance._send(data);
}); });
addEventHandler("onPlayerDamage", function(playerid, killerid, description) addEventHandler("onPlayerDamage", function(playerid, killerid, description)
@@ -271,7 +271,7 @@ addEventHandler("onPlayerDamage", function(playerid, killerid, description)
} }
if (_globalInstance != -1) if (_globalInstance != -1)
_globalInstance._send("event", data); _globalInstance._send(data);
}); });
addEventHandler("onPlayerDead", function(playerid, killerid) addEventHandler("onPlayerDead", function(playerid, killerid)
@@ -283,7 +283,7 @@ addEventHandler("onPlayerDead", function(playerid, killerid)
} }
if (_globalInstance != -1) if (_globalInstance != -1)
_globalInstance._send("event", data); _globalInstance._send(data);
}); });
addEventHandler("onPlayerDisconnect", function(playerid, reason) addEventHandler("onPlayerDisconnect", function(playerid, reason)
@@ -295,7 +295,7 @@ addEventHandler("onPlayerDisconnect", function(playerid, reason)
} }
if (_globalInstance != -1) if (_globalInstance != -1)
_globalInstance._send("event", data); _globalInstance._send(data);
}); });
addEventHandler("onPlayerDropItem", function(playerid, itemGround) addEventHandler("onPlayerDropItem", function(playerid, itemGround)
@@ -310,7 +310,7 @@ addEventHandler("onPlayerDropItem", function(playerid, itemGround)
} }
if (_globalInstance != -1) if (_globalInstance != -1)
_globalInstance._send("event", data); _globalInstance._send(data);
}); });
addEventHandler("onPlayerEnterWorld", function(playerid, world) addEventHandler("onPlayerEnterWorld", function(playerid, world)
@@ -322,7 +322,7 @@ addEventHandler("onPlayerEnterWorld", function(playerid, world)
} }
if (_globalInstance != -1) if (_globalInstance != -1)
_globalInstance._send("event", data); _globalInstance._send(data);
}); });
addEventHandler("onPlayerEquipAmulet", function(playerid, instance) addEventHandler("onPlayerEquipAmulet", function(playerid, instance)
@@ -334,7 +334,7 @@ addEventHandler("onPlayerEquipAmulet", function(playerid, instance)
} }
if (_globalInstance != -1) if (_globalInstance != -1)
_globalInstance._send("event", data); _globalInstance._send(data);
}); });
addEventHandler("onPlayerEquipArmor", function(playerid, instance) addEventHandler("onPlayerEquipArmor", function(playerid, instance)
@@ -346,7 +346,7 @@ addEventHandler("onPlayerEquipArmor", function(playerid, instance)
} }
if (_globalInstance != -1) if (_globalInstance != -1)
_globalInstance._send("event", data); _globalInstance._send(data);
}); });
addEventHandler("onPlayerEquipBelt", function(playerid, instance) addEventHandler("onPlayerEquipBelt", function(playerid, instance)
@@ -358,7 +358,7 @@ addEventHandler("onPlayerEquipBelt", function(playerid, instance)
} }
if (_globalInstance != -1) if (_globalInstance != -1)
_globalInstance._send("event", data); _globalInstance._send(data);
}); });
addEventHandler("onPlayerEquipHandItem", function(playerid, hand, instance) addEventHandler("onPlayerEquipHandItem", function(playerid, hand, instance)
@@ -371,7 +371,7 @@ addEventHandler("onPlayerEquipHandItem", function(playerid, hand, instance)
} }
if (_globalInstance != -1) if (_globalInstance != -1)
_globalInstance._send("event", data); _globalInstance._send(data);
}); });
addEventHandler("onPlayerEquipHelmet", function(playerid, instance) addEventHandler("onPlayerEquipHelmet", function(playerid, instance)
@@ -383,7 +383,7 @@ addEventHandler("onPlayerEquipHelmet", function(playerid, instance)
} }
if (_globalInstance != -1) if (_globalInstance != -1)
_globalInstance._send("event", data); _globalInstance._send(data);
}); });
addEventHandler("onPlayerEquipMeleeWeapon", function(playerid, instance) addEventHandler("onPlayerEquipMeleeWeapon", function(playerid, instance)
@@ -395,7 +395,7 @@ addEventHandler("onPlayerEquipMeleeWeapon", function(playerid, instance)
} }
if (_globalInstance != -1) if (_globalInstance != -1)
_globalInstance._send("event", data); _globalInstance._send(data);
}); });
addEventHandler("onPlayerEquipRangedWeapon", function(playerid, instance) addEventHandler("onPlayerEquipRangedWeapon", function(playerid, instance)
@@ -407,7 +407,7 @@ addEventHandler("onPlayerEquipRangedWeapon", function(playerid, instance)
} }
if (_globalInstance != -1) if (_globalInstance != -1)
_globalInstance._send("event", data); _globalInstance._send(data);
}); });
addEventHandler("onPlayerEquipRing", function(playerid, handId, instance) addEventHandler("onPlayerEquipRing", function(playerid, handId, instance)
@@ -420,7 +420,7 @@ addEventHandler("onPlayerEquipRing", function(playerid, handId, instance)
} }
if (_globalInstance != -1) if (_globalInstance != -1)
_globalInstance._send("event", data); _globalInstance._send(data);
}); });
addEventHandler("onPlayerEquipShield", function(playerid, instance) addEventHandler("onPlayerEquipShield", function(playerid, instance)
@@ -432,7 +432,7 @@ addEventHandler("onPlayerEquipShield", function(playerid, instance)
} }
if (_globalInstance != -1) if (_globalInstance != -1)
_globalInstance._send("event", data); _globalInstance._send(data);
}); });
addEventHandler("onPlayerEquipSpell", function(playerid, slotId, instance) addEventHandler("onPlayerEquipSpell", function(playerid, slotId, instance)
@@ -445,7 +445,7 @@ addEventHandler("onPlayerEquipSpell", function(playerid, slotId, instance)
} }
if (_globalInstance != -1) if (_globalInstance != -1)
_globalInstance._send("event", data); _globalInstance._send(data);
}); });
addEventHandler("onPlayerJoin", function(playerid) addEventHandler("onPlayerJoin", function(playerid)
@@ -456,7 +456,7 @@ addEventHandler("onPlayerJoin", function(playerid)
} }
if (_globalInstance != -1) if (_globalInstance != -1)
_globalInstance._send("event", data); _globalInstance._send(data);
}); });
addEventHandler("onPlayerMessage", function(playerid, message) addEventHandler("onPlayerMessage", function(playerid, message)
@@ -468,7 +468,7 @@ addEventHandler("onPlayerMessage", function(playerid, message)
} }
if (_globalInstance != -1) if (_globalInstance != -1)
_globalInstance._send("event", data); _globalInstance._send(data);
}); });
addEventHandler("onPlayerMobInteract", function(playerid, from, to) addEventHandler("onPlayerMobInteract", function(playerid, from, to)
@@ -481,7 +481,7 @@ addEventHandler("onPlayerMobInteract", function(playerid, from, to)
} }
if (_globalInstance != -1) if (_globalInstance != -1)
_globalInstance._send("event", data); _globalInstance._send(data);
}); });
addEventHandler("onPlayerRespawn", function(playerid) addEventHandler("onPlayerRespawn", function(playerid)
@@ -492,7 +492,7 @@ addEventHandler("onPlayerRespawn", function(playerid)
} }
if (_globalInstance != -1) if (_globalInstance != -1)
_globalInstance._send("event", data); _globalInstance._send(data);
}); });
addEventHandler("onPlayerShoot", function(playerid, munition) addEventHandler("onPlayerShoot", function(playerid, munition)
@@ -504,7 +504,7 @@ addEventHandler("onPlayerShoot", function(playerid, munition)
} }
if (_globalInstance != -1) if (_globalInstance != -1)
_globalInstance._send("event", data); _globalInstance._send(data);
}); });
addEventHandler("onPlayerSpellCast", function(playerid, instance, spellLevel) addEventHandler("onPlayerSpellCast", function(playerid, instance, spellLevel)
@@ -517,7 +517,7 @@ addEventHandler("onPlayerSpellCast", function(playerid, instance, spellLevel)
} }
if (_globalInstance != -1) if (_globalInstance != -1)
_globalInstance._send("event", data); _globalInstance._send(data);
}); });
addEventHandler("onPlayerSpellSetup", function(playerid, instance) addEventHandler("onPlayerSpellSetup", function(playerid, instance)
@@ -529,7 +529,7 @@ addEventHandler("onPlayerSpellSetup", function(playerid, instance)
} }
if (_globalInstance != -1) if (_globalInstance != -1)
_globalInstance._send("event", data); _globalInstance._send(data);
}); });
addEventHandler("onPlayerTakeItem", function(playerid, itemGround) addEventHandler("onPlayerTakeItem", function(playerid, itemGround)
@@ -544,7 +544,7 @@ addEventHandler("onPlayerTakeItem", function(playerid, itemGround)
} }
if (_globalInstance != -1) if (_globalInstance != -1)
_globalInstance._send("event", data); _globalInstance._send(data);
}); });
addEventHandler("onPlayerTeleport", function(playerid, vobName) addEventHandler("onPlayerTeleport", function(playerid, vobName)
@@ -556,7 +556,7 @@ addEventHandler("onPlayerTeleport", function(playerid, vobName)
} }
if (_globalInstance != -1) if (_globalInstance != -1)
_globalInstance._send("event", data); _globalInstance._send(data);
}); });
addEventHandler("onPlayerToggleFaceAni", function(playerid, aniName, toggle) addEventHandler("onPlayerToggleFaceAni", function(playerid, aniName, toggle)
@@ -569,7 +569,7 @@ addEventHandler("onPlayerToggleFaceAni", function(playerid, aniName, toggle)
} }
if (_globalInstance != -1) if (_globalInstance != -1)
_globalInstance._send("event", data); _globalInstance._send(data);
}); });
addEventHandler("onPlayerSpawnForPlayer", function(playerid, spawnid) addEventHandler("onPlayerSpawnForPlayer", function(playerid, spawnid)
@@ -581,7 +581,7 @@ addEventHandler("onPlayerSpawnForPlayer", function(playerid, spawnid)
} }
if (_globalInstance != -1) if (_globalInstance != -1)
_globalInstance._send("event", data); _globalInstance._send(data);
}); });
addEventHandler("onPlayerUnspawnForPlayer", function(playerid, spawnid) addEventHandler("onPlayerUnspawnForPlayer", function(playerid, spawnid)
@@ -593,7 +593,7 @@ addEventHandler("onPlayerUnspawnForPlayer", function(playerid, spawnid)
} }
if (_globalInstance != -1) if (_globalInstance != -1)
_globalInstance._send("event", data); _globalInstance._send(data);
}); });
addEventHandler("onPlayerChangeChunk", function(playerid, chunk_index) addEventHandler("onPlayerChangeChunk", function(playerid, chunk_index)
@@ -605,5 +605,5 @@ addEventHandler("onPlayerChangeChunk", function(playerid, chunk_index)
} }
if (_globalInstance != -1) if (_globalInstance != -1)
_globalInstance._send("event", data); _globalInstance._send(data);
}); });

View File

@@ -10,14 +10,12 @@ class PyG2O
_max_reconnect_attempts = 0; _max_reconnect_attempts = 0;
_constantsInitialized = false; _constantsInitialized = false;
_messageHandlers = null;
constructor(url, silent = false, max_reconnect_attempts = 0) constructor(url, silent = false, max_reconnect_attempts = 0)
{ {
_url = url; _url = url;
_max_reconnect_attempts = max_reconnect_attempts; _max_reconnect_attempts = max_reconnect_attempts;
_silent = silent; _silent = silent;
_messageHandlers = {};
_connection = WebsocketClient(); _connection = WebsocketClient();
_connection.silent = _silent; _connection.silent = _silent;
@@ -27,8 +25,6 @@ class PyG2O
_connection.onClose = _onClose.bindenv(this); _connection.onClose = _onClose.bindenv(this);
_connection.onMessage = _onMessage.bindenv(this); _connection.onMessage = _onMessage.bindenv(this);
_registerMessage("call", _message_call.bindenv(this));
if (_globalInstance == -1) if (_globalInstance == -1)
_globalInstance = this; _globalInstance = this;
} }
@@ -47,28 +43,11 @@ class PyG2O
print("[PyG2O] Stopped connection"); 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") function _send(type, data, uuid = "none")
{ {
local sendData = { local sendData = {
"type": type, "uuid": uuid,
"data": data, "data": data
"uuid": uuid
} }
_connection.send(JSON.dump_ansi(sendData, 2)); _connection.send(JSON.dump_ansi(sendData, 2));
@@ -147,11 +126,10 @@ class PyG2O
function _onMessage(url, message) function _onMessage(url, message)
{ {
local request = JSON.parse_ansi(message); local request = JSON.parse_ansi(message);
if (!("type" in request) || if (!("uuid" in request) ||
!("uuid" in request) ||
!("data" in request)) !("data" in request))
return; return;
_callMessage(request["type"], request); _message_call.bindenv(this)(request["data"]);
} }
} }