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
苍蓝
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() {
...
@@ -3809,45 +3809,24 @@ void DuelClient::BeginRefreshHost() {
if
(
!
host
)
if
(
!
host
)
return
;
return
;
SOCKET
reply
=
socket
(
AF_INET
,
SOCK_DGRAM
,
IPPROTO_UDP
);
SOCKET
reply
=
socket
(
AF_INET
,
SOCK_DGRAM
,
IPPROTO_UDP
);
sockaddr_in
reply_addr
;
BOOL
opt
=
TRUE
;
memset
(
&
reply_addr
,
0
,
sizeof
(
reply_addr
));
setsockopt
(
reply
,
SOL_SOCKET
,
SO_BROADCAST
,
(
const
char
*
)
&
opt
,
sizeof
(
BOOL
));
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
;
}
timeval
timeout
=
{
3
,
0
};
timeval
timeout
=
{
3
,
0
};
resp_event
=
event_new
(
broadev
,
reply
,
EV_TIMEOUT
|
EV_READ
|
EV_PERSIST
,
BroadcastReply
,
broadev
);
resp_event
=
event_new
(
broadev
,
reply
,
EV_TIMEOUT
|
EV_READ
|
EV_PERSIST
,
BroadcastReply
,
broadev
);
event_add
(
resp_event
,
&
timeout
);
event_add
(
resp_event
,
&
timeout
);
Thread
::
NewThread
(
RefreshThread
,
broadev
);
Thread
::
NewThread
(
RefreshThread
,
broadev
);
//send request
//send request
SOCKADDR_IN
local
;
SOCKADDR_IN
sockTo
=
{};
local
.
sin_family
=
AF_INET
;
local
.
sin_port
=
htons
(
7922
);
SOCKADDR_IN
sockTo
;
sockTo
.
sin_addr
.
s_addr
=
htonl
(
INADDR_BROADCAST
);
sockTo
.
sin_family
=
AF_INET
;
sockTo
.
sin_family
=
AF_INET
;
sockTo
.
sin_port
=
htons
(
79
20
);
sockTo
.
sin_port
=
htons
(
79
11
);
HostRequest
hReq
;
HostRequest
hReq
;
hReq
.
identifier
=
NETWORK_CLIENT_ID
;
hReq
.
identifier
=
NETWORK_CLIENT_ID
;
for
(
int
i
=
0
;
i
<
8
;
++
i
)
{
for
(
int
i
=
0
;
i
<
8
;
++
i
)
{
if
(
host
->
h_addr_list
[
i
]
==
0
)
if
(
host
->
h_addr_list
[
i
]
==
0
)
break
;
break
;
unsigned
int
local_addr
=
*
(
unsigned
int
*
)
host
->
h_addr_list
[
i
];
unsigned
int
local_addr
=
*
(
unsigned
int
*
)
host
->
h_addr_list
[
i
];
local
.
sin_addr
.
s_addr
=
local_addr
;
sockTo
.
sin_addr
.
s_addr
=
local_addr
;
SOCKET
sSend
=
socket
(
AF_INET
,
SOCK_DGRAM
,
IPPROTO_UDP
);
sendto
(
reply
,
(
const
char
*
)
&
hReq
,
sizeof
(
HostRequest
),
0
,
(
sockaddr
*
)
&
sockTo
,
sizeof
(
sockaddr
));
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
);
}
}
}
}
int
DuelClient
::
RefreshThread
(
void
*
arg
)
{
int
DuelClient
::
RefreshThread
(
void
*
arg
)
{
...
...
gframe/netserver.cpp
View file @
8d586161
...
@@ -40,13 +40,11 @@ bool NetServer::StartBroadcast() {
...
@@ -40,13 +40,11 @@ bool NetServer::StartBroadcast() {
if
(
!
net_evbase
)
if
(
!
net_evbase
)
return
false
;
return
false
;
SOCKET
udp
=
socket
(
AF_INET
,
SOCK_DGRAM
,
IPPROTO_UDP
);
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
;
sockaddr_in
addr
;
memset
(
&
addr
,
0
,
sizeof
(
addr
));
memset
(
&
addr
,
0
,
sizeof
(
addr
));
addr
.
sin_family
=
AF_INET
;
addr
.
sin_family
=
AF_INET
;
addr
.
sin_port
=
htons
(
79
20
);
addr
.
sin_port
=
htons
(
79
11
);
addr
.
sin_addr
.
s_addr
=
0
;
addr
.
sin_addr
.
s_addr
=
htonl
(
INADDR_ANY
)
;
if
(
bind
(
udp
,
(
sockaddr
*
)
&
addr
,
sizeof
(
addr
))
==
SOCKET_ERROR
)
{
if
(
bind
(
udp
,
(
sockaddr
*
)
&
addr
,
sizeof
(
addr
))
==
SOCKET_ERROR
)
{
closesocket
(
udp
);
closesocket
(
udp
);
return
false
;
return
false
;
...
@@ -85,17 +83,13 @@ void NetServer::BroadcastEvent(evutil_socket_t fd, short events, void* arg) {
...
@@ -85,17 +83,13 @@ void NetServer::BroadcastEvent(evutil_socket_t fd, short events, void* arg) {
return
;
return
;
HostRequest
*
pHR
=
(
HostRequest
*
)
buf
;
HostRequest
*
pHR
=
(
HostRequest
*
)
buf
;
if
(
pHR
->
identifier
==
NETWORK_CLIENT_ID
)
{
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
;
HostPacket
hp
;
hp
.
identifier
=
NETWORK_SERVER_ID
;
hp
.
identifier
=
NETWORK_SERVER_ID
;
hp
.
port
=
server_port
;
hp
.
port
=
server_port
;
hp
.
version
=
PRO_VERSION
;
hp
.
version
=
PRO_VERSION
;
hp
.
host
=
duel_mode
->
host_info
;
hp
.
host
=
duel_mode
->
host_info
;
BufferIO
::
CopyWStr
(
duel_mode
->
name
,
hp
.
name
,
20
);
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
)
{
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