mirror of
https://github.com/smartcmd/MinecraftConsoles.git
synced 2026-08-20 09:57:09 +00:00
feat: cleanup exceptions a bit
This commit is contained in:
parent
7c2869c5b9
commit
be6af511bd
|
|
@ -35,6 +35,9 @@
|
||||||
#include "..\Minecraft.World\net.minecraft.world.item.crafting.h"
|
#include "..\Minecraft.World\net.minecraft.world.item.crafting.h"
|
||||||
#include "Options.h"
|
#include "Options.h"
|
||||||
|
|
||||||
|
// MinecraftConsoles Added
|
||||||
|
#include "..\Minecraft.World\Exceptions.h"
|
||||||
|
|
||||||
Random PlayerConnection::random;
|
Random PlayerConnection::random;
|
||||||
|
|
||||||
PlayerConnection::PlayerConnection(MinecraftServer *server, Connection *connection, shared_ptr<ServerPlayer> player)
|
PlayerConnection::PlayerConnection(MinecraftServer *server, Connection *connection, shared_ptr<ServerPlayer> player)
|
||||||
|
|
@ -88,6 +91,18 @@ void PlayerConnection::tick()
|
||||||
|
|
||||||
didTick = false;
|
didTick = false;
|
||||||
tickCount++;
|
tickCount++;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
connection->tick();
|
||||||
|
}
|
||||||
|
catch (const IOException& e)
|
||||||
|
{
|
||||||
|
app.DebugPrintF("IOException -- %ls\n", e.information);
|
||||||
|
disconnect(DisconnectPacket::eDisconnect_None);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
connection->tick();
|
connection->tick();
|
||||||
if(done) return;
|
if(done) return;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,29 +1,30 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
class EOFException : public std::exception
|
// izzint - TODO: these other exceptions should really be implemented
|
||||||
|
|
||||||
|
class EOFException : public std::runtime_error
|
||||||
{
|
{
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class IllegalArgumentException : public std::exception
|
class IllegalArgumentException : public std::runtime_error
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
wstring information;
|
std::wstring information;
|
||||||
|
|
||||||
IllegalArgumentException(const wstring& information);
|
IllegalArgumentException(const std::wstring& information);
|
||||||
};
|
};
|
||||||
|
|
||||||
class IOException : public std::exception
|
class IOException : public std::runtime_error
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
wstring information;
|
std::wstring information;
|
||||||
|
|
||||||
IOException(const wstring& information);
|
IOException(const std::wstring& information);
|
||||||
};
|
};
|
||||||
|
|
||||||
class RuntimeException : public std::exception
|
class RuntimeException : public std::runtime_error
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
RuntimeException(const wstring& information);
|
RuntimeException(const std::wstring& information);
|
||||||
};
|
};
|
||||||
|
|
@ -157,9 +157,9 @@ IllegalArgumentException::IllegalArgumentException(const wstring& information)
|
||||||
this->information = information;
|
this->information = information;
|
||||||
}
|
}
|
||||||
|
|
||||||
IOException::IOException(const wstring& information)
|
IOException::IOException(const wstring &info) : std::runtime_error("IOException")
|
||||||
{
|
{
|
||||||
this->information = information;
|
this->information = info;
|
||||||
}
|
}
|
||||||
|
|
||||||
Packet::Packet() : createTime( System::currentTimeMillis() )
|
Packet::Packet() : createTime( System::currentTimeMillis() )
|
||||||
|
|
@ -379,12 +379,10 @@ void Packet::writePacket(shared_ptr<Packet> packet, DataOutputStream *dos) // th
|
||||||
|
|
||||||
void Packet::writeUtf(const wstring& value, DataOutputStream *dos) // throws IOException TODO 4J JEV, should this declare a throws?
|
void Packet::writeUtf(const wstring& value, DataOutputStream *dos) // throws IOException TODO 4J JEV, should this declare a throws?
|
||||||
{
|
{
|
||||||
#if 0
|
|
||||||
if (value.length() > Short::MAX_VALUE)
|
if (value.length() > Short::MAX_VALUE)
|
||||||
{
|
{
|
||||||
throw new IOException(L"String too big");
|
throw IOException(L"Packet::writeUtf - String too big");
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
dos->writeShort((short)value.length());
|
dos->writeShort((short)value.length());
|
||||||
dos->writeChars(value);
|
dos->writeChars(value);
|
||||||
|
|
@ -394,20 +392,15 @@ wstring Packet::readUtf(DataInputStream *dis, int maxLength) // throws IOExcepti
|
||||||
{
|
{
|
||||||
|
|
||||||
short stringLength = dis->readShort();
|
short stringLength = dis->readShort();
|
||||||
if (stringLength > maxLength)
|
|
||||||
|
if (stringLength > maxLength || stringLength < 0)
|
||||||
{
|
{
|
||||||
wstringstream stream;
|
throw IOException(L"Packet::readUtf - Invalid string passed");
|
||||||
stream << L"Received string length longer than maximum allowed (" << stringLength << " > " << maxLength << ")";
|
|
||||||
assert(false);
|
|
||||||
// throw new IOException( stream.str() );
|
|
||||||
}
|
|
||||||
if (stringLength < 0)
|
|
||||||
{
|
|
||||||
assert(false);
|
|
||||||
// throw new IOException(L"Received string length is less than zero! Weird string!");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wstring builder = L"";
|
wstring builder = L"";
|
||||||
|
builder.reserve(stringLength);
|
||||||
|
|
||||||
for (int i = 0; i < stringLength; i++)
|
for (int i = 0; i < stringLength; i++)
|
||||||
{
|
{
|
||||||
wchar_t rc = dis->readChar();
|
wchar_t rc = dis->readChar();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue