Commit 0cee78b9 authored by mercury233's avatar mercury233

update

parent 31b4a96e
......@@ -30,24 +30,15 @@ Game* mainGame;
#ifdef YGOPRO_SERVER_MODE
unsigned short aServerPort;
unsigned short replay_mode;
unsigned int lflist;
unsigned char rule;
unsigned char mode;
unsigned char duel_rule;
bool no_check_deck;
bool no_shuffle_deck;
unsigned int start_lp;
unsigned short time_limit;
unsigned char start_hand;
unsigned char draw_count;
HostInfo game_info;
void Game::MainServerLoop(int mode, int lflist) {
void Game::MainServerLoop() {
deckManager.LoadLFList();
LoadExpansionDB();
dataManager.LoadDB("cards.cdb");
aServerPort = NetServer::StartServer(aServerPort);
NetServer::InitDuel(mode, lflist);
NetServer::InitDuel();
printf("%u\n", aServerPort);
fflush(stdout);
......
......@@ -6,6 +6,8 @@
#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>
......@@ -87,7 +89,7 @@ class Game {
public:
bool Initialize();
#ifdef YGOPRO_SERVER_MODE
void MainServerLoop(int mode, int lflist);
void MainServerLoop();
void LoadExpansionDB();
void AddDebugMsg(char* msgbuf);
#else
......@@ -439,16 +441,7 @@ extern Game* mainGame;
#ifdef YGOPRO_SERVER_MODE
extern unsigned short aServerPort;
extern unsigned short replay_mode;
extern unsigned int lflist;
extern unsigned char rule;
extern unsigned char mode;
extern unsigned char duel_rule;
extern bool no_check_deck;
extern bool no_shuffle_deck;
extern unsigned int start_lp;
extern unsigned short time_limit;
extern unsigned char start_hand;
extern unsigned char draw_count;
extern HostInfo game_info;
#endif //YGOPRO_SERVER_MODE
}
......
......@@ -60,34 +60,44 @@ int main(int argc, char* argv[]) {
#ifdef YGOPRO_SERVER_MODE
enable_log = 1;
ygo::aServerPort = 7911;
ygo::aServerPort = atoi(argv[1]);
ygo::lflist = atoi(argv[2]);
ygo::start_hand = 0;
if(argc > 2) {
ygo::rule = atoi(argv[3]);
ygo::mode = atoi(argv[4]);
if(ygo::mode > 2)
ygo::mode = 0;
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]);
ygo::game_info.lflist = atoi(argv[2]);
ygo::game_info.rule = atoi(argv[3]);
ygo::game_info.mode = atoi(argv[4]);
if(ygo::game_info.mode > 2)
ygo::game_info.mode = 0;
if(argv[5][0] == 'T')
ygo::duel_rule = DEFAULT_DUEL_RULE-1;
ygo::game_info.duel_rule = DEFAULT_DUEL_RULE - 1;
else
ygo::duel_rule = DEFAULT_DUEL_RULE;
ygo::game_info.duel_rule = DEFAULT_DUEL_RULE;
if(argv[6][0] == 'T')
ygo::no_check_deck = true;
ygo::game_info.no_check_deck = true;
else
ygo::no_check_deck = false;
ygo::game_info.no_check_deck = false;
if(argv[7][0] == 'T')
ygo::no_shuffle_deck = true;
ygo::game_info.no_shuffle_deck = true;
else
ygo::no_shuffle_deck = false;
ygo::start_lp = atoi(argv[8]);
ygo::start_hand = atoi(argv[9]);
ygo::draw_count = atoi(argv[10]);
ygo::time_limit = atoi(argv[11]);
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(ygo::mode, ygo::lflist);
ygo::mainGame->MainServerLoop();
return 0;
#else
ygo::mainGame = &_game;
......
......@@ -14,29 +14,40 @@ char NetServer::net_server_write[0x2000];
unsigned short NetServer::last_sent = 0;
#ifdef YGOPRO_SERVER_MODE
void NetServer::InitDuel(int mode, int lflist)
extern unsigned short replay_mode;
extern HostInfo game_info;
void NetServer::InitDuel()
{
if(mode == MODE_SINGLE) {
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(mode == MODE_MATCH) {
} 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(mode == MODE_TAG) {
} 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;
pkt->info.mode = mode;
if(lflist < 0)
if(game_info.lflist < 0)
pkt->info.lflist = 0;
else if(lflist >= deckManager._lfList.size())
else if(game_info.lflist >= deckManager._lfList.size())
pkt->info.lflist = deckManager._lfList[0].hash;
else
pkt->info.lflist = deckManager._lfList[lflist].hash;
pkt->info.lflist = deckManager._lfList[game_info.lflist].hash;
duel_mode->host_info = pkt->info;
......
......@@ -27,7 +27,7 @@ private:
public:
#ifdef YGOPRO_SERVER_MODE
static event_base* net_evbase;
static void InitDuel(int mode, int lflist);
static void InitDuel();
static unsigned short StartServer(unsigned short port);
#else
static bool StartServer(unsigned short port);
......@@ -74,7 +74,7 @@ public:
}
static void ReSendToPlayer(DuelPlayer* dp) {
if(dp)
bufferevent_write(dp->bev, net_server_write, last_sent);
bufferevent_write(dp->bev, nest_server_write, last_sent);
}
};
......
......@@ -9,18 +9,7 @@
namespace ygo {
extern unsigned int lflist;
extern unsigned char rule;
extern unsigned char mode;
extern unsigned char duel_rule;
extern bool no_check_deck;
extern bool no_shuffle_deck;
extern unsigned int start_lp;
extern unsigned short time_limit;
extern unsigned short replay_mode;
extern unsigned char start_hand;
extern unsigned char draw_count;
bool runasserver = true;
SingleDuel::SingleDuel(bool is_match) {
game_started = false;
......@@ -46,15 +35,19 @@ void SingleDuel::Chat(DuelPlayer* dp, void* pdata, int len) {
for(auto pit = observers.begin(); pit != observers.end(); ++pit)
if((*pit) != dp)
NetServer::ReSendToPlayer(*pit);
#ifdef YGOPRO_SERVER_MODE
/*for(auto pit = recorders.begin(); pit != recorders.end(); ++pit)
if((*pit) != dp)
NetServer::ReSendToPlayer(*pit);*/
#endif //YGOPRO_SERVER_MODE
} else {
NetServer::SendBufferToPlayer(players[1 - dp->type], STOC_CHAT, &scc, 4 + msglen * 2);
for(auto pit = observers.begin(); pit != observers.end(); ++pit)
NetServer::ReSendToPlayer(*pit);
#ifdef YGOPRO_SERVER_MODE
/*for(auto pit = recorders.begin(); pit != recorders.end(); ++pit)
NetServer::ReSendToPlayer(*pit);*/
#endif //YGOPRO_SERVER_MODE
}
}
void SingleDuel::JoinGame(DuelPlayer* dp, void* pdata, bool is_creater) {
......@@ -76,31 +69,9 @@ void SingleDuel::JoinGame(DuelPlayer* dp, void* pdata, bool is_creater) {
NetServer::DisconnectPlayer(dp);
return;
}
if (runasserver){
host_info.start_hand=5;
host_info.start_lp=8000;
host_info.draw_count=1;
host_info.mode=1;
host_info.no_check_deck=false;
host_info.no_shuffle_deck=false;
host_info.duel_rule=DEFAULT_DUEL_RULE;
host_info.rule=0;
host_info.time_limit=180;
#ifdef YGOPRO_SERVER_MODE
if (ygo::start_hand !=0 ){
host_info.start_hand=ygo::start_hand;
host_info.start_lp=ygo::start_lp;
host_info.draw_count=ygo::draw_count;
host_info.mode=ygo::mode;
host_info.no_check_deck=ygo::no_check_deck;
host_info.no_shuffle_deck=ygo::no_shuffle_deck;
host_info.duel_rule=ygo::duel_rule;
host_info.rule=ygo::rule;
host_info.time_limit=ygo::time_limit;
}
}else
{
#else
wchar_t jpass[20];
BufferIO::CopyWStr(pkt->pass, jpass, 20);
if(wcscmp(jpass, pass)) {
......@@ -110,7 +81,7 @@ void SingleDuel::JoinGame(DuelPlayer* dp, void* pdata, bool is_creater) {
NetServer::SendPacketToPlayer(dp, STOC_ERROR_MSG, scem);
return;
}
}
#endif //YGOPRO_SERVER_MODE
}
dp->game = this;
if(!players[0] && !players[1] && observers.size() == 0)
......
......@@ -49,7 +49,9 @@ protected:
unsigned char hand_result[2];
unsigned char last_response;
std::set<DuelPlayer*> observers;
#ifdef YGOPRO_SERVER_MODE
std::set<DuelPlayer*> recorders;
#endif //YGOPRO_SERVER_MODE
Replay last_replay;
bool match_mode;
int match_kill;
......
......@@ -9,17 +9,7 @@
namespace ygo {
extern unsigned int lflist;
extern unsigned char rule;
extern unsigned char mode;
extern unsigned char duel_rule;
extern bool no_check_deck;
extern bool no_shuffle_deck;
extern unsigned int start_lp;
extern unsigned short time_limit;
extern unsigned short replay_mode;
extern unsigned char start_hand;
extern unsigned char draw_count;
TagDuel::TagDuel() {
game_started = false;
......@@ -58,40 +48,19 @@ void TagDuel::JoinGame(DuelPlayer* dp, void* pdata, bool is_creater) {
NetServer::DisconnectPlayer(dp);
return;
}
if (true){
host_info.start_hand=5;
host_info.start_lp=8000;
host_info.draw_count=1;
host_info.mode=3;
host_info.no_check_deck=false;
host_info.no_shuffle_deck=false;
host_info.duel_rule=DEFAULT_DUEL_RULE;
host_info.rule=0;
host_info.time_limit=180;
#ifdef YGOPRO_SERVER_MODE
if (ygo::start_hand !=0 ){
host_info.start_hand=ygo::start_hand;
host_info.start_lp=ygo::start_lp;
host_info.draw_count=ygo::draw_count;
host_info.mode=ygo::mode;
host_info.no_check_deck=ygo::no_check_deck;
host_info.no_shuffle_deck=ygo::no_shuffle_deck;
host_info.duel_rule=ygo::duel_rule;
host_info.rule=ygo::rule;
host_info.time_limit=ygo::time_limit;
}
}else
{
wchar_t jpass[20];
BufferIO::CopyWStr(pkt->pass, jpass, 20);
if(wcscmp(jpass, pass)) {
STOC_ErrorMsg scem;
scem.msg = ERRMSG_JOINERROR;
scem.code = 1;
NetServer::SendPacketToPlayer(dp, STOC_ERROR_MSG, scem);
return;
}
#else
wchar_t jpass[20];
BufferIO::CopyWStr(pkt->pass, jpass, 20);
if(wcscmp(jpass, pass)) {
STOC_ErrorMsg scem;
scem.msg = ERRMSG_JOINERROR;
scem.code = 1;
NetServer::SendPacketToPlayer(dp, STOC_ERROR_MSG, scem);
return;
}
#endif //YGOPRO_SERVER_MODE
}
dp->game = this;
if(!players[0] && !players[1] && !players[2] && !players[3] && observers.size() == 0)
......
......@@ -46,7 +46,9 @@ protected:
DuelPlayer* pplayer[4];
DuelPlayer* cur_player[2];
std::set<DuelPlayer*> observers;
#ifdef YGOPRO_SERVER_MODE
std::set<DuelPlayer*> recorders;
#endif //YGOPRO_SERVER_MODE
bool ready[4];
Deck pdeck[4];
unsigned char hand_result[2];
......
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