Commit 4e324d60 authored by mercury233's avatar mercury233

fix player quit when finger-guessing

parent c4222113
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
namespace ygo { namespace ygo {
SingleDuel::SingleDuel(bool is_match) { SingleDuel::SingleDuel(bool is_match) {
game_started = false;
match_mode = is_match; match_mode = is_match;
match_kill = 0; match_kill = 0;
for(int i = 0; i < 2; ++i) { for(int i = 0; i < 2; ++i) {
...@@ -145,7 +146,7 @@ void SingleDuel::LeaveGame(DuelPlayer* dp) { ...@@ -145,7 +146,7 @@ void SingleDuel::LeaveGame(DuelPlayer* dp) {
NetServer::StopServer(); NetServer::StopServer();
} else if(dp->type == NETPLAYER_TYPE_OBSERVER) { } else if(dp->type == NETPLAYER_TYPE_OBSERVER) {
observers.erase(dp); observers.erase(dp);
if(!pduel) { if(!game_started) {
STOC_HS_WatchChange scwc; STOC_HS_WatchChange scwc;
scwc.watch_count = observers.size(); scwc.watch_count = observers.size();
if(players[0]) if(players[0])
...@@ -157,7 +158,7 @@ void SingleDuel::LeaveGame(DuelPlayer* dp) { ...@@ -157,7 +158,7 @@ void SingleDuel::LeaveGame(DuelPlayer* dp) {
} }
NetServer::DisconnectPlayer(dp); NetServer::DisconnectPlayer(dp);
} else { } else {
if(!pduel && duel_count == 0) { if(!game_started && duel_count == 0) {
STOC_HS_PlayerChange scpc; STOC_HS_PlayerChange scpc;
players[dp->type] = 0; players[dp->type] = 0;
ready[dp->type] = false; ready[dp->type] = false;
...@@ -170,7 +171,7 @@ void SingleDuel::LeaveGame(DuelPlayer* dp) { ...@@ -170,7 +171,7 @@ void SingleDuel::LeaveGame(DuelPlayer* dp) {
NetServer::SendPacketToPlayer(*pit, STOC_HS_PLAYER_CHANGE, scpc); NetServer::SendPacketToPlayer(*pit, STOC_HS_PLAYER_CHANGE, scpc);
NetServer::DisconnectPlayer(dp); NetServer::DisconnectPlayer(dp);
} else { } else {
if(!pduel) { if(!game_started) {
if(!ready[0]) if(!ready[0])
NetServer::SendPacketToPlayer(players[0], STOC_DUEL_START); NetServer::SendPacketToPlayer(players[0], STOC_DUEL_START);
if(!ready[1]) if(!ready[1])
...@@ -310,6 +311,7 @@ void SingleDuel::StartDuel(DuelPlayer* dp) { ...@@ -310,6 +311,7 @@ void SingleDuel::StartDuel(DuelPlayer* dp) {
return; return;
NetServer::StopListen(); NetServer::StopListen();
//NetServer::StopBroadcast(); //NetServer::StopBroadcast();
game_started = true;
NetServer::SendPacketToPlayer(players[0], STOC_DUEL_START); NetServer::SendPacketToPlayer(players[0], STOC_DUEL_START);
NetServer::ReSendToPlayer(players[1]); NetServer::ReSendToPlayer(players[1]);
for(auto oit = observers.begin(); oit != observers.end(); ++oit) { for(auto oit = observers.begin(); oit != observers.end(); ++oit) {
......
...@@ -52,6 +52,7 @@ protected: ...@@ -52,6 +52,7 @@ protected:
Replay last_replay; Replay last_replay;
bool match_mode; bool match_mode;
int match_kill; int match_kill;
bool game_started;
unsigned char duel_count; unsigned char duel_count;
unsigned char tp_player; unsigned char tp_player;
unsigned char match_result[3]; unsigned char match_result[3];
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
namespace ygo { namespace ygo {
TagDuel::TagDuel() { TagDuel::TagDuel() {
game_started = false;
for(int i = 0; i < 4; ++i) { for(int i = 0; i < 4; ++i) {
players[i] = 0; players[i] = 0;
ready[i] = false; ready[i] = false;
...@@ -119,7 +120,7 @@ void TagDuel::LeaveGame(DuelPlayer* dp) { ...@@ -119,7 +120,7 @@ void TagDuel::LeaveGame(DuelPlayer* dp) {
NetServer::StopServer(); NetServer::StopServer();
} else if(dp->type == NETPLAYER_TYPE_OBSERVER) { } else if(dp->type == NETPLAYER_TYPE_OBSERVER) {
observers.erase(dp); observers.erase(dp);
if(!pduel) { if(!game_started) {
STOC_HS_WatchChange scwc; STOC_HS_WatchChange scwc;
scwc.watch_count = observers.size(); scwc.watch_count = observers.size();
for(int i = 0; i < 4; ++i) for(int i = 0; i < 4; ++i)
...@@ -130,7 +131,7 @@ void TagDuel::LeaveGame(DuelPlayer* dp) { ...@@ -130,7 +131,7 @@ void TagDuel::LeaveGame(DuelPlayer* dp) {
} }
NetServer::DisconnectPlayer(dp); NetServer::DisconnectPlayer(dp);
} else { } else {
if(!pduel) { if(!game_started) {
STOC_HS_PlayerChange scpc; STOC_HS_PlayerChange scpc;
players[dp->type] = 0; players[dp->type] = 0;
ready[dp->type] = false; ready[dp->type] = false;
...@@ -263,6 +264,7 @@ void TagDuel::StartDuel(DuelPlayer* dp) { ...@@ -263,6 +264,7 @@ void TagDuel::StartDuel(DuelPlayer* dp) {
if(!ready[0] || !ready[1] || !ready[2] || !ready[3]) if(!ready[0] || !ready[1] || !ready[2] || !ready[3])
return; return;
NetServer::StopListen(); NetServer::StopListen();
game_started = true;
//NetServer::StopBroadcast(); //NetServer::StopBroadcast();
for(int i = 0; i < 4; ++i) for(int i = 0; i < 4; ++i)
NetServer::SendPacketToPlayer(players[i], STOC_DUEL_START); NetServer::SendPacketToPlayer(players[i], STOC_DUEL_START);
......
...@@ -51,6 +51,7 @@ protected: ...@@ -51,6 +51,7 @@ protected:
unsigned char hand_result[2]; unsigned char hand_result[2];
unsigned char last_response; unsigned char last_response;
Replay last_replay; Replay last_replay;
bool game_started;
unsigned char turn_count; unsigned char turn_count;
unsigned short time_limit[2]; unsigned short time_limit[2];
unsigned short time_elapsed; unsigned short time_elapsed;
......
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