Commit 3f2970fa authored by nanahira's avatar nanahira

Merge branch 'server_subdir' into server

parents f48181e1 e2dd3802
......@@ -71,7 +71,13 @@ bool DataManager::LoadDB(const char* file) {
return true;
}
bool DataManager::LoadStrings(const char* file) {
#ifdef _WIN32
wchar_t fname[1024];
BufferIO::DecodeUTF8(file, fname);
FILE* fp = _wfopen(fname, L"r");
#else
FILE* fp = fopen(file, "r");
#endif // _WIN32
if(!fp)
return false;
char linebuf[256];
......
......@@ -10,7 +10,13 @@ DeckManager deckManager;
void DeckManager::LoadLFListSingle(const char* path) {
LFList* cur = NULL;
#ifdef _WIN32
wchar_t fname[1024];
BufferIO::DecodeUTF8(path, fname);
FILE* fp = _wfopen(fname, L"r");
#else
FILE* fp = fopen(path, "r");
#endif // _WIN32
char linebuf[256];
wchar_t strBuffer[256];
if(fp) {
......@@ -51,6 +57,13 @@ void DeckManager::LoadLFListSingle(const char* path) {
}
void DeckManager::LoadLFList() {
LoadLFListSingle("expansions/lflist.conf");
FileSystem::TraversalDir("./expansions", [this](const char* name, bool isdir) {
if(isdir && strcmp(name, ".") && strcmp(name, "..")) {
char fpath[1024];
sprintf(fpath, "./expansions/%s/lflist.conf", name);
LoadLFListSingle(fpath);
}
});
LoadLFListSingle("lflist.conf");
LFList nolimit;
myswprintf(nolimit.listName, L"N/A");
......
......@@ -56,17 +56,18 @@ void Game::MainTestLoop(int code) {
NetServer::InitTestCard(code);
}
void Game::LoadBetaDB() {
LoadExpansionDBDirectry("./beta");
#ifdef _WIN32
char fpath[1000];
WIN32_FIND_DATAW fdataw;
HANDLE fh = FindFirstFileW(L"./beta/*.cdb", &fdataw);
HANDLE fh = FindFirstFileW(L"./beta/*", &fdataw);
if(fh != INVALID_HANDLE_VALUE) {
do {
if(!(fdataw.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
if(wcscmp(L".",fdataw.cFileName) != 0 && wcscmp(L"..",fdataw.cFileName) != 0 && fdataw.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
char fname[780];
BufferIO::EncodeUTF8(fdataw.cFileName, fname);
sprintf(fpath, "./beta/%s", fname);
dataManager.LoadDB(fpath);
LoadExpansionDBDirectry(fpath);
}
} while(FindNextFileW(fh, &fdataw));
FindClose(fh);
......@@ -76,12 +77,11 @@ void Game::LoadBetaDB() {
struct dirent * dirp;
if((dir = opendir("./beta/")) != NULL) {
while((dirp = readdir(dir)) != NULL) {
size_t len = strlen(dirp->d_name);
if(len < 5 || strcasecmp(dirp->d_name + len - 4, ".cdb") != 0)
if (strcmp(".", dirp->d_name) == 0 || strcmp("..", dirp->d_name) == 0 || dirp->d_type != DT_DIR)
continue;
char filepath[1000];
sprintf(filepath, "./beta/%s", dirp->d_name);
dataManager.LoadDB(filepath);
sprintf(filepath, "./beta/%s/", dirp->d_name);
LoadExpansionDBDirectry(filepath);
}
closedir(dir);
}
......@@ -159,7 +159,7 @@ bool Game::Initialize() {
ErrorLog("Failed to load strings!");
return false;
}
dataManager.LoadStrings("./expansions/strings.conf");
LoadExpansionStrings();
env = device->getGUIEnvironment();
numFont = irr::gui::CGUITTFont::createTTFont(env, gameConf.numfont, 16);
adFont = irr::gui::CGUITTFont::createTTFont(env, gameConf.numfont, 12);
......@@ -1044,15 +1044,35 @@ void Game::SetStaticText(irr::gui::IGUIStaticText* pControl, u32 cWidth, irr::gu
}
#endif //YGOPRO_SERVER_MODE
void Game::LoadExpansionDB() {
FileSystem::TraversalDir("./expansions", [](const char* name, bool isdir) {
LoadExpansionDBDirectry("./expansions");
FileSystem::TraversalDir("./expansions", [this](const char* name, bool isdir) {
if(isdir && strcmp(name, ".") && strcmp(name, "..")) {
char subdir[1024];
sprintf(subdir, "./expansions/%s", name);
LoadExpansionDBDirectry(subdir);
}
});
}
void Game::LoadExpansionDBDirectry(const char* path) {
FileSystem::TraversalDir(path, [path](const char* name, bool isdir) {
if(!isdir && strrchr(name, '.') && !mystrncasecmp(strrchr(name, '.'), ".cdb", 4)) {
char fpath[1024];
sprintf(fpath, "./expansions/%s", name);
sprintf(fpath, "%s/%s", path, name);
dataManager.LoadDB(fpath);
}
});
}
#ifndef YGOPRO_SERVER_MODE
void Game::LoadExpansionStrings() {
dataManager.LoadStrings("./expansions/strings.conf");
FileSystem::TraversalDir("./expansions", [](const char* name, bool isdir) {
if(isdir && strcmp(name, ".") && strcmp(name, "..")) {
char fpath[1024];
sprintf(fpath, "./expansions/%s/strings.conf", name);
dataManager.LoadStrings(fpath);
}
});
}
void Game::RefreshDeck(irr::gui::IGUIComboBox* cbDeck) {
cbDeck->clear();
FileSystem::TraversalDir(L"./deck", [cbDeck](const wchar_t* name, bool isdir) {
......
......@@ -131,6 +131,7 @@ public:
void MainServerLoop();
void MainTestLoop(int code);
void LoadExpansionDB();
void LoadExpansionDBDirectry(const char* path);
void LoadBetaDB();
void AddDebugMsg(const char* msgbuf);
void initUtils();
......@@ -141,6 +142,8 @@ public:
void InitStaticText(irr::gui::IGUIStaticText* pControl, u32 cWidth, u32 cHeight, irr::gui::CGUITTFont* font, const wchar_t* text);
void SetStaticText(irr::gui::IGUIStaticText* pControl, u32 cWidth, irr::gui::CGUITTFont* font, const wchar_t* text, u32 pos = 0);
void LoadExpansionDB();
void LoadExpansionDBDirectry(const char* path);
void LoadExpansionStrings();
void RefreshDeck(irr::gui::IGUIComboBox* cbDeck);
void RefreshReplay();
void RefreshSingleplay();
......
......@@ -271,23 +271,30 @@ void imageScaleNNAA(irr::video::IImage *src, irr::video::IImage *dest) {
}
}
irr::video::ITexture* ImageManager::GetTextureFromFile(char* file, s32 width, s32 height) {
#ifdef _WIN32
wchar_t name[1024];
BufferIO::DecodeUTF8(file, name);
#else
char* name = file;
#endif // _WIN32
if(mainGame->gameConf.use_image_scale) {
irr::video::ITexture* texture;
irr::video::IImage* srcimg = driver->createImageFromFile(file);
irr::video::IImage* srcimg = driver->createImageFromFile(name);
if(srcimg == NULL)
return NULL;
if(srcimg->getDimension() == irr::core::dimension2d<u32>(width, height)) {
texture = driver->addTexture(file, srcimg);
texture = driver->addTexture(name, srcimg);
} else {
video::IImage *destimg = driver->createImage(srcimg->getColorFormat(), irr::core::dimension2d<u32>(width, height));
imageScaleNNAA(srcimg, destimg);
texture = driver->addTexture(file, destimg);
texture = driver->addTexture(name, destimg);
destimg->drop();
}
srcimg->drop();
return texture;
} else {
return driver->getTexture(file);
return driver->getTexture(name);
}
}
irr::video::ITexture* ImageManager::GetTextureUnknown(s32 width, s32 height, int index) {
......@@ -295,6 +302,29 @@ irr::video::ITexture* ImageManager::GetTextureUnknown(s32 width, s32 height, int
tUnknown[index] = GetTextureFromFile("textures/unknown.jpg", width, height);
return tUnknown[index];
}
irr::video::ITexture* ImageManager::GetTextureExpansions(char* file, s32 width, s32 height) {
irr::video::ITexture* img = GetTextureExpansionsDirectry("./expansions", file, width, height);
if(img != NULL)
return img;
bool find = false;
FileSystem::TraversalDir("./expansions", [this, file, width, height, &img, &find](const char* name, bool isdir) {
if(!find && isdir && strcmp(name, ".") && strcmp(name, "..")) {
char subdir[1024];
sprintf(subdir, "./expansions/%s", name);
img = GetTextureExpansionsDirectry(subdir, file, width, height);
if(img)
find = true;
}
});
if(find)
return img;
return img;
}
irr::video::ITexture* ImageManager::GetTextureExpansionsDirectry(const char* path, char* file, s32 width, s32 height) {
char fpath[1000];
sprintf(fpath, "%s/%s", path, file);
return GetTextureFromFile(fpath, width, height);
}
irr::video::ITexture* ImageManager::GetTexture(int code, bool fit) {
int width = CARD_IMG_WIDTH;
int height = CARD_IMG_HEIGHT;
......@@ -310,11 +340,11 @@ irr::video::ITexture* ImageManager::GetTexture(int code, bool fit) {
auto tit = tMap[fit ? 1 : 0].find(code);
if(tit == tMap[fit ? 1 : 0].end()) {
char file[256];
sprintf(file, "expansions/pics/%d.png", code);
irr::video::ITexture* img = GetTextureFromFile(file, width, height);
sprintf(file, "pics/%d.png", code);
irr::video::ITexture* img = GetTextureExpansions(file, width, height);
if(img == NULL) {
sprintf(file, "expansions/pics/%d.jpg", code);
img = GetTextureFromFile(file, width, height);
sprintf(file, "pics/%d.jpg", code);
img = GetTextureExpansions(file, width, height);
}
if(img == NULL) {
sprintf(file, mainGame->GetLocaleDir("pics/%d.png"), code);
......@@ -352,11 +382,11 @@ irr::video::ITexture* ImageManager::GetTextureThumb(int code) {
return GetTextureUnknown(width, height, 2);
if(tit == tThumb.end()) {
char file[256];
sprintf(file, "expansions/pics/thumbnail/%d.png", code);
irr::video::ITexture* img = GetTextureFromFile(file, width, height);
sprintf(file, "pics/thumbnail/%d.png", code);
irr::video::ITexture* img = GetTextureExpansions(file, width, height);
if(img == NULL) {
sprintf(file, "expansions/pics/thumbnail/%d.jpg", code);
img = GetTextureFromFile(file, width, height);
sprintf(file, "pics/thumbnail/%d.jpg", code);
img = GetTextureExpansions(file, width, height);
}
if(img == NULL) {
sprintf(file, mainGame->GetLocaleDir("pics/thumbnail/%d.png"), code);
......@@ -375,11 +405,11 @@ irr::video::ITexture* ImageManager::GetTextureThumb(int code) {
img = GetTextureFromFile(file, width, height);
}
if(img == NULL && mainGame->gameConf.use_image_scale) {
sprintf(file, "expansions/pics/%d.png", code);
img = GetTextureFromFile(file, width, height);
sprintf(file, "pics/%d.png", code);
img = GetTextureExpansions(file, width, height);
if(img == NULL) {
sprintf(file, "expansions/pics/%d.jpg", code);
img = GetTextureFromFile(file, width, height);
sprintf(file, "pics/%d.jpg", code);
img = GetTextureExpansions(file, width, height);
}
if(img == NULL) {
sprintf(file, mainGame->GetLocaleDir("pics/%d.png"), code);
......@@ -412,11 +442,11 @@ irr::video::ITexture* ImageManager::GetTextureField(int code) {
auto tit = tFields.find(code);
if(tit == tFields.end()) {
char file[256];
sprintf(file, "expansions/pics/field/%d.png", code);
irr::video::ITexture* img = GetTextureFromFile(file, 512 * mainGame->xScale, 512 * mainGame->yScale);
sprintf(file, "pics/field/%d.png", code);
irr::video::ITexture* img = GetTextureExpansions(file, 512 * mainGame->xScale, 512 * mainGame->yScale);
if(img == NULL) {
sprintf(file, "expansions/pics/field/%d.jpg", code);
img = GetTextureFromFile(file, 512 * mainGame->xScale, 512 * mainGame->yScale);
sprintf(file, "pics/field/%d.jpg", code);
img = GetTextureExpansions(file, 512 * mainGame->xScale, 512 * mainGame->yScale);
}
if(img == NULL) {
sprintf(file, "pics/field/%d.png", code);
......
......@@ -23,6 +23,8 @@ public:
void ResizeTexture();
irr::video::ITexture* GetTextureFromFile(char* file, s32 width, s32 height);
irr::video::ITexture* GetTextureUnknown(s32 width, s32 height, int index);
irr::video::ITexture* GetTextureExpansions(char* file, s32 width, s32 height);
irr::video::ITexture* GetTextureExpansionsDirectry(const char* path, char* file, s32 width, s32 height);
irr::video::ITexture* GetTexture(int code, bool fit = false);
irr::video::ITexture* GetTextureThumb(int code);
irr::video::ITexture* GetTextureField(int code);
......
......@@ -940,23 +940,34 @@ void ReplayMode::ReplayReload() {
mainGame->dField.UpdateFieldCard(mainGame->LocalPlayer(1), LOCATION_REMOVED, (char*)queryBuffer);
}
byte* ReplayMode::ScriptReaderEx(const char* script_name, int* slen) {
char sname[256] = "./specials";
strcat(sname, script_name + 8);//default script name: ./script/c%d.lua
byte* buffer = default_script_reader(sname, slen);
if(!buffer) {
char sname[256] = "./expansions";
strcat(sname, script_name + 1);
buffer = default_script_reader(sname, slen);
}
if(!buffer) {
char sname[256] = "./beta";
strcat(sname, script_name + 1);
buffer = default_script_reader(sname, slen);
}
byte* buffer = ScriptReaderExDirectry("./specials", script_name, slen, 8);
if(buffer)
return buffer;
else
return default_script_reader(script_name, slen);
buffer = ScriptReaderExDirectry("./expansions", script_name, slen);
if(buffer)
return buffer;
buffer = ScriptReaderExDirectry("./beta", script_name, slen);
if(buffer)
return buffer;
bool find = false;
FileSystem::TraversalDir("./expansions", [script_name, slen, &buffer, &find](const char* name, bool isdir) {
if(!find && isdir && strcmp(name, ".") && strcmp(name, "..")) {
char subdir[1024];
sprintf(subdir, "./expansions/%s", name);
buffer = ScriptReaderExDirectry(subdir, script_name, slen);
if(buffer)
find = true;
}
});
if(find)
return buffer;
return default_script_reader(script_name, slen);
}
byte* ReplayMode::ScriptReaderExDirectry(const char* path, const char* script_name, int* slen, int pre_len) {
char sname[256];
strcpy(sname, path);
strcat(sname, script_name + pre_len);//default script name: ./script/c%d.lua
return default_script_reader(sname, slen);
}
int ReplayMode::MessageHandler(long fduel, int type) {
if(!enable_log)
......
......@@ -25,7 +25,7 @@ private:
public:
static Replay cur_replay;
public:
static bool StartReplay(int skipturn);
static void StopReplay(bool is_exiting = false);
......@@ -38,7 +38,7 @@ public:
static void Restart(bool refresh);
static void Undo();
static bool ReplayAnalyze(char* msg, unsigned int len);
static void ReplayRefresh(int flag = 0xf81fff);
static void ReplayRefreshHand(int player, int flag = 0x781fff);
static void ReplayRefreshGrave(int player, int flag = 0x181fff);
......@@ -48,6 +48,7 @@ public:
static void ReplayReload();
static byte* ScriptReaderEx(const char* script_name, int* slen);
static byte* ScriptReaderExDirectry(const char* path, const char* script_name, int* slen, int pre_len = 1);
static int MessageHandler(long fduel, int type);
};
......
......@@ -2123,23 +2123,34 @@ void SingleDuel::RefreshSingle(int player, int location, int sequence, int flag)
}
}
byte* SingleDuel::ScriptReaderEx(const char* script_name, int* slen) {
char sname[256] = "./specials";
strcat(sname, script_name + 8);//default script name: ./script/c%d.lua
byte* buffer = default_script_reader(sname, slen);
if(!buffer) {
char sname[256] = "./expansions";
strcat(sname, script_name + 1);
buffer = default_script_reader(sname, slen);
}
if(!buffer) {
char sname[256] = "./beta";
strcat(sname, script_name + 1);
buffer = default_script_reader(sname, slen);
}
byte* buffer = ScriptReaderExDirectry("./specials", script_name, slen, 8);
if(buffer)
return buffer;
else
return default_script_reader(script_name, slen);
buffer = ScriptReaderExDirectry("./expansions", script_name, slen);
if(buffer)
return buffer;
buffer = ScriptReaderExDirectry("./beta", script_name, slen);
if(buffer)
return buffer;
bool find = false;
FileSystem::TraversalDir("./expansions", [script_name, slen, &buffer, &find](const char* name, bool isdir) {
if(!find && isdir && strcmp(name, ".") && strcmp(name, "..")) {
char subdir[1024];
sprintf(subdir, "./expansions/%s", name);
buffer = ScriptReaderExDirectry(subdir, script_name, slen);
if(buffer)
find = true;
}
});
if(find)
return buffer;
return default_script_reader(script_name, slen);
}
byte* SingleDuel::ScriptReaderExDirectry(const char* path, const char* script_name, int* slen, int pre_len) {
char sname[256];
strcpy(sname, path);
strcat(sname, script_name + pre_len);//default script name: ./script/c%d.lua
return default_script_reader(sname, slen);
}
int SingleDuel::MessageHandler(long fduel, int type) {
if(!enable_log)
......
......@@ -34,7 +34,7 @@ public:
#ifdef YGOPRO_SERVER_MODE
virtual void TestCard(int code);
#endif
void DuelEndProc();
void WaitforResponse(int playerid);
#ifdef YGOPRO_SERVER_MODE
......@@ -54,10 +54,10 @@ public:
void RefreshSingle(int player, int location, int sequence, int flag = 0xf81fff);
static byte* ScriptReaderEx(const char* script_name, int* slen);
static byte* ScriptReaderExDirectry(const char* path, const char* script_name, int* slen, int pre_len = 1);
static int MessageHandler(long fduel, int type);
static void SingleTimer(evutil_socket_t fd, short events, void* arg);
protected:
DuelPlayer* players[2];
DuelPlayer* pplayer[2];
......@@ -87,4 +87,3 @@ protected:
}
#endif //SINGLE_DUEL_H
......@@ -860,23 +860,33 @@ void SingleMode::SinglePlayReload() {
mainGame->dField.UpdateFieldCard(mainGame->LocalPlayer(1), LOCATION_REMOVED, (char*)queryBuffer);
}
byte* SingleMode::ScriptReaderEx(const char* script_name, int* slen) {
char sname[256] = "./specials";
strcat(sname, script_name + 8);//default script name: ./script/c%d.lua
byte* buffer = ScriptReader(sname, slen);
if(!buffer) {
char sname[256] = "./expansions";
strcat(sname, script_name + 1);
buffer = ScriptReader(sname, slen);
}
if(!buffer) {
char sname[256] = "./beta";
strcat(sname, script_name + 1);
buffer = ScriptReader(sname, slen);
}
byte* buffer = ScriptReaderExDirectry("./specials", script_name, slen, 8);
if(buffer)
return buffer;
buffer = ScriptReaderExDirectry("./expansions", script_name, slen);
if(buffer)
return buffer;
else
return ScriptReader(script_name, slen);
buffer = ScriptReaderExDirectry("./beta", script_name, slen);
if(buffer)
return buffer;
bool find = false;
FileSystem::TraversalDir("./expansions", [script_name, slen, &buffer, &find](const char* name, bool isdir) {
if(!find && isdir && strcmp(name, ".") && strcmp(name, "..")) {
char subdir[1024];
sprintf(subdir, "./expansions/%s", name);
buffer = ScriptReaderExDirectry(subdir, script_name, slen);
if(buffer)
find = true;
}
});
if(find)
return buffer;
return ScriptReader(script_name, slen);
}
byte* SingleMode::ScriptReaderExDirectry(const char* path, const char* script_name, int* slen, int pre_len) {
char sname[256];
sprintf(sname, "%s%s", path, script_name + pre_len); //default script name: ./script/c%d.lua
return ScriptReader(sname, slen);
}
byte* SingleMode::ScriptReader(const char* script_name, int* slen) {
FILE *fp;
......
......@@ -17,7 +17,7 @@ public:
static void SetResponse(unsigned char* resp, unsigned int len);
static int SinglePlayThread(void* param);
static bool SinglePlayAnalyze(char* msg, unsigned int len);
static void SinglePlayRefresh(int flag = 0xf81fff);
static void SinglePlayRefreshHand(int player, int flag = 0x781fff);
static void SinglePlayRefreshGrave(int player, int flag = 0x181fff);
......@@ -27,6 +27,7 @@ public:
static void SinglePlayReload();
static byte* ScriptReaderEx(const char* script_name, int* slen);
static byte* ScriptReaderExDirectry(const char* path, const char* script_name, int* slen, int pre_len = 1);
static byte* ScriptReader(const char* script_name, int* slen);
static int MessageHandler(long fduel, int type);
......
......@@ -2281,24 +2281,36 @@ void TagDuel::RefreshSingle(int player, int location, int sequence, int flag) {
}
}
}
byte* TagDuel::ScriptReaderEx(const char* script_name, int* slen) {
char sname[256] = "./specials";
strcat(sname, script_name + 8);//default script name: ./script/c%d.lua
byte* buffer = default_script_reader(sname, slen);
if(!buffer) {
char sname[256] = "./expansions";
strcat(sname, script_name + 1);
buffer = default_script_reader(sname, slen);
}
if(!buffer) {
char sname[256] = "./beta";
strcat(sname, script_name + 1);
buffer = default_script_reader(sname, slen);
}
byte* buffer = ScriptReaderExDirectry("./specials", script_name, slen, 8);
if(buffer)
return buffer;
else
return default_script_reader(script_name, slen);
buffer = ScriptReaderExDirectry("./expansions", script_name, slen);
if(buffer)
return buffer;
buffer = ScriptReaderExDirectry("./beta", script_name, slen);
if(buffer)
return buffer;
bool find = false;
FileSystem::TraversalDir("./expansions", [script_name, slen, &buffer, &find](const char* name, bool isdir) {
if(!find && isdir && strcmp(name, ".") && strcmp(name, "..")) {
char subdir[1024];
sprintf(subdir, "./expansions/%s", name);
buffer = ScriptReaderExDirectry(subdir, script_name, slen);
if(buffer)
find = true;
}
});
if(find)
return buffer;
return default_script_reader(script_name, slen);
}
byte* TagDuel::ScriptReaderExDirectry(const char* path, const char* script_name, int* slen, int pre_len) {
char sname[256];
strcpy(sname, path);
strcat(sname, script_name + pre_len);//default script name: ./script/c%d.lua
return default_script_reader(sname, slen);
}
int TagDuel::MessageHandler(long fduel, int type) {
if(!enable_log)
......
......@@ -31,7 +31,7 @@ public:
virtual void RequestField(DuelPlayer* dp);
#endif
virtual void EndDuel();
void DuelEndProc();
void WaitforResponse(int playerid);
#ifdef YGOPRO_SERVER_MODE
......@@ -51,9 +51,10 @@ public:
void RefreshSingle(int player, int location, int sequence, int flag = 0xf81fff);
static byte* ScriptReaderEx(const char* script_name, int* slen);
static byte* ScriptReaderExDirectry(const char* path, const char* script_name, int* slen, int pre_len = 1);
static int MessageHandler(long fduel, int type);
static void TagTimer(evutil_socket_t fd, short events, void* arg);
protected:
DuelPlayer* players[4];
DuelPlayer* pplayer[4];
......@@ -80,4 +81,3 @@ protected:
}
#endif //TAG_DUEL_H
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