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
fdbfce40
Commit
fdbfce40
authored
May 21, 2024
by
Chen Bill
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use memcpy in DuelClient, NetServer
parent
1b59f4c6
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
57 additions
and
23 deletions
+57
-23
gframe/drawing.cpp
gframe/drawing.cpp
+4
-4
gframe/duelclient.cpp
gframe/duelclient.cpp
+34
-13
gframe/netserver.cpp
gframe/netserver.cpp
+19
-6
No files found.
gframe/drawing.cpp
View file @
fdbfce40
...
...
@@ -18,10 +18,10 @@ void Game::DrawSelectionLine(irr::video::S3DVertex* vec, bool strip, int width,
glDisable
(
GL_TEXTURE_2D
);
glMaterialfv
(
GL_FRONT
,
GL_AMBIENT
,
cv
);
glBegin
(
GL_LINE_LOOP
);
glVertex3fv
(
(
float
*
)
&
vec
[
0
].
Pos
);
glVertex3fv
(
(
float
*
)
&
vec
[
1
].
Pos
);
glVertex3fv
(
(
float
*
)
&
vec
[
3
].
Pos
);
glVertex3fv
(
(
float
*
)
&
vec
[
2
].
Pos
);
glVertex3fv
(
&
vec
[
0
].
Pos
.
X
);
glVertex3fv
(
&
vec
[
1
].
Pos
.
X
);
glVertex3fv
(
&
vec
[
3
].
Pos
.
X
);
glVertex3fv
(
&
vec
[
2
].
Pos
.
X
);
glEnd
();
glMaterialfv
(
GL_FRONT
,
GL_AMBIENT
,
origin
);
glDisable
(
GL_LINE_STIPPLE
);
...
...
gframe/duelclient.cpp
View file @
fdbfce40
...
...
@@ -244,7 +244,9 @@ void DuelClient::HandleSTOCPacketLan(unsigned char* data, unsigned int len) {
break;
}
case STOC_ERROR_MSG: {
STOC_ErrorMsg
*
pkt
=
(
STOC_ErrorMsg
*
)
pdata
;
STOC_ErrorMsg packet;
std::memcpy(&packet, pdata, sizeof packet);
const auto* pkt = &packet;
switch(pkt->msg) {
case ERRMSG_JOINERROR: {
mainGame->btnCreateHost->setEnabled(true);
...
...
@@ -358,7 +360,9 @@ void DuelClient::HandleSTOCPacketLan(unsigned char* data, unsigned int len) {
break;
}
case STOC_HAND_RESULT: {
STOC_HandResult
*
pkt
=
(
STOC_HandResult
*
)
pdata
;
STOC_HandResult packet;
std::memcpy(&packet, pdata, sizeof packet);
const auto* pkt = &packet;
mainGame->stHintMsg->setVisible(false);
mainGame->showcardcode = (pkt->res1 - 1) + ((pkt->res2 - 1) << 16);
mainGame->showcarddif = 50;
...
...
@@ -426,7 +430,9 @@ void DuelClient::HandleSTOCPacketLan(unsigned char* data, unsigned int len) {
break;
}
case STOC_JOIN_GAME: {
STOC_JoinGame
*
pkt
=
(
STOC_JoinGame
*
)
pdata
;
STOC_JoinGame packet;
std::memcpy(&packet, pdata, sizeof packet);
const auto* pkt = &packet;
std::wstring str;
wchar_t msgbuf[256];
myswprintf(msgbuf, L"%ls%ls\n", dataManager.GetSysString(1226), deckManager.GetLFListName(pkt->info.lflist));
...
...
@@ -505,7 +511,9 @@ void DuelClient::HandleSTOCPacketLan(unsigned char* data, unsigned int len) {
break;
}
case STOC_TYPE_CHANGE: {
STOC_TypeChange
*
pkt
=
(
STOC_TypeChange
*
)
pdata
;
STOC_TypeChange packet;
std::memcpy(&packet, pdata, sizeof packet);
const auto* pkt = &packet;
if(!mainGame->dInfo.isTag) {
selftype = pkt->type & 0xf;
is_host = ((pkt->type >> 4) & 0xf) != 0;
...
...
@@ -738,7 +746,9 @@ void DuelClient::HandleSTOCPacketLan(unsigned char* data, unsigned int len) {
break;
}
case STOC_TIME_LIMIT: {
STOC_TimeLimit
*
pkt
=
(
STOC_TimeLimit
*
)
pdata
;
STOC_TimeLimit packet;
std::memcpy(&packet, pdata, sizeof packet);
const auto* pkt = &packet;
int lplayer = mainGame->LocalPlayer(pkt->player);
if(lplayer == 0)
DuelClient::SendPacketToServer(CTOS_TIME_CONFIRM);
...
...
@@ -747,7 +757,9 @@ void DuelClient::HandleSTOCPacketLan(unsigned char* data, unsigned int len) {
break;
}
case STOC_CHAT: {
STOC_Chat
*
pkt
=
(
STOC_Chat
*
)
pdata
;
STOC_Chat packet;
std::memcpy(&packet, pdata, sizeof packet);
const auto* pkt = &packet;
int player = pkt->player;
auto play_sound = false;
if(player < 4) {
...
...
@@ -777,7 +789,9 @@ void DuelClient::HandleSTOCPacketLan(unsigned char* data, unsigned int len) {
}
case STOC_HS_PLAYER_ENTER: {
soundManager.PlaySoundEffect(SOUND_PLAYER_ENTER);
STOC_HS_PlayerEnter
*
pkt
=
(
STOC_HS_PlayerEnter
*
)
pdata
;
STOC_HS_PlayerEnter packet;
std::memcpy(&packet, pdata, sizeof packet);
const auto* pkt = &packet;
if(pkt->pos > 3)
break;
wchar_t name[20];
...
...
@@ -808,7 +822,9 @@ void DuelClient::HandleSTOCPacketLan(unsigned char* data, unsigned int len) {
break;
}
case STOC_HS_PLAYER_CHANGE: {
STOC_HS_PlayerChange
*
pkt
=
(
STOC_HS_PlayerChange
*
)
pdata
;
STOC_HS_PlayerChange packet;
std::memcpy(&packet, pdata, sizeof packet);
const auto* pkt = &packet;
unsigned char pos = (pkt->status >> 4) & 0xf;
unsigned char state = pkt->status & 0xf;
if(pos > 3)
...
...
@@ -816,7 +832,7 @@ void DuelClient::HandleSTOCPacketLan(unsigned char* data, unsigned int len) {
mainGame->gMutex.lock();
if(state < 8) {
soundManager.PlaySoundEffect(SOUND_PLAYER_ENTER);
wchar_t
*
prename
=
(
wchar_t
*
)
mainGame
->
stHostPrepDuelist
[
pos
]
->
getToolTipText
().
c_str
();
const wchar_t* prename =
mainGame->stHostPrepDuelist[pos]->getToolTipText().c_str();
if(mainGame->gameConf.hide_player_name)
mainGame->stHostPrepDuelist[state]->setText(L"[********]");
else
...
...
@@ -868,7 +884,9 @@ void DuelClient::HandleSTOCPacketLan(unsigned char* data, unsigned int len) {
break;
}
case STOC_HS_WATCH_CHANGE: {
STOC_HS_WatchChange
*
pkt
=
(
STOC_HS_WatchChange
*
)
pdata
;
STOC_HS_WatchChange packet;
std::memcpy(&packet, pdata, sizeof packet);
const auto* pkt = &packet;
watching = pkt->watch_count;
wchar_t watchbuf[32];
myswprintf(watchbuf, L"%ls%d", dataManager.GetSysString(1253), watching);
...
...
@@ -3946,7 +3964,7 @@ void DuelClient::SwapField() {
is_swapping = true;
}
void DuelClient::SetResponseI(int respI) {
*
((
int
*
)
response_buf
)
=
respI
;
std::memcpy(response_buf, &respI, sizeof respI)
;
response_len = 4;
}
void DuelClient::SetResponseB(void* respB, unsigned int len) {
...
...
@@ -4032,7 +4050,8 @@ void DuelClient::BeginRefreshHost() {
for(int i = 0; i < 8; ++i) {
if(host->h_addr_list[i] == 0)
break;
unsigned
int
local_addr
=
*
(
unsigned
int
*
)
host
->
h_addr_list
[
i
];
unsigned int local_addr = 0;
std::memcpy(&local_addr, host->h_addr_list[i], sizeof local_addr);
local.sin_addr.s_addr = local_addr;
SOCKET sSend = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if(sSend == INVALID_SOCKET)
...
...
@@ -4068,7 +4087,9 @@ void DuelClient::BroadcastReply(evutil_socket_t fd, short events, void * arg) {
socklen_t sz = sizeof(sockaddr_in);
char buf[256];
/*int ret = */recvfrom(fd, buf, 256, 0, (sockaddr*)&bc_addr, &sz);
HostPacket
*
pHP
=
(
HostPacket
*
)
buf
;
HostPacket packet;
std::memcpy(&packet, buf, sizeof packet);
HostPacket* pHP = &packet;
if(is_closing || pHP->identifier != NETWORK_SERVER_ID)
return;
if(pHP->version != PRO_VERSION)
...
...
gframe/netserver.cpp
View file @
fdbfce40
...
...
@@ -84,7 +84,9 @@ void NetServer::BroadcastEvent(evutil_socket_t fd, short events, void* arg) {
int
ret
=
recvfrom
(
fd
,
buf
,
256
,
0
,
(
sockaddr
*
)
&
bc_addr
,
&
sz
);
if
(
ret
==
-
1
)
return
;
HostRequest
*
pHR
=
(
HostRequest
*
)
buf
;
HostRequest
packet
;
std
::
memcpy
(
&
packet
,
buf
,
sizeof
packet
);
const
HostRequest
*
pHR
=
&
packet
;
if
(
pHR
->
identifier
==
NETWORK_CLIENT_ID
)
{
SOCKADDR_IN
sockTo
;
sockTo
.
sin_addr
.
s_addr
=
bc_addr
.
sin_addr
.
s_addr
;
...
...
@@ -204,26 +206,34 @@ void NetServer::HandleCTOSPacket(DuelPlayer* dp, unsigned char* data, unsigned i
case
CTOS_HAND_RESULT
:
{
if
(
!
dp
->
game
)
return
;
CTOS_HandResult
*
pkt
=
(
CTOS_HandResult
*
)
pdata
;
CTOS_HandResult
packet
;
std
::
memcpy
(
&
packet
,
pdata
,
sizeof
packet
);
const
auto
*
pkt
=
&
packet
;
dp
->
game
->
HandResult
(
dp
,
pkt
->
res
);
break
;
}
case
CTOS_TP_RESULT
:
{
if
(
!
dp
->
game
)
return
;
CTOS_TPResult
*
pkt
=
(
CTOS_TPResult
*
)
pdata
;
CTOS_TPResult
packet
;
std
::
memcpy
(
&
packet
,
pdata
,
sizeof
packet
);
const
auto
*
pkt
=
&
packet
;
dp
->
game
->
TPResult
(
dp
,
pkt
->
res
);
break
;
}
case
CTOS_PLAYER_INFO
:
{
CTOS_PlayerInfo
*
pkt
=
(
CTOS_PlayerInfo
*
)
pdata
;
CTOS_PlayerInfo
packet
;
std
::
memcpy
(
&
packet
,
pdata
,
sizeof
packet
);
const
auto
*
pkt
=
&
packet
;
BufferIO
::
CopyWStr
(
pkt
->
name
,
dp
->
name
,
20
);
break
;
}
case
CTOS_CREATE_GAME
:
{
if
(
dp
->
game
||
duel_mode
)
return
;
CTOS_CreateGame
*
pkt
=
(
CTOS_CreateGame
*
)
pdata
;
CTOS_CreateGame
packet
;
std
::
memcpy
(
&
packet
,
pdata
,
sizeof
packet
);
auto
pkt
=
&
packet
;
if
(
pkt
->
info
.
mode
==
MODE_SINGLE
)
{
duel_mode
=
new
SingleDuel
(
false
);
duel_mode
->
etimer
=
event_new
(
net_evbase
,
0
,
EV_TIMEOUT
|
EV_PERSIST
,
SingleDuel
::
SingleTimer
,
duel_mode
);
...
...
@@ -247,6 +257,7 @@ void NetServer::HandleCTOSPacket(DuelPlayer* dp, unsigned char* data, unsigned i
}
if
(
hash
==
1
)
pkt
->
info
.
lflist
=
deckManager
.
_lfList
[
0
].
hash
;
std
::
memcpy
(
pdata
,
&
packet
,
sizeof
packet
);
duel_mode
->
host_info
=
pkt
->
info
;
BufferIO
::
CopyWStr
(
pkt
->
name
,
duel_mode
->
name
,
20
);
BufferIO
::
CopyWStr
(
pkt
->
pass
,
duel_mode
->
pass
,
20
);
...
...
@@ -294,7 +305,9 @@ void NetServer::HandleCTOSPacket(DuelPlayer* dp, unsigned char* data, unsigned i
case
CTOS_HS_KICK
:
{
if
(
!
duel_mode
||
duel_mode
->
pduel
)
break
;
CTOS_Kick
*
pkt
=
(
CTOS_Kick
*
)
pdata
;
CTOS_Kick
packet
;
std
::
memcpy
(
&
packet
,
pdata
,
sizeof
packet
);
const
auto
*
pkt
=
&
packet
;
duel_mode
->
PlayerKick
(
dp
,
pkt
->
pos
);
break
;
}
...
...
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