Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Y
ygopro-2pick
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-2pick
Commits
fa14238e
Commit
fa14238e
authored
Jan 30, 2012
by
argon.sun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
host finding done.
parent
2007e1b6
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
72 additions
and
21 deletions
+72
-21
gframe/duelclient.cpp
gframe/duelclient.cpp
+27
-5
gframe/duelclient.h
gframe/duelclient.h
+3
-1
gframe/menu_handler.cpp
gframe/menu_handler.cpp
+14
-0
gframe/netserver.cpp
gframe/netserver.cpp
+9
-2
gframe/network.h
gframe/network.h
+2
-0
gframe/single_duel.cpp
gframe/single_duel.cpp
+14
-12
strings.conf
strings.conf
+2
-0
system.conf
system.conf
+1
-1
No files found.
gframe/duelclient.cpp
View file @
fa14238e
...
...
@@ -24,7 +24,8 @@ wchar_t DuelClient::event_string[256];
mtrandom
DuelClient
::
rnd
;
bool
DuelClient
::
is_refreshing
=
false
;
std
::
vector
<
HostInfo
>
DuelClient
::
hosts
;
std
::
vector
<
HostPacket
>
DuelClient
::
hosts
;
std
::
set
<
int
>
DuelClient
::
remotes
;
event
*
DuelClient
::
resp_event
=
0
;
bool
DuelClient
::
StartClient
(
unsigned
int
ip
,
unsigned
short
port
,
bool
create_game
)
{
...
...
@@ -2283,8 +2284,8 @@ void DuelClient::BeginRefreshHost() {
if
(
is_refreshing
)
return
;
is_refreshing
=
true
;
mainGame
->
gMutex
.
Lock
();
mainGame
->
lstHostList
->
clear
();
remotes
.
clear
();
hosts
.
clear
();
event_base
*
broadev
=
event_base_new
();
char
hname
[
256
];
...
...
@@ -2292,7 +2293,7 @@ void DuelClient::BeginRefreshHost() {
hostent
*
host
=
gethostbyname
(
hname
);
if
(
!
host
)
return
;
SOCKET
reply
=
socket
(
AF_INET
,
SOCK_DGRAM
,
0
);
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
;
...
...
@@ -2305,6 +2306,7 @@ void DuelClient::BeginRefreshHost() {
timeval
timeout
=
{
5
,
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
;
...
...
@@ -2332,7 +2334,6 @@ void DuelClient::BeginRefreshHost() {
sendto
(
sSend
,
(
const
char
*
)
&
hReq
,
sizeof
(
HostRequest
),
0
,
(
sockaddr
*
)
&
sockTo
,
sizeof
(
sockaddr
));
closesocket
(
sSend
);
}
Thread
::
NewThread
(
RefreshThread
,
broadev
);
}
int
DuelClient
::
RefreshThread
(
void
*
arg
)
{
event_base
*
broadev
=
(
event_base
*
)
arg
;
...
...
@@ -2352,9 +2353,30 @@ void DuelClient::BroadcastReply(evutil_socket_t fd, short events, void* arg) {
int
sz
=
sizeof
(
sockaddr_in
);
char
buf
[
256
];
int
ret
=
recvfrom
(
fd
,
buf
,
256
,
0
,
(
sockaddr
*
)
&
bc_addr
,
&
sz
);
int
ipaddr
=
bc_addr
.
sin_addr
.
s_addr
;
HostPacket
*
pHP
=
(
HostPacket
*
)
buf
;
if
(
pHP
->
identifier
==
NETWORK_SERVER_ID
&&
pHP
->
version
==
PRO_VERSION
)
{
if
(
pHP
->
identifier
==
NETWORK_SERVER_ID
&&
pHP
->
version
==
PRO_VERSION
&&
remotes
.
find
(
ipaddr
)
==
remotes
.
end
()
)
{
mainGame
->
gMutex
.
Lock
();
remotes
.
insert
(
ipaddr
);
pHP
->
ipaddr
=
ipaddr
;
hosts
.
push_back
(
*
pHP
);
std
::
wstring
hoststr
;
hoststr
.
append
(
L"["
);
hoststr
.
append
(
deckManager
.
GetLFListName
(
pHP
->
host
.
lflist
));
hoststr
.
append
(
L"]["
);
hoststr
.
append
(
dataManager
.
GetSysString
(
pHP
->
host
.
rule
+
1240
));
hoststr
.
append
(
L"]["
);
hoststr
.
append
(
dataManager
.
GetSysString
(
pHP
->
host
.
mode
+
1244
));
hoststr
.
append
(
L"]["
);
if
(
pHP
->
host
.
draw_count
==
1
&&
pHP
->
host
.
start_hand
==
5
&&
pHP
->
host
.
start_lp
==
8000
&&
!
pHP
->
host
.
no_check_deck
&&
!
pHP
->
host
.
no_shuffle_deck
&&
!
pHP
->
host
.
enable_priority
)
hoststr
.
append
(
dataManager
.
GetSysString
(
1280
));
else
hoststr
.
append
(
dataManager
.
GetSysString
(
1281
));
hoststr
.
append
(
L"]"
);
wchar_t
gamename
[
20
];
BufferIO
::
CopyWStr
(
pHP
->
name
,
gamename
,
20
);
hoststr
.
append
(
gamename
);
mainGame
->
lstHostList
->
addItem
(
hoststr
.
c_str
());
mainGame
->
gMutex
.
Unlock
();
}
}
...
...
gframe/duelclient.h
View file @
fa14238e
...
...
@@ -3,6 +3,7 @@
#include "config.h"
#include <vector>
#include <set>
#include <event2/event.h>
#include <event2/listener.h>
#include <event2/bufferevent.h>
...
...
@@ -67,8 +68,9 @@ public:
protected:
static
bool
is_refreshing
;
static
event
*
resp_event
;
static
std
::
set
<
int
>
remotes
;
public:
static
std
::
vector
<
Host
Info
>
hosts
;
static
std
::
vector
<
Host
Packet
>
hosts
;
static
void
BeginRefreshHost
();
static
int
RefreshThread
(
void
*
arg
);
static
void
BroadcastReply
(
evutil_socket_t
fd
,
short
events
,
void
*
arg
);
...
...
gframe/menu_handler.cpp
View file @
fa14238e
...
...
@@ -52,6 +52,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
break
;
}
case
BUTTON_LAN_REFRESH
:
{
DuelClient
::
BeginRefreshHost
();
break
;
}
case
BUTTON_CREATE_HOST
:
{
...
...
@@ -187,6 +188,19 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
}
case
irr
:
:
gui
::
EGET_LISTBOX_CHANGED
:
{
switch
(
id
)
{
case
LISTBOX_LAN_HOST
:
{
int
sel
=
mainGame
->
lstHostList
->
getSelected
();
if
(
sel
==
-
1
)
break
;
int
addr
=
DuelClient
::
hosts
[
sel
].
ipaddr
;
int
port
=
DuelClient
::
hosts
[
sel
].
port
;
wchar_t
buf
[
20
];
myswprintf
(
buf
,
L"%d.%d.%d.%d"
,
addr
&
0xff
,
(
addr
>>
8
)
&
0xff
,
(
addr
>>
16
)
&
0xff
,
(
addr
>>
24
)
&
0xff
);
mainGame
->
ebJoinIP
->
setText
(
buf
);
myswprintf
(
buf
,
L"%d"
,
port
);
mainGame
->
ebJoinPort
->
setText
(
buf
);
break
;
}
case
LISTBOX_REPLAY_LIST
:
{
break
;
}
...
...
gframe/netserver.cpp
View file @
fa14238e
...
...
@@ -38,7 +38,7 @@ bool NetServer::StartServer(unsigned short port) {
bool
NetServer
::
StartBroadcast
()
{
if
(
!
net_evbase
)
return
false
;
SOCKET
udp
=
socket
(
AF_INET
,
SOCK_DGRAM
,
0
);
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
;
...
...
@@ -77,14 +77,21 @@ void NetServer::BroadcastEvent(evutil_socket_t fd, short events, void* arg) {
int
sz
=
sizeof
(
sockaddr_in
);
char
buf
[
256
];
int
ret
=
recvfrom
(
fd
,
buf
,
256
,
0
,
(
sockaddr
*
)
&
bc_addr
,
&
sz
);
if
(
ret
==
-
1
)
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
;
sendto
(
fd
,
(
const
char
*
)
&
hp
,
sizeof
(
HostPacket
),
0
,
(
sockaddr
*
)
&
bc_addr
,
sizeof
(
bc_addr
));
BufferIO
::
CopyWStr
(
duel_mode
->
name
,
hp
.
name
,
20
);
sendto
(
fd
,
(
const
char
*
)
&
hp
,
sizeof
(
HostPacket
),
0
,
(
sockaddr
*
)
&
sockTo
,
sizeof
(
sockTo
));
}
}
void
NetServer
::
ServerAccept
(
evconnlistener
*
listener
,
evutil_socket_t
fd
,
sockaddr
*
address
,
int
socklen
,
void
*
ctx
)
{
...
...
gframe/network.h
View file @
fa14238e
...
...
@@ -26,6 +26,8 @@ struct HostPacket {
unsigned
short
identifier
;
unsigned
short
version
;
unsigned
short
port
;
unsigned
int
ipaddr
;
unsigned
short
name
[
20
];
HostInfo
host
;
};
struct
HostRequest
{
...
...
gframe/single_duel.cpp
View file @
fa14238e
...
...
@@ -195,7 +195,7 @@ void SingleDuel::PlayerReady(DuelPlayer* dp, bool is_ready) {
if
(
is_ready
)
{
bool
allow_ocg
=
host_info
.
rule
==
0
||
host_info
.
rule
==
2
;
bool
allow_tcg
=
host_info
.
rule
==
1
||
host_info
.
rule
==
2
;
int
res
=
deckManager
.
CheckLFList
(
pdeck
[
dp
->
type
],
host_info
.
lflist
,
allow_ocg
,
allow_tcg
);
int
res
=
host_info
.
no_check_deck
?
true
:
deckManager
.
CheckLFList
(
pdeck
[
dp
->
type
],
host_info
.
lflist
,
allow_ocg
,
allow_tcg
);
if
(
res
)
{
STOC_HS_PlayerChange
scpc
;
scpc
.
status
=
(
dp
->
type
<<
4
)
|
PLAYERCHANGE_NOTREADY
;
...
...
@@ -311,17 +311,19 @@ void SingleDuel::TPResult(DuelPlayer* dp, unsigned char tp) {
rnd
.
reset
(
seed
);
last_replay
.
WriteData
(
players
[
0
],
40
,
false
);
last_replay
.
WriteData
(
players
[
1
],
40
,
false
);
for
(
int
i
=
0
;
i
<
pdeck
[
0
].
main
.
size
();
++
i
)
{
int
swap
=
rnd
.
real
()
*
pdeck
[
0
].
main
.
size
();
auto
tmp
=
pdeck
[
0
].
main
[
i
];
pdeck
[
0
].
main
[
i
]
=
pdeck
[
0
].
main
[
swap
];
pdeck
[
0
].
main
[
swap
]
=
tmp
;
}
for
(
int
i
=
0
;
i
<
pdeck
[
1
].
main
.
size
();
++
i
)
{
int
swap
=
rnd
.
real
()
*
pdeck
[
1
].
main
.
size
();
auto
tmp
=
pdeck
[
1
].
main
[
i
];
pdeck
[
1
].
main
[
i
]
=
pdeck
[
1
].
main
[
swap
];
pdeck
[
1
].
main
[
swap
]
=
tmp
;
if
(
!
host_info
.
no_shuffle_deck
)
{
for
(
int
i
=
0
;
i
<
pdeck
[
0
].
main
.
size
();
++
i
)
{
int
swap
=
rnd
.
real
()
*
pdeck
[
0
].
main
.
size
();
auto
tmp
=
pdeck
[
0
].
main
[
i
];
pdeck
[
0
].
main
[
i
]
=
pdeck
[
0
].
main
[
swap
];
pdeck
[
0
].
main
[
swap
]
=
tmp
;
}
for
(
int
i
=
0
;
i
<
pdeck
[
1
].
main
.
size
();
++
i
)
{
int
swap
=
rnd
.
real
()
*
pdeck
[
1
].
main
.
size
();
auto
tmp
=
pdeck
[
1
].
main
[
i
];
pdeck
[
1
].
main
[
i
]
=
pdeck
[
1
].
main
[
swap
];
pdeck
[
1
].
main
[
swap
]
=
tmp
;
}
}
set_card_reader
((
card_reader
)
DataManager
::
CardReader
);
set_message_handler
((
message_handler
)
SingleDuel
::
MessageHandler
);
...
...
strings.conf
View file @
fa14238e
...
...
@@ -251,6 +251,8 @@
!
system
1275
↑随机选择位置
!
system
1276
自动排列连锁顺序
!
system
1277
没有可连锁的卡时延迟回应
!
system
1280
标准对战
!
system
1281
自定义
!
system
1300
禁限卡表:
!
system
1301
卡组列表:
!
system
1302
保存
...
...
system.conf
View file @
fa14238e
...
...
@@ -7,5 +7,5 @@ lastdeck = tgagent
textfont
=
c
:/
windows
/
fonts
/
simsun
.
ttc
numfont
=
c
:/
windows
/
fonts
/
arialbd
.
ttf
serverport
=
7911
lastip
=
1
27
.
0
.
0
.
1
lastip
=
1
92
.
168
.
2
.
100
lastport
=
7911
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