Commit 47935247 authored by mercury233's avatar mercury233

Merge branch 'master' of https://github.com/Fluorohydride/ygopro into server

parents 43a3e6ba de2ec1ba
...@@ -67,11 +67,11 @@ inline int myswprintf(wchar_t(&buf)[N], const wchar_t* fmt, TR... args) { ...@@ -67,11 +67,11 @@ inline int myswprintf(wchar_t(&buf)[N], const wchar_t* fmt, TR... args) {
#include <stdlib.h> #include <stdlib.h>
#include <memory.h> #include <memory.h>
#include <time.h> #include <time.h>
#include <thread>
#include "bufferio.h" #include "bufferio.h"
#include "myfilesystem.h" #include "myfilesystem.h"
#include "mymutex.h" #include "mymutex.h"
#include "mysignal.h" #include "mysignal.h"
#include "mythread.h"
#include "../ocgcore/ocgapi.h" #include "../ocgcore/ocgapi.h"
#include "../ocgcore/common.h" #include "../ocgcore/common.h"
......
...@@ -27,7 +27,7 @@ bool DuelClient::is_swapping = false; ...@@ -27,7 +27,7 @@ bool DuelClient::is_swapping = false;
int DuelClient::select_hint = 0; int DuelClient::select_hint = 0;
int DuelClient::select_unselect_hint = 0; int DuelClient::select_unselect_hint = 0;
int DuelClient::last_select_hint = 0; int DuelClient::last_select_hint = 0;
char DuelClient::last_successful_msg[2048]; char DuelClient::last_successful_msg[0x2000];
unsigned int DuelClient::last_successful_msg_length = 0; unsigned int DuelClient::last_successful_msg_length = 0;
wchar_t DuelClient::event_string[256]; wchar_t DuelClient::event_string[256];
mtrandom DuelClient::rnd; mtrandom DuelClient::rnd;
...@@ -65,7 +65,7 @@ bool DuelClient::StartClient(unsigned int ip, unsigned short port, bool create_g ...@@ -65,7 +65,7 @@ bool DuelClient::StartClient(unsigned int ip, unsigned short port, bool create_g
event* resp_event = event_new(client_base, 0, EV_TIMEOUT, ConnectTimeout, 0); event* resp_event = event_new(client_base, 0, EV_TIMEOUT, ConnectTimeout, 0);
event_add(resp_event, &timeout); event_add(resp_event, &timeout);
} }
Thread::NewThread(ClientThread, 0); std::thread(ClientThread).detach();
return true; return true;
} }
void DuelClient::ConnectTimeout(evutil_socket_t fd, short events, void* arg) { void DuelClient::ConnectTimeout(evutil_socket_t fd, short events, void* arg) {
...@@ -225,7 +225,7 @@ void DuelClient::ClientEvent(bufferevent *bev, short events, void *ctx) { ...@@ -225,7 +225,7 @@ void DuelClient::ClientEvent(bufferevent *bev, short events, void *ctx) {
event_base_loopexit(client_base, 0); event_base_loopexit(client_base, 0);
} }
} }
int DuelClient::ClientThread(void* param) { int DuelClient::ClientThread() {
event_base_dispatch(client_base); event_base_dispatch(client_base);
bufferevent_free(client_bev); bufferevent_free(client_bev);
event_base_free(client_base); event_base_free(client_base);
...@@ -3884,7 +3884,7 @@ void DuelClient::BeginRefreshHost() { ...@@ -3884,7 +3884,7 @@ void DuelClient::BeginRefreshHost() {
timeval timeout = {3, 0}; timeval timeout = {3, 0};
resp_event = event_new(broadev, reply, EV_TIMEOUT | EV_READ | EV_PERSIST, BroadcastReply, broadev); resp_event = event_new(broadev, reply, EV_TIMEOUT | EV_READ | EV_PERSIST, BroadcastReply, broadev);
event_add(resp_event, &timeout); event_add(resp_event, &timeout);
Thread::NewThread(RefreshThread, broadev); std::thread(RefreshThread, broadev).detach();
//send request //send request
SOCKADDR_IN local; SOCKADDR_IN local;
local.sin_family = AF_INET; local.sin_family = AF_INET;
...@@ -3913,8 +3913,7 @@ void DuelClient::BeginRefreshHost() { ...@@ -3913,8 +3913,7 @@ void DuelClient::BeginRefreshHost() {
closesocket(sSend); closesocket(sSend);
} }
} }
int DuelClient::RefreshThread(void * arg) { int DuelClient::RefreshThread(event_base* broadev) {
event_base* broadev = (event_base*)arg;
event_base_dispatch(broadev); event_base_dispatch(broadev);
evutil_socket_t fd; evutil_socket_t fd;
event_get_assignment(resp_event, 0, &fd, 0, 0, 0); event_get_assignment(resp_event, 0, &fd, 0, 0, 0);
......
...@@ -33,7 +33,7 @@ private: ...@@ -33,7 +33,7 @@ private:
static int select_hint; static int select_hint;
static int select_unselect_hint; static int select_unselect_hint;
static int last_select_hint; static int last_select_hint;
static char last_successful_msg[2048]; static char last_successful_msg[0x2000];
static unsigned int last_successful_msg_length; static unsigned int last_successful_msg_length;
static wchar_t event_string[256]; static wchar_t event_string[256];
static mtrandom rnd; static mtrandom rnd;
...@@ -43,7 +43,7 @@ public: ...@@ -43,7 +43,7 @@ public:
static void StopClient(bool is_exiting = false); static void StopClient(bool is_exiting = false);
static void ClientRead(bufferevent* bev, void* ctx); static void ClientRead(bufferevent* bev, void* ctx);
static void ClientEvent(bufferevent *bev, short events, void *ctx); static void ClientEvent(bufferevent *bev, short events, void *ctx);
static int ClientThread(void* param); static int ClientThread();
static void HandleSTOCPacketLan(char* data, unsigned int len); static void HandleSTOCPacketLan(char* data, unsigned int len);
static int ClientAnalyze(char* msg, unsigned int len); static int ClientAnalyze(char* msg, unsigned int len);
static void SwapField(); static void SwapField();
...@@ -80,7 +80,7 @@ protected: ...@@ -80,7 +80,7 @@ protected:
public: public:
static std::vector<HostPacket> hosts; static std::vector<HostPacket> hosts;
static void BeginRefreshHost(); static void BeginRefreshHost();
static int RefreshThread(void* arg); static int RefreshThread(event_base* broadev);
static void BroadcastReply(evutil_socket_t fd, short events, void* arg); static void BroadcastReply(evutil_socket_t fd, short events, void* arg);
}; };
......
...@@ -1537,8 +1537,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) { ...@@ -1537,8 +1537,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
myswprintf(formatBuffer, L"%ls", dataManager.GetName(mcard->code)); myswprintf(formatBuffer, L"%ls", dataManager.GetName(mcard->code));
str.append(formatBuffer); str.append(formatBuffer);
if(mcard->type & TYPE_MONSTER) { if(mcard->type & TYPE_MONSTER) {
if(mcard->alias && (mcard->alias < mcard->code - 10 || mcard->alias > mcard->code + 10) if(mcard->alias && wcscmp(dataManager.GetName(mcard->code), dataManager.GetName(mcard->alias))) {
&& wcscmp(dataManager.GetName(mcard->code), dataManager.GetName(mcard->alias))) {
myswprintf(formatBuffer, L"\n(%ls)", dataManager.GetName(mcard->alias)); myswprintf(formatBuffer, L"\n(%ls)", dataManager.GetName(mcard->alias));
str.append(formatBuffer); str.append(formatBuffer);
} }
...@@ -1560,7 +1559,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) { ...@@ -1560,7 +1559,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
str.append(formatBuffer); str.append(formatBuffer);
} }
} else { } else {
if(mcard->alias && (mcard->alias < mcard->code - 10 || mcard->alias > mcard->code + 10)) { if(mcard->alias && wcscmp(dataManager.GetName(mcard->code), dataManager.GetName(mcard->alias))) {
myswprintf(formatBuffer, L"\n(%ls)", dataManager.GetName(mcard->alias)); myswprintf(formatBuffer, L"\n(%ls)", dataManager.GetName(mcard->alias));
str.append(formatBuffer); str.append(formatBuffer);
} }
......
...@@ -38,11 +38,7 @@ void Game::MainServerLoop() { ...@@ -38,11 +38,7 @@ void Game::MainServerLoop() {
fflush(stdout); fflush(stdout);
while(NetServer::net_evbase) { while(NetServer::net_evbase) {
#ifdef WIN32 std::this_thread::sleep_for(std::chrono::milliseconds(200));
Sleep(200);
#else
usleep(200000);
#endif
} }
} }
#else //YGOPRO_SERVER_MODE #else //YGOPRO_SERVER_MODE
...@@ -872,11 +868,7 @@ void Game::MainLoop() { ...@@ -872,11 +868,7 @@ void Game::MainLoop() {
fps++; fps++;
cur_time = timer->getTime(); cur_time = timer->getTime();
if(cur_time < fps * 17 - 20) if(cur_time < fps * 17 - 20)
#ifdef _WIN32 std::this_thread::sleep_for(std::chrono::milliseconds(20));
Sleep(20);
#else
usleep(20000);
#endif
if(cur_time >= 1000) { if(cur_time >= 1000) {
myswprintf(cap, L"YGOPro FPS: %d", fps); myswprintf(cap, L"YGOPro FPS: %d", fps);
device->setWindowCaption(cap); device->setWindowCaption(cap);
...@@ -891,11 +883,7 @@ void Game::MainLoop() { ...@@ -891,11 +883,7 @@ void Game::MainLoop() {
DuelClient::StopClient(true); DuelClient::StopClient(true);
if(dInfo.isSingleMode) if(dInfo.isSingleMode)
SingleMode::StopPlay(true); SingleMode::StopPlay(true);
#ifdef _WIN32 std::this_thread::sleep_for(std::chrono::milliseconds(500));
Sleep(500);
#else
usleep(500000);
#endif
SaveConfig(); SaveConfig();
// device->drop(); // device->drop();
} }
......
#ifndef THREAD_H
#define THREAD_H
#ifdef _WIN32
#include <windows.h>
class Thread {
public:
static void NewThread(int (*thread_func)(void*), void* param) {
CreateThread(0, 0, (LPTHREAD_START_ROUTINE)thread_func, param, 0, 0);
}
};
#else // _WIN32
#include <pthread.h>
class Thread {
public:
static void NewThread(int (*thread_func)(void*), void* param) {
pthread_t thread;
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_create(&thread, &attr, (void * (*)(void *))thread_func, param);
}
};
#endif // _WIN32
#endif // THREAD_H
...@@ -78,7 +78,7 @@ bool NetServer::StartServer(unsigned short port) { ...@@ -78,7 +78,7 @@ bool NetServer::StartServer(unsigned short port) {
return false; return false;
} }
evconnlistener_set_error_cb(listener, ServerAcceptError); evconnlistener_set_error_cb(listener, ServerAcceptError);
Thread::NewThread(ServerThread, net_evbase); std::thread(ServerThread).detach();
#ifdef YGOPRO_SERVER_MODE #ifdef YGOPRO_SERVER_MODE
evutil_socket_t fd = evconnlistener_get_fd(listener); evutil_socket_t fd = evconnlistener_get_fd(listener);
socklen_t addrlen = sizeof(sockaddr); socklen_t addrlen = sizeof(sockaddr);
...@@ -194,7 +194,7 @@ void NetServer::ServerEchoEvent(bufferevent* bev, short events, void* ctx) { ...@@ -194,7 +194,7 @@ void NetServer::ServerEchoEvent(bufferevent* bev, short events, void* ctx) {
else DisconnectPlayer(dp); else DisconnectPlayer(dp);
} }
} }
int NetServer::ServerThread(void* param) { int NetServer::ServerThread() {
event_base_dispatch(net_evbase); event_base_dispatch(net_evbase);
for(auto bit = users.begin(); bit != users.end(); ++bit) { for(auto bit = users.begin(); bit != users.end(); ++bit) {
bufferevent_disable(bit->first, EV_READ); bufferevent_disable(bit->first, EV_READ);
......
...@@ -41,7 +41,7 @@ public: ...@@ -41,7 +41,7 @@ public:
static void ServerAcceptError(evconnlistener *listener, void* ctx); static void ServerAcceptError(evconnlistener *listener, void* ctx);
static void ServerEchoRead(bufferevent* bev, void* ctx); static void ServerEchoRead(bufferevent* bev, void* ctx);
static void ServerEchoEvent(bufferevent* bev, short events, void* ctx); static void ServerEchoEvent(bufferevent* bev, short events, void* ctx);
static int ServerThread(void* param); static int ServerThread();
static void DisconnectPlayer(DuelPlayer* dp); static void DisconnectPlayer(DuelPlayer* dp);
static void HandleCTOSPacket(DuelPlayer* dp, char* data, unsigned int len); static void HandleCTOSPacket(DuelPlayer* dp, char* data, unsigned int len);
static void SendPacketToPlayer(DuelPlayer* dp, unsigned char proto) { static void SendPacketToPlayer(DuelPlayer* dp, unsigned char proto) {
......
...@@ -24,7 +24,7 @@ bool ReplayMode::StartReplay(int skipturn) { ...@@ -24,7 +24,7 @@ bool ReplayMode::StartReplay(int skipturn) {
skip_turn = skipturn; skip_turn = skipturn;
if(skip_turn < 0) if(skip_turn < 0)
skip_turn = 0; skip_turn = 0;
Thread::NewThread(ReplayThread, 0); std::thread(ReplayThread).detach();
return true; return true;
} }
void ReplayMode::StopReplay(bool is_exiting) { void ReplayMode::StopReplay(bool is_exiting) {
...@@ -56,7 +56,7 @@ bool ReplayMode::ReadReplayResponse() { ...@@ -56,7 +56,7 @@ bool ReplayMode::ReadReplayResponse() {
set_responseb(pduel, resp); set_responseb(pduel, resp);
return result; return result;
} }
int ReplayMode::ReplayThread(void* param) { int ReplayMode::ReplayThread() {
const ReplayHeader& rh = cur_replay.pheader; const ReplayHeader& rh = cur_replay.pheader;
mainGame->dInfo.isFirst = true; mainGame->dInfo.isFirst = true;
mainGame->dInfo.isTag = !!(rh.flag & REPLAY_TAG); mainGame->dInfo.isTag = !!(rh.flag & REPLAY_TAG);
......
...@@ -32,7 +32,7 @@ public: ...@@ -32,7 +32,7 @@ public:
static void SwapField(); static void SwapField();
static void Pause(bool is_pause, bool is_step); static void Pause(bool is_pause, bool is_step);
static bool ReadReplayResponse(); static bool ReadReplayResponse();
static int ReplayThread(void* param); static int ReplayThread();
static bool StartDuel(); static bool StartDuel();
static void EndDuel(); static void EndDuel();
static void Restart(bool refresh); static void Restart(bool refresh);
......
...@@ -12,7 +12,7 @@ bool SingleMode::is_continuing = false; ...@@ -12,7 +12,7 @@ bool SingleMode::is_continuing = false;
Replay SingleMode::last_replay; Replay SingleMode::last_replay;
bool SingleMode::StartPlay() { bool SingleMode::StartPlay() {
Thread::NewThread(SinglePlayThread, 0); std::thread(SinglePlayThread).detach();
return true; return true;
} }
void SingleMode::StopPlay(bool is_exiting) { void SingleMode::StopPlay(bool is_exiting) {
...@@ -28,7 +28,7 @@ void SingleMode::SetResponse(unsigned char* resp, unsigned int len) { ...@@ -28,7 +28,7 @@ void SingleMode::SetResponse(unsigned char* resp, unsigned int len) {
last_replay.WriteData(resp, len); last_replay.WriteData(resp, len);
set_responseb(pduel, resp); set_responseb(pduel, resp);
} }
int SingleMode::SinglePlayThread(void* param) { int SingleMode::SinglePlayThread() {
const int start_lp = 8000; const int start_lp = 8000;
const int start_hand = 5; const int start_hand = 5;
const int draw_count = 1; const int draw_count = 1;
...@@ -125,6 +125,7 @@ int SingleMode::SinglePlayThread(void* param) { ...@@ -125,6 +125,7 @@ int SingleMode::SinglePlayThread(void* param) {
} }
} }
last_replay.EndRecord(); last_replay.EndRecord();
mainGame->gMutex.Lock();
time_t nowtime = time(NULL); time_t nowtime = time(NULL);
tm* localedtime = localtime(&nowtime); tm* localedtime = localtime(&nowtime);
wchar_t timetext[40]; wchar_t timetext[40];
......
...@@ -15,7 +15,7 @@ public: ...@@ -15,7 +15,7 @@ public:
static bool StartPlay(); static bool StartPlay();
static void StopPlay(bool is_exiting = false); static void StopPlay(bool is_exiting = false);
static void SetResponse(unsigned char* resp, unsigned int len); static void SetResponse(unsigned char* resp, unsigned int len);
static int SinglePlayThread(void* param); static int SinglePlayThread();
static bool SinglePlayAnalyze(char* msg, unsigned int len); static bool SinglePlayAnalyze(char* msg, unsigned int len);
static void SinglePlayRefresh(int flag = 0xf81fff); static void SinglePlayRefresh(int flag = 0xf81fff);
......
...@@ -9,9 +9,9 @@ ...@@ -9,9 +9,9 @@
!system 5 特殊召唤成功 !system 5 特殊召唤成功
!system 6 反转召唤成功 !system 6 反转召唤成功
!system 7 发动 !system 7 发动
!system 10 除指示物 !system 10 除指示物
!system 11 支付基本分 !system 11 支付基本分
!system 12 除本身的素材 !system 12 除本身的素材
!system 20 抽卡阶段中 !system 20 抽卡阶段中
!system 21 准备阶段中 !system 21 准备阶段中
!system 22 主要阶段中 !system 22 主要阶段中
...@@ -57,7 +57,7 @@ ...@@ -57,7 +57,7 @@
!system 201 此时没有可以发动的效果 !system 201 此时没有可以发动的效果
!system 202 是否要确认场上的情况? !system 202 是否要确认场上的情况?
!system 203 是否要进行连锁? !system 203 是否要进行连锁?
!system 204除%d个[%ls] !system 204除%d个[%ls]
!system 205 请选择排列顺序 !system 205 请选择排列顺序
!system 206 请选择连锁顺序 !system 206 请选择连锁顺序
!system 207 翻开卡组上方%d张卡: !system 207 翻开卡组上方%d张卡:
...@@ -335,7 +335,7 @@ ...@@ -335,7 +335,7 @@
!system 1294 可用时点 !system 1294 可用时点
!system 1295 取消操作 !system 1295 取消操作
!system 1296 完成选择 !system 1296 完成选择
!system 1297 切洗手卡 !system 1297 洗切手卡
!system 1298 辅助功能 !system 1298 辅助功能
!system 1299 加快动画效果 !system 1299 加快动画效果
!system 1300 禁限卡表: !system 1300 禁限卡表:
...@@ -474,7 +474,7 @@ ...@@ -474,7 +474,7 @@
!system 1615 我方回复%d基本分 !system 1615 我方回复%d基本分
!system 1616 对方回复%d基本分 !system 1616 对方回复%d基本分
!system 1617 [%ls]放置了%d个[%ls] !system 1617 [%ls]放置了%d个[%ls]
!system 1618 [%ls]除了%d个[%ls] !system 1618 [%ls]除了%d个[%ls]
!system 1619 [%ls]攻击[%ls] !system 1619 [%ls]攻击[%ls]
!system 1620 [%ls]直接攻击 !system 1620 [%ls]直接攻击
!system 1621 攻击被无效 !system 1621 攻击被无效
......
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