리눅스랑 코드 동기화
This commit is contained in:
@@ -29,13 +29,16 @@ enum class DataType : std::uint8_t {
|
||||
|
||||
class alignas(4) Packet {
|
||||
public:
|
||||
Packet() {
|
||||
memset(serialized, 0, 1500);
|
||||
}
|
||||
union {
|
||||
struct {
|
||||
PacketType packetType;
|
||||
RequestType requestType;
|
||||
DataType dataType;
|
||||
std::uint16_t packetLength;
|
||||
std::uint8_t data[1484];
|
||||
std::uint8_t data[1495];
|
||||
} __data;
|
||||
std::uint8_t serialized[1500];
|
||||
};
|
||||
@@ -90,6 +93,16 @@ public:
|
||||
} __data;
|
||||
std::uint8_t serialized[1500];
|
||||
};
|
||||
std::uint8_t* convToN() {
|
||||
__data.packetLength = ::htons(__data.packetLength);
|
||||
__data.roomCount = ::htonl(__data.roomCount);
|
||||
return serialized;
|
||||
}
|
||||
std::uint8_t* convToH() {
|
||||
__data.packetLength = ::ntohs(__data.packetLength);
|
||||
__data.roomCount = ::ntohl(__data.roomCount);
|
||||
return serialized;
|
||||
}
|
||||
};
|
||||
|
||||
class alignas(4) RoomJoinRequestPacket : public Packet {
|
||||
@@ -128,7 +141,6 @@ public:
|
||||
RequestType requestType;
|
||||
DataType dataType;
|
||||
std::uint16_t packetLength;
|
||||
std::uint32_t usersCount;
|
||||
std::uint8_t name[];
|
||||
} __data;
|
||||
std::uint8_t serialized[1500];
|
||||
@@ -143,16 +155,31 @@ public:
|
||||
RequestType requestType;
|
||||
DataType dataType;
|
||||
std::uint16_t packetLength;
|
||||
std::uint8_t name[];
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
class alignas(4) ContinuePacket : public Packet {
|
||||
public:
|
||||
union {
|
||||
struct {
|
||||
PacketType packetType;
|
||||
std::uint8_t padding[2];
|
||||
std::uint16_t packetLength;
|
||||
std::uint8_t data[];
|
||||
} __data;
|
||||
@@ -174,6 +201,41 @@ enum class ResponseStatusCode : std::uint16_t {
|
||||
};
|
||||
|
||||
class alignas(4) ResponsePacket : public Packet {
|
||||
public:
|
||||
union {
|
||||
struct {
|
||||
PacketType packetType;
|
||||
RequestType requestType;
|
||||
DataType dataType;
|
||||
std::uint16_t packetLength;
|
||||
ResponseStatusCode responseStatusCode;
|
||||
std::uint8_t data[];
|
||||
} __data;
|
||||
std::uint8_t serialized[1500];
|
||||
};
|
||||
std::uint8_t* convToN() {
|
||||
__data.packetLength = ::htons(__data.packetLength);
|
||||
__data.responseStatusCode = (ResponseStatusCode)::htons((std::uint16_t)__data.responseStatusCode);
|
||||
return serialized;
|
||||
}
|
||||
std::uint8_t* convToH() {
|
||||
__data.packetLength = ::ntohs(__data.packetLength);
|
||||
__data.responseStatusCode = (ResponseStatusCode)::ntohs((std::uint16_t)__data.responseStatusCode);
|
||||
return serialized;
|
||||
}
|
||||
};
|
||||
|
||||
//enum class RequestType : std::uint8_t {
|
||||
// LOGIN,
|
||||
// ROOM_CREATE,
|
||||
// ROOM_LIST,
|
||||
// ROOM_JOIN,
|
||||
// ROOM_EXIT,
|
||||
// USERS_LIST,
|
||||
// DATA
|
||||
//};
|
||||
|
||||
class alignas(4) LoginResponsePacket : public ResponsePacket {
|
||||
public:
|
||||
union {
|
||||
struct {
|
||||
|
||||
Reference in New Issue
Block a user