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
wind2009
ygopro
Commits
415e363c
Commit
415e363c
authored
Sep 20, 2013
by
wudizhanche1000
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加随机端口功能
parent
b08a99a5
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
5 deletions
+14
-5
gframe/netserver.cpp
gframe/netserver.cpp
+10
-4
gframe/netserver.h
gframe/netserver.h
+4
-1
No files found.
gframe/netserver.cpp
View file @
415e363c
#include "netserver.h"
#include "single_duel.h"
#include "tag_duel.h"
#include <stdio.h>
namespace
ygo
{
std
::
unordered_map
<
bufferevent
*
,
DuelPlayer
>
NetServer
::
users
;
unsigned
short
NetServer
::
server_port
=
0
;
...
...
@@ -57,19 +57,25 @@ void NetServer::Initduel(int bDuel_mode)
bool
NetServer
::
StartServer
(
unsigned
short
port
)
{
if
(
net_evbase
)
return
false
;
net_evbase
=
event_base_new
();
if
(
!
net_evbase
)
return
false
;
sockaddr_in
sin
;
int
fd
=
0
,
addr_len
=
sizeof
(
sockaddr_in
);
sockaddr_in
sin
,
addr_info
;
memset
(
&
sin
,
0
,
sizeof
(
sin
));
server_port
=
port
;
sin
.
sin_family
=
AF_INET
;
sin
.
sin_addr
.
s_addr
=
htonl
(
INADDR_ANY
);
sin
.
sin_port
=
htons
(
port
);
listener
=
evconnlistener_new_bind
(
net_evbase
,
ServerAccept
,
NULL
,
LEV_OPT_CLOSE_ON_FREE
|
LEV_OPT_REUSEABLE
,
-
1
,
(
sockaddr
*
)
&
sin
,
sizeof
(
sin
));
fd
=
socket
(
AF_INET
,
SOCK_STREAM
,
0
);
bind
(
fd
,
sin
,
sizeof
(
sockaddr_in
));
getsockname
(
fd
,
addr_info
,
&
addr_len
);
printf
(
"%d
\n
"
,
ntohs
(
addr_info
.
sin_port
));
listener
=
evconnlistener_new
(
net_evbase
,
ServerAccept
,
NULL
,
LEV_OPT_CLOSE_ON_FREE
|
LEV_OPT_REUSEABLE
,
-
1
,
fd
);
if
(
!
listener
)
{
event_base_free
(
net_evbase
);
net_evbase
=
0
;
...
...
gframe/netserver.h
View file @
415e363c
...
...
@@ -7,7 +7,10 @@
#include "deck_manager.h"
#include <set>
#include <unordered_map>
#include <sys/socket.h>
#include <netinet/ip.h>
#include <netinet/in.h>
#include <arpa/inet.h>
namespace
ygo
{
class
NetServer
{
...
...
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