Commit 98edda72 authored by nanahira's avatar nanahira

refa to CTOS_EXTERNAL_ADDRESS

parent 7e584bb9
...@@ -118,9 +118,13 @@ void DuelClient::ClientEvent(bufferevent* bev, short events, void* ctx) { ...@@ -118,9 +118,13 @@ void DuelClient::ClientEvent(bufferevent* bev, short events, void* ctx) {
if (events & BEV_EVENT_CONNECTED) { if (events & BEV_EVENT_CONNECTED) {
bool create_game = (intptr_t)ctx; bool create_game = (intptr_t)ctx;
if(!create_game) { if(!create_game) {
uint16_t msgbuf[LEN_HOSTNAME]; uint16_t hostname_buf[LEN_HOSTNAME];
int len = BufferIO::CopyCharArray(mainGame->ebJoinHost->getText(), msgbuf); auto hostname_len = BufferIO::CopyCharArray(mainGame->ebJoinHost->getText(), hostname_buf);
DuelClient::SendBufferToServer(CTOS_HOSTNAME, msgbuf, (len + 1) * sizeof(uint16_t)); auto hostname_msglen = (hostname_len + 1) * sizeof(uint16_t);
char buf[LEN_HOSTNAME * sizeof(int16_t) + sizeof(uint32_t)];
memset(buf, 0, sizeof(uint32_t));
memcpy(buf + sizeof(uint32_t), hostname_buf, hostname_msglen);
DuelClient::SendBufferToServer(CTOS_EXTERNAL_ADDRESS, buf, hostname_msglen + sizeof(uint32_t));
} }
CTOS_PlayerInfo cspi; CTOS_PlayerInfo cspi;
BufferIO::CopyCharArray(mainGame->ebNickName->getText(), cspi.name); BufferIO::CopyCharArray(mainGame->ebNickName->getText(), cspi.name);
......
...@@ -253,8 +253,13 @@ void NetServer::HandleCTOSPacket(DuelPlayer* dp, unsigned char* data, int len) { ...@@ -253,8 +253,13 @@ void NetServer::HandleCTOSPacket(DuelPlayer* dp, unsigned char* data, int len) {
BufferIO::CopyCharArray(pkt->name, dp->name); BufferIO::CopyCharArray(pkt->name, dp->name);
break; break;
} }
case CTOS_HOSTNAME: { case CTOS_EXTERNAL_ADDRESS: {
// for other server impl use only // for other server & reverse proxy use only
/*
wchar_t hostname[LEN_HOSTNAME];
uint32_t real_ip = BufferIO::ReadInt32(pdata);
BufferIO::CopyCharArray((uint16_t*)pdata, hostname);
*/
break; break;
} }
case CTOS_CREATE_GAME: { case CTOS_CREATE_GAME: {
......
...@@ -103,6 +103,14 @@ struct CTOS_Kick { ...@@ -103,6 +103,14 @@ struct CTOS_Kick {
check_trivially_copyable(CTOS_Kick); check_trivially_copyable(CTOS_Kick);
static_assert(sizeof(CTOS_Kick) == 1, "size mismatch: CTOS_Kick"); static_assert(sizeof(CTOS_Kick) == 1, "size mismatch: CTOS_Kick");
/*
* CTOS_ExternalAddress
* uint32_t real_ip; (IPv4 address)
* uint16_t hostname[256]; (UTF-16 string)
*/
constexpr int LEN_HOSTNAME = 256;
// STOC // STOC
struct STOC_ErrorMsg { struct STOC_ErrorMsg {
uint8_t msg{}; uint8_t msg{};
...@@ -164,13 +172,6 @@ constexpr int LEN_CHAT_PLAYER = 1; ...@@ -164,13 +172,6 @@ constexpr int LEN_CHAT_PLAYER = 1;
constexpr int LEN_CHAT_MSG = 256; constexpr int LEN_CHAT_MSG = 256;
constexpr int SIZE_STOC_CHAT = (LEN_CHAT_PLAYER + LEN_CHAT_MSG) * sizeof(uint16_t); constexpr int SIZE_STOC_CHAT = (LEN_CHAT_PLAYER + LEN_CHAT_MSG) * sizeof(uint16_t);
/*
* STOC_HOSTNAME
* uint16_t hostname[256]; (UTF-16 string)
*/
constexpr int LEN_HOSTNAME = 256;
struct STOC_HS_PlayerEnter { struct STOC_HS_PlayerEnter {
uint16_t name[20]{}; uint16_t name[20]{};
uint8_t pos{}; uint8_t pos{};
...@@ -276,7 +277,7 @@ public: ...@@ -276,7 +277,7 @@ public:
#define CTOS_SURRENDER 0x14 // no data #define CTOS_SURRENDER 0x14 // no data
#define CTOS_TIME_CONFIRM 0x15 // no data #define CTOS_TIME_CONFIRM 0x15 // no data
#define CTOS_CHAT 0x16 // uint16_t array #define CTOS_CHAT 0x16 // uint16_t array
#define CTOS_HOSTNAME 0x17 // uint16_t array #define CTOS_EXTERNAL_ADDRESS 0x17 // CTOS_ExternalAddress
#define CTOS_HS_TODUELIST 0x20 // no data #define CTOS_HS_TODUELIST 0x20 // no data
#define CTOS_HS_TOOBSERVER 0x21 // no data #define CTOS_HS_TOOBSERVER 0x21 // no data
#define CTOS_HS_READY 0x22 // no data #define CTOS_HS_READY 0x22 // no data
......
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