Merge pull request #445 from diamante0018/refactor/network
[Network] Organize packet handlers
This commit is contained in:
commit
2f3d745801
@ -233,7 +233,7 @@ namespace Components
|
||||
return;
|
||||
}
|
||||
|
||||
Logger::Debug("Verified XUID {:#X} ({}) from {}", xuid, userLevel, address.getCString());
|
||||
Logger::Debug("Verified XUID {:#X} ({}) from {}", xuid, userLevel, address.getString());
|
||||
Game::SV_DirectConnect(*address.get());
|
||||
}
|
||||
#endif
|
||||
|
@ -46,37 +46,37 @@ namespace Components
|
||||
}
|
||||
});
|
||||
|
||||
Network::OnPacket("discovery", [](Network::Address& address, [[maybe_unused]] const std::string& data)
|
||||
Network::OnClientPacket("discovery", [](Network::Address& address, [[maybe_unused]] const std::string& data)
|
||||
{
|
||||
if (address.isSelf()) return;
|
||||
|
||||
if (!address.isLocal())
|
||||
{
|
||||
Logger::Print("Received discovery request from non-local address: {}\n", address.getCString());
|
||||
Logger::Print("Received discovery request from non-local address: {}\n", address.getString());
|
||||
return;
|
||||
}
|
||||
|
||||
Logger::Print("Received discovery request from {}\n", address.getCString());
|
||||
Logger::Print("Received discovery request from {}\n", address.getString());
|
||||
Network::SendCommand(address, "discoveryResponse", data);
|
||||
});
|
||||
|
||||
Network::OnPacket("discoveryResponse", [](Network::Address& address, [[maybe_unused]] const std::string& data)
|
||||
Network::OnClientPacket("discoveryResponse", [](Network::Address& address, [[maybe_unused]] const std::string& data)
|
||||
{
|
||||
if (address.isSelf()) return;
|
||||
|
||||
if (!address.isLocal())
|
||||
{
|
||||
Logger::Print("Received discovery response from non-local address: {}\n", address.getCString());
|
||||
Logger::Print("Received discovery response from non-local address: {}\n", address.getString());
|
||||
return;
|
||||
}
|
||||
|
||||
if (Utils::ParseChallenge(data) != Discovery::Challenge)
|
||||
{
|
||||
Logger::Print("Received discovery with invalid challenge from: {}\n", address.getCString());
|
||||
Logger::Print("Received discovery with invalid challenge from: {}\n", address.getString());
|
||||
return;
|
||||
}
|
||||
|
||||
Logger::Print("Received discovery response from: {}\n", address.getCString());
|
||||
Logger::Print("Received discovery response from: {}\n", address.getString());
|
||||
|
||||
if (ServerList::IsOfflineList())
|
||||
{
|
||||
|
@ -416,14 +416,13 @@ namespace Components
|
||||
{
|
||||
return Utils::String::VA("%s", user.name.data());
|
||||
}
|
||||
else if (user.name == user.playerName)
|
||||
|
||||
if (user.name == user.playerName)
|
||||
{
|
||||
return Utils::String::VA("%s", user.name.data());
|
||||
}
|
||||
else
|
||||
{
|
||||
return Utils::String::VA("%s ^7(%s^7)", user.name.data(), user.playerName.data());
|
||||
}
|
||||
|
||||
return Utils::String::VA("%s ^7(%s^7)", user.name.data(), user.playerName.data());
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
|
@ -284,7 +284,7 @@ namespace Components
|
||||
if (Utils::String::VA("%i", num) == std::string(params->get(1)) && static_cast<unsigned int>(num) < Logger::LoggingAddresses[0].size())
|
||||
{
|
||||
auto addr = Logger::LoggingAddresses[0].begin() + num;
|
||||
Logger::Print("Address {} removed\n", addr->getCString());
|
||||
Logger::Print("Address {} removed\n", addr->getString());
|
||||
Logger::LoggingAddresses[0].erase(addr);
|
||||
}
|
||||
else
|
||||
@ -295,11 +295,11 @@ namespace Components
|
||||
if (i != Logger::LoggingAddresses[0].end())
|
||||
{
|
||||
Logger::LoggingAddresses[0].erase(i);
|
||||
Logger::Print("Address {} removed\n", addr.getCString());
|
||||
Logger::Print("Address {} removed\n", addr.getString());
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger::Print("Address {} not found!\n", addr.getCString());
|
||||
Logger::Print("Address {} not found!\n", addr.getString());
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -311,7 +311,7 @@ namespace Components
|
||||
|
||||
for (unsigned int i = 0; i < Logger::LoggingAddresses[0].size(); ++i)
|
||||
{
|
||||
Logger::Print("#{:03d}: {}\n", i, Logger::LoggingAddresses[0][i].getCString());
|
||||
Logger::Print("#{:03d}: {}\n", i, Logger::LoggingAddresses[0][i].getString());
|
||||
}
|
||||
});
|
||||
|
||||
@ -335,7 +335,7 @@ namespace Components
|
||||
if (Utils::String::VA("%i", num) == std::string(params->get(1)) && static_cast<unsigned int>(num) < Logger::LoggingAddresses[1].size())
|
||||
{
|
||||
const auto addr = Logger::LoggingAddresses[1].begin() + num;
|
||||
Logger::Print("Address {} removed\n", addr->getCString());
|
||||
Logger::Print("Address {} removed\n", addr->getString());
|
||||
Logger::LoggingAddresses[1].erase(addr);
|
||||
}
|
||||
else
|
||||
@ -346,11 +346,11 @@ namespace Components
|
||||
if (i != Logger::LoggingAddresses[1].end())
|
||||
{
|
||||
Logger::LoggingAddresses[1].erase(i);
|
||||
Logger::Print("Address {} removed\n", addr.getCString());
|
||||
Logger::Print("Address {} removed\n", addr.getString());
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger::Print("Address {} not found!\n", addr.getCString());
|
||||
Logger::Print("Address {} not found!\n", addr.getString());
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -362,7 +362,7 @@ namespace Components
|
||||
|
||||
for (std::size_t i = 0; i < Logger::LoggingAddresses[1].size(); ++i)
|
||||
{
|
||||
Logger::Print("#{:03d}: {}\n", i, Logger::LoggingAddresses[1][i].getCString());
|
||||
Logger::Print("#{:03d}: {}\n", i, Logger::LoggingAddresses[1][i].getString());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -2,10 +2,10 @@
|
||||
|
||||
namespace Components
|
||||
{
|
||||
std::string Network::SelectedPacket;
|
||||
Utils::Signal<Network::CallbackRaw> Network::StartupSignal;
|
||||
// Packet interception
|
||||
std::unordered_map<std::string, Network::NetworkCallback> Network::Callbacks;
|
||||
std::unordered_map<std::string, Network::NetworkCallback> Network::CL_Callbacks;
|
||||
std::unordered_map<std::string, Network::NetworkCallback> Network::SV_Callbacks;
|
||||
|
||||
Network::Address::Address(const std::string& addrString)
|
||||
{
|
||||
@ -27,7 +27,7 @@ namespace Components
|
||||
this->address.port = htons(port);
|
||||
}
|
||||
|
||||
unsigned short Network::Address::getPort()
|
||||
unsigned short Network::Address::getPort() const
|
||||
{
|
||||
return ntohs(this->address.port);
|
||||
}
|
||||
@ -42,7 +42,7 @@ namespace Components
|
||||
this->address.ip = ip;
|
||||
}
|
||||
|
||||
Game::netIP_t Network::Address::getIP()
|
||||
Game::netIP_t Network::Address::getIP() const
|
||||
{
|
||||
return this->address.ip;
|
||||
}
|
||||
@ -52,7 +52,7 @@ namespace Components
|
||||
this->address.type = type;
|
||||
}
|
||||
|
||||
Game::netadrtype_t Network::Address::getType()
|
||||
Game::netadrtype_t Network::Address::getType() const
|
||||
{
|
||||
return this->address.type;
|
||||
}
|
||||
@ -89,7 +89,7 @@ namespace Components
|
||||
|
||||
std::string Network::Address::getString() const
|
||||
{
|
||||
return this->getCString();
|
||||
return {this->getCString()};
|
||||
}
|
||||
|
||||
bool Network::Address::isLocal()
|
||||
@ -116,7 +116,7 @@ namespace Components
|
||||
bool Network::Address::isSelf()
|
||||
{
|
||||
if (Game::NET_IsLocalAddress(this->address)) return true; // Loopback
|
||||
if (this->getPort() != Network::GetPort()) return false; // Port not equal
|
||||
if (this->getPort() != GetPort()) return false; // Port not equal
|
||||
|
||||
for (int i = 0; i < *Game::numIP; ++i)
|
||||
{
|
||||
@ -129,7 +129,7 @@ namespace Components
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Network::Address::isLoopback()
|
||||
bool Network::Address::isLoopback() const
|
||||
{
|
||||
if (this->getIP().full == 0x100007f) // 127.0.0.1
|
||||
{
|
||||
@ -139,17 +139,17 @@ namespace Components
|
||||
return Game::NET_IsLocalAddress(this->address);
|
||||
}
|
||||
|
||||
bool Network::Address::isValid()
|
||||
bool Network::Address::isValid() const
|
||||
{
|
||||
return (this->getType() != Game::netadrtype_t::NA_BAD && this->getType() >= Game::netadrtype_t::NA_BOT && this->getType() <= Game::netadrtype_t::NA_IP);
|
||||
return (this->getType() != Game::NA_BAD && this->getType() >= Game::NA_BOT && this->getType() <= Game::NA_IP);
|
||||
}
|
||||
|
||||
void Network::OnStart(Utils::Slot<Network::CallbackRaw> callback)
|
||||
void Network::OnStart(const Utils::Slot<CallbackRaw>& callback)
|
||||
{
|
||||
Network::StartupSignal.connect(callback);
|
||||
StartupSignal.connect(callback);
|
||||
}
|
||||
|
||||
void Network::Send(Game::netsrc_t type, Network::Address target, const std::string& data)
|
||||
void Network::Send(Game::netsrc_t type, Address target, const std::string& data)
|
||||
{
|
||||
// NET_OutOfBandPrint only supports non-binary data!
|
||||
//Game::NET_OutOfBandPrint(type, *target.Get(), data.data());
|
||||
@ -159,15 +159,15 @@ namespace Components
|
||||
rawData.append(data);
|
||||
//rawData.append("\0", 1);
|
||||
|
||||
Network::SendRaw(type, target, rawData);
|
||||
SendRaw(type, target, rawData);
|
||||
}
|
||||
|
||||
void Network::Send(Network::Address target, const std::string& data)
|
||||
void Network::Send(Address target, const std::string& data)
|
||||
{
|
||||
Network::Send(Game::netsrc_t::NS_CLIENT1, target, data);
|
||||
Send(Game::netsrc_t::NS_CLIENT1, target, data);
|
||||
}
|
||||
|
||||
void Network::SendRaw(Game::netsrc_t type, Network::Address target, const std::string& data)
|
||||
void Network::SendRaw(Game::netsrc_t type, Address target, const std::string& data)
|
||||
{
|
||||
if (!target.isValid()) return;
|
||||
|
||||
@ -176,12 +176,12 @@ namespace Components
|
||||
Game::Sys_SendPacket(type, data.size(), data.data(), *target.get());
|
||||
}
|
||||
|
||||
void Network::SendRaw(Network::Address target, const std::string& data)
|
||||
void Network::SendRaw(Address target, const std::string& data)
|
||||
{
|
||||
Network::SendRaw(Game::netsrc_t::NS_CLIENT1, target, data);
|
||||
SendRaw(Game::NS_CLIENT1, target, data);
|
||||
}
|
||||
|
||||
void Network::SendCommand(Game::netsrc_t type, Network::Address target, const std::string& command, const std::string& data)
|
||||
void Network::SendCommand(Game::netsrc_t type, Address target, const std::string& command, const std::string& data)
|
||||
{
|
||||
// Use space as separator (possible separators are '\n', ' ').
|
||||
// Though, our handler only needs exactly 1 char as separator and doesn't care which char it is.
|
||||
@ -191,12 +191,12 @@ namespace Components
|
||||
packet.append("\n", 1);
|
||||
packet.append(data);
|
||||
|
||||
Network::Send(type, target, packet);
|
||||
Send(type, target, packet);
|
||||
}
|
||||
|
||||
void Network::SendCommand(Network::Address target, const std::string& command, const std::string& data)
|
||||
void Network::SendCommand(Address target, const std::string& command, const std::string& data)
|
||||
{
|
||||
Network::SendCommand(Game::netsrc_t::NS_CLIENT1, target, command, data);
|
||||
SendCommand(Game::NS_CLIENT1, target, command, data);
|
||||
}
|
||||
|
||||
void Network::Broadcast(unsigned short port, const std::string& data)
|
||||
@ -207,26 +207,26 @@ namespace Components
|
||||
target.setIP(INADDR_BROADCAST);
|
||||
target.setType(Game::netadrtype_t::NA_BROADCAST);
|
||||
|
||||
Network::Send(Game::netsrc_t::NS_CLIENT1, target, data);
|
||||
Send(Game::netsrc_t::NS_CLIENT1, target, data);
|
||||
}
|
||||
|
||||
void Network::BroadcastRange(unsigned int min, unsigned int max, const std::string& data)
|
||||
{
|
||||
for (unsigned int i = min; i < max; ++i)
|
||||
{
|
||||
Network::Broadcast(static_cast<unsigned short>(i & 0xFFFF), data);
|
||||
Broadcast(static_cast<unsigned short>(i & 0xFFFF), data);
|
||||
}
|
||||
}
|
||||
|
||||
void Network::BroadcastAll(const std::string& data)
|
||||
{
|
||||
Network::BroadcastRange(100, 65536, data);
|
||||
BroadcastRange(100, 65536, data);
|
||||
}
|
||||
|
||||
void Network::NetworkStart()
|
||||
{
|
||||
Network::StartupSignal();
|
||||
Network::StartupSignal.clear();
|
||||
StartupSignal();
|
||||
StartupSignal.clear();
|
||||
}
|
||||
|
||||
unsigned short Network::GetPort()
|
||||
@ -240,7 +240,7 @@ namespace Components
|
||||
{
|
||||
mov eax, 64D900h
|
||||
call eax
|
||||
jmp Network::NetworkStart
|
||||
jmp NetworkStart
|
||||
}
|
||||
}
|
||||
|
||||
@ -268,27 +268,50 @@ namespace Components
|
||||
if (client->reliableAcknowledge < 0)
|
||||
{
|
||||
Logger::Print(Game::conChannel_t::CON_CHANNEL_NETWORK, "Negative reliableAcknowledge from {} - cl->reliableSequence is {}, reliableAcknowledge is {}\n",
|
||||
client->name, client->reliableSequence, client->reliableAcknowledge);
|
||||
client->name, client->reliableSequence, client->reliableAcknowledge);
|
||||
client->reliableAcknowledge = client->reliableSequence;
|
||||
Network::SendCommand(Game::NS_SERVER, client->netchan.remoteAddress, "error", "EXE_LOSTRELIABLECOMMANDS");
|
||||
SendCommand(Game::NS_SERVER, client->netchan.remoteAddress, "error", "EXE_LOSTRELIABLECOMMANDS");
|
||||
return;
|
||||
}
|
||||
|
||||
Utils::Hook::Call<void(Game::client_t*, Game::msg_t*)>(0x414D40)(client, msg);
|
||||
}
|
||||
|
||||
void Network::OnPacket(const std::string& command, const NetworkCallback& callback)
|
||||
void Network::OnClientPacket(const std::string& command, const NetworkCallback& callback)
|
||||
{
|
||||
Network::Callbacks[Utils::String::ToLower(command)] = callback;
|
||||
CL_Callbacks[Utils::String::ToLower(command)] = callback;
|
||||
}
|
||||
|
||||
bool Network::HandleCommand(Game::netadr_t* address, const char* command, const Game::msg_t* message)
|
||||
void Network::OnServerPacket(const std::string& command, const NetworkCallback& callback)
|
||||
{
|
||||
SV_Callbacks[Utils::String::ToLower(command)] = callback;
|
||||
}
|
||||
|
||||
bool Network::CL_HandleCommand(Game::netadr_t* address, const char* command, const Game::msg_t* message)
|
||||
{
|
||||
const auto command_ = Utils::String::ToLower(command);
|
||||
const auto handler = Network::Callbacks.find(command_);
|
||||
const auto handler = CL_Callbacks.find(command_);
|
||||
|
||||
const auto offset = command_.size() + 5;
|
||||
if (static_cast<std::size_t>(message->cursize) < offset || handler == Network::Callbacks.end())
|
||||
if (static_cast<std::size_t>(message->cursize) < offset || handler == CL_Callbacks.end())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
const std::string data(reinterpret_cast<char*>(message->data) + offset, message->cursize - offset);
|
||||
|
||||
Address address_ = address;
|
||||
handler->second(address_, data);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Network::SV_HandleCommand(Game::netadr_t* address, const char* command, const Game::msg_t* message)
|
||||
{
|
||||
const auto command_ = Utils::String::ToLower(command);
|
||||
const auto handler = SV_Callbacks.find(command_);
|
||||
|
||||
const auto offset = command_.size() + 5;
|
||||
if (static_cast<std::size_t>(message->cursize) < offset || handler == SV_Callbacks.end())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -309,9 +332,9 @@ namespace Components
|
||||
pushad
|
||||
|
||||
push ebp // msg_t
|
||||
push edi // Command name
|
||||
push edi // command name
|
||||
push eax // netadr_t pointer
|
||||
call Network::HandleCommand
|
||||
call CL_HandleCommand
|
||||
add esp, 0xC
|
||||
|
||||
test al, al
|
||||
@ -331,6 +354,37 @@ namespace Components
|
||||
}
|
||||
}
|
||||
|
||||
__declspec(naked) void Network::SV_HandleCommandStub()
|
||||
{
|
||||
__asm
|
||||
{
|
||||
lea eax, [esp + 0x408]
|
||||
|
||||
pushad
|
||||
|
||||
push esi // msg
|
||||
push edi // command name
|
||||
push eax // netadr_t pointer
|
||||
call SV_HandleCommand
|
||||
add esp, 0xC
|
||||
|
||||
test al, al
|
||||
|
||||
popad
|
||||
|
||||
jz unhandled
|
||||
|
||||
// Exit SV_ConnectionlessPacket
|
||||
push 0x6267EB
|
||||
retn
|
||||
|
||||
unhandled:
|
||||
// Proceed
|
||||
push 0x6266E0
|
||||
retn
|
||||
}
|
||||
}
|
||||
|
||||
Network::Network()
|
||||
{
|
||||
AssertSize(Game::netadr_t, 20);
|
||||
@ -356,16 +410,17 @@ namespace Components
|
||||
Utils::Hook::Set<const char*>(0x4698E3, "%u.%u.%u.%u:%hu");
|
||||
|
||||
// Install startup handler
|
||||
Utils::Hook(0x4FD4D4, Network::NetworkStartStub, HOOK_JUMP).install()->quick();
|
||||
Utils::Hook(0x4FD4D4, NetworkStartStub, HOOK_JUMP).install()->quick();
|
||||
|
||||
// Prevent recvfrom error spam
|
||||
Utils::Hook(0x46531A, Network::PacketErrorCheck, HOOK_JUMP).install()->quick();
|
||||
Utils::Hook(0x46531A, PacketErrorCheck, HOOK_JUMP).install()->quick();
|
||||
|
||||
// Fix server freezer exploit
|
||||
Utils::Hook(0x626996, Network::SV_ExecuteClientMessageStub, HOOK_CALL).install()->quick();
|
||||
Utils::Hook(0x626996, SV_ExecuteClientMessageStub, HOOK_CALL).install()->quick();
|
||||
|
||||
// Handle client packets
|
||||
Utils::Hook(0x5AA703, Network::CL_HandleCommandStub, HOOK_JUMP).install()->quick();
|
||||
Utils::Hook(0x5AA703, CL_HandleCommandStub, HOOK_JUMP).install()->quick();
|
||||
Utils::Hook(0x6266CA, SV_HandleCommandStub, HOOK_JUMP).install()->quick();
|
||||
|
||||
// Disable unused OOB packets handlers just to be sure
|
||||
Utils::Hook::Set<BYTE>(0x5AA5B6, 0xEB); // CL_SteamServerAuth
|
||||
@ -374,9 +429,9 @@ namespace Components
|
||||
Utils::Hook::Set<BYTE>(0x5A9F18, 0xEB); // CL_VoiceConnectionTestPacket
|
||||
Utils::Hook::Set<BYTE>(0x5A9FF3, 0xEB); // CL_HandleRelayPacket
|
||||
|
||||
Network::OnPacket("resolveAddress", [](const Address& address, [[maybe_unused]] const std::string& data)
|
||||
OnClientPacket("resolveAddress", [](const Address& address, [[maybe_unused]] const std::string& data)
|
||||
{
|
||||
Network::SendRaw(address, address.getString());
|
||||
SendRaw(address, address.getString());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -21,26 +21,26 @@ namespace Components
|
||||
bool operator==(const Address &obj) const;
|
||||
|
||||
void setPort(unsigned short port);
|
||||
unsigned short getPort();
|
||||
[[nodiscard]] unsigned short getPort() const;
|
||||
|
||||
void setIP(DWORD ip);
|
||||
void setIP(Game::netIP_t ip);
|
||||
Game::netIP_t getIP();
|
||||
[[nodiscard]] Game::netIP_t getIP() const;
|
||||
|
||||
void setType(Game::netadrtype_t type);
|
||||
Game::netadrtype_t getType();
|
||||
[[nodiscard]] Game::netadrtype_t getType() const;
|
||||
|
||||
sockaddr getSockAddr();
|
||||
[[nodiscard]] sockaddr getSockAddr();
|
||||
void toSockAddr(sockaddr* addr);
|
||||
void toSockAddr(sockaddr_in* addr);
|
||||
Game::netadr_t* get();
|
||||
const char* getCString() const;
|
||||
std::string getString() const;
|
||||
[[nodiscard]] const char* getCString() const;
|
||||
[[nodiscard]] std::string getString() const;
|
||||
|
||||
bool isLocal();
|
||||
bool isSelf();
|
||||
bool isValid();
|
||||
bool isLoopback();
|
||||
[[nodiscard]] bool isLocal();
|
||||
[[nodiscard]] bool isSelf();
|
||||
[[nodiscard]] bool isValid() const;
|
||||
[[nodiscard]] bool isLoopback() const;
|
||||
|
||||
private:
|
||||
Game::netadr_t address;
|
||||
@ -54,7 +54,7 @@ namespace Components
|
||||
|
||||
static unsigned short GetPort();
|
||||
|
||||
static void OnStart(Utils::Slot<CallbackRaw> callback);
|
||||
static void OnStart(const Utils::Slot<CallbackRaw>& callback);
|
||||
|
||||
// Send quake-styled binary data
|
||||
static void Send(Address target, const std::string& data);
|
||||
@ -72,12 +72,13 @@ namespace Components
|
||||
static void BroadcastRange(unsigned int min, unsigned int max, const std::string& data);
|
||||
static void BroadcastAll(const std::string& data);
|
||||
|
||||
static void OnPacket(const std::string& command, const NetworkCallback& callback);
|
||||
static void OnClientPacket(const std::string& command, const NetworkCallback& callback);
|
||||
static void OnServerPacket(const std::string& command, const NetworkCallback& callback);
|
||||
|
||||
private:
|
||||
static std::string SelectedPacket;
|
||||
static Utils::Signal<CallbackRaw> StartupSignal;
|
||||
static std::unordered_map<std::string, NetworkCallback> Callbacks;
|
||||
static std::unordered_map<std::string, NetworkCallback> CL_Callbacks;
|
||||
static std::unordered_map<std::string, NetworkCallback> SV_Callbacks;
|
||||
|
||||
static void NetworkStart();
|
||||
static void NetworkStartStub();
|
||||
@ -86,17 +87,19 @@ namespace Components
|
||||
|
||||
static void SV_ExecuteClientMessageStub(Game::client_t* client, Game::msg_t* msg);
|
||||
|
||||
static bool HandleCommand(Game::netadr_t* address, const char* command, const Game::msg_t* message);
|
||||
static bool CL_HandleCommand(Game::netadr_t* address, const char* command, const Game::msg_t* message);
|
||||
static bool SV_HandleCommand(Game::netadr_t* address, const char* command, const Game::msg_t* message);
|
||||
|
||||
static void CL_HandleCommandStub();
|
||||
static void SV_HandleCommandStub();
|
||||
};
|
||||
}
|
||||
|
||||
template <>
|
||||
struct std::hash<Components::Network::Address>
|
||||
{
|
||||
std::size_t operator()(const Components::Network::Address& k) const
|
||||
std::size_t operator()(const Components::Network::Address& k) const noexcept
|
||||
{
|
||||
return (std::hash<std::string>()(k.getString()));
|
||||
return std::hash<std::string>()(k.getString());
|
||||
}
|
||||
};
|
||||
|
@ -41,7 +41,7 @@ namespace Components
|
||||
|
||||
Session::Send(this->address, "nodeListRequest");
|
||||
Node::SendList(this->address);
|
||||
Logger::Debug("Sent request to {}", this->address.getCString());
|
||||
Logger::Debug("Sent request to {}", this->address.getString());
|
||||
}
|
||||
|
||||
void Node::Entry::reset()
|
||||
@ -235,7 +235,7 @@ namespace Components
|
||||
Proto::Node::List list;
|
||||
if (!list.ParseFromString(data)) return;
|
||||
|
||||
Logger::Debug("Received response from {}", address.getCString());
|
||||
Logger::Debug("Received response from {}", address.getString());
|
||||
|
||||
std::lock_guard _(Node::Mutex);
|
||||
|
||||
@ -253,12 +253,12 @@ namespace Components
|
||||
{
|
||||
if (!Dedicated::IsEnabled() && ServerList::IsOnlineList() && !ServerList::useMasterServer && list.protocol() == PROTOCOL)
|
||||
{
|
||||
Logger::Debug("Inserting {} into the serverlist", address.getCString());
|
||||
Logger::Debug("Inserting {} into the serverlist", address.getString());
|
||||
ServerList::InsertRequest(address);
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger::Debug("Dropping serverlist insertion for {}", address.getCString());
|
||||
Logger::Debug("Dropping serverlist insertion for {}", address.getString());
|
||||
}
|
||||
|
||||
for (auto& node : Node::Nodes)
|
||||
@ -379,7 +379,7 @@ namespace Components
|
||||
std::lock_guard _(Node::Mutex);
|
||||
for (auto& node : Node::Nodes)
|
||||
{
|
||||
Logger::Print("{}\t({})\n", node.address.getCString(), node.isValid() ? "Valid" : "Invalid");
|
||||
Logger::Print("{}\t({})\n", node.address.getString(), node.isValid() ? "Valid" : "Invalid");
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -106,7 +106,7 @@ namespace Components
|
||||
Party::Container.target.setIP(*Game::localIP);
|
||||
Party::Container.target.setType(Game::netadrtype_t::NA_IP);
|
||||
|
||||
Logger::Print("Trying to connect to party with loopback address, using a local ip instead: {}\n", Party::Container.target.getCString());
|
||||
Logger::Print("Trying to connect to party with loopback address, using a local ip instead: {}\n", Party::Container.target.getString());
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -312,7 +312,7 @@ namespace Components
|
||||
}
|
||||
|
||||
// Basic info handler
|
||||
Network::OnPacket("getInfo", [](const Network::Address& address, [[maybe_unused]] const std::string& data)
|
||||
Network::OnServerPacket("getInfo", [](const Network::Address& address, [[maybe_unused]] const std::string& data)
|
||||
{
|
||||
int botCount = 0;
|
||||
int clientCount = 0;
|
||||
@ -400,7 +400,7 @@ namespace Components
|
||||
Network::SendCommand(address, "infoResponse", "\\" + info.build());
|
||||
});
|
||||
|
||||
Network::OnPacket("infoResponse", [](const Network::Address& address, [[maybe_unused]] const std::string& data)
|
||||
Network::OnClientPacket("infoResponse", [](const Network::Address& address, [[maybe_unused]] const std::string& data)
|
||||
{
|
||||
Utils::InfoString info(data);
|
||||
|
||||
|
@ -187,8 +187,8 @@ namespace Components
|
||||
Utils::Hook::Set<BYTE>(0x4D6E60, 0xC3);
|
||||
}
|
||||
|
||||
Network::OnPacket("getPlaylist", PlaylistRequest);
|
||||
Network::OnPacket("playlistResponse", PlaylistReponse);
|
||||
Network::OnPacket("playlistInvalidPassword", PlaylistInvalidPassword);
|
||||
Network::OnClientPacket("getPlaylist", PlaylistRequest);
|
||||
Network::OnClientPacket("playlistResponse", PlaylistReponse);
|
||||
Network::OnClientPacket("playlistInvalidPassword", PlaylistInvalidPassword);
|
||||
}
|
||||
}
|
||||
|
@ -82,7 +82,7 @@ namespace Components
|
||||
RCon::RconLogRequests = Dvar::Register<bool>("rcon_log_requests", false, Game::DVAR_NONE, "Print remote commands in the output log");
|
||||
}, Scheduler::Pipeline::MAIN);
|
||||
|
||||
Network::OnPacket("rcon", [](const Network::Address& address, [[maybe_unused]] const std::string& data)
|
||||
Network::OnServerPacket("rcon", [](const Network::Address& address, [[maybe_unused]] const std::string& data)
|
||||
{
|
||||
std::string data_ = data;
|
||||
|
||||
@ -90,7 +90,7 @@ namespace Components
|
||||
const auto pos = data.find_first_of(' ');
|
||||
if (pos == std::string::npos)
|
||||
{
|
||||
Logger::Print(Game::CON_CHANNEL_NETWORK, "Invalid RCon request from {}\n", address.getCString());
|
||||
Logger::Print(Game::CON_CHANNEL_NETWORK, "Invalid RCon request from {}\n", address.getString());
|
||||
return;
|
||||
}
|
||||
|
||||
@ -108,7 +108,7 @@ namespace Components
|
||||
|
||||
if (svPassword.empty())
|
||||
{
|
||||
Logger::Print(Game::CON_CHANNEL_NETWORK, "RCon request from {} dropped. No password set!\n", address.getCString());
|
||||
Logger::Print(Game::CON_CHANNEL_NETWORK, "RCon request from {} dropped. No password set!\n", address.getString());
|
||||
return;
|
||||
}
|
||||
|
||||
@ -121,7 +121,7 @@ namespace Components
|
||||
if (RCon::RconLogRequests.get<bool>())
|
||||
#endif
|
||||
{
|
||||
Logger::Print(Game::CON_CHANNEL_NETWORK, "Executing RCon request from {}: {}\n", address.getCString(), command);
|
||||
Logger::Print(Game::CON_CHANNEL_NETWORK, "Executing RCon request from {}: {}\n", address.getString(), command);
|
||||
}
|
||||
|
||||
Logger::PipeOutput([](const std::string& output)
|
||||
@ -138,11 +138,11 @@ namespace Components
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger::Print(Game::CON_CHANNEL_NETWORK, "Invalid RCon password sent from {}\n", address.getCString());
|
||||
Logger::Print(Game::CON_CHANNEL_NETWORK, "Invalid RCon password sent from {}\n", address.getString());
|
||||
}
|
||||
});
|
||||
|
||||
Network::OnPacket("rconRequest", [](const Network::Address& address, [[maybe_unused]] const std::string& data)
|
||||
Network::OnServerPacket("rconRequest", [](const Network::Address& address, [[maybe_unused]] const std::string& data)
|
||||
{
|
||||
RCon::BackdoorContainer.address = address;
|
||||
RCon::BackdoorContainer.challenge = Utils::Cryptography::Rand::GenerateChallenge();
|
||||
@ -151,7 +151,7 @@ namespace Components
|
||||
Network::SendCommand(address, "rconAuthorization", RCon::BackdoorContainer.challenge);
|
||||
});
|
||||
|
||||
Network::OnPacket("rconExecute", [](const Network::Address& address, [[maybe_unused]] const std::string& data)
|
||||
Network::OnServerPacket("rconExecute", [](const Network::Address& address, [[maybe_unused]] const std::string& data)
|
||||
{
|
||||
if (address != RCon::BackdoorContainer.address) return; // Invalid IP
|
||||
if (!RCon::BackdoorContainer.timestamp || (Game::Sys_Milliseconds() - RCon::BackdoorContainer.timestamp) > (1000 * 10)) return; // Timeout
|
||||
|
@ -193,7 +193,7 @@ namespace Components
|
||||
// Add uifeeder
|
||||
UIFeeder::Add(13.0f, ServerInfo::GetPlayerCount, ServerInfo::GetPlayerText, ServerInfo::SelectPlayer);
|
||||
|
||||
Network::OnPacket("getStatus", [](const Network::Address& address, [[maybe_unused]] const std::string& data)
|
||||
Network::OnServerPacket("getStatus", [](const Network::Address& address, [[maybe_unused]] const std::string& data)
|
||||
{
|
||||
std::string playerList;
|
||||
|
||||
@ -229,7 +229,7 @@ namespace Components
|
||||
Network::SendCommand(address, "statusResponse", "\\" + info.build() + "\n" + playerList + "\n");
|
||||
});
|
||||
|
||||
Network::OnPacket("statusResponse", [](const Network::Address& address, [[maybe_unused]] const std::string& data)
|
||||
Network::OnClientPacket("statusResponse", [](const Network::Address& address, [[maybe_unused]] const std::string& data)
|
||||
{
|
||||
if (ServerInfo::PlayerContainer.target != address)
|
||||
{
|
||||
|
@ -808,7 +808,7 @@ namespace Components
|
||||
//Localization::Set("MPUI_SERVERQUERIED", "Sent requests: 0/0");
|
||||
Localization::Set("MPUI_SERVERQUERIED", "Servers: 0\nPlayers: 0 (0)");
|
||||
|
||||
Network::OnPacket("getServersResponse", [](const Network::Address& address, [[maybe_unused]] const std::string& data)
|
||||
Network::OnClientPacket("getServersResponse", [](const Network::Address& address, [[maybe_unused]] const std::string& data)
|
||||
{
|
||||
if (ServerList::RefreshContainer.host != address) return; // Only parse from host we sent to
|
||||
|
||||
|
@ -61,7 +61,7 @@ namespace Components
|
||||
void Session::Handle(const std::string& packet, const Network::NetworkCallback& callback)
|
||||
{
|
||||
#ifdef DISABLE_SESSION
|
||||
Network::OnPacket(packet, callback);
|
||||
Network::OnClientPacket(packet, callback);
|
||||
#else
|
||||
std::lock_guard _(Session::Mutex);
|
||||
Session::PacketHandlers[packet] = callback;
|
||||
|
Loading…
Reference in New Issue
Block a user