Commit 1b3cbe32 authored by nanahira's avatar nanahira

add backup time

parent 48347267
......@@ -55,6 +55,27 @@ void NetServer::InitDuel()
BufferIO::CopyWStr(pkt->pass, duel_mode->pass, 20);
}
bool NetServer::IsCanIncreaseTime(unsigned short gameMsg, void *pdata, unsigned int len) {
int32* ivalue = (int32*)pdata;
switch(gameMsg) {
case MSG_RETRY:
case MSG_SELECT_UNSELECT_CARD:
return false;
case MSG_SELECT_CHAIN:
return ivalue[0] != -1;
case MSG_SELECT_IDLECMD: {
int32 idleChoice = ivalue[0] & 0xffff;
return idleChoice <= 5; // no shuffle hand, enter other phases
}
case MSG_SELECT_BATTLECMD: {
int32 battleChoice = ivalue[0] & 0xffff;
return battleChoice <= 1; // attack only
}
default:
return true;
}
}
unsigned short NetServer::StartServer(unsigned short port) {
#else
bool NetServer::StartServer(unsigned short port) {
......
......@@ -29,6 +29,7 @@ public:
static event_base* net_evbase;
static void InitDuel();
static unsigned short StartServer(unsigned short port);
static bool IsCanIncreaseTime(unsigned short gameMsg, void *pdata, unsigned int len);
#else
static bool StartServer(unsigned short port);
#endif //YGOPRO_SERVER_MODE
......
......@@ -627,6 +627,9 @@ void SingleDuel::TPResult(DuelPlayer* dp, unsigned char tp) {
#ifdef YGOPRO_SERVER_MODE
time_compensator[0] = host_info.time_limit;
time_compensator[1] = host_info.time_limit;
time_backed[0] = host_info.time_limit;
time_backed[1] = host_info.time_limit;
last_game_msg = 0;
#endif
timeval timeout = { 1, 0 };
event_add(etimer, &timeout);
......@@ -741,6 +744,9 @@ int SingleDuel::Analyze(char* msgbuffer, unsigned int len) {
while (pbuf - msgbuffer < (int)len) {
offset = pbuf;
unsigned char engType = BufferIO::ReadUInt8(pbuf);
#ifdef YGOPRO_SERVER_MODE
last_game_msg = engType;
#endif
switch (engType) {
case MSG_RETRY: {
WaitforResponse(last_response);
......@@ -1143,6 +1149,8 @@ int SingleDuel::Analyze(char* msgbuffer, unsigned int len) {
#ifdef YGOPRO_SERVER_MODE
time_compensator[0] = host_info.time_limit;
time_compensator[1] = host_info.time_limit;
time_backed[0] = host_info.time_limit;
time_backed[1] = host_info.time_limit;
#endif
NetServer::SendBufferToPlayer(players[0], STOC_GAME_MSG, offset, pbuf - offset);
NetServer::ReSendToPlayer(players[1]);
......@@ -1769,6 +1777,13 @@ void SingleDuel::GetResponse(DuelPlayer* dp, void* pdata, unsigned int len) {
time_limit[dp->type] -= time_elapsed;
else time_limit[dp->type] = 0;
time_elapsed = 0;
#ifdef YGOPRO_SERVER_MODE
if(time_backed[dp->type] > 0 && time_limit[dp->type] < host_info.time_limit && NetServer::IsCanIncreaseTime(last_game_msg, pdata, len)) {
++time_limit[dp->type];
++time_compensator[dp->type];
--time_backed[dp->type];
}
#endif
}
Process();
}
......
......@@ -78,10 +78,11 @@ protected:
short time_elapsed;
#ifdef YGOPRO_SERVER_MODE
short time_compensator[2];
short time_backed[2];
unsigned char last_game_msg;
#endif
};
}
#endif //SINGLE_DUEL_H
......@@ -626,6 +626,9 @@ void TagDuel::TPResult(DuelPlayer* dp, unsigned char tp) {
#ifdef YGOPRO_SERVER_MODE
time_compensator[0] = host_info.time_limit;
time_compensator[1] = host_info.time_limit;
time_backed[0] = host_info.time_limit;
time_backed[1] = host_info.time_limit;
last_game_msg = 0;
#endif
timeval timeout = { 1, 0 };
event_add(etimer, &timeout);
......@@ -1081,6 +1084,8 @@ int TagDuel::Analyze(char* msgbuffer, unsigned int len) {
#ifdef YGOPRO_SERVER_MODE
time_compensator[0] = host_info.time_limit;
time_compensator[1] = host_info.time_limit;
time_backed[0] = host_info.time_limit;
time_backed[1] = host_info.time_limit;
#endif
NetServer::SendBufferToPlayer(players[0], STOC_GAME_MSG, offset, pbuf - offset);
NetServer::ReSendToPlayer(players[1]);
......@@ -1836,6 +1841,13 @@ void TagDuel::GetResponse(DuelPlayer* dp, void* pdata, unsigned int len) {
time_limit[resp_type] -= time_elapsed;
else time_limit[resp_type] = 0;
time_elapsed = 0;
#ifdef YGOPRO_SERVER_MODE
if(time_backed[resp_type] > 0 && time_limit[resp_type] < host_info.time_limit && NetServer::IsCanIncreaseTime(last_game_msg, pdata, len)) {
++time_limit[resp_type];
++time_compensator[resp_type];
--time_backed[resp_type];
}
#endif
}
Process();
}
......
......@@ -75,10 +75,11 @@ protected:
short time_elapsed;
#ifdef YGOPRO_SERVER_MODE
short time_compensator[2];
short time_backed[2];
unsigned char last_game_msg;
#endif
};
}
#endif //TAG_DUEL_H
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