summaryrefslogtreecommitdiffstats
path: root/src/Protocol/ProtocolRecognizer.cpp
diff options
context:
space:
mode:
authorRorkh <78957156+Rorkh@users.noreply.github.com>2022-01-27 01:56:45 +0100
committerGitHub <noreply@github.com>2022-01-27 01:56:45 +0100
commit5fe1fe899bfe55b1c27fb03a7d7e76b0b67b9cc7 (patch)
tree555ed9a75b3d3c168fcd4b1461c8c6965e32cf3d /src/Protocol/ProtocolRecognizer.cpp
parentUpdate to libdeflate 1.9 (diff)
downloadcuberite-5fe1fe899bfe55b1c27fb03a7d7e76b0b67b9cc7.tar
cuberite-5fe1fe899bfe55b1c27fb03a7d7e76b0b67b9cc7.tar.gz
cuberite-5fe1fe899bfe55b1c27fb03a7d7e76b0b67b9cc7.tar.bz2
cuberite-5fe1fe899bfe55b1c27fb03a7d7e76b0b67b9cc7.tar.lz
cuberite-5fe1fe899bfe55b1c27fb03a7d7e76b0b67b9cc7.tar.xz
cuberite-5fe1fe899bfe55b1c27fb03a7d7e76b0b67b9cc7.tar.zst
cuberite-5fe1fe899bfe55b1c27fb03a7d7e76b0b67b9cc7.zip
Diffstat (limited to 'src/Protocol/ProtocolRecognizer.cpp')
-rw-r--r--src/Protocol/ProtocolRecognizer.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/Protocol/ProtocolRecognizer.cpp b/src/Protocol/ProtocolRecognizer.cpp
index ba179c1bf..9062eb9b5 100644
--- a/src/Protocol/ProtocolRecognizer.cpp
+++ b/src/Protocol/ProtocolRecognizer.cpp
@@ -90,6 +90,11 @@ void cMultiVersionProtocol::HandleIncomingDataInRecognitionStage(cClientHandle &
return;
}
+ if (TryHandleHTTPRequest(a_Client, a_Data))
+ {
+ return;
+ }
+
// TODO: recover from git history
// Unlengthed protocol, ...
@@ -238,6 +243,37 @@ void cMultiVersionProtocol::SendDisconnect(cClientHandle & a_Client, const AStri
+bool cMultiVersionProtocol::TryHandleHTTPRequest(cClientHandle & a_Client, ContiguousByteBuffer & a_Data)
+{
+ const auto RedirectUrl = cRoot::Get()->GetServer()->GetCustomRedirectUrl();
+
+ if (RedirectUrl.empty())
+ {
+ return false;
+ }
+
+ ContiguousByteBuffer Buffer;
+ m_Buffer.ReadSome(Buffer, 10U);
+ m_Buffer.ResetRead();
+
+ // The request line, hastily decoded with the hope that it's encoded in US-ASCII.
+ const std::string_view Value(reinterpret_cast<const char *>(Buffer.data()), Buffer.size());
+
+ if (Value == u8"GET / HTTP")
+ {
+ const auto Response = fmt::format(u8"HTTP/1.0 303 See Other\r\nLocation: {}\r\n\r\n", cRoot::Get()->GetServer()->GetCustomRedirectUrl());
+ a_Client.SendData({ reinterpret_cast<const std::byte *>(Response.data()), Response.size() });
+ a_Client.Destroy();
+ return true;
+ }
+
+ return false;
+}
+
+
+
+
+
std::unique_ptr<cProtocol> cMultiVersionProtocol::TryRecognizeLengthedProtocol(cClientHandle & a_Client)
{
UInt32 PacketType;