Commit 878ba230 authored by nanahira's avatar nanahira

Merge branch 'server-develop' into test-arm-optimize-server

parents b6437560 a04d54c6
# data files
/beta
/expansions
/specials
# build files
/bin
build
/obj
# dependencies
/event
/freetype
/sqlite3
/irrklang
/irrlicht*
# gframe additionals
/gframe/ygopro.ico
/gframe/ygopro.rc
/gframe/ygopro.aps
/gframe/ygopro.icns
/gframe/dirent.h
# git repos
/CustomTools
/DataEditorX
/Magic*
/pics
/Printer
/ygopro-*
/*-Cards
# libs
/*.dll
/*.so
/*.dylib
# windbot related files
/[Bb]ot
/[Bb]ot.conf
/[Bb]ot.exe
/[Bb]ot.sh
/[Ww]ind[Bb]ot
# ygopro config file
/system_user.conf
# ygopro folders
/deck
/pack
/fonts
/replay
/single
/screenshots
/sound/*.wav
/sound/custom
/sound/BGM
/sound/README.md
/sound/LICENSE
/sound/,*
/update
/update*
/locales
# ygopro main program
/ygopro
/ygopro_*
/ygopro.exe
/ygopro_*.exe
/ygopro.app
/ygopro_*.app
/premake4
/premake4.exe
/premake5
/premake5.exe
# others
*.log
.vscode
core*
/bak/
/.vs
/bug.txt
/output
/temp
[Tt]humbs.cdb
/PrinterData.txt
/*.bat
/*.sh
/*.sql
/patch.exe.manifest
/patch.exe
/diff.exe
Dockerfile
.dockerignore
/ocgcore
/script
/skin
/sound
/textures
/premake
/ikpmp3
/cards.cdb
/LICENSE
/README.md
/.gitignore
/strings.conf
/system.conf
This diff is collapsed.
language: cpp
dist: bionic
git:
submodules: false
addons:
ssh_known_hosts:
- github.com
apt:
# sources:
# - ubuntu-toolchain-r-test
packages:
# - gcc-6
# - g++-6
- libevent-dev
- libsqlite3-dev
- liblua5.3-dev
env:
- DATABASE_FILE=cards.cdb
before_install:
- git submodule update --init --recursive
#- sudo ln -s /usr/bin/gcc-6 /usr/local/bin/gcc
#- sudo ln -s /usr/bin/g++-6 /usr/local/bin/g++
#- g++ --version
- wget -O - https://github.com/premake/premake-core/releases/download/v5.0.0-beta1/premake-5.0.0-beta1-linux.tar.gz | tar zfx -
#- wget -O - https://www.lua.org/ftp/lua-5.3.6.tar.gz | tar zfx -; cd lua-5.3.6; sudo make linux install; cd ..
script:
- ./premake5 gmake
- cd build
- make config=release
- cd ..
- mv -f ./bin/release/ygopro .
- strip ygopro
- mkdir replay
- echo "select id from datas;" | sqlite3 $DATABASE_FILE | xargs -I {} ./ygopro {} 2>&1 | tee ./redtext.txt
- bash -c "exit $(cat ./redtext.txt | wc -l)"
FROM debian:buster-slim as git-checkout
RUN apt update && \
env DEBIAN_FRONTEND=noninteractive apt install -y git wget tar && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
WORKDIR /usr/src/app
COPY .git ./.git
RUN git checkout -f && \
git submodule update --init && \
git submodule foreach git checkout master && \
wget -O - https://github.com/premake/premake-core/releases/download/v5.0.0-alpha14/premake-5.0.0-alpha14-linux.tar.gz | tar zfx - && \
./premake5 gmake
FROM debian:buster-slim as builder
# apt
RUN apt update && \
env DEBIAN_FRONTEND=noninteractive apt install -y build-essential libsqlite3-dev libevent-dev liblua5.3-dev && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
WORKDIR /usr/src/app
COPY --from=git-checkout /usr/src/app/ ./
RUN cd build && \
make -j$(nproc) && \
cd .. && \
cp -rf bin/release/ygopro . && \
strip ygopro
FROM debian:buster-slim
# apt
RUN apt update && \
env DEBIAN_FRONTEND=noninteractive apt install -y libsqlite3-dev libevent-dev liblua5.3-dev && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
WORKDIR /usr/src/app
COPY --from=builder /usr/src/app/ygopro .
COPY --from=git-checkout /usr/src/app/script ./script
COPY ./lflist.conf .
ENTRYPOINT [ "./ygopro" ]
## YGOPro
A script engine for "yu-gi-oh!" and sample gui
## YGOPro(Server)
[![Build status](https://ci.appveyor.com/api/projects/status/qgkqi6o0wq7qn922/branch/server?svg=true)](https://ci.appveyor.com/project/zh99998/ygopro/branch/server)
[![Build Status](https://travis-ci.org/moecube/ygopro.svg?branch=server)](https://travis-ci.org/moecube/ygopro)
[中文说明](https://github.com/Fluorohydride/ygopro/wiki/%E4%B8%AD%E6%96%87%E8%AF%B4%E6%98%8E)
一个YGOPro的服务端版本,运行后自动建立主机,并开启端口供YGOPro客户端连接。
### Keys:
* ESC: Minimize the window.
* A: Holding down this button will let the system stop at every timing.
* S: Holding down this button will let the system skip every timing.
* D: Holding down this button will let the system stop at available timing.
* R: Fix the font glitch.
* F1~F4: Show the cards in your grave, banished zone, extra deck, xyz materials.
* F5~F8: Show the cards in your opponent's grave, banished zone, extra deck, xyz materials.
现用于[萌卡](https://mycard.moe/)[YGOPro 233服](http://mercury233.me/ygosrv233/)
### Color in card list:
#### Background:
* White = your card, Grey = your opponent's card
### Linux下编译
* 需要以下组件或工具
* gcc
* premake5
* libevent
* lua5.3
* sqlite3
* 可参考本项目 [.travis.yml](https://github.com/mycard/ygopro/blob/server/.travis.yml) 中的脚本
#### Text:
Cards in deck, extra deck and banished zone:
* Black = face-up, Blue = face-down
### Windows下编译
* 需要以下组件或工具
* Visual Studio
* premake5
* libevent
* lua5.3
* sqlite3
* 可参考本项目 [appveyor.yml](https://github.com/mycard/ygopro/blob/server/appveyor.yml) 中的脚本
Xyz materials:
* Black = default, Blue = the owner of the xyz material is different from its controller
### MacOS下编译
* 需要以下组件或工具
* clang
* premake5
* libevent
* lua5.3
* sqlite3
* 参考步骤
* 安装libevent sqlite3
* 编译premake5
* wget https://www.lua.org/ftp/lua-5.4.3.tar.gz && tar xf lua-5.4.3.tar.gz && mv lua-5.4.3 lua && cp premake/lua/* lua/
* ./premake5 gmake --cc=clang
* cd build && make config=release
### Sequence:
* Monster Zone: 1~5, starting from the left hand side.
* Spell & Trap Zone: 1~5, starting from the left hand side.
* Field Zone: 6
* Pendulum Zone: 0~1, starting from the left hand side.
* The others: 1~n, starting from the bottom.
### 运行
* 使用[ygopro-server](https://github.com/mycard/ygopro-server)运行
* 手动运行的参数是
* `./ygopro 0 0 0 1 F F F 8000 5 1 180 0`
* 端口(0为随机)
* 禁卡表编号
* 卡片允许
* 决斗模式
* 决斗规则编号
* 不检查卡组
* 不洗切卡组
* 初始LP
* 初始手牌数
* 每回合抽卡
* 每回合时间
* 录像保存模式
* 特殊选项,按位选择
* 0x1: 保存录像到 `./replay` 文件夹
* 0x2: 不向观战者发送录像
### Deck edit page:
* All numeric textboxs: They support >, =, <, >=, <= signs.
* Card name: Search card names and texts by default, $foo will only search foo in card names, and @foo will search cards of "foo" archetype(due to translation, card name contains "foo" does not mean that card is "foo" card).
### Command-line options:
* `-e foo.cdb`: Load foo.cdb as the extra database.
* `-n nickname`: Set the nickname.
* `-h 192.168.0.2`: Set the host to join in LAN mode.
* `-p 7911`: Set the port to join in LAN mode.
* `-w abc`: Set the password to join in LAN mode.
* `-d`: Enter the deck edit page.
* `-d deck`: If used along with `-j` it mean select the deck, or it will open the deck to edit.
* `-c`: Create host with default settings.
* `-j`: Join the host specified in above, or if absent, lasthost in system.conf file.
* `-r`: Enter the replay mode page.
* `-r replay.yrp`: Load the replay.yrp in replay mode.
* `-s`: Enter the single mode page.
* `-s puzzle.lua`: Load the puzzle.lua in single mode.
* `-k`: Keep when duel finished. See below.
#### Note:
* `-c` `-j` `-e` `-r` `-s` shoule be the last parameter, because any parameters after it will get ignored.
* `-d` `-c` `-j` `-e` `-r` `-s` will make YGOPro automatically exit when the duel or deck editing is finished. This is useful for some launchers. If you want to keep it, add `-k` before them.
* `-d` `-r` `-s` support full path of file, or just filename. But remember deck filename should NOT have extension when replay and single filename MUST have extension.
### Directories:
* pics: .jpg card images(177*254).
* pics\thumbnail: .jpg thumbnail images(44*64).
* script: .lua script files.
* textures: Other image files.
* deck: .ydk deck files.
* replay: .yrp replay files.
* expansions: *.cdb will be loaded as extra databases.
\ No newline at end of file
### 特殊编译参数
执行`premake5 gmake`之前,可以通过设置一些环境变量,来改变一些编译参数。
* `YGOPRO_DEFAULT_DUEL_RULE=X` 设置默认决斗规则为大师规则X。
* `YGOPRO_NO_LUA_SAFE` 若有定义,则开启默认禁用的`os``io`库。请慎用这个参数,确保运行的卡片脚本文件是可以信任的。
version: '{build}'
image: Visual Studio 2019
skip_tags: true
install:
- git submodule update --init --recursive
# environment and system dependency
- bash -c "curl --retry 5 --connect-timeout 30 --location --remote-header-name --remote-name https://github.com/premake/premake-core/releases/download/v5.0.0-beta5/premake-5.0.0-beta5-windows.zip ; exit 0"
- 7z x premake-5.0.0-beta5-windows.zip
- bash -c "curl --retry 5 --connect-timeout 30 --location --remote-header-name --remote-name https://github.com/libevent/libevent/releases/download/release-2.0.22-stable/libevent-2.0.22-stable.tar.gz ; exit 0"
- tar xf libevent-2.0.22-stable.tar.gz
- move libevent-2.0.22-stable event
- xcopy /E event\WIN32-Code event\include
- bash -c "curl --retry 5 --connect-timeout 30 --location --remote-header-name --remote-name https://www.lua.org/ftp/lua-5.4.4.tar.gz ; exit 0"
- tar xf lua-5.4.4.tar.gz
- move lua-5.4.4 lua
- bash -c "curl --retry 5 --connect-timeout 30 --location --remote-header-name --remote-name https://www.sqlite.org/2024/sqlite-amalgamation-3470000.zip ; exit 0"
- 7z x sqlite-amalgamation-3470000.zip
- move sqlite-amalgamation-3470000 sqlite3
- git clone --depth=1 https://github.com/mercury233/irrlicht irrlicht
before_build:
- xcopy /E premake\* .
- xcopy /E resource\* .
- premake5 vs2019 --server-zip-support
configuration: Release
build:
project: build/YGOPro.sln
parallel: true
after_build:
- ps: move bin\release\ygopro.exe .
# nodejs
- bash -c "curl --retry 5 --connect-timeout 30 --location --remote-header-name --remote-name https://nodejs.org/dist/v16.9.1/node-v16.9.1-win-x64.7z ; exit 0"
- 7z x -y node-v16.9.1-win-x64.7z
- mv node-v16.9.1-win-x64 node
# srvpro
- git clone https://github.com/purerosefallen/ygopro-server
- cd ygopro-server
- ../node/npm ci
- bash -c "curl --retry 5 --connect-timeout 30 --location --remote-header-name --remote-name https://github.com/purerosefallen/windbot/releases/download/latest/WindBot.7z ; exit 0"
- 7z x -y WindBot.7z
- rm -rf Bot.exe bot.conf
- mv WindBot windbot_
- mv windbot_ windbot # Windows NTFS does not support case sensitive, so renaming the folder twice.
- rm -rf WindBot.7z
- cp ../cards.cdb windbot/
- mkdir ygopro decks_save
- cp -rf ../ygopro.exe ygopro/
- mv ../cards.cdb ygopro/
- mv ../lflist.conf ygopro/
- mv ../script ygopro/
- cd ygopro
- mkdir gframe
- cp -rf ../../gframe/game.cpp gframe/ # Toss game.cpp in for version detection
# - cp -rf config_build config
- cd ../..
# start script
- bash -c "echo '@echo off' >> run.bat ; echo 'cd ygopro-server/windbot' >> run.bat ; echo 'start WindBot.exe servermode=true serverport=2399' >> run.bat ; echo 'cd ..' >> run.bat ; echo 'start ../node/node.exe ygopro-server.js' >> run.bat"
- 7z a -mx9 -xr!.git* ygopro-server-win.zip node ygopro-server run.bat
test: off
artifacts:
- path: ygopro.exe
name: ygopro server mode
- path: ygopro-server-win.zip
name: Windows version of SRVPro
deploy:
release: win
description: 'Automatic build commit $(APPVEYOR_REPO_COMMIT) $(APPVEYOR_REPO_COMMIT_TIMESTAMP)'
provider: GitHub
force_update: true
auth_token:
secure: EQ9miMjfX/QAoBvgc6D+JLmHatLyxOEKZ/uo68QijxWW5Gp4MzB/pOH9+u2GlDVO
on:
branch: server
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
......@@ -10,6 +10,7 @@ namespace ygo {
class ClientCard {
public:
#ifndef YGOPRO_SERVER_MODE
irr::core::matrix4 mTransform;
irr::core::vector3df curPos;
irr::core::vector3df curRot;
......@@ -80,6 +81,7 @@ public:
void ClearTarget();
void ClearData();
static bool client_card_sort(ClientCard* c1, ClientCard* c2);
#endif //YGOPRO_SERVER_MODE
};
}
......
......@@ -79,7 +79,9 @@ inline FILE* mywfopen(const wchar_t* filename, const char* mode) {
return fp;
}
#if !defined(YGOPRO_SERVER_MODE) || defined(SERVER_ZIP_SUPPORT)
#include <irrlicht.h>
#endif
extern unsigned short PRO_VERSION;
extern unsigned int enable_log;
......
#include "data_manager.h"
#include "game.h"
#if !defined(YGOPRO_SERVER_MODE) || defined(SERVER_ZIP_SUPPORT)
#include "spmemvfs/spmemvfs.h"
#endif
namespace ygo {
const wchar_t* DataManager::unknown_string = L"???";
unsigned char DataManager::scriptBuffer[0x100000] = {};
#if !defined(YGOPRO_SERVER_MODE) || defined(SERVER_ZIP_SUPPORT)
irr::io::IFileSystem* DataManager::FileSystem = nullptr;
#endif
DataManager dataManager;
DataManager::DataManager() : _datas(32768), _strings(32768) {
......@@ -14,10 +18,16 @@ DataManager::DataManager() : _datas(32768), _strings(32768) {
}
bool DataManager::ReadDB(sqlite3* pDB) {
sqlite3_stmt* pStmt = nullptr;
#ifdef YGOPRO_SERVER_MODE
const char* sql = "select * from datas";
#else
const char* sql = "select * from datas,texts where datas.id=texts.id";
#endif
if (sqlite3_prepare_v2(pDB, sql, -1, &pStmt, 0) != SQLITE_OK)
return Error(pDB, pStmt);
#ifndef YGOPRO_SERVER_MODE
wchar_t strBuffer[4096];
#endif
int step = 0;
do {
CardDataC cd;
......@@ -57,6 +67,7 @@ bool DataManager::ReadDB(sqlite3* pDB) {
cd.attribute = static_cast<decltype(cd.attribute)>(sqlite3_column_int64(pStmt, 9));
cd.category = static_cast<decltype(cd.category)>(sqlite3_column_int64(pStmt, 10));
_datas[cd.code] = cd;
#ifndef YGOPRO_SERVER_MODE
if (const char* text = (const char*)sqlite3_column_text(pStmt, 12)) {
BufferIO::DecodeUTF8(text, strBuffer);
cs.name = strBuffer;
......@@ -73,6 +84,7 @@ bool DataManager::ReadDB(sqlite3* pDB) {
}
}
_strings[cd.code] = cs;
#endif //YGOPRO_SERVER_MODE
}
else if (step != SQLITE_DONE)
return Error(pDB, pStmt);
......@@ -83,6 +95,15 @@ bool DataManager::ReadDB(sqlite3* pDB) {
bool DataManager::LoadDB(const wchar_t* wfile) {
char file[256];
BufferIO::EncodeUTF8(wfile, file);
#if defined(YGOPRO_SERVER_MODE) && !defined(SERVER_ZIP_SUPPORT)
bool ret{};
sqlite3* pDB{};
if (sqlite3_open_v2(file, &pDB, SQLITE_OPEN_READONLY, 0) != SQLITE_OK)
ret = Error(pDB);
else
ret = ReadDB(pDB);
sqlite3_close(pDB);
#else
#ifdef _WIN32
auto reader = FileSystem->createAndOpenFile(wfile);
#else
......@@ -105,8 +126,10 @@ bool DataManager::LoadDB(const wchar_t* wfile) {
ret = ReadDB(db.handle);
spmemvfs_close_db(&db);
spmemvfs_env_fini();
#endif //YGOPRO_SERVER_MODE
return ret;
}
#ifndef YGOPRO_SERVER_MODE
bool DataManager::LoadStrings(const char* file) {
FILE* fp = std::fopen(file, "r");
if(!fp)
......@@ -164,6 +187,7 @@ void DataManager::ReadStringConfLine(const char* linebuf) {
_setnameStrings[value] = strBuffer;
}
}
#endif //YGOPRO_SERVER_MODE
bool DataManager::Error(sqlite3* pDB, sqlite3_stmt* pStmt) {
errmsg[0] = '\0';
std::strncat(errmsg, sqlite3_errmsg(pDB), sizeof errmsg - 1);
......@@ -174,6 +198,7 @@ bool DataManager::Error(sqlite3* pDB, sqlite3_stmt* pStmt) {
code_pointer DataManager::GetCodePointer(unsigned int code) const {
return _datas.find(code);
}
#ifndef YGOPRO_SERVER_MODE
string_pointer DataManager::GetStringPointer(unsigned int code) const {
return _strings.find(code);
}
......@@ -189,6 +214,7 @@ string_pointer DataManager::strings_begin() const {
string_pointer DataManager::strings_end() const {
return _strings.cend();
}
#endif //YGOPRO_SERVER_MODE
bool DataManager::GetData(unsigned int code, CardData* pData) const {
auto cdit = _datas.find(code);
if(cdit == _datas.end())
......@@ -198,6 +224,7 @@ bool DataManager::GetData(unsigned int code, CardData* pData) const {
}
return true;
}
#ifndef YGOPRO_SERVER_MODE
bool DataManager::GetString(unsigned int code, CardString* pStr) const {
auto csit = _strings.find(code);
if(csit == _strings.end()) {
......@@ -266,10 +293,12 @@ std::vector<unsigned int> DataManager::GetSetCodes(std::wstring setname) const {
std::vector<unsigned int> matchingCodes;
for(auto csit = _setnameStrings.begin(); csit != _setnameStrings.end(); ++csit) {
auto xpos = csit->second.find_first_of(L'|');//setname|another setname or extra info
#ifndef YGOPRO_SERVER_MODE
if (mainGame->CheckRegEx(csit->second, setname, true)) {
matchingCodes.push_back(csit->first);
}
else if(setname.size() < 2) {
} else
#endif
if(setname.size() < 2) {
if(csit->second.compare(0, xpos, setname) == 0
|| csit->second.compare(xpos + 1, csit->second.length(), setname) == 0)
matchingCodes.push_back(csit->first);
......@@ -386,6 +415,7 @@ std::wstring DataManager::FormatLinkMarker(unsigned int link_marker) const {
buffer.append(L"[\u2198]");
return buffer;
}
#endif //YGOPRO_SERVER_MODE
uint32_t DataManager::CardReader(uint32_t code, card_data* pData) {
if (!dataManager.GetData(code, pData))
pData->clear();
......@@ -395,30 +425,42 @@ unsigned char* DataManager::ScriptReaderEx(const char* script_name, int* slen) {
if (std::strncmp(script_name, "./script", 8) != 0)
return ReadScriptFromFile(script_name, slen);
unsigned char* buffer;
#ifndef YGOPRO_SERVER_MODE
if(!mainGame->gameConf.prefer_expansion_script) {
buffer = ScriptReaderExSingle("", script_name, slen);
if(buffer)
return buffer;
}
#endif //YGOPRO_SERVER_MODE
buffer = ScriptReaderExSingle("specials/", script_name, slen, 9);
if(buffer)
return buffer;
buffer = ScriptReaderExSingle("expansions/", script_name, slen);
if(buffer)
return buffer;
#if defined(SERVER_PRO3_SUPPORT) && !defined(_WIN32)
buffer = ScriptReaderExSingle("Expansions/", script_name, slen);
if(buffer)
return buffer;
#endif
#if !defined(YGOPRO_SERVER_MODE) || defined(SERVER_ZIP_SUPPORT)
buffer = ScriptReaderExSingle("", script_name, slen, 2, TRUE);
if(buffer)
return buffer;
#endif
return ScriptReaderExSingle("", script_name, slen);
}
unsigned char* DataManager::ScriptReaderExSingle(const char* path, const char* script_name, int* slen, int pre_len, unsigned int use_irr) {
char sname[256];
std::snprintf(sname, sizeof sname, "%s%s", path, script_name + pre_len); //default script name: ./script/c%d.lua
#if !defined(YGOPRO_SERVER_MODE) || defined(SERVER_ZIP_SUPPORT)
if (use_irr) {
return ReadScriptFromIrrFS(sname, slen);
}
#endif
return ReadScriptFromFile(sname, slen);
}
#if !defined(YGOPRO_SERVER_MODE) || defined(SERVER_ZIP_SUPPORT)
unsigned char* DataManager::ReadScriptFromIrrFS(const char* script_name, int* slen) {
#ifdef _WIN32
wchar_t fname[256]{};
......@@ -436,6 +478,7 @@ unsigned char* DataManager::ReadScriptFromIrrFS(const char* script_name, int* sl
*slen = size;
return scriptBuffer;
}
#endif
unsigned char* DataManager::ReadScriptFromFile(const char* script_name, int* slen) {
wchar_t fname[256]{};
BufferIO::DecodeUTF8(script_name, fname);
......@@ -449,6 +492,7 @@ unsigned char* DataManager::ReadScriptFromFile(const char* script_name, int* sle
*slen = (int)len;
return scriptBuffer;
}
#ifndef YGOPRO_SERVER_MODE
bool DataManager::deck_sort_lv(code_pointer p1, code_pointer p2) {
if ((p1->second.type & 0x7) != (p2->second.type & 0x7))
return (p1->second.type & 0x7) < (p2->second.type & 0x7);
......@@ -517,5 +561,6 @@ bool DataManager::deck_sort_name(code_pointer p1, code_pointer p2) {
return res < 0;
return p1->first < p2->first;
}
#endif //YGOPRO_SERVER_MODE
}
......@@ -45,18 +45,23 @@ public:
DataManager();
bool ReadDB(sqlite3* pDB);
bool LoadDB(const wchar_t* wfile);
#ifndef YGOPRO_SERVER_MODE
bool LoadStrings(const char* file);
bool LoadStrings(irr::io::IReadFile* reader);
void ReadStringConfLine(const char* linebuf);
#endif
bool Error(sqlite3* pDB, sqlite3_stmt* pStmt = nullptr);
code_pointer GetCodePointer(unsigned int code) const;
#ifndef YGOPRO_SERVER_MODE
string_pointer GetStringPointer(unsigned int code) const;
code_pointer datas_begin() const;
code_pointer datas_end() const;
string_pointer strings_begin() const;
string_pointer strings_end() const;
#endif
bool GetData(unsigned int code, CardData* pData) const;
#ifndef YGOPRO_SERVER_MODE
bool GetString(unsigned int code, CardString* pStr) const;
const wchar_t* GetName(unsigned int code) const;
const wchar_t* GetText(unsigned int code) const;
......@@ -78,6 +83,7 @@ public:
std::unordered_map<unsigned int, std::wstring> _victoryStrings;
std::unordered_map<unsigned int, std::wstring> _setnameStrings;
std::unordered_map<unsigned int, std::wstring> _sysStrings;
#endif
char errmsg[512]{};
static unsigned char scriptBuffer[0x100000];
......@@ -85,13 +91,24 @@ public:
static uint32_t CardReader(uint32_t, card_data*);
static unsigned char* ScriptReaderEx(const char* script_name, int* slen);
static unsigned char* ScriptReaderExSingle(const char* path, const char* script_name, int* slen, int pre_len = 2, unsigned int use_irr = FALSE);
#if !defined(YGOPRO_SERVER_MODE) || defined(SERVER_ZIP_SUPPORT)
//read by IFileSystem
static unsigned char* ReadScriptFromIrrFS(const char* script_name, int* slen);
#endif
//read by fread
static unsigned char* ReadScriptFromFile(const char* script_name, int* slen);
#if !defined(YGOPRO_SERVER_MODE) || defined(SERVER_ZIP_SUPPORT)
static irr::io::IFileSystem* FileSystem;
#endif
#ifndef YGOPRO_SERVER_MODE
static bool deck_sort_lv(code_pointer l1, code_pointer l2);
static bool deck_sort_atk(code_pointer l1, code_pointer l2);
static bool deck_sort_def(code_pointer l1, code_pointer l2);
static bool deck_sort_name(code_pointer l1, code_pointer l2);
#endif
static bool deck_sort_lv(code_pointer l1, code_pointer l2);
static bool deck_sort_atk(code_pointer l1, code_pointer l2);
......
......@@ -6,7 +6,9 @@
namespace ygo {
#ifndef YGOPRO_SERVER_MODE
char DeckManager::deckBuffer[0x10000]{};
#endif
DeckManager deckManager;
void DeckManager::LoadLFListSingle(const char* path) {
......@@ -44,6 +46,15 @@ void DeckManager::LoadLFListSingle(const char* path) {
}
}
void DeckManager::LoadLFList() {
#ifdef SERVER_PRO2_SUPPORT
LoadLFListSingle("config/lflist.conf");
#endif
#ifdef SERVER_PRO3_SUPPORT
LoadLFListSingle("Data/lflist.conf");
#ifndef _WIN32
LoadLFListSingle("Expansions/lflist.conf");
#endif
#endif
LoadLFListSingle("expansions/lflist.conf");
LoadLFListSingle("lflist.conf");
LFList nolimit;
......@@ -185,6 +196,7 @@ int DeckManager::LoadDeck(Deck& deck, int* dbuf, int mainc, int sidec, bool is_p
}
return errorcode;
}
#ifndef YGOPRO_SERVER_MODE
int DeckManager::LoadDeck(Deck& deck, std::istringstream& deckStream, bool is_packlist) {
size_t ct = 0;
int mainc = 0, sidec = 0, code = 0;
......@@ -210,6 +222,7 @@ int DeckManager::LoadDeck(Deck& deck, std::istringstream& deckStream, bool is_pa
}
return LoadDeck(deck, cardlist, mainc, sidec, is_packlist);
}
#endif
bool DeckManager::LoadSide(Deck& deck, int* dbuf, int mainc, int sidec) {
std::unordered_map<int, int> pcount;
std::unordered_map<int, int> ncount;
......@@ -239,6 +252,7 @@ bool DeckManager::LoadSide(Deck& deck, int* dbuf, int mainc, int sidec) {
deck = ndeck;
return true;
}
#ifndef YGOPRO_SERVER_MODE
void DeckManager::GetCategoryPath(wchar_t* ret, int index, const wchar_t* text) {
wchar_t catepath[256];
switch(index) {
......@@ -439,4 +453,5 @@ bool DeckManager::SaveDeckBuffer(const int deckbuf[], const wchar_t* name) {
std::fclose(fp);
return true;
}
#endif //YGOPRO_SERVER_MODE
}
......@@ -56,7 +56,9 @@ public:
Deck current_deck;
std::vector<LFList> _lfList;
#ifndef YGOPRO_SERVER_MODE
static char deckBuffer[0x10000];
#endif
void LoadLFListSingle(const char* path);
void LoadLFList();
......@@ -64,8 +66,9 @@ public:
const LFList* GetLFList(unsigned int lfhash);
unsigned int CheckDeck(const Deck& deck, unsigned int lfhash, int rule);
int LoadDeck(Deck& deck, int* dbuf, int mainc, int sidec, bool is_packlist = false);
int LoadDeck(Deck& deck, std::istringstream& deckStream, bool is_packlist = false);
bool LoadSide(Deck& deck, int* dbuf, int mainc, int sidec);
#ifndef YGOPRO_SERVER_MODE
int LoadDeck(Deck& deck, std::istringstream& deckStream, bool is_packlist = false);
void GetCategoryPath(wchar_t* ret, int index, const wchar_t* text);
void GetDeckFile(wchar_t* ret, int category_index, const wchar_t* category_name, const wchar_t* deckname);
FILE* OpenDeckFile(const wchar_t* file, const char* mode);
......@@ -82,10 +85,31 @@ public:
bool RenameCategory(const wchar_t* oldname, const wchar_t* newname);
bool DeleteCategory(const wchar_t* name);
bool SaveDeckBuffer(const int deckbuf[], const wchar_t* name);
#endif //YGOPRO_SERVER_MODE
};
extern DeckManager deckManager;
}
#ifdef YGOPRO_SERVER_MODE
#ifndef DECKCOUNT_MAIN_MIN
#define DECKCOUNT_MAIN_MIN 40
#endif
#ifndef DECKCOUNT_MAIN_MAX
#define DECKCOUNT_MAIN_MAX 60
#endif
#ifndef DECKCOUNT_SIDE
#define DECKCOUNT_SIDE 15
#endif
#ifndef DECKCOUNT_EXTRA
#define DECKCOUNT_EXTRA 15
#endif
#endif //YGOPRO_SERVER_MODE
#endif //DECKMANAGER_H
......@@ -364,7 +364,6 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
if(sel == -1)
break;
DuelClient::SetResponseI(ancard[sel]);
mainGame->dInfo.announce_cache.insert(mainGame->dInfo.announce_cache.begin(), ancard[sel]);
mainGame->HideElement(mainGame->wANCard, true);
break;
}
......
#include "config.h"
#include "game.h"
#include "myfilesystem.h"
#ifdef YGOPRO_SERVER_MODE
#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"
#include "deck_manager.h"
......@@ -12,7 +25,9 @@
#include "single_mode.h"
#include <sstream>
#include <regex>
#endif //YGOPRO_SERVER_MODE
#include <thread>
#include "myfilesystem.h"
unsigned short PRO_VERSION = 0x1361;
......@@ -20,6 +35,7 @@ namespace ygo {
Game* mainGame;
#ifndef YGOPRO_SERVER_MODE
void DuelInfo::Clear() {
isStarted = false;
isInDuel = false;
......@@ -65,6 +81,7 @@ void DuelInfo::Clear() {
total_attack_color[1] = 0;
announce_cache.clear();
}
#endif
bool IsExtension(const wchar_t* filename, const wchar_t* extension) {
auto flen = std::wcslen(filename);
......@@ -82,6 +99,42 @@ bool IsExtension(const char* filename, const char* extension) {
return !mystrncasecmp(filename + (flen - elen), extension, elen);
}
#ifdef YGOPRO_SERVER_MODE
unsigned short server_port;
unsigned short replay_mode;
unsigned int pre_seed[5];
unsigned int duel_flags;
HostInfo game_info;
void Game::MainServerLoop() {
#ifdef SERVER_ZIP_SUPPORT
DataManager::FileSystem = new irr::io::CFileSystem();
#endif
initUtils();
deckManager.LoadLFList();
dataManager.LoadDB(L"cards.cdb");
LoadExpansions();
#if defined SERVER_PRO2_SUPPORT || defined SERVER_PRO3_SUPPORT
DataManager::FileSystem->addFileArchive("data/script.zip", true, false, irr::io::EFAT_ZIP);
#endif
server_port = NetServer::StartServer(server_port);
NetServer::InitDuel();
printf("%u\n", server_port);
fflush(stdout);
while(NetServer::net_evbase) {
std::this_thread::sleep_for(std::chrono::milliseconds(200));
}
}
void Game::MainTestLoop(int code) {
LoadExpansions();
dataManager.LoadDB(L"cards.cdb");
fflush(stdout);
NetServer::InitTestCard(code);
}
#else //YGOPRO_SERVER_MODE
bool Game::Initialize() {
initUtils();
LoadConfig();
......@@ -1242,7 +1295,35 @@ std::wstring Game::SetStaticText(irr::gui::IGUIStaticText* pControl, irr::u32 cW
ret.assign(strBuffer);
return ret;
}
#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 && IsExtension(name, L".cdb")) {
dataManager.LoadDB(fpath);
}
});
#endif // SERVER_PRO2_SUPPORT
#ifdef SERVER_PRO3_SUPPORT
FileSystem::TraversalDir(L"./Data/locales/zh-CN", [](const wchar_t* name, bool isdir) {
wchar_t fpath[1024];
myswprintf(fpath, L"./Data/locales/zh-CN/%ls", name);
if(!isdir && IsExtension(name, L".cdb")) {
dataManager.LoadDB(fpath);
}
});
#ifndef _WIN32
FileSystem::TraversalDir(L"./Expansions", [](const wchar_t* name, bool isdir) {
wchar_t fpath[1024];
myswprintf(fpath, L"./Expansions/%ls", name);
if(!isdir && IsExtension(name, L".cdb")) {
dataManager.LoadDB(fpath);
}
});
#endif
#endif // SERVER_PRO3_SUPPORT
FileSystem::TraversalDir(L"./expansions", [](const wchar_t* name, bool isdir) {
wchar_t fpath[1024];
myswprintf(fpath, L"./expansions/%ls", name);
......@@ -1250,12 +1331,15 @@ void Game::LoadExpansions() {
dataManager.LoadDB(fpath);
return;
}
#ifndef YGOPRO_SERVER_MODE
if (!isdir && IsExtension(name, L".conf")) {
char upath[1024];
BufferIO::EncodeUTF8(fpath, upath);
dataManager.LoadStrings(upath);
return;
}
#endif // YGOPRO_SERVER_MODE
#if defined(SERVER_ZIP_SUPPORT) || !defined(YGOPRO_SERVER_MODE)
if (!isdir && (IsExtension(name, L".zip") || IsExtension(name, L".ypk"))) {
#ifdef _WIN32
DataManager::FileSystem->addFileArchive(fpath, true, false, irr::io::EFAT_ZIP);
......@@ -1266,7 +1350,9 @@ void Game::LoadExpansions() {
#endif
return;
}
#endif //SERVER_ZIP_SUPPORT
});
#if defined(SERVER_ZIP_SUPPORT) || !defined(YGOPRO_SERVER_MODE)
for(irr::u32 i = 0; i < DataManager::FileSystem->getFileArchiveCount(); ++i) {
auto archive = DataManager::FileSystem->getFileArchive(i)->getFileList();
for(irr::u32 j = 0; j < archive->getFileCount(); ++j) {
......@@ -1281,6 +1367,7 @@ void Game::LoadExpansions() {
dataManager.LoadDB(fname);
continue;
}
#ifndef YGOPRO_SERVER_MODE
if (IsExtension(fname, L".conf")) {
#ifdef _WIN32
auto reader = DataManager::FileSystem->createAndOpenFile(fname);
......@@ -1294,9 +1381,12 @@ void Game::LoadExpansions() {
deckBuilder.expansionPacks.push_back(fname);
continue;
}
#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) {
cbCategory->clear();
cbCategory->addItem(dataManager.GetSysString(1450));
......@@ -1980,7 +2070,22 @@ void Game::ClearChatMsg() {
chatTiming[i] = 0;
}
}
#endif //YGOPRO_SERVER_MODE
void Game::AddDebugMsg(const char* msg) {
#ifdef YGOPRO_LOG_IN_CHAT
wchar_t msgbuf_w[1024];
wchar_t msgbuf_w2[1024];
uint16_t msgbuf_u16[LEN_CHAT_MSG];
BufferIO::DecodeUTF8(msg, msgbuf_w);
myswprintf(msgbuf_w2, L"[Script Error]: %ls", msgbuf_w); // prefix for debug messages
auto len = BufferIO::CopyCharArray(msgbuf_w2, msgbuf_u16);
DuelPlayer tmp_dp;
tmp_dp.type = 11;
NetServer::duel_mode->Chat(&tmp_dp, (unsigned char*)msgbuf_u16, (len + 1) * sizeof(uint16_t)); // send to chat log
#endif
#ifdef YGOPRO_SERVER_MODE
fprintf(stderr, "%s\n", msg);
#else
if (enable_log & 0x1) {
wchar_t wbuf[1024];
BufferIO::DecodeUTF8(msg, wbuf);
......@@ -1991,7 +2096,9 @@ void Game::AddDebugMsg(const char* msg) {
std::snprintf(msgbuf, sizeof msgbuf, "[Script Error]: %s", msg);
ErrorLog(msgbuf);
}
#endif //YGOPRO_SERVER_MODE
}
#ifndef YGOPRO_SERVER_MODE
void Game::ErrorLog(const char* msg) {
FILE* fp = std::fopen("error.log", "a");
if(!fp)
......@@ -2002,12 +2109,17 @@ void Game::ErrorLog(const char* msg) {
std::fprintf(fp, "[%s]%s\n", timebuf, msg);
std::fclose(fp);
}
#endif //YGOPRO_SERVER_MODE
void Game::initUtils() {
//user files
FileSystem::MakeDir("replay");
FileSystem::MakeDir("screenshots");
//cards from extra pack
FileSystem::MakeDir("expansions");
#ifdef YGOPRO_SERVER_MODE
//special scripts
FileSystem::MakeDir("specials");
#else
FileSystem::MakeDir("screenshots");
//files in ygopro-starter-pack
FileSystem::MakeDir("deck");
FileSystem::MakeDir("single");
......@@ -2044,7 +2156,9 @@ void Game::initUtils() {
//pics
FileSystem::MakeDir("pics");
FileSystem::MakeDir("pics/field");
#endif //YGOPRO_SERVER_MODE
}
#ifndef YGOPRO_SERVER_MODE
void Game::ClearTextures() {
matManager.mCard.setTexture(0, 0);
ClearCardInfo(0);
......@@ -2526,5 +2640,6 @@ void Game::SetCursor(irr::gui::ECURSOR_ICON icon) {
cursor->setActiveIcon(icon);
}
}
#endif //YGOPRO_SERVER_MODE
}
......@@ -2,6 +2,7 @@
#define GAME_H
#include "config.h"
#ifndef YGOPRO_SERVER_MODE
#ifdef __APPLE__
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
......@@ -16,6 +17,9 @@
#include "deck_con.h"
#include "menu_handler.h"
#include "CGUISkinSystem/CGUISkinSystem.h"
#else
#include "netserver.h"
#endif //YGOPRO_SERVER_MODE
#include <ctime>
#include <unordered_map>
#include <vector>
......@@ -26,6 +30,8 @@
#ifndef YGOPRO_DEFAULT_DUEL_RULE
#define YGOPRO_DEFAULT_DUEL_RULE 5
#endif
#define DEFAULT_DUEL_RULE YGOPRO_DEFAULT_DUEL_RULE
constexpr int CONFIG_LINE_SIZE = 1024;
constexpr int TEXT_LINE_SIZE = 256;
......@@ -34,6 +40,7 @@ namespace ygo {
bool IsExtension(const wchar_t* filename, const wchar_t* extension);
bool IsExtension(const char* filename, const char* extension);
#ifndef YGOPRO_SERVER_MODE
struct Config {
bool use_d3d{ false };
bool use_image_scale{ true };
......@@ -156,11 +163,19 @@ struct FadingUnit {
irr::core::vector2di fadingLR;
irr::core::vector2di fadingDiff;
};
#endif //YGOPRO_SERVER_MODE
class Game {
public:
bool Initialize();
#ifdef YGOPRO_SERVER_MODE
void MainServerLoop();
void MainTestLoop(int code);
void LoadExpansions();
void AddDebugMsg(const char* msgbuf);
void initUtils();
#else
void MainLoop();
void RefreshTimeDisplay();
void BuildProjectionMatrix(irr::core::matrix4& mProjection, irr::f32 left, irr::f32 right, irr::f32 bottom, irr::f32 top, irr::f32 znear, irr::f32 zfar);
......@@ -665,13 +680,25 @@ public:
irr::gui::IGUIButton* btnBigCardZoomIn;
irr::gui::IGUIButton* btnBigCardZoomOut;
irr::gui::IGUIButton* btnBigCardClose;
#endif //YGOPRO_SERVER_MODE
};
extern Game* mainGame;
#ifdef YGOPRO_SERVER_MODE
extern unsigned short server_port;
extern unsigned short replay_mode;
extern HostInfo game_info;
extern unsigned int pre_seed[5];
extern unsigned int duel_flags;
#endif
}
#ifdef YGOPRO_SERVER_MODE
#define SIZE_QUERY_BUFFER 0x40000
#else
#define SIZE_QUERY_BUFFER 0x4000
#endif
#define CARD_IMG_WIDTH 177
#define CARD_IMG_HEIGHT 254
......
......@@ -10,6 +10,7 @@
#endif
unsigned int enable_log = 0x3;
#ifndef YGOPRO_SERVER_MODE
bool exit_on_return = false;
bool auto_watch_mode = false;
bool open_file = false;
......@@ -23,12 +24,13 @@ void ClickButton(irr::gui::IGUIElement* btn) {
event.GUIEvent.Caller = btn;
ygo::mainGame->device->postEventFromUser(event);
}
#endif //YGOPRO_SERVER_MODE
int main(int argc, char* argv[]) {
#ifndef _WIN32
std::setlocale(LC_CTYPE, "UTF-8");
#endif
#ifdef __APPLE__
#if defined __APPLE__ && !defined YGOPRO_SERVER_MODE
CFURLRef bundle_url = CFBundleCopyBundleURL(CFBundleGetMainBundle());
CFURLRef bundle_base_url = CFURLCreateCopyDeletingLastPathComponent(nullptr, bundle_url);
CFRelease(bundle_url);
......@@ -58,6 +60,74 @@ int main(int argc, char* argv[]) {
evthread_use_pthreads();
#endif //_WIN32
ygo::Game _game;
#ifdef YGOPRO_SERVER_MODE
enable_log = 1;
ygo::server_port = 7911;
ygo::replay_mode = 0;
ygo::duel_flags = 0;
ygo::game_info.lflist = 0;
ygo::game_info.rule = 0;
ygo::game_info.mode = 0;
ygo::game_info.start_hand = 5;
ygo::game_info.start_lp = 8000;
ygo::game_info.draw_count = 1;
ygo::game_info.no_check_deck = false;
ygo::game_info.no_shuffle_deck = false;
ygo::game_info.duel_rule = YGOPRO_DEFAULT_DUEL_RULE;
ygo::game_info.time_limit = 180;
for (int i = 0; i < 3; ++i)
ygo::pre_seed[i] = (unsigned int)0;
if (argc == 2) {
int code = atoi(argv[1]);
ygo::mainGame = &_game;
ygo::mainGame->MainTestLoop(code);
return 0;
} else
if(argc > 2) {
ygo::server_port = atoi(argv[1]);
int lflist = atoi(argv[2]);
if(lflist < 0)
lflist = 999;
ygo::game_info.lflist = lflist;
ygo::game_info.rule = atoi(argv[3]);
int mode = atoi(argv[4]);
if(mode > 2)
mode = 0;
ygo::game_info.mode = mode;
if(argv[5][0] == 'T')
ygo::game_info.duel_rule = YGOPRO_DEFAULT_DUEL_RULE - 1;
else if(argv[5][0] == 'F')
ygo::game_info.duel_rule = YGOPRO_DEFAULT_DUEL_RULE;
else {
ygo::duel_flags = atoi(argv[5]);
auto master_rule = ygo::duel_flags & 0xF;
if(master_rule)
ygo::game_info.duel_rule = master_rule;
else
ygo::game_info.duel_rule = YGOPRO_DEFAULT_DUEL_RULE;
}
if(argv[6][0] == 'T')
ygo::game_info.no_check_deck = true;
else
ygo::game_info.no_check_deck = false;
if(argv[7][0] == 'T')
ygo::game_info.no_shuffle_deck = true;
else
ygo::game_info.no_shuffle_deck = false;
ygo::game_info.start_lp = atoi(argv[8]);
ygo::game_info.start_hand = atoi(argv[9]);
ygo::game_info.draw_count = atoi(argv[10]);
ygo::game_info.time_limit = atoi(argv[11]);
ygo::replay_mode = atoi(argv[12]);
for (int i = 13; (i < argc && i <= 17) ; ++i)
{
ygo::pre_seed[i - 13] = (unsigned int)atol(argv[i]);
}
}
ygo::mainGame = &_game;
ygo::mainGame->MainServerLoop();
return 0;
#else //YGOPRO_SERVER_MODE
ygo::mainGame = &_game;
if(!ygo::mainGame->Initialize())
return 0;
......@@ -214,5 +284,6 @@ int main(int argc, char* argv[]) {
#else
#endif //_WIN32
#endif //YGOPRO_SERVER_MODE
return EXIT_SUCCESS;
}
#include "config.h"
#include "game.h"
#include "data_manager.h"
#include <event2/thread.h>
#include <memory>
#ifdef __APPLE__
#import <CoreFoundation/CoreFoundation.h>
#endif
int main(int argc, char* argv[]);
......@@ -195,10 +195,12 @@ public:
return success;
}
#ifndef YGOPRO_SERVER_MODE
struct file_unit {
std::string filename;
bool is_dir;
};
#endif
static void TraversalDir(const char* path, const std::function<void(const char*, bool)>& cb) {
DIR* dir = nullptr;
......@@ -206,26 +208,40 @@ public:
if((dir = opendir(path)) == nullptr)
return;
struct stat fileStat;
#ifndef YGOPRO_SERVER_MODE
std::vector<file_unit> file_list;
#endif
while((dirp = readdir(dir)) != nullptr) {
#ifndef YGOPRO_SERVER_MODE
file_unit funit;
#endif
char fname[1024];
int len = std::snprintf(fname, sizeof fname, "%s/%s", path, dirp->d_name);
if (len < 0 || len >= (int)(sizeof fname))
continue;
stat(fname, &fileStat);
#ifdef YGOPRO_SERVER_MODE
bool is_dir = S_ISDIR(fileStat.st_mode);
if (is_dir && (strcmp(dirp->d_name, ".") == 0 || strcmp(dirp->d_name, "..") == 0) || strcmp(dirp->d_name, ".git") == 0)
continue;
cb(dirp->d_name, is_dir);
#else
funit.filename = std::string(dirp->d_name);
funit.is_dir = S_ISDIR(fileStat.st_mode);
if(funit.is_dir && (strcmp(dirp->d_name, ".") == 0 || strcmp(dirp->d_name, "..") == 0) || strcmp(dirp->d_name, ".git") == 0)
continue;
file_list.push_back(funit);
#endif
}
closedir(dir);
#ifndef YGOPRO_SERVER_MODE
std::sort(file_list.begin(), file_list.end(), TraversalDirSort);
for (file_unit funit : file_list)
cb(funit.filename.c_str(), funit.is_dir);
#endif
}
#ifndef YGOPRO_SERVER_MODE
static bool TraversalDirSort(file_unit file1, file_unit file2) {
if(file1.is_dir != file2.is_dir) {
return file2.is_dir;
......@@ -233,6 +249,7 @@ public:
return file1.filename < file2.filename;
}
}
#endif
static void TraversalDir(const wchar_t* wpath, const std::function<void(const wchar_t*, bool)>& cb) {
char path[1024];
......
......@@ -15,7 +15,77 @@ DuelMode* NetServer::duel_mode = 0;
unsigned char NetServer::net_server_write[SIZE_NETWORK_BUFFER];
size_t NetServer::last_sent = 0;
#ifdef YGOPRO_SERVER_MODE
extern unsigned short replay_mode;
extern HostInfo game_info;
void NetServer::InitDuel()
{
if(game_info.mode == MODE_SINGLE) {
duel_mode = new SingleDuel(false);
duel_mode->etimer = event_new(net_evbase, 0, EV_TIMEOUT | EV_PERSIST, SingleDuel::SingleTimer, duel_mode);
} else if(game_info.mode == MODE_MATCH) {
duel_mode = new SingleDuel(true);
duel_mode->etimer = event_new(net_evbase, 0, EV_TIMEOUT | EV_PERSIST, SingleDuel::SingleTimer, duel_mode);
} else if(game_info.mode == MODE_TAG) {
duel_mode = new TagDuel();
duel_mode->etimer = event_new(net_evbase, 0, EV_TIMEOUT | EV_PERSIST, TagDuel::TagTimer, duel_mode);
}
CTOS_CreateGame* pkt = new CTOS_CreateGame;
pkt->info.mode = game_info.mode;
pkt->info.start_hand = game_info.start_hand;
pkt->info.start_lp = game_info.start_lp;
pkt->info.draw_count = game_info.draw_count;
pkt->info.no_check_deck = game_info.no_check_deck;
pkt->info.no_shuffle_deck = game_info.no_shuffle_deck;
pkt->info.duel_rule = game_info.duel_rule;
pkt->info.rule = game_info.rule;
pkt->info.time_limit = game_info.time_limit;
if(game_info.lflist == 999)
pkt->info.lflist = 0;
else if(game_info.lflist >= deckManager._lfList.size())
pkt->info.lflist = deckManager._lfList[0].hash;
else
pkt->info.lflist = deckManager._lfList[game_info.lflist].hash;
duel_mode->host_info = pkt->info;
BufferIO::CopyWStr(pkt->name, duel_mode->name, 20);
BufferIO::CopyWStr(pkt->pass, duel_mode->pass, 20);
}
void NetServer::InitTestCard(int code) {
DuelMode* test_duel = new SingleDuel(false);
test_duel->TestCard(code);
}
bool NetServer::IsCanIncreaseTime(unsigned short gameMsg, void *pdata, unsigned int len) {
int32_t* ivalue = (int32_t*)pdata;
switch(gameMsg) {
case MSG_RETRY:
case MSG_SELECT_UNSELECT_CARD:
return false;
case MSG_SELECT_CHAIN:
return ivalue[0] != -1;
case MSG_SELECT_IDLECMD: {
int32_t idleChoice = ivalue[0] & 0xffff;
return idleChoice <= 5; // no shuffle hand, enter other phases
}
case MSG_SELECT_BATTLECMD: {
int32_t battleChoice = ivalue[0] & 0xffff;
return battleChoice <= 1; // attack only
}
default:
return true;
}
}
unsigned short NetServer::StartServer(unsigned short port) {
#else
bool NetServer::StartServer(unsigned short port) {
#endif //YGOPRO_SERVER_MODE
if(net_evbase)
return false;
net_evbase = event_base_new();
......@@ -25,7 +95,11 @@ bool NetServer::StartServer(unsigned short port) {
std::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, nullptr,
LEV_OPT_CLOSE_ON_FREE | LEV_OPT_REUSEABLE, -1, (sockaddr*)&sin, sizeof(sin));
......@@ -36,7 +110,15 @@ bool NetServer::StartServer(unsigned short port) {
}
evconnlistener_set_error_cb(listener, ServerAcceptError);
std::thread(ServerThread).detach();
#ifdef YGOPRO_SERVER_MODE
evutil_socket_t fd = evconnlistener_get_fd(listener);
socklen_t addrlen = sizeof(sockaddr);
sockaddr_in addr;
getsockname(fd, (sockaddr*)&addr, &addrlen);
return ntohs(addr.sin_port);
#else
return true;
#endif //YGOPRO_SERVER_MODE
}
bool NetServer::StartBroadcast() {
if(!net_evbase)
......@@ -63,7 +145,12 @@ void NetServer::StopServer() {
return;
if(duel_mode)
duel_mode->EndDuel();
#ifdef YGOPRO_SERVER_MODE // For solving the problem of connection lost after duel. See https://github.com/Fluorohydride/ygopro/issues/2067 for details.
timeval etv = { 0, 1 };
event_base_loopexit(net_evbase, &etv);
#else
event_base_loopexit(net_evbase, 0);
#endif
}
void NetServer::StopBroadcast() {
if(!net_evbase || !broadcast_ev)
......@@ -186,7 +273,11 @@ void NetServer::DisconnectPlayer(DuelPlayer* dp) {
void NetServer::HandleCTOSPacket(DuelPlayer* dp, unsigned char* data, int len) {
auto pdata = data;
unsigned char pktType = BufferIO::ReadUInt8(pdata);
#ifdef YGOPRO_SERVER_MODE
if((pktType != CTOS_SURRENDER) && (pktType != CTOS_CHAT) && (pktType != CTOS_REQUEST_FIELD) && (dp->state == 0xff || (dp->state && dp->state != pktType)))
#else
if((pktType != CTOS_SURRENDER) && (pktType != CTOS_CHAT) && (dp->state == 0xff || (dp->state && dp->state != pktType)))
#endif
return;
switch(pktType) {
case CTOS_RESPONSE: {
......@@ -357,6 +448,14 @@ void NetServer::HandleCTOSPacket(DuelPlayer* dp, unsigned char* data, int len) {
duel_mode->StartDuel(dp);
break;
}
#ifdef YGOPRO_SERVER_MODE
case CTOS_REQUEST_FIELD: {
if(!dp->game || !duel_mode->pduel)
break;
duel_mode->RequestField(dp);
break;
}
#endif
}
}
size_t NetServer::CreateChatPacket(unsigned char* src, int src_size, unsigned char* dst, uint16_t dst_player_type) {
......
......@@ -10,15 +10,30 @@ class NetServer {
private:
static std::unordered_map<bufferevent*, DuelPlayer> users;
static unsigned short server_port;
#ifndef YGOPRO_SERVER_MODE
static event_base* net_evbase;
#endif
static event* broadcast_ev;
static evconnlistener* listener;
#ifndef YGOPRO_LOG_IN_CHAT
static DuelMode* duel_mode;
#endif
static unsigned char net_server_write[SIZE_NETWORK_BUFFER];
static size_t last_sent;
public:
#ifdef YGOPRO_LOG_IN_CHAT
static DuelMode* duel_mode;
#endif
#ifdef YGOPRO_SERVER_MODE
static event_base* net_evbase;
static void InitDuel();
static void InitTestCard(int code);
static unsigned short StartServer(unsigned short port);
static bool IsCanIncreaseTime(unsigned short gameMsg, void *pdata, unsigned int len);
#else
static bool StartServer(unsigned short port);
#endif //YGOPRO_SERVER_MODE
static bool StartBroadcast();
static void StopServer();
static void StopBroadcast();
......@@ -67,6 +82,14 @@ public:
if(dp)
bufferevent_write(dp->bev, net_server_write, last_sent);
}
#ifdef YGOPRO_SERVER_MODE
static void ReSendToPlayers(DuelPlayer* dp1, DuelPlayer* dp2) {
if(dp1)
bufferevent_write(dp1->bev, net_server_write, last_sent);
if(dp2)
bufferevent_write(dp2->bev, net_server_write, last_sent);
}
#endif //YGOPRO_SERVER_MODE
};
}
......
......@@ -233,7 +233,13 @@ public:
virtual void Surrender(DuelPlayer* dp) = 0;
virtual void GetResponse(DuelPlayer* dp, unsigned char* pdata, unsigned int len) = 0;
virtual void TimeConfirm(DuelPlayer* dp) = 0;
#ifdef YGOPRO_SERVER_MODE
virtual void RequestField(DuelPlayer* dp) = 0;
#endif
virtual void EndDuel() = 0;
#ifdef YGOPRO_SERVER_MODE
virtual void TestCard(int code) = 0;
#endif
public:
event* etimer { nullptr };
......
include "lzma/."
if (SERVER_ZIP_SUPPORT or not SERVER_MODE) then
include "spmemvfs/."
end
project "YGOPro"
if SERVER_MODE then
if SERVER_PRO3_SUPPORT then
project "ygoserver"
kind "SharedLib"
else
project "ygopro"
kind "ConsoleApp"
end
cppdialect "C++14"
defines { "YGOPRO_SERVER_MODE" }
files { "gframe.cpp", "config.h",
"game.cpp", "game.h", "myfilesystem.h",
"deck_manager.cpp", "deck_manager.h",
"data_manager.cpp", "data_manager.h",
"replay.cpp", "replay.h",
"netserver.cpp", "netserver.h",
"single_duel.cpp", "single_duel.h",
"tag_duel.cpp", "tag_duel.h" }
if SERVER_PRO3_SUPPORT then
files { "gframe.h", "serverapi.cpp", "serverapi.h" }
defines { "SERVER_PRO3_SUPPORT" }
end
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
if SERVER_TAG_SURRENDER_CONFIRM then
defines { "SERVER_TAG_SURRENDER_CONFIRM" }
end
else
project "ygopro"
kind "WindowedApp"
cppdialect "C++14"
rtti "Off"
files { "*.cpp", "*.h", "CGUISkinSystem/*.cpp", "CGUISkinSystem/*.h", "CXMLRegistry/*.cpp", "CXMLRegistry/*.h" }
files { "*.cpp", "*.h" }
includedirs { "../ocgcore" }
links { "ocgcore", "clzma", "cspmemvfs", LUA_LIB_NAME, "sqlite3", "irrlicht", "freetype", "event" }
end
if BUILD_EVENT then
includedirs { "../event/include" }
......@@ -68,8 +111,17 @@ project "YGOPro"
filter "system:windows"
defines { "_IRR_WCHAR_FILESYSTEM" }
files "ygopro.rc"
if not SERVER_MODE then
libdirs { "$(DXSDK_DIR)Lib/x86" }
end
if SERVER_PRO2_SUPPORT then
targetname ("AI.Server")
end
if SERVER_MODE then
links { "ws2_32" }
else
links { "opengl32", "ws2_32", "winmm", "gdi32", "kernel32", "user32", "imm32", "Dnsapi" }
end
if USE_AUDIO and AUDIO_LIB == "irrklang" then
links { "irrKlang" }
if IRRKLANG_PRO then
......@@ -84,8 +136,10 @@ project "YGOPro"
filter "not system:windows"
links { "event_pthreads", "dl", "pthread", "resolv" }
filter "system:macosx"
if not SERVER_MODE then
links { "z" }
defines { "GL_SILENCE_DEPRECATION" }
end
if MAC_ARM then
buildoptions { "--target=arm64-apple-macos12" }
linkoptions { "-arch arm64" }
......@@ -95,7 +149,9 @@ project "YGOPro"
end
filter "system:linux"
linkoptions { "-static-libstdc++", "-static-libgcc" }
if not SERVER_MODE then
links { "GL", "X11", "Xxf86vm" }
end
if USE_AUDIO and AUDIO_LIB == "irrklang" then
links { "IrrKlang" }
linkoptions{ IRRKLANG_LINK_RPATH }
......
......@@ -3,7 +3,11 @@
#include "lzma/LzmaLib.h"
namespace ygo {
#ifdef YGOPRO_SERVER_MODE
extern unsigned short server_port;
extern unsigned short replay_mode;
#endif
Replay::Replay() {
replay_data = new unsigned char[MAX_REPLAY_SIZE];
comp_data = new unsigned char[MAX_COMP_SIZE];
......@@ -13,21 +17,47 @@ Replay::~Replay() {
delete[] comp_data;
}
void Replay::BeginRecord() {
#ifdef YGOPRO_SERVER_MODE
if(replay_mode & REPLAY_MODE_SAVE_IN_SERVER) {
#endif
if(!FileSystem::IsDirExists(L"./replay") && !FileSystem::MakeDir(L"./replay"))
return;
#ifdef _WIN32
if(is_recording)
CloseHandle(recording_fp);
#ifdef YGOPRO_SERVER_MODE
time_t nowtime = time(nullptr);
struct tm *localedtime = localtime(&nowtime);
wchar_t tmppath[80];
wcsftime(tmppath, 80, L"./replay/%Y-%m-%d %H-%M-%S %%u.yrp", localedtime);
wchar_t path[80];
myswprintf(path, tmppath, server_port);
recording_fp = CreateFileW(path, GENERIC_WRITE, 0, nullptr, CREATE_ALWAYS, FILE_FLAG_WRITE_THROUGH, nullptr);
#else
recording_fp = CreateFileW(L"./replay/_LastReplay.yrp", GENERIC_WRITE, 0, nullptr, CREATE_ALWAYS, FILE_FLAG_WRITE_THROUGH, nullptr);
#endif //YGOPRO_SERVER_MODE
if(recording_fp == INVALID_HANDLE_VALUE)
return;
#else
if(is_recording)
std::fclose(fp);
#ifdef YGOPRO_SERVER_MODE
time_t nowtime = time(nullptr);
struct tm *localedtime = localtime(&nowtime);
char tmppath[40];
strftime(tmppath, 40, "./replay/%Y-%m-%d %H-%M-%S %%u.yrp", localedtime);
char path[40];
std::sprintf(path, tmppath, server_port);
fp = std::fopen(path, "wb");
#else
fp = std::fopen("./replay/_LastReplay.yrp", "wb");
#endif //YGOPRO_SERVER_MODE
if(!fp)
return;
#endif
#ifdef YGOPRO_SERVER_MODE
}
#endif //YGOPRO_SERVER_MODE
replay_size = 0;
comp_size = 0;
is_replaying = false;
......@@ -35,6 +65,9 @@ void Replay::BeginRecord() {
}
void Replay::WriteHeader(ReplayHeader& header) {
pheader = header;
#ifdef YGOPRO_SERVER_MODE
if(!(replay_mode & REPLAY_MODE_SAVE_IN_SERVER)) return;
#endif
#ifdef _WIN32
DWORD size;
WriteFile(recording_fp, &header, sizeof(header), &size, nullptr);
......@@ -50,6 +83,9 @@ void Replay::WriteData(const void* data, size_t length, bool flush) {
return;
std::memcpy(replay_data + replay_size, data, length);
replay_size += length;
#ifdef YGOPRO_SERVER_MODE
if(!(replay_mode & REPLAY_MODE_SAVE_IN_SERVER)) return;
#endif
#ifdef _WIN32
DWORD size;
WriteFile(recording_fp, data, length, &size, nullptr);
......@@ -65,6 +101,9 @@ void Replay::WriteInt32(int32_t data, bool flush) {
void Replay::Flush() {
if(!is_recording)
return;
#ifdef YGOPRO_SERVER_MODE
if(!(replay_mode & REPLAY_MODE_SAVE_IN_SERVER)) return;
#endif
#ifdef _WIN32
#else
std::fflush(fp);
......@@ -73,10 +112,16 @@ void Replay::Flush() {
void Replay::EndRecord() {
if(!is_recording)
return;
#ifdef YGOPRO_SERVER_MODE
if(replay_mode & REPLAY_MODE_SAVE_IN_SERVER) {
#endif
#ifdef _WIN32
CloseHandle(recording_fp);
#else
std::fclose(fp);
#endif
#ifdef YGOPRO_SERVER_MODE
}
#endif
pheader.datasize = replay_size;
pheader.flag |= REPLAY_COMPRESSED;
......
......@@ -16,6 +16,15 @@ namespace ygo {
constexpr int MAX_REPLAY_SIZE = 0x20000;
constexpr int MAX_COMP_SIZE = UINT16_MAX + 1;
#ifdef YGOPRO_SERVER_MODE
#define REPLAY_MODE_SAVE_IN_SERVER 0x1
#define REPLAY_MODE_WATCHER_NO_SEND 0x2
#define REPLAY_MODE_INCLUDE_CHAT 0x4
#define DUEL_FLAG_SIDEINS 0x10
#define DUEL_FLAG_BO5 0x20
#endif // YGOPRO_SERVER_MODE
struct ReplayHeader {
unsigned int id{};
unsigned int version{};
......
......@@ -282,7 +282,6 @@ void ReplayMode::EndDuel() {
}
void ReplayMode::Restart(bool refresh) {
end_duel(pduel);
mainGame->dInfo.isInDuel = false;
mainGame->dInfo.isStarted = false;
mainGame->dInfo.isInDuel = false;
mainGame->dInfo.isFinished = true;
......
#include "serverapi.h"
namespace ygo {
extern "C" DECL_DLLEXPORT int start_server(const char* args) {
int argc = 1;
char** argv = new char* [13];
const char* server_name = "ygoserver";
argv[0] = new char[strlen(server_name) + 1];
strcpy(argv[0], server_name);
size_t argLength = strlen(args);
for (size_t i = 1, j = 0; j < argLength; ) {
while (args[j] == ' ' && j < argLength) { ++j; }
if (j < argLength) {
size_t tokenLength = 0;
while (args[j + tokenLength] != ' ' && args[j + tokenLength] != '\0') { ++tokenLength; }
char* currentToken = new char[tokenLength + 1];
strncpy(currentToken, args + j, tokenLength);
currentToken[tokenLength] = '\0';
argv[i] = currentToken;
i++;
j += tokenLength;
argc++;
}
}
int result = main(argc, argv);
for (int i = 1; i < argc; ++i) {
if (argv[i]) {
delete[] argv[i];
argv[i] = nullptr;
}
}
delete[] argv;
return result;
}
extern "C" DECL_DLLEXPORT void stop_server() {
NetServer::StopServer();
}
}
#ifndef SERVERAPI_H
#define SERVERAPI_H
#include "game.h"
#include "netserver.h"
#include "network.h"
#include "config.h"
#include "data_manager.h"
#include "gframe.h"
#include <event2/thread.h>
#include <memory>
#ifdef WIN32
#define DECL_DLLEXPORT __declspec(dllexport)
#else
#define DECL_DLLEXPORT
#endif
namespace ygo {
extern "C" DECL_DLLEXPORT int start_server(const char* args);
extern "C" DECL_DLLEXPORT void stop_server();
}
#endif // !SERVERAPI_H
This diff is collapsed.
......@@ -28,15 +28,30 @@ public:
int Analyze(unsigned char* msgbuffer, unsigned int len) override;
void GetResponse(DuelPlayer* dp, unsigned char* pdata, unsigned int len) override;
void TimeConfirm(DuelPlayer* dp) override;
#ifdef YGOPRO_SERVER_MODE
void RequestField(DuelPlayer* dp) override;
#endif
void EndDuel() override;
#ifdef YGOPRO_SERVER_MODE
void TestCard(int code) override;
#endif
void DuelEndProc();
void WaitforResponse(int playerid);
#ifdef YGOPRO_SERVER_MODE
void RefreshMzone(int player, int flag = 0x881fff, int use_cache = 1, DuelPlayer* dp = 0);
void RefreshSzone(int player, int flag = 0xe81fff, int use_cache = 1, DuelPlayer* dp = 0);
void RefreshHand(int player, int flag = 0x681fff, int use_cache = 1, DuelPlayer* dp = 0);
void RefreshGrave(int player, int flag = 0x81fff, int use_cache = 1, DuelPlayer* dp = 0);
void RefreshExtra(int player, int flag = 0xe81fff, int use_cache = 1, DuelPlayer* dp = 0);
void RefreshRemoved(int player, int flag = 0x81fff, int use_cache = 1, DuelPlayer* dp = 0);
#else
void RefreshMzone(int player, int flag = 0x881fff, int use_cache = 1);
void RefreshSzone(int player, int flag = 0xe81fff, int use_cache = 1);
void RefreshHand(int player, int flag = 0x681fff, int use_cache = 1);
void RefreshGrave(int player, int flag = 0x81fff, int use_cache = 1);
void RefreshExtra(int player, int flag = 0xe81fff, int use_cache = 1);
#endif
void RefreshSingle(int player, int location, int sequence, int flag = 0xf81fff);
static uint32_t MessageHandler(intptr_t fduel, uint32_t type);
......@@ -54,14 +69,29 @@ protected:
unsigned char hand_result[2]{};
unsigned char last_response{ 0 };
std::set<DuelPlayer*> observers;
#ifdef YGOPRO_SERVER_MODE
DuelPlayer* cache_recorder;
DuelPlayer* replay_recorder;
unsigned char turn_player;
unsigned short phase;
#endif
Replay last_replay;
bool match_mode{ false };
int match_kill{ 0 };
unsigned char duel_count{ 0 };
unsigned char tp_player{ 0 };
#ifdef YGOPRO_SERVER_MODE
unsigned char match_result[5]{};
#else
unsigned char match_result[3]{};
#endif
short time_limit[2]{};
short time_elapsed{ 0 };
#ifdef YGOPRO_SERVER_MODE
short time_compensator[2];
short time_backed[2];
unsigned char last_game_msg;
#endif
};
}
......
This diff is collapsed.
......@@ -28,15 +28,30 @@ public:
int Analyze(unsigned char* msgbuffer, unsigned int len) override;
void GetResponse(DuelPlayer* dp, unsigned char* pdata, unsigned int len) override;
void TimeConfirm(DuelPlayer* dp) override;
#ifdef YGOPRO_SERVER_MODE
void RequestField(DuelPlayer* dp) override;
#endif
void EndDuel() override;
#ifdef YGOPRO_SERVER_MODE
void TestCard(int code) override;
#endif
void DuelEndProc();
void WaitforResponse(int playerid);
#ifdef YGOPRO_SERVER_MODE
void RefreshMzone(int player, int flag = 0x881fff, int use_cache = 1, DuelPlayer* dp = 0);
void RefreshSzone(int player, int flag = 0xe81fff, int use_cache = 1, DuelPlayer* dp = 0);
void RefreshHand(int player, int flag = 0x681fff, int use_cache = 1, DuelPlayer* dp = 0);
void RefreshGrave(int player, int flag = 0x81fff, int use_cache = 1, DuelPlayer* dp = 0);
void RefreshExtra(int player, int flag = 0xe81fff, int use_cache = 1, DuelPlayer* dp = 0);
void RefreshRemoved(int player, int flag = 0x81fff, int use_cache = 1, DuelPlayer* dp = 0);
#else
void RefreshMzone(int player, int flag = 0x881fff, int use_cache = 1);
void RefreshSzone(int player, int flag = 0xe81fff, int use_cache = 1);
void RefreshHand(int player, int flag = 0x681fff, int use_cache = 1);
void RefreshGrave(int player, int flag = 0x81fff, int use_cache = 1);
void RefreshExtra(int player, int flag = 0xe81fff, int use_cache = 1);
#endif
void RefreshSingle(int player, int location, int sequence, int flag = 0xf81fff);
static uint32_t MessageHandler(intptr_t fduel, uint32_t type);
......@@ -50,6 +65,12 @@ protected:
DuelPlayer* pplayer[4];
DuelPlayer* cur_player[2];
std::set<DuelPlayer*> observers;
#ifdef YGOPRO_SERVER_MODE
DuelPlayer* cache_recorder;
DuelPlayer* replay_recorder;
int turn_player;
int phase;
#endif
bool ready[4];
bool surrender[4];
Deck pdeck[4];
......@@ -60,8 +81,14 @@ protected:
unsigned char turn_count;
short time_limit[2];
short time_elapsed;
#ifdef YGOPRO_SERVER_MODE
short time_compensator[2];
short time_backed[2];
unsigned char last_game_msg;
#endif
};
}
#endif //TAG_DUEL_H
This diff is collapsed.
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" }
......@@ -14,6 +14,13 @@ MINIAUDIO_SUPPORT_OPUS_VORBIS = true
MINIAUDIO_BUILD_OPUS_VORBIS = os.istarget("windows")
IRRKLANG_PRO_BUILD_IKPMP3 = false
SERVER_MODE = true
SERVER_ZIP_SUPPORT = false
SERVER_PRO2_SUPPORT = false
SERVER_PRO3_SUPPORT = false
SERVER_TAG_SURRENDER_CONFIRM = false
USE_IRRKLANG = false
-- read settings from command line or environment variables
newoption { trigger = "build-lua", category = "YGOPro - lua", description = "" }
......@@ -93,14 +100,20 @@ newoption { trigger = 'build-ikpmp3', category = "YGOPro - irrklang - ikpmp3", d
newoption { trigger = "winxp-support", category = "YGOPro", description = "" }
newoption { trigger = "mac-arm", category = "YGOPro", description = "Cross compile for Apple Silicon" }
-- koishipro specific
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 = "" }
newoption { trigger = "server-pro3-support", category = "YGOPro - server", description = "" }
newoption { trigger = "server-tag-surrender-confirm", category = "YGOPro - server", description = "" }
boolOptions = {
"compat-mycard",
"no-lua-safe",
"message-debug",
"no-side-check",
"enable-debug-func",
"log-lua-memory-size",
"log-in-chat",
}
for _, boolOption in ipairs(boolOptions) do
......@@ -199,6 +212,7 @@ if not BUILD_IRRLICHT then
IRRLICHT_LIB_DIR = GetParam("irrlicht-lib-dir") or os.findlib("irrlicht")
end
USE_AUDIO = not SERVER_MODE and not GetParam("no-audio")
if GetParam("no-audio") then
USE_AUDIO = false
elseif GetParam("no-use-miniaudio") then
......@@ -287,6 +301,37 @@ function spawn(cmd)
return nil
end
end
if GetParam("server-mode") then
SERVER_MODE = true
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
SERVER_TAG_SURRENDER_CONFIRM = true
end
if GetParam("server-pro3-support") then
SERVER_PRO3_SUPPORT = true
SERVER_ZIP_SUPPORT = true
SERVER_TAG_SURRENDER_CONFIRM = true
end
if GetParam("server-tag-surrender-confirm") then
SERVER_TAG_SURRENDER_CONFIRM = true
end
if SERVER_MODE then
BUILD_FREETYPE = false
BUILD_IKPMP3 = false
USE_IRRKLANG = false
IRRKLANG_PRO = false
if not SERVER_ZIP_SUPPORT then
BUILD_IRRLICHT = false
else
BUILD_IRRLICHT = true
end
end
function isRunningUnderRosetta()
local rosetta_result=spawn("sysctl -n sysctl.proc_translated 2>/dev/null")
......@@ -342,7 +387,6 @@ workspace "YGOPro"
configurations { "Release", "Debug" }
for _, numberOption in ipairs(numberOptions) do
ApplyNumber(numberOption)
end
......@@ -351,10 +395,11 @@ workspace "YGOPro"
ApplyBoolean(boolOption)
end
filter "system:windows"
defines { "WIN32", "_WIN32" }
if not SERVER_PRO3_SUPPORT then
entrypoint "mainCRTStartup"
end
systemversion "latest"
startproject "YGOPro"
if WINXP_SUPPORT then
......@@ -363,6 +408,9 @@ workspace "YGOPro"
else
defines { "WINVER=0x0601" } -- WIN7
end
if SERVER_PRO3_SUPPORT then
architecture "x86_64"
end
filter "system:macosx"
libdirs { "/usr/local/lib" }
......@@ -370,7 +418,9 @@ workspace "YGOPro"
if MAC_ARM then
buildoptions { "--target=arm64-apple-macos12" }
end
if not SERVER_MODE then
links { "OpenGL.framework", "Cocoa.framework", "IOKit.framework" }
end
filter "system:linux"
buildoptions { "-U_FORTIFY_SOURCE" }
......@@ -423,6 +473,11 @@ workspace "YGOPro"
filter "not action:vs*"
buildoptions { "-fno-strict-aliasing", "-Wno-multichar", "-Wno-format-security" }
if SERVER_PRO3_SUPPORT then
filter "not action:vs*"
pic "On"
end
filter {}
include "ocgcore"
......@@ -433,12 +488,15 @@ workspace "YGOPro"
if BUILD_EVENT then
include "event"
end
if BUILD_FREETYPE then
if BUILD_FREETYPE and not SERVER_MODE then
include "freetype"
end
if BUILD_IRRLICHT then
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
......
resource/gframe/ygopro.ico

159 KB | W: | H:

resource/gframe/ygopro.ico

17.1 KB | W: | H:

resource/gframe/ygopro.ico
resource/gframe/ygopro.ico
resource/gframe/ygopro.ico
resource/gframe/ygopro.ico
  • 2-up
  • Swipe
  • Onion skin
......@@ -11,13 +11,13 @@ BLOCK "StringFileInfo"
BEGIN
BLOCK "080404b0"
BEGIN
VALUE "FileDescription", "KoishiPro"
VALUE "InternalName", "KoishiPro"
VALUE "FileDescription", "YGOPRO Server Mode ver.Koishi"
VALUE "InternalName", "YGOPRO Server Mode"
VALUE "LegalCopyright", "Copyright (C) 2023 Nanahira"
VALUE "OriginalFilename", "ygopro.exe"
VALUE "ProductName", "KoishiPro"
VALUE "FileVersion", "Bumblebee"
VALUE "ProductVersion", "Bumblebee"
VALUE "ProductName", "YGOPRO Server Mode"
VALUE "FileVersion", "Server"
VALUE "ProductVersion", "Server"
END
END
BLOCK "VarFileInfo"
......
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