Commit e444e818 authored by DailyShana's avatar DailyShana Committed by GitHub

do not stop server at duel end process (#2217)

server will stop when host player leaves the game

* do not need stop server at duel end process

* update tag_duel.cpp

* add duel stage

* fix

* fix
parent e65e5c61
......@@ -114,7 +114,7 @@ struct DuelPlayer {
class DuelMode {
public:
DuelMode(): host_player(0), pduel(0) {}
DuelMode(): host_player(0), pduel(0), duel_stage(0) {}
virtual ~DuelMode() {}
virtual void Chat(DuelPlayer* dp, void* pdata, int len) {}
virtual void JoinGame(DuelPlayer* dp, void* pdata, bool is_creater) {}
......@@ -140,6 +140,7 @@ public:
event* etimer;
DuelPlayer* host_player;
HostInfo host_info;
int duel_stage;
unsigned long pduel;
wchar_t name[20];
wchar_t pass[20];
......@@ -219,4 +220,11 @@ public:
#define MODE_SINGLE 0x0
#define MODE_MATCH 0x1
#define MODE_TAG 0x2
#define DUEL_STAGE_BEGIN 0
#define DUEL_STAGE_FINGER 1
#define DUEL_STAGE_FIRSTGO 2
#define DUEL_STAGE_DUELING 3
#define DUEL_STAGE_SIDING 4
#define DUEL_STAGE_END 5
#endif //NETWORK_H
......@@ -8,7 +8,6 @@
namespace ygo {
SingleDuel::SingleDuel(bool is_match) {
game_started = false;
match_mode = is_match;
match_kill = 0;
for(int i = 0; i < 2; ++i) {
......@@ -139,7 +138,7 @@ void SingleDuel::LeaveGame(DuelPlayer* dp) {
NetServer::StopServer();
} else if(dp->type == NETPLAYER_TYPE_OBSERVER) {
observers.erase(dp);
if(!game_started) {
if(duel_stage == DUEL_STAGE_BEGIN) {
STOC_HS_WatchChange scwc;
scwc.watch_count = observers.size();
if(players[0])
......@@ -151,7 +150,7 @@ void SingleDuel::LeaveGame(DuelPlayer* dp) {
}
NetServer::DisconnectPlayer(dp);
} else {
if(!game_started && duel_count == 0) {
if(duel_stage == DUEL_STAGE_BEGIN) {
STOC_HS_PlayerChange scpc;
players[dp->type] = 0;
ready[dp->type] = false;
......@@ -164,12 +163,13 @@ void SingleDuel::LeaveGame(DuelPlayer* dp) {
NetServer::SendPacketToPlayer(*pit, STOC_HS_PLAYER_CHANGE, scpc);
NetServer::DisconnectPlayer(dp);
} else {
if(!game_started) {
if(duel_stage == DUEL_STAGE_SIDING) {
if(!ready[0])
NetServer::SendPacketToPlayer(players[0], STOC_DUEL_START);
if(!ready[1])
NetServer::SendPacketToPlayer(players[1], STOC_DUEL_START);
}
if(duel_stage != DUEL_STAGE_END) {
unsigned char wbuf[3];
wbuf[0] = MSG_WIN;
wbuf[1] = 1 - dp->type;
......@@ -183,7 +183,8 @@ void SingleDuel::LeaveGame(DuelPlayer* dp) {
NetServer::ReSendToPlayer(players[1]);
for(auto oit = observers.begin(); oit != observers.end(); ++oit)
NetServer::ReSendToPlayer(*oit);
NetServer::StopServer();
}
NetServer::DisconnectPlayer(dp);
}
}
}
......@@ -304,6 +305,7 @@ void SingleDuel::UpdateDeck(DuelPlayer* dp, void* pdata, unsigned int len) {
NetServer::SendPacketToPlayer(players[tp_player], STOC_SELECT_TP);
players[1 - tp_player]->state = 0xff;
players[tp_player]->state = CTOS_TP_RESULT;
duel_stage = DUEL_STAGE_FIRSTGO;
}
} else {
STOC_ErrorMsg scem;
......@@ -320,7 +322,6 @@ void SingleDuel::StartDuel(DuelPlayer* dp) {
return;
NetServer::StopListen();
//NetServer::StopBroadcast();
game_started = true;
NetServer::SendPacketToPlayer(players[0], STOC_DUEL_START);
NetServer::ReSendToPlayer(players[1]);
for(auto oit = observers.begin(); oit != observers.end(); ++oit) {
......@@ -333,6 +334,7 @@ void SingleDuel::StartDuel(DuelPlayer* dp) {
hand_result[1] = 0;
players[0]->state = CTOS_HAND_RESULT;
players[1]->state = CTOS_HAND_RESULT;
duel_stage = DUEL_STAGE_FINGER;
}
void SingleDuel::HandResult(DuelPlayer* dp, unsigned char res) {
if(res > 3)
......@@ -364,17 +366,20 @@ void SingleDuel::HandResult(DuelPlayer* dp, unsigned char res) {
tp_player = 1;
players[0]->state = 0xff;
players[1]->state = CTOS_TP_RESULT;
duel_stage = DUEL_STAGE_FIRSTGO;
} else {
NetServer::SendPacketToPlayer(players[0], CTOS_TP_RESULT);
players[1]->state = 0xff;
players[0]->state = CTOS_TP_RESULT;
tp_player = 0;
duel_stage = DUEL_STAGE_FIRSTGO;
}
}
}
void SingleDuel::TPResult(DuelPlayer* dp, unsigned char tp) {
if(dp->state != CTOS_TP_RESULT)
return;
duel_stage = DUEL_STAGE_DUELING;
bool swapped = false;
mtrandom rnd;
pplayer[0] = players[0];
......@@ -497,7 +502,7 @@ void SingleDuel::DuelEndProc() {
NetServer::ReSendToPlayer(players[1]);
for(auto oit = observers.begin(); oit != observers.end(); ++oit)
NetServer::ReSendToPlayer(*oit);
NetServer::StopServer();
duel_stage = DUEL_STAGE_END;
} else {
int winc[3] = {0, 0, 0};
for(int i = 0; i < duel_count; ++i)
......@@ -510,7 +515,7 @@ void SingleDuel::DuelEndProc() {
NetServer::ReSendToPlayer(players[1]);
for(auto oit = observers.begin(); oit != observers.end(); ++oit)
NetServer::ReSendToPlayer(*oit);
NetServer::StopServer();
duel_stage = DUEL_STAGE_END;
} else {
if(players[0] != pplayer[0]) {
players[0] = pplayer[0];
......@@ -529,6 +534,7 @@ void SingleDuel::DuelEndProc() {
NetServer::SendPacketToPlayer(players[1], STOC_CHANGE_SIDE);
for(auto oit = observers.begin(); oit != observers.end(); ++oit)
NetServer::SendPacketToPlayer(*oit, STOC_WAITING_SIDE);
duel_stage = DUEL_STAGE_SIDING;
}
}
}
......
......@@ -53,7 +53,6 @@ protected:
Replay last_replay;
bool match_mode;
int match_kill;
bool game_started;
unsigned char duel_count;
unsigned char tp_player;
unsigned char match_result[3];
......
......@@ -8,7 +8,6 @@
namespace ygo {
TagDuel::TagDuel() {
game_started = false;
for(int i = 0; i < 4; ++i) {
players[i] = 0;
ready[i] = false;
......@@ -119,7 +118,7 @@ void TagDuel::LeaveGame(DuelPlayer* dp) {
NetServer::StopServer();
} else if(dp->type == NETPLAYER_TYPE_OBSERVER) {
observers.erase(dp);
if(!game_started) {
if(duel_stage == DUEL_STAGE_BEGIN) {
STOC_HS_WatchChange scwc;
scwc.watch_count = observers.size();
for(int i = 0; i < 4; ++i)
......@@ -130,7 +129,7 @@ void TagDuel::LeaveGame(DuelPlayer* dp) {
}
NetServer::DisconnectPlayer(dp);
} else {
if(!game_started) {
if(duel_stage == DUEL_STAGE_BEGIN) {
STOC_HS_PlayerChange scpc;
players[dp->type] = 0;
ready[dp->type] = false;
......@@ -141,10 +140,11 @@ void TagDuel::LeaveGame(DuelPlayer* dp) {
for(auto pit = observers.begin(); pit != observers.end(); ++pit)
NetServer::SendPacketToPlayer(*pit, STOC_HS_PLAYER_CHANGE, scpc);
NetServer::DisconnectPlayer(dp);
} else {
} else if(duel_stage != DUEL_STAGE_END) {
EndDuel();
DuelEndProc();
}
NetServer::DisconnectPlayer(dp);
}
}
void TagDuel::ToDuelist(DuelPlayer* dp) {
......@@ -278,7 +278,6 @@ void TagDuel::StartDuel(DuelPlayer* dp) {
if(!ready[0] || !ready[1] || !ready[2] || !ready[3])
return;
NetServer::StopListen();
game_started = true;
//NetServer::StopBroadcast();
for(int i = 0; i < 4; ++i)
NetServer::SendPacketToPlayer(players[i], STOC_DUEL_START);
......@@ -292,6 +291,7 @@ void TagDuel::StartDuel(DuelPlayer* dp) {
hand_result[1] = 0;
players[0]->state = CTOS_HAND_RESULT;
players[2]->state = CTOS_HAND_RESULT;
duel_stage = DUEL_STAGE_FINGER;
}
void TagDuel::HandResult(DuelPlayer* dp, unsigned char res) {
if(res > 3 || dp->state != CTOS_HAND_RESULT)
......@@ -325,16 +325,19 @@ void TagDuel::HandResult(DuelPlayer* dp, unsigned char res) {
NetServer::SendPacketToPlayer(players[2], CTOS_TP_RESULT);
players[0]->state = 0xff;
players[2]->state = CTOS_TP_RESULT;
duel_stage = DUEL_STAGE_FIRSTGO;
} else {
NetServer::SendPacketToPlayer(players[0], CTOS_TP_RESULT);
players[2]->state = 0xff;
players[0]->state = CTOS_TP_RESULT;
duel_stage = DUEL_STAGE_FIRSTGO;
}
}
}
void TagDuel::TPResult(DuelPlayer* dp, unsigned char tp) {
if(dp->state != CTOS_TP_RESULT)
return;
duel_stage = DUEL_STAGE_DUELING;
bool swapped = false;
mtrandom rnd;
pplayer[0] = players[0];
......@@ -500,7 +503,7 @@ void TagDuel::DuelEndProc() {
NetServer::ReSendToPlayer(players[3]);
for(auto oit = observers.begin(); oit != observers.end(); ++oit)
NetServer::ReSendToPlayer(*oit);
NetServer::StopServer();
duel_stage = DUEL_STAGE_END;
}
void TagDuel::Surrender(DuelPlayer* dp) {
return;
......
......@@ -52,7 +52,6 @@ protected:
unsigned char hand_result[2];
unsigned char last_response;
Replay last_replay;
bool game_started;
unsigned char turn_count;
unsigned short time_limit[2];
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