Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
R
rd-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
苍蓝
rd-ygopro
Commits
171b8014
Commit
171b8014
authored
Sep 20, 2022
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
support random response
parent
cb53f9e2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
15 deletions
+38
-15
gframe/duelclient.cpp
gframe/duelclient.cpp
+14
-15
gframe/duelclient.h
gframe/duelclient.h
+24
-0
No files found.
gframe/duelclient.cpp
View file @
171b8014
...
@@ -10,8 +10,6 @@
...
@@ -10,8 +10,6 @@
#include "replay_mode.h"
#include "replay_mode.h"
#ifdef _WIN32
#ifdef _WIN32
#include <Windns.h>
#include <Windns.h>
#else
#include <resolv.h>
#endif
#endif
namespace
ygo
{
namespace
ygo
{
...
@@ -4392,24 +4390,25 @@ bool DuelClient::LookupSRV(char *hostname, HostResult* result) {
...
@@ -4392,24 +4390,25 @@ bool DuelClient::LookupSRV(char *hostname, HostResult* result) {
if
(
status
<
0
)
if
(
status
<
0
)
return
false
;
return
false
;
ns_msg
nsMsg
;
ns_msg
nsMsg
;
ns_rr
rr
;
ns_initparse
(
answer
,
status
,
&
nsMsg
);
ns_initparse
(
answer
,
status
,
&
nsMsg
);
bool
found
=
false
;
bool
found
=
false
;
for
(
int
i
=
0
;
i
<
ns_msg_count
(
nsMsg
,
ns_s_an
);
i
++
)
{
std
::
vector
<
RetrivedSRVRecord
>
records
;
if
(
ns_parserr
(
&
nsMsg
,
ns_s_an
,
i
,
&
rr
)
<
0
||
ns_rr_type
(
rr
)
!=
T_SRV
)
for
(
int
i
=
0
;
i
<
ns_msg_count
(
nsMsg
,
ns_s_an
);
i
++
)
{
continue
;
auto
record
=
RetrivedSRVRecord
(
nsMsg
,
i
);
if
(
!
record
.
valid
)
// priority = ns_get16(ns_rr_rdata(rr));
// weight = ns_get16(ns_rr_rdata(rr) + NS_INT16SZ);
result
->
port
=
ns_get16
(
ns_rr_rdata
(
rr
)
+
2
*
NS_INT16SZ
);
// decompress domain name
if
(
dn_expand
(
ns_msg_base
(
nsMsg
),
ns_msg_end
(
nsMsg
),
ns_rr_rdata
(
rr
)
+
3
*
NS_INT16SZ
,
resolved
,
sizeof
(
resolved
))
<
0
)
continue
;
continue
;
found
=
true
;
for
(
int
j
=
0
;
j
<
record
.
weight
;
++
j
)
{
records
.
push_back
(
record
);
}
}
}
if
(
!
found
)
if
(
!
records
.
size
()
)
return
false
;
return
false
;
rnd
.
reset
((
unsigned
int
)
time
(
nullptr
));
rnd
.
shuffle_vector
(
records
);
auto
record
=
records
.
front
();
printf
(
"Result: %s:%d
\n
"
,
record
.
host
,
record
.
port
);
memcpy
(
resolved
,
record
.
host
,
100
);
result
->
port
=
record
.
port
;
#endif
#endif
result
->
host
=
LookupHost
(
resolved
);
result
->
host
=
LookupHost
(
resolved
);
return
true
;
return
true
;
...
...
gframe/duelclient.h
View file @
171b8014
...
@@ -30,6 +30,30 @@ public:
...
@@ -30,6 +30,30 @@ public:
}
}
};
};
#ifndef _WIN32
#include <resolv.h>
class
RetrivedSRVRecord
{
public:
bool
valid
;
unsigned
short
priority
;
unsigned
short
weight
;
unsigned
short
port
;
char
host
[
100
];
RetrivedSRVRecord
(
ns_msg
nsMsg
,
int
i
)
{
valid
=
false
;
ns_rr
rr
;
if
(
ns_parserr
(
&
nsMsg
,
ns_s_an
,
i
,
&
rr
)
<
0
||
ns_rr_type
(
rr
)
!=
T_SRV
)
return
;
priority
=
ns_get16
(
ns_rr_rdata
(
rr
));
weight
=
ns_get16
(
ns_rr_rdata
(
rr
)
+
NS_INT16SZ
);
port
=
ns_get16
(
ns_rr_rdata
(
rr
)
+
2
*
NS_INT16SZ
);
if
(
dn_expand
(
ns_msg_base
(
nsMsg
),
ns_msg_end
(
nsMsg
),
ns_rr_rdata
(
rr
)
+
3
*
NS_INT16SZ
,
host
,
sizeof
(
host
))
<
0
)
return
;
valid
=
true
;
}
};
#endif
class
DuelClient
{
class
DuelClient
{
private:
private:
static
unsigned
int
connect_state
;
static
unsigned
int
connect_state
;
...
...
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