Commit a65a474b authored by nanahira's avatar nanahira

patches

parent 02e1ddae
Pipeline #38141 failed with stages
in 3 minutes and 50 seconds
...@@ -179,8 +179,6 @@ void DataManager::ReadStringConfLine(const char* linebuf) { ...@@ -179,8 +179,6 @@ void DataManager::ReadStringConfLine(const char* linebuf) {
} }
} }
bool DataManager::LoadServerList(const char* file) { bool DataManager::LoadServerList(const char* file) {
if (_serverStrings.empty())
_serverStrings.emplace_back(GetSysString(1304), L"");
FILE* fp = myfopen(file, "r"); FILE* fp = myfopen(file, "r");
if(!fp) if(!fp)
return false; return false;
...@@ -192,8 +190,6 @@ bool DataManager::LoadServerList(const char* file) { ...@@ -192,8 +190,6 @@ bool DataManager::LoadServerList(const char* file) {
return true; return true;
} }
bool DataManager::LoadServerList(const wchar_t* file) { bool DataManager::LoadServerList(const wchar_t* file) {
if (_serverStrings.empty())
_serverStrings.emplace_back(GetSysString(1304), L"");
FILE* fp = mywfopen(file, "r"); FILE* fp = mywfopen(file, "r");
if(!fp) if(!fp)
return false; return false;
...@@ -205,8 +201,6 @@ bool DataManager::LoadServerList(const wchar_t* file) { ...@@ -205,8 +201,6 @@ bool DataManager::LoadServerList(const wchar_t* file) {
return true; return true;
} }
bool DataManager::LoadServerList(irr::io::IReadFile* reader) { bool DataManager::LoadServerList(irr::io::IReadFile* reader) {
if (_serverStrings.empty())
_serverStrings.emplace_back(GetSysString(1304), L"");
char ch{}; char ch{};
std::string linebuf; std::string linebuf;
while (reader->read(&ch, 1)) { while (reader->read(&ch, 1)) {
...@@ -222,52 +216,59 @@ bool DataManager::LoadServerList(irr::io::IReadFile* reader) { ...@@ -222,52 +216,59 @@ bool DataManager::LoadServerList(irr::io::IReadFile* reader) {
return true; return true;
} }
void DataManager::ReadServerConfLine(const char* linebuf) { void DataManager::ReadServerConfLine(const char* linebuf) {
char* buffer = const_cast<char*>(linebuf); char buffer[1024];
std::strncpy(buffer, linebuf, sizeof(buffer) - 1);
buffer[sizeof(buffer) - 1] = '\0';
buffer[strcspn(buffer, "\n")] = '\0'; buffer[strcspn(buffer, "\n")] = '\0';
char* separator = strchr(buffer, '|');
if (separator != nullptr) { char* sep1 = std::strchr(buffer, '|');
*separator = '\0'; if (sep1 != nullptr) {
std::wstring name, ip; *sep1 = '\0';
wchar_t wname[256], wip[256]; char* addrPart = sep1 + 1;
if (mbstowcs(wname, buffer, 256) != (size_t)-1 && mbstowcs(wip, separator + 1, 256) != (size_t)-1) {
ip = wip;
name = wname; wchar_t wname[256], wip[512];
// read the server name
BufferIO::DecodeUTF8(buffer, wname);
// replace the first '|' with ':'
char* sep2 = std::strchr(addrPart, '|');
if (sep2) {
*sep2 = ':';
} }
auto it = std::find_if(_serverStrings.begin(), _serverStrings.end(),
[name](const auto& pair) { return pair.first == name; }
);
if (it != _serverStrings.end()) BufferIO::DecodeUTF8(addrPart, wip);
it->second = ip;
else _serverStrings.emplace_back(wname, wip);
_serverStrings.emplace_back(name, ip);
} }
} }
bool DataManager::LoadINI(const char* file) { bool DataManager::LoadCorresSrvIni(const char* file) {
FILE* fp = myfopen(file, "r"); FILE* fp = myfopen(file, "r");
if(!fp) if(!fp)
return false; return false;
char linebuf[TEXT_LINE_SIZE]{}; char linebuf[TEXT_LINE_SIZE]{};
while(std::fgets(linebuf, sizeof linebuf, fp)) { while(std::fgets(linebuf, sizeof linebuf, fp)) {
ReadINI(linebuf); ReadCorresSrvIniLine(linebuf);
} }
std::fclose(fp); std::fclose(fp);
InsertServerList(); InsertServerList();
return true; return true;
} }
bool DataManager::LoadINI(const wchar_t* file) { bool DataManager::LoadCorresSrvIni(const wchar_t* file) {
FILE* fp = mywfopen(file, "r"); FILE* fp = mywfopen(file, "r");
if(!fp) if(!fp)
return false; return false;
char linebuf[TEXT_LINE_SIZE]{}; char linebuf[TEXT_LINE_SIZE]{};
while(std::fgets(linebuf, sizeof linebuf, fp)) { while(std::fgets(linebuf, sizeof linebuf, fp)) {
ReadINI(linebuf); ReadCorresSrvIniLine(linebuf);
} }
std::fclose(fp); std::fclose(fp);
InsertServerList(); InsertServerList();
return true; return true;
} }
bool DataManager::LoadINI(irr::io::IReadFile* reader) { bool DataManager::LoadCorresSrvIni(irr::io::IReadFile* reader) {
char ch{}; char ch{};
std::string linebuf; std::string linebuf;
while (reader->read(&ch, 1)) { while (reader->read(&ch, 1)) {
...@@ -275,7 +276,7 @@ bool DataManager::LoadINI(irr::io::IReadFile* reader) { ...@@ -275,7 +276,7 @@ bool DataManager::LoadINI(irr::io::IReadFile* reader) {
break; break;
linebuf.push_back(ch); linebuf.push_back(ch);
if (ch == '\n' || linebuf.size() >= TEXT_LINE_SIZE - 1) { if (ch == '\n' || linebuf.size() >= TEXT_LINE_SIZE - 1) {
ReadINI(linebuf.data()); ReadCorresSrvIniLine(linebuf.data());
linebuf.clear(); linebuf.clear();
} }
} }
...@@ -283,7 +284,7 @@ bool DataManager::LoadINI(irr::io::IReadFile* reader) { ...@@ -283,7 +284,7 @@ bool DataManager::LoadINI(irr::io::IReadFile* reader) {
InsertServerList(); InsertServerList();
return true; return true;
} }
void DataManager::ReadINI(const char* linebuf) { void DataManager::ReadCorresSrvIniLine(const char* linebuf) {
std::wstring name = GetINIValue(linebuf, "ServerName = "); std::wstring name = GetINIValue(linebuf, "ServerName = ");
std::wstring host = GetINIValue(linebuf, "ServerHost = "); std::wstring host = GetINIValue(linebuf, "ServerHost = ");
std::wstring port = GetINIValue(linebuf, "ServerPort = "); std::wstring port = GetINIValue(linebuf, "ServerPort = ");
...@@ -295,48 +296,36 @@ void DataManager::ReadINI(const char* linebuf) { ...@@ -295,48 +296,36 @@ void DataManager::ReadINI(const char* linebuf) {
iniPort = port; iniPort = port;
} }
std::wstring DataManager::GetINIValue(const char* line, const char* key) { std::wstring DataManager::GetINIValue(const char* line, const char* key) {
if (!line || !key) { if (!line || !key) {
return L""; return L"";
} }
const char* keyPos = strstr(line, key); const char* keyPos = strstr(line, key);
if (!keyPos) { if (!keyPos) {
return L""; return L"";
} }
const char* valStart = keyPos + strlen(key); const char* valStart = keyPos + strlen(key);
while (*valStart == ' ') while (*valStart == ' ')
valStart++; valStart++;
const char* valEnd = valStart; const char* valEnd = valStart;
while (*valEnd && *valEnd != '\n' && *valEnd != '\r') while (*valEnd && *valEnd != '\n' && *valEnd != '\r')
valEnd++; valEnd++;
if (valStart == valEnd) if (valStart == valEnd)
return L""; return L"";
std::string narrowStr(valStart, valEnd); std::string narrowStr(valStart, valEnd);
if (narrowStr.empty()) if (narrowStr.empty())
return L""; return L"";
size_t requiredSize = mbstowcs(nullptr, narrowStr.c_str(), 0); wchar_t wbuf[1024];
if (requiredSize == (size_t)-1) BufferIO::DecodeUTF8(narrowStr.c_str(), wbuf);
return L""; return wbuf;
std::wstring wideStr(requiredSize + 1, L'\0');
mbstowcs(&wideStr[0], narrowStr.c_str(), requiredSize + 1);
wideStr.resize(requiredSize);
return wideStr;
} }
void DataManager::InsertServerList() { void DataManager::InsertServerList() {
if (iniName != L"" && iniHost != L"") { if (iniName != L"" && iniHost != L"") {
std::wstring ip = iniHost; std::wstring ip = iniHost;
std::wstring name = iniName;
if (iniPort != L"") { if (iniPort != L"") {
ip += L":"; ip += L":";
ip += iniPort; ip += iniPort;
} }
auto it = std::find_if(_serverStrings.begin(), _serverStrings.end(), _serverStrings.emplace_back(iniName, ip);
[name](const auto& pair) { return pair.first == name; }
);
if (it != _serverStrings.end())
it->second = ip;
else
_serverStrings.emplace_back(name, ip);
} }
iniName.clear(); iniName.clear();
iniHost.clear(); iniHost.clear();
......
...@@ -54,10 +54,10 @@ public: ...@@ -54,10 +54,10 @@ public:
bool LoadServerList(const wchar_t* file); bool LoadServerList(const wchar_t* file);
bool LoadServerList(irr::io::IReadFile* reader); bool LoadServerList(irr::io::IReadFile* reader);
void ReadServerConfLine(const char* linebuf); void ReadServerConfLine(const char* linebuf);
bool LoadINI(const char* file); bool LoadCorresSrvIni(const char* file);
bool LoadINI(const wchar_t* file); bool LoadCorresSrvIni(const wchar_t* file);
bool LoadINI(irr::io::IReadFile* reader); bool LoadCorresSrvIni(irr::io::IReadFile* reader);
void ReadINI(const char* linebuf); void ReadCorresSrvIniLine(const char* linebuf);
std::wstring GetINIValue(const char* line, const char* key); std::wstring GetINIValue(const char* line, const char* key);
void InsertServerList(); void InsertServerList();
bool Error(sqlite3* pDB, sqlite3_stmt* pStmt = nullptr); bool Error(sqlite3* pDB, sqlite3_stmt* pStmt = nullptr);
......
...@@ -622,6 +622,7 @@ void DuelClient::HandleSTOCPacketLan(unsigned char* data, int len) { ...@@ -622,6 +622,7 @@ void DuelClient::HandleSTOCPacketLan(unsigned char* data, int len) {
mainGame->cbDeckSelect->setEnabled(true); mainGame->cbDeckSelect->setEnabled(true);
mainGame->HideElement(mainGame->wCreateHost); mainGame->HideElement(mainGame->wCreateHost);
mainGame->HideElement(mainGame->wLanWindow); mainGame->HideElement(mainGame->wLanWindow);
mainGame->HideElement(mainGame->wServerList);
mainGame->HideElement(mainGame->wSinglePlay); mainGame->HideElement(mainGame->wSinglePlay);
mainGame->ShowElement(mainGame->wHostPrepare); mainGame->ShowElement(mainGame->wHostPrepare);
mainGame->ResizeChatInputWindow(); mainGame->ResizeChatInputWindow();
......
...@@ -124,7 +124,7 @@ bool Game::Initialize() { ...@@ -124,7 +124,7 @@ bool Game::Initialize() {
ErrorLog("Failed to load strings!"); ErrorLog("Failed to load strings!");
return false; return false;
} }
dataManager.LoadServerList(GetLocaleDir("server.conf")); dataManager.LoadServerList(GetLocaleDir("servers.conf"));
dataManager.LoadDB(L"specials/special.cdb"); dataManager.LoadDB(L"specials/special.cdb");
env = device->getGUIEnvironment(); env = device->getGUIEnvironment();
numFont = irr::gui::CGUITTFont::createTTFont(env, gameConf.numfont, 16); numFont = irr::gui::CGUITTFont::createTTFont(env, gameConf.numfont, 16);
...@@ -236,8 +236,8 @@ bool Game::Initialize() { ...@@ -236,8 +236,8 @@ bool Game::Initialize() {
editbox_list.push_back(ebNickName); editbox_list.push_back(ebNickName);
lstHostList = env->addListBox(irr::core::rect<irr::s32>(10, 60, 570, 320), wLanWindow, LISTBOX_LAN_HOST, true); lstHostList = env->addListBox(irr::core::rect<irr::s32>(10, 60, 570, 320), wLanWindow, LISTBOX_LAN_HOST, true);
lstHostList->setItemHeight(18); lstHostList->setItemHeight(18);
btnLanRefresh = env->addButton(irr::core::rect<irr::s32>(170, 325, 270, 350), wLanWindow, BUTTON_LAN_REFRESH, dataManager.GetSysString(1217)); btnLanRefresh = env->addButton(irr::core::rect<irr::s32>(150, 325, 250, 350), wLanWindow, BUTTON_LAN_REFRESH, dataManager.GetSysString(1217));
btnServerList = env->addButton(irr::core::rect<irr::s32>(310, 325, 410, 350), wLanWindow, BUTTON_SERVER_LIST, dataManager.GetSysString(1239)); btnServerList = env->addButton(irr::core::rect<irr::s32>(280, 325, 380, 350), wLanWindow, BUTTON_SERVER_LIST, dataManager.GetSysString(1239));
env->addStaticText(dataManager.GetSysString(1221), irr::core::rect<irr::s32>(10, 360, 220, 380), false, false, wLanWindow); env->addStaticText(dataManager.GetSysString(1221), irr::core::rect<irr::s32>(10, 360, 220, 380), false, false, wLanWindow);
ebJoinHost = env->addEditBox(gameConf.lasthost, irr::core::rect<irr::s32>(110, 355, 420, 380), true, wLanWindow); ebJoinHost = env->addEditBox(gameConf.lasthost, irr::core::rect<irr::s32>(110, 355, 420, 380), true, wLanWindow);
ebJoinHost->setTextAlignment(irr::gui::EGUIA_CENTER, irr::gui::EGUIA_CENTER); ebJoinHost->setTextAlignment(irr::gui::EGUIA_CENTER, irr::gui::EGUIA_CENTER);
...@@ -369,8 +369,7 @@ bool Game::Initialize() { ...@@ -369,8 +369,7 @@ bool Game::Initialize() {
lstServerList = env->addListBox(irr::core::rect<irr::s32>(10, 20, 290, 270), wServerList, LISTBOX_SERVER_LIST, true); lstServerList = env->addListBox(irr::core::rect<irr::s32>(10, 20, 290, 270), wServerList, LISTBOX_SERVER_LIST, true);
lstServerList->setItemHeight(18); lstServerList->setItemHeight(18);
RefreshServerList(); RefreshServerList();
btnServerSelected = env->addButton(irr::core::rect<irr::s32>(30, 280, 130, 310), wServerList, BUTTON_SERVER_SELECTED, dataManager.GetSysString(1211)); btnServerReturn = env->addButton(irr::core::rect<irr::s32>(100, 280, 200, 310), wServerList, BUTTON_SERVER_RETURN, dataManager.GetSysString(1210));
btnServerCancel = env->addButton(irr::core::rect<irr::s32>(170, 280, 270, 310), wServerList, BUTTON_SERVER_CANCEL, dataManager.GetSysString(1212));
//img //img
wCardImg = env->addStaticText(L"", irr::core::rect<irr::s32>(1, 1, 1 + CARD_IMG_WIDTH + 20, 1 + CARD_IMG_HEIGHT + 18), true, false, 0, -1, true); wCardImg = env->addStaticText(L"", irr::core::rect<irr::s32>(1, 1, 1 + CARD_IMG_WIDTH + 20, 1 + CARD_IMG_HEIGHT + 18), true, false, 0, -1, true);
wCardImg->setBackgroundColor(0xc0c0c0c0); wCardImg->setBackgroundColor(0xc0c0c0c0);
...@@ -1258,7 +1257,7 @@ void Game::LoadExpansions(const wchar_t* expansions_path) { ...@@ -1258,7 +1257,7 @@ void Game::LoadExpansions(const wchar_t* expansions_path) {
if(!std::wcscmp(name, L"lflist.conf")) { if(!std::wcscmp(name, L"lflist.conf")) {
deckManager.LoadLFListSingle(fpath, true); deckManager.LoadLFListSingle(fpath, true);
lflist_changed = true; lflist_changed = true;
} else if(!std::wcscmp(name, L"server.conf")) { } else if(!std::wcscmp(name, L"servers.conf")) {
dataManager.LoadServerList(fpath); dataManager.LoadServerList(fpath);
server_list_changed = true; server_list_changed = true;
} else { } else {
...@@ -1266,9 +1265,10 @@ void Game::LoadExpansions(const wchar_t* expansions_path) { ...@@ -1266,9 +1265,10 @@ void Game::LoadExpansions(const wchar_t* expansions_path) {
} }
return; return;
} }
if (IsExtension(name, L".ini")) { if (!std::wcscmp(name, L"corres_srv.ini")) {
dataManager.LoadINI(fpath); dataManager.LoadCorresSrvIni(fpath);
server_list_changed = true; server_list_changed = true;
return;
} }
if (IsExtension(name, L".zip") || IsExtension(name, L".ypk")) { if (IsExtension(name, L".zip") || IsExtension(name, L".ypk")) {
#ifdef _WIN32 #ifdef _WIN32
...@@ -1308,7 +1308,7 @@ void Game::LoadExpansions(const wchar_t* expansions_path) { ...@@ -1308,7 +1308,7 @@ void Game::LoadExpansions(const wchar_t* expansions_path) {
if(!std::wcscmp(fname, L"lflist.conf")) { if(!std::wcscmp(fname, L"lflist.conf")) {
deckManager.LoadLFListSingle(reader, true); deckManager.LoadLFListSingle(reader, true);
lflist_changed = true; lflist_changed = true;
} else if(!std::wcscmp(fname, L"server.conf")) { } else if(!std::wcscmp(fname, L"servers.conf")) {
dataManager.LoadServerList(reader); dataManager.LoadServerList(reader);
server_list_changed = true; server_list_changed = true;
} else { } else {
...@@ -1316,8 +1316,8 @@ void Game::LoadExpansions(const wchar_t* expansions_path) { ...@@ -1316,8 +1316,8 @@ void Game::LoadExpansions(const wchar_t* expansions_path) {
} }
continue; continue;
} }
if (IsExtension(fname, L".ini")) { if (!std::wcscmp(fname, L"corres_srv.ini")) {
dataManager.LoadINI(createReader()); dataManager.LoadCorresSrvIni(createReader());
server_list_changed = true; server_list_changed = true;
} }
if (!mywcsncasecmp(fname, L"pack/", 5) && IsExtension(fname, L".ydk")) { if (!mywcsncasecmp(fname, L"pack/", 5) && IsExtension(fname, L".ydk")) {
......
...@@ -698,8 +698,7 @@ public: ...@@ -698,8 +698,7 @@ public:
irr::gui::IGUIButton* btnServerList; irr::gui::IGUIButton* btnServerList;
irr::gui::IGUIWindow* wServerList; irr::gui::IGUIWindow* wServerList;
irr::gui::IGUIListBox* lstServerList; irr::gui::IGUIListBox* lstServerList;
irr::gui::IGUIButton* btnServerSelected; irr::gui::IGUIButton* btnServerReturn;
irr::gui::IGUIButton* btnServerCancel;
}; };
extern Game* mainGame; extern Game* mainGame;
...@@ -929,8 +928,7 @@ extern Game* mainGame; ...@@ -929,8 +928,7 @@ extern Game* mainGame;
#define BUTTON_SERVER_LIST 392 #define BUTTON_SERVER_LIST 392
#define LISTBOX_SERVER_LIST 393 #define LISTBOX_SERVER_LIST 393
#define BUTTON_SERVER_SELECTED 394 #define BUTTON_SERVER_RETURN 394
#define BUTTON_SERVER_CANCEL 395
#define TEXTURE_DUEL 0 #define TEXTURE_DUEL 0
#define TEXTURE_DECK 1 #define TEXTURE_DECK 1
......
...@@ -90,8 +90,8 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) { ...@@ -90,8 +90,8 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
break; break;
} }
case BUTTON_JOIN_CANCEL: { case BUTTON_JOIN_CANCEL: {
mainGame->HideElement(mainGame->wServerList);
mainGame->HideElement(mainGame->wLanWindow); mainGame->HideElement(mainGame->wLanWindow);
mainGame->HideElement(mainGame->wServerList);
mainGame->ShowElement(mainGame->wMainMenu); mainGame->ShowElement(mainGame->wMainMenu);
if(exit_on_return) if(exit_on_return)
mainGame->device->closeDevice(); mainGame->device->closeDevice();
...@@ -105,6 +105,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) { ...@@ -105,6 +105,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
mainGame->btnHostConfirm->setEnabled(true); mainGame->btnHostConfirm->setEnabled(true);
mainGame->btnHostCancel->setEnabled(true); mainGame->btnHostCancel->setEnabled(true);
mainGame->HideElement(mainGame->wLanWindow); mainGame->HideElement(mainGame->wLanWindow);
mainGame->HideElement(mainGame->wServerList);
mainGame->ShowElement(mainGame->wCreateHost); mainGame->ShowElement(mainGame->wCreateHost);
break; break;
} }
...@@ -490,16 +491,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) { ...@@ -490,16 +491,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
mainGame->PopupElement(mainGame->wServerList); mainGame->PopupElement(mainGame->wServerList);
break; break;
} }
case BUTTON_SERVER_SELECTED: { case BUTTON_SERVER_RETURN: {
int sel = mainGame->lstServerList->getSelected();
wcscpy(mainGame->gameConf.lasthost, sel == -1 ? L"" : dataManager._serverStrings[sel].second.c_str());
wchar_t buf[256];
myswprintf(buf, L"%s", mainGame->gameConf.lasthost);
mainGame->ebJoinHost->setText(buf);
mainGame->HideElement(mainGame->wServerList);
break;
}
case BUTTON_SERVER_CANCEL: {
mainGame->HideElement(mainGame->wServerList); mainGame->HideElement(mainGame->wServerList);
break; break;
} }
...@@ -614,6 +606,13 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) { ...@@ -614,6 +606,13 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
mainGame->cbBotDeck->setVisible(mainGame->botInfo[sel].select_deckfile); mainGame->cbBotDeck->setVisible(mainGame->botInfo[sel].select_deckfile);
break; break;
} }
case LISTBOX_SERVER_LIST: {
int sel = mainGame->lstServerList->getSelected();
auto target = sel == -1 ? L"" : dataManager._serverStrings[sel].second.c_str();
wcscpy(mainGame->gameConf.lasthost, target);
mainGame->ebJoinHost->setText(target);
break;
}
} }
break; break;
} }
......
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