Commit 8aea5771 authored by mercury233's avatar mercury233 Committed by GitHub

add ygopro2 ai server mode, support zip again (#11)

* add SERVER_ZIP_SUPPORT using irrlicht

* pro2 path

* load db from zip

* pro2 cdb support

* fix irrlicht

* minor change declare order

* update pro2 support, add premake option

* fix appveyor

* Revert "fix appveyor"

This reverts commit 4e3d6b04fb8850c1bb2fa6bcc7ba36a664160680.

* fix

* fix

* test appveyor

* test appveyor

* test appveyor

* test appveyor

* test appveyor

* test appveyor

* fix

* irrlicht only zip reader
parent dce15d52
......@@ -2,7 +2,7 @@
/replay
/deck
/deck
/data
/expansions
/fonts
/icon
......
version: '{build}'
image: Visual Studio 2019
environment:
matrix:
- SERVER_MODE: true
- SERVER_PRO2_SUPPORT: true
install:
- git submodule update --init --recursive
......@@ -20,11 +24,9 @@ install:
- bash -c "curl --retry 5 --connect-timeout 30 --location --remote-header-name --remote-name https://www.sqlite.org/2022/sqlite-amalgamation-3390300.zip ; exit 0"
- 7z x sqlite-amalgamation-3390300.zip
- move sqlite-amalgamation-3390300 sqlite3
# let premake happy
before_build:
- xcopy /E premake\* .
# premake
- premake5 vs2019
configuration: Release
......@@ -33,17 +35,37 @@ build:
project: build/YGOPro.sln
parallel: true
after_build:
- ps: move bin\release\YGOPro.exe .
test: off
artifacts:
- path: YGOPro.exe
name: YGOPro(server)
for:
-
matrix:
only:
- SERVER_PRO2_SUPPORT: true
before_build:
- bash -c "curl --retry 5 --connect-timeout 30 --location --remote-header-name --remote-name http://downloads.sourceforge.net/irrlicht/irrlicht-1.8.5.zip ; exit 0"
- 7z x irrlicht-1.8.5.zip
- move irrlicht-1.8.5 irrlicht
- xcopy /E premake\* .
- cd irrlicht
- patch -p1 < irrlicht.patch
- cd ..
- premake5 vs2019
after_build:
- ps: move bin\release\AI.Server.exe .
artifacts:
- path: AI.Server.exe
name: YGOPro server for YGOPro2 AI
cache:
- premake-5.0.0-beta2-windows.zip
- libevent-2.0.22-stable.tar.gz
- irrlicht-1.8.5.zip
- lua-5.4.4.tar.gz
- sqlite-amalgamation-3390300.zip
......@@ -91,6 +91,12 @@ using namespace io;
using namespace gui;
#endif //YGOPRO_SERVER_MODE
#ifdef SERVER_ZIP_SUPPORT
#include <irrlicht.h>
using namespace irr;
using namespace io;
#endif
extern const unsigned short PRO_VERSION;
extern int enable_log;
extern bool exit_on_return;
......
......@@ -6,7 +6,7 @@ namespace ygo {
const wchar_t* DataManager::unknown_string = L"???";
byte DataManager::scriptBuffer[0x20000];
#ifndef YGOPRO_SERVER_MODE
#if !defined(YGOPRO_SERVER_MODE) || defined(SERVER_ZIP_SUPPORT)
IFileSystem* DataManager::FileSystem;
#endif
DataManager dataManager;
......@@ -14,7 +14,7 @@ DataManager dataManager;
bool DataManager::LoadDB(const wchar_t* wfile) {
char file[256];
BufferIO::EncodeUTF8(wfile, file);
#ifdef YGOPRO_SERVER_MODE
#if defined(YGOPRO_SERVER_MODE) && !defined(SERVER_ZIP_SUPPORT)
sqlite3* pDB;
if(sqlite3_open_v2(file, &pDB, SQLITE_OPEN_READONLY, 0) != SQLITE_OK)
return Error(pDB);
......@@ -45,7 +45,7 @@ bool DataManager::LoadDB(const wchar_t* wfile) {
const char* sql = "select * from datas,texts where datas.id=texts.id";
#endif
if(sqlite3_prepare_v2(pDB, sql, -1, &pStmt, 0) != SQLITE_OK)
#ifdef YGOPRO_SERVER_MODE
#if defined(YGOPRO_SERVER_MODE) && !defined(SERVER_ZIP_SUPPORT)
return Error(pDB);
#else
return Error(&db);
......@@ -59,7 +59,7 @@ bool DataManager::LoadDB(const wchar_t* wfile) {
do {
step = sqlite3_step(pStmt);
if(step == SQLITE_BUSY || step == SQLITE_ERROR || step == SQLITE_MISUSE)
#ifdef YGOPRO_SERVER_MODE
#if defined(YGOPRO_SERVER_MODE) && !defined(SERVER_ZIP_SUPPORT)
return Error(pDB, pStmt);
#else
return Error(&db, pStmt);
......@@ -168,7 +168,7 @@ void DataManager::ReadStringConfLine(const char* linebuf) {
_setnameStrings[value] = strBuffer;
}
}
#ifdef YGOPRO_SERVER_MODE
#if defined(YGOPRO_SERVER_MODE) && !defined(SERVER_ZIP_SUPPORT)
bool DataManager::Error(sqlite3* pDB, sqlite3_stmt* pStmt) {
wchar_t strBuffer[4096];
BufferIO::DecodeUTF8(sqlite3_errmsg(pDB), strBuffer);
......@@ -424,7 +424,7 @@ byte* DataManager::ScriptReaderEx(const char* script_name, int* slen) {
#endif //YGOPRO_SERVER_MODE
}
byte* DataManager::ScriptReader(const char* script_name, int* slen) {
#ifdef YGOPRO_SERVER_MODE
#if defined(YGOPRO_SERVER_MODE) && !defined(SERVER_ZIP_SUPPORT)
FILE* fp = fopen(script_name, "rb");
if(!fp)
return 0;
......
......@@ -3,7 +3,7 @@
#include "config.h"
#include "sqlite3.h"
#ifndef YGOPRO_SERVER_MODE
#if !defined(YGOPRO_SERVER_MODE) || defined(SERVER_ZIP_SUPPORT)
#include "spmemvfs/spmemvfs.h"
#endif
#include "client_card.h"
......@@ -18,10 +18,11 @@ public:
bool LoadStrings(const char* file);
#ifndef YGOPRO_SERVER_MODE
bool LoadStrings(IReadFile* reader);
#endif
void ReadStringConfLine(const char* linebuf);
#if !defined(YGOPRO_SERVER_MODE) || defined(SERVER_ZIP_SUPPORT)
bool Error(spmemvfs_db_t* pDB, sqlite3_stmt* pStmt = 0);
#else
void ReadStringConfLine(const char* linebuf);
bool Error(sqlite3* pDB, sqlite3_stmt* pStmt = 0);
#endif //YGOPRO_SERVER_MODE
bool GetData(int code, CardData* pData);
......@@ -63,7 +64,7 @@ public:
static int CardReader(int, void*);
static byte* ScriptReaderEx(const char* script_name, int* slen);
static byte* ScriptReader(const char* script_name, int* slen);
#ifndef YGOPRO_SERVER_MODE
#if !defined(YGOPRO_SERVER_MODE) || defined(SERVER_ZIP_SUPPORT)
static IFileSystem* FileSystem;
#endif
};
......
......@@ -51,6 +51,9 @@ void DeckManager::LoadLFListSingle(const char* path) {
}
}
void DeckManager::LoadLFList() {
#ifdef SERVER_PRO2_SUPPORT
LoadLFListSingle("config/lflist.conf");
#endif
LoadLFListSingle("expansions/lflist.conf");
LoadLFListSingle("lflist.conf");
LFList nolimit;
......
......@@ -4,6 +4,15 @@
#include "data_manager.h"
#include "deck_manager.h"
#include "replay.h"
#ifdef SERVER_ZIP_SUPPORT
#include "CFileSystem.h"
namespace irr {
namespace core {
// taken from Irrlicht.cpp beacuse that file is not included
irr::core::stringc LOCALE_DECIMAL_POINTS(".");
}
}
#endif
#else
#include "image_manager.h"
#include "data_manager.h"
......@@ -29,6 +38,12 @@ unsigned int pre_seed[3];
HostInfo game_info;
void Game::MainServerLoop() {
#ifdef SERVER_ZIP_SUPPORT
dataManager.FileSystem = new irr::io::CFileSystem();
#endif
#ifdef SERVER_PRO2_SUPPORT
dataManager.FileSystem->addFileArchive("data/script.zip");
#endif
deckManager.LoadLFList();
dataManager.LoadDB(L"cards.cdb");
LoadExpansions();
......@@ -1131,20 +1146,29 @@ std::wstring Game::SetStaticText(irr::gui::IGUIStaticText* pControl, u32 cWidth,
}
#endif //YGOPRO_SERVER_MODE
void Game::LoadExpansions() {
#ifdef SERVER_PRO2_SUPPORT
FileSystem::TraversalDir(L"./cdb", [](const wchar_t* name, bool isdir) {
wchar_t fpath[1024];
myswprintf(fpath, L"./cdb/%ls", name);
if(!isdir && wcsrchr(name, '.') && !mywcsncasecmp(wcsrchr(name, '.'), L".cdb", 4)) {
dataManager.LoadDB(fpath);
}
});
#endif // SERVER_PRO2_SUPPORT
FileSystem::TraversalDir(L"./expansions", [](const wchar_t* name, bool isdir) {
wchar_t fpath[1024];
myswprintf(fpath, L"./expansions/%ls", name);
if(!isdir && wcsrchr(name, '.') && !mywcsncasecmp(wcsrchr(name, '.'), L".cdb", 4)) {
dataManager.LoadDB(fpath);
}
#ifdef YGOPRO_SERVER_MODE
});
#else
#ifndef YGOPRO_SERVER_MODE
if(!isdir && wcsrchr(name, '.') && !mywcsncasecmp(wcsrchr(name, '.'), L".conf", 5)) {
char upath[1024];
BufferIO::EncodeUTF8(fpath, upath);
dataManager.LoadStrings(upath);
}
#endif // YGOPRO_SERVER_MODE
#if defined(SERVER_ZIP_SUPPORT) || !defined(YGOPRO_SERVER_MODE)
if(!isdir && wcsrchr(name, '.') && (!mywcsncasecmp(wcsrchr(name, '.'), L".zip", 4) || !mywcsncasecmp(wcsrchr(name, '.'), L".ypk", 4))) {
#ifdef _WIN32
dataManager.FileSystem->addFileArchive(fpath, true, false, EFAT_ZIP);
......@@ -1154,7 +1178,9 @@ void Game::LoadExpansions() {
dataManager.FileSystem->addFileArchive(upath, true, false, EFAT_ZIP);
#endif
}
#endif //SERVER_ZIP_SUPPORT
});
#if defined(SERVER_ZIP_SUPPORT) || !defined(YGOPRO_SERVER_MODE)
for(u32 i = 0; i < DataManager::FileSystem->getFileArchiveCount(); ++i) {
const IFileList* archive = DataManager::FileSystem->getFileArchive(i)->getFileList();
for(u32 j = 0; j < archive->getFileCount(); ++j) {
......@@ -1167,6 +1193,7 @@ void Game::LoadExpansions() {
#endif
if(wcsrchr(fname, '.') && !mywcsncasecmp(wcsrchr(fname, '.'), L".cdb", 4))
dataManager.LoadDB(fname);
#ifndef YGOPRO_SERVER_MODE
if(wcsrchr(fname, '.') && !mywcsncasecmp(wcsrchr(fname, '.'), L".conf", 5)) {
#ifdef _WIN32
IReadFile* reader = DataManager::FileSystem->createAndOpenFile(fname);
......@@ -1178,9 +1205,10 @@ void Game::LoadExpansions() {
if(wcsrchr(fname, '.') && !mywcsncasecmp(wcsrchr(fname, '.'), L".ydk", 4)) {
deckBuilder.expansionPacks.push_back(fname);
}
#endif // YGOPRO_SERVER_MODE
}
}
#endif //YGOPRO_SERVER_MODE
#endif //SERVER_ZIP_SUPPORT
}
#ifndef YGOPRO_SERVER_MODE
void Game::RefreshCategoryDeck(irr::gui::IGUIComboBox* cbCategory, irr::gui::IGUIComboBox* cbDeck, bool selectlastused) {
......
......@@ -89,7 +89,11 @@ bool NetServer::StartServer(unsigned short port) {
memset(&sin, 0, sizeof(sin));
server_port = port;
sin.sin_family = AF_INET;
#ifdef SERVER_PRO2_SUPPORT
sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
#else
sin.sin_addr.s_addr = htonl(INADDR_ANY);
#endif
sin.sin_port = htons(port);
listener = evconnlistener_new_bind(net_evbase, ServerAccept, NULL,
LEV_OPT_CLOSE_ON_FREE | LEV_OPT_REUSEABLE, -1, (sockaddr*)&sin, sizeof(sin));
......
include "lzma/."
if not SERVER_MODE then
if (SERVER_ZIP_SUPPORT or not SERVER_MODE) then
include "spmemvfs/."
end
......@@ -19,6 +19,16 @@ if SERVER_MODE then
"tag_duel.cpp", "tag_duel.h" }
includedirs { "../ocgcore" }
links { "ocgcore", "clzma", LUA_LIB_NAME, "sqlite3", "event" }
if SERVER_ZIP_SUPPORT then
defines { "SERVER_ZIP_SUPPORT" }
links { "irrlicht", "cspmemvfs" }
if BUILD_IRRLICHT then
includedirs { "../irrlicht/source/Irrlicht" }
end
end
if SERVER_PRO2_SUPPORT then
defines { "SERVER_PRO2_SUPPORT" }
end
else
kind "WindowedApp"
......@@ -72,6 +82,9 @@ end
files "ygopro.rc"
if not SERVER_MODE then
libdirs { "$(DXSDK_DIR)Lib/x86" }
end
if SERVER_PRO2_SUPPORT then
targetname ("AI.Server")
end
if USE_IRRKLANG then
links { "irrKlang" }
......
project "irrlicht"
kind "StaticLib"
includedirs { "include", "source/Irrlicht", "source/Irrlicht/zlib" }
defines {
"_IRR_STATIC_LIB_",
"NO_IRR_COMPILE_WITH_ZIP_ENCRYPTION_",
"NO_IRR_COMPILE_WITH_BZIP2_",
"NO__IRR_COMPILE_WITH_MOUNT_ARCHIVE_LOADER_",
"NO__IRR_COMPILE_WITH_PAK_ARCHIVE_LOADER_",
"NO__IRR_COMPILE_WITH_NPK_ARCHIVE_LOADER_",
"NO__IRR_COMPILE_WITH_TAR_ARCHIVE_LOADER_",
"NO__IRR_COMPILE_WITH_WAD_ARCHIVE_LOADER_"
}
exceptionhandling "Off"
rtti "Off"
files {
"source/Irrlicht/os.cpp",
"source/Irrlicht/zlib/adler32.c",
"source/Irrlicht/zlib/crc32.c",
"source/Irrlicht/zlib/inffast.c",
"source/Irrlicht/zlib/inflate.c",
"source/Irrlicht/zlib/inftrees.c",
"source/Irrlicht/zlib/zutil.c",
"source/Irrlicht/CAttributes.cpp",
"source/Irrlicht/CFileList.cpp",
"source/Irrlicht/CFileSystem.cpp",
"source/Irrlicht/CLimitReadFile.cpp",
"source/Irrlicht/CMemoryFile.cpp",
"source/Irrlicht/CReadFile.cpp",
"source/Irrlicht/CWriteFile.cpp",
"source/Irrlicht/CXMLReader.cpp",
"source/Irrlicht/CXMLWriter.cpp",
"source/Irrlicht/CZipReader.cpp"
}
filter { "system:windows" }
defines { "_IRR_WCHAR_FILESYSTEM" }
......@@ -10,6 +10,8 @@ IRRKLANG_PRO = false
LUA_LIB_NAME = "lua"
SERVER_MODE = true
SERVER_ZIP_SUPPORT = false
SERVER_PRO2_SUPPORT = false
USE_IRRKLANG = false
-- read settings from command line or environment variables
......@@ -54,7 +56,10 @@ newoption { trigger = 'build-ikpmp3', category = "YGOPro - irrklang - ikpmp3", d
newoption { trigger = "winxp-support", category = "YGOPro", description = "" }
newoption { trigger = "mac-arm", category = "YGOPro", description = "M1" }
newoption { trigger = "server-mode", category = "YGOPro", description = "" }
newoption { trigger = "server-mode", category = "YGOPro - server", description = "" }
newoption { trigger = "server-zip-support", category = "YGOPro - server", description = "" }
newoption { trigger = "server-pro2-support", category = "YGOPro - server", description = "" }
function GetParam(param)
return _OPTIONS[param] or os.getenv(string.upper(string.gsub(param,"-","_")))
......@@ -164,6 +169,14 @@ if GetParam("mac-arm") and os.istarget("macosx") then
end
if GetParam("server-mode") then
SERVER_MODE = true
SERVER_ZIP_SUPPORT = false
end
if GetParam("server-zip-support") then
SERVER_ZIP_SUPPORT = true
end
if GetParam("server-pro2-support") then
SERVER_PRO2_SUPPORT = true
SERVER_ZIP_SUPPORT = true
end
workspace "YGOPro"
......@@ -175,9 +188,7 @@ workspace "YGOPro"
filter "system:windows"
defines { "WIN32", "_WIN32" }
if not SERVER_MODE then
entrypoint "mainCRTStartup"
end
systemversion "latest"
startproject "YGOPro"
if WINXP_SUPPORT then
......@@ -248,6 +259,9 @@ end
if BUILD_IRRLICHT and not SERVER_MODE then
include "irrlicht"
end
if BUILD_IRRLICHT and SERVER_MODE and SERVER_ZIP_SUPPORT then
include "irrlicht/premake5-only-zipreader.lua"
end
if BUILD_SQLITE then
include "sqlite3"
end
......
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