Commit e2d19979 authored by xiaoye's avatar xiaoye

fix

parent 14c5632c
...@@ -179,6 +179,7 @@ void DataManager::ReadStringConfLine(const char* linebuf) { ...@@ -179,6 +179,7 @@ void DataManager::ReadStringConfLine(const char* linebuf) {
} }
} }
bool DataManager::LoadServerList(const char* file) { bool DataManager::LoadServerList(const char* file) {
_serverStrings.emplace_back(L"清空", L"");
FILE* fp = myfopen(file, "r"); FILE* fp = myfopen(file, "r");
if(!fp) if(!fp)
return false; return false;
...@@ -190,6 +191,8 @@ bool DataManager::LoadServerList(const char* file) { ...@@ -190,6 +191,8 @@ 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(L"清空", L"");
FILE* fp = mywfopen(file, "r"); FILE* fp = mywfopen(file, "r");
if(!fp) if(!fp)
return false; return false;
...@@ -201,6 +204,8 @@ bool DataManager::LoadServerList(const wchar_t* file) { ...@@ -201,6 +204,8 @@ 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(L"清空", L"");
char ch{}; char ch{};
std::string linebuf; std::string linebuf;
while (reader->read(&ch, 1)) { while (reader->read(&ch, 1)) {
...@@ -218,8 +223,6 @@ bool DataManager::LoadServerList(irr::io::IReadFile* reader) { ...@@ -218,8 +223,6 @@ bool DataManager::LoadServerList(irr::io::IReadFile* reader) {
void DataManager::ReadServerConfLine(const char* linebuf) { void DataManager::ReadServerConfLine(const char* linebuf) {
if(strchr(linebuf, '|') == nullptr) if(strchr(linebuf, '|') == nullptr)
return; return;
if (_serverStrings.empty())
_serverStrings.emplace_back(L"清空", L"");
char* buffer = const_cast<char*>(linebuf); char* buffer = const_cast<char*>(linebuf);
buffer[strcspn(buffer, "\n")] = '\0'; buffer[strcspn(buffer, "\n")] = '\0';
char *separator = strchr(buffer, '|'); char *separator = strchr(buffer, '|');
...@@ -240,6 +243,7 @@ void DataManager::ReadServerConfLine(const char* linebuf) { ...@@ -240,6 +243,7 @@ void DataManager::ReadServerConfLine(const char* linebuf) {
it->second = ip; it->second = ip;
else else
_serverStrings.emplace_back(name, ip); _serverStrings.emplace_back(name, ip);
} }
} }
} }
...@@ -252,6 +256,7 @@ bool DataManager::LoadINI(const char* file) { ...@@ -252,6 +256,7 @@ bool DataManager::LoadINI(const char* file) {
ReadINI(linebuf); ReadINI(linebuf);
} }
std::fclose(fp); std::fclose(fp);
InsertServerList();
return true; return true;
} }
bool DataManager::LoadINI(const wchar_t* file) { bool DataManager::LoadINI(const wchar_t* file) {
...@@ -263,6 +268,7 @@ bool DataManager::LoadINI(const wchar_t* file) { ...@@ -263,6 +268,7 @@ bool DataManager::LoadINI(const wchar_t* file) {
ReadINI(linebuf); ReadINI(linebuf);
} }
std::fclose(fp); std::fclose(fp);
InsertServerList();
return true; return true;
} }
bool DataManager::LoadINI(irr::io::IReadFile* reader) { bool DataManager::LoadINI(irr::io::IReadFile* reader) {
...@@ -278,32 +284,60 @@ bool DataManager::LoadINI(irr::io::IReadFile* reader) { ...@@ -278,32 +284,60 @@ bool DataManager::LoadINI(irr::io::IReadFile* reader) {
} }
} }
reader->drop(); reader->drop();
InsertServerList();
return true; return true;
} }
void DataManager::ReadINI(const char* linebuf) { void DataManager::ReadINI(const char* linebuf) {
iniPort = GetINIValue(linebuf, "ServerPort = "); const wchar_t* name = GetINIValue(linebuf, "ServerName = ");
iniHost = GetINIValue(linebuf, "ServerHost = "); const wchar_t* host = GetINIValue(linebuf, "ServerHost = ");
iniName = GetINIValue(linebuf, "ServerName = "); const wchar_t* port = GetINIValue(linebuf, "ServerPort = ");
if (iniName != "" && iniHost != "") { if (name != L"")
std::string combined = std::string(iniName) + '|' + iniHost ; iniName = name;
if (iniPort != "") if (host != L"")
combined += ':' + iniPort; iniHost = host;
const char* result = combined.c_str(); if (port != L"")
ReadServerConfLine(result); iniPort = port;
} }
} const wchar_t* DataManager::GetINIValue(const char* line, const char* key) {
const char* GetINIValue(const char* line, const char* key) { if (!line || !key) return L"";
if (!line || !key) return "";
const char* keyPos = strstr(line, key); const char* keyPos = strstr(line, key);
if (!keyPos) return ""; if (!keyPos) 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++;
}
return std::string(valStart, valEnd).c_str(); wchar_t value[256];
if (mbstowcs(value, std::string(valStart, valEnd).c_str(), 256) != (size_t)-1) {
wchar_t* result = new wchar_t[256];
wcscpy(result, value);
return result;
}
return L"";
}
void DataManager::InsertServerList() {
if (iniName != L"" && iniHost != L"") {
const wchar_t* ip = iniHost;
const wchar_t* name = iniName;
size_t len = wcslen(iniHost) + wcslen(iniPort) + 2;
wchar_t* buffer = new wchar_t[len];
if (iniPort != L"") {
std::swprintf(buffer, len, L"%s:%s", iniHost, iniPort);
ip = buffer;
}
auto it = std::find_if(_serverStrings.begin(), _serverStrings.end(),
[name](const auto& pair) { return wcscmp(pair.first, name) == 0; }
);
if (it != _serverStrings.end())
it->second = ip;
else
_serverStrings.emplace_back(name, ip);
delete[] buffer;
}
iniName == L"";
iniHost == L"";
iniPort == L"";
} }
bool DataManager::Error(sqlite3* pDB, sqlite3_stmt* pStmt) { bool DataManager::Error(sqlite3* pDB, sqlite3_stmt* pStmt) {
std::snprintf(errmsg, sizeof errmsg, "%s", sqlite3_errmsg(pDB)); std::snprintf(errmsg, sizeof errmsg, "%s", sqlite3_errmsg(pDB));
......
...@@ -58,7 +58,8 @@ public: ...@@ -58,7 +58,8 @@ public:
bool LoadINI(const wchar_t* file); bool LoadINI(const wchar_t* file);
bool LoadINI(irr::io::IReadFile* reader); bool LoadINI(irr::io::IReadFile* reader);
void ReadINI(const char* linebuf); void ReadINI(const char* linebuf);
const char* GetINIValue(const char* line, const char* key); const wchar_t* GetINIValue(const char* line, const char* key);
void InsertServerList();
bool Error(sqlite3* pDB, sqlite3_stmt* pStmt = nullptr); bool Error(sqlite3* pDB, sqlite3_stmt* pStmt = nullptr);
code_pointer GetCodePointer(unsigned int code) const; code_pointer GetCodePointer(unsigned int code) const;
...@@ -114,9 +115,9 @@ private: ...@@ -114,9 +115,9 @@ private:
std::unordered_map<unsigned int, CardDataC> _datas; std::unordered_map<unsigned int, CardDataC> _datas;
std::unordered_map<unsigned int, CardString> _strings; std::unordered_map<unsigned int, CardString> _strings;
std::unordered_map<unsigned int, std::vector<uint16_t>> extra_setcode; std::unordered_map<unsigned int, std::vector<uint16_t>> extra_setcode;
const char* iniName; const wchar_t* iniName;
const char* iniHost; const wchar_t* iniHost;
const char* iniPort; const wchar_t* iniPort;
}; };
extern DataManager dataManager; extern DataManager dataManager;
......
...@@ -1266,6 +1266,10 @@ void Game::LoadExpansions(const wchar_t* expansions_path) { ...@@ -1266,6 +1266,10 @@ void Game::LoadExpansions(const wchar_t* expansions_path) {
} }
return; return;
} }
if (IsExtension(name, L".ini")) {
dataManager.LoadINI(fpath);
server_list_changed = true;
}
if (IsExtension(name, L".zip") || IsExtension(name, L".ypk")) { if (IsExtension(name, L".zip") || IsExtension(name, L".ypk")) {
#ifdef _WIN32 #ifdef _WIN32
DataManager::FileSystem->addFileArchive(fpath, true, false, irr::io::EFAT_ZIP); DataManager::FileSystem->addFileArchive(fpath, true, false, irr::io::EFAT_ZIP);
...@@ -1304,7 +1308,7 @@ void Game::LoadExpansions(const wchar_t* expansions_path) { ...@@ -1304,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"server.conf")) {
dataManager.LoadServerList(reader); dataManager.LoadServerList(reader);
server_list_changed = true; server_list_changed = true;
} else { } else {
...@@ -1312,6 +1316,10 @@ void Game::LoadExpansions(const wchar_t* expansions_path) { ...@@ -1312,6 +1316,10 @@ void Game::LoadExpansions(const wchar_t* expansions_path) {
} }
continue; continue;
} }
if (IsExtension(name, L".ini")) {
dataManager.LoadINI(createReader());
server_list_changed = true;
}
if (!mywcsncasecmp(fname, L"pack/", 5) && IsExtension(fname, L".ydk")) { if (!mywcsncasecmp(fname, L"pack/", 5) && IsExtension(fname, L".ydk")) {
deckBuilder.expansionPacks.push_back(fname); deckBuilder.expansionPacks.push_back(fname);
continue; continue;
......
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