Commit 1872e6b1 authored by nanahira's avatar nanahira

Merge branch 'develop' into server-develop

parents 9c818868 41e1c2a8
Pipeline #36857 passed with stages
in 10 minutes and 9 seconds
......@@ -83,22 +83,6 @@ void DuelInfo::Clear() {
}
#endif
bool IsExtension(const wchar_t* filename, const wchar_t* extension) {
auto flen = std::wcslen(filename);
auto elen = std::wcslen(extension);
if (!elen || flen < elen)
return false;
return !mywcsncasecmp(filename + (flen - elen), extension, elen);
}
bool IsExtension(const char* filename, const char* extension) {
auto flen = std::strlen(filename);
auto elen = std::strlen(extension);
if (!elen || flen < elen)
return false;
return !mystrncasecmp(filename + (flen - elen), extension, elen);
}
#ifdef YGOPRO_SERVER_MODE
unsigned short server_port;
unsigned short replay_mode;
......@@ -1334,14 +1318,16 @@ void Game::LoadExpansions() {
#endif
#endif // SERVER_PRO3_SUPPORT
FileSystem::TraversalDir(L"./expansions", [](const wchar_t* name, bool isdir) {
if (isdir)
return;
wchar_t fpath[1024];
myswprintf(fpath, L"./expansions/%ls", name);
if (!isdir && IsExtension(name, L".cdb")) {
if (IsExtension(name, L".cdb")) {
dataManager.LoadDB(fpath);
return;
}
#ifndef YGOPRO_SERVER_MODE
if (!isdir && IsExtension(name, L".conf")) {
if (IsExtension(name, L".conf")) {
char upath[1024];
BufferIO::EncodeUTF8(fpath, upath);
dataManager.LoadStrings(upath);
......@@ -1349,7 +1335,7 @@ void Game::LoadExpansions() {
}
#endif // YGOPRO_SERVER_MODE
#if defined(SERVER_ZIP_SUPPORT) || !defined(YGOPRO_SERVER_MODE)
if (!isdir && (IsExtension(name, L".zip") || IsExtension(name, L".ypk"))) {
if (IsExtension(name, L".zip") || IsExtension(name, L".ypk")) {
#ifdef _WIN32
DataManager::FileSystem->addFileArchive(fpath, true, false, irr::io::EFAT_ZIP);
#else
......@@ -1458,7 +1444,7 @@ void Game::RefreshDeck(const wchar_t* deckpath, const std::function<void(const w
void Game::RefreshReplay() {
lstReplayList->clear();
FileSystem::TraversalDir(L"./replay", [this](const wchar_t* name, bool isdir) {
if (!isdir && IsExtension(name, L".yrp") && Replay::CheckReplay(name))
if (!isdir && IsExtension(name, L".yrp"))
lstReplayList->addItem(name);
});
}
......
......@@ -37,8 +37,23 @@ constexpr int TEXT_LINE_SIZE = 256;
namespace ygo {
bool IsExtension(const wchar_t* filename, const wchar_t* extension);
bool IsExtension(const char* filename, const char* extension);
template<size_t N>
bool IsExtension(const wchar_t* filename, const wchar_t(&extension)[N]) {
auto flen = std::wcslen(filename);
constexpr size_t elen = N - 1;
if (!elen || flen < elen)
return false;
return !mywcsncasecmp(filename + (flen - elen), extension, elen);
}
template<size_t N>
bool IsExtension(const char* filename, const char(&extension)[N]) {
auto flen = std::strlen(filename);
constexpr size_t elen = N - 1;
if (!elen || flen < elen)
return false;
return !mystrncasecmp(filename + (flen - elen), extension, elen);
}
#ifndef YGOPRO_SERVER_MODE
struct Config {
......
......@@ -236,8 +236,8 @@ void ImageManager::ResizeTexture() {
}
// function by Warr1024, from https://github.com/minetest/minetest/issues/2419 , modified
void imageScaleNNAA(irr::video::IImage *src, irr::video::IImage *dest) {
const irr::core::dimension2d<irr::u32> srcDim = src->getDimension();
const irr::core::dimension2d<irr::u32> destDim = dest->getDimension();
const auto& srcDim = src->getDimension();
const auto& destDim = dest->getDimension();
// Cache scale ratios.
const double rx = (double)srcDim.Width / destDim.Width;
......@@ -250,8 +250,8 @@ void imageScaleNNAA(irr::video::IImage *src, irr::video::IImage *dest) {
// Walk each destination image pixel.
#pragma omp for schedule(dynamic)
for(irr::s32 dy = 0; dy < destDim.Height; dy++) {
for(irr::s32 dx = 0; dx < destDim.Width; dx++) {
for(irr::s32 dy = 0; dy < (irr::s32)destDim.Height; dy++) {
for(irr::s32 dx = 0; dx < (irr::s32)destDim.Width; dx++) {
// Calculate floating-point source rectangle bounds.
minsx = dx * rx;
maxsx = minsx + rx;
......
......@@ -513,10 +513,13 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
}
case LISTBOX_REPLAY_LIST: {
int sel = mainGame->lstReplayList->getSelected();
if(sel == -1)
if(sel < 0)
break;
auto filename = mainGame->lstReplayList->getListItem(sel);
if (!filename)
break;
wchar_t replay_path[256]{};
myswprintf(replay_path, L"./replay/%ls", mainGame->lstReplayList->getListItem(sel));
myswprintf(replay_path, L"./replay/%ls", filename);
if (!temp_replay.OpenReplay(replay_path)) {
mainGame->stReplayInfo->setText(L"Error");
break;
......@@ -526,8 +529,13 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
time_t curtime;
if(temp_replay.pheader.flag & REPLAY_UNIFORM)
curtime = temp_replay.pheader.start_time;
else
else{
curtime = temp_replay.pheader.seed;
wchar_t version_info[256]{};
myswprintf(version_info, L"version 0x%X", temp_replay.pheader.version);
repinfo.append(version_info);
repinfo.append(L"\n");
}
std::wcsftime(infobuf, sizeof infobuf / sizeof infobuf[0], L"%Y/%m/%d %H:%M:%S\n", std::localtime(&curtime));
repinfo.append(infobuf);
if (temp_replay.pheader.flag & REPLAY_SINGLE_MODE) {
......
......@@ -156,7 +156,16 @@ bool Replay::OpenReplay(const wchar_t* name) {
return false;
Reset();
if(std::fread(&pheader, sizeof pheader, 1, rfp) < 1) {
bool correct_header = true;
if (std::fread(&pheader, sizeof pheader, 1, rfp) < 1)
correct_header = false;
else if (pheader.id != 0x31707279)
correct_header = false;
else if (pheader.version < 0x12d0u)
correct_header = false;
else if (pheader.version >= 0x1353u && !(pheader.flag & REPLAY_UNIFORM))
correct_header = false;
if (!correct_header) {
std::fclose(rfp);
return false;
}
......@@ -187,17 +196,6 @@ bool Replay::OpenReplay(const wchar_t* name) {
data_position = 0;
return true;
}
bool Replay::CheckReplay(const wchar_t* name) {
wchar_t fname[256];
myswprintf(fname, L"./replay/%ls", name);
FILE* rfp = mywfopen(fname, "rb");
if(!rfp)
return false;
ReplayHeader rheader;
size_t count = std::fread(&rheader, sizeof rheader, 1, rfp);
std::fclose(rfp);
return count == 1 && rheader.id == 0x31707279 && rheader.version >= 0x12d0u && (rheader.version < 0x1353u || (rheader.flag & REPLAY_UNIFORM));
}
bool Replay::DeleteReplay(const wchar_t* name) {
wchar_t fname[256];
myswprintf(fname, L"./replay/%ls", name);
......
......@@ -62,7 +62,6 @@ public:
void SaveReplay(const wchar_t* name);
// play
static bool CheckReplay(const wchar_t* name);
static bool DeleteReplay(const wchar_t* name);
static bool RenameReplay(const wchar_t* oldname, const wchar_t* newname);
static size_t GetDeckPlayer(size_t deck_index) {
......
......@@ -3,6 +3,18 @@ project "sqlite3"
files { "sqlite3.c", "sqlite3.h" }
if not SERVER_PRO3_SUPPORT then
defines {
"SQLITE_DQS=0",
"SQLITE_DEFAULT_MEMSTATUS=0",
"SQLITE_MAX_EXPR_DEPTH=0",
"SQLITE_OMIT_DECLTYPE",
"SQLITE_OMIT_DEPRECATED",
"SQLITE_OMIT_PROGRESS_CALLBACK",
"SQLITE_OMIT_SHARED_CACHE",
}
end
if SERVER_PRO3_SUPPORT then
filter "system:windows"
defines { "SQLITE_API=__declspec(dllexport)" }
......
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