Commit 14c5632c authored by xiaoye's avatar xiaoye

fix

parent a29afe20
...@@ -243,6 +243,68 @@ void DataManager::ReadServerConfLine(const char* linebuf) { ...@@ -243,6 +243,68 @@ void DataManager::ReadServerConfLine(const char* linebuf) {
} }
} }
} }
bool DataManager::LoadINI(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);
}
std::fclose(fp);
return true;
}
bool DataManager::LoadINI(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);
}
std::fclose(fp);
return true;
}
bool DataManager::LoadINI(irr::io::IReadFile* reader) {
char ch{};
std::string linebuf;
while (reader->read(&ch, 1)) {
if (ch == '\0')
break;
linebuf.push_back(ch);
if (ch == '\n' || linebuf.size() >= TEXT_LINE_SIZE - 1) {
ReadINI(linebuf.data());
linebuf.clear();
}
}
reader->drop();
return true;
}
void DataManager::ReadINI(const char* linebuf) {
iniPort = GetINIValue(linebuf, "ServerPort = ");
iniHost = GetINIValue(linebuf, "ServerHost = ");
iniName = GetINIValue(linebuf, "ServerName = ");
if (iniName != "" && iniHost != "") {
std::string combined = std::string(iniName) + '|' + iniHost ;
if (iniPort != "")
combined += ':' + iniPort;
const char* result = combined.c_str();
ReadServerConfLine(result);
}
}
const char* GetINIValue(const char* line, const char* key) {
if (!line || !key) return "";
const char* keyPos = strstr(line, key);
if (!keyPos) return "";
const char* valStart = keyPos + strlen(key);
while (*valStart == ' ')
valStart++;
const char* valEnd = valStart;
while (*valEnd && *valEnd != '\n' && *valEnd != '\r')
valEnd++;
return std::string(valStart, valEnd).c_str();
}
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));
if(pStmt) if(pStmt)
......
...@@ -54,6 +54,11 @@ public: ...@@ -54,6 +54,11 @@ 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 LoadINI(const wchar_t* file);
bool LoadINI(irr::io::IReadFile* reader);
void ReadINI(const char* linebuf);
const char* GetINIValue(const char* line, const char* key);
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;
...@@ -109,6 +114,9 @@ private: ...@@ -109,6 +114,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 char* iniHost;
const char* iniPort;
}; };
extern DataManager dataManager; extern DataManager dataManager;
......
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