feat: Добавлена авторизация через UDP пакеты

This commit is contained in:
AURUMVORXX
2025-08-27 13:55:15 +05:00
parent 77bfd7492a
commit 7447973428
18 changed files with 249 additions and 3645 deletions

617
include/server/events.nut Normal file
View File

@@ -0,0 +1,617 @@
addEventHandler("onPlayerUseCheat", function(playerid, type)
{
local data = {
event = "onPlayerUseCheat",
playerid = playerid,
type = type
}
if (_globalInstance != -1)
_globalInstance._send(data);
});
addEventHandler("onBan", function(banInfo)
{
local data = {
event = "onBan",
ban = {
mac = "mac" in banInfo ? banInfo["mac"] : "-1",
ip = "ip" in banInfo ? banInfo["ip"] : "-1",
serial = "serial" in banInfo ? banInfo["serial"] : "-1",
name = "name" in banInfo ? banInfo["name"] : "-1",
timestamp = "timestamp" in banInfo ? banInfo["timestamp"] : -1
}
}
if (_globalInstance != -1)
_globalInstance._send(data);
});
addEventHandler("onExit", function()
{
local data = {
event = "onExit"
}
if (_globalInstance != -1)
_globalInstance._send(data);
});
addEventHandler("onTick", function()
{
local data = {
event = "onTick"
}
if (_globalInstance != -1)
_globalInstance._send(data);
});
addEventHandler("onTime", function(day, hour, min)
{
local data = {
event = "onTime",
day = day,
hour = hour,
min = min
}
if (_globalInstance != -1)
_globalInstance._send(data);
});
addEventHandler("onUnban", function(banInfo)
{
local data = {
event = "onUnban",
ban = {
mac = "mac" in banInfo ? banInfo["mac"] : "-1",
ip = "ip" in banInfo ? banInfo["ip"] : "-1",
serial = "serial" in banInfo ? banInfo["serial"] : "-1",
name = "name" in banInfo ? banInfo["name"] : "-1",
timestamp = "timestamp" in banInfo ? banInfo["timestamp"] : -1
}
}
if (_globalInstance != -1)
_globalInstance._send(data);
});
addEventHandler("onNpcActionFinished", function(npc_id, action_type, action_id, result)
{
local data = {
event = "onNpcActionFinished",
npc_id = npc_id,
action_type = action_type,
action_id = action_id,
result = result
}
if (_globalInstance != -1)
_globalInstance._send(data);
});
addEventHandler("onNpcActionSent", function(npc_id, action_type, action_id)
{
local data = {
event = "onNpcActionSent",
npc_id = npc_id,
action_type = action_type,
action_id = action_id,
}
if (_globalInstance != -1)
_globalInstance._send(data);
});
addEventHandler("onNpcChangeHostPlayer", function(npc_id, current_id, previous_id)
{
local data = {
event = "onNpcChangeHostPlayer",
npc_id = npc_id,
current_id = current_id,
previous_id = previous_id
}
if (_globalInstance != -1)
_globalInstance._send(data);
});
addEventHandler("onNpcCreated", function(npc_id)
{
local data = {
event = "onNpcCreated",
npc_id = npc_id
}
if (_globalInstance != -1)
_globalInstance._send(data);
});
addEventHandler("onNpcDestroyed", function(npc_id)
{
local data = {
event = "onNpcCreated",
npc_id = npc_id
}
if (_globalInstance != -1)
_globalInstance._send(data);
});
addEventHandler("onPlayerChangeColor", function(playerid, r, g, b)
{
local data = {
event = "onPlayerChangeColor",
playerid = playerid,
r = r,
g = g,
b = b
}
if (_globalInstance != -1)
_globalInstance._send(data);
});
addEventHandler("onPlayerChangeFocus", function(playerid, oldFocusId, newFocusId)
{
local data = {
event = "onPlayerChangeFocus",
playerid = playerid,
oldFocusId = oldFocusId,
newFocusId = newFocusId
}
if (_globalInstance != -1)
_globalInstance._send(data);
});
addEventHandler("onPlayerChangeHealth", function(playerid, previous, current)
{
local data = {
event = "onPlayerChangeHealth",
playerid = playerid,
previous = previous,
current = current
}
if (_globalInstance != -1)
_globalInstance._send(data);
});
addEventHandler("onPlayerChangeMana", function(playerid, previous, current)
{
local data = {
event = "onPlayerChangeMana",
playerid = playerid,
previous = previous,
current = current
}
if (_globalInstance != -1)
_globalInstance._send(data);
});
addEventHandler("onPlayerChangeMaxHealth", function(playerid, previous, current)
{
local data = {
event = "onPlayerChangeMaxHealth",
playerid = playerid,
previous = previous,
current = current
}
if (_globalInstance != -1)
_globalInstance._send(data);
});
addEventHandler("onPlayerChangeMaxMana", function(playerid, previous, current)
{
local data = {
event = "onPlayerChangeMaxMana",
playerid = playerid,
previous = previous,
current = current
}
if (_globalInstance != -1)
_globalInstance._send(data);
});
addEventHandler("onPlayerChangeWeaponMode", function(playerid, previous, current)
{
local data = {
event = "onPlayerChangeWeaponMode",
playerid = playerid,
previous = previous,
current = current
}
if (_globalInstance != -1)
_globalInstance._send(data);
});
addEventHandler("onPlayerChangeWorld", function(playerid, previous, current)
{
local data = {
event = "onPlayerChangeWorld",
playerid = playerid,
previous = previous,
current = current
}
if (_globalInstance != -1)
_globalInstance._send(data);
});
addEventHandler("onPlayerCommand", function(playerid, command, params)
{
local data = {
event = "onPlayerCommand",
playerid = playerid,
command = command,
params = params
}
if (_globalInstance != -1)
_globalInstance._send(data);
});
addEventHandler("onPlayerDamage", function(playerid, killerid, description)
{
local data = {
event = "onPlayerDamage",
playerid = playerid,
killerid = killerid,
desc = {
obj_name = "DamageDescription",
obj_data = _globalInstance._serializeObject(description)
}
}
if (_globalInstance != -1)
_globalInstance._send(data);
});
addEventHandler("onPlayerDead", function(playerid, killerid)
{
local data = {
event = "onPlayerDead",
playerid = playerid,
killerid = killerid
}
if (_globalInstance != -1)
_globalInstance._send(data);
});
addEventHandler("onPlayerDisconnect", function(playerid, reason)
{
local data = {
event = "onPlayerDisconnect",
playerid = playerid,
reason = reason
}
if (_globalInstance != -1)
_globalInstance._send(data);
});
addEventHandler("onPlayerDropItem", function(playerid, itemGround)
{
local data = {
event = "onPlayerDropItem",
playerid = playerid,
itemGround = {
obj_name = "ItemGround",
obj_data = _globalInstance._serializeObject(itemGround)
}
}
if (_globalInstance != -1)
_globalInstance._send(data);
});
addEventHandler("onPlayerEnterWorld", function(playerid, world)
{
local data = {
event = "onPlayerEnterWorld",
playerid = playerid,
world = world
}
if (_globalInstance != -1)
_globalInstance._send(data);
});
addEventHandler("onPlayerEquipAmulet", function(playerid, instance)
{
local data = {
event = "onPlayerEquipAmulet",
playerid = playerid,
instance = instance
}
if (_globalInstance != -1)
_globalInstance._send(data);
});
addEventHandler("onPlayerEquipArmor", function(playerid, instance)
{
local data = {
event = "onPlayerEquipArmor",
playerid = playerid,
instance = instance
}
if (_globalInstance != -1)
_globalInstance._send(data);
});
addEventHandler("onPlayerEquipBelt", function(playerid, instance)
{
local data = {
event = "onPlayerEquipBelt",
playerid = playerid,
instance = instance
}
if (_globalInstance != -1)
_globalInstance._send(data);
});
addEventHandler("onPlayerEquipHandItem", function(playerid, hand, instance)
{
local data = {
event = "onPlayerEquipHandItem",
playerid = playerid,
hand = hand,
instance = instance
}
if (_globalInstance != -1)
_globalInstance._send(data);
});
addEventHandler("onPlayerEquipHelmet", function(playerid, instance)
{
local data = {
event = "onPlayerEquipHelmet",
playerid = playerid,
instance = instance
}
if (_globalInstance != -1)
_globalInstance._send(data);
});
addEventHandler("onPlayerEquipMeleeWeapon", function(playerid, instance)
{
local data = {
event = "onPlayerEquipMeleeWeapon",
playerid = playerid,
instance = instance
}
if (_globalInstance != -1)
_globalInstance._send(data);
});
addEventHandler("onPlayerEquipRangedWeapon", function(playerid, instance)
{
local data = {
event = "onPlayerEquipRangedWeapon",
playerid = playerid,
instance = instance
}
if (_globalInstance != -1)
_globalInstance._send(data);
});
addEventHandler("onPlayerEquipRing", function(playerid, handId, instance)
{
local data = {
event = "onPlayerEquipRing",
playerid = playerid,
handId = handId,
instance = instance
}
if (_globalInstance != -1)
_globalInstance._send(data);
});
addEventHandler("onPlayerEquipShield", function(playerid, instance)
{
local data = {
event = "onPlayerEquipShield",
playerid = playerid,
instance = instance
}
if (_globalInstance != -1)
_globalInstance._send(data);
});
addEventHandler("onPlayerEquipSpell", function(playerid, slotId, instance)
{
local data = {
event = "onPlayerEquipSpell",
playerid = playerid,
slotId = slotId,
instance = instance
}
if (_globalInstance != -1)
_globalInstance._send(data);
});
addEventHandler("onPlayerJoin", function(playerid)
{
client_password = _globalInstance.generateClientPassword();
local packet = Packet();
packet.writeUInt8(250);
packet.writeString(client_password);
packet.send(playerid, RELIABLE);
local data = {
event = "onPlayerJoin",
playerid = playerid,
password = client_password
}
if (_globalInstance != -1)
_globalInstance._send(data);
});
addEventHandler("onPlayerMessage", function(playerid, message)
{
local data = {
event = "onPlayerMessage",
playerid = playerid,
message = message
}
if (_globalInstance != -1)
_globalInstance._send(data);
});
addEventHandler("onPlayerMobInteract", function(playerid, from, to)
{
local data = {
event = "onPlayerMobInteract",
playerid = playerid,
from = from,
to = to
}
if (_globalInstance != -1)
_globalInstance._send(data);
});
addEventHandler("onPlayerRespawn", function(playerid)
{
local data = {
event = "onPlayerRespawn",
playerid = playerid
}
if (_globalInstance != -1)
_globalInstance._send(data);
});
addEventHandler("onPlayerShoot", function(playerid, munition)
{
local data = {
event = "onPlayerShoot",
playerid = playerid,
munition = munition
}
if (_globalInstance != -1)
_globalInstance._send(data);
});
addEventHandler("onPlayerSpellCast", function(playerid, instance, spellLevel)
{
local data = {
event = "onPlayerSpellCast",
playerid = playerid,
instance = instance,
spellLevel = spellLevel
}
if (_globalInstance != -1)
_globalInstance._send(data);
});
addEventHandler("onPlayerSpellSetup", function(playerid, instance)
{
local data = {
event = "onPlayerSpellSetup",
playerid = playerid,
instance = instance
}
if (_globalInstance != -1)
_globalInstance._send(data);
});
addEventHandler("onPlayerTakeItem", function(playerid, itemGround)
{
local data = {
event = "onPlayerTakeItem",
playerid = playerid,
itemGround = {
obj_name = "ItemGround",
obj_data = _globalInstance._serializeObject(itemGround)
}
}
if (_globalInstance != -1)
_globalInstance._send(data);
});
addEventHandler("onPlayerTeleport", function(playerid, vobName)
{
local data = {
event = "onPlayerTeleport",
playerid = playerid,
vobName = vobName
}
if (_globalInstance != -1)
_globalInstance._send(data);
});
addEventHandler("onPlayerToggleFaceAni", function(playerid, aniName, toggle)
{
local data = {
event = "onPlayerToggleFaceAni",
playerid = playerid,
aniName = aniName,
toggle = toggle
}
if (_globalInstance != -1)
_globalInstance._send(data);
});
addEventHandler("onPlayerSpawnForPlayer", function(playerid, spawnid)
{
local data = {
event = "onPlayerSpawnForPlayer",
playerid = playerid,
spawnid = spawnid
}
if (_globalInstance != -1)
_globalInstance._send(data);
});
addEventHandler("onPlayerUnspawnForPlayer", function(playerid, spawnid)
{
local data = {
event = "onPlayerUnspawnForPlayer",
playerid = playerid,
spawnid = spawnid
}
if (_globalInstance != -1)
_globalInstance._send(data);
});
addEventHandler("onPlayerChangeChunk", function(playerid, chunk_index)
{
local data = {
event = "onPlayerChangeChunk",
playerid = playerid,
chunk_index = chunk_index
}
if (_globalInstance != -1)
_globalInstance._send(data);
});

150
include/server/main.nut Normal file
View File

@@ -0,0 +1,150 @@
_globalInstance <- -1;
class PyG2O
{
_connection = -1;
_silent = false;
_url = -1;
_reconnect_attempts = 0;
_max_reconnect_attempts = 0;
_constantsInitialized = false;
constructor(url, silent = false, max_reconnect_attempts = 0)
{
_url = url;
_max_reconnect_attempts = max_reconnect_attempts;
_silent = silent;
_connection = WebsocketClient();
_connection.silent = _silent;
_connection.setUrl(_url);
_connection.onOpen = _onOpen.bindenv(this);
_connection.onClose = _onClose.bindenv(this);
_connection.onMessage = _onMessage.bindenv(this);
if (_globalInstance == -1)
_globalInstance = this;
}
function start()
{
_connection.start();
if (_connection.running)
print("[PyG2O] Initializing connection on " + _url);
}
function stop()
{
_connection.stop();
if (!_connection.running)
print("[PyG2O] Stopped connection");
}
function _send(type, data, uuid = "none")
{
local sendData = {
"data": data
}
if (uuid != "none")
sendData["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;
}
function _onOpen(url)
{
_initializeConstants();
if (!_silent)
print("[PyG2O] Successfully connected to " + url);
}
function _onClose(url, message)
{
if (_max_reconnect_attempts == 0)
return;
_reconnect_attempts += 1;
if (_reconnect_attempts < _max_reconnect_attempts)
return;
_connection.stop();
}
function _onMessage(url, message)
{
local request = JSON.parse_ansi(message);
if (!("uuid" in request) ||
!("data" in request))
return;
_message_call.bindenv(this)(request["data"]);
}
function generateClientPassword()
{
local chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()";
local result = "";
local length = 32;
for (local i = 0; i < length; i++) {
local randomIndex = rand() % chars.len();
result += chars.slice(randomIndex, randomIndex + 1);
}
return result;
}
}

View File

@@ -0,0 +1,30 @@
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"]);
}