feat: implement all serverside exceptions

This commit is contained in:
izzy 2026-03-07 17:06:44 -05:00
parent e0408115ea
commit 839ce24b9e
2 changed files with 37 additions and 12 deletions

View file

@ -81,12 +81,13 @@ PlayerConnection::~PlayerConnection()
void PlayerConnection::tick() void PlayerConnection::tick()
{ {
if( done ) return; if (done || m_bCloseOnTick)
{
if( m_bCloseOnTick ) if (m_bCloseOnTick && !done)
{ {
disconnect( DisconnectPacket::eDisconnect_Closed ); disconnect(DisconnectPacket::eDisconnect_Closed);
return; }
return;
} }
didTick = false; didTick = false;
@ -98,12 +99,29 @@ void PlayerConnection::tick()
} }
catch (const IOException& e) catch (const IOException& e)
{ {
app.DebugPrintF("IOException -- %ls\n", e.information); app.DebugPrintf("IOException - %ls\n", e.information.c_str());
disconnect(DisconnectPacket::eDisconnect_None); disconnect(DisconnectPacket::eDisconnect_UnexpectedPacket);
return; return;
} }
catch (const RuntimeException &e)
{
app.DebugPrintf("RuntimeException - %ls\n", e.information.c_str());
disconnect(DisconnectPacket::eDisconnect_None); // izzint - no good disconnect packet for this, just keep as-is
return;
}
catch (const IllegalArgumentException &e)
{
app.DebugPrintf("IllegalArgumentException - %ls\n", e.information.c_str());
disconnect(DisconnectPacket::eDisconnect_None); // izzint - no good disconnect packet for this, just keep as-is
return;
}
catch (const EOFException &e)
{
app.DebugPrintf("EOFException - %ls\n", e.information.c_str());
disconnect(DisconnectPacket::eDisconnect_EndOfStream);
return;
}
connection->tick();
if(done) return; if(done) return;
if ((tickCount - lastKeepAliveTick) > 20 * 1) if ((tickCount - lastKeepAliveTick) > 20 * 1)

View file

@ -16,7 +16,14 @@ DataInputStream::DataInputStream(InputStream *in) : stream( in )
//This method simply performs in.read() and returns the result. //This method simply performs in.read() and returns the result.
int DataInputStream::read() int DataInputStream::read()
{ {
return stream->read(); int result = stream->read();
if (result == -1)
{
throw EOFException(L"DataInputStream::read - end of stream"); // izzint - implementation 4j didn't do for some reason
}
return result;
} }
//Reads some number of bytes from the contained input stream and stores them into the buffer array b. //Reads some number of bytes from the contained input stream and stores them into the buffer array b.
@ -134,7 +141,7 @@ bool DataInputStream::readFully(byteArray b)
int byteRead = stream->read(); int byteRead = stream->read();
if( byteRead == -1 ) if( byteRead == -1 )
{ {
return false; throw EOFException(L"DataInputStream::readFully - end of stream");
} }
else else
{ {
@ -153,7 +160,7 @@ bool DataInputStream::readFully(charArray b)
int byteRead = stream->read(); int byteRead = stream->read();
if( byteRead == -1 ) if( byteRead == -1 )
{ {
return false; throw EOFException(L"DataInputStream::readFully - end of stream");
} }
else else
{ {