Commit fdbfce40 authored by Chen Bill's avatar Chen Bill

use memcpy in DuelClient, NetServer

parent 1b59f4c6
......@@ -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);
......
......@@ -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)
......
......@@ -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;
}
......
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