Commit 14e70e62 authored by mercury233's avatar mercury233

Merge branch 'server' of git.mycard.moe:mycard/ygopro into server

parents 91d38707 0dae13ea
No preview for this file type
...@@ -79,9 +79,9 @@ video::IImage* SGUITTGlyph::createGlyphImage(const FT_Bitmap& bits, video::IVide ...@@ -79,9 +79,9 @@ video::IImage* SGUITTGlyph::createGlyphImage(const FT_Bitmap& bits, video::IVide
const u32 image_pitch = image->getPitch() / sizeof(u16); const u32 image_pitch = image->getPitch() / sizeof(u16);
u16* image_data = (u16*)image->lock(); u16* image_data = (u16*)image->lock();
u8* glyph_data = bits.buffer; u8* glyph_data = bits.buffer;
for (s32 y = 0; y < bits.rows; ++y) { for (s32 y = 0; y < (s32)bits.rows; ++y) {
u16* row = image_data; u16* row = image_data;
for (s32 x = 0; x < bits.width; ++x) { for (s32 x = 0; x < (s32)bits.width; ++x) {
// Monochrome bitmaps store 8 pixels per byte. The left-most pixel is the bit 0x80. // Monochrome bitmaps store 8 pixels per byte. The left-most pixel is the bit 0x80.
// So, we go through the data each bit at a time. // So, we go through the data each bit at a time.
if ((glyph_data[y * bits.pitch + (x / 8)] & (0x80 >> (x % 8))) != 0) if ((glyph_data[y * bits.pitch + (x / 8)] & (0x80 >> (x % 8))) != 0)
...@@ -105,9 +105,9 @@ video::IImage* SGUITTGlyph::createGlyphImage(const FT_Bitmap& bits, video::IVide ...@@ -105,9 +105,9 @@ video::IImage* SGUITTGlyph::createGlyphImage(const FT_Bitmap& bits, video::IVide
const u32 image_pitch = image->getPitch() / sizeof(u32); const u32 image_pitch = image->getPitch() / sizeof(u32);
u32* image_data = (u32*)image->lock(); u32* image_data = (u32*)image->lock();
u8* glyph_data = bits.buffer; u8* glyph_data = bits.buffer;
for (s32 y = 0; y < bits.rows; ++y) { for (s32 y = 0; y < (s32)bits.rows; ++y) {
u8* row = glyph_data; u8* row = glyph_data;
for (s32 x = 0; x < bits.width; ++x) { for (s32 x = 0; x < (s32)bits.width; ++x) {
image_data[y * image_pitch + x] |= static_cast<u32>(255.0f * (static_cast<float>(*row++) / gray_count)) << 24; image_data[y * image_pitch + x] |= static_cast<u32>(255.0f * (static_cast<float>(*row++) / gray_count)) << 24;
//data[y * image_pitch + x] |= ((u32)(*bitsdata++) << 24); //data[y * image_pitch + x] |= ((u32)(*bitsdata++) << 24);
} }
...@@ -154,8 +154,8 @@ void SGUITTGlyph::preload(u32 char_index, FT_Face face, video::IVideoDriver* dri ...@@ -154,8 +154,8 @@ void SGUITTGlyph::preload(u32 char_index, FT_Face face, video::IVideoDriver* dri
glyph_page = parent->getLastGlyphPageIndex(); glyph_page = parent->getLastGlyphPageIndex();
u32 texture_side_length = page->texture_size.Width - font_size; u32 texture_side_length = page->texture_size.Width - font_size;
u32 margin = font_size * 0.5; u32 margin = (u32)(font_size * 0.5);
u32 sprite_size = font_size * 1.5; u32 sprite_size = (u32)(font_size * 1.5);
core::vector2di page_position( core::vector2di page_position(
(s32)(page->used_slots % (s32)(texture_side_length / sprite_size)) * sprite_size + margin, (s32)(page->used_slots % (s32)(texture_side_length / sprite_size)) * sprite_size + margin,
(s32)(page->used_slots / (s32)(texture_side_length / sprite_size)) * sprite_size + margin (s32)(page->used_slots / (s32)(texture_side_length / sprite_size)) * sprite_size + margin
......
...@@ -96,8 +96,6 @@ using namespace irr; ...@@ -96,8 +96,6 @@ using namespace irr;
using namespace io; using namespace io;
#endif #endif
typedef int BOOL;
extern const unsigned short PRO_VERSION; extern const unsigned short PRO_VERSION;
extern int enable_log; extern int enable_log;
extern bool exit_on_return; extern bool exit_on_return;
......
...@@ -54,13 +54,13 @@ public: ...@@ -54,13 +54,13 @@ public:
string_pointer strings_begin; string_pointer strings_begin;
string_pointer strings_end; string_pointer strings_end;
wchar_t numStrings[301][4]; wchar_t numStrings[301][4]{};
wchar_t numBuffer[6]; wchar_t numBuffer[6]{};
wchar_t attBuffer[128]; wchar_t attBuffer[128]{};
wchar_t racBuffer[128]; wchar_t racBuffer[128]{};
wchar_t tpBuffer[128]; wchar_t tpBuffer[128]{};
wchar_t scBuffer[128]; wchar_t scBuffer[128]{};
wchar_t lmBuffer[32]; wchar_t lmBuffer[32]{};
static byte scriptBuffer[0x20000]; static byte scriptBuffer[0x20000];
static const wchar_t* unknown_string; static const wchar_t* unknown_string;
......
...@@ -1197,10 +1197,10 @@ void Game::DrawDeckBd() { ...@@ -1197,10 +1197,10 @@ void Game::DrawDeckBd() {
dx = 436.0f / (lx - 1); dx = 436.0f / (lx - 1);
} }
int padding = scrPackCards->getPos() * lx; int padding = scrPackCards->getPos() * lx;
for(size_t i = 0; i < mainsize - padding && i < 7 * lx; ++i) { for(int i = 0; i < mainsize - padding && i < 7 * lx; ++i) {
size_t j = i + padding; int j = i + padding;
DrawThumb(deckManager.current_deck.main[j], position2di(314 + (i % lx) * dx, 164 + (i / lx) * dy), deckBuilder.filterList); DrawThumb(deckManager.current_deck.main[j], position2di(314 + (i % lx) * dx, 164 + (i / lx) * dy), deckBuilder.filterList);
if(deckBuilder.hovered_pos == 1 && deckBuilder.hovered_seq == (int)j) if(deckBuilder.hovered_pos == 1 && deckBuilder.hovered_seq == j)
driver->draw2DRectangleOutline(Resize(313 + (i % lx) * dx, 163 + (i / lx) * dy, 359 + (i % lx) * dx, 228 + (i / lx) * dy)); driver->draw2DRectangleOutline(Resize(313 + (i % lx) * dx, 163 + (i / lx) * dy, 359 + (i % lx) * dx, 228 + (i / lx) * dy));
} }
if(!deckBuilder.showing_pack) { if(!deckBuilder.showing_pack) {
......
...@@ -19,8 +19,8 @@ unsigned char DuelClient::selftype = 0; ...@@ -19,8 +19,8 @@ unsigned char DuelClient::selftype = 0;
bool DuelClient::is_host = false; bool DuelClient::is_host = false;
event_base* DuelClient::client_base = 0; event_base* DuelClient::client_base = 0;
bufferevent* DuelClient::client_bev = 0; bufferevent* DuelClient::client_bev = 0;
unsigned char DuelClient::duel_client_read[0x2000]; unsigned char DuelClient::duel_client_read[SIZE_NETWORK_BUFFER];
unsigned char DuelClient::duel_client_write[0x2000]; unsigned char DuelClient::duel_client_write[SIZE_NETWORK_BUFFER];
bool DuelClient::is_closing = false; bool DuelClient::is_closing = false;
bool DuelClient::is_swapping = false; bool DuelClient::is_swapping = false;
int DuelClient::select_hint = 0; int DuelClient::select_hint = 0;
...@@ -4023,8 +4023,8 @@ void DuelClient::BeginRefreshHost() { ...@@ -4023,8 +4023,8 @@ void DuelClient::BeginRefreshHost() {
SOCKET sSend = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); SOCKET sSend = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if(sSend == INVALID_SOCKET) if(sSend == INVALID_SOCKET)
break; break;
BOOL opt = TRUE; int opt = TRUE;
setsockopt(sSend, SOL_SOCKET, SO_BROADCAST, (const char*)&opt, sizeof(BOOL)); setsockopt(sSend, SOL_SOCKET, SO_BROADCAST, (const char*)&opt, sizeof opt);
if(bind(sSend, (sockaddr*)&local, sizeof(sockaddr)) == SOCKET_ERROR) { if(bind(sSend, (sockaddr*)&local, sizeof(sockaddr)) == SOCKET_ERROR) {
closesocket(sSend); closesocket(sSend);
break; break;
......
...@@ -27,8 +27,8 @@ private: ...@@ -27,8 +27,8 @@ private:
static bool is_host; static bool is_host;
static event_base* client_base; static event_base* client_base;
static bufferevent* client_bev; static bufferevent* client_bev;
static unsigned char duel_client_read[0x2000]; static unsigned char duel_client_read[SIZE_NETWORK_BUFFER];
static unsigned char duel_client_write[0x2000]; static unsigned char duel_client_write[SIZE_NETWORK_BUFFER];
static bool is_closing; static bool is_closing;
static bool is_swapping; static bool is_swapping;
static int select_hint; static int select_hint;
...@@ -60,17 +60,25 @@ public: ...@@ -60,17 +60,25 @@ public:
template<typename ST> template<typename ST>
static void SendPacketToServer(unsigned char proto, ST& st) { static void SendPacketToServer(unsigned char proto, ST& st) {
auto p = duel_client_write; auto p = duel_client_write;
BufferIO::WriteInt16(p, 1 + sizeof(ST)); int blen = sizeof(ST);
if (blen > MAX_DATA_SIZE)
blen = MAX_DATA_SIZE;
BufferIO::WriteInt16(p, (short)(1 + blen));
BufferIO::WriteInt8(p, proto); BufferIO::WriteInt8(p, proto);
memcpy(p, &st, sizeof(ST)); memcpy(p, &st, blen);
bufferevent_write(client_bev, duel_client_write, sizeof(ST) + 3); bufferevent_write(client_bev, duel_client_write, blen + 3);
} }
static void SendBufferToServer(unsigned char proto, void* buffer, size_t len) { static void SendBufferToServer(unsigned char proto, void* buffer, size_t len) {
auto p = duel_client_write; auto p = duel_client_write;
BufferIO::WriteInt16(p, 1 + len); int blen = len;
if (blen < 0)
return;
if (blen > MAX_DATA_SIZE)
blen = MAX_DATA_SIZE;
BufferIO::WriteInt16(p, (short)(1 + blen));
BufferIO::WriteInt8(p, proto); BufferIO::WriteInt8(p, proto);
memcpy(p, buffer, len); memcpy(p, buffer, blen);
bufferevent_write(client_bev, duel_client_write, len + 3); bufferevent_write(client_bev, duel_client_write, blen + 3);
} }
protected: protected:
......
...@@ -827,7 +827,7 @@ bool Game::Initialize() { ...@@ -827,7 +827,7 @@ bool Game::Initialize() {
btnCategoryOK = env->addButton(rect<s32>(150, 210, 250, 235), wCategories, BUTTON_CATEGORY_OK, dataManager.GetSysString(1211)); btnCategoryOK = env->addButton(rect<s32>(150, 210, 250, 235), wCategories, BUTTON_CATEGORY_OK, dataManager.GetSysString(1211));
int catewidth = 0; int catewidth = 0;
for(int i = 0; i < 32; ++i) { for(int i = 0; i < 32; ++i) {
irr::core::dimension2d<unsigned int> dtxt = mainGame->guiFont->getDimension(dataManager.GetSysString(1100 + i)); irr::core::dimension2d<unsigned int> dtxt = guiFont->getDimension(dataManager.GetSysString(1100 + i));
if((int)dtxt.Width + 40 > catewidth) if((int)dtxt.Width + 40 > catewidth)
catewidth = dtxt.Width + 40; catewidth = dtxt.Width + 40;
} }
...@@ -1619,7 +1619,7 @@ void Game::ShowCardInfo(int code, bool resize) { ...@@ -1619,7 +1619,7 @@ void Game::ShowCardInfo(int code, bool resize) {
myswprintf(formatBuffer, L"[%ls] %ls/%ls", dataManager.FormatType(cd.type), dataManager.FormatRace(cd.race), dataManager.FormatAttribute(cd.attribute)); myswprintf(formatBuffer, L"[%ls] %ls/%ls", dataManager.FormatType(cd.type), dataManager.FormatRace(cd.race), dataManager.FormatAttribute(cd.attribute));
stInfo->setText(formatBuffer); stInfo->setText(formatBuffer);
int offset_info = 0; int offset_info = 0;
irr::core::dimension2d<unsigned int> dtxt = mainGame->guiFont->getDimension(formatBuffer); irr::core::dimension2d<unsigned int> dtxt = guiFont->getDimension(formatBuffer);
if(dtxt.Width > (300 * xScale - 13) - 15) if(dtxt.Width > (300 * xScale - 13) - 15)
offset_info = 15; offset_info = 15;
if(!(cd.type & TYPE_LINK)) { if(!(cd.type & TYPE_LINK)) {
...@@ -1653,7 +1653,7 @@ void Game::ShowCardInfo(int code, bool resize) { ...@@ -1653,7 +1653,7 @@ void Game::ShowCardInfo(int code, bool resize) {
} }
stDataInfo->setText(formatBuffer); stDataInfo->setText(formatBuffer);
int offset_arrows = offset_info; int offset_arrows = offset_info;
dtxt = mainGame->guiFont->getDimension(formatBuffer); dtxt = guiFont->getDimension(formatBuffer);
if(dtxt.Width > (300 * xScale - 13) - 15) if(dtxt.Width > (300 * xScale - 13) - 15)
offset_arrows += 15; offset_arrows += 15;
stInfo->setRelativePosition(rect<s32>(15, 37, 300 * xScale - 13, (60 + offset_info))); stInfo->setRelativePosition(rect<s32>(15, 37, 300 * xScale - 13, (60 + offset_info)));
...@@ -1989,8 +1989,8 @@ void Game::OnResize() { ...@@ -1989,8 +1989,8 @@ void Game::OnResize() {
scrTabSystem->setVisible(false); scrTabSystem->setVisible(false);
if(gameConf.resize_popup_menu) { if(gameConf.resize_popup_menu) {
int width = 100 * mainGame->xScale; int width = 100 * xScale;
int height = (mainGame->yScale >= 0.666) ? 21 * mainGame->yScale : 14; int height = (yScale >= 0.666) ? 21 * yScale : 14;
wCmdMenu->setRelativePosition(recti(1, 1, width + 1, 1)); wCmdMenu->setRelativePosition(recti(1, 1, width + 1, 1));
btnActivate->setRelativePosition(recti(1, 1, width, height)); btnActivate->setRelativePosition(recti(1, 1, width, height));
btnSummon->setRelativePosition(recti(1, 1, width, height)); btnSummon->setRelativePosition(recti(1, 1, width, height));
...@@ -2170,7 +2170,7 @@ void Game::FlashWindow() { ...@@ -2170,7 +2170,7 @@ void Game::FlashWindow() {
#endif #endif
} }
void Game::SetCursor(ECURSOR_ICON icon) { void Game::SetCursor(ECURSOR_ICON icon) {
ICursorControl* cursor = mainGame->device->getCursorControl(); ICursorControl* cursor = device->getCursorControl();
if(cursor->getActiveIcon() != icon) { if(cursor->getActiveIcon() != icon) {
cursor->setActiveIcon(icon); cursor->setActiveIcon(icon);
} }
......
...@@ -9,8 +9,8 @@ event_base* NetServer::net_evbase = 0; ...@@ -9,8 +9,8 @@ event_base* NetServer::net_evbase = 0;
event* NetServer::broadcast_ev = 0; event* NetServer::broadcast_ev = 0;
evconnlistener* NetServer::listener = 0; evconnlistener* NetServer::listener = 0;
DuelMode* NetServer::duel_mode = 0; DuelMode* NetServer::duel_mode = 0;
unsigned char NetServer::net_server_read[0x2000]; unsigned char NetServer::net_server_read[SIZE_NETWORK_BUFFER];
unsigned char NetServer::net_server_write[0x2000]; unsigned char NetServer::net_server_write[SIZE_NETWORK_BUFFER];
unsigned short NetServer::last_sent = 0; unsigned short NetServer::last_sent = 0;
#ifdef YGOPRO_SERVER_MODE #ifdef YGOPRO_SERVER_MODE
...@@ -118,9 +118,9 @@ bool NetServer::StartBroadcast() { ...@@ -118,9 +118,9 @@ bool NetServer::StartBroadcast() {
if(!net_evbase) if(!net_evbase)
return false; return false;
SOCKET udp = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); SOCKET udp = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
BOOL opt = TRUE; int opt = TRUE;
setsockopt(udp, SOL_SOCKET, SO_BROADCAST, (const char*)&opt, sizeof(BOOL)); setsockopt(udp, SOL_SOCKET, SO_BROADCAST, (const char*)&opt, sizeof opt);
setsockopt(udp, SOL_SOCKET, SO_REUSEADDR, (const char*)&opt, sizeof(BOOL)); setsockopt(udp, SOL_SOCKET, SO_REUSEADDR, (const char*)&opt, sizeof opt);
sockaddr_in addr; sockaddr_in addr;
memset(&addr, 0, sizeof(addr)); memset(&addr, 0, sizeof(addr));
addr.sin_family = AF_INET; addr.sin_family = AF_INET;
......
...@@ -20,8 +20,8 @@ private: ...@@ -20,8 +20,8 @@ private:
static event* broadcast_ev; static event* broadcast_ev;
static evconnlistener* listener; static evconnlistener* listener;
static DuelMode* duel_mode; static DuelMode* duel_mode;
static unsigned char net_server_read[0x2000]; static unsigned char net_server_read[SIZE_NETWORK_BUFFER];
static unsigned char net_server_write[0x2000]; static unsigned char net_server_write[SIZE_NETWORK_BUFFER];
static unsigned short last_sent; static unsigned short last_sent;
public: public:
...@@ -52,26 +52,34 @@ public: ...@@ -52,26 +52,34 @@ public:
last_sent = 3; last_sent = 3;
if(!dp) if(!dp)
return; return;
bufferevent_write(dp->bev, net_server_write, last_sent); bufferevent_write(dp->bev, net_server_write, 3);
} }
template<typename ST> template<typename ST>
static void SendPacketToPlayer(DuelPlayer* dp, unsigned char proto, ST& st) { static void SendPacketToPlayer(DuelPlayer* dp, unsigned char proto, ST& st) {
auto p = net_server_write; auto p = net_server_write;
BufferIO::WriteInt16(p, 1 + sizeof(ST)); int blen = sizeof(ST);
if (blen > MAX_DATA_SIZE)
blen = MAX_DATA_SIZE;
BufferIO::WriteInt16(p, (short)(1 + blen));
BufferIO::WriteInt8(p, proto); BufferIO::WriteInt8(p, proto);
memcpy(p, &st, sizeof(ST)); memcpy(p, &st, blen);
last_sent = sizeof(ST) + 3; last_sent = blen + 3;
if(dp) if (dp)
bufferevent_write(dp->bev, net_server_write, last_sent); bufferevent_write(dp->bev, net_server_write, blen + 3);
} }
static void SendBufferToPlayer(DuelPlayer* dp, unsigned char proto, void* buffer, size_t len) { static void SendBufferToPlayer(DuelPlayer* dp, unsigned char proto, void* buffer, size_t len) {
auto p = net_server_write; auto p = net_server_write;
BufferIO::WriteInt16(p, 1 + len); int blen = len;
if (blen < 0)
return;
if (blen > MAX_DATA_SIZE)
blen = MAX_DATA_SIZE;
BufferIO::WriteInt16(p, (short)(1 + blen));
BufferIO::WriteInt8(p, proto); BufferIO::WriteInt8(p, proto);
memcpy(p, buffer, len); memcpy(p, buffer, blen);
last_sent = len + 3; last_sent = blen + 3;
if(dp) if (dp)
bufferevent_write(dp->bev, net_server_write, last_sent); bufferevent_write(dp->bev, net_server_write, blen + 3);
} }
static void ReSendToPlayer(DuelPlayer* dp) { static void ReSendToPlayer(DuelPlayer* dp) {
if(dp) if(dp)
......
...@@ -10,6 +10,8 @@ ...@@ -10,6 +10,8 @@
#include <event2/thread.h> #include <event2/thread.h>
namespace ygo { namespace ygo {
constexpr int SIZE_NETWORK_BUFFER = 0x2000;
constexpr int MAX_DATA_SIZE = SIZE_NETWORK_BUFFER - 3;
struct HostInfo { struct HostInfo {
unsigned int lflist{ 0 }; unsigned int lflist{ 0 };
......
...@@ -55,7 +55,7 @@ int SingleMode::SinglePlayThread() { ...@@ -55,7 +55,7 @@ int SingleMode::SinglePlayThread() {
if(mainGame->chkSinglePlayReturnDeckTop->isChecked()) if(mainGame->chkSinglePlayReturnDeckTop->isChecked())
opt |= DUEL_RETURN_DECK_TOP; opt |= DUEL_RETURN_DECK_TOP;
char filename[256]; char filename[256];
size_t slen = 0; int slen = 0;
if(open_file) { if(open_file) {
open_file = false; open_file = false;
slen = BufferIO::EncodeUTF8(open_file_name, filename); slen = BufferIO::EncodeUTF8(open_file_name, filename);
......
This diff is collapsed.
Subproject commit c146c5493b5dd33db4026eb38b25fd45f8211b10 Subproject commit dfef9c1415a6bc006c1b60909a9106a5a228ac00
Subproject commit d6202e392bb5e3aa53e4cc1b822c929c5bcc1aff Subproject commit e5433ecb3d214e4e9a5fd76f41904edeeba6f402
...@@ -1183,7 +1183,7 @@ ...@@ -1183,7 +1183,7 @@
!setname 0x18f 防火 ファイアウォール !setname 0x18f 防火 ファイアウォール
!setname 0x190 末那愚子族 マナドゥム !setname 0x190 末那愚子族 マナドゥム
!setname 0x191 妮穆蕾莉娅 ネムレリア !setname 0x191 妮穆蕾莉娅 ネムレリア
!setname 0x192 金傲大奖赛 GP(ゴールド・プライド) !setname 0x192 黄金荣耀 GP(ゴールド・プライド)
!setname 0x193 迷宫壁 ラビリンス・ウォール !setname 0x193 迷宫壁 ラビリンス・ウォール
!setname 0x194 至爱 フェイバリット !setname 0x194 至爱 フェイバリット
!setname 0x195 征服斗魂 VS(ヴァンキッシュ・ソウル) !setname 0x195 征服斗魂 VS(ヴァンキッシュ・ソウル)
...@@ -1211,3 +1211,4 @@ ...@@ -1211,3 +1211,4 @@
!setname 0x1aa 天杯龙 天盃龍 !setname 0x1aa 天杯龙 天盃龍
!setname 0x1ab 蕾祸 蕾禍 !setname 0x1ab 蕾祸 蕾禍
!setname 0x1ac 飞龙炎 Salamandra !setname 0x1ac 飞龙炎 Salamandra
!setname 0x1ad 灰尽 Ashened
...@@ -41,6 +41,7 @@ bot_deck_path = ./botdeck ...@@ -41,6 +41,7 @@ bot_deck_path = ./botdeck
quick_animation = 0 quick_animation = 0
auto_save_replay = 0 auto_save_replay = 0
draw_single_chain = 0 draw_single_chain = 0
hide_player_name = 0
prefer_expansion_script = 0 prefer_expansion_script = 0
window_maximized = 0 window_maximized = 0
window_width = 1280 window_width = 1280
......
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