Commit 3510520e authored by nanahira's avatar nanahira

Merge branch 'server' into server-develop

parents 3b514da5 ad821bb4
......@@ -49,67 +49,93 @@ public:
return l;
}
// UTF-16/UTF-32 to UTF-8
static int EncodeUTF8(const wchar_t * wsrc, char * str) {
template<size_t N>
static int EncodeUTF8(const wchar_t* wsrc, char(&str)[N]) {
char* pstr = str;
while(*wsrc != 0) {
if(*wsrc < 0x80) {
*str = (char)*wsrc;
++str;
} else if(*wsrc < 0x800) {
str[0] = ((*wsrc >> 6) & 0x1f) | 0xc0;
str[1] = ((*wsrc) & 0x3f) | 0x80;
str += 2;
} else if(*wsrc < 0x10000 && (*wsrc < 0xd800 || *wsrc > 0xdfff)) {
str[0] = ((*wsrc >> 12) & 0xf) | 0xe0;
str[1] = ((*wsrc >> 6) & 0x3f) | 0x80;
str[2] = ((*wsrc) & 0x3f) | 0x80;
str += 3;
} else {
#ifdef _WIN32
unsigned unicode = 0;
unicode |= (*wsrc++ & 0x3ff) << 10;
unicode |= *wsrc & 0x3ff;
unicode += 0x10000;
str[0] = ((unicode >> 18) & 0x7) | 0xf0;
str[1] = ((unicode >> 12) & 0x3f) | 0x80;
str[2] = ((unicode >> 6) & 0x3f) | 0x80;
str[3] = ((unicode) & 0x3f) | 0x80;
#else
str[0] = ((*wsrc >> 18) & 0x7) | 0xf0;
str[1] = ((*wsrc >> 12) & 0x3f) | 0x80;
str[2] = ((*wsrc >> 6) & 0x3f) | 0x80;
str[3] = ((*wsrc) & 0x3f) | 0x80;
#endif // _WIN32
str += 4;
while (*wsrc != 0) {
unsigned cur = *wsrc;
int codepoint_size = 0;
if (cur < 0x80U)
codepoint_size = 1;
else if (cur < 0x800U)
codepoint_size = 2;
else if (cur < 0x10000U && (cur < 0xd800U || cur > 0xdfffU))
codepoint_size = 3;
else
codepoint_size = 4;
if (pstr - str + codepoint_size > N - 1)
break;
switch (codepoint_size) {
case 1:
*pstr = (char)cur;
break;
case 2:
pstr[0] = ((cur >> 6) & 0x1f) | 0xc0;
pstr[1] = (cur & 0x3f) | 0x80;
break;
case 3:
pstr[0] = ((cur >> 12) & 0xf) | 0xe0;
pstr[1] = ((cur >> 6) & 0x3f) | 0x80;
pstr[2] = (cur & 0x3f) | 0x80;
break;
case 4:
if (sizeof(wchar_t) == 2) {
cur = 0;
cur |= ((unsigned)*wsrc & 0x3ff) << 10;
++wsrc;
cur |= (unsigned)*wsrc & 0x3ff;
cur += 0x10000;
}
pstr[0] = ((cur >> 18) & 0x7) | 0xf0;
pstr[1] = ((cur >> 12) & 0x3f) | 0x80;
pstr[2] = ((cur >> 6) & 0x3f) | 0x80;
pstr[3] = (cur & 0x3f) | 0x80;
break;
default:
break;
}
pstr += codepoint_size;
wsrc++;
}
*str = 0;
return str - pstr;
*pstr = 0;
return pstr - str;
}
// UTF-8 to UTF-16/UTF-32
static int DecodeUTF8(const char * src, wchar_t * wstr) {
template<size_t N>
static int DecodeUTF8(const char* src, wchar_t(&wstr)[N]) {
const char* p = src;
wchar_t* wp = wstr;
while(*p != 0) {
if((*p & 0x80) == 0) {
const unsigned cur = (unsigned)*p & 0xff;
int codepoint_size = 0;
if ((cur & 0xf8) == 0xf0) {
if (sizeof(wchar_t) == 2)
codepoint_size = 2;
else
codepoint_size = 1;
}
else
codepoint_size = 1;
if (wp - wstr + codepoint_size > N - 1)
break;
if((cur & 0x80) == 0) {
*wp = *p;
p++;
} else if((*p & 0xe0) == 0xc0) {
} else if((cur & 0xe0) == 0xc0) {
*wp = (((unsigned)p[0] & 0x1f) << 6) | ((unsigned)p[1] & 0x3f);
p += 2;
} else if((*p & 0xf0) == 0xe0) {
} else if((cur & 0xf0) == 0xe0) {
*wp = (((unsigned)p[0] & 0xf) << 12) | (((unsigned)p[1] & 0x3f) << 6) | ((unsigned)p[2] & 0x3f);
p += 3;
} else if((*p & 0xf8) == 0xf0) {
#ifdef _WIN32
unsigned unicode = (((unsigned)p[0] & 0x7) << 18) | (((unsigned)p[1] & 0x3f) << 12) | (((unsigned)p[2] & 0x3f) << 6) | ((unsigned)p[3] & 0x3f);
unicode -= 0x10000;
*wp++ = (unicode >> 10) | 0xd800;
*wp = (unicode & 0x3ff) | 0xdc00;
#else
*wp = (((unsigned)p[0] & 0x7) << 18) | (((unsigned)p[1] & 0x3f) << 12) | (((unsigned)p[2] & 0x3f) << 6) | ((unsigned)p[3] & 0x3f);
#endif // _WIN32
} else if((cur & 0xf8) == 0xf0) {
if (sizeof(wchar_t) == 2) {
unsigned unicode = (((unsigned)p[0] & 0x7) << 18) | (((unsigned)p[1] & 0x3f) << 12) | (((unsigned)p[2] & 0x3f) << 6) | ((unsigned)p[3] & 0x3f);
unicode -= 0x10000;
*wp++ = (unicode >> 10) | 0xd800;
*wp = (unicode & 0x3ff) | 0xdc00;
} else {
*wp = (((unsigned)p[0] & 0x7) << 18) | (((unsigned)p[1] & 0x3f) << 12) | (((unsigned)p[2] & 0x3f) << 6) | ((unsigned)p[3] & 0x3f);
}
p += 4;
} else
p++;
......
......@@ -14,6 +14,14 @@ using CardData = card_data;
struct CardDataC : card_data {
unsigned int ot{};
unsigned int category{};
bool is_setcodes(std::vector <uint32> values) const {
for (auto& value : values) {
if (is_setcode(value))
return true;
}
return false;
}
};
struct CardString {
std::wstring name;
......
......@@ -682,8 +682,7 @@ void ClientField::ShowSelectOption(int select_hint) {
pos.LowerRightCorner.Y = pos.UpperLeftCorner.Y + newheight;
mainGame->wOptions->setRelativePosition(pos);
} else {
mainGame->SetStaticText(mainGame->stOptions, 310, mainGame->guiFont,
(wchar_t*)dataManager.GetDesc(select_options[0]));
mainGame->SetStaticText(mainGame->stOptions, 310, mainGame->guiFont, dataManager.GetDesc(select_options[0]));
mainGame->stOptions->setVisible(true);
mainGame->btnOptionp->setVisible(false);
mainGame->btnOptionn->setVisible(count > 1);
......
......@@ -308,13 +308,22 @@ const wchar_t* DataManager::GetSetName(int code) {
return NULL;
return csit->second.c_str();
}
unsigned int DataManager::GetSetCode(const wchar_t* setname) {
std::vector<unsigned int> DataManager::GetSetCodes(std::wstring setname) {
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
if(csit->second.compare(0, xpos, setname) == 0 || csit->second.compare(xpos + 1, csit->second.length(), setname) == 0)
return csit->first;
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);
} else {
if(csit->second.substr(0, xpos).find(setname) != std::wstring::npos
|| csit->second.substr(xpos + 1).find(setname) != std::wstring::npos) {
matchingCodes.push_back(csit->first);
}
}
}
return 0;
return matchingCodes;
}
const wchar_t* DataManager::GetNumString(int num, bool bracket) {
if(!bracket)
......@@ -455,14 +464,14 @@ byte* DataManager::ScriptReaderEx(const char* script_name, int* slen) {
else
return ScriptReader(third, slen);
#else
char first[256];
char second[256];
char first[256]{};
char second[256]{};
if(mainGame->gameConf.prefer_expansion_script) {
sprintf(first, "expansions/%s", script_name + 2);
sprintf(second, "%s", script_name + 2);
snprintf(first, sizeof first, "expansions/%s", script_name + 2);
snprintf(second, sizeof second, "%s", script_name + 2);
} else {
sprintf(first, "%s", script_name + 2);
sprintf(second, "expansions/%s", script_name + 2);
snprintf(first, sizeof first, "%s", script_name + 2);
snprintf(second, sizeof second, "expansions/%s", script_name + 2);
}
if(ScriptReader(first, slen))
return scriptBuffer;
......@@ -482,7 +491,7 @@ byte* DataManager::ScriptReader(const char* script_name, int* slen) {
*slen = len;
#else
#ifdef _WIN32
wchar_t fname[256];
wchar_t fname[256]{};
BufferIO::DecodeUTF8(script_name, fname);
IReadFile* reader = FileSystem->createAndOpenFile(fname);
#else
......
......@@ -38,7 +38,7 @@ public:
const wchar_t* GetVictoryString(int code);
const wchar_t* GetCounterName(int code);
const wchar_t* GetSetName(int code);
unsigned int GetSetCode(const wchar_t* setname);
std::vector<unsigned int> GetSetCodes(std::wstring setname);
const wchar_t* GetNumString(int num, bool bracket = false);
const wchar_t* FormatLocation(int location, int sequence);
const wchar_t* FormatAttribute(int attribute);
......
......@@ -1337,14 +1337,14 @@ void DeckBuilder::FilterCards() {
results.clear();
struct element_t {
std::wstring keyword;
unsigned int setcode;
std::vector<unsigned int> setcodes;
enum class type_t {
all,
name,
setcode
} type;
bool exclude;
element_t(): setcode(0), type(type_t::all), exclude(false) {}
element_t(): type(type_t::all), exclude(false) {}
};
const wchar_t* pstr = mainGame->ebCardName->getText();
std::wstring str = std::wstring(pstr);
......@@ -1385,7 +1385,7 @@ void DeckBuilder::FilterCards() {
element.keyword = str.substr(element_start, length);
} else
element.keyword = str.substr(element_start);
element.setcode = dataManager.GetSetCode(element.keyword.c_str());
element.setcodes = dataManager.GetSetCodes(element.keyword);
query_elements.push_back(element);
if(element_end == std::wstring::npos)
break;
......@@ -1403,7 +1403,7 @@ void DeckBuilder::FilterCards() {
}
if(element_start < str.size()) {
element.keyword = str.substr(element_start);
element.setcode = dataManager.GetSetCode(element.keyword.c_str());
element.setcodes = dataManager.GetSetCodes(element.keyword);
query_elements.push_back(element);
}
}
......@@ -1490,14 +1490,14 @@ void DeckBuilder::FilterCards() {
if (elements_iterator->type == element_t::type_t::name) {
match = CardNameContains(text.name.c_str(), elements_iterator->keyword.c_str());
} else if (elements_iterator->type == element_t::type_t::setcode) {
match = elements_iterator->setcode && data.is_setcode(elements_iterator->setcode);
match = data.is_setcodes(elements_iterator->setcodes);
} else {
int trycode = BufferIO::GetVal(elements_iterator->keyword.c_str());
bool tryresult = dataManager.GetData(trycode, 0);
if(!tryresult) {
match = CardNameContains(text.name.c_str(), elements_iterator->keyword.c_str())
|| text.text.find(elements_iterator->keyword) != std::wstring::npos
|| (elements_iterator->setcode && data.is_setcode(elements_iterator->setcode));
|| data.is_setcodes(elements_iterator->setcodes);
} else {
match = data.code == trycode || data.alias == trycode;
}
......@@ -1757,7 +1757,7 @@ bool DeckBuilder::push_main(code_pointer pointer, int seq) {
if(pointer->second.type & (TYPE_FUSION | TYPE_SYNCHRO | TYPE_XYZ | TYPE_LINK))
return false;
auto& container = deckManager.current_deck.main;
int maxc = mainGame->is_siding ? 64 : 60;
int maxc = mainGame->is_siding ? YGOPRO_MAX_DECK + 5 : YGOPRO_MAX_DECK;
if((int)container.size() >= maxc)
return false;
if(seq >= 0 && seq < (int)container.size())
......@@ -1772,7 +1772,7 @@ bool DeckBuilder::push_extra(code_pointer pointer, int seq) {
if(!(pointer->second.type & (TYPE_FUSION | TYPE_SYNCHRO | TYPE_XYZ | TYPE_LINK)))
return false;
auto& container = deckManager.current_deck.extra;
int maxc = mainGame->is_siding ? 20 : 15;
int maxc = mainGame->is_siding ? YGOPRO_MAX_EXTRA + 5 : YGOPRO_MAX_EXTRA;
if((int)container.size() >= maxc)
return false;
if(seq >= 0 && seq < (int)container.size())
......@@ -1785,7 +1785,7 @@ bool DeckBuilder::push_extra(code_pointer pointer, int seq) {
}
bool DeckBuilder::push_side(code_pointer pointer, int seq) {
auto& container = deckManager.current_deck.side;
int maxc = mainGame->is_siding ? 20 : 15;
int maxc = mainGame->is_siding ? YGOPRO_MAX_SIDE + 5 : YGOPRO_MAX_SIDE;
if((int)container.size() >= maxc)
return false;
if(seq >= 0 && seq < (int)container.size())
......
......@@ -91,11 +91,11 @@ int DeckManager::CheckDeck(Deck& deck, int lfhash, int rule) {
if(!list)
return 0;
int dc = 0;
if(deck.main.size() < 40 || deck.main.size() > 60)
if(deck.main.size() < YGOPRO_MIN_DECK || deck.main.size() > YGOPRO_MAX_DECK)
return (DECKERROR_MAINCOUNT << 28) + deck.main.size();
if(deck.extra.size() > 15)
if(deck.extra.size() > YGOPRO_MAX_EXTRA)
return (DECKERROR_EXTRACOUNT << 28) + deck.extra.size();
if(deck.side.size() > 15)
if(deck.side.size() > YGOPRO_MAX_SIDE)
return (DECKERROR_SIDECOUNT << 28) + deck.side.size();
const int rule_map[6] = { AVAIL_OCG, AVAIL_TCG, AVAIL_SC, AVAIL_CUSTOM, AVAIL_OCGTCG, 0 };
int avail = rule_map[rule];
......@@ -163,10 +163,10 @@ int DeckManager::LoadDeck(Deck& deck, int* dbuf, int mainc, int sidec, bool is_p
continue;
}
else if(cd.type & (TYPE_FUSION | TYPE_SYNCHRO | TYPE_XYZ | TYPE_LINK)) {
if(deck.extra.size() >= 15)
if(deck.extra.size() >= YGOPRO_MAX_EXTRA)
continue;
deck.extra.push_back(dataManager.GetCodePointer(code));
} else if(deck.main.size() < 60) {
} else if(deck.main.size() < YGOPRO_MAX_DECK) {
deck.main.push_back(dataManager.GetCodePointer(code));
}
}
......@@ -178,7 +178,7 @@ int DeckManager::LoadDeck(Deck& deck, int* dbuf, int mainc, int sidec, bool is_p
}
if(cd.type & TYPE_TOKEN)
continue;
if(deck.side.size() < 15)
if(deck.side.size() < YGOPRO_MAX_SIDE)
deck.side.push_back(dataManager.GetCodePointer(code));
}
return errorcode;
......@@ -194,17 +194,21 @@ bool DeckManager::LoadSide(Deck& deck, int* dbuf, int mainc, int sidec) {
pcount[deck.side[i]->first]++;
Deck ndeck;
LoadDeck(ndeck, dbuf, mainc, sidec);
#ifndef YGOPRO_NO_SIDE_CHECK
if(ndeck.main.size() != deck.main.size() || ndeck.extra.size() != deck.extra.size())
return false;
#endif
for(size_t i = 0; i < ndeck.main.size(); ++i)
ncount[ndeck.main[i]->first]++;
for(size_t i = 0; i < ndeck.extra.size(); ++i)
ncount[ndeck.extra[i]->first]++;
for(size_t i = 0; i < ndeck.side.size(); ++i)
ncount[ndeck.side[i]->first]++;
#ifndef YGOPRO_NO_SIDE_CHECK
for(auto cdit = ncount.begin(); cdit != ncount.end(); ++cdit)
if(cdit->second != pcount[cdit->first])
return false;
#endif
deck = ndeck;
return true;
}
......@@ -231,7 +235,7 @@ void DeckManager::GetCategoryPath(wchar_t* ret, int index, const wchar_t* text)
void DeckManager::GetDeckFile(wchar_t* ret, irr::gui::IGUIComboBox* cbCategory, irr::gui::IGUIComboBox* cbDeck) {
wchar_t filepath[256];
wchar_t catepath[256];
wchar_t* deckname = (wchar_t*)cbDeck->getItem(cbDeck->getSelected());
const wchar_t* deckname = cbDeck->getItem(cbDeck->getSelected());
if(deckname != NULL) {
GetCategoryPath(catepath, cbCategory->getSelected(), cbCategory->getText());
myswprintf(filepath, L"%ls/%ls.ydk", catepath, deckname);
......
......@@ -1780,7 +1780,7 @@ void Game::AddDebugMsg(const char* msg) {
}
if (enable_log & 0x2) {
char msgbuf[1040];
sprintf(msgbuf, "[Script Error]: %s", msg);
snprintf(msgbuf, sizeof msgbuf, "[Script Error]: %s", msg);
ErrorLog(msgbuf);
}
#endif //YGOPRO_SERVER_MODE
......
......@@ -13,7 +13,27 @@
#include <vector>
#include <list>
#define DEFAULT_DUEL_RULE 5
#ifndef YGOPRO_DEFAULT_DUEL_RULE
#define YGOPRO_DEFAULT_DUEL_RULE 5
#endif
#ifndef YGOPRO_MAX_DECK
#define YGOPRO_MAX_DECK 60
#endif
#ifndef YGOPRO_MIN_DECK
#define YGOPRO_MIN_DECK 40
#endif
#ifndef YGOPRO_MAX_EXTRA
#define YGOPRO_MAX_EXTRA 15
#endif
#ifndef YGOPRO_MAX_SIDE
#define YGOPRO_MAX_SIDE 15
#endif
#define DEFAULT_DUEL_RULE YGOPRO_DEFAULT_DUEL_RULE
namespace ygo {
......
......@@ -233,10 +233,10 @@ irr::video::ITexture* ImageManager::GetTexture(int code, bool fit) {
auto tit = tMap[fit ? 1 : 0].find(code);
if(tit == tMap[fit ? 1 : 0].end()) {
char file[256];
sprintf(file, "expansions/pics/%d.jpg", code);
snprintf(file, sizeof file, "expansions/pics/%d.jpg", code);
irr::video::ITexture* img = GetTextureFromFile(file, width, height);
if(img == NULL) {
sprintf(file, "pics/%d.jpg", code);
snprintf(file, sizeof file, "pics/%d.jpg", code);
img = GetTextureFromFile(file, width, height);
}
if(img == NULL && !mainGame->gameConf.use_image_scale) {
......@@ -260,10 +260,10 @@ irr::video::ITexture* ImageManager::GetBigPicture(int code, float zoom) {
}
irr::video::ITexture* texture;
char file[256];
sprintf(file, "expansions/pics/%d.jpg", code);
snprintf(file, sizeof file, "expansions/pics/%d.jpg", code);
irr::video::IImage* srcimg = driver->createImageFromFile(file);
if(srcimg == NULL) {
sprintf(file, "pics/%d.jpg", code);
snprintf(file, sizeof file, "pics/%d.jpg", code);
srcimg = driver->createImageFromFile(file);
}
if(srcimg == NULL) {
......@@ -289,18 +289,18 @@ int ImageManager::LoadThumbThread() {
imageManager.tThumbLoadingCodes.pop();
imageManager.tThumbLoadingMutex.unlock();
char file[256];
sprintf(file, "expansions/pics/thumbnail/%d.jpg", code);
snprintf(file, sizeof file, "expansions/pics/thumbnail/%d.jpg", code);
irr::video::IImage* img = imageManager.driver->createImageFromFile(file);
if(img == NULL) {
sprintf(file, "pics/thumbnail/%d.jpg", code);
snprintf(file, sizeof file, "pics/thumbnail/%d.jpg", code);
img = imageManager.driver->createImageFromFile(file);
}
if(img == NULL && mainGame->gameConf.use_image_scale) {
sprintf(file, "expansions/pics/%d.jpg", code);
snprintf(file, sizeof file, "expansions/pics/%d.jpg", code);
img = imageManager.driver->createImageFromFile(file);
}
if(img == NULL && mainGame->gameConf.use_image_scale) {
sprintf(file, "pics/%d.jpg", code);
snprintf(file, sizeof file, "pics/%d.jpg", code);
img = imageManager.driver->createImageFromFile(file);
}
if(img != NULL) {
......@@ -345,7 +345,7 @@ irr::video::ITexture* ImageManager::GetTextureThumb(int code) {
if(lit != tThumbLoading.end()) {
if(lit->second != NULL) {
char file[256];
sprintf(file, "pics/thumbnail/%d.jpg", code);
snprintf(file, sizeof file, "pics/thumbnail/%d.jpg", code);
irr::video::ITexture* texture = driver->addTexture(file, lit->second); // textures must be added in the main thread due to OpenGL
lit->second->drop();
tThumb[code] = texture;
......@@ -378,18 +378,18 @@ irr::video::ITexture* ImageManager::GetTextureField(int code) {
auto tit = tFields.find(code);
if(tit == tFields.end()) {
char file[256];
sprintf(file, "expansions/pics/field/%d.png", code);
snprintf(file, sizeof file, "expansions/pics/field/%d.png", code);
irr::video::ITexture* img = GetTextureFromFile(file, 512 * mainGame->xScale, 512 * mainGame->yScale);
if(img == NULL) {
sprintf(file, "expansions/pics/field/%d.jpg", code);
snprintf(file, sizeof file, "expansions/pics/field/%d.jpg", code);
img = GetTextureFromFile(file, 512 * mainGame->xScale, 512 * mainGame->yScale);
}
if(img == NULL) {
sprintf(file, "pics/field/%d.png", code);
snprintf(file, sizeof file, "pics/field/%d.png", code);
img = GetTextureFromFile(file, 512 * mainGame->xScale, 512 * mainGame->yScale);
}
if(img == NULL) {
sprintf(file, "pics/field/%d.jpg", code);
snprintf(file, sizeof file, "pics/field/%d.jpg", code);
img = GetTextureFromFile(file, 512 * mainGame->xScale, 512 * mainGame->yScale);
if(img == NULL) {
tFields[code] = NULL;
......
......@@ -31,12 +31,8 @@
#ifndef __IRR_USTRING_H_INCLUDED__
#define __IRR_USTRING_H_INCLUDED__
#if (__cplusplus > 199711L) || (_MSC_VER >= 1600) || defined(__GXX_EXPERIMENTAL_CXX0X__)
# define USTRING_CPP0X
# if defined(__GXX_EXPERIMENTAL_CXX0X__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 5)))
# define USTRING_CPP0X_NEWLITERALS
# endif
#endif
#define USTRING_CPP0X
#define USTRING_CPP0X_NEWLITERALS
#include <stdio.h>
#include <string.h>
......
......@@ -74,15 +74,9 @@ typedef unsigned long UInt64;
#else
#if defined(_MSC_VER) || defined(__BORLANDC__)
typedef __int64 Int64;
typedef unsigned __int64 UInt64;
#define UINT64_CONST(n) n
#else
typedef long long int Int64;
typedef unsigned long long int UInt64;
#define UINT64_CONST(n) n ## ULL
#endif
#endif
......
......@@ -388,9 +388,9 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
int flag = 0;
flag += (mainGame->chkBotHand->isChecked() ? 0x1 : 0);
char arg2[8];
sprintf(arg2, "%d", flag);
snprintf(arg2, sizeof arg2, "%d", flag);
char arg3[8];
sprintf(arg3, "%d", mainGame->gameConf.serverport);
snprintf(arg3, sizeof arg3, "%d", mainGame->gameConf.serverport);
execl("./bot", "bot", arg1, arg2, arg3, NULL);
exit(0);
} else {
......
......@@ -176,7 +176,7 @@ public:
bool success = true;
TraversalDir(dir, [dir, &success](const char *name, bool isdir) {
char full_path[256];
sprintf(full_path, "%s/%s", dir, name);
snprintf(full_path, sizeof full_path, "%s/%s", dir, name);
if (isdir)
{
if(!DeleteDir(full_path))
......
......@@ -7,11 +7,7 @@ namespace ygo {
extern unsigned short server_port;
extern unsigned short replay_mode;
#endif
Replay::Replay()
: fp(nullptr), pheader(), pdata(nullptr), replay_size(0), comp_size(0), is_recording(false), is_replaying(false) {
#ifdef _WIN32
recording_fp = nullptr;
#endif
Replay::Replay() {
replay_data = new unsigned char[MAX_REPLAY_SIZE];
comp_data = new unsigned char[MAX_COMP_SIZE];
}
......@@ -188,8 +184,8 @@ void Replay::EndRecord() {
comp_size = MAX_COMP_SIZE;
int ret = LzmaCompress(comp_data, &comp_size, replay_data, replay_size, pheader.props, &propsize, 5, 1 << 24, 3, 0, 2, 32, 1);
if (ret != SZ_OK) {
*((int*)(comp_data)) = ret;
comp_size = sizeof(ret);
std::memcpy(comp_data, &ret, sizeof ret);
comp_size = sizeof ret;
}
is_recording = false;
}
......
......@@ -23,16 +23,13 @@ namespace ygo {
#endif // YGOPRO_SERVER_MODE
struct ReplayHeader {
unsigned int id;
unsigned int version;
unsigned int flag;
unsigned int seed;
unsigned int datasize;
unsigned int start_time;
unsigned char props[8];
ReplayHeader()
: id(0), version(0), flag(0), seed(0), datasize(0), start_time(0), props{ 0 } {}
unsigned int id{};
unsigned int version{};
unsigned int flag{};
unsigned int seed{};
unsigned int datasize{};
unsigned int start_time{};
unsigned char props[8]{};
};
class Replay {
......@@ -65,21 +62,21 @@ public:
char ReadInt8();
void Rewind();
FILE* fp;
FILE* fp{ nullptr };
#ifdef _WIN32
HANDLE recording_fp;
HANDLE recording_fp{ nullptr };
#endif
ReplayHeader pheader;
unsigned char* replay_data;
unsigned char* comp_data;
size_t replay_size;
size_t comp_size;
size_t replay_size{};
size_t comp_size{};
private:
unsigned char* pdata;
bool is_recording;
bool is_replaying;
unsigned char* pdata{ nullptr };
bool is_recording{};
bool is_replaying{};
};
}
......
......@@ -679,7 +679,7 @@ void TagDuel::Surrender(DuelPlayer* dp) {
if(dp->type > 3 || !pduel)
return;
uint32 player = dp->type;
#ifndef YGOPRO_SERVER_MODE
#if !defined(YGOPRO_SERVER_MODE) || defined(YGOPRO_TAG_SURRENDER_CONFIRM)
if(surrender[player])
return;
static const uint32 teammatemap[] = { 1, 0, 3, 2 };
......
Subproject commit 7e2f105643fc1fb4bdedc477f58b04b5aaae3100
Subproject commit a3b75211281ebb89becf6970553338be405fdccb
......@@ -61,10 +61,46 @@ 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 = "" }
boolOptions = {
"no-lua-safe",
"no-side-check",
"tag-surrender-confirm"
}
for _, boolOption in ipairs(boolOptions) do
newoption { trigger = boolOption, category = "YGOPro - options", description = "" }
end
numberOptions = {
"default-duel-rule",
"max-deck",
"min-deck",
"max-extra",
"max-side",
}
for _, numberOption in ipairs(numberOptions) do
newoption { trigger = numberOption, category = "YGOPro - options", description = "", value = "NUMBER" }
end
function GetParam(param)
return _OPTIONS[param] or os.getenv(string.upper(string.gsub(param,"-","_")))
end
function ApplyBoolean(param)
if GetParam(param) then
defines { "YGOPRO_" .. string.upper(string.gsub(param,"-","_")) }
end
end
function ApplyNumber(param)
local value = GetParam(param)
if not value then return end
local numberValue = tonumber(value)
if numberValue then
defines { "YGOPRO_" .. string.upper(string.gsub(param,"-","_")) .. "=" .. numberValue }
end
end
if GetParam("build-lua") then
BUILD_LUA = true
elseif GetParam("no-build-lua") then
......@@ -186,6 +222,14 @@ workspace "YGOPro"
configurations { "Release", "Debug" }
for _, numberOption in ipairs(numberOptions) do
ApplyNumber(numberOption)
end
for _, boolOption in ipairs(boolOptions) do
ApplyBoolean(boolOption)
end
filter "system:windows"
defines { "WIN32", "_WIN32" }
entrypoint "mainCRTStartup"
......
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