feat: Added Packet class and onPacket event
This commit is contained in:
@@ -66,6 +66,10 @@ file(GLOB_RECURSE SOURCE
|
|||||||
|
|
||||||
"src/NoNut/core/*.h"
|
"src/NoNut/core/*.h"
|
||||||
"src/NoNut/core/*.cpp"
|
"src/NoNut/core/*.cpp"
|
||||||
|
"src/classes/sq/*.h"
|
||||||
|
"src/classes/sq/*.cpp"
|
||||||
|
"src/classes/py/*.h"
|
||||||
|
"src/classes/py/*.cpp"
|
||||||
"src/*.h"
|
"src/*.h"
|
||||||
"src/*.cpp"
|
"src/*.cpp"
|
||||||
"src/events/*.h"
|
"src/events/*.h"
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
|
|
||||||
from g2o.events import addEvent
|
from g2o.events import addEvent
|
||||||
from g2o.events import callEvent
|
from g2o.events import callEvent
|
||||||
from g2o.events import event
|
from g2o.events import event
|
||||||
from g2o.events import removeEventHandler
|
from g2o.events import removeEventHandler
|
||||||
|
|
||||||
|
from g2o.packets import Packet
|
||||||
@@ -161,3 +161,5 @@ addEvent('onPlayerEquipRangedWeapon')
|
|||||||
addEvent('onPlayerEquipRing')
|
addEvent('onPlayerEquipRing')
|
||||||
addEvent('onPlayerEquipShield')
|
addEvent('onPlayerEquipShield')
|
||||||
addEvent('onPlayerEquipSpell')
|
addEvent('onPlayerEquipSpell')
|
||||||
|
|
||||||
|
addEvent('onPacket')
|
||||||
73
g2o/packets.py
Normal file
73
g2o/packets.py
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
import sqg2o
|
||||||
|
|
||||||
|
class Packet(sqg2o.Packet):
|
||||||
|
def __init__(self):
|
||||||
|
return super().__init__()
|
||||||
|
|
||||||
|
def reset(self):
|
||||||
|
return super().reset()
|
||||||
|
|
||||||
|
def send(self, playerid : int, reliability : int):
|
||||||
|
return super().send(playerid, reliability)
|
||||||
|
|
||||||
|
def writeInt8(self, value : int):
|
||||||
|
return super().writeInt8(value)
|
||||||
|
|
||||||
|
def writeUInt8(self, value : int):
|
||||||
|
return super().writeInt8(value)
|
||||||
|
|
||||||
|
def writeInt16(self, value : int):
|
||||||
|
return super().writeInt16(value)
|
||||||
|
|
||||||
|
def writeUInt16(self, value : int):
|
||||||
|
return super().writeInt16(value)
|
||||||
|
|
||||||
|
def writeInt32(self, value : int):
|
||||||
|
return super().writeInt32(value)
|
||||||
|
|
||||||
|
def writeUInt32(self, value : int):
|
||||||
|
return super().writeInt32(value)
|
||||||
|
|
||||||
|
def writeBool(self, value : bool):
|
||||||
|
return super().writeBool(value)
|
||||||
|
|
||||||
|
def writeFloat(self, value : float):
|
||||||
|
return super().writeFloat(value)
|
||||||
|
|
||||||
|
def writeString(self, value : str):
|
||||||
|
return super().writeString(value)
|
||||||
|
|
||||||
|
def readInt8(self,) -> int:
|
||||||
|
return super().readInt8()
|
||||||
|
|
||||||
|
def readUInt8(self,) -> int:
|
||||||
|
return super().readInt8()
|
||||||
|
|
||||||
|
def readInt16(self) -> int:
|
||||||
|
return super().readInt16()
|
||||||
|
|
||||||
|
def readUInt16(self) -> int:
|
||||||
|
return super().readInt16()
|
||||||
|
|
||||||
|
def readInt32(self) -> int:
|
||||||
|
return super().readInt32()
|
||||||
|
|
||||||
|
def readUInt32(self) -> int:
|
||||||
|
return super().readInt32()
|
||||||
|
|
||||||
|
def readBool(self) -> bool:
|
||||||
|
return super().readBool()
|
||||||
|
|
||||||
|
def readFloat(self) -> float:
|
||||||
|
return super().readFloat()
|
||||||
|
|
||||||
|
def readString(self) -> str:
|
||||||
|
return super().readString()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def bitsUsed(self):
|
||||||
|
return super().bitsUsed
|
||||||
|
|
||||||
|
@property
|
||||||
|
def bytesUsed(self):
|
||||||
|
return super().bytesUsed
|
||||||
111
src/NoNut/core/CustomTypes.cpp
Normal file
111
src/NoNut/core/CustomTypes.cpp
Normal file
@@ -0,0 +1,111 @@
|
|||||||
|
#include "CustomTypes.h"
|
||||||
|
|
||||||
|
#include "Array.h"
|
||||||
|
#include "Property.h"
|
||||||
|
|
||||||
|
namespace nonut::g2o
|
||||||
|
{
|
||||||
|
#define GET_SLOT(slot, type) slot = arrayWrapper.get<type>(#slot)
|
||||||
|
|
||||||
|
void GameTime::convert(SQObject object)
|
||||||
|
{
|
||||||
|
Array arrayWrapper(object);
|
||||||
|
GET_SLOT(day, Int);
|
||||||
|
GET_SLOT(hour, Int);
|
||||||
|
GET_SLOT(min, Int);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Position2d::convert(SQObject object)
|
||||||
|
{
|
||||||
|
Array arrayWrapper(object);
|
||||||
|
GET_SLOT(x, Int);
|
||||||
|
GET_SLOT(y, Int);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Position3d::convert(SQObject object)
|
||||||
|
{
|
||||||
|
Array arrayWrapper(object);
|
||||||
|
GET_SLOT(x, Float);
|
||||||
|
GET_SLOT(y, Float);
|
||||||
|
GET_SLOT(z, Float);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Size2d::convert(SQObject object)
|
||||||
|
{
|
||||||
|
Array arrayWrapper(object);
|
||||||
|
GET_SLOT(width, Int);
|
||||||
|
GET_SLOT(height, Int);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Rect::convert(SQObject object)
|
||||||
|
{
|
||||||
|
Array arrayWrapper(object);
|
||||||
|
GET_SLOT(x, Int);
|
||||||
|
GET_SLOT(y, Int);
|
||||||
|
GET_SLOT(width, Int);
|
||||||
|
GET_SLOT(height, Int);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UV::convert(SQObject object)
|
||||||
|
{
|
||||||
|
Array arrayWrapper(object);
|
||||||
|
GET_SLOT(x, Float);
|
||||||
|
GET_SLOT(y, Float);
|
||||||
|
GET_SLOT(width, Float);
|
||||||
|
GET_SLOT(height, Float);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Resolution::convert(SQObject object)
|
||||||
|
{
|
||||||
|
Array arrayWrapper(object);
|
||||||
|
GET_SLOT(x, Int);
|
||||||
|
GET_SLOT(y, Int);
|
||||||
|
GET_SLOT(bpp, Int);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Item::convert(SQObject object)
|
||||||
|
{
|
||||||
|
Array arrayWrapper(object);
|
||||||
|
GET_SLOT(instance, Int);
|
||||||
|
GET_SLOT(amount, Int);
|
||||||
|
GET_SLOT(name, String);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Color::convert(SQObject object)
|
||||||
|
{
|
||||||
|
Array arrayWrapper(object);
|
||||||
|
GET_SLOT(r, Int);
|
||||||
|
GET_SLOT(g, Int);
|
||||||
|
GET_SLOT(b, Int);
|
||||||
|
}
|
||||||
|
|
||||||
|
void BodyVisual::convert(SQObject object)
|
||||||
|
{
|
||||||
|
Array arrayWrapper(object);
|
||||||
|
GET_SLOT(bodyModel, String);
|
||||||
|
GET_SLOT(bodyTxt, Int);
|
||||||
|
GET_SLOT(headModel, String);
|
||||||
|
GET_SLOT(headTxt, Int);
|
||||||
|
}
|
||||||
|
|
||||||
|
void NetworkStats::convert(SQObject object)
|
||||||
|
{
|
||||||
|
Array arrayWrapper(object);
|
||||||
|
GET_SLOT(packetReceived, Int);
|
||||||
|
GET_SLOT(packetlossTotal, Int);
|
||||||
|
GET_SLOT(packetlossLastSecond, Int);
|
||||||
|
GET_SLOT(messagesInResendBuffer, Int);
|
||||||
|
GET_SLOT(messageInSendBuffer, Int);
|
||||||
|
GET_SLOT(bytesInResendBuffer, Int);
|
||||||
|
GET_SLOT(bytesInSendBuffer, Int);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Position3dWithName::convert(SQObject object)
|
||||||
|
{
|
||||||
|
Array arrayWrapper(object);
|
||||||
|
GET_SLOT(name, String);
|
||||||
|
GET_SLOT(x, Float);
|
||||||
|
GET_SLOT(y, Float);
|
||||||
|
GET_SLOT(z, Float);
|
||||||
|
}
|
||||||
|
}
|
||||||
168
src/NoNut/core/CustomTypes.h
Normal file
168
src/NoNut/core/CustomTypes.h
Normal file
@@ -0,0 +1,168 @@
|
|||||||
|
#ifndef NONUT_G2O_SHARED_CUSTOM_TYPES_H
|
||||||
|
#define NONUT_G2O_SHARED_CUSTOM_TYPES_H
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "Utils.h"
|
||||||
|
|
||||||
|
namespace nonut::g2o
|
||||||
|
{
|
||||||
|
struct GameTime : CustomType
|
||||||
|
{
|
||||||
|
void convert(SQObject object) override;
|
||||||
|
Int day{};
|
||||||
|
Int hour{};
|
||||||
|
Int min{};
|
||||||
|
|
||||||
|
auto toTuple()
|
||||||
|
{
|
||||||
|
return std::make_tuple(day, hour, min);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Position2d : CustomType
|
||||||
|
{
|
||||||
|
void convert(SQObject object) override;
|
||||||
|
Int x{};
|
||||||
|
Int y{};
|
||||||
|
auto toTuple()
|
||||||
|
{
|
||||||
|
return std::make_tuple(x, y);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Position3d : CustomType
|
||||||
|
{
|
||||||
|
void convert(SQObject object) override;
|
||||||
|
Float x{};
|
||||||
|
Float y{};
|
||||||
|
Float z{};
|
||||||
|
auto toTuple()
|
||||||
|
{
|
||||||
|
return std::make_tuple(x, y, z);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Size2d : CustomType
|
||||||
|
{
|
||||||
|
void convert(SQObject object) override;
|
||||||
|
Int width{};
|
||||||
|
Int height{};
|
||||||
|
auto toTuple()
|
||||||
|
{
|
||||||
|
return std::make_tuple(width, height);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Rect : CustomType
|
||||||
|
{
|
||||||
|
void convert(SQObject object) override;
|
||||||
|
Int x;
|
||||||
|
Int y;
|
||||||
|
Int width;
|
||||||
|
Int height;
|
||||||
|
auto toTuple()
|
||||||
|
{
|
||||||
|
return std::make_tuple(x, y, width, height);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct UV : CustomType
|
||||||
|
{
|
||||||
|
void convert(SQObject object) override;
|
||||||
|
Float x;
|
||||||
|
Float y;
|
||||||
|
Float width;
|
||||||
|
Float height;
|
||||||
|
auto toTuple()
|
||||||
|
{
|
||||||
|
return std::make_tuple(x, y, width, height);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Resolution : CustomType
|
||||||
|
{
|
||||||
|
void convert(SQObject object) override;
|
||||||
|
Int x{};
|
||||||
|
Int y{};
|
||||||
|
Int bpp{};
|
||||||
|
auto toTuple()
|
||||||
|
{
|
||||||
|
return std::make_tuple(x, y, bpp);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Item : CustomType
|
||||||
|
{
|
||||||
|
void convert(SQObject object) override;
|
||||||
|
Int instance{};
|
||||||
|
Int amount{};
|
||||||
|
String name{};
|
||||||
|
auto toTuple()
|
||||||
|
{
|
||||||
|
return std::make_tuple(instance, amount, name);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Color : CustomType
|
||||||
|
{
|
||||||
|
void convert(SQObject object) override;
|
||||||
|
Int r{};
|
||||||
|
Int g{};
|
||||||
|
Int b{};
|
||||||
|
auto toTuple()
|
||||||
|
{
|
||||||
|
return std::make_tuple(r, g, b);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct BodyVisual : CustomType
|
||||||
|
{
|
||||||
|
void convert(SQObject object) override;
|
||||||
|
String bodyModel{};
|
||||||
|
Int bodyTxt{};
|
||||||
|
String headModel{};
|
||||||
|
Int headTxt{};
|
||||||
|
auto toTuple()
|
||||||
|
{
|
||||||
|
return std::make_tuple(bodyModel, bodyTxt, headModel, headTxt);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct NetworkStats : CustomType
|
||||||
|
{
|
||||||
|
void convert(SQObject object) override;
|
||||||
|
Int packetReceived{};
|
||||||
|
Int packetlossTotal{};
|
||||||
|
Int packetlossLastSecond{};
|
||||||
|
Int messagesInResendBuffer{};
|
||||||
|
Int messageInSendBuffer{};
|
||||||
|
Int bytesInResendBuffer{};
|
||||||
|
Int bytesInSendBuffer{};
|
||||||
|
auto toTuple()
|
||||||
|
{
|
||||||
|
return std::make_tuple(
|
||||||
|
packetReceived,
|
||||||
|
packetlossTotal,
|
||||||
|
packetlossLastSecond,
|
||||||
|
messagesInResendBuffer,
|
||||||
|
messageInSendBuffer,
|
||||||
|
bytesInResendBuffer,
|
||||||
|
bytesInSendBuffer);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Position3dWithName : CustomType
|
||||||
|
{
|
||||||
|
void convert(SQObject object) override;
|
||||||
|
String name{};
|
||||||
|
Float x{};
|
||||||
|
Float y{};
|
||||||
|
Float z{};
|
||||||
|
auto toTuple()
|
||||||
|
{
|
||||||
|
return std::make_tuple(name, x, y, z);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
#endif // NONUT_G2O_SHARED_CUSTOM_TYPES_H
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
#ifndef NONUT_CORE_INSTANCE_H
|
#ifndef NONUT_CORE_INSTANCE_H
|
||||||
#define NONUT_CORE_INSTANCE_H
|
#define NONUT_CORE_INSTANCE_H
|
||||||
|
#include <sqapi.h>
|
||||||
|
|
||||||
namespace nonut
|
namespace nonut
|
||||||
{
|
{
|
||||||
|
|||||||
34
src/bind.cpp
Normal file
34
src/bind.cpp
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
#include <pybind11/embed.h>
|
||||||
|
#include "classes/py/Packet.h"
|
||||||
|
|
||||||
|
namespace py = pybind11;
|
||||||
|
|
||||||
|
PYBIND11_EMBEDDED_MODULE(sqg2o, m) {
|
||||||
|
py::class_<PyPacket>(m, "Packet")
|
||||||
|
.def(py::init<>())
|
||||||
|
.def("reset", &PyPacket::reset)
|
||||||
|
.def("send", &PyPacket::send)
|
||||||
|
.def("sendToAll", &PyPacket::sendToAll)
|
||||||
|
.def("writeInt8", &PyPacket::writeInt8)
|
||||||
|
.def("writeUInt8", &PyPacket::writeUInt8)
|
||||||
|
.def("writeInt16", &PyPacket::writeInt16)
|
||||||
|
.def("writeUInt16", &PyPacket::writeUInt16)
|
||||||
|
.def("writeInt32", &PyPacket::writeInt32)
|
||||||
|
.def("writeUInt32", &PyPacket::writeUInt32)
|
||||||
|
.def("writeFloat", &PyPacket::writeFloat)
|
||||||
|
.def("writeBool", &PyPacket::writeBool)
|
||||||
|
.def("writeString", &PyPacket::writeString)
|
||||||
|
.def("readInt8", &PyPacket::readInt8)
|
||||||
|
.def("readUInt8", &PyPacket::readUInt8)
|
||||||
|
.def("readInt16", &PyPacket::readInt16)
|
||||||
|
.def("readUInt16", &PyPacket::readUInt16)
|
||||||
|
.def("readInt32", &PyPacket::readInt32)
|
||||||
|
.def("readUInt32", &PyPacket::readUInt32)
|
||||||
|
.def("readFloat", &PyPacket::readFloat)
|
||||||
|
.def("readBool", &PyPacket::readBool)
|
||||||
|
.def("readString", &PyPacket::readString)
|
||||||
|
.def("__del__", &PyPacket::del)
|
||||||
|
|
||||||
|
.def_property_readonly("bitsUsed", &PyPacket::getBitsUsed)
|
||||||
|
.def_property_readonly("bytesUsed", &PyPacket::getBytesUsed);
|
||||||
|
}
|
||||||
47
src/classes/py/Packet.h
Normal file
47
src/classes/py/Packet.h
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
#ifndef _PYPACKET_H_
|
||||||
|
#define _PYPACKET_
|
||||||
|
|
||||||
|
#include <classes/sq/Packet.h>
|
||||||
|
|
||||||
|
class PyPacket
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
nonut::Packet *sqpacket;
|
||||||
|
|
||||||
|
public:
|
||||||
|
PyPacket() { sqpacket = new nonut::Packet(); };
|
||||||
|
PyPacket(SQObject obj) { sqpacket = new nonut::Packet(obj); }
|
||||||
|
|
||||||
|
void reset() { sqpacket->reset(); }
|
||||||
|
void send(nonut::Int id, nonut::Int value) { sqpacket->send(id, value); }
|
||||||
|
void sendToAll(nonut::Int value) { sqpacket->sendToAll(value); };
|
||||||
|
|
||||||
|
void writeInt8(nonut::Int value) { sqpacket->writeInt8(value); }
|
||||||
|
void writeUInt8(nonut::Int value) { sqpacket->writeUInt8(value); }
|
||||||
|
void writeInt16(nonut::Int value) { sqpacket->writeInt16(value); }
|
||||||
|
void writeUInt16(nonut::Int value) { sqpacket->writeUInt16(value); }
|
||||||
|
void writeInt32(nonut::Int value) { sqpacket->writeInt32(value); }
|
||||||
|
void writeUInt32(nonut::Int value) { sqpacket->writeUInt32(value); }
|
||||||
|
|
||||||
|
void writeBool(nonut::Bool value) { sqpacket->writeBool(value); }
|
||||||
|
void writeFloat(nonut::Float value) { sqpacket->writeFloat(value); }
|
||||||
|
void writeString(nonut::String value) { sqpacket->writeString(value); }
|
||||||
|
|
||||||
|
nonut::Int readInt8() { return sqpacket->readInt8(); }
|
||||||
|
nonut::Int readUInt8() { return sqpacket->readUInt8(); }
|
||||||
|
nonut::Int readInt16() { return sqpacket->readInt16(); }
|
||||||
|
nonut::Int readUInt16() { return sqpacket->readUInt16(); }
|
||||||
|
nonut::Int readInt32() { return sqpacket->readInt32(); }
|
||||||
|
nonut::Int readUInt32() { return sqpacket->readUInt32(); }
|
||||||
|
|
||||||
|
nonut::Bool readBool() { return sqpacket->readBool(); }
|
||||||
|
nonut::Float readFloat() { return sqpacket->readFloat(); }
|
||||||
|
nonut::String readString() { return sqpacket->readString(); }
|
||||||
|
|
||||||
|
nonut::Int getBitsUsed() { return sqpacket->bitsUsed; }
|
||||||
|
nonut::Int getBytesUsed() { return sqpacket->bytesUsed; }
|
||||||
|
|
||||||
|
void del() { delete sqpacket; }
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
64
src/classes/sq/Packet.cpp
Normal file
64
src/classes/sq/Packet.cpp
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
#include <NoNut/core/CommonHeader.h>
|
||||||
|
#include "Packet.h"
|
||||||
|
|
||||||
|
namespace nonut
|
||||||
|
{
|
||||||
|
Packet::Packet() :
|
||||||
|
Class("Packet"),
|
||||||
|
METHOD_CTOR(reset),
|
||||||
|
METHOD_CTOR(send),
|
||||||
|
METHOD_CTOR(sendToAll),
|
||||||
|
METHOD_CTOR(writeBool),
|
||||||
|
METHOD_CTOR(writeInt8),
|
||||||
|
METHOD_CTOR(writeUInt8),
|
||||||
|
METHOD_CTOR(writeInt16),
|
||||||
|
METHOD_CTOR(writeUInt16),
|
||||||
|
METHOD_CTOR(writeInt32),
|
||||||
|
METHOD_CTOR(writeUInt32),
|
||||||
|
METHOD_CTOR(writeFloat),
|
||||||
|
METHOD_CTOR(writeString),
|
||||||
|
METHOD_CTOR(readBool),
|
||||||
|
METHOD_CTOR(readInt8),
|
||||||
|
METHOD_CTOR(readUInt8),
|
||||||
|
METHOD_CTOR(readInt16),
|
||||||
|
METHOD_CTOR(readUInt16),
|
||||||
|
METHOD_CTOR(readInt32),
|
||||||
|
METHOD_CTOR(readUInt32),
|
||||||
|
METHOD_CTOR(readFloat),
|
||||||
|
METHOD_CTOR(readString),
|
||||||
|
|
||||||
|
PROPERTY_CTOR(bitsUsed),
|
||||||
|
PROPERTY_CTOR(bytesUsed)
|
||||||
|
{
|
||||||
|
classCtor();
|
||||||
|
}
|
||||||
|
|
||||||
|
Packet::Packet(SQObject object) :
|
||||||
|
Class("Packet", object),
|
||||||
|
METHOD_CTOR(reset),
|
||||||
|
METHOD_CTOR(send),
|
||||||
|
METHOD_CTOR(sendToAll),
|
||||||
|
METHOD_CTOR(writeBool),
|
||||||
|
METHOD_CTOR(writeInt8),
|
||||||
|
METHOD_CTOR(writeUInt8),
|
||||||
|
METHOD_CTOR(writeInt16),
|
||||||
|
METHOD_CTOR(writeUInt16),
|
||||||
|
METHOD_CTOR(writeInt32),
|
||||||
|
METHOD_CTOR(writeUInt32),
|
||||||
|
METHOD_CTOR(writeFloat),
|
||||||
|
METHOD_CTOR(writeString),
|
||||||
|
METHOD_CTOR(readBool),
|
||||||
|
METHOD_CTOR(readInt8),
|
||||||
|
METHOD_CTOR(readUInt8),
|
||||||
|
METHOD_CTOR(readInt16),
|
||||||
|
METHOD_CTOR(readUInt16),
|
||||||
|
METHOD_CTOR(readInt32),
|
||||||
|
METHOD_CTOR(readUInt32),
|
||||||
|
METHOD_CTOR(readFloat),
|
||||||
|
METHOD_CTOR(readString),
|
||||||
|
|
||||||
|
PROPERTY_CTOR(bitsUsed),
|
||||||
|
PROPERTY_CTOR(bytesUsed)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
45
src/classes/sq/Packet.h
Normal file
45
src/classes/sq/Packet.h
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
#ifndef NONUT_G2O_SERVER_CLASS_PACKET
|
||||||
|
#define NONUT_G2O_SERVER_CLASS_PACKET
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include <NoNut/core/Class.h>
|
||||||
|
#include <NoNut/core/CustomTypes.h>
|
||||||
|
|
||||||
|
namespace nonut
|
||||||
|
{
|
||||||
|
class Packet : public Class
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Packet();
|
||||||
|
explicit Packet(SQObject object);
|
||||||
|
|
||||||
|
// Methods
|
||||||
|
Function<void> reset;
|
||||||
|
Function<void, Int, Int> send;
|
||||||
|
Function<void, Int> sendToAll;
|
||||||
|
Function<void, Bool> writeBool;
|
||||||
|
Function<void, Int> writeInt8;
|
||||||
|
Function<void, Int> writeUInt8;
|
||||||
|
Function<void, Int> writeInt16;
|
||||||
|
Function<void, Int> writeUInt16;
|
||||||
|
Function<void, Int> writeInt32;
|
||||||
|
Function<void, Int> writeUInt32;
|
||||||
|
Function<void, Float> writeFloat;
|
||||||
|
Function<void, String&> writeString;
|
||||||
|
Function<Bool> readBool;
|
||||||
|
Function<Int> readInt8;
|
||||||
|
Function<Int> readUInt8;
|
||||||
|
Function<Int> readInt16;
|
||||||
|
Function<Int> readUInt16;
|
||||||
|
Function<Int> readInt32;
|
||||||
|
Function<Int> readUInt32;
|
||||||
|
Function<Float> readFloat;
|
||||||
|
Function<String> readString;
|
||||||
|
|
||||||
|
// Properties
|
||||||
|
Property<Int> bitsUsed;
|
||||||
|
Property<Int> bytesUsed;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
#endif // NONUT_G2O_SERVER_CLASS_PACKET
|
||||||
|
|
||||||
@@ -84,4 +84,6 @@ void registerSquirrelEvents()
|
|||||||
addEventHandler("onPlayerEquipRing", sq_onPlayerEquipRing, 0);
|
addEventHandler("onPlayerEquipRing", sq_onPlayerEquipRing, 0);
|
||||||
addEventHandler("onPlayerEquipShield", sq_onPlayerEquipShield, 0);
|
addEventHandler("onPlayerEquipShield", sq_onPlayerEquipShield, 0);
|
||||||
addEventHandler("onPlayerEquipSpell", sq_onPlayerEquipSpell, 0);
|
addEventHandler("onPlayerEquipSpell", sq_onPlayerEquipSpell, 0);
|
||||||
|
|
||||||
|
addEventHandler("onPacket", sq_onPacket, 0);
|
||||||
}
|
}
|
||||||
@@ -45,6 +45,8 @@ SQInteger sq_onPlayerSpellSetup(HSQUIRRELVM);
|
|||||||
SQInteger sq_onPlayerTeleport(HSQUIRRELVM);
|
SQInteger sq_onPlayerTeleport(HSQUIRRELVM);
|
||||||
SQInteger sq_onPlayerToggleFaceAni(HSQUIRRELVM);
|
SQInteger sq_onPlayerToggleFaceAni(HSQUIRRELVM);
|
||||||
|
|
||||||
|
SQInteger sq_onPacket(HSQUIRRELVM);
|
||||||
|
|
||||||
void registerSquirrelEvents();
|
void registerSquirrelEvents();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
24
src/events/sqevents_network.cpp
Normal file
24
src/events/sqevents_network.cpp
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
#include <sqapi.h>
|
||||||
|
#include <pybind11/embed.h>
|
||||||
|
#include "NoNut/core/Utils.h"
|
||||||
|
#include <classes/py/Packet.h>
|
||||||
|
#include "sqevents.h"
|
||||||
|
|
||||||
|
namespace py = pybind11;
|
||||||
|
using namespace pybind11::literals;
|
||||||
|
|
||||||
|
extern py::module_ g2o;
|
||||||
|
|
||||||
|
SQInteger sq_onPacket(HSQUIRRELVM vm)
|
||||||
|
{
|
||||||
|
SQInteger playerid;
|
||||||
|
HSQOBJECT data;
|
||||||
|
|
||||||
|
nonut::sqGetValue(vm, 2, &playerid);
|
||||||
|
nonut::sqGetValue(vm, 3, &data);
|
||||||
|
|
||||||
|
py::dict kwargs = py::dict("playerid"_a=playerid, "data"_a=PyPacket(data));
|
||||||
|
callEvent("onPacket", kwargs);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
#include <sqapi.h>
|
#include <sqapi.h>
|
||||||
#include <pybind11/embed.h>
|
#include <pybind11/embed.h>
|
||||||
#include <iostream>
|
|
||||||
#include <pybind11/embed.h>
|
|
||||||
#include "events/sqevents.h"
|
#include "events/sqevents.h"
|
||||||
|
|
||||||
namespace py = pybind11;
|
namespace py = pybind11;
|
||||||
@@ -11,6 +9,7 @@ py::module_ pysys = py::module_::import("sys");
|
|||||||
py::module_ g2o;
|
py::module_ g2o;
|
||||||
py::module_ scripts;
|
py::module_ scripts;
|
||||||
|
|
||||||
|
|
||||||
extern "C" SQRESULT SQRAT_API sqmodule_load(HSQUIRRELVM vm, HSQAPI api)
|
extern "C" SQRESULT SQRAT_API sqmodule_load(HSQUIRRELVM vm, HSQAPI api)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|||||||
Reference in New Issue
Block a user