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