mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2025-01-19 12:07:13 +01:00
Improve the client script data event. Also fix a crash because the buffer type was not registered.
This commit is contained in:
parent
29abf2e9c0
commit
ea70a21437
@ -7,9 +7,6 @@
|
|||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
namespace SqMod {
|
namespace SqMod {
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
|
||||||
extern Object CreateBufferWrapperMove(Buffer && b);
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
void Core::EmitCustomEvent(Int32 group, Int32 header, Object & payload)
|
void Core::EmitCustomEvent(Int32 group, Int32 header, Object & payload)
|
||||||
{
|
{
|
||||||
@ -1064,19 +1061,42 @@ void Core::EmitVehicleUpdate(Int32 vehicle_id, vcmpVehicleUpdate update_type)
|
|||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
void Core::EmitClientScriptData(Int32 player_id, const uint8_t * data, size_t size)
|
void Core::EmitClientScriptData(Int32 player_id, const uint8_t * data, size_t size)
|
||||||
{
|
{
|
||||||
|
PlayerInst & _player = m_Players.at(player_id);
|
||||||
|
// Don't even bother if there's no one listening
|
||||||
|
if (_player.mOnClientScriptData.IsNull() && mOnClientScriptData.IsNull())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
// Allocate a buffer with the received size
|
// Allocate a buffer with the received size
|
||||||
Buffer b(size);
|
Buffer b(size);
|
||||||
// Replicate the data to the allocated buffer
|
// Replicate the data to the allocated buffer
|
||||||
b.Write(0, reinterpret_cast< Buffer::ConstPtr >(data), size);
|
b.Write(0, reinterpret_cast< Buffer::ConstPtr >(data), size);
|
||||||
// Wrap the buffer into a script object
|
// Prepare an object for the obtained buffer
|
||||||
const Object o = CreateBufferWrapperMove(std::move(b));
|
Object o;
|
||||||
// Wrap the buffer into a script object
|
// Attempt to create the requested buffer
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// Remember the current stack size
|
||||||
|
const StackGuard sg;
|
||||||
|
// Create a protected instance of a buffer wrapper
|
||||||
|
AutoDelete< BufferWrapper > ad(new BufferWrapper(std::move(b)));
|
||||||
|
// Transform the pointer into a script object
|
||||||
|
PushVar< BufferWrapper * >(DefaultVM::Get(), ad.Get());
|
||||||
|
// The script took over the instance now
|
||||||
|
ad.Release();
|
||||||
|
// Get the object from the stack and store it
|
||||||
|
o = Var< Object >(DefaultVM::Get(), -1).value;
|
||||||
|
}
|
||||||
|
catch (const std::exception & e)
|
||||||
|
{
|
||||||
|
STHROWF("%s", e.what()); // Re-package
|
||||||
|
}
|
||||||
|
// Make sure the buffer cannot be null at this point
|
||||||
if (o.IsNull())
|
if (o.IsNull())
|
||||||
{
|
{
|
||||||
STHROWF("Unable to transform script data into buffer");
|
STHROWF("Unable to transform script data into buffer");
|
||||||
}
|
}
|
||||||
// Forward the event call
|
// Forward the event call
|
||||||
PlayerInst & _player = m_Players.at(player_id);
|
|
||||||
Emit(_player.mOnClientScriptData, o, size);
|
Emit(_player.mOnClientScriptData, o, size);
|
||||||
Emit(mOnClientScriptData, _player.mObj, o, size);
|
Emit(mOnClientScriptData, _player.mObj, o, size);
|
||||||
}
|
}
|
||||||
|
@ -11,56 +11,6 @@ namespace SqMod {
|
|||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
extern void Register_BufferInterpreter(Table & bns);
|
extern void Register_BufferInterpreter(Table & bns);
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
|
||||||
Object CreateBufferWrapperCopy(const Buffer & b)
|
|
||||||
{
|
|
||||||
// Attempt to create the requested buffer
|
|
||||||
try
|
|
||||||
{
|
|
||||||
// Remember the current stack size
|
|
||||||
const StackGuard sg;
|
|
||||||
// Transform the pointer into a script object
|
|
||||||
PushVar< const BufferWrapper & >(DefaultVM::Get(), BufferWrapper(b));
|
|
||||||
// Get the object from the stack and return it
|
|
||||||
return Var< Object >(DefaultVM::Get(), -1).value;
|
|
||||||
}
|
|
||||||
catch (const Sqrat::Exception & e)
|
|
||||||
{
|
|
||||||
throw e; // Re-throw
|
|
||||||
}
|
|
||||||
catch (const std::exception & e)
|
|
||||||
{
|
|
||||||
STHROWF("%s", e.what()); // Re-package
|
|
||||||
}
|
|
||||||
// Shouldn't really reach this point
|
|
||||||
return NullObject();
|
|
||||||
}
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
|
||||||
Object CreateBufferWrapperMove(Buffer && b)
|
|
||||||
{
|
|
||||||
// Attempt to create the requested buffer
|
|
||||||
try
|
|
||||||
{
|
|
||||||
// Remember the current stack size
|
|
||||||
const StackGuard sg;
|
|
||||||
// Transform the pointer into a script object
|
|
||||||
PushVar< const BufferWrapper & >(DefaultVM::Get(), BufferWrapper(std::move(b)));
|
|
||||||
// Get the object from the stack and return it
|
|
||||||
return Var< Object >(DefaultVM::Get(), -1).value;
|
|
||||||
}
|
|
||||||
catch (const Sqrat::Exception & e)
|
|
||||||
{
|
|
||||||
throw e; // Re-throw
|
|
||||||
}
|
|
||||||
catch (const std::exception & e)
|
|
||||||
{
|
|
||||||
STHROWF("%s", e.what()); // Re-package
|
|
||||||
}
|
|
||||||
// Shouldn't really reach this point
|
|
||||||
return NullObject();
|
|
||||||
}
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
Object BufferWrapper::Create(SzType n)
|
Object BufferWrapper::Create(SzType n)
|
||||||
{
|
{
|
||||||
|
@ -40,6 +40,7 @@ extern void Register_IO(HSQUIRRELVM vm);
|
|||||||
extern void Register_Numeric(HSQUIRRELVM vm);
|
extern void Register_Numeric(HSQUIRRELVM vm);
|
||||||
extern void Register_String(HSQUIRRELVM vm);
|
extern void Register_String(HSQUIRRELVM vm);
|
||||||
extern void Register_System(HSQUIRRELVM vm);
|
extern void Register_System(HSQUIRRELVM vm);
|
||||||
|
extern void Register_Utils(HSQUIRRELVM vm);
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
extern void Register_Constants(HSQUIRRELVM vm);
|
extern void Register_Constants(HSQUIRRELVM vm);
|
||||||
@ -80,6 +81,7 @@ bool RegisterAPI(HSQUIRRELVM vm)
|
|||||||
Register_Numeric(vm);
|
Register_Numeric(vm);
|
||||||
Register_String(vm);
|
Register_String(vm);
|
||||||
Register_System(vm);
|
Register_System(vm);
|
||||||
|
Register_Utils(vm);
|
||||||
|
|
||||||
Register_Constants(vm);
|
Register_Constants(vm);
|
||||||
Register_Log(vm);
|
Register_Log(vm);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user