Commit 0a8a4726 authored by DailyShana's avatar DailyShana Committed by nanahira

verify deck data (#2216)

parent 284bc470
......@@ -197,7 +197,7 @@ void NetServer::HandleCTOSPacket(DuelPlayer* dp, char* data, unsigned int len) {
case CTOS_UPDATE_DECK: {
if(!dp->game)
return;
duel_mode->UpdateDeck(dp, pdata);
duel_mode->UpdateDeck(dp, pdata, len - 1);
break;
}
case CTOS_HAND_RESULT: {
......
......@@ -123,7 +123,7 @@ public:
virtual void ToObserver(DuelPlayer* dp) {}
virtual void PlayerReady(DuelPlayer* dp, bool is_ready) {}
virtual void PlayerKick(DuelPlayer* dp, unsigned char pos) {}
virtual void UpdateDeck(DuelPlayer* dp, void* pdata) {}
virtual void UpdateDeck(DuelPlayer* dp, void* pdata, unsigned int len) {}
virtual void StartDuel(DuelPlayer* dp) {}
virtual void HandResult(DuelPlayer* dp, unsigned char res) {}
virtual void TPResult(DuelPlayer* dp, unsigned char tp) {}
......
......@@ -280,12 +280,20 @@ void SingleDuel::PlayerKick(DuelPlayer* dp, unsigned char pos) {
return;
LeaveGame(players[pos]);
}
void SingleDuel::UpdateDeck(DuelPlayer* dp, void* pdata) {
void SingleDuel::UpdateDeck(DuelPlayer* dp, void* pdata, unsigned int len) {
if(dp->type > 1 || ready[dp->type])
return;
char* deckbuf = (char*)pdata;
int mainc = BufferIO::ReadInt32(deckbuf);
int sidec = BufferIO::ReadInt32(deckbuf);
// verify data
if((unsigned)mainc + (unsigned)sidec > (len - 8) / 4) {
STOC_ErrorMsg scem;
scem.msg = ERRMSG_DECKERROR;
scem.code = DECKERROR_MAINCOUNT << 28;
NetServer::SendPacketToPlayer(dp, STOC_ERROR_MSG, scem);
return;
}
if(duel_count == 0) {
deck_error[dp->type] = deckManager.LoadDeck(pdeck[dp->type], (int*)deckbuf, mainc, sidec);
} else {
......
......@@ -18,7 +18,7 @@ public:
virtual void ToObserver(DuelPlayer* dp);
virtual void PlayerReady(DuelPlayer* dp, bool ready);
virtual void PlayerKick(DuelPlayer* dp, unsigned char pos);
virtual void UpdateDeck(DuelPlayer* dp, void* pdata);
virtual void UpdateDeck(DuelPlayer* dp, void* pdata, unsigned int len);
virtual void StartDuel(DuelPlayer* dp);
virtual void HandResult(DuelPlayer* dp, unsigned char res);
virtual void TPResult(DuelPlayer* dp, unsigned char tp);
......
......@@ -256,12 +256,20 @@ void TagDuel::PlayerKick(DuelPlayer* dp, unsigned char pos) {
return;
LeaveGame(players[pos]);
}
void TagDuel::UpdateDeck(DuelPlayer* dp, void* pdata) {
void TagDuel::UpdateDeck(DuelPlayer* dp, void* pdata, unsigned int len) {
if(dp->type > 3 || ready[dp->type])
return;
char* deckbuf = (char*)pdata;
int mainc = BufferIO::ReadInt32(deckbuf);
int sidec = BufferIO::ReadInt32(deckbuf);
// verify data
if((unsigned)mainc + (unsigned)sidec > (len - 8) / 4) {
STOC_ErrorMsg scem;
scem.msg = ERRMSG_DECKERROR;
scem.code = DECKERROR_MAINCOUNT << 28;
NetServer::SendPacketToPlayer(dp, STOC_ERROR_MSG, scem);
return;
}
deck_error[dp->type] = deckManager.LoadDeck(pdeck[dp->type], (int*)deckbuf, mainc, sidec);
}
void TagDuel::StartDuel(DuelPlayer* dp) {
......
......@@ -18,7 +18,7 @@ public:
virtual void ToObserver(DuelPlayer* dp);
virtual void PlayerReady(DuelPlayer* dp, bool ready);
virtual void PlayerKick(DuelPlayer* dp, unsigned char pos);
virtual void UpdateDeck(DuelPlayer* dp, void* pdata);
virtual void UpdateDeck(DuelPlayer* dp, void* pdata, unsigned int len);
virtual void StartDuel(DuelPlayer* dp);
virtual void HandResult(DuelPlayer* dp, unsigned char res);
virtual void TPResult(DuelPlayer* dp, unsigned char tp);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment