Commit 945959d2 authored by DailyShana's avatar DailyShana

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

parents 30d80b7e 35e4eb1a
/expansions
/specials
/obj
/bin
/build
/event
/lua
/sqlite3
/replay
/deck
/.vscode
/gframe/ygopro.ico
/gframe/ygopro.rc
/gframe/ygopro.aps
ygopro
premake5.exe
premake5
[submodule "ocgcore"]
path = ocgcore
url = git@github.com:Fluorohydride/ygopro-core.git
url = https://github.com/mycard/ygopro-core
[submodule "script"]
path = script
url = git@github.com:Fluorohydride/ygopro-scripts.git
url = https://github.com/mycard/ygopro-scripts
language: cpp
dist: trusty
git:
submodules: false
addons:
ssh_known_hosts:
- github.com
apt:
packages:
- libevent-dev
- libsqlite3-dev
before_install:
- git submodule update --init --recursive
- wget -O - https://github.com/premake/premake-core/releases/download/v5.0.0-alpha10/premake-5.0.0-alpha10-linux.tar.gz | tar zfx -
- wget -O - https://www.lua.org/ftp/lua-5.3.4.tar.gz | tar zfx -; cd lua-5.3.4; sudo make linux install; cd ..
script:
- ./premake5 gmake
- cd build
- make config=release
## YGOPro
A script engine for "yu-gi-oh!" and sample gui
[中文说明](https://github.com/Fluorohydride/ygopro/wiki/%E4%B8%AD%E6%96%87%E8%AF%B4%E6%98%8E)
### 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.
### Color in card list:
#### Background:
* White = your card, Grey = your opponent's card
#### Text:
Cards in deck, extra deck and banished zone:
* Black = face-up, Blue = face-down
Xyz materials:
* Black = default, Blue = the owner of the xyz material is different from its controller
### 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.
### 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.
## 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)
一个YGOPro的服务端版本,运行后自动建立主机,并开启端口供YGOPro客户端连接。
现用于[萌卡](https://mycard.moe/)[YGOPro 233服](http://mercury233.me/ygosrv233/)
### Linux下编译
* 需要以下组件或工具
* gcc
* premake5
* libevent
* lua5.3
* sqlite3
* 可参考本项目 [.travis.yml](https://github.com/mycard/ygopro/blob/server/.travis.yml) 中的脚本
### Windows下编译
* 需要以下组件或工具
* Visual Studio
* premake5
* libevent
* lua5.3
* sqlite3
* 可参考本项目 [appveyor.yml](https://github.com/mycard/ygopro/blob/server/appveyor.yml) 中的脚本
### 运行
* 使用[ygopro-server](https://github.com/mycard/ygopro-server)运行
* 手动运行的参数是
* ./ygopro 0 0 0 1 F F F 8000 5 1 180 0
* 端口(0为随机)
* 禁卡表编号
* 卡片允许
* 决斗模式
* 旧规则
* 不检查卡组
* 不洗切卡组
* 初始LP
* 初始手牌数
* 每回合抽卡
* 每回合时间
* 录像保存模式
version: '{build}'
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-alpha10/premake-5.0.0-alpha10-windows.zip ; exit 0"
- 7z x premake-5.0.0-alpha10-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.3.4.tar.gz ; exit 0"
- tar xf lua-5.3.4.tar.gz
- move lua-5.3.4\src lua
- bash -c "curl --retry 5 --connect-timeout 30 --location --remote-header-name --remote-name https://www.sqlite.org/2017/sqlite-amalgamation-3200000.zip ; exit 0"
- 7z x sqlite-amalgamation-3200000.zip
- move sqlite-amalgamation-3200000 sqlite3
# let premake happy
- xcopy /E premake\* .
# premake
- premake5 vs2015
configuration: Release
build:
project: build/ygo.sln
parallel: true
after_build:
- ps: move bin\release\ygopro.exe .
test: off
artifacts:
- path: ygopro.exe
name: ygopro(server)
cache:
- premake-5.0.0-alpha10-windows.zip
- libevent-2.0.22-stable.tar.gz
- lua-5.3.4.tar.gz
- sqlite-amalgamation-3200000.zip
File added
......@@ -4,6 +4,7 @@
#include "config.h"
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
namespace ygo {
......@@ -47,6 +48,7 @@ typedef std::unordered_map<unsigned int, CardDataC>::const_iterator code_pointer
class ClientCard {
public:
#ifndef YGOPRO_SERVER_MODE
irr::core::matrix4 mTransform;
irr::core::vector3df curPos;
irr::core::vector3df curRot;
......@@ -119,6 +121,7 @@ public:
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 //YGOPRO_SERVER_MODE
};
}
......
......@@ -6,7 +6,7 @@
#include "image_manager.h"
#include "game.h"
#include "materials.h"
#include "../ocgcore/field.h"
#include "../ocgcore/common.h"
namespace ygo {
......
......@@ -4,6 +4,7 @@
#include "config.h"
#include <vector>
#include <set>
#include <map>
namespace ygo {
......
......@@ -53,11 +53,13 @@ inline int _wtoi(const wchar_t * s) {
}
#endif
#ifndef YGOPRO_SERVER_MODE
#include <irrlicht.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include "CGUITTFont.h"
#include "CGUIImageButton.h"
#endif //YGOPRO_SERVER_MODE
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
......@@ -68,14 +70,16 @@ inline int _wtoi(const wchar_t * s) {
#include "mysignal.h"
#include "mythread.h"
#include "../ocgcore/ocgapi.h"
#include "../ocgcore/card.h"
#include "../ocgcore/common.h"
#ifndef YGOPRO_SERVER_MODE
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
#endif //YGOPRO_SERVER_MODE
extern const unsigned short PRO_VERSION;
extern int enable_log;
......
......@@ -12,7 +12,11 @@ bool DataManager::LoadDB(const char* file) {
if(sqlite3_open_v2(file, &pDB, SQLITE_OPEN_READONLY, 0) != SQLITE_OK)
return Error(pDB);
sqlite3_stmt* pStmt;
#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);
CardDataC cd;
......@@ -43,6 +47,7 @@ bool DataManager::LoadDB(const char* file) {
cd.attribute = sqlite3_column_int(pStmt, 9);
cd.category = sqlite3_column_int(pStmt, 10);
_datas.insert(std::make_pair(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;
......@@ -58,6 +63,7 @@ bool DataManager::LoadDB(const char* file) {
}
}
_strings.emplace(cd.code, cs);
#endif //YGOPRO_SERVER_MODE
}
} while(step != SQLITE_DONE);
sqlite3_finalize(pStmt);
......
......@@ -4,7 +4,7 @@
#include "deck_manager.h"
#include "sound_manager.h"
#include "duelclient.h"
#include "../ocgcore/field.h"
#include "../ocgcore/common.h"
namespace ygo {
......
......@@ -4,11 +4,11 @@
#include "image_manager.h"
#include "sound_manager.h"
#include "single_mode.h"
#include "../ocgcore/field.h"
#include "../ocgcore/duel.h"
#include "../ocgcore/common.h"
#include "game.h"
#include "replay.h"
#include "replay_mode.h"
#include <algorithm>
namespace ygo {
......
......@@ -10,7 +10,8 @@
#include "replay_mode.h"
#include "single_mode.h"
#include "materials.h"
#include "../ocgcore/field.h"
#include "../ocgcore/common.h"
#include <algorithm>
namespace ygo {
......
#include "config.h"
#include "game.h"
#ifdef YGOPRO_SERVER_MODE
#include "data_manager.h"
#include "deck_manager.h"
#include "replay.h"
#else
#include "image_manager.h"
#include "data_manager.h"
#include "deck_manager.h"
......@@ -9,6 +14,7 @@
#include "duelclient.h"
#include "netserver.h"
#include "single_mode.h"
#endif //YGOPRO_SERVER_MODE
#ifndef _WIN32
#include <sys/types.h>
......@@ -26,6 +32,31 @@ namespace ygo {
Game* mainGame;
#ifdef YGOPRO_SERVER_MODE
unsigned short aServerPort;
unsigned short replay_mode;
HostInfo game_info;
void Game::MainServerLoop() {
initUtils();
deckManager.LoadLFList();
LoadExpansionDB();
dataManager.LoadDB("cards.cdb");
aServerPort = NetServer::StartServer(aServerPort);
NetServer::InitDuel();
printf("%u\n", aServerPort);
fflush(stdout);
while(NetServer::net_evbase) {
#ifdef WIN32
Sleep(200);
#else
usleep(200000);
#endif
}
}
#else //YGOPRO_SERVER_MODE
bool Game::Initialize() {
srand(time(0));
initUtils();
......@@ -847,6 +878,7 @@ void Game::SetStaticText(irr::gui::IGUIStaticText* pControl, u32 cWidth, irr::gu
dataManager.strBuffer[pbuffer] = 0;
pControl->setText(dataManager.strBuffer);
}
#endif //YGOPRO_SERVER_MODE
void Game::LoadExpansionDB() {
#ifdef _WIN32
char fpath[1000];
......@@ -879,6 +911,7 @@ void Game::LoadExpansionDB() {
}
#endif
}
#ifndef YGOPRO_SERVER_MODE
void Game::RefreshDeck(irr::gui::IGUIComboBox* cbDeck) {
cbDeck->clear();
#ifdef _WIN32
......@@ -1335,8 +1368,12 @@ void Game::ClearChatMsg() {
chatTiming[i] = 0;
}
}
#endif //YGOPRO_SERVER_MODE
void Game::AddDebugMsg(char* msg)
{
#ifdef YGOPRO_SERVER_MODE
fprintf(stderr, "%s\n", msg);
#else
if (enable_log & 0x1) {
wchar_t wbuf[1024];
BufferIO::DecodeUTF8(msg, wbuf);
......@@ -1353,6 +1390,7 @@ void Game::AddDebugMsg(char* msg)
fprintf(fp, "[%s][Script Error]: %s\n", timebuf, msg);
fclose(fp);
}
#endif //YGOPRO_SERVER_MODE
}
bool Game::MakeDirectory(const std::string folder) {
std::string folder_builder;
......@@ -1380,6 +1418,10 @@ void Game::initUtils() {
MakeDirectory("replay");
//cards from extra pack
MakeDirectory("expansions");
#ifdef YGOPRO_SERVER_MODE
//special scripts
MakeDirectory("specials");
#else
//files in ygopro-starter-pack
MakeDirectory("deck");
MakeDirectory("single");
......@@ -1401,7 +1443,9 @@ void Game::initUtils() {
//pics
MakeDirectory("pics");
MakeDirectory("pics/field");
#endif //YGOPRO_SERVER_MODE
}
#ifndef YGOPRO_SERVER_MODE
void Game::ClearTextures() {
matManager.mCard.setTexture(0, 0);
imgCard->setImage(imageManager.tCover[0]);
......@@ -1489,5 +1533,6 @@ void Game::SetCursor(ECURSOR_ICON icon) {
cursor->setActiveIcon(icon);
}
}
#endif //YGOPRO_SERVER_MODE
}
......@@ -2,15 +2,20 @@
#define GAME_H
#include "config.h"
#ifndef YGOPRO_SERVER_MODE
#include "client_field.h"
#include "deck_con.h"
#include "menu_handler.h"
#else
#include "netserver.h"
#endif //YGOPRO_SERVER_MODE
#include <unordered_map>
#include <vector>
#include <list>
namespace ygo {
#ifndef YGOPRO_SERVER_MODE
struct Config {
bool use_d3d;
bool use_image_scale;
......@@ -95,11 +100,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 LoadExpansionDB();
void AddDebugMsg(char* msgbuf);
bool MakeDirectory(const std::string folder);
void initUtils();
#else
void MainLoop();
void BuildProjectionMatrix(irr::core::matrix4& mProjection, f32 left, f32 right, f32 bottom, f32 top, f32 znear, f32 zfar);
void InitStaticText(irr::gui::IGUIStaticText* pControl, u32 cWidth, u32 cHeight, irr::gui::CGUITTFont* font, const wchar_t* text);
......@@ -467,9 +480,15 @@ public:
irr::gui::IGUIButton* btnChainWhenAvail;
//cancel or finish
irr::gui::IGUIButton* btnCancelOrFinish;
#endif //YGOPRO_SERVER_MODE
};
extern Game* mainGame;
#ifdef YGOPRO_SERVER_MODE
extern unsigned short aServerPort;
extern unsigned short replay_mode;
extern HostInfo game_info;
#endif
}
......
......@@ -7,6 +7,7 @@
#endif
int enable_log = 0;
#ifndef YGOPRO_SERVER_MODE
bool exit_on_return = false;
bool open_file = false;
wchar_t open_file_name[256] = L"";
......@@ -35,6 +36,7 @@ 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
......@@ -68,6 +70,53 @@ int main(int argc, char* argv[]) {
evthread_use_pthreads();
#endif //_WIN32
ygo::Game _game;
#ifdef YGOPRO_SERVER_MODE
enable_log = 1;
ygo::aServerPort = 7911;
ygo::replay_mode = 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 = DEFAULT_DUEL_RULE;
ygo::game_info.time_limit = 180;
if(argc > 1) {
ygo::aServerPort = 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 = DEFAULT_DUEL_RULE - 1;
else
ygo::game_info.duel_rule = 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]);
}
ygo::mainGame = &_game;
ygo::mainGame->MainServerLoop();
return 0;
#else //YGOPRO_SERVER_MODE
ygo::mainGame = &_game;
if(!ygo::mainGame->Initialize())
return 0;
......@@ -182,5 +231,6 @@ int main(int argc, char* argv[]) {
#else
#endif //_WIN32
#endif //YGOPRO_SERVER_MODE
return EXIT_SUCCESS;
}
......@@ -13,7 +13,52 @@ char NetServer::net_server_read[0x2000];
char NetServer::net_server_write[0x2000];
unsigned short 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);
}
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();
......@@ -34,7 +79,15 @@ bool NetServer::StartServer(unsigned short port) {
}
evconnlistener_set_error_cb(listener, ServerAcceptError);
Thread::NewThread(ServerThread, net_evbase);
#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)
......@@ -173,7 +226,11 @@ void NetServer::DisconnectPlayer(DuelPlayer* dp) {
void NetServer::HandleCTOSPacket(DuelPlayer* dp, char* data, unsigned int len) {
char* 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: {
......@@ -303,6 +360,14 @@ void NetServer::HandleCTOSPacket(DuelPlayer* dp, char* data, unsigned 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
}
}
......
......@@ -14,7 +14,9 @@ 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;
static DuelMode* duel_mode;
......@@ -23,7 +25,13 @@ private:
static unsigned short last_sent;
public:
#ifdef YGOPRO_SERVER_MODE
static event_base* net_evbase;
static void InitDuel();
static unsigned short StartServer(unsigned short port);
#else
static bool StartServer(unsigned short port);
#endif //YGOPRO_SERVER_MODE
static bool StartBroadcast();
static void StopServer();
static void StopBroadcast();
......@@ -68,6 +76,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
};
}
......
......@@ -134,6 +134,9 @@ public:
virtual void Surrender(DuelPlayer* dp) {}
virtual void GetResponse(DuelPlayer* dp, void* pdata, unsigned int len) {}
virtual void TimeConfirm(DuelPlayer* dp) {}
#ifdef YGOPRO_SERVER_MODE
virtual void RequestField(DuelPlayer* dp) {}
#endif
virtual void EndDuel() {};
public:
......@@ -175,6 +178,9 @@ public:
#define CTOS_HS_NOTREADY 0x23
#define CTOS_HS_KICK 0x24
#define CTOS_HS_START 0x25
#ifdef YGOPRO_SERVER_MODE
#define CTOS_REQUEST_FIELD 0x30
#endif
#define STOC_GAME_MSG 0x1
#define STOC_ERROR_MSG 0x2
......@@ -196,6 +202,9 @@ public:
#define STOC_HS_PLAYER_ENTER 0x20
#define STOC_HS_PLAYER_CHANGE 0x21
#define STOC_HS_WATCH_CHANGE 0x22
#ifdef YGOPRO_SERVER_MODE
#define STOC_FIELD_FINISH 0x30
#endif
#define PLAYERCHANGE_OBSERVE 0x8
#define PLAYERCHANGE_READY 0x9
......
include "lzma/."
project "ygopro"
kind "WindowedApp"
kind "ConsoleApp"
defines { "YGOPRO_SERVER_MODE" }
files { "**.cpp", "**.cc", "**.c", "**.h" }
excludes "lzma/**"
files { "gframe.cpp", "config.h",
"game.cpp", "game.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" }
includedirs { "../ocgcore" }
links { "ocgcore", "clzma", "Irrlicht", "freetype", "sqlite3", "lua" , "event" }
links { "ocgcore", "clzma", "sqlite3", "lua" , "event"}
configuration "windows"
files "ygopro.rc"
excludes "CGUIButton.cpp"
includedirs { "../irrlicht/include", "../freetype/include", "../event/include", "../sqlite3" }
if USE_IRRKLANG then
defines { "YGOPRO_USE_IRRKLANG" }
links { "irrKlang" }
includedirs { "../irrklang/include" }
libdirs { "../irrklang/lib/Win32-visualStudio" }
if IRRKLANG_PRO then
defines { "IRRKLANG_STATIC" }
links { "ikpmp3" }
end
end
links { "opengl32", "ws2_32", "winmm", "gdi32", "kernel32", "user32", "imm32" }
configuration {"windows", "not vs*"}
includedirs { "/mingw/include/irrlicht", "/mingw/include/freetype2" }
includedirs { "../event/include", "../sqlite3" }
links { "ws2_32" }
configuration "not vs*"
buildoptions { "-std=gnu++0x", "-fno-rtti" }
configuration "not windows"
includedirs { "/usr/include/lua", "/usr/include/lua5.3", "/usr/include/lua/5.3", "/usr/include/irrlicht", "/usr/include/freetype2" }
excludes { "COSOperator.*" }
links { "event_pthreads", "GL", "dl", "pthread" }
configuration "linux"
if USE_IRRKLANG then
defines { "YGOPRO_USE_IRRKLANG" }
links { "IrrKlang" }
linkoptions{ "-Wl,-rpath=./irrklang/bin/linux-gcc-64/" }
libdirs { "../irrklang/bin/linux-gcc-64" }
includedirs { "../irrklang/include" }
end
includedirs { "/usr/include/lua", "/usr/include/lua5.3", "/usr/include/lua/5.3" }
links { "event_pthreads", "dl", "pthread" }
#include "replay.h"
#include "../ocgcore/ocgapi.h"
#include "../ocgcore/card.h"
#include "../ocgcore/common.h"
#include <algorithm>
#include "lzma/LzmaLib.h"
namespace ygo {
#ifdef YGOPRO_SERVER_MODE
extern unsigned short aServerPort;
extern unsigned short replay_mode;
#endif
Replay::Replay() {
is_recording = false;
is_replaying = false;
......@@ -17,24 +21,53 @@ Replay::~Replay() {
delete[] comp_data;
}
void Replay::BeginRecord() {
#ifdef YGOPRO_SERVER_MODE
if(replay_mode > 0) {
#endif
#ifdef _WIN32
if(is_recording)
CloseHandle(recording_fp);
#ifdef YGOPRO_SERVER_MODE
time_t nowtime = time(NULL);
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, aServerPort);
recording_fp = CreateFileW(path, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_FLAG_WRITE_THROUGH, NULL);
#else
recording_fp = CreateFileW(L"./replay/_LastReplay.yrp", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_FLAG_WRITE_THROUGH, NULL);
#endif //YGOPRO_SERVER_MODE
if(recording_fp == INVALID_HANDLE_VALUE)
return;
#else
if(is_recording)
fclose(fp);
#ifdef YGOPRO_SERVER_MODE
time_t nowtime = time(NULL);
struct tm *localedtime = localtime(&nowtime);
char tmppath[40];
strftime(tmppath, 40, "./replay/%Y-%m-%d %H-%M-%S %%u.yrp", localedtime);
char path[40];
sprintf(path, tmppath, aServerPort);
fp = fopen(path, "wb");
#else
fp = fopen("./replay/_LastReplay.yrp", "wb");
#endif //YGOPRO_SERVER_MODE
if(!fp)
return;
#endif
#ifdef YGOPRO_SERVER_MODE
}
#endif //YGOPRO_SERVER_MODE
pdata = replay_data;
is_recording = true;
}
void Replay::WriteHeader(ReplayHeader& header) {
pheader = header;
#ifdef YGOPRO_SERVER_MODE
if(replay_mode == 0) return;
#endif
#ifdef _WIN32
DWORD size;
WriteFile(recording_fp, &header, sizeof(header), &size, NULL);
......@@ -48,6 +81,9 @@ void Replay::WriteData(const void* data, unsigned int length, bool flush) {
return;
memcpy(pdata, data, length);
pdata += length;
#ifdef YGOPRO_SERVER_MODE
if(replay_mode == 0) return;
#endif
#ifdef _WIN32
DWORD size;
WriteFile(recording_fp, data, length, &size, NULL);
......@@ -62,6 +98,9 @@ void Replay::WriteInt32(int data, bool flush) {
return;
*((int*)(pdata)) = data;
pdata += 4;
#ifdef YGOPRO_SERVER_MODE
if(replay_mode == 0) return;
#endif
#ifdef _WIN32
DWORD size;
WriteFile(recording_fp, &data, sizeof(int), &size, NULL);
......@@ -76,6 +115,9 @@ void Replay::WriteInt16(short data, bool flush) {
return;
*((short*)(pdata)) = data;
pdata += 2;
#ifdef YGOPRO_SERVER_MODE
if(replay_mode == 0) return;
#endif
#ifdef _WIN32
DWORD size;
WriteFile(recording_fp, &data, sizeof(short), &size, NULL);
......@@ -90,6 +132,9 @@ void Replay::WriteInt8(char data, bool flush) {
return;
*pdata = data;
pdata++;
#ifdef YGOPRO_SERVER_MODE
if(replay_mode == 0) return;
#endif
#ifdef _WIN32
DWORD size;
WriteFile(recording_fp, &data, sizeof(char), &size, NULL);
......@@ -102,6 +147,9 @@ void Replay::WriteInt8(char data, bool flush) {
void Replay::Flush() {
if(!is_recording)
return;
#ifdef YGOPRO_SERVER_MODE
if(replay_mode == 0) return;
#endif
#ifdef _WIN32
#else
fflush(fp);
......@@ -110,10 +158,16 @@ void Replay::Flush() {
void Replay::EndRecord() {
if(!is_recording)
return;
#ifdef YGOPRO_SERVER_MODE
if(replay_mode > 0) {
#endif
#ifdef _WIN32
CloseHandle(recording_fp);
#else
fclose(fp);
#endif
#ifdef YGOPRO_SERVER_MODE
}
#endif
pheader.datasize = pdata - replay_data;
pheader.flag |= REPLAY_COMPRESSED;
......
......@@ -2,8 +2,7 @@
#include "duelclient.h"
#include "game.h"
#include "single_mode.h"
#include "../ocgcore/duel.h"
#include "../ocgcore/field.h"
#include "../ocgcore/common.h"
#include "../ocgcore/mtrandom.h"
namespace ygo {
......
This diff is collapsed.
......@@ -27,15 +27,27 @@ public:
virtual int Analyze(char* msgbuffer, unsigned int len);
virtual void GetResponse(DuelPlayer* dp, void* pdata, unsigned int len);
virtual void TimeConfirm(DuelPlayer* dp);
#ifdef YGOPRO_SERVER_MODE
virtual void RequestField(DuelPlayer* dp);
#endif
virtual void EndDuel();
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 = 0x681fff, int use_cache = 1, DuelPlayer* dp = 0);
void RefreshHand(int player, int flag = 0x781fff, 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 = 0x81fff, 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 = 0x681fff, int use_cache = 1);
void RefreshHand(int player, int flag = 0x781fff, int use_cache = 1);
void RefreshGrave(int player, int flag = 0x81fff, int use_cache = 1);
void RefreshExtra(int player, int flag = 0x81fff, int use_cache = 1);
#endif
void RefreshSingle(int player, int location, int sequence, int flag = 0xf81fff);
static byte* ScriptReaderEx(const char* script_name, int* slen);
......@@ -51,6 +63,13 @@ protected:
unsigned char hand_result[2];
unsigned char last_response;
std::set<DuelPlayer*> observers;
#ifdef YGOPRO_SERVER_MODE
DuelPlayer* cache_recorder;
DuelPlayer* replay_recorder;
int lp[2];
unsigned char turn_player;
unsigned short phase;
#endif
Replay last_replay;
bool match_mode;
int match_kill;
......
#include "single_mode.h"
#include "duelclient.h"
#include "game.h"
#include "../ocgcore/duel.h"
#include "../ocgcore/field.h"
#include "../ocgcore/common.h"
#include "../ocgcore/mtrandom.h"
namespace ygo {
......
This diff is collapsed.
......@@ -27,15 +27,27 @@ public:
virtual int Analyze(char* msgbuffer, unsigned int len);
virtual void GetResponse(DuelPlayer* dp, void* pdata, unsigned int len);
virtual void TimeConfirm(DuelPlayer* dp);
#ifdef YGOPRO_SERVER_MODE
virtual void RequestField(DuelPlayer* dp);
#endif
virtual void EndDuel();
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 = 0x681fff, int use_cache = 1, DuelPlayer* dp = 0);
void RefreshHand(int player, int flag = 0x781fff, 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 = 0x81fff, 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 = 0x681fff, int use_cache = 1);
void RefreshHand(int player, int flag = 0x781fff, int use_cache = 1);
void RefreshGrave(int player, int flag = 0x81fff, int use_cache = 1);
void RefreshExtra(int player, int flag = 0x81fff, int use_cache = 1);
#endif
void RefreshSingle(int player, int location, int sequence, int flag = 0xf81fff);
static byte* ScriptReaderEx(const char* script_name, int* slen);
......@@ -47,6 +59,13 @@ protected:
DuelPlayer* pplayer[4];
DuelPlayer* cur_player[2];
std::set<DuelPlayer*> observers;
#ifdef YGOPRO_SERVER_MODE
DuelPlayer* cache_recorder;
DuelPlayer* replay_recorder;
int lp[2];
int turn_player;
int phase;
#endif
bool ready[4];
Deck pdeck[4];
int deck_error[4];
......
Subproject commit 7da0970abec7155fe7de65e86e905a971c56db79
Subproject commit f3fb923b305735f09080866d57f14e2895f55da6
project "event"
kind "StaticLib"
includedirs { "include", "compat" }
files { "event.c", "evthread.c", "buffer.c", "bufferevent.c", "bufferevent_sock.c",
"bufferevent_filter.c", "bufferevent_pair.c", "listener.c", "bufferevent_ratelim.c",
"evmap.c", "log.c", "evutil.c", "evutil_rand.c", "strlcpy.c", "signal.c",
"event_tagging.c", "http.c", "evdns.c", "evrpc.c" }
configuration "windows"
files { "win32select.c", "evthread_win32.c", "buffer_iocp.c", "event_iocp.c", "bufferevent_async.c" }
1 ICON "ygopro.ico"
1 VERSIONINFO
FILEVERSION 1, 0, 33, 12
PRODUCTVERSION 1, 0, 33, 12
FILEOS 0x4
FILETYPE 0x1
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "080404b0"
BEGIN
VALUE "FileDescription", "YGOPRO Server Mode ver.233"
VALUE "InternalName", "YGOPRO Server Mode"
VALUE "LegalCopyright", "Copyright (C) 2016 Fluorohydride"
VALUE "OriginalFilename", "ygopro.exe"
VALUE "ProductName", "YGOPRO Server Mode"
VALUE "FileVersion", "1.033.C.233"
VALUE "ProductVersion", "1.033.C.233"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x804, 1200
END
END
project "lua"
kind "StaticLib"
files { "*.c", "*.h" }
removefiles { "luac.c" }
project "sqlite3"
kind "StaticLib"
files { "sqlite3.c", "sqlite3.h" }
solution "ygo"
location "build"
language "C++"
objdir "obj"
configurations { "Release", "Debug" }
configuration "windows"
defines { "WIN32", "_WIN32" }
configuration "linux"
defines { "LUA_USE_LINUX" }
configuration "Release"
targetdir "bin/release"
configuration "Debug"
symbols "On"
defines "_DEBUG"
targetdir "bin/debug"
configuration { "Release", "vs*" }
optimize "Speed"
flags { "StaticRuntime", "LinkTimeOptimization" }
disablewarnings { "4244", "4267", "4838", "4577", "4819", "4018", "4996", "4477" }
configuration { "Release", "not vs*" }
symbols "On"
defines "NDEBUG"
buildoptions "-march=native"
configuration { "Debug", "vs*" }
defines { "_ITERATOR_DEBUG_LEVEL=0" }
configuration "vs*"
flags "EnableSSE2"
defines { "_CRT_SECURE_NO_WARNINGS" }
configuration "not vs*"
buildoptions { "-fno-strict-aliasing", "-Wno-multichar" }
configuration {"not vs*", "windows"}
buildoptions { "-static-libgcc" }
startproject "ygopro"
include "ocgcore"
include "gframe"
if os.is("windows") then
include "event"
include "lua"
include "sqlite3"
end
Subproject commit a7ac36907a08e612671914681a808af971290bc9
Subproject commit 8a38d1c2d9b1c7a9415cf1e4e3155ec44d445b39
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