Commit 06145170 authored by nanahira's avatar nanahira

Merge branch 'server' of github.com:moecube/ygopro into server

parents 3a8c5e96 39dc7730
...@@ -7,21 +7,21 @@ install: ...@@ -7,21 +7,21 @@ install:
- git submodule update --init --recursive - git submodule update --init --recursive
# environment and system dependency # 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-beta1/premake-5.0.0-beta1-windows.zip ; exit 0" - 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-beta2/premake-5.0.0-beta2-windows.zip ; exit 0"
- 7z x premake-5.0.0-beta1-windows.zip - 7z x premake-5.0.0-beta2-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" - 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 - tar xf libevent-2.0.22-stable.tar.gz
- move libevent-2.0.22-stable event - move libevent-2.0.22-stable event
- xcopy /E event\WIN32-Code event\include - 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.3.6.tar.gz ; exit 0" - 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.3.6.tar.gz - tar xf lua-5.4.4.tar.gz
- move lua-5.3.6 lua - move lua-5.4.4 lua
- bash -c "curl --retry 5 --connect-timeout 30 --location --remote-header-name --remote-name https://www.sqlite.org/2020/sqlite-amalgamation-3310100.zip ; exit 0" - 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 -y sqlite-amalgamation-3310100.zip - 7z x -y sqlite-amalgamation-3390300.zip
- move sqlite-amalgamation-3310100 sqlite3 - move sqlite-amalgamation-3390300 sqlite3
# let premake happy # let premake happy
- xcopy /E premake\* . - xcopy /E premake\* .
...@@ -89,7 +89,7 @@ deploy: ...@@ -89,7 +89,7 @@ deploy:
branch: server branch: server
cache: cache:
- premake-5.0.0-beta1-windows.zip - premake-5.0.0-beta2-windows.zip
- libevent-2.0.22-stable.tar.gz - libevent-2.0.22-stable.tar.gz
- lua-5.3.6.tar.gz - lua-5.4.4.tar.gz
- sqlite-amalgamation-3310100.zip - sqlite-amalgamation-3390300.zip
No preview for this file type
...@@ -185,7 +185,7 @@ bool DataManager::Error(spmemvfs_db_t* pDB, sqlite3_stmt* pStmt) { ...@@ -185,7 +185,7 @@ bool DataManager::Error(spmemvfs_db_t* pDB, sqlite3_stmt* pStmt) {
spmemvfs_env_fini(); spmemvfs_env_fini();
return false; return false;
} }
#endif #endif //YGOPRO_SERVER_MODE
bool DataManager::GetData(int code, CardData* pData) { bool DataManager::GetData(int code, CardData* pData) {
auto cdit = _datas.find(code); auto cdit = _datas.find(code);
if(cdit == _datas.end()) if(cdit == _datas.end())
...@@ -402,7 +402,7 @@ byte* DataManager::ScriptReaderEx(const char* script_name, int* slen) { ...@@ -402,7 +402,7 @@ byte* DataManager::ScriptReaderEx(const char* script_name, int* slen) {
if(buffer) if(buffer)
return buffer; return buffer;
} }
#endif #endif //YGOPRO_SERVER_MODE
buffer = ScriptReaderExSingle("specials/", script_name, slen, 9); buffer = ScriptReaderExSingle("specials/", script_name, slen, 9);
if(buffer) if(buffer)
return buffer; return buffer;
...@@ -417,9 +417,8 @@ byte* DataManager::ScriptReaderExSingle(const char* path, const char* script_nam ...@@ -417,9 +417,8 @@ byte* DataManager::ScriptReaderExSingle(const char* path, const char* script_nam
return ScriptReader(sname, slen); return ScriptReader(sname, slen);
} }
byte* DataManager::ScriptReader(const char* script_name, int* slen) { byte* DataManager::ScriptReader(const char* script_name, int* slen) {
FILE *fp;
#ifdef YGOPRO_SERVER_MODE #ifdef YGOPRO_SERVER_MODE
fp = fopen(script_name, "rb"); FILE* fp = fopen(script_name, "rb");
if(!fp) if(!fp)
return 0; return 0;
int len = fread(scriptBuffer, 1, sizeof(scriptBuffer), fp); int len = fread(scriptBuffer, 1, sizeof(scriptBuffer), fp);
......
...@@ -23,7 +23,7 @@ public: ...@@ -23,7 +23,7 @@ public:
#else #else
void ReadStringConfLine(const char* linebuf); void ReadStringConfLine(const char* linebuf);
bool Error(sqlite3* pDB, sqlite3_stmt* pStmt = 0); bool Error(sqlite3* pDB, sqlite3_stmt* pStmt = 0);
#endif #endif //YGOPRO_SERVER_MODE
bool GetData(int code, CardData* pData); bool GetData(int code, CardData* pData);
code_pointer GetCodePointer(int code); code_pointer GetCodePointer(int code);
bool GetString(int code, CardString* pStr); bool GetString(int code, CardString* pStr);
......
...@@ -6,7 +6,9 @@ ...@@ -6,7 +6,9 @@
namespace ygo { namespace ygo {
#ifndef YGOPRO_SERVER_MODE
char DeckManager::deckBuffer[0x10000]; char DeckManager::deckBuffer[0x10000];
#endif
DeckManager deckManager; DeckManager deckManager;
void DeckManager::LoadLFListSingle(const char* path) { void DeckManager::LoadLFListSingle(const char* path) {
...@@ -253,7 +255,6 @@ bool DeckManager::LoadDeck(irr::gui::IGUIComboBox* cbCategory, irr::gui::IGUICom ...@@ -253,7 +255,6 @@ bool DeckManager::LoadDeck(irr::gui::IGUIComboBox* cbCategory, irr::gui::IGUICom
mainGame->deckBuilder.RefreshPackListScroll(); mainGame->deckBuilder.RefreshPackListScroll();
return res; return res;
} }
#endif
FILE* DeckManager::OpenDeckFile(const wchar_t* file, const char* mode) { FILE* DeckManager::OpenDeckFile(const wchar_t* file, const char* mode) {
#ifdef WIN32 #ifdef WIN32
FILE* fp = _wfopen(file, (wchar_t*)mode); FILE* fp = _wfopen(file, (wchar_t*)mode);
...@@ -412,4 +413,5 @@ bool DeckManager::DeleteCategory(const wchar_t* name) { ...@@ -412,4 +413,5 @@ bool DeckManager::DeleteCategory(const wchar_t* name) {
return false; return false;
return FileSystem::DeleteDir(localname); return FileSystem::DeleteDir(localname);
} }
#endif //YGOPRO_SERVER_MODE
} }
...@@ -5,7 +5,9 @@ ...@@ -5,7 +5,9 @@
#include "client_card.h" #include "client_card.h"
#include <unordered_map> #include <unordered_map>
#include <vector> #include <vector>
#ifndef YGOPRO_SERVER_MODE
#include <sstream> #include <sstream>
#endif
namespace ygo { namespace ygo {
...@@ -36,7 +38,9 @@ public: ...@@ -36,7 +38,9 @@ public:
Deck current_deck; Deck current_deck;
std::vector<LFList> _lfList; std::vector<LFList> _lfList;
#ifndef YGOPRO_SERVER_MODE
static char deckBuffer[0x10000]; static char deckBuffer[0x10000];
#endif
void LoadLFListSingle(const char* path); void LoadLFListSingle(const char* path);
void LoadLFList(); void LoadLFList();
...@@ -49,7 +53,6 @@ public: ...@@ -49,7 +53,6 @@ public:
void GetCategoryPath(wchar_t* ret, int index, const wchar_t* text); void GetCategoryPath(wchar_t* ret, int index, const wchar_t* text);
void GetDeckFile(wchar_t* ret, irr::gui::IGUIComboBox* cbCategory, irr::gui::IGUIComboBox* cbDeck); void GetDeckFile(wchar_t* ret, irr::gui::IGUIComboBox* cbCategory, irr::gui::IGUIComboBox* cbDeck);
bool LoadDeck(irr::gui::IGUIComboBox* cbCategory, irr::gui::IGUIComboBox* cbDeck); bool LoadDeck(irr::gui::IGUIComboBox* cbCategory, irr::gui::IGUIComboBox* cbDeck);
#endif
FILE* OpenDeckFile(const wchar_t* file, const char* mode); FILE* OpenDeckFile(const wchar_t* file, const char* mode);
IReadFile* OpenDeckReader(const wchar_t* file); IReadFile* OpenDeckReader(const wchar_t* file);
bool LoadDeck(const wchar_t* file, bool is_packlist = false); bool LoadDeck(const wchar_t* file, bool is_packlist = false);
...@@ -63,6 +66,7 @@ public: ...@@ -63,6 +66,7 @@ public:
bool CreateCategory(const wchar_t* name); bool CreateCategory(const wchar_t* name);
bool RenameCategory(const wchar_t* oldname, const wchar_t* newname); bool RenameCategory(const wchar_t* oldname, const wchar_t* newname);
bool DeleteCategory(const wchar_t* name); bool DeleteCategory(const wchar_t* name);
#endif //YGOPRO_SERVER_MODE
}; };
extern DeckManager deckManager; extern DeckManager deckManager;
......
...@@ -25,7 +25,7 @@ namespace ygo { ...@@ -25,7 +25,7 @@ namespace ygo {
Game* mainGame; Game* mainGame;
#ifdef YGOPRO_SERVER_MODE #ifdef YGOPRO_SERVER_MODE
unsigned short aServerPort; unsigned short server_port;
unsigned short replay_mode; unsigned short replay_mode;
unsigned int pre_seed[3]; unsigned int pre_seed[3];
HostInfo game_info; HostInfo game_info;
...@@ -36,9 +36,9 @@ void Game::MainServerLoop() { ...@@ -36,9 +36,9 @@ void Game::MainServerLoop() {
dataManager.LoadDB(L"cards.cdb"); dataManager.LoadDB(L"cards.cdb");
LoadExpansions(); LoadExpansions();
aServerPort = NetServer::StartServer(aServerPort); server_port = NetServer::StartServer(server_port);
NetServer::InitDuel(); NetServer::InitDuel();
printf("%u\n", aServerPort); printf("%u\n", server_port);
fflush(stdout); fflush(stdout);
while(NetServer::net_evbase) { while(NetServer::net_evbase) {
......
...@@ -645,8 +645,9 @@ public: ...@@ -645,8 +645,9 @@ public:
}; };
extern Game* mainGame; extern Game* mainGame;
#ifdef YGOPRO_SERVER_MODE #ifdef YGOPRO_SERVER_MODE
extern unsigned short aServerPort; extern unsigned short server_port;
extern unsigned short replay_mode; extern unsigned short replay_mode;
extern HostInfo game_info; extern HostInfo game_info;
extern unsigned int pre_seed[3]; extern unsigned int pre_seed[3];
......
...@@ -62,7 +62,7 @@ int main(int argc, char* argv[]) { ...@@ -62,7 +62,7 @@ int main(int argc, char* argv[]) {
ygo::Game _game; ygo::Game _game;
#ifdef YGOPRO_SERVER_MODE #ifdef YGOPRO_SERVER_MODE
enable_log = 1; enable_log = 1;
ygo::aServerPort = 7911; ygo::server_port = 7911;
ygo::replay_mode = 0; ygo::replay_mode = 0;
ygo::game_info.lflist = 0; ygo::game_info.lflist = 0;
ygo::game_info.rule = 0; ygo::game_info.rule = 0;
...@@ -83,7 +83,7 @@ int main(int argc, char* argv[]) { ...@@ -83,7 +83,7 @@ int main(int argc, char* argv[]) {
return 0; return 0;
} else } else
if(argc > 2) { if(argc > 2) {
ygo::aServerPort = atoi(argv[1]); ygo::server_port = atoi(argv[1]);
int lflist = atoi(argv[2]); int lflist = atoi(argv[2]);
if(lflist < 0) if(lflist < 0)
lflist = 999; lflist = 999;
......
...@@ -209,8 +209,7 @@ public: ...@@ -209,8 +209,7 @@ public:
#ifndef YGOPRO_SERVER_MODE #ifndef YGOPRO_SERVER_MODE
std::vector<file_unit> file_list; std::vector<file_unit> file_list;
#endif #endif
while ((dirp = readdir(dir)) != nullptr) while((dirp = readdir(dir)) != nullptr) {
{
#ifndef YGOPRO_SERVER_MODE #ifndef YGOPRO_SERVER_MODE
file_unit funit; file_unit funit;
#endif #endif
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
namespace ygo { namespace ygo {
#ifdef YGOPRO_SERVER_MODE #ifdef YGOPRO_SERVER_MODE
extern unsigned short aServerPort; extern unsigned short server_port;
extern unsigned short replay_mode; extern unsigned short replay_mode;
#endif #endif
Replay::Replay() Replay::Replay()
...@@ -23,7 +23,7 @@ Replay::~Replay() { ...@@ -23,7 +23,7 @@ Replay::~Replay() {
} }
void Replay::BeginRecord() { void Replay::BeginRecord() {
#ifdef YGOPRO_SERVER_MODE #ifdef YGOPRO_SERVER_MODE
if(replay_mode & 0x1) { if(replay_mode & REPLAY_MODE_SAVE_IN_SERVER) {
#endif #endif
if(!FileSystem::IsDirExists(L"./replay") && !FileSystem::MakeDir(L"./replay")) if(!FileSystem::IsDirExists(L"./replay") && !FileSystem::MakeDir(L"./replay"))
return; return;
...@@ -36,7 +36,7 @@ void Replay::BeginRecord() { ...@@ -36,7 +36,7 @@ void Replay::BeginRecord() {
wchar_t tmppath[80]; wchar_t tmppath[80];
wcsftime(tmppath, 80, L"./replay/%Y-%m-%d %H-%M-%S %%u.yrp", localedtime); wcsftime(tmppath, 80, L"./replay/%Y-%m-%d %H-%M-%S %%u.yrp", localedtime);
wchar_t path[80]; wchar_t path[80];
myswprintf(path, tmppath, aServerPort); myswprintf(path, tmppath, server_port);
recording_fp = CreateFileW(path, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_FLAG_WRITE_THROUGH, NULL); recording_fp = CreateFileW(path, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_FLAG_WRITE_THROUGH, NULL);
#else #else
recording_fp = CreateFileW(L"./replay/_LastReplay.yrp", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_FLAG_WRITE_THROUGH, NULL); recording_fp = CreateFileW(L"./replay/_LastReplay.yrp", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_FLAG_WRITE_THROUGH, NULL);
...@@ -52,7 +52,7 @@ void Replay::BeginRecord() { ...@@ -52,7 +52,7 @@ void Replay::BeginRecord() {
char tmppath[40]; char tmppath[40];
strftime(tmppath, 40, "./replay/%Y-%m-%d %H-%M-%S %%u.yrp", localedtime); strftime(tmppath, 40, "./replay/%Y-%m-%d %H-%M-%S %%u.yrp", localedtime);
char path[40]; char path[40];
sprintf(path, tmppath, aServerPort); sprintf(path, tmppath, server_port);
fp = fopen(path, "wb"); fp = fopen(path, "wb");
#else #else
fp = fopen("./replay/_LastReplay.yrp", "wb"); fp = fopen("./replay/_LastReplay.yrp", "wb");
...@@ -72,7 +72,7 @@ void Replay::BeginRecord() { ...@@ -72,7 +72,7 @@ void Replay::BeginRecord() {
void Replay::WriteHeader(ReplayHeader& header) { void Replay::WriteHeader(ReplayHeader& header) {
pheader = header; pheader = header;
#ifdef YGOPRO_SERVER_MODE #ifdef YGOPRO_SERVER_MODE
if(!(replay_mode & 0x1)) return; if(!(replay_mode & REPLAY_MODE_SAVE_IN_SERVER)) return;
#endif #endif
#ifdef _WIN32 #ifdef _WIN32
DWORD size; DWORD size;
...@@ -90,7 +90,7 @@ void Replay::WriteData(const void* data, int length, bool flush) { ...@@ -90,7 +90,7 @@ void Replay::WriteData(const void* data, int length, bool flush) {
memcpy(pdata, data, length); memcpy(pdata, data, length);
pdata += length; pdata += length;
#ifdef YGOPRO_SERVER_MODE #ifdef YGOPRO_SERVER_MODE
if(!(replay_mode & 0x1)) return; if(!(replay_mode & REPLAY_MODE_SAVE_IN_SERVER)) return;
#endif #endif
#ifdef _WIN32 #ifdef _WIN32
DWORD size; DWORD size;
...@@ -109,7 +109,7 @@ void Replay::WriteInt32(int data, bool flush) { ...@@ -109,7 +109,7 @@ void Replay::WriteInt32(int data, bool flush) {
*((int*)(pdata)) = data; *((int*)(pdata)) = data;
pdata += 4; pdata += 4;
#ifdef YGOPRO_SERVER_MODE #ifdef YGOPRO_SERVER_MODE
if(!(replay_mode & 0x1)) return; if(!(replay_mode & REPLAY_MODE_SAVE_IN_SERVER)) return;
#endif #endif
#ifdef _WIN32 #ifdef _WIN32
DWORD size; DWORD size;
...@@ -128,7 +128,7 @@ void Replay::WriteInt16(short data, bool flush) { ...@@ -128,7 +128,7 @@ void Replay::WriteInt16(short data, bool flush) {
*((short*)(pdata)) = data; *((short*)(pdata)) = data;
pdata += 2; pdata += 2;
#ifdef YGOPRO_SERVER_MODE #ifdef YGOPRO_SERVER_MODE
if(!(replay_mode & 0x1)) return; if(!(replay_mode & REPLAY_MODE_SAVE_IN_SERVER)) return;
#endif #endif
#ifdef _WIN32 #ifdef _WIN32
DWORD size; DWORD size;
...@@ -147,7 +147,7 @@ void Replay::WriteInt8(char data, bool flush) { ...@@ -147,7 +147,7 @@ void Replay::WriteInt8(char data, bool flush) {
*pdata = data; *pdata = data;
pdata++; pdata++;
#ifdef YGOPRO_SERVER_MODE #ifdef YGOPRO_SERVER_MODE
if(!(replay_mode & 0x1)) return; if(!(replay_mode & REPLAY_MODE_SAVE_IN_SERVER)) return;
#endif #endif
#ifdef _WIN32 #ifdef _WIN32
DWORD size; DWORD size;
...@@ -162,7 +162,7 @@ void Replay::Flush() { ...@@ -162,7 +162,7 @@ void Replay::Flush() {
if(!is_recording) if(!is_recording)
return; return;
#ifdef YGOPRO_SERVER_MODE #ifdef YGOPRO_SERVER_MODE
if(!(replay_mode & 0x1)) return; if(!(replay_mode & REPLAY_MODE_SAVE_IN_SERVER)) return;
#endif #endif
#ifdef _WIN32 #ifdef _WIN32
#else #else
...@@ -173,7 +173,7 @@ void Replay::EndRecord() { ...@@ -173,7 +173,7 @@ void Replay::EndRecord() {
if(!is_recording) if(!is_recording)
return; return;
#ifdef YGOPRO_SERVER_MODE #ifdef YGOPRO_SERVER_MODE
if(replay_mode & 0x1) { if(replay_mode & REPLAY_MODE_SAVE_IN_SERVER) {
#endif #endif
#ifdef _WIN32 #ifdef _WIN32
CloseHandle(recording_fp); CloseHandle(recording_fp);
......
...@@ -17,6 +17,11 @@ namespace ygo { ...@@ -17,6 +17,11 @@ namespace ygo {
#define MAX_REPLAY_SIZE 0x20000 #define MAX_REPLAY_SIZE 0x20000
#define MAX_COMP_SIZE 0x2000 #define MAX_COMP_SIZE 0x2000
#ifdef YGOPRO_SERVER_MODE
#define REPLAY_MODE_SAVE_IN_SERVER 0x1
#define REPLAY_MODE_WATCHER_NO_SEND 0x2
#endif // YGOPRO_SERVER_MODE
struct ReplayHeader { struct ReplayHeader {
unsigned int id; unsigned int id;
unsigned int version; unsigned int version;
......
...@@ -1814,7 +1814,7 @@ void SingleDuel::EndDuel() { ...@@ -1814,7 +1814,7 @@ void SingleDuel::EndDuel() {
NetServer::SendBufferToPlayer(players[0], STOC_REPLAY, replaybuf, sizeof(ReplayHeader) + last_replay.comp_size); NetServer::SendBufferToPlayer(players[0], STOC_REPLAY, replaybuf, sizeof(ReplayHeader) + last_replay.comp_size);
NetServer::ReSendToPlayer(players[1]); NetServer::ReSendToPlayer(players[1]);
#ifdef YGOPRO_SERVER_MODE #ifdef YGOPRO_SERVER_MODE
if(!(replay_mode & 0x2)) { if(!(replay_mode & REPLAY_MODE_WATCHER_NO_SEND)) {
for(auto oit = observers.begin(); oit != observers.end(); ++oit) for(auto oit = observers.begin(); oit != observers.end(); ++oit)
NetServer::ReSendToPlayer(*oit); NetServer::ReSendToPlayer(*oit);
NetServer::ReSendToPlayers(cache_recorder, replay_recorder); NetServer::ReSendToPlayers(cache_recorder, replay_recorder);
......
...@@ -1905,7 +1905,7 @@ void TagDuel::EndDuel() { ...@@ -1905,7 +1905,7 @@ void TagDuel::EndDuel() {
NetServer::ReSendToPlayer(players[2]); NetServer::ReSendToPlayer(players[2]);
NetServer::ReSendToPlayer(players[3]); NetServer::ReSendToPlayer(players[3]);
#ifdef YGOPRO_SERVER_MODE #ifdef YGOPRO_SERVER_MODE
if(!(replay_mode & 0x2)) { if(!(replay_mode & REPLAY_MODE_WATCHER_NO_SEND)) {
for(auto oit = observers.begin(); oit != observers.end(); ++oit) for(auto oit = observers.begin(); oit != observers.end(); ++oit)
NetServer::ReSendToPlayer(*oit); NetServer::ReSendToPlayer(*oit);
NetServer::ReSendToPlayers(cache_recorder, replay_recorder); NetServer::ReSendToPlayers(cache_recorder, replay_recorder);
......
Subproject commit 64c326410f815b48f5a42e78b59d4924c10f438a Subproject commit ac7997c0e493373c30f3485c136d4093e2f14ccd
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