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
4c70d159
Commit
4c70d159
authored
May 31, 2024
by
nanahira
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'patch-pointer' of github.com:salix5/ygopro into develop
parents
76328024
9e8dbeeb
Pipeline
#27391
canceled with stages
in 3 minutes and 35 seconds
Changes
4
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
103 additions
and
30 deletions
+103
-30
gframe/duelclient.cpp
gframe/duelclient.cpp
+2
-2
gframe/network.h
gframe/network.h
+93
-20
gframe/single_duel.cpp
gframe/single_duel.cpp
+4
-4
gframe/tag_duel.cpp
gframe/tag_duel.cpp
+4
-4
No files found.
gframe/duelclient.cpp
View file @
4c70d159
...
...
@@ -818,11 +818,11 @@ void DuelClient::HandleSTOCPacketLan(unsigned char* data, int len) {
break
;
}
case
STOC_HS_PLAYER_ENTER
:
{
if
(
len
<
1
+
(
int
)
sizeof
(
STOC_HS_PlayerEnter
)
)
if
(
len
<
1
+
STOC_HS_PlayerEnter_size
)
return
;
soundManager
.
PlaySoundEffect
(
SOUND_PLAYER_ENTER
);
STOC_HS_PlayerEnter
packet
;
std
::
memcpy
(
&
packet
,
pdata
,
sizeof
packet
);
std
::
memcpy
(
&
packet
,
pdata
,
STOC_HS_PlayerEnter_size
);
const
auto
*
pkt
=
&
packet
;
if
(
pkt
->
pos
>
3
)
break
;
...
...
gframe/network.h
View file @
4c70d159
...
...
@@ -8,82 +8,144 @@
#include <event2/bufferevent.h>
#include <event2/buffer.h>
#include <event2/thread.h>
#include <type_traits>
#define check_trivially_copyable(T) static_assert(std::is_trivially_copyable<T>::value == true, "not trivially copyable")
namespace
ygo
{
constexpr
int
SIZE_NETWORK_BUFFER
=
0x2000
;
constexpr
int
MAX_DATA_SIZE
=
SIZE_NETWORK_BUFFER
-
3
;
constexpr
int
MAINC_MAX
=
250
;
// the limit of card_state
constexpr
int
SIDEC_MAX
=
MAINC_MAX
;
struct
HostInfo
{
u
nsigned
in
t
lflist
{};
u
int32_
t
lflist
{};
unsigned
char
rule
{};
unsigned
char
mode
{};
unsigned
char
duel_rule
{};
unsigned
char
no_check_deck
{};
unsigned
char
no_shuffle_deck
{};
unsigned
int
start_lp
{};
// byte padding[3]
uint32_t
start_lp
{};
unsigned
char
start_hand
{};
unsigned
char
draw_count
{};
u
nsigned
shor
t
time_limit
{};
u
int16_
t
time_limit
{};
};
check_trivially_copyable
(
HostInfo
);
static_assert
(
sizeof
(
HostInfo
)
==
20
,
"size mismatch: HostInfo"
);
struct
HostPacket
{
unsigned
short
identifier
;
unsigned
short
version
;
unsigned
short
port
;
unsigned
int
ipaddr
;
unsigned
short
name
[
20
];
uint16_t
identifier
;
uint16_t
version
;
uint16_t
port
;
// byte padding[2]
uint32_t
ipaddr
;
uint16_t
name
[
20
];
HostInfo
host
;
};
check_trivially_copyable
(
HostPacket
);
static_assert
(
sizeof
(
HostPacket
)
==
72
,
"size mismatch: HostPacket"
);
struct
HostRequest
{
u
nsigned
shor
t
identifier
;
u
int16_
t
identifier
;
};
check_trivially_copyable
(
HostRequest
);
static_assert
(
sizeof
(
HostRequest
)
==
2
,
"size mismatch: HostRequest"
);
struct
CTOS_HandResult
{
unsigned
char
res
;
};
check_trivially_copyable
(
CTOS_HandResult
);
static_assert
(
sizeof
(
CTOS_HandResult
)
==
1
,
"size mismatch: CTOS_HandResult"
);
struct
CTOS_TPResult
{
unsigned
char
res
;
};
check_trivially_copyable
(
CTOS_TPResult
);
static_assert
(
sizeof
(
CTOS_TPResult
)
==
1
,
"size mismatch: CTOS_TPResult"
);
struct
CTOS_PlayerInfo
{
u
nsigned
shor
t
name
[
20
];
u
int16_
t
name
[
20
];
};
check_trivially_copyable
(
CTOS_PlayerInfo
);
static_assert
(
sizeof
(
CTOS_PlayerInfo
)
==
40
,
"size mismatch: CTOS_PlayerInfo"
);
struct
CTOS_CreateGame
{
HostInfo
info
;
u
nsigned
shor
t
name
[
20
];
u
nsigned
shor
t
pass
[
20
];
u
int16_
t
name
[
20
];
u
int16_
t
pass
[
20
];
};
check_trivially_copyable
(
CTOS_CreateGame
);
static_assert
(
sizeof
(
CTOS_CreateGame
)
==
100
,
"size mismatch: CTOS_CreateGame"
);
struct
CTOS_JoinGame
{
unsigned
short
version
;
unsigned
int
gameid
;
unsigned
short
pass
[
20
];
uint16_t
version
;
// byte padding[2]
uint32_t
gameid
;
uint16_t
pass
[
20
];
};
check_trivially_copyable
(
CTOS_JoinGame
);
static_assert
(
sizeof
(
CTOS_JoinGame
)
==
48
,
"size mismatch: CTOS_JoinGame"
);
struct
CTOS_Kick
{
unsigned
char
pos
;
};
check_trivially_copyable
(
CTOS_Kick
);
static_assert
(
sizeof
(
CTOS_Kick
)
==
1
,
"size mismatch: CTOS_Kick"
);
// STOC
struct
STOC_ErrorMsg
{
unsigned
char
msg
;
unsigned
int
code
;
// byte padding[3]
uint32_t
code
;
};
check_trivially_copyable
(
STOC_ErrorMsg
);
static_assert
(
sizeof
(
STOC_ErrorMsg
)
==
8
,
"size mismatch: STOC_ErrorMsg"
);
struct
STOC_HandResult
{
unsigned
char
res1
;
unsigned
char
res2
;
};
check_trivially_copyable
(
STOC_HandResult
);
static_assert
(
sizeof
(
STOC_HandResult
)
==
2
,
"size mismatch: STOC_HandResult"
);
struct
STOC_CreateGame
{
u
nsigned
in
t
gameid
;
u
int32_
t
gameid
;
};
check_trivially_copyable
(
STOC_CreateGame
);
static_assert
(
sizeof
(
STOC_CreateGame
)
==
4
,
"size mismatch: STOC_CreateGame"
);
struct
STOC_JoinGame
{
HostInfo
info
;
};
check_trivially_copyable
(
STOC_JoinGame
);
static_assert
(
sizeof
(
STOC_JoinGame
)
==
20
,
"size mismatch: STOC_JoinGame"
);
struct
STOC_TypeChange
{
unsigned
char
type
;
};
check_trivially_copyable
(
STOC_TypeChange
);
static_assert
(
sizeof
(
STOC_TypeChange
)
==
1
,
"size mismatch: STOC_TypeChange"
);
struct
STOC_ExitGame
{
unsigned
char
pos
;
};
check_trivially_copyable
(
STOC_ExitGame
);
static_assert
(
sizeof
(
STOC_ExitGame
)
==
1
,
"size mismatch: STOC_ExitGame"
);
struct
STOC_TimeLimit
{
unsigned
char
player
;
unsigned
short
left_time
;
// byte padding[1]
uint16_t
left_time
;
};
check_trivially_copyable
(
STOC_TimeLimit
);
static_assert
(
sizeof
(
STOC_TimeLimit
)
==
4
,
"size mismatch: STOC_TimeLimit"
);
/*
* STOC_Chat
* uint16_t player_type;
...
...
@@ -92,17 +154,28 @@ struct STOC_TimeLimit {
constexpr
int
LEN_CHAT_PLAYER
=
1
;
constexpr
int
LEN_CHAT_MSG
=
256
;
constexpr
int
SIZE_STOC_CHAT
=
(
LEN_CHAT_PLAYER
+
LEN_CHAT_MSG
)
*
sizeof
(
uint16_t
);
struct
STOC_HS_PlayerEnter
{
u
nsigned
shor
t
name
[
20
];
u
int16_
t
name
[
20
];
unsigned
char
pos
;
// byte padding[1]
};
check_trivially_copyable
(
STOC_HS_PlayerEnter
);
//static_assert(sizeof(STOC_HS_PlayerEnter) == 42, "size mismatch: STOC_HS_PlayerEnter");
constexpr
int
STOC_HS_PlayerEnter_size
=
41
;
//workwround
struct
STOC_HS_PlayerChange
{
//pos<<4 | state
unsigned
char
status
;
};
check_trivially_copyable
(
STOC_HS_PlayerChange
);
static_assert
(
sizeof
(
STOC_HS_PlayerChange
)
==
1
,
"size mismatch: STOC_HS_PlayerChange"
);
struct
STOC_HS_WatchChange
{
u
nsigned
shor
t
watch_count
;
u
int16_
t
watch_count
;
};
check_trivially_copyable
(
STOC_HS_WatchChange
);
static_assert
(
sizeof
(
STOC_HS_WatchChange
)
==
2
,
"size mismatch: STOC_HS_WatchChange"
);
class
DuelMode
;
...
...
gframe/single_duel.cpp
View file @
4c70d159
...
...
@@ -277,16 +277,16 @@ void SingleDuel::PlayerKick(DuelPlayer* dp, unsigned char pos) {
void
SingleDuel
::
UpdateDeck
(
DuelPlayer
*
dp
,
unsigned
char
*
pdata
,
int
len
)
{
if
(
dp
->
type
>
1
||
ready
[
dp
->
type
])
return
;
if
(
len
<
=
8
||
len
%
sizeof
(
int32_t
)
!=
0
)
if
(
len
<
8
)
return
;
bool
valid
=
true
;
auto
deckbuf
=
pdata
;
int
mainc
=
BufferIO
::
ReadInt32
(
deckbuf
);
int
sidec
=
BufferIO
::
ReadInt32
(
deckbuf
);
const
int
deck_size
=
len
-
2
*
sizeof
(
int32_t
);
if
(
mainc
<
DECK_MIN_SIZE
||
mainc
>
DECK_MAX_SIZE
+
EXTRA_MAX_SIZE
)
if
(
mainc
<
0
||
mainc
>
MAINC_MAX
)
valid
=
false
;
else
if
(
sidec
<
0
||
sidec
>
SIDE
_MAX_SIZE
)
else
if
(
sidec
<
0
||
sidec
>
SIDE
C_MAX
)
valid
=
false
;
else
if
(
deck_size
!=
(
mainc
+
sidec
)
*
(
int
)
sizeof
(
int32_t
))
valid
=
false
;
...
...
@@ -297,7 +297,7 @@ void SingleDuel::UpdateDeck(DuelPlayer* dp, unsigned char* pdata, int len) {
NetServer
::
SendPacketToPlayer
(
dp
,
STOC_ERROR_MSG
,
scem
);
return
;
}
int
deck_list
[
DECK_MAX_SIZE
+
EXTRA_MAX_SIZE
+
SIDE_MAX_SIZE
];
int
deck_list
[
SIZE_NETWORK_BUFFER
/
sizeof
(
int32_t
)
];
std
::
memcpy
(
deck_list
,
deckbuf
,
deck_size
);
if
(
duel_count
==
0
)
{
deck_error
[
dp
->
type
]
=
deckManager
.
LoadDeck
(
pdeck
[
dp
->
type
],
deck_list
,
mainc
,
sidec
);
...
...
gframe/tag_duel.cpp
View file @
4c70d159
...
...
@@ -260,16 +260,16 @@ void TagDuel::PlayerKick(DuelPlayer* dp, unsigned char pos) {
void
TagDuel
::
UpdateDeck
(
DuelPlayer
*
dp
,
unsigned
char
*
pdata
,
int
len
)
{
if
(
dp
->
type
>
3
||
ready
[
dp
->
type
])
return
;
if
(
len
<
=
8
||
len
%
sizeof
(
int32_t
)
!=
0
)
if
(
len
<
8
)
return
;
bool
valid
=
true
;
auto
deckbuf
=
pdata
;
int
mainc
=
BufferIO
::
ReadInt32
(
deckbuf
);
int
sidec
=
BufferIO
::
ReadInt32
(
deckbuf
);
const
int
deck_size
=
len
-
2
*
sizeof
(
int32_t
);
if
(
mainc
<
DECK_MIN_SIZE
||
mainc
>
DECK_MAX_SIZE
+
EXTRA_MAX_SIZE
)
if
(
mainc
<
0
||
mainc
>
MAINC_MAX
)
valid
=
false
;
else
if
(
sidec
<
0
||
sidec
>
SIDE
_MAX_SIZE
)
else
if
(
sidec
<
0
||
sidec
>
SIDE
C_MAX
)
valid
=
false
;
else
if
(
deck_size
!=
(
mainc
+
sidec
)
*
(
int
)
sizeof
(
int32_t
))
valid
=
false
;
...
...
@@ -280,7 +280,7 @@ void TagDuel::UpdateDeck(DuelPlayer* dp, unsigned char* pdata, int len) {
NetServer
::
SendPacketToPlayer
(
dp
,
STOC_ERROR_MSG
,
scem
);
return
;
}
int
deck_list
[
DECK_MAX_SIZE
+
EXTRA_MAX_SIZE
+
SIDE_MAX_SIZE
];
int
deck_list
[
SIZE_NETWORK_BUFFER
/
sizeof
(
int32_t
)
];
std
::
memcpy
(
deck_list
,
deckbuf
,
deck_size
);
deck_error
[
dp
->
type
]
=
deckManager
.
LoadDeck
(
pdeck
[
dp
->
type
],
deck_list
,
mainc
,
sidec
);
}
...
...
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