feat: Squirrel изменения для PyG2O

This commit is contained in:
AURUMVORXX
2025-09-02 20:40:00 +05:00
parent fdfb01f825
commit 0e3d061f4b
5 changed files with 23 additions and 92 deletions

View File

@@ -3,7 +3,5 @@ CLIENT_PASSWORD <- "";
addEventHandler("onPacket", function(data){
local id = data.readUInt8();
if (id == 250)
{
CLIENT_PASSWORD = data.readString();
}
})

View File

@@ -1,5 +1,6 @@
<server>
<script src="messages.nut" type="server" />
<script src="main.nut" type="server" />
<script src="events.nut" type="server" />
<script src="server/messages.nut" type="server" />
<script src="server/main.nut" type="server" />
<script src="server/events.nut" type="server" />
<script src="client/main.nut" type="client" />
</server>

View File

@@ -450,7 +450,7 @@ addEventHandler("onPlayerEquipSpell", function(playerid, slotId, instance)
addEventHandler("onPlayerJoin", function(playerid)
{
client_password = _globalInstance.generateClientPassword();
local client_password = _globalInstance.generateClientPassword();
local packet = Packet();
packet.writeUInt8(250);

View File

@@ -1,5 +1,6 @@
_globalInstance <- -1;
local _clientTokens = [];
class PyG2O
{
@@ -9,9 +10,7 @@ class PyG2O
_reconnect_attempts = 0;
_max_reconnect_attempts = 0;
_constantsInitialized = false;
constructor(url, silent = false, max_reconnect_attempts = 0)
constructor(url, silent = false, headers = {}, max_reconnect_attempts = 0)
{
_url = url;
_max_reconnect_attempts = max_reconnect_attempts;
@@ -20,6 +19,7 @@ class PyG2O
_connection = WebsocketClient();
_connection.silent = _silent;
_connection.setUrl(_url);
_connection.headers = headers;
_connection.onOpen = _onOpen.bindenv(this);
_connection.onClose = _onClose.bindenv(this);
@@ -43,71 +43,16 @@ class PyG2O
print("[PyG2O] Stopped connection");
}
function _send(type, data, uuid = "none")
function _send(data, uuid = "none")
{
local sendData = {
"data": data
}
if (uuid != "none")
sendData["uuid"] <- uuid;
data["uuid"] <- uuid;
_connection.send(JSON.dump_ansi(sendData, 2));
}
function _initializeConstants()
{
if (_constantsInitialized)
return;
_send("init_constants", getconsttable());
}
function _getClassName(object)
{
if (object instanceof DamageDescription)
return "DamageDescription";
else if (object instanceof ItemGround)
return "ItemGround";
else if (object instanceof Vec3)
return "Vec3";
else if (object instanceof Vec2i)
return "Vec2i";
return null;
}
function _serializeObject(object)
{
local cls = object.getclass();
local tab = {};
if (object instanceof DamageDescription)
{
tab["_flags"] <- object.flags;
tab["_damage"] <- object.damage;
tab["_item_instance"] <- object.item_instance;
tab["_distance"] <- object.distance;
tab["_spell_id"] <- object.spell_id;
tab["_spell_level"] <- object.spell_level;
tab["_node"] <- object.node;
}
else if (object instanceof ItemGround)
{
tab["_id"] <- object.id;
tab["_instance"] <- object.instance;
tab["_amount"] <- object.amount;
tab["_world"] <- object.world;
tab["_virtualWorld"] <- object.virtualWorld;
tab["_position"] <- object.getPosition();
tab["_rotation"] <- object.getRotation();
}
return tab;
_connection.send(JSON.dump_ansi(data, 2));
}
function _onOpen(url)
{
_initializeConstants();
if (!_silent)
print("[PyG2O] Successfully connected to " + url);
}
@@ -148,3 +93,13 @@ class PyG2O
return result;
}
}
addEventHandler("onPlayerJoin", function(playerid){
new_token = _globalInstance.generateClientPassword();
_globalInstance.send({"create_temp_token": new_token})
_clientTokens[playerid] = new_token;
});
addEventHandler("onPlayerDisconnect", function(playerid, reason){
_globalInstance.send({"remove_temp_token": _clientTokens[playerid]});
});

View File

@@ -3,28 +3,5 @@ function _message_call(data)
{
local compile_string = "try { " + data["data"] + " } catch(id) { print(\"[PyG2O] Error white executing the code: \" + id + \"\\nCode: " + data["data"] + "\"); return null; }";
local result = compilestring(compile_string)();
local className = _getClassName(result);
if (className == "Vec3")
{
data["data"] = {};
data["data"]["x"] <- result.x;
data["data"]["y"] <- result.y;
data["data"]["z"] <- result.z;
}
else if (className == "Vec2i")
{
data["data"] = {};
data["data"]["x"] <- result.x;
data["data"]["y"] <- result.y;
}
else if (className != null)
{
data["data"] = {};
data["data"]["obj_name"] <- className;
data["data"]["obj_data"] <- _serializeObject(result);
}
else
data["data"] = result;
_send("result", data["data"], data["uuid"]);
_send({"uuid": data["uuid"], "data": result});
}