Commit e65e5c61 authored by nanahira's avatar nanahira Committed by DailyShana

really retry when receiving MSG_RETRY (#2196)

* really retrying one when MSG_RETRY
* remove unnecessary retry paramter
* retry in single mode
* different hint for different action
* update retry hint
parent 9135f797
......@@ -25,6 +25,9 @@ char DuelClient::duel_client_write[0x2000];
bool DuelClient::is_closing = false;
int DuelClient::select_hint = 0;
int DuelClient::select_unselect_hint = 0;
int DuelClient::last_select_hint = 0;
char DuelClient::last_successful_msg[2048];
unsigned int DuelClient::last_successful_msg_length = 0;
wchar_t DuelClient::event_string[256];
mtrandom DuelClient::rnd;
......@@ -863,6 +866,10 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) {
char* pbuf = msg;
wchar_t textBuffer[256];
mainGame->dInfo.curMsg = BufferIO::ReadUInt8(pbuf);
if(mainGame->dInfo.curMsg != MSG_RETRY) {
memcpy(last_successful_msg, msg, len);
last_successful_msg_length = len;
}
mainGame->wCmdMenu->setVisible(false);
if(!mainGame->dInfo.isReplay && mainGame->dInfo.curMsg != MSG_WAITING && mainGame->dInfo.curMsg != MSG_CARD_SELECTED) {
mainGame->waitFrame = -1;
......@@ -884,33 +891,90 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) {
mainGame->dInfo.time_player = 2;
switch(mainGame->dInfo.curMsg) {
case MSG_RETRY: {
if(last_successful_msg_length) {
char* p = last_successful_msg;
auto last_msg = BufferIO::ReadUInt8(p);
int err_desc = 1421;
switch(last_msg) {
case MSG_ANNOUNCE_CARD:
case MSG_ANNOUNCE_CARD_FILTER:
err_desc = 1422;
break;
case MSG_ANNOUNCE_ATTRIB:
err_desc = 1423;
break;
case MSG_ANNOUNCE_RACE:
err_desc = 1424;
break;
case MSG_ANNOUNCE_NUMBER:
err_desc = 1425;
break;
case MSG_SELECT_EFFECTYN:
case MSG_SELECT_YESNO:
case MSG_SELECT_OPTION:
err_desc = 1426;
break;
case MSG_SELECT_CARD:
case MSG_SELECT_UNSELECT_CARD:
case MSG_SELECT_TRIBUTE:
case MSG_SELECT_SUM:
case MSG_SORT_CARD:
err_desc = 1427;
break;
case MSG_SELECT_CHAIN:
err_desc = 1428;
break;
case MSG_SELECT_PLACE:
case MSG_SELECT_DISFIELD:
err_desc = 1429;
break;
case MSG_SELECT_POSITION:
err_desc = 1430;
break;
case MSG_SELECT_COUNTER:
err_desc = 1431;
break;
default:
break;
}
mainGame->gMutex.Lock();
mainGame->stMessage->setText(dataManager.GetDesc(err_desc));
mainGame->PopupElement(mainGame->wMessage);
mainGame->gMutex.Unlock();
mainGame->actionSignal.Reset();
mainGame->actionSignal.Wait();
select_hint = last_select_hint;
return ClientAnalyze(last_successful_msg, last_successful_msg_length);
}
mainGame->gMutex.Lock();
mainGame->stMessage->setText(L"Error occurs.");
mainGame->PopupElement(mainGame->wMessage);
mainGame->gMutex.Unlock();
mainGame->actionSignal.Reset();
mainGame->actionSignal.Wait();
mainGame->closeDoneSignal.Reset();
mainGame->closeSignal.Set();
mainGame->closeDoneSignal.Wait();
mainGame->gMutex.Lock();
mainGame->dInfo.isStarted = false;
mainGame->dInfo.isFinished = false;
mainGame->btnCreateHost->setEnabled(true);
mainGame->btnJoinHost->setEnabled(true);
mainGame->btnJoinCancel->setEnabled(true);
mainGame->btnStartBot->setEnabled(true);
mainGame->btnBotCancel->setEnabled(true);
mainGame->stTip->setVisible(false);
mainGame->device->setEventReceiver(&mainGame->menuHandler);
if(bot_mode)
mainGame->ShowElement(mainGame->wSinglePlay);
else
mainGame->ShowElement(mainGame->wLanWindow);
mainGame->gMutex.Unlock();
event_base_loopbreak(client_base);
if(exit_on_return)
mainGame->device->closeDevice();
if(!mainGame->dInfo.isSingleMode) {
mainGame->closeDoneSignal.Reset();
mainGame->closeSignal.Set();
mainGame->closeDoneSignal.Wait();
mainGame->gMutex.Lock();
mainGame->dInfo.isStarted = false;
mainGame->dInfo.isFinished = false;
mainGame->btnCreateHost->setEnabled(true);
mainGame->btnJoinHost->setEnabled(true);
mainGame->btnJoinCancel->setEnabled(true);
mainGame->btnStartBot->setEnabled(true);
mainGame->btnBotCancel->setEnabled(true);
mainGame->stTip->setVisible(false);
mainGame->device->setEventReceiver(&mainGame->menuHandler);
if(bot_mode)
mainGame->ShowElement(mainGame->wSinglePlay);
else
mainGame->ShowElement(mainGame->wLanWindow);
mainGame->gMutex.Unlock();
event_base_loopbreak(client_base);
if(exit_on_return)
mainGame->device->closeDevice();
}
return false;
}
case MSG_HINT: {
......@@ -935,6 +999,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) {
}
case HINT_SELECTMSG: {
select_hint = data;
last_select_hint = data;
break;
}
case HINT_OPSELECTED: {
......@@ -1078,6 +1143,10 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) {
mainGame->dField.Initial(mainGame->LocalPlayer(1), deckc, extrac);
mainGame->dInfo.turn = 0;
mainGame->dInfo.is_shuffling = false;
select_hint = 0;
select_unselect_hint = 0;
last_select_hint = 0;
last_successful_msg_length = 0;
if(mainGame->dInfo.isReplaySwapped) {
std::swap(mainGame->dInfo.hostname, mainGame->dInfo.clientname);
std::swap(mainGame->dInfo.hostname_tag, mainGame->dInfo.clientname_tag);
......
......@@ -31,6 +31,9 @@ private:
static bool is_closing;
static int select_hint;
static int select_unselect_hint;
static int last_select_hint;
static char last_successful_msg[2048];
static unsigned int last_successful_msg_length;
static wchar_t event_string[256];
static mtrandom rnd;
public:
......
......@@ -177,13 +177,11 @@ bool SingleMode::SinglePlayAnalyze(char* msg, unsigned int len) {
mainGame->dInfo.curMsg = BufferIO::ReadUInt8(pbuf);
switch (mainGame->dInfo.curMsg) {
case MSG_RETRY: {
mainGame->gMutex.Lock();
mainGame->stMessage->setText(L"Error occurs.");
mainGame->PopupElement(mainGame->wMessage);
mainGame->gMutex.Unlock();
mainGame->actionSignal.Reset();
mainGame->actionSignal.Wait();
return false;
if(!DuelClient::ClientAnalyze(offset, pbuf - offset)) {
mainGame->singleSignal.Reset();
mainGame->singleSignal.Wait();
}
break;
}
case MSG_HINT: {
/*int type = */BufferIO::ReadInt8(pbuf);
......
......@@ -438,7 +438,17 @@
!system 1418 额外卡组数量应不超过15张,当前卡组数量为%d张。
!system 1419 副卡组数量应不超过15张,当前卡组数量为%d张。
!system 1420 有额外卡组卡片存在于主卡组,可能是额外卡组数量超过15张。
!system 1421 宣言的卡不符合条件,或无法被主机识别。
!system 1421 操作无效,请重试。
!system 1422 宣言的卡不符合条件,或无法被主机识别。
!system 1423 宣言的属性不符合条件。
!system 1424 宣言的种族不符合条件
!system 1425 宣言的数字不符合条件。
!system 1426 选择的选项不符合条件
!system 1427 选择的卡片不符合条件。
!system 1428 选择的连锁不符合条件。
!system 1429 选择的位置不符合条件。
!system 1430 选择的表示形式不符合条件。
!system 1431 选择的指示物不符合条件。
!system 1500 决斗结束。
!system 1501 录像结束。
!system 1502 连接已断开。
......
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