Commit 681be1c4 authored by nanahira's avatar nanahira

add MSG_REVERSE_DECK in reconnect

parent ec6813fb
......@@ -611,6 +611,8 @@ void SingleDuel::TPResult(DuelPlayer* dp, unsigned char tp) {
NetServer::SendBufferToPlayer(replay_recorder, STOC_GAME_MSG, startbuf, 19);
turn_player = 0;
phase = 1;
deck_reversed = false;
std::memset(deck_top, 0, sizeof(deck_top));
#endif
RefreshExtra(0);
RefreshExtra(1);
......@@ -1095,11 +1097,20 @@ int SingleDuel::Analyze(unsigned char* msgbuffer, unsigned int len) {
NetServer::ReSendToPlayer(*oit);
#ifdef YGOPRO_SERVER_MODE
NetServer::ReSendToPlayers(cache_recorder, replay_recorder);
deck_reversed = !deck_reversed;
#endif
break;
}
case MSG_DECK_TOP: {
#ifdef YGOPRO_SERVER_MODE
auto player = BufferIO::ReadUInt8(pbuf);
auto seq = BufferIO::ReadUInt8(pbuf);
auto code = BufferIO::ReadInt32(pbuf);
if(seq == 0)
deck_top[player] = code;
#else
pbuf += 6;
#endif
NetServer::SendBufferToPlayer(players[0], STOC_GAME_MSG, offset, pbuf - offset);
NetServer::ReSendToPlayer(players[1]);
for(auto oit = observers.begin(); oit != observers.end(); ++oit)
......@@ -1829,39 +1840,47 @@ void SingleDuel::WaitforResponse(int playerid) {
void SingleDuel::RequestField(DuelPlayer* dp) {
if(dp->type > 1)
return;
int player = dp->type;
uint8_t player = dp->type;
NetServer::SendPacketToPlayer(dp, STOC_DUEL_START);
unsigned char startbuf[32], *pbuf = startbuf;
BufferIO::WriteInt8(pbuf, MSG_START);
BufferIO::WriteInt8(pbuf, player);
BufferIO::WriteInt8(pbuf, host_info.duel_rule);
BufferIO::WriteInt32(pbuf, host_info.start_lp);
BufferIO::WriteInt32(pbuf, host_info.start_lp);
BufferIO::WriteInt16(pbuf, 0);
BufferIO::WriteInt16(pbuf, 0);
BufferIO::WriteInt16(pbuf, 0);
BufferIO::WriteInt16(pbuf, 0);
NetServer::SendBufferToPlayer(dp, STOC_GAME_MSG, startbuf, 19);
uint8_t buf[1024];
uint8_t* temp_buf = buf;
auto WriteMsg = [&](const std::function<void(uint8_t*&)> &writer) {
temp_buf = buf;
writer(temp_buf);
NetServer::SendBufferToPlayer(dp, STOC_GAME_MSG, buf, temp_buf - buf);
};
int newturn_count = 1;
if(turn_player == 1)
newturn_count = 2;
for(int i = 0; i < newturn_count; i++) {
unsigned char turnbuf[2], *pbuf_t = turnbuf;
BufferIO::WriteInt8(pbuf_t, MSG_NEW_TURN);
BufferIO::WriteInt8(pbuf_t, i);
NetServer::SendBufferToPlayer(dp, STOC_GAME_MSG, turnbuf, 2);
WriteMsg([&](uint8_t*& pbuf) {
BufferIO::WriteInt8(pbuf, MSG_START);
BufferIO::WriteInt8(pbuf, player);
BufferIO::WriteInt8(pbuf, this->host_info.duel_rule);
BufferIO::WriteInt32(pbuf, this->host_info.start_lp);
BufferIO::WriteInt32(pbuf, this->host_info.start_lp);
BufferIO::WriteInt16(pbuf, 0);
BufferIO::WriteInt16(pbuf, 0);
BufferIO::WriteInt16(pbuf, 0);
BufferIO::WriteInt16(pbuf, 0);
});
uint8_t newturn_count = (turn_player == 1) ? 2 : 1;
for (uint8_t i = 0; i < newturn_count; ++i) {
WriteMsg([&](uint8_t*& pbuf) {
BufferIO::WriteInt8(pbuf, MSG_NEW_TURN);
BufferIO::WriteInt8(pbuf, i);
});
}
unsigned char phasebuf[4], *pbuf_p = phasebuf;
BufferIO::WriteInt8(pbuf_p, MSG_NEW_PHASE);
BufferIO::WriteInt16(pbuf_p, phase);
NetServer::SendBufferToPlayer(dp, STOC_GAME_MSG, phasebuf, 3);
WriteMsg([&](uint8_t*& pbuf) {
BufferIO::WriteInt8(pbuf, MSG_NEW_PHASE);
BufferIO::WriteInt16(pbuf, this->phase);
});
WriteMsg([&](uint8_t*& pbuf) {
auto length = query_field_info(this->pduel, pbuf);
pbuf += length;
});
unsigned char query_buffer[1024];
int length = query_field_info(pduel, (unsigned char*)query_buffer);
NetServer::SendBufferToPlayer(dp, STOC_GAME_MSG, query_buffer, length);
RefreshMzone(1 - player, 0xefffff, 0, dp);
RefreshMzone(player, 0xefffff, 0, dp);
RefreshSzone(1 - player, 0xefffff, 0, dp);
......@@ -1874,6 +1893,23 @@ void SingleDuel::RequestField(DuelPlayer* dp) {
RefreshExtra(player, 0xefffff, 0, dp);
RefreshRemoved(1 - player, 0xefffff, 0, dp);
RefreshRemoved(player, 0xefffff, 0, dp);
// send MSG_REVERSE_DECK if deck is reversed
if(deck_reversed) {
WriteMsg([&](uint8_t*& pbuf) {
BufferIO::WriteInt8(pbuf, MSG_REVERSE_DECK);
});
for(uint8_t i = 0; i < 2; ++i) {
WriteMsg([&](uint8_t*& pbuf) {
BufferIO::WriteInt8(pbuf, MSG_DECK_TOP);
BufferIO::WriteInt8(pbuf, i);
BufferIO::WriteInt8(pbuf, 0);
BufferIO::WriteInt32(pbuf, this->deck_top[i]);
});
}
}
/*
if(dp == players[last_response])
WaitforResponse(last_response);
......
......@@ -71,6 +71,8 @@ protected:
DuelPlayer* replay_recorder{};
unsigned char turn_player{ 0 };
unsigned short phase{ 0 };
bool deck_reversed{ false };
uint32_t deck_top[2]{};
#endif
Replay last_replay;
bool match_mode{ false };
......
......@@ -604,6 +604,8 @@ void TagDuel::TPResult(DuelPlayer* dp, unsigned char tp) {
NetServer::SendBufferToPlayer(replay_recorder, STOC_GAME_MSG, startbuf, 19);
turn_player = 0;
phase = 1;
deck_reversed = false;
std::memset(deck_top, 0, sizeof(deck_top));
#endif
RefreshExtra(0);
RefreshExtra(1);
......@@ -1057,11 +1059,20 @@ int TagDuel::Analyze(unsigned char* msgbuffer, unsigned int len) {
NetServer::ReSendToPlayer(*oit);
#ifdef YGOPRO_SERVER_MODE
NetServer::ReSendToPlayers(cache_recorder, replay_recorder);
deck_reversed = !deck_reversed;
#endif
break;
}
case MSG_DECK_TOP: {
#ifdef YGOPRO_SERVER_MODE
auto player = BufferIO::ReadUInt8(pbuf);
auto seq = BufferIO::ReadUInt8(pbuf);
auto code = BufferIO::ReadInt32(pbuf);
if(seq == 0)
deck_top[player] = code;
#else
pbuf += 6;
#endif
NetServer::SendBufferToPlayer(players[0], STOC_GAME_MSG, offset, pbuf - offset);
NetServer::ReSendToPlayer(players[1]);
NetServer::ReSendToPlayer(players[2]);
......@@ -1926,39 +1937,49 @@ void TagDuel::WaitforResponse(int playerid) {
void TagDuel::RequestField(DuelPlayer* dp) {
if(dp->type > 3)
return;
int player = (dp->type > 1) ? 1 : 0;
uint8_t player = (dp->type > 1) ? 1 : 0;
NetServer::SendPacketToPlayer(dp, STOC_DUEL_START);
unsigned char startbuf[32], *pbuf = startbuf;
BufferIO::WriteInt8(pbuf, MSG_START);
BufferIO::WriteInt8(pbuf, player);
BufferIO::WriteInt8(pbuf, host_info.duel_rule);
BufferIO::WriteInt32(pbuf, host_info.start_lp);
BufferIO::WriteInt32(pbuf, host_info.start_lp);
BufferIO::WriteInt16(pbuf, 0);
BufferIO::WriteInt16(pbuf, 0);
BufferIO::WriteInt16(pbuf, 0);
BufferIO::WriteInt16(pbuf, 0);
NetServer::SendBufferToPlayer(dp, STOC_GAME_MSG, startbuf, 19);
uint8_t buf[1024];
uint8_t* temp_buf = buf;
auto WriteMsg = [&](const std::function<void(uint8_t*&)> &writer) {
temp_buf = buf;
writer(temp_buf);
NetServer::SendBufferToPlayer(dp, STOC_GAME_MSG, buf, temp_buf - buf);
};
int newturn_count = turn_count % 4;
WriteMsg([&](uint8_t*& pbuf) {
BufferIO::WriteInt8(pbuf, MSG_START);
BufferIO::WriteInt8(pbuf, player);
BufferIO::WriteInt8(pbuf, this->host_info.duel_rule);
BufferIO::WriteInt32(pbuf, this->host_info.start_lp);
BufferIO::WriteInt32(pbuf, this->host_info.start_lp);
BufferIO::WriteInt16(pbuf, 0);
BufferIO::WriteInt16(pbuf, 0);
BufferIO::WriteInt16(pbuf, 0);
BufferIO::WriteInt16(pbuf, 0);
});
uint8_t newturn_count = turn_count % 4;
if(newturn_count == 0)
newturn_count = 4;
for(int i = 0; i < newturn_count; i++) {
unsigned char turnbuf[2], *pbuf_t = turnbuf;
BufferIO::WriteInt8(pbuf_t, MSG_NEW_TURN);
BufferIO::WriteInt8(pbuf_t, i % 2);
NetServer::SendBufferToPlayer(dp, STOC_GAME_MSG, turnbuf, 2);
}
for (uint8_t i = 0; i < newturn_count; ++i) {
WriteMsg([&](uint8_t*& pbuf) {
BufferIO::WriteInt8(pbuf, MSG_NEW_TURN);
BufferIO::WriteInt8(pbuf, i % 2);
});
}
unsigned char phasebuf[4], *pbuf_p = phasebuf;
BufferIO::WriteInt8(pbuf_p, MSG_NEW_PHASE);
BufferIO::WriteInt16(pbuf_p, phase);
NetServer::SendBufferToPlayer(dp, STOC_GAME_MSG, phasebuf, 3);
WriteMsg([&](uint8_t*& pbuf) {
BufferIO::WriteInt8(pbuf, MSG_NEW_PHASE);
BufferIO::WriteInt16(pbuf, this->phase);
});
WriteMsg([&](uint8_t*& pbuf) {
auto length = query_field_info(this->pduel, pbuf);
pbuf += length;
});
unsigned char query_buffer[1024];
int length = query_field_info(pduel, (unsigned char*)query_buffer);
NetServer::SendBufferToPlayer(dp, STOC_GAME_MSG, query_buffer, length);
RefreshMzone(1 - player, 0xefffff, 0, dp);
RefreshMzone(player, 0xefffff, 0, dp);
RefreshSzone(1 - player, 0xefffff, 0, dp);
......@@ -1971,6 +1992,23 @@ void TagDuel::RequestField(DuelPlayer* dp) {
RefreshExtra(player, 0xefffff, 0, dp);
RefreshRemoved(1 - player, 0xefffff, 0, dp);
RefreshRemoved(player, 0xefffff, 0, dp);
// send MSG_REVERSE_DECK if deck is reversed
if(deck_reversed) {
WriteMsg([&](uint8_t*& pbuf) {
BufferIO::WriteInt8(pbuf, MSG_REVERSE_DECK);
});
for(uint8_t i = 0; i < 2; ++i) {
WriteMsg([&](uint8_t*& pbuf) {
BufferIO::WriteInt8(pbuf, MSG_DECK_TOP);
BufferIO::WriteInt8(pbuf, i);
BufferIO::WriteInt8(pbuf, 0);
BufferIO::WriteInt32(pbuf, this->deck_top[i]);
});
}
}
/*
if(dp == cur_player[last_response])
WaitforResponse(last_response);
......
......@@ -67,6 +67,8 @@ protected:
DuelPlayer* replay_recorder{};
unsigned char turn_player{ 0 };
unsigned short phase{ 0 };
bool deck_reversed{ false };
uint32_t deck_top[2]{};
#endif
bool ready[4];
bool surrender[4];
......
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