Commit 545f42bf authored by mercury233's avatar mercury233 Committed by GitHub

update time limit handling (#2296)

parent 7f1e1135
......@@ -484,6 +484,11 @@ void SingleDuel::TPResult(DuelPlayer* dp, unsigned char tp) {
RefreshExtra(0);
RefreshExtra(1);
start_duel(pduel, opt);
if(host_info.time_limit) {
time_elapsed = 0;
timeval timeout = { 1, 0 };
event_add(etimer, &timeout);
}
Process();
}
void SingleDuel::Process() {
......@@ -1410,7 +1415,7 @@ void SingleDuel::GetResponse(DuelPlayer* dp, void* pdata, unsigned int len) {
if(time_limit[dp->type] >= time_elapsed)
time_limit[dp->type] -= time_elapsed;
else time_limit[dp->type] = 0;
event_del(etimer);
time_elapsed = 0;
}
Process();
}
......@@ -1427,6 +1432,7 @@ void SingleDuel::EndDuel() {
for(auto oit = observers.begin(); oit != observers.end(); ++oit)
NetServer::ReSendToPlayer(*oit);
end_duel(pduel);
event_del(etimer);
pduel = 0;
}
void SingleDuel::WaitforResponse(int playerid) {
......@@ -1449,9 +1455,8 @@ void SingleDuel::TimeConfirm(DuelPlayer* dp) {
if(dp->type != last_response)
return;
players[last_response]->state = CTOS_RESPONSE;
time_elapsed = 0;
timeval timeout = {1, 0};
event_add(etimer, &timeout);
if(time_elapsed < 10)
time_elapsed = 0;
}
void SingleDuel::RefreshMzone(int player, int flag, int use_cache) {
char query_buffer[0x2000];
......@@ -1571,7 +1576,7 @@ int SingleDuel::MessageHandler(long fduel, int type) {
void SingleDuel::SingleTimer(evutil_socket_t fd, short events, void* arg) {
SingleDuel* sd = static_cast<SingleDuel*>(arg);
sd->time_elapsed++;
if(sd->time_elapsed >= sd->time_limit[sd->last_response]) {
if(sd->time_elapsed >= sd->time_limit[sd->last_response] || sd->time_limit[sd->last_response] <= 0) {
unsigned char wbuf[3];
uint32 player = sd->last_response;
wbuf[0] = MSG_WIN;
......@@ -1591,7 +1596,10 @@ void SingleDuel::SingleTimer(evutil_socket_t fd, short events, void* arg) {
sd->EndDuel();
sd->DuelEndProc();
event_del(sd->etimer);
return;
}
timeval timeout = { 1, 0 };
event_add(sd->etimer, &timeout);
}
}
......@@ -56,8 +56,8 @@ protected:
unsigned char duel_count;
unsigned char tp_player;
unsigned char match_result[3];
unsigned short time_limit[2];
unsigned short time_elapsed;
short time_limit[2];
short time_elapsed;
};
}
......
......@@ -480,6 +480,11 @@ void TagDuel::TPResult(DuelPlayer* dp, unsigned char tp) {
RefreshExtra(0);
RefreshExtra(1);
start_duel(pduel, opt);
if(host_info.time_limit) {
time_elapsed = 0;
timeval timeout = { 1, 0 };
event_add(etimer, &timeout);
}
Process();
}
void TagDuel::Process() {
......@@ -1491,7 +1496,7 @@ void TagDuel::GetResponse(DuelPlayer* dp, void* pdata, unsigned int len) {
if(time_limit[resp_type] >= time_elapsed)
time_limit[resp_type] -= time_elapsed;
else time_limit[resp_type] = 0;
event_del(etimer);
time_elapsed = 0;
}
Process();
}
......@@ -1510,6 +1515,7 @@ void TagDuel::EndDuel() {
for(auto oit = observers.begin(); oit != observers.end(); ++oit)
NetServer::ReSendToPlayer(*oit);
end_duel(pduel);
event_del(etimer);
pduel = 0;
}
void TagDuel::WaitforResponse(int playerid) {
......@@ -1536,9 +1542,8 @@ void TagDuel::TimeConfirm(DuelPlayer* dp) {
if(dp != cur_player[last_response])
return;
cur_player[last_response]->state = CTOS_RESPONSE;
time_elapsed = 0;
timeval timeout = {1, 0};
event_add(etimer, &timeout);
if(time_elapsed < 10)
time_elapsed = 0;
}
void TagDuel::RefreshMzone(int player, int flag, int use_cache) {
char query_buffer[0x4000];
......@@ -1687,7 +1692,7 @@ int TagDuel::MessageHandler(long fduel, int type) {
void TagDuel::TagTimer(evutil_socket_t fd, short events, void* arg) {
TagDuel* sd = static_cast<TagDuel*>(arg);
sd->time_elapsed++;
if(sd->time_elapsed >= sd->time_limit[sd->last_response]) {
if(sd->time_elapsed >= sd->time_limit[sd->last_response] || sd->time_limit[sd->last_response] <= 0) {
unsigned char wbuf[3];
uint32 player = sd->last_response;
wbuf[0] = MSG_WIN;
......@@ -1700,7 +1705,10 @@ void TagDuel::TagTimer(evutil_socket_t fd, short events, void* arg) {
sd->EndDuel();
sd->DuelEndProc();
event_del(sd->etimer);
return;
}
timeval timeout = { 1, 0 };
event_add(sd->etimer, &timeout);
}
}
......@@ -53,8 +53,8 @@ protected:
unsigned char last_response;
Replay last_replay;
unsigned char turn_count;
unsigned short time_limit[2];
unsigned short time_elapsed;
short time_limit[2];
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