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