Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Y
ygopro
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
REIKAI
ygopro
Commits
e1ee08b2
Commit
e1ee08b2
authored
Sep 24, 2022
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update ParseHost
parent
87a502d0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
19 deletions
+37
-19
gframe/duelclient.cpp
gframe/duelclient.cpp
+35
-18
gframe/duelclient.h
gframe/duelclient.h
+2
-1
No files found.
gframe/duelclient.cpp
View file @
e1ee08b2
...
@@ -4147,35 +4147,52 @@ bool DuelClient::LookupSRV(char *hostname, HostResult* result) {
...
@@ -4147,35 +4147,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;
}
}
}
}
gframe/duelclient.h
View file @
e1ee08b2
...
@@ -91,7 +91,8 @@ public:
...
@@ -91,7 +91,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
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment