Commit 69b9e8cf authored by nanahira's avatar nanahira

Merge branch 'develop' into server-develop

parents 3781c056 8c8a4b67
......@@ -120,7 +120,7 @@ jobs:
- name: Download miniaudio
if: matrix.audiolib == 'miniaudio'
run: |
git clone --depth=1 --branch 0.11.22 https://github.com/mackron/miniaudio
git clone --depth=1 https://github.com/mercury233/miniaudio
cd miniaudio
xcopy /Y extras\miniaudio_split\miniaudio.* .
cd ..
......@@ -367,7 +367,7 @@ jobs:
- name: Download miniaudio
run: |
git clone --depth=1 --branch 0.11.22 https://github.com/mackron/miniaudio
git clone --depth=1 https://github.com/mercury233/miniaudio
cd miniaudio
cp extras/miniaudio_split/miniaudio.* .
cd ..
......@@ -601,7 +601,7 @@ jobs:
- name: Download miniaudio
run: |
git clone --depth=1 --branch 0.11.22 https://github.com/mackron/miniaudio
git clone --depth=1 https://github.com/mercury233/miniaudio
cd miniaudio
cp extras/miniaudio_split/miniaudio.* .
cd ..
......
......@@ -1162,6 +1162,14 @@ bool ClientField::ShowSelectSum(bool panelmode) {
}
return false;
}
static void get_sum_params(irr::u32 opParam, int& op1, int& op2) {
op1 = opParam & 0xffff;
op2 = (opParam >> 16) & 0xffff;
if(op2 & 0x8000) {
op1 = opParam & 0x7fffffff;
op2 = 0;
}
}
bool ClientField::CheckSelectSum() {
std::set<ClientCard*> selable;
for(auto sc : selectsum_all) {
......@@ -1202,8 +1210,8 @@ bool ClientField::CheckSelectSum() {
int mm = -1, mx = -1, max = 0, sumc = 0;
bool ret = false;
for (auto sc : selected_cards) {
int op1 = sc->opParam & 0xffff;
int op2 = sc->opParam >> 16;
int op1, op2;
get_sum_params(sc->opParam, op1, op2);
int opmin = (op2 > 0 && op1 > op2) ? op2 : op1;
int opmax = op2 > op1 ? op2 : op1;
if (mm == -1 || opmin < mm)
......@@ -1218,8 +1226,8 @@ bool ClientField::CheckSelectSum() {
if (select_sumval <= max && select_sumval > max - mx)
ret = true;
for(auto sc : selable) {
int op1 = sc->opParam & 0xffff;
int op2 = sc->opParam >> 16;
int op1, op2;
get_sum_params(sc->opParam, op1, op2);
int m = op1;
int sums = sumc;
sums += m;
......@@ -1288,8 +1296,8 @@ bool ClientField::CheckSelectTribute() {
bool ClientField::check_min(const std::set<ClientCard*>& left, std::set<ClientCard*>::const_iterator index, int min, int max) {
if (index == left.end())
return false;
int op1 = (*index)->opParam & 0xffff;
int op2 = (*index)->opParam >> 16;
int op1, op2;
get_sum_params((*index)->opParam, op1, op2);
int m = (op2 > 0 && op1 > op2) ? op2 : op1;
if (m >= min && m <= max)
return true;
......@@ -1308,9 +1316,8 @@ bool ClientField::check_sel_sum_s(const std::set<ClientCard*>& left, int index,
check_sel_sum_t(left, acc);
return false;
}
int l = selected_cards[index]->opParam;
int l1 = l & 0xffff;
int l2 = l >> 16;
int l1, l2;
get_sum_params(selected_cards[index]->opParam, l1, l2);
bool res1 = false, res2 = false;
res1 = check_sel_sum_s(left, index + 1, acc - l1);
if (l2 > 0)
......@@ -1324,9 +1331,8 @@ void ClientField::check_sel_sum_t(const std::set<ClientCard*>& left, int acc) {
continue;
std::set<ClientCard*> testlist(left);
testlist.erase(*sit);
int l = (*sit)->opParam;
int l1 = l & 0xffff;
int l2 = l >> 16;
int l1, l2;
get_sum_params((*sit)->opParam, l1, l2);
if (check_sum(testlist.begin(), testlist.end(), acc - l1, count)
|| (l2 > 0 && check_sum(testlist.begin(), testlist.end(), acc - l2, count))) {
selectsum_cards.insert(*sit);
......@@ -1338,9 +1344,8 @@ bool ClientField::check_sum(std::set<ClientCard*>::const_iterator index, std::se
return count >= select_min && count <= select_max;
if (acc < 0 || index == end)
return false;
int l = (*index)->opParam;
int l1 = l & 0xffff;
int l2 = l >> 16;
int l1, l2;
get_sum_params((*index)->opParam, l1, l2);
if ((l1 == acc || (l2 > 0 && l2 == acc)) && (count + 1 >= select_min) && (count + 1 <= select_max))
return true;
++index;
......@@ -1355,9 +1360,8 @@ bool ClientField::check_sel_sum_trib_s(const std::set<ClientCard*>& left, int in
check_sel_sum_trib_t(left, acc);
return acc >= select_min && acc <= select_max;
}
int l = selected_cards[index]->opParam;
int l1 = l & 0xffff;
int l2 = l >> 16;
int l1, l2;
get_sum_params(selected_cards[index]->opParam, l1, l2);
bool res1 = false, res2 = false;
res1 = check_sel_sum_trib_s(left, index + 1, acc + l1);
if(l2 > 0)
......@@ -1370,9 +1374,8 @@ void ClientField::check_sel_sum_trib_t(const std::set<ClientCard*>& left, int ac
continue;
std::set<ClientCard*> testlist(left);
testlist.erase(*sit);
int l = (*sit)->opParam;
int l1 = l & 0xffff;
int l2 = l >> 16;
int l1, l2;
get_sum_params((*sit)->opParam, l1, l2);
if(check_sum_trib(testlist.begin(), testlist.end(), acc + l1)
|| (l2 > 0 && check_sum_trib(testlist.begin(), testlist.end(), acc + l2))) {
selectsum_cards.insert(*sit);
......@@ -1384,9 +1387,8 @@ bool ClientField::check_sum_trib(std::set<ClientCard*>::const_iterator index, st
return true;
if(acc > select_max || index == end)
return false;
int l = (*index)->opParam;
int l1 = l & 0xffff;
int l2 = l >> 16;
int l1, l2;
get_sum_params((*index)->opParam, l1, l2);
if((acc + l1 >= select_min && acc + l1 <= select_max) || (acc + l2 >= select_min && acc + l2 <= select_max))
return true;
++index;
......
......@@ -130,6 +130,15 @@ void DuelClient::ClientRead(bufferevent* bev, void* ctx) {
void DuelClient::ClientEvent(bufferevent* bev, short events, void* ctx) {
if (events & BEV_EVENT_CONNECTED) {
bool create_game = (intptr_t)ctx;
if(!create_game) {
uint16_t hostname_buf[LEN_HOSTNAME];
auto hostname_len = BufferIO::CopyCharArray(mainGame->ebJoinHost->getText(), hostname_buf);
auto hostname_msglen = (hostname_len + 1) * sizeof(uint16_t);
char buf[LEN_HOSTNAME * sizeof(int16_t) + sizeof(uint32_t)];
memset(buf, 0, sizeof(uint32_t)); // real_ip
memcpy(buf + sizeof(uint32_t), hostname_buf, hostname_msglen);
SendBufferToServer(CTOS_EXTERNAL_ADDRESS, buf, hostname_msglen + sizeof(uint32_t));
}
CTOS_PlayerInfo cspi;
BufferIO::CopyCharArray(mainGame->ebNickName->getText(), cspi.name);
SendPacketToServer(CTOS_PLAYER_INFO, cspi);
......@@ -1488,7 +1497,7 @@ bool DuelClient::ClientAnalyze(unsigned char* msg, int len) {
}
mainGame->dField.activatable_cards.push_back(pcard);
mainGame->dField.activatable_descs.push_back(std::make_pair(desc, flag));
if(flag == EDESC_OPERATION) {
if(flag & EDESC_OPERATION) {
pcard->chain_code = code;
mainGame->dField.conti_cards.push_back(pcard);
mainGame->dField.conti_act = true;
......@@ -1621,7 +1630,7 @@ bool DuelClient::ClientAnalyze(unsigned char* msg, int len) {
}
mainGame->dField.activatable_cards.push_back(pcard);
mainGame->dField.activatable_descs.push_back(std::make_pair(desc, flag));
if(flag == EDESC_OPERATION) {
if(flag & EDESC_OPERATION) {
pcard->chain_code = code;
mainGame->dField.conti_cards.push_back(pcard);
mainGame->dField.conti_act = true;
......@@ -1881,7 +1890,6 @@ bool DuelClient::ClientAnalyze(unsigned char* msg, int len) {
/*int selecting_player = */BufferIO::ReadUInt8(pbuf);
int count = BufferIO::ReadUInt8(pbuf);
int specount = BufferIO::ReadUInt8(pbuf);
int forced = BufferIO::ReadUInt8(pbuf);
/*int hint0 = */BufferIO::ReadInt32(pbuf);
/*int hint1 = */BufferIO::ReadInt32(pbuf);
int c, s, ss, desc;
......@@ -1890,12 +1898,14 @@ bool DuelClient::ClientAnalyze(unsigned char* msg, int len) {
bool panelmode = false;
bool conti_exist = false;
bool select_trigger = (specount == 0x7f);
mainGame->dField.chain_forced = (forced != 0);
mainGame->dField.chain_forced = false;
mainGame->dField.activatable_cards.clear();
mainGame->dField.activatable_descs.clear();
mainGame->dField.conti_cards.clear();
for (int i = 0; i < count; ++i) {
int flag = BufferIO::ReadUInt8(pbuf);
int forced = BufferIO::ReadUInt8(pbuf);
flag |= forced << 8;
code = BufferIO::ReadInt32(pbuf);
c = mainGame->LocalPlayer(BufferIO::ReadUInt8(pbuf));
l = BufferIO::ReadUInt8(pbuf);
......@@ -1906,14 +1916,17 @@ bool DuelClient::ClientAnalyze(unsigned char* msg, int len) {
mainGame->dField.activatable_cards.push_back(pcard);
mainGame->dField.activatable_descs.push_back(std::make_pair(desc, flag));
pcard->is_selected = false;
if(flag == EDESC_OPERATION) {
if(forced) {
mainGame->dField.chain_forced = true;
}
if(flag & EDESC_OPERATION) {
pcard->chain_code = code;
mainGame->dField.conti_cards.push_back(pcard);
mainGame->dField.conti_act = true;
conti_exist = true;
} else {
pcard->is_selectable = true;
if(flag == EDESC_RESET)
if(flag & EDESC_RESET)
pcard->cmdFlag |= COMMAND_RESET;
else
pcard->cmdFlag |= COMMAND_ACTIVATE;
......@@ -1930,7 +1943,7 @@ bool DuelClient::ClientAnalyze(unsigned char* msg, int len) {
panelmode = true;
}
}
if(!select_trigger && !forced && (mainGame->ignore_chain || ((count == 0 || specount == 0) && !mainGame->always_chain)) && (count == 0 || !mainGame->chain_when_avail)) {
if(!select_trigger && !mainGame->dField.chain_forced && (mainGame->ignore_chain || ((count == 0 || specount == 0) && !mainGame->always_chain)) && (count == 0 || !mainGame->chain_when_avail)) {
SetResponseI(-1);
mainGame->dField.ClearChainSelect();
if(mainGame->chkWaitChain->isChecked() && !mainGame->ignore_chain) {
......@@ -1939,8 +1952,14 @@ bool DuelClient::ClientAnalyze(unsigned char* msg, int len) {
DuelClient::SendResponse();
return true;
}
if(mainGame->chkAutoChain->isChecked() && forced && !(mainGame->always_chain || mainGame->chain_when_avail)) {
SetResponseI(0);
if(mainGame->chkAutoChain->isChecked() && mainGame->dField.chain_forced && !(mainGame->always_chain || mainGame->chain_when_avail)) {
for(size_t i = 0; i < mainGame->dField.activatable_descs.size();++i) {
auto it = mainGame->dField.activatable_descs[i];
if(it.second >> 8) {
SetResponseI((int)i);
break;
}
}
mainGame->dField.ClearChainSelect();
DuelClient::SendResponse();
return true;
......@@ -1959,7 +1978,7 @@ bool DuelClient::ClientAnalyze(unsigned char* msg, int len) {
mainGame->dField.selectable_cards.erase(eit, mainGame->dField.selectable_cards.end());
mainGame->dField.ShowChainCard();
} else {
if(!forced) {
if(!mainGame->dField.chain_forced) {
if(count == 0)
myswprintf(textBuffer, L"%ls\n%ls", dataManager.GetSysString(201), dataManager.GetSysString(202));
else if(select_trigger)
......@@ -2339,6 +2358,7 @@ bool DuelClient::ClientAnalyze(unsigned char* msg, int len) {
}
case MSG_CONFIRM_CARDS: {
/*int player = */mainGame->LocalPlayer(BufferIO::ReadUInt8(pbuf));
int skip_panel = BufferIO::ReadUInt8(pbuf);
int count = BufferIO::ReadUInt8(pbuf);
int c, s;
unsigned int code, l;
......@@ -2447,7 +2467,7 @@ bool DuelClient::ClientAnalyze(unsigned char* msg, int len) {
}
mainGame->WaitFrameSignal(5);
}
if (panel_confirm.size() && mainGame->dInfo.player_type != 7 && !auto_watch_mode) {
if (!skip_panel && panel_confirm.size() && mainGame->dInfo.player_type != 7 && !auto_watch_mode) {
std::sort(panel_confirm.begin(), panel_confirm.end(), ClientCard::client_card_sort);
mainGame->gMutex.lock();
mainGame->dField.selectable_cards = panel_confirm;
......
......@@ -382,9 +382,9 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
select_options_index.clear();
for (size_t i = 0; i < activatable_cards.size(); ++i) {
if (activatable_cards[i] == menu_card) {
if(activatable_descs[i].second == EDESC_OPERATION)
if(activatable_descs[i].second & EDESC_OPERATION)
continue;
else if(activatable_descs[i].second == EDESC_RESET) {
else if(activatable_descs[i].second & EDESC_RESET) {
if(id == BUTTON_CMD_ACTIVATE) continue;
} else {
if(id == BUTTON_CMD_RESET) continue;
......@@ -673,7 +673,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
select_options_index.clear();
for (size_t i = 0; i < activatable_cards.size(); ++i) {
if (activatable_cards[i] == command_card) {
if(activatable_descs[i].second == EDESC_OPERATION) {
if(activatable_descs[i].second & EDESC_OPERATION) {
if(list_command == COMMAND_ACTIVATE) continue;
} else {
if(list_command == COMMAND_OPERATION) continue;
......
......@@ -348,6 +348,15 @@ void NetServer::HandleCTOSPacket(DuelPlayer* dp, unsigned char* data, int len) {
BufferIO::CopyCharArray(pkt->name, dp->name);
break;
}
case CTOS_EXTERNAL_ADDRESS: {
// for other server & reverse proxy use only
/*
wchar_t hostname[LEN_HOSTNAME];
uint32_t real_ip = ntohl(BufferIO::ReadInt32(pdata));
BufferIO::CopyCharArray((uint16_t*)pdata, hostname);
*/
break;
}
case CTOS_CREATE_GAME: {
if(dp->game || duel_mode)
return;
......
......@@ -103,6 +103,14 @@ struct CTOS_Kick {
check_trivially_copyable(CTOS_Kick);
static_assert(sizeof(CTOS_Kick) == 1, "size mismatch: CTOS_Kick");
/*
* CTOS_ExternalAddress
* uint32_t real_ip; (IPv4 address, BE, alway 0 in normal client)
* uint16_t hostname[256]; (UTF-16 string)
*/
constexpr int LEN_HOSTNAME = 256;
// STOC
struct STOC_ErrorMsg {
uint8_t msg{};
......@@ -265,6 +273,7 @@ public:
#define CTOS_SURRENDER 0x14 // no data
#define CTOS_TIME_CONFIRM 0x15 // no data
#define CTOS_CHAT 0x16 // uint16_t array
#define CTOS_EXTERNAL_ADDRESS 0x17 // CTOS_ExternalAddress
#define CTOS_HS_TODUELIST 0x20 // no data
#define CTOS_HS_TOOBSERVER 0x21 // no data
#define CTOS_HS_READY 0x22 // no data
......
......@@ -169,7 +169,7 @@ bool Replay::OpenReplay(const wchar_t* name) {
std::fclose(rfp);
return false;
}
if (pheader.base.id == REPLAY_ID_YRP2 && std::fread((uint8_t*)(&pheader) + sizeof pheader.base, sizeof pheader - sizeof pheader.base, 1, rfp) < 1) {
if (pheader.base.id == REPLAY_ID_YRP2 && std::fread(reinterpret_cast<unsigned char*>(&pheader) + sizeof pheader.base, sizeof pheader - sizeof pheader.base, 1, rfp) < 1) {
std::fclose(rfp);
return false;
}
......
......@@ -432,7 +432,7 @@ bool ReplayMode::ReplayAnalyze(unsigned char* msg, unsigned int len) {
case MSG_SELECT_CHAIN: {
player = BufferIO::ReadUInt8(pbuf);
count = BufferIO::ReadUInt8(pbuf);
pbuf += 10 + count * 13;
pbuf += 9 + count * 14;
return ReadReplayResponse();
}
case MSG_SELECT_PLACE:
......@@ -485,6 +485,7 @@ bool ReplayMode::ReplayAnalyze(unsigned char* msg, unsigned int len) {
}
case MSG_CONFIRM_CARDS: {
player = BufferIO::ReadUInt8(pbuf);
pbuf += 1;
count = BufferIO::ReadUInt8(pbuf);
pbuf += count * 7;
DuelClient::ClientAnalyze(offset, pbuf - offset);
......
......@@ -1025,7 +1025,7 @@ int SingleDuel::Analyze(unsigned char* msgbuffer, unsigned int len) {
case MSG_SELECT_CHAIN: {
player = BufferIO::ReadUInt8(pbuf);
count = BufferIO::ReadUInt8(pbuf);
pbuf += 10 + count * 13;
pbuf += 9 + count * 14;
WaitforResponse(player);
NetServer::SendBufferToPlayer(players[player], STOC_GAME_MSG, offset, pbuf - offset);
return 1;
......@@ -1102,6 +1102,7 @@ int SingleDuel::Analyze(unsigned char* msgbuffer, unsigned int len) {
}
case MSG_CONFIRM_CARDS: {
player = BufferIO::ReadUInt8(pbuf);
pbuf += 1;
count = BufferIO::ReadUInt8(pbuf);
if(pbuf[5] != LOCATION_DECK) {
pbuf += count * 7;
......
......@@ -316,7 +316,7 @@ bool SingleMode::SinglePlayAnalyze(unsigned char* msg, unsigned int len) {
case MSG_SELECT_CHAIN: {
player = BufferIO::ReadUInt8(pbuf);
count = BufferIO::ReadUInt8(pbuf);
pbuf += 10 + count * 13;
pbuf += 9 + count * 14;
if(!DuelClient::ClientAnalyze(offset, pbuf - offset)) {
mainGame->singleSignal.Reset();
mainGame->singleSignal.Wait();
......@@ -393,6 +393,7 @@ bool SingleMode::SinglePlayAnalyze(unsigned char* msg, unsigned int len) {
}
case MSG_CONFIRM_CARDS: {
player = BufferIO::ReadUInt8(pbuf);
pbuf += 1;
count = BufferIO::ReadUInt8(pbuf);
pbuf += count * 7;
DuelClient::ClientAnalyze(offset, pbuf - offset);
......
......@@ -966,7 +966,7 @@ int TagDuel::Analyze(unsigned char* msgbuffer, unsigned int len) {
case MSG_SELECT_CHAIN: {
player = BufferIO::ReadUInt8(pbuf);
count = BufferIO::ReadUInt8(pbuf);
pbuf += 10 + count * 13;
pbuf += 9 + count * 14;
WaitforResponse(player);
NetServer::SendBufferToPlayer(cur_player[player], STOC_GAME_MSG, offset, pbuf - offset);
return 1;
......@@ -1047,6 +1047,7 @@ int TagDuel::Analyze(unsigned char* msgbuffer, unsigned int len) {
}
case MSG_CONFIRM_CARDS: {
player = BufferIO::ReadUInt8(pbuf);
pbuf += 1;
count = BufferIO::ReadUInt8(pbuf);
if(pbuf[5] != LOCATION_DECK) {
pbuf += count * 7;
......
Subproject commit 62d35dd317fbbbd72d1eda3b19573ccb68ba60a6
Subproject commit dc4501aee33d83cc4849f0e49f2efde02e7dff0e
Subproject commit 46668054cffa8566fa5f97312fd9c087f06854c0
Subproject commit e7feeaa304fcf9c7fc23dfcbc68276be09c5e2ef
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