diff --git a/src/Components/Loader.cpp b/src/Components/Loader.cpp index 3b7d2c46..65882eea 100644 --- a/src/Components/Loader.cpp +++ b/src/Components/Loader.cpp @@ -27,6 +27,7 @@ namespace Components Loader::Register(new UIFeeder()); Loader::Register(new UIScript()); Loader::Register(new FastFiles()); + Loader::Register(new Discovery()); Loader::Register(new Materials()); Loader::Register(new FileSystem()); Loader::Register(new QuickPatch()); diff --git a/src/Components/Loader.hpp b/src/Components/Loader.hpp index 6928fd3e..db1292ad 100644 --- a/src/Components/Loader.hpp +++ b/src/Components/Loader.hpp @@ -38,6 +38,7 @@ namespace Components #include "Modules\UIFeeder.hpp" #include "Modules\UIScript.hpp" #include "Modules\Dedicated.hpp" +#include "Modules\Discovery.hpp" #include "Modules\FastFiles.hpp" #include "Modules\Materials.hpp" #include "Modules\Singleton.hpp" diff --git a/src/Components/Modules/Discovery.cpp b/src/Components/Modules/Discovery.cpp new file mode 100644 index 00000000..2b82cd93 --- /dev/null +++ b/src/Components/Modules/Discovery.cpp @@ -0,0 +1,24 @@ +#include "..\..\STDInclude.hpp" +#include + +namespace Components +{ + Discovery::Discovery() + { + Command::Add("bcast", [] (Command::Params params) + { + std::async([]() + { + int start = Game::Com_Milliseconds(); + OutputDebugStringA("Start!"); + Network::BroadcastAll("getinfo xxx\n"); + OutputDebugStringA(Utils::VA("End: %d", Game::Com_Milliseconds() - start)); + }); + }); + } + + Discovery::~Discovery() + { + + } +} diff --git a/src/Components/Modules/Discovery.hpp b/src/Components/Modules/Discovery.hpp new file mode 100644 index 00000000..504b8c9e --- /dev/null +++ b/src/Components/Modules/Discovery.hpp @@ -0,0 +1,10 @@ +namespace Components +{ + class Discovery : public Component + { + public: + Discovery(); + ~Discovery(); + const char* GetName() { return "Discovery"; }; + }; +} diff --git a/src/Components/Modules/Network.cpp b/src/Components/Modules/Network.cpp index 969b6291..8e8565a0 100644 --- a/src/Components/Modules/Network.cpp +++ b/src/Components/Modules/Network.cpp @@ -15,11 +15,11 @@ namespace Components } void Network::Address::SetPort(unsigned short port) { - this->address.port = port; + this->address.port = htons(port); }; unsigned short Network::Address::GetPort() { - return this->address.port; + return ntohs(this->address.port); } void Network::Address::SetIP(DWORD ip) { @@ -29,6 +29,14 @@ namespace Components { return *(DWORD*)this->address.ip; } + void Network::Address::SetType(Game::netadrtype_t type) + { + this->address.type = type; + } + Game::netadrtype_t Network::Address::GetType() + { + return this->address.type; + } Game::netadr_t* Network::Address::Get() { return &this->address; @@ -70,6 +78,30 @@ namespace Components Network::SendRaw(Game::netsrc_t::NS_CLIENT, target, data); } + void Network::Broadcast(unsigned short port, std::string data) + { + Address target; + + target.SetPort(port); + target.SetIP(INADDR_BROADCAST); + target.SetType(Game::netadrtype_t::NA_BROADCAST); + + Network::SendRaw(Game::netsrc_t::NS_CLIENT, target, data); + } + + void Network::BroadcastRange(unsigned int min, unsigned int max, std::string data) + { + for (unsigned int i = min; i < max; i++) + { + Network::Broadcast((unsigned short)(i & 0xFFFF), data); + } + } + + void Network::BroadcastAll(std::string data) + { + Network::BroadcastRange(100, 65536, data); + } + int Network::PacketInterceptionHandler(const char* packet) { // Check if custom handler exists diff --git a/src/Components/Modules/Network.hpp b/src/Components/Modules/Network.hpp index 3a8517f5..9aae8068 100644 --- a/src/Components/Modules/Network.hpp +++ b/src/Components/Modules/Network.hpp @@ -20,6 +20,9 @@ namespace Components void SetIP(DWORD ip); DWORD GetIP(); + void SetType(Game::netadrtype_t type); + Game::netadrtype_t GetType(); + Game::netadr_t* Get(); const char* GetString(); @@ -44,6 +47,10 @@ namespace Components static void SendRaw(Address target, std::string data); static void SendRaw(Game::netsrc_t type, Address target, std::string data); + static void Broadcast(unsigned short port, std::string data); + static void BroadcastRange(unsigned int min, unsigned int max, std::string data); + static void BroadcastAll(std::string data); + private: static std::string SelectedPacket; static std::map PacketHandlers; diff --git a/src/Components/Modules/Party.cpp b/src/Components/Modules/Party.cpp index 74e5fa16..1ea43f1c 100644 --- a/src/Components/Modules/Party.cpp +++ b/src/Components/Modules/Party.cpp @@ -228,6 +228,7 @@ namespace Components // Basic info handler Network::Handle("getInfo", [] (Network::Address address, std::string data) { + OutputDebugStringA(Utils::VA("Received inforequest from: %s", address.GetString())); int clientCount = 0; int maxclientCount = *Game::svs_numclients; @@ -294,6 +295,7 @@ namespace Components Network::Handle("infoResponse", [] (Network::Address address, std::string data) { + OutputDebugStringA(Utils::VA("Received inforesponse from: %s", address.GetString())); Utils::InfoString info(data); // Handle connection diff --git a/src/Components/Modules/Playlist.cpp b/src/Components/Modules/Playlist.cpp index 138dc36a..32dd57f2 100644 --- a/src/Components/Modules/Playlist.cpp +++ b/src/Components/Modules/Playlist.cpp @@ -36,7 +36,7 @@ namespace Components Logger::Print("Received playlist request, sending currently stored buffer.\n"); // Split playlist data - int maxPacketSize = 1000; + unsigned int maxPacketSize = 1000; unsigned int maxBytes = Playlist::CurrentPlaylistBuffer.size(); for (unsigned int i = 0; i < maxBytes; i += maxPacketSize) diff --git a/src/Components/Modules/ServerList.cpp b/src/Components/Modules/ServerList.cpp index a042c14c..35b05773 100644 --- a/src/Components/Modules/ServerList.cpp +++ b/src/Components/Modules/ServerList.cpp @@ -247,6 +247,7 @@ namespace Components // Display in the menu, like in COD4 //Logger::Print("Sent %d/%d\n", ServerList::RefreshContainer.SentCount, ServerList::RefreshContainer.SendCount); + Localization::Set("MPUI_SERVERQUERIED", Utils::VA("Queried: %d/%d", ServerList::RefreshContainer.SentCount, ServerList::RefreshContainer.SendCount)); if (SendServers <= 0) break; } @@ -259,6 +260,8 @@ namespace Components ServerList::OnlineList.clear(); ServerList::VisibleList.clear(); + Localization::Set("MPUI_SERVERQUERIED", "Queried: 0/0"); + Network::Handle("getServersResponse", [] (Network::Address address, std::string data) { if (ServerList::RefreshContainer.Host != address) return; // Only parse from host we sent to