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
8d542df6
Commit
8d542df6
authored
May 24, 2024
by
Chen Bill
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
check len in HandleCTOSPacket()
parent
9570e838
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
18 deletions
+36
-18
gframe/netserver.cpp
gframe/netserver.cpp
+35
-17
gframe/netserver.h
gframe/netserver.h
+1
-1
No files found.
gframe/netserver.cpp
View file @
8d542df6
...
@@ -186,7 +186,7 @@ void NetServer::DisconnectPlayer(DuelPlayer* dp) {
...
@@ -186,7 +186,7 @@ void NetServer::DisconnectPlayer(DuelPlayer* dp) {
users
.
erase
(
bit
);
users
.
erase
(
bit
);
}
}
}
}
void
NetServer
::
HandleCTOSPacket
(
DuelPlayer
*
dp
,
unsigned
char
*
data
,
unsigned
int
len
)
{
void
NetServer
::
HandleCTOSPacket
(
DuelPlayer
*
dp
,
unsigned
char
*
data
,
int
len
)
{
auto
pdata
=
data
;
auto
pdata
=
data
;
unsigned
char
pktType
=
BufferIO
::
ReadUInt8
(
pdata
);
unsigned
char
pktType
=
BufferIO
::
ReadUInt8
(
pdata
);
if
((
pktType
!=
CTOS_SURRENDER
)
&&
(
pktType
!=
CTOS_CHAT
)
&&
(
dp
->
state
==
0xff
||
(
dp
->
state
&&
dp
->
state
!=
pktType
)))
if
((
pktType
!=
CTOS_SURRENDER
)
&&
(
pktType
!=
CTOS_CHAT
)
&&
(
dp
->
state
==
0xff
||
(
dp
->
state
&&
dp
->
state
!=
pktType
)))
...
@@ -195,6 +195,8 @@ void NetServer::HandleCTOSPacket(DuelPlayer* dp, unsigned char* data, unsigned i
...
@@ -195,6 +195,8 @@ void NetServer::HandleCTOSPacket(DuelPlayer* dp, unsigned char* data, unsigned i
case
CTOS_RESPONSE
:
{
case
CTOS_RESPONSE
:
{
if
(
!
dp
->
game
||
!
duel_mode
->
pduel
)
if
(
!
dp
->
game
||
!
duel_mode
->
pduel
)
return
;
return
;
if
(
len
<
1
+
(
int
)
sizeof
(
unsigned
char
))
return
;
duel_mode
->
GetResponse
(
dp
,
pdata
,
len
-
1
);
duel_mode
->
GetResponse
(
dp
,
pdata
,
len
-
1
);
break
;
break
;
}
}
...
@@ -207,18 +209,24 @@ void NetServer::HandleCTOSPacket(DuelPlayer* dp, unsigned char* data, unsigned i
...
@@ -207,18 +209,24 @@ void NetServer::HandleCTOSPacket(DuelPlayer* dp, unsigned char* data, unsigned i
case
CTOS_CHAT
:
{
case
CTOS_CHAT
:
{
if
(
!
dp
->
game
)
if
(
!
dp
->
game
)
return
;
return
;
if
(
len
<
1
+
(
int
)
sizeof
(
unsigned
char
))
return
;
duel_mode
->
Chat
(
dp
,
pdata
,
len
-
1
);
duel_mode
->
Chat
(
dp
,
pdata
,
len
-
1
);
break
;
break
;
}
}
case
CTOS_UPDATE_DECK
:
{
case
CTOS_UPDATE_DECK
:
{
if
(
!
dp
->
game
)
if
(
!
dp
->
game
)
return
;
return
;
if
(
len
<
1
+
(
int
)
sizeof
(
unsigned
char
))
return
;
duel_mode
->
UpdateDeck
(
dp
,
pdata
,
len
-
1
);
duel_mode
->
UpdateDeck
(
dp
,
pdata
,
len
-
1
);
break
;
break
;
}
}
case
CTOS_HAND_RESULT
:
{
case
CTOS_HAND_RESULT
:
{
if
(
!
dp
->
game
)
if
(
!
dp
->
game
)
return
;
return
;
if
(
len
<
1
+
(
int
)
sizeof
(
CTOS_HandResult
))
return
;
CTOS_HandResult
packet
;
CTOS_HandResult
packet
;
std
::
memcpy
(
&
packet
,
pdata
,
sizeof
packet
);
std
::
memcpy
(
&
packet
,
pdata
,
sizeof
packet
);
const
auto
*
pkt
=
&
packet
;
const
auto
*
pkt
=
&
packet
;
...
@@ -228,6 +236,8 @@ void NetServer::HandleCTOSPacket(DuelPlayer* dp, unsigned char* data, unsigned i
...
@@ -228,6 +236,8 @@ void NetServer::HandleCTOSPacket(DuelPlayer* dp, unsigned char* data, unsigned i
case
CTOS_TP_RESULT
:
{
case
CTOS_TP_RESULT
:
{
if
(
!
dp
->
game
)
if
(
!
dp
->
game
)
return
;
return
;
if
(
len
<
1
+
(
int
)
sizeof
(
CTOS_TPResult
))
return
;
CTOS_TPResult
packet
;
CTOS_TPResult
packet
;
std
::
memcpy
(
&
packet
,
pdata
,
sizeof
packet
);
std
::
memcpy
(
&
packet
,
pdata
,
sizeof
packet
);
const
auto
*
pkt
=
&
packet
;
const
auto
*
pkt
=
&
packet
;
...
@@ -235,6 +245,8 @@ void NetServer::HandleCTOSPacket(DuelPlayer* dp, unsigned char* data, unsigned i
...
@@ -235,6 +245,8 @@ void NetServer::HandleCTOSPacket(DuelPlayer* dp, unsigned char* data, unsigned i
break
;
break
;
}
}
case
CTOS_PLAYER_INFO
:
{
case
CTOS_PLAYER_INFO
:
{
if
(
len
<
1
+
(
int
)
sizeof
(
CTOS_PlayerInfo
))
return
;
CTOS_PlayerInfo
packet
;
CTOS_PlayerInfo
packet
;
std
::
memcpy
(
&
packet
,
pdata
,
sizeof
packet
);
std
::
memcpy
(
&
packet
,
pdata
,
sizeof
packet
);
const
auto
*
pkt
=
&
packet
;
const
auto
*
pkt
=
&
packet
;
...
@@ -244,6 +256,8 @@ void NetServer::HandleCTOSPacket(DuelPlayer* dp, unsigned char* data, unsigned i
...
@@ -244,6 +256,8 @@ void NetServer::HandleCTOSPacket(DuelPlayer* dp, unsigned char* data, unsigned i
case
CTOS_CREATE_GAME
:
{
case
CTOS_CREATE_GAME
:
{
if
(
dp
->
game
||
duel_mode
)
if
(
dp
->
game
||
duel_mode
)
return
;
return
;
if
(
len
<
1
+
(
int
)
sizeof
(
CTOS_CreateGame
))
return
;
CTOS_CreateGame
packet
;
CTOS_CreateGame
packet
;
std
::
memcpy
(
&
packet
,
pdata
,
sizeof
packet
);
std
::
memcpy
(
&
packet
,
pdata
,
sizeof
packet
);
auto
pkt
=
&
packet
;
auto
pkt
=
&
packet
;
...
@@ -279,45 +293,49 @@ void NetServer::HandleCTOSPacket(DuelPlayer* dp, unsigned char* data, unsigned i
...
@@ -279,45 +293,49 @@ void NetServer::HandleCTOSPacket(DuelPlayer* dp, unsigned char* data, unsigned i
break
;
break
;
}
}
case
CTOS_JOIN_GAME
:
{
case
CTOS_JOIN_GAME
:
{
if
(
!
duel_mode
)
if
(
!
duel_mode
)
break
;
return
;
if
(
len
<
1
+
(
int
)
sizeof
(
CTOS_JoinGame
))
return
;
duel_mode
->
JoinGame
(
dp
,
pdata
,
false
);
duel_mode
->
JoinGame
(
dp
,
pdata
,
false
);
break
;
break
;
}
}
case
CTOS_LEAVE_GAME
:
{
case
CTOS_LEAVE_GAME
:
{
if
(
!
duel_mode
)
if
(
!
duel_mode
)
break
;
return
;
duel_mode
->
LeaveGame
(
dp
);
duel_mode
->
LeaveGame
(
dp
);
break
;
break
;
}
}
case
CTOS_SURRENDER
:
{
case
CTOS_SURRENDER
:
{
if
(
!
duel_mode
)
if
(
!
duel_mode
)
break
;
return
;
duel_mode
->
Surrender
(
dp
);
duel_mode
->
Surrender
(
dp
);
break
;
break
;
}
}
case
CTOS_HS_TODUELIST
:
{
case
CTOS_HS_TODUELIST
:
{
if
(
!
duel_mode
||
duel_mode
->
pduel
)
if
(
!
duel_mode
||
duel_mode
->
pduel
)
break
;
return
;
duel_mode
->
ToDuelist
(
dp
);
duel_mode
->
ToDuelist
(
dp
);
break
;
break
;
}
}
case
CTOS_HS_TOOBSERVER
:
{
case
CTOS_HS_TOOBSERVER
:
{
if
(
!
duel_mode
||
duel_mode
->
pduel
)
if
(
!
duel_mode
||
duel_mode
->
pduel
)
break
;
return
;
duel_mode
->
ToObserver
(
dp
);
duel_mode
->
ToObserver
(
dp
);
break
;
break
;
}
}
case
CTOS_HS_READY
:
case
CTOS_HS_READY
:
case
CTOS_HS_NOTREADY
:
{
case
CTOS_HS_NOTREADY
:
{
if
(
!
duel_mode
||
duel_mode
->
pduel
)
if
(
!
duel_mode
||
duel_mode
->
pduel
)
break
;
return
;
duel_mode
->
PlayerReady
(
dp
,
(
CTOS_HS_NOTREADY
-
pktType
)
!=
0
);
duel_mode
->
PlayerReady
(
dp
,
(
CTOS_HS_NOTREADY
-
pktType
)
!=
0
);
break
;
break
;
}
}
case
CTOS_HS_KICK
:
{
case
CTOS_HS_KICK
:
{
if
(
!
duel_mode
||
duel_mode
->
pduel
)
if
(
!
duel_mode
||
duel_mode
->
pduel
)
break
;
return
;
if
(
len
<
1
+
(
int
)
sizeof
(
CTOS_Kick
))
return
;
CTOS_Kick
packet
;
CTOS_Kick
packet
;
std
::
memcpy
(
&
packet
,
pdata
,
sizeof
packet
);
std
::
memcpy
(
&
packet
,
pdata
,
sizeof
packet
);
const
auto
*
pkt
=
&
packet
;
const
auto
*
pkt
=
&
packet
;
...
@@ -325,8 +343,8 @@ void NetServer::HandleCTOSPacket(DuelPlayer* dp, unsigned char* data, unsigned i
...
@@ -325,8 +343,8 @@ void NetServer::HandleCTOSPacket(DuelPlayer* dp, unsigned char* data, unsigned i
break
;
break
;
}
}
case
CTOS_HS_START
:
{
case
CTOS_HS_START
:
{
if
(
!
duel_mode
||
duel_mode
->
pduel
)
if
(
!
duel_mode
||
duel_mode
->
pduel
)
break
;
return
;
duel_mode
->
StartDuel
(
dp
);
duel_mode
->
StartDuel
(
dp
);
break
;
break
;
}
}
...
...
gframe/netserver.h
View file @
8d542df6
...
@@ -36,7 +36,7 @@ public:
...
@@ -36,7 +36,7 @@ public:
static
void
ServerEchoEvent
(
bufferevent
*
bev
,
short
events
,
void
*
ctx
);
static
void
ServerEchoEvent
(
bufferevent
*
bev
,
short
events
,
void
*
ctx
);
static
int
ServerThread
();
static
int
ServerThread
();
static
void
DisconnectPlayer
(
DuelPlayer
*
dp
);
static
void
DisconnectPlayer
(
DuelPlayer
*
dp
);
static
void
HandleCTOSPacket
(
DuelPlayer
*
dp
,
unsigned
char
*
data
,
unsigned
int
len
);
static
void
HandleCTOSPacket
(
DuelPlayer
*
dp
,
unsigned
char
*
data
,
int
len
);
static
void
SendPacketToPlayer
(
DuelPlayer
*
dp
,
unsigned
char
proto
)
{
static
void
SendPacketToPlayer
(
DuelPlayer
*
dp
,
unsigned
char
proto
)
{
auto
p
=
net_server_write
;
auto
p
=
net_server_write
;
BufferIO
::
WriteInt16
(
p
,
1
);
BufferIO
::
WriteInt16
(
p
,
1
);
...
...
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