자잘한 수정, 이제 다른 소켓으로 쓰기 요청 할 수 있을 듯

This commit is contained in:
2025-05-03 13:59:04 +09:00
parent 181d30ff28
commit f765c163bf
12 changed files with 512 additions and 310 deletions

View File

@@ -5,7 +5,27 @@
namespace Chattr {
enum class PacketType : std::uint8_t {
enum class PacketSet {
LOGINREQUEST,
ROOMCREATEREQUEST,
ROOMLISTREQUEST,
ROOMJOINREQUEST,
ROOMEXITREQUEST,
USERSLISTREQUEST,
DATAPOSTTEXT,
DATAPOSTBINARY,
CONTINUE,
RESPONSE,
LOGINRESPONSE,
ROOMCREATERESPONSE,
ROOMLISTRESPONSE,
ROOMJOINRESPONSE,
ROOMEXITRESPONSE,
USERSLISTRESPONSE,
INVALID
};
enum class PacketCategory : std::uint8_t {
PACKET_POST,
PACKET_REQUEST,
PACKET_RESPONSE,
@@ -22,6 +42,8 @@ enum class RequestType : std::uint8_t {
DATA
};
#define MOREFRAG 0b00000001
enum class DataType : std::uint8_t {
TEXT,
BINARY
@@ -31,7 +53,7 @@ class alignas(4) Packet {
public:
union {
struct {
PacketType packetType;
PacketCategory packetType;
RequestType requestType;
DataType dataType;
std::uint16_t packetLength;
@@ -49,106 +71,48 @@ public:
}
};
class alignas(4) LoginRequestPacket : public Packet {
public:
union {
struct {
PacketType packetType;
RequestType requestType;
DataType dataType;
std::uint16_t packetLength;
std::uint8_t name[];
} __data;
std::uint8_t serialized[1500] = "";
};
};
class alignas(4) LoginRequestPacket : public Packet {};
class alignas(4) RoomCreateRequestPacket : public Packet {
public:
union {
struct {
PacketType packetType;
RequestType requestType;
DataType dataType;
std::uint16_t packetLength;
std::uint8_t name[];
} __data;
std::uint8_t serialized[1500] = "";
};
};
class alignas(4) RoomCreateRequestPacket : public Packet {};
class alignas(4) RoomListRequestPacket : public Packet {
class alignas(4) RoomListRequestPacket : public Packet {};
class alignas(4) RoomJoinRequestPacket : public Packet {
public:
union {
struct {
PacketType packetType;
PacketCategory packetType;
RequestType requestType;
DataType dataType;
std::uint16_t packetLength;
std::uint32_t roomCount;
std::uint16_t destId[4];
std::uint8_t name[];
} __data;
std::uint8_t serialized[1500] = "";
};
std::uint8_t* convToN() {
__data.packetLength = ::htons(__data.packetLength);
__data.roomCount = ::htonl(__data.roomCount);
for (int i = 0; i < 4; i++)
__data.destId[i] = ::htons(__data.destId[i]);
return serialized;
}
std::uint8_t* convToH() {
__data.packetLength = ::ntohs(__data.packetLength);
__data.roomCount = ::ntohl(__data.roomCount);
for (int i = 0; i < 4; i++)
__data.destId[i] = ::ntohs(__data.destId[i]);
return serialized;
}
};
class alignas(4) RoomJoinRequestPacket : public Packet {
public:
union {
struct {
PacketType packetType;
RequestType requestType;
DataType dataType;
std::uint16_t packetLength;
std::uint8_t name[];
} __data;
std::uint8_t serialized[1500] = "";
};
};
class alignas(4) RoomExitRequestPacket : public Packet {};
class alignas(4) RoomExitRequestPacket : public Packet {
public:
union {
struct {
PacketType packetType;
RequestType requestType;
DataType dataType;
std::uint16_t packetLength;
std::uint8_t data[];
} __data;
std::uint8_t serialized[1500] = "";
};
};
class alignas(4) UsersListRequestPacket : public Packet {
public:
union {
struct {
PacketType packetType;
RequestType requestType;
DataType dataType;
std::uint16_t packetLength;
std::uint8_t name[];
} __data;
std::uint8_t serialized[1500] = "";
};
};
class alignas(4) UsersListRequestPacket : public Packet {};
class alignas(4) DataPostPacket : public Packet {
public:
union {
struct {
PacketType packetType;
PacketCategory packetType;
RequestType requestType;
DataType dataType;
std::uint16_t packetLength;
@@ -175,13 +139,27 @@ class alignas(4) ContinuePacket : public Packet {
public:
union {
struct {
PacketType packetType;
std::uint8_t padding[2];
PacketCategory packetType;
std::uint8_t padding;
DataType dataType;
std::uint16_t packetLength;
std::uint16_t destId[4];
std::uint8_t data[];
} __data;
std::uint8_t serialized[1500] = "";
};
std::uint8_t* convToN() {
__data.packetLength = ::htons(__data.packetLength);
for (int i = 0; i < 4; i++)
__data.destId[i] = ::htons(__data.destId[i]);
return serialized;
}
std::uint8_t* convToH() {
__data.packetLength = ::ntohs(__data.packetLength);
for (int i = 0; i < 4; i++)
__data.destId[i] = ::ntohs(__data.destId[i]);
return serialized;
}
};
enum class ResponseStatusCode : std::uint16_t {
@@ -201,7 +179,7 @@ class alignas(4) ResponsePacket : public Packet {
public:
union {
struct {
PacketType packetType;
PacketCategory packetType;
RequestType requestType;
DataType dataType;
std::uint16_t packetLength;
@@ -222,29 +200,98 @@ public:
}
};
//enum class RequestType : std::uint8_t {
// LOGIN,
// ROOM_CREATE,
// ROOM_LIST,
// ROOM_JOIN,
// ROOM_EXIT,
// USERS_LIST,
// DATA
//};
class alignas(4) LoginResponsePacket : public ResponsePacket {};
class alignas(4) LoginResponsePacket : public ResponsePacket {
class alignas(4) RoomCreateResponsePacket : public ResponsePacket {
public:
union {
struct {
PacketType packetType;
PacketCategory packetType;
RequestType requestType;
DataType dataType;
std::uint16_t packetLength;
ResponseStatusCode responseStatusCode;
std::uint16_t createdRoomId[4];
std::uint8_t data[];
} __data;
std::uint8_t serialized[1500] = "";
};
std::uint8_t* convToN() {
__data.packetLength = ::htons(__data.packetLength);
for (int i = 0; i < 4; i++)
__data.createdRoomId[i] = ::htons(__data.createdRoomId[i]);
return serialized;
}
std::uint8_t* convToH() {
__data.packetLength = ::ntohs(__data.packetLength);
for (int i = 0; i < 4; i++)
__data.createdRoomId[i] = ::ntohs(__data.createdRoomId[i]);
return serialized;
}
};
class alignas(4) RoomListResponsePacket : public ResponsePacket {
public:
union {
struct {
PacketCategory packetType;
RequestType requestType;
DataType dataType;
std::uint16_t packetLength;
ResponseStatusCode responseStatusCode;
std::uint32_t roomCount;
std::uint16_t roomId[4];
std::uint8_t name[];
} __data;
std::uint8_t serialized[1500] = "";
};
std::uint8_t* convToN() {
__data.packetLength = ::htons(__data.packetLength);
__data.roomCount = ::htonl(__data.roomCount);
for (int i = 0; i < 4; i++)
__data.roomId[i] = ::htons(__data.roomId[i]);
return serialized;
}
std::uint8_t* convToH() {
__data.packetLength = ::ntohs(__data.packetLength);
__data.roomCount = ::ntohl(__data.roomCount);
for (int i = 0; i < 4; i++)
__data.roomId[i] = ::ntohs(__data.roomId[i]);
return serialized;
}
};
class alignas(4) RoomJoinResponsePacket : public ResponsePacket {};
class alignas(4) RoomExitResponsePacket : public ResponsePacket {};
class alignas(4) UsersListResponsePacket : public ResponsePacket {
public:
union {
struct {
PacketCategory packetType;
RequestType requestType;
DataType dataType;
std::uint16_t packetLength;
ResponseStatusCode responseStatusCode;
std::uint32_t usersCount;
std::uint16_t userId[4];
std::uint8_t name[];
} __data;
std::uint8_t serialized[1500] = "";
};
std::uint8_t* convToN() {
__data.packetLength = ::htons(__data.packetLength);
for (int i = 0; i < 4; i++)
__data.userId[i] = ::htons(__data.userId[i]);
return serialized;
}
std::uint8_t* convToH() {
__data.packetLength = ::ntohs(__data.packetLength);
for (int i = 0; i < 4; i++)
__data.userId[i] = ::ntohs(__data.userId[i]);
return serialized;
}
};
}