Commit 75b4f7c5 authored by nanahira's avatar nanahira

Merge branch 'patch' of github.com:edo9300/ygopro

parents 5dcb50e4 76d61cf1
Pipeline #16648 failed with stages
in 9 minutes and 49 seconds
......@@ -35,7 +35,7 @@ bool DuelClient::is_refreshing = false;
int DuelClient::match_kill = 0;
std::vector<HostPacket> DuelClient::hosts;
std::vector<std::wstring> DuelClient::hosts_srvpro;
std::set<unsigned int> DuelClient::remotes;
std::set<std::pair<unsigned int, unsigned short>> DuelClient::remotes;
event* DuelClient::resp_event = 0;
unsigned int DuelClient::temp_ip = 0;
unsigned short DuelClient::temp_port = 0;
......@@ -4309,11 +4309,16 @@ void DuelClient::BroadcastReply(evutil_socket_t fd, short events, void * arg) {
socklen_t sz = sizeof(sockaddr_in);
char buf[256];
/*int ret = */recvfrom(fd, buf, 256, 0, (sockaddr*)&bc_addr, &sz);
unsigned int ipaddr = bc_addr.sin_addr.s_addr;
HostPacket* pHP = (HostPacket*)buf;
if(!is_closing && pHP->identifier == NETWORK_SERVER_ID && remotes.find(ipaddr) == remotes.end() ) {
if(is_closing || pHP->identifier != NETWORK_SERVER_ID)
return;
//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();
remotes.insert(ipaddr);
remotes.insert(remote);
pHP->ipaddr = ipaddr;
hosts.push_back(*pHP);
std::wstring hoststr;
......
......@@ -4,6 +4,7 @@
#include "config.h"
#include <vector>
#include <set>
#include <utility>
#include <event2/event.h>
#include <event2/listener.h>
#include <event2/bufferevent.h>
......@@ -90,7 +91,7 @@ protected:
static bool is_refreshing;
static int match_kill;
static event* resp_event;
static std::set<unsigned int> remotes;
static std::set<std::pair<unsigned int, unsigned short>> remotes;
public:
static std::vector<HostPacket> hosts;
static std::vector<std::wstring> hosts_srvpro;
......
......@@ -42,6 +42,7 @@ bool NetServer::StartBroadcast() {
SOCKET udp = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
BOOL opt = TRUE;
setsockopt(udp, SOL_SOCKET, SO_BROADCAST, (const char*)&opt, sizeof(BOOL));
setsockopt(udp, SOL_SOCKET, SO_REUSEADDR, (const char*)&opt, sizeof(BOOL));
sockaddr_in addr;
memset(&addr, 0, sizeof(addr));
addr.sin_family = AF_INET;
......
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