Commit 2a1ce3f1 authored by nanahira's avatar nanahira

Merge branch 'patch-srv-withport' of ../versions/ygopro-fh

parents 8c2c071f e1ee08b2
...@@ -4425,35 +4425,52 @@ bool DuelClient::LookupSRV(char *hostname, HostResult* result) { ...@@ -4425,35 +4425,52 @@ bool DuelClient::LookupSRV(char *hostname, HostResult* result) {
return true; return true;
} }
bool DuelClient::CheckHostnameSplitter(char* hostname, HostResult* result) {
auto trySplitter = strchr(hostname, ':');
if(trySplitter == NULL)
return false;
char host[100];
auto hostLength = trySplitter - hostname;
strncpy(host, hostname, hostLength);
host[hostLength] = '\0';
result.host = LookupHost(host);
result.port = atoi(trySplitter + 1);
return true;
}
HostResult DuelClient::ParseHost(char *hostname, unsigned short port) { HostResult DuelClient::ParseHost(char *hostname, unsigned short port) {
HostResult result; HostResult result;
// if port found, use port directly
if(port) { if(port) {
result.host = LookupHost(hostname); // if hostname contains splitter, use port after splitter in priority
result.port = port; if(!CheckHostnameSplitter(hostname, &result)) {
result.host = LookupHost(hostname);
result.port = port;
}
return result; return result;
} }
// if hostname is an IP, use it directly and use default port
unsigned int tryAddress = htonl(inet_addr(hostname)); unsigned int tryAddress = htonl(inet_addr(hostname));
if(tryAddress != -1) { if(tryAddress != -1) {
result.host = tryAddress; result.host = tryAddress;
result.port = 7911; result.port = 7911;
return result; return result;
} }
auto trySplitter = strchr(hostname, ':');
if(trySplitter == NULL) { // if hostname contains splitter, use it first
char srvHostname[114]; if(CheckHostnameSplitter(hostname, &result))
sprintf(srvHostname, "_ygopro._tcp.%s", hostname); return result;
if(!LookupSRV(srvHostname, &result)) {
result.host = LookupHost(hostname); // lookup SRV record
result.port = 7911; char srvHostname[114];
} sprintf(srvHostname, "_ygopro._tcp.%s", hostname);
} else { if(LookupSRV(srvHostname, &result))
char host[100]; return result;
auto hostLength = trySplitter - hostname;
strncpy(host, hostname, hostLength); // finally, use default port
host[hostLength] = '\0'; result.host = LookupHost(hostname);
result.host = LookupHost(host); result.port = 7911;
result.port = atoi(trySplitter + 1);
}
return result; return result;
} }
} }
...@@ -96,7 +96,8 @@ public: ...@@ -96,7 +96,8 @@ public:
static void SetResponseB(void* respB, unsigned char len); static void SetResponseB(void* respB, unsigned char len);
static void SendResponse(); static void SendResponse();
static unsigned int LookupHost(char *host); static unsigned int LookupHost(char *host);
static bool LookupSRV(char *hostname, HostResult *result); static bool LookupSRV(char *hostname, HostResult* result);
static bool CheckHostnameSplitter(char* hostname, HostResult* result)
static HostResult ParseHost(char *hostname, unsigned short port); static HostResult ParseHost(char *hostname, unsigned short port);
static void SendPacketToServer(unsigned char proto) { static void SendPacketToServer(unsigned char proto) {
char* p = duel_client_write; char* p = duel_client_write;
......
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