Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions gframe/duelclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,15 @@ void DuelClient::ClientRead(bufferevent* bev, void* ctx) {
void DuelClient::ClientEvent(bufferevent* bev, short events, void* ctx) {
if (events & BEV_EVENT_CONNECTED) {
bool create_game = (intptr_t)ctx;
if(!create_game) {
uint16_t hostname_buf[LEN_HOSTNAME];
auto hostname_len = BufferIO::CopyCharArray(mainGame->ebJoinHost->getText(), hostname_buf);
auto hostname_msglen = (hostname_len + 1) * sizeof(uint16_t);
char buf[LEN_HOSTNAME * sizeof(int16_t) + sizeof(uint32_t)];
Comment thread
mercury233 marked this conversation as resolved.
Outdated
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));
Comment thread
purerosefallen marked this conversation as resolved.
Outdated
Comment thread
mercury233 marked this conversation as resolved.
Outdated
}
CTOS_PlayerInfo cspi;
BufferIO::CopyCharArray(mainGame->ebNickName->getText(), cspi.name);
SendPacketToServer(CTOS_PLAYER_INFO, cspi);
Expand Down
9 changes: 9 additions & 0 deletions gframe/netserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,15 @@ void NetServer::HandleCTOSPacket(DuelPlayer* dp, unsigned char* data, int len) {
BufferIO::CopyCharArray(pkt->name, dp->name);
break;
}
case CTOS_EXTERNAL_ADDRESS: {
Comment thread
purerosefallen marked this conversation as resolved.
// for other server & reverse proxy use only
/*
wchar_t hostname[LEN_HOSTNAME];
uint32_t real_ip = ntohl(BufferIO::ReadInt32(pdata));
BufferIO::CopyCharArray((uint16_t*)pdata, hostname);
*/
break;
}
case CTOS_CREATE_GAME: {
if(dp->game || duel_mode)
return;
Expand Down
9 changes: 9 additions & 0 deletions gframe/network.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,14 @@ struct CTOS_Kick {
check_trivially_copyable(CTOS_Kick);
static_assert(sizeof(CTOS_Kick) == 1, "size mismatch: CTOS_Kick");

/*
* CTOS_ExternalAddress
* uint32_t real_ip; (IPv4 address, BE)
* uint16_t hostname[256]; (UTF-16 string)
*/

constexpr int LEN_HOSTNAME = 256;

// STOC
struct STOC_ErrorMsg {
uint8_t msg{};
Expand Down Expand Up @@ -269,6 +277,7 @@ class DuelMode {
#define CTOS_SURRENDER 0x14 // no data
#define CTOS_TIME_CONFIRM 0x15 // no data
#define CTOS_CHAT 0x16 // uint16_t array
#define CTOS_EXTERNAL_ADDRESS 0x17 // CTOS_ExternalAddress
#define CTOS_HS_TODUELIST 0x20 // no data
#define CTOS_HS_TOOBSERVER 0x21 // no data
#define CTOS_HS_READY 0x22 // no data
Expand Down