Commit fd79494c authored by nanahira's avatar nanahira

Merge branch 'time-incr' into time-incr-koishi

parents 02006f16 1b3cbe32
Pipeline #16278 passed with stages
in 2 minutes and 59 seconds
...@@ -59,6 +59,27 @@ void NetServer::InitTestCard(int code) { ...@@ -59,6 +59,27 @@ void NetServer::InitTestCard(int code) {
test_duel->TestCard(code); test_duel->TestCard(code);
} }
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) { unsigned short NetServer::StartServer(unsigned short port) {
#else #else
bool NetServer::StartServer(unsigned short port) { bool NetServer::StartServer(unsigned short port) {
......
...@@ -30,6 +30,7 @@ public: ...@@ -30,6 +30,7 @@ public:
static void InitDuel(); static void InitDuel();
static void InitTestCard(int code); static void InitTestCard(int code);
static unsigned short StartServer(unsigned short port); static unsigned short StartServer(unsigned short port);
static bool IsCanIncreaseTime(unsigned short gameMsg, void *pdata, unsigned int len);
#else #else
static bool StartServer(unsigned short port); static bool StartServer(unsigned short port);
#endif //YGOPRO_SERVER_MODE #endif //YGOPRO_SERVER_MODE
......
...@@ -628,6 +628,9 @@ void SingleDuel::TPResult(DuelPlayer* dp, unsigned char tp) { ...@@ -628,6 +628,9 @@ void SingleDuel::TPResult(DuelPlayer* dp, unsigned char tp) {
#ifdef YGOPRO_SERVER_MODE #ifdef YGOPRO_SERVER_MODE
time_compensator[0] = host_info.time_limit; time_compensator[0] = host_info.time_limit;
time_compensator[1] = 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 #endif
timeval timeout = { 1, 0 }; timeval timeout = { 1, 0 };
event_add(etimer, &timeout); event_add(etimer, &timeout);
...@@ -742,6 +745,9 @@ int SingleDuel::Analyze(char* msgbuffer, unsigned int len) { ...@@ -742,6 +745,9 @@ int SingleDuel::Analyze(char* msgbuffer, unsigned int len) {
while (pbuf - msgbuffer < (int)len) { while (pbuf - msgbuffer < (int)len) {
offset = pbuf; offset = pbuf;
unsigned char engType = BufferIO::ReadUInt8(pbuf); unsigned char engType = BufferIO::ReadUInt8(pbuf);
#ifdef YGOPRO_SERVER_MODE
last_game_msg = engType;
#endif
switch (engType) { switch (engType) {
case MSG_RESET_TIME: { case MSG_RESET_TIME: {
player = BufferIO::ReadInt8(pbuf); player = BufferIO::ReadInt8(pbuf);
...@@ -1159,6 +1165,8 @@ int SingleDuel::Analyze(char* msgbuffer, unsigned int len) { ...@@ -1159,6 +1165,8 @@ int SingleDuel::Analyze(char* msgbuffer, unsigned int len) {
#ifdef YGOPRO_SERVER_MODE #ifdef YGOPRO_SERVER_MODE
time_compensator[0] = host_info.time_limit; time_compensator[0] = host_info.time_limit;
time_compensator[1] = 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 #endif
NetServer::SendBufferToPlayer(players[0], STOC_GAME_MSG, offset, pbuf - offset); NetServer::SendBufferToPlayer(players[0], STOC_GAME_MSG, offset, pbuf - offset);
NetServer::ReSendToPlayer(players[1]); NetServer::ReSendToPlayer(players[1]);
...@@ -1785,6 +1793,13 @@ void SingleDuel::GetResponse(DuelPlayer* dp, void* pdata, unsigned int len) { ...@@ -1785,6 +1793,13 @@ void SingleDuel::GetResponse(DuelPlayer* dp, void* pdata, unsigned int len) {
time_limit[dp->type] -= time_elapsed; time_limit[dp->type] -= time_elapsed;
else time_limit[dp->type] = 0; else time_limit[dp->type] = 0;
time_elapsed = 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(); Process();
} }
...@@ -2195,7 +2210,7 @@ int SingleDuel::MessageHandler(intptr_t fduel, int type) { ...@@ -2195,7 +2210,7 @@ int SingleDuel::MessageHandler(intptr_t fduel, int type) {
void SingleDuel::SingleTimer(evutil_socket_t fd, short events, void* arg) { void SingleDuel::SingleTimer(evutil_socket_t fd, short events, void* arg) {
SingleDuel* sd = static_cast<SingleDuel*>(arg); SingleDuel* sd = static_cast<SingleDuel*>(arg);
sd->time_elapsed++; 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]; unsigned char wbuf[3];
uint32 player = sd->last_response; uint32 player = sd->last_response;
wbuf[0] = MSG_WIN; wbuf[0] = MSG_WIN;
......
...@@ -77,10 +77,12 @@ protected: ...@@ -77,10 +77,12 @@ protected:
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];
unsigned short time_limit[2]; short time_limit[2];
unsigned short time_elapsed; short time_elapsed;
#ifdef YGOPRO_SERVER_MODE #ifdef YGOPRO_SERVER_MODE
unsigned short time_compensator[2]; short time_compensator[2];
short time_backed[2];
unsigned char last_game_msg;
#endif #endif
}; };
......
...@@ -627,6 +627,9 @@ void TagDuel::TPResult(DuelPlayer* dp, unsigned char tp) { ...@@ -627,6 +627,9 @@ void TagDuel::TPResult(DuelPlayer* dp, unsigned char tp) {
#ifdef YGOPRO_SERVER_MODE #ifdef YGOPRO_SERVER_MODE
time_compensator[0] = host_info.time_limit; time_compensator[0] = host_info.time_limit;
time_compensator[1] = 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 #endif
timeval timeout = { 1, 0 }; timeval timeout = { 1, 0 };
event_add(etimer, &timeout); event_add(etimer, &timeout);
...@@ -1117,6 +1120,8 @@ int TagDuel::Analyze(char* msgbuffer, unsigned int len) { ...@@ -1117,6 +1120,8 @@ int TagDuel::Analyze(char* msgbuffer, unsigned int len) {
#ifdef YGOPRO_SERVER_MODE #ifdef YGOPRO_SERVER_MODE
time_compensator[0] = host_info.time_limit; time_compensator[0] = host_info.time_limit;
time_compensator[1] = 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 #endif
NetServer::SendBufferToPlayer(players[0], STOC_GAME_MSG, offset, pbuf - offset); NetServer::SendBufferToPlayer(players[0], STOC_GAME_MSG, offset, pbuf - offset);
NetServer::ReSendToPlayer(players[1]); NetServer::ReSendToPlayer(players[1]);
...@@ -1874,6 +1879,13 @@ void TagDuel::GetResponse(DuelPlayer* dp, void* pdata, unsigned int len) { ...@@ -1874,6 +1879,13 @@ void TagDuel::GetResponse(DuelPlayer* dp, void* pdata, unsigned int len) {
time_limit[resp_type] -= time_elapsed; time_limit[resp_type] -= time_elapsed;
else time_limit[resp_type] = 0; else time_limit[resp_type] = 0;
time_elapsed = 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(); Process();
} }
...@@ -2346,7 +2358,7 @@ int TagDuel::MessageHandler(intptr_t fduel, int type) { ...@@ -2346,7 +2358,7 @@ int TagDuel::MessageHandler(intptr_t fduel, int type) {
void TagDuel::TagTimer(evutil_socket_t fd, short events, void* arg) { void TagDuel::TagTimer(evutil_socket_t fd, short events, void* arg) {
TagDuel* sd = static_cast<TagDuel*>(arg); TagDuel* sd = static_cast<TagDuel*>(arg);
sd->time_elapsed++; 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]; unsigned char wbuf[3];
uint32 player = sd->last_response; uint32 player = sd->last_response;
wbuf[0] = MSG_WIN; wbuf[0] = MSG_WIN;
......
...@@ -71,10 +71,12 @@ protected: ...@@ -71,10 +71,12 @@ protected:
unsigned char last_response; unsigned char last_response;
Replay last_replay; Replay last_replay;
unsigned char turn_count; unsigned char turn_count;
unsigned short time_limit[2]; short time_limit[2];
unsigned short time_elapsed; short time_elapsed;
#ifdef YGOPRO_SERVER_MODE #ifdef YGOPRO_SERVER_MODE
unsigned short time_compensator[2]; short time_compensator[2];
short time_backed[2];
unsigned char last_game_msg;
#endif #endif
}; };
......
...@@ -311,6 +311,6 @@ end ...@@ -311,6 +311,6 @@ end
if BUILD_SQLITE then if BUILD_SQLITE then
include "sqlite3" include "sqlite3"
end end
if BUILD_IKPMP3 then if BUILD_IKPMP3 and not SERVER_MODE then
include "ikpmp3" include "ikpmp3"
end end
...@@ -1163,3 +1163,4 @@ ...@@ -1163,3 +1163,4 @@
!setname 0x187 桥梁 架け橋 !setname 0x187 桥梁 架け橋
!setname 0x188 深渊之兽 ビーステッド !setname 0x188 深渊之兽 ビーステッド
!setname 0x189 俱舍怒威族 クシャトリラ !setname 0x189 俱舍怒威族 クシャトリラ
!setname 0x18a 魊影 Ghoti
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