Commit 2e021726 authored by fallenstardust's avatar fallenstardust

revert BeginRefreshHost()

parent 670359ae
...@@ -4164,36 +4164,58 @@ void DuelClient::BeginRefreshHost() { ...@@ -4164,36 +4164,58 @@ void DuelClient::BeginRefreshHost() {
remotes.clear(); remotes.clear();
hosts.clear(); hosts.clear();
event_base* broadev = event_base_new(); event_base* broadev = event_base_new();
char hname[256]; #ifdef _IRR_ANDROID_PLATFORM_
//get local ip address in android style
int ipaddr = android::getLocalAddr(mainGame->appMain);
if (ipaddr == -1) {
return;
}
#else
char hname[256];
gethostname(hname, 256); gethostname(hname, 256);
hostent* host = gethostbyname(hname); hostent* host = gethostbyname(hname);
if(!host) if(!host)
return; return;
SOCKET reply = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); #endif
sockaddr_in reply_addr; SOCKET reply = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
memset(&reply_addr, 0, sizeof(reply_addr)); sockaddr_in reply_addr;
reply_addr.sin_family = AF_INET; memset(&reply_addr, 0, sizeof(reply_addr));
reply_addr.sin_port = htons(7921); reply_addr.sin_family = AF_INET;
reply_addr.sin_addr.s_addr = 0; reply_addr.sin_port = htons(7921);
if(bind(reply, (sockaddr*)&reply_addr, sizeof(reply_addr)) == SOCKET_ERROR) { reply_addr.sin_addr.s_addr = 0;
closesocket(reply); if(bind(reply, (sockaddr*)&reply_addr, sizeof(reply_addr)) == SOCKET_ERROR) {
return; closesocket(reply);
} return;
timeval timeout = {3, 0}; }
resp_event = event_new(broadev, reply, EV_TIMEOUT | EV_READ | EV_PERSIST, BroadcastReply, broadev); timeval timeout = {3, 0};
event_add(resp_event, &timeout); resp_event = event_new(broadev, reply, EV_TIMEOUT | EV_READ | EV_PERSIST, BroadcastReply, broadev);
std::thread(RefreshThread, broadev).detach(); event_add(resp_event, &timeout);
//send request std::thread(RefreshThread, broadev).detach();
SOCKADDR_IN local; //send request
local.sin_family = AF_INET; SOCKADDR_IN local;
local.sin_port = htons(7922); local.sin_family = AF_INET;
SOCKADDR_IN sockTo; local.sin_port = htons(7922);
sockTo.sin_addr.s_addr = htonl(INADDR_BROADCAST); SOCKADDR_IN sockTo;
sockTo.sin_family = AF_INET; sockTo.sin_addr.s_addr = htonl(INADDR_BROADCAST);
sockTo.sin_port = htons(7920); sockTo.sin_family = AF_INET;
HostRequest hReq; sockTo.sin_port = htons(7920);
hReq.identifier = NETWORK_CLIENT_ID; HostRequest hReq;
for(int i = 0; i < 8; ++i) { hReq.identifier = NETWORK_CLIENT_ID;
#ifdef _IRR_ANDROID_PLATFORM_
local.sin_addr.s_addr = ipaddr;
SOCKET sSend = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if (sSend == INVALID_SOCKET)
return;
int opt = TRUE;
setsockopt(sSend, SOL_SOCKET, SO_BROADCAST, (const char*) &opt, sizeof opt);
if (bind(sSend, (sockaddr*) &local, sizeof(sockaddr)) == SOCKET_ERROR) {
closesocket(sSend);
return;
}
sendto(sSend, (const char*) &hReq, sizeof(HostRequest), 0, (sockaddr*) &sockTo, sizeof(sockaddr));
closesocket(sSend);
#else
for(int i = 0; i < 8; ++i) {
if(host->h_addr_list[i] == 0) if(host->h_addr_list[i] == 0)
break; break;
unsigned int local_addr = 0; unsigned int local_addr = 0;
...@@ -4211,6 +4233,7 @@ void DuelClient::BeginRefreshHost() { ...@@ -4211,6 +4233,7 @@ void DuelClient::BeginRefreshHost() {
sendto(sSend, (const char*)&hReq, sizeof(HostRequest), 0, (sockaddr*)&sockTo, sizeof(sockaddr)); sendto(sSend, (const char*)&hReq, sizeof(HostRequest), 0, (sockaddr*)&sockTo, sizeof(sockaddr));
closesocket(sSend); closesocket(sSend);
} }
#endif
} }
int DuelClient::RefreshThread(event_base* broadev) { int DuelClient::RefreshThread(event_base* broadev) {
event_base_dispatch(broadev); event_base_dispatch(broadev);
......
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