Commit 6d7ff3fc authored by Edoardo Lolletti's avatar Edoardo Lolletti

Support multiple lam rooms from the same ip on different ports

parent ab330b7f
...@@ -34,7 +34,7 @@ mt19937 DuelClient::rnd; ...@@ -34,7 +34,7 @@ mt19937 DuelClient::rnd;
bool DuelClient::is_refreshing = false; bool DuelClient::is_refreshing = false;
int DuelClient::match_kill = 0; int DuelClient::match_kill = 0;
std::vector<HostPacket> DuelClient::hosts; std::vector<HostPacket> DuelClient::hosts;
std::set<unsigned int> DuelClient::remotes; std::set<std::pair<unsigned int, unsigned short>> DuelClient::remotes;
event* DuelClient::resp_event = 0; event* DuelClient::resp_event = 0;
bool DuelClient::StartClient(unsigned int ip, unsigned short port, bool create_game) { bool DuelClient::StartClient(unsigned int ip, unsigned short port, bool create_game) {
...@@ -4031,11 +4031,16 @@ void DuelClient::BroadcastReply(evutil_socket_t fd, short events, void * arg) { ...@@ -4031,11 +4031,16 @@ void DuelClient::BroadcastReply(evutil_socket_t fd, short events, void * arg) {
socklen_t sz = sizeof(sockaddr_in); socklen_t sz = sizeof(sockaddr_in);
char buf[256]; char buf[256];
/*int ret = */recvfrom(fd, buf, 256, 0, (sockaddr*)&bc_addr, &sz); /*int ret = */recvfrom(fd, buf, 256, 0, (sockaddr*)&bc_addr, &sz);
unsigned int ipaddr = bc_addr.sin_addr.s_addr; if(is_closing || pHP->identifier == NETWORK_SERVER_ID)
return;
HostPacket* pHP = (HostPacket*)buf; HostPacket* pHP = (HostPacket*)buf;
if(!is_closing && pHP->identifier == NETWORK_SERVER_ID && pHP->version == PRO_VERSION && remotes.find(ipaddr) == remotes.end() ) { if(pHP->version != PRO_VERSION)
return;
unsigned int ipaddr = bc_addr.sin_addr.s_addr;
const auto remote = std::make_pair(ipaddr, pHP->port);
if(remotes.find(remote) == remotes.end()) {
mainGame->gMutex.lock(); mainGame->gMutex.lock();
remotes.insert(ipaddr); remotes.insert(remote);
pHP->ipaddr = ipaddr; pHP->ipaddr = ipaddr;
hosts.push_back(*pHP); hosts.push_back(*pHP);
std::wstring hoststr; std::wstring hoststr;
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "config.h" #include "config.h"
#include <vector> #include <vector>
#include <set> #include <set>
#include <utility>
#include <event2/event.h> #include <event2/event.h>
#include <event2/listener.h> #include <event2/listener.h>
#include <event2/bufferevent.h> #include <event2/bufferevent.h>
...@@ -76,7 +77,7 @@ protected: ...@@ -76,7 +77,7 @@ protected:
static bool is_refreshing; static bool is_refreshing;
static int match_kill; static int match_kill;
static event* resp_event; static event* resp_event;
static std::set<unsigned int> remotes; static std::set<std::pair<unsigned int, unsigned short>> remotes;
public: public:
static std::vector<HostPacket> hosts; static std::vector<HostPacket> hosts;
static void BeginRefreshHost(); static void BeginRefreshHost();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment