Feature/plugin api experimental (#12)

* added a null check to fix crash, expose internal latency value (its buggy)

* fix latency calculations

* sending packets from c#

* world save event, move shutdown def, move called location of shutdown, expose FourKit.FireEvent

* add docs

---------

Co-authored-by: sylvessa <225480449+sylvessa@users.noreply.github.com>
This commit is contained in:
DrPerkyLegit 2026-04-05 22:21:22 -04:00 committed by GitHub
parent 682989c8f1
commit 21b5accc69
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
18 changed files with 1420 additions and 20 deletions

View file

@ -1,3 +1,4 @@
#include "Connection.h"
#include "stdafx.h"
#include "InputOutputStream.h"
#include "Socket.h"
@ -32,6 +33,7 @@ void Connection::_init()
disconnectReason = DisconnectPacket::eDisconnect_None;
noInputTicks = 0;
estimatedRemaining = 0;
estimatedRemainingRaw = 0;
fakeLag = 0;
slowWriteDelay = 50;
@ -145,6 +147,23 @@ void Connection::setListener(PacketListener *packetListener)
this->packetListener = packetListener;
}
void Connection::send(unsigned char* buffer, int size)
{
if (quitting) return;
MemSect(15);
// 4J Jev, synchronized (&writeLock)
EnterCriticalSection(&writeLock);
estimatedRemainingRaw += size;
outgoingRaw.push(std::make_pair(buffer, size));
// 4J Jev, end synchronized.
LeaveCriticalSection(&writeLock);
MemSect(0);
}
void Connection::send(shared_ptr<Packet> packet)
{
if (quitting) return;
@ -232,6 +251,32 @@ bool Connection::writeTick()
didSomething = true;
}
if (!outgoingRaw.empty())
{
std::pair<unsigned char*, int> rawPacket;
EnterCriticalSection(&writeLock);
rawPacket = outgoingRaw.front();
outgoingRaw.pop();
estimatedRemainingRaw -= rawPacket.second;
LeaveCriticalSection(&writeLock);
for (int i = 0; i < rawPacket.second; i++) {
byteArrayDos->writeByte(rawPacket.first[i]);
}
// 4J Stu - Changed this so that rather than writing to the network stream through a buffered stream we want to:
// a) Only push whole "game" packets to QNet, rather than amalgamated chunks of data that may include many packets, and partial packets
// b) To be able to change the priority and queue of a packet if required
//sos->writeWithFlags( baos->buf, 0, baos->size(), 0 );
//baos->reset();
int value = rawPacket.first[0];
writeSizes[value] += rawPacket.second;
didSomething = true;
}
if ((slowWriteDelay-- <= 0) && !outgoing_slow.empty() && (fakeLag == 0 || System::currentTimeMillis() - outgoing_slow.front()->createTime >= fakeLag))
{
shared_ptr<Packet> packet;