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
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
MyCard
ygopro
Commits
8d586161
Commit
8d586161
authored
Jun 29, 2019
by
Edoardo Lolletti
Committed by
DailyShana
Jun 29, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clean up broadcasting code (#2218)
parent
dbb12f03
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
36 deletions
+9
-36
gframe/duelclient.cpp
gframe/duelclient.cpp
+6
-27
gframe/netserver.cpp
gframe/netserver.cpp
+3
-9
No files found.
gframe/duelclient.cpp
View file @
8d586161
...
...
@@ -3809,45 +3809,24 @@ void DuelClient::BeginRefreshHost() {
if
(
!
host
)
return
;
SOCKET
reply
=
socket
(
AF_INET
,
SOCK_DGRAM
,
IPPROTO_UDP
);
sockaddr_in
reply_addr
;
memset
(
&
reply_addr
,
0
,
sizeof
(
reply_addr
));
reply_addr
.
sin_family
=
AF_INET
;
reply_addr
.
sin_port
=
htons
(
7921
);
reply_addr
.
sin_addr
.
s_addr
=
0
;
if
(
bind
(
reply
,
(
sockaddr
*
)
&
reply_addr
,
sizeof
(
reply_addr
))
==
SOCKET_ERROR
)
{
closesocket
(
reply
);
return
;
}
BOOL
opt
=
TRUE
;
setsockopt
(
reply
,
SOL_SOCKET
,
SO_BROADCAST
,
(
const
char
*
)
&
opt
,
sizeof
(
BOOL
));
timeval
timeout
=
{
3
,
0
};
resp_event
=
event_new
(
broadev
,
reply
,
EV_TIMEOUT
|
EV_READ
|
EV_PERSIST
,
BroadcastReply
,
broadev
);
event_add
(
resp_event
,
&
timeout
);
Thread
::
NewThread
(
RefreshThread
,
broadev
);
//send request
SOCKADDR_IN
local
;
local
.
sin_family
=
AF_INET
;
local
.
sin_port
=
htons
(
7922
);
SOCKADDR_IN
sockTo
;
sockTo
.
sin_addr
.
s_addr
=
htonl
(
INADDR_BROADCAST
);
SOCKADDR_IN
sockTo
=
{};
sockTo
.
sin_family
=
AF_INET
;
sockTo
.
sin_port
=
htons
(
79
20
);
sockTo
.
sin_port
=
htons
(
79
11
);
HostRequest
hReq
;
hReq
.
identifier
=
NETWORK_CLIENT_ID
;
for
(
int
i
=
0
;
i
<
8
;
++
i
)
{
if
(
host
->
h_addr_list
[
i
]
==
0
)
break
;
unsigned
int
local_addr
=
*
(
unsigned
int
*
)
host
->
h_addr_list
[
i
];
local
.
sin_addr
.
s_addr
=
local_addr
;
SOCKET
sSend
=
socket
(
AF_INET
,
SOCK_DGRAM
,
IPPROTO_UDP
);
if
(
sSend
==
INVALID_SOCKET
)
break
;
BOOL
opt
=
TRUE
;
setsockopt
(
sSend
,
SOL_SOCKET
,
SO_BROADCAST
,
(
const
char
*
)
&
opt
,
sizeof
(
BOOL
));
if
(
bind
(
sSend
,
(
sockaddr
*
)
&
local
,
sizeof
(
sockaddr
))
==
SOCKET_ERROR
)
{
closesocket
(
sSend
);
break
;
}
sendto
(
sSend
,
(
const
char
*
)
&
hReq
,
sizeof
(
HostRequest
),
0
,
(
sockaddr
*
)
&
sockTo
,
sizeof
(
sockaddr
));
closesocket
(
sSend
);
sockTo
.
sin_addr
.
s_addr
=
local_addr
;
sendto
(
reply
,
(
const
char
*
)
&
hReq
,
sizeof
(
HostRequest
),
0
,
(
sockaddr
*
)
&
sockTo
,
sizeof
(
sockaddr
));
}
}
int
DuelClient
::
RefreshThread
(
void
*
arg
)
{
...
...
gframe/netserver.cpp
View file @
8d586161
...
...
@@ -40,13 +40,11 @@ bool NetServer::StartBroadcast() {
if
(
!
net_evbase
)
return
false
;
SOCKET
udp
=
socket
(
AF_INET
,
SOCK_DGRAM
,
IPPROTO_UDP
);
BOOL
opt
=
TRUE
;
setsockopt
(
udp
,
SOL_SOCKET
,
SO_BROADCAST
,
(
const
char
*
)
&
opt
,
sizeof
(
BOOL
));
sockaddr_in
addr
;
memset
(
&
addr
,
0
,
sizeof
(
addr
));
addr
.
sin_family
=
AF_INET
;
addr
.
sin_port
=
htons
(
79
20
);
addr
.
sin_addr
.
s_addr
=
0
;
addr
.
sin_port
=
htons
(
79
11
);
addr
.
sin_addr
.
s_addr
=
htonl
(
INADDR_ANY
)
;
if
(
bind
(
udp
,
(
sockaddr
*
)
&
addr
,
sizeof
(
addr
))
==
SOCKET_ERROR
)
{
closesocket
(
udp
);
return
false
;
...
...
@@ -85,17 +83,13 @@ void NetServer::BroadcastEvent(evutil_socket_t fd, short events, void* arg) {
return
;
HostRequest
*
pHR
=
(
HostRequest
*
)
buf
;
if
(
pHR
->
identifier
==
NETWORK_CLIENT_ID
)
{
SOCKADDR_IN
sockTo
;
sockTo
.
sin_addr
.
s_addr
=
bc_addr
.
sin_addr
.
s_addr
;
sockTo
.
sin_family
=
AF_INET
;
sockTo
.
sin_port
=
htons
(
7921
);
HostPacket
hp
;
hp
.
identifier
=
NETWORK_SERVER_ID
;
hp
.
port
=
server_port
;
hp
.
version
=
PRO_VERSION
;
hp
.
host
=
duel_mode
->
host_info
;
BufferIO
::
CopyWStr
(
duel_mode
->
name
,
hp
.
name
,
20
);
sendto
(
fd
,
(
const
char
*
)
&
hp
,
sizeof
(
HostPacket
),
0
,
(
sockaddr
*
)
&
sockTo
,
sizeof
(
sockTo
)
);
sendto
(
fd
,
(
const
char
*
)
&
hp
,
sizeof
(
HostPacket
),
0
,
(
sockaddr
*
)
&
bc_addr
,
sz
);
}
}
void
NetServer
::
ServerAccept
(
evconnlistener
*
listener
,
evutil_socket_t
fd
,
sockaddr
*
address
,
int
socklen
,
void
*
ctx
)
{
...
...
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