mirror of
https://github.com/smartcmd/MinecraftConsoles.git
synced 2026-08-20 09:57:09 +00:00
feat: improve handling in Packet
This commit is contained in:
parent
cfce17c19b
commit
e0408115ea
|
|
@ -1,7 +1,5 @@
|
|||
#pragma once
|
||||
|
||||
// izzint - TODO: these other exceptions should really be implemented
|
||||
|
||||
class EOFException : public std::runtime_error
|
||||
{
|
||||
public:
|
||||
|
|
|
|||
|
|
@ -152,15 +152,13 @@ void Packet::staticCtor()
|
|||
map(255, true, true, true, false, typeid(DisconnectPacket), DisconnectPacket::create);
|
||||
}
|
||||
|
||||
IllegalArgumentException::IllegalArgumentException(const wstring& information)
|
||||
{
|
||||
this->information = information;
|
||||
}
|
||||
IllegalArgumentException::IllegalArgumentException(const wstring &info) : std::runtime_error("IllegalArgumentException"), information(info) {}
|
||||
|
||||
IOException::IOException(const wstring &info) : std::runtime_error("IOException")
|
||||
{
|
||||
this->information = info;
|
||||
}
|
||||
EOFException::EOFException(const wstring &info) : std::runtime_error("EOFException"), information(info) {}
|
||||
|
||||
IOException::IOException(const wstring &info) : std::runtime_error("IOException"), information(info) {}
|
||||
|
||||
RuntimeException::RuntimeException(const wstring &info) : std::runtime_error("RuntimeException"), information(info) {}
|
||||
|
||||
Packet::Packet() : createTime( System::currentTimeMillis() )
|
||||
{
|
||||
|
|
@ -282,12 +280,7 @@ byteArray Packet::readBytes(DataInputStream *datainputstream)
|
|||
int size = datainputstream->readShort();
|
||||
if (size < 0)
|
||||
{
|
||||
app.DebugPrintf("Key was smaller than nothing! Weird key!");
|
||||
#ifndef _CONTENT_PACKAGE
|
||||
__debugbreak();
|
||||
#endif
|
||||
return byteArray();
|
||||
//throw new IOException("Key was smaller than nothing! Weird key!");
|
||||
throw IOException(L"Key was smaller than nothing! Weird key!");
|
||||
}
|
||||
|
||||
byteArray bytes(size);
|
||||
|
|
@ -296,7 +289,6 @@ byteArray Packet::readBytes(DataInputStream *datainputstream)
|
|||
return bytes;
|
||||
}
|
||||
|
||||
|
||||
bool Packet::canSendToAnyClient(shared_ptr<Packet> packet)
|
||||
{
|
||||
int packetId = packet->getId();
|
||||
|
|
@ -329,14 +321,14 @@ shared_ptr<Packet> Packet::readPacket(DataInputStream *dis, bool isServer) // th
|
|||
|
||||
if ((isServer && serverReceivedPackets.find(id) == serverReceivedPackets.end()) || (!isServer && clientReceivedPackets.find(id) == clientReceivedPackets.end()))
|
||||
{
|
||||
//app.DebugPrintf("Bad packet id %d\n", id);
|
||||
__debugbreak();
|
||||
assert(false);
|
||||
// throw new IOException(wstring(L"Bad packet id ") + std::to_wstring(id));
|
||||
throw IOException(wstring(L"Bad packet id ") + std::to_wstring(id));
|
||||
}
|
||||
|
||||
packet = getPacket(id);
|
||||
if (packet == NULL) assert(false);//throw new IOException(wstring(L"Bad packet id ") + std::to_wstring(id));
|
||||
if (packet == nullptr)
|
||||
{
|
||||
throw IOException(wstring(L"Bad packet id ") + std::to_wstring(id));
|
||||
}
|
||||
|
||||
//app.DebugPrintf("%s reading packet %d\n", isServer ? "Server" : "Client", packet->getId());
|
||||
packet->read(dis);
|
||||
|
|
|
|||
Loading…
Reference in a new issue