Servercount and discovery tests.

This commit is contained in:
momo5502 2016-01-03 19:28:47 +01:00
parent 0bbcff083b
commit b514b9fb9d
9 changed files with 83 additions and 3 deletions

View File

@ -27,6 +27,7 @@ namespace Components
Loader::Register(new UIFeeder()); Loader::Register(new UIFeeder());
Loader::Register(new UIScript()); Loader::Register(new UIScript());
Loader::Register(new FastFiles()); Loader::Register(new FastFiles());
Loader::Register(new Discovery());
Loader::Register(new Materials()); Loader::Register(new Materials());
Loader::Register(new FileSystem()); Loader::Register(new FileSystem());
Loader::Register(new QuickPatch()); Loader::Register(new QuickPatch());

View File

@ -38,6 +38,7 @@ namespace Components
#include "Modules\UIFeeder.hpp" #include "Modules\UIFeeder.hpp"
#include "Modules\UIScript.hpp" #include "Modules\UIScript.hpp"
#include "Modules\Dedicated.hpp" #include "Modules\Dedicated.hpp"
#include "Modules\Discovery.hpp"
#include "Modules\FastFiles.hpp" #include "Modules\FastFiles.hpp"
#include "Modules\Materials.hpp" #include "Modules\Materials.hpp"
#include "Modules\Singleton.hpp" #include "Modules\Singleton.hpp"

View File

@ -0,0 +1,24 @@
#include "..\..\STDInclude.hpp"
#include <future>
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()
{
}
}

View File

@ -0,0 +1,10 @@
namespace Components
{
class Discovery : public Component
{
public:
Discovery();
~Discovery();
const char* GetName() { return "Discovery"; };
};
}

View File

@ -15,11 +15,11 @@ namespace Components
} }
void Network::Address::SetPort(unsigned short port) void Network::Address::SetPort(unsigned short port)
{ {
this->address.port = port; this->address.port = htons(port);
}; };
unsigned short Network::Address::GetPort() unsigned short Network::Address::GetPort()
{ {
return this->address.port; return ntohs(this->address.port);
} }
void Network::Address::SetIP(DWORD ip) void Network::Address::SetIP(DWORD ip)
{ {
@ -29,6 +29,14 @@ namespace Components
{ {
return *(DWORD*)this->address.ip; 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() Game::netadr_t* Network::Address::Get()
{ {
return &this->address; return &this->address;
@ -70,6 +78,30 @@ namespace Components
Network::SendRaw(Game::netsrc_t::NS_CLIENT, target, data); 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) int Network::PacketInterceptionHandler(const char* packet)
{ {
// Check if custom handler exists // Check if custom handler exists

View File

@ -20,6 +20,9 @@ namespace Components
void SetIP(DWORD ip); void SetIP(DWORD ip);
DWORD GetIP(); DWORD GetIP();
void SetType(Game::netadrtype_t type);
Game::netadrtype_t GetType();
Game::netadr_t* Get(); Game::netadr_t* Get();
const char* GetString(); const char* GetString();
@ -44,6 +47,10 @@ namespace Components
static void SendRaw(Address target, std::string data); static void SendRaw(Address target, std::string data);
static void SendRaw(Game::netsrc_t type, 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: private:
static std::string SelectedPacket; static std::string SelectedPacket;
static std::map<std::string, Callback> PacketHandlers; static std::map<std::string, Callback> PacketHandlers;

View File

@ -228,6 +228,7 @@ namespace Components
// Basic info handler // Basic info handler
Network::Handle("getInfo", [] (Network::Address address, std::string data) Network::Handle("getInfo", [] (Network::Address address, std::string data)
{ {
OutputDebugStringA(Utils::VA("Received inforequest from: %s", address.GetString()));
int clientCount = 0; int clientCount = 0;
int maxclientCount = *Game::svs_numclients; int maxclientCount = *Game::svs_numclients;
@ -294,6 +295,7 @@ namespace Components
Network::Handle("infoResponse", [] (Network::Address address, std::string data) Network::Handle("infoResponse", [] (Network::Address address, std::string data)
{ {
OutputDebugStringA(Utils::VA("Received inforesponse from: %s", address.GetString()));
Utils::InfoString info(data); Utils::InfoString info(data);
// Handle connection // Handle connection

View File

@ -36,7 +36,7 @@ namespace Components
Logger::Print("Received playlist request, sending currently stored buffer.\n"); Logger::Print("Received playlist request, sending currently stored buffer.\n");
// Split playlist data // Split playlist data
int maxPacketSize = 1000; unsigned int maxPacketSize = 1000;
unsigned int maxBytes = Playlist::CurrentPlaylistBuffer.size(); unsigned int maxBytes = Playlist::CurrentPlaylistBuffer.size();
for (unsigned int i = 0; i < maxBytes; i += maxPacketSize) for (unsigned int i = 0; i < maxBytes; i += maxPacketSize)

View File

@ -247,6 +247,7 @@ namespace Components
// Display in the menu, like in COD4 // Display in the menu, like in COD4
//Logger::Print("Sent %d/%d\n", ServerList::RefreshContainer.SentCount, ServerList::RefreshContainer.SendCount); //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; if (SendServers <= 0) break;
} }
@ -259,6 +260,8 @@ namespace Components
ServerList::OnlineList.clear(); ServerList::OnlineList.clear();
ServerList::VisibleList.clear(); ServerList::VisibleList.clear();
Localization::Set("MPUI_SERVERQUERIED", "Queried: 0/0");
Network::Handle("getServersResponse", [] (Network::Address address, std::string data) Network::Handle("getServersResponse", [] (Network::Address address, std::string data)
{ {
if (ServerList::RefreshContainer.Host != address) return; // Only parse from host we sent to if (ServerList::RefreshContainer.Host != address) return; // Only parse from host we sent to