Commit 59293efc authored by nanahira's avatar nanahira

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

parents ccf75811 203718b5
......@@ -37,8 +37,9 @@ public:
inline static void WriteInt8(unsigned char*& p, char val) {
buffer_write<char>(p, val);
}
// return: string length
template<typename T1, typename T2>
inline static int CopyWStr(T1* src, T2* pstr, int bufsize) {
inline static int CopyWStr(const T1* src, T2* pstr, int bufsize) {
int l = 0;
while(src[l] && l < bufsize - 1) {
pstr[l] = (T2)src[l];
......@@ -48,7 +49,7 @@ public:
return l;
}
template<typename T1, typename T2>
inline static int CopyWStrRef(T1* src, T2*& pstr, int bufsize) {
inline static int CopyWStrRef(const T1* src, T2*& pstr, int bufsize) {
int l = 0;
while(src[l] && l < bufsize - 1) {
pstr[l] = (T2)src[l];
......@@ -59,8 +60,8 @@ public:
return l;
}
// UTF-16/UTF-32 to UTF-8
template<size_t N>
static int EncodeUTF8(const wchar_t* wsrc, char(&str)[N]) {
// return: string length
static int EncodeUTF8String(const wchar_t* wsrc, char* str, int size) {
char* pstr = str;
while (*wsrc != 0) {
unsigned cur = *wsrc;
......@@ -73,36 +74,36 @@ public:
codepoint_size = 3;
else
codepoint_size = 4;
if (pstr - str + codepoint_size > N - 1)
if (pstr - str + codepoint_size > size - 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;
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++;
......@@ -111,8 +112,8 @@ public:
return pstr - str;
}
// UTF-8 to UTF-16/UTF-32
template<size_t N>
static int DecodeUTF8(const char* src, wchar_t(&wstr)[N]) {
// return: string length
static int DecodeUTF8String(const char* src, wchar_t* wstr, int size) {
const char* p = src;
wchar_t* wp = wstr;
while(*p != 0) {
......@@ -126,7 +127,7 @@ public:
}
else
codepoint_size = 1;
if (wp - wstr + codepoint_size > N - 1)
if (wp - wstr + codepoint_size > size - 1)
break;
if((cur & 0x80) == 0) {
*wp = *p;
......@@ -154,6 +155,14 @@ public:
*wp = 0;
return wp - wstr;
}
template<size_t N>
static int EncodeUTF8(const wchar_t* src, char(&dst)[N]) {
return EncodeUTF8String(src, dst, N);
}
template<size_t N>
static int DecodeUTF8(const char* src, wchar_t(&dst)[N]) {
return DecodeUTF8String(src, dst, N);
}
static int GetVal(const wchar_t* pstr) {
unsigned int ret = 0;
while(*pstr >= L'0' && *pstr <= L'9') {
......
......@@ -36,7 +36,7 @@ void DeckManager::LoadLFListSingle(const char* path) {
int count = -1;
if (sscanf(linebuf, "%d %d", &code, &count) != 2)
continue;
if (code <= 0 || code > 99999999)
if (code <= 0 || code > 0xfffffff)
continue;
if (count < 0 || count > 2)
continue;
......
......@@ -12,7 +12,7 @@
#include <sstream>
#include <regex>
unsigned short PRO_VERSION = 0x1360;
unsigned short PRO_VERSION = 0x1361;
namespace ygo {
......
......@@ -10,7 +10,7 @@
#include <event2/thread.h>
#include <type_traits>
#define check_trivially_copyable(T) static_assert(std::is_trivially_copyable<T>::value == true, "not trivially copyable")
#define check_trivially_copyable(T) static_assert(std::is_trivially_copyable<T>::value == true && std::is_standard_layout<T>::value == true, "not trivially copyable")
namespace ygo {
constexpr int SIZE_NETWORK_BUFFER = 0x2000;
......@@ -113,6 +113,7 @@ struct STOC_HandResult {
check_trivially_copyable(STOC_HandResult);
static_assert(sizeof(STOC_HandResult) == 2, "size mismatch: STOC_HandResult");
// reserved for STOC_CREATE_GAME
struct STOC_CreateGame {
uint32_t gameid;
};
......@@ -131,6 +132,7 @@ struct STOC_TypeChange {
check_trivially_copyable(STOC_TypeChange);
static_assert(sizeof(STOC_TypeChange) == 1, "size mismatch: STOC_TypeChange");
// reserved for STOC_LEAVE_GAME
struct STOC_ExitGame {
unsigned char pos;
};
......@@ -250,46 +252,48 @@ public:
#define NETPLAYER_TYPE_PLAYER6 5
#define NETPLAYER_TYPE_OBSERVER 7
#define CTOS_RESPONSE 0x1
#define CTOS_UPDATE_DECK 0x2
#define CTOS_HAND_RESULT 0x3
#define CTOS_TP_RESULT 0x4
#define CTOS_PLAYER_INFO 0x10
#define CTOS_CREATE_GAME 0x11
#define CTOS_JOIN_GAME 0x12
#define CTOS_LEAVE_GAME 0x13
#define CTOS_SURRENDER 0x14
#define CTOS_TIME_CONFIRM 0x15
#define CTOS_CHAT 0x16
#define CTOS_HS_TODUELIST 0x20
#define CTOS_HS_TOOBSERVER 0x21
#define CTOS_HS_READY 0x22
#define CTOS_HS_NOTREADY 0x23
#define CTOS_HS_KICK 0x24
#define CTOS_HS_START 0x25
#define STOC_GAME_MSG 0x1
#define STOC_ERROR_MSG 0x2
#define STOC_SELECT_HAND 0x3
#define STOC_SELECT_TP 0x4
#define STOC_HAND_RESULT 0x5
#define STOC_TP_RESULT 0x6
#define STOC_CHANGE_SIDE 0x7
#define STOC_WAITING_SIDE 0x8
#define STOC_DECK_COUNT 0x9
#define STOC_CREATE_GAME 0x11
#define STOC_JOIN_GAME 0x12
#define STOC_TYPE_CHANGE 0x13
#define STOC_LEAVE_GAME 0x14
#define STOC_DUEL_START 0x15
#define STOC_DUEL_END 0x16
#define STOC_REPLAY 0x17
#define STOC_TIME_LIMIT 0x18
#define STOC_CHAT 0x19
#define STOC_HS_PLAYER_ENTER 0x20
#define STOC_HS_PLAYER_CHANGE 0x21
#define STOC_HS_WATCH_CHANGE 0x22
#define STOC_TEAMMATE_SURRENDER 0x23
#define CTOS_RESPONSE 0x1 // byte array
#define CTOS_UPDATE_DECK 0x2 // int32_t array
#define CTOS_HAND_RESULT 0x3 // CTOS_HandResult
#define CTOS_TP_RESULT 0x4 // CTOS_TPResult
#define CTOS_PLAYER_INFO 0x10 // CTOS_PlayerInfo
#define CTOS_CREATE_GAME 0x11 // CTOS_CreateGame
#define CTOS_JOIN_GAME 0x12 // CTOS_JoinGame
#define CTOS_LEAVE_GAME 0x13 // no data
#define CTOS_SURRENDER 0x14 // no data
#define CTOS_TIME_CONFIRM 0x15 // no data
#define CTOS_CHAT 0x16 // uint16_t array
#define CTOS_HS_TODUELIST 0x20 // no data
#define CTOS_HS_TOOBSERVER 0x21 // no data
#define CTOS_HS_READY 0x22 // no data
#define CTOS_HS_NOTREADY 0x23 // no data
#define CTOS_HS_KICK 0x24 // CTOS_Kick
#define CTOS_HS_START 0x25 // no data
#define CTOS_REQUEST_FIELD 0x30
#define STOC_GAME_MSG 0x1 // byte array
#define STOC_ERROR_MSG 0x2 // STOC_ErrorMsg
#define STOC_SELECT_HAND 0x3 // no data
#define STOC_SELECT_TP 0x4 // no data
#define STOC_HAND_RESULT 0x5 // STOC_HandResult
#define STOC_TP_RESULT 0x6 // reserved
#define STOC_CHANGE_SIDE 0x7 // no data
#define STOC_WAITING_SIDE 0x8 // no data
#define STOC_DECK_COUNT 0x9 // int16_t[6]
#define STOC_CREATE_GAME 0x11 // reserved
#define STOC_JOIN_GAME 0x12 // STOC_JoinGame
#define STOC_TYPE_CHANGE 0x13 // STOC_TypeChange
#define STOC_LEAVE_GAME 0x14 // reserved
#define STOC_DUEL_START 0x15 // no data
#define STOC_DUEL_END 0x16 // no data
#define STOC_REPLAY 0x17 // ReplayHeader + byte array
#define STOC_TIME_LIMIT 0x18 // STOC_TimeLimit
#define STOC_CHAT 0x19 // uint16_t + uint16_t array
#define STOC_HS_PLAYER_ENTER 0x20 // STOC_HS_PlayerEnter
#define STOC_HS_PLAYER_CHANGE 0x21 // STOC_HS_PlayerChange
#define STOC_HS_WATCH_CHANGE 0x22 // STOC_HS_WatchChange
#define STOC_TEAMMATE_SURRENDER 0x23 // no data
#define STOC_FIELD_FINISH 0x30
#define STOC_SRVPRO_ROOMLIST 0x31
#define PLAYERCHANGE_OBSERVE 0x8
......
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