패킷 정의, 로그가 더 많이 설명하도록 변경

This commit is contained in:
2025-04-30 20:13:20 +09:00
parent b662823726
commit af414e58a1
9 changed files with 222 additions and 12 deletions

191
include/Packet/Packet.hpp Normal file
View File

@@ -0,0 +1,191 @@
#pragma once
#include "Utils/Snowflake.hpp"
#include "precomp.hpp"
namespace Chattr {
enum class PacketType : std::uint8_t {
PACKET_POST,
PACKET_REQUEST,
PACKET_RESPONSE,
PACKET_CONTINUE,
};
enum class RequestType : std::uint8_t {
LOGIN,
ROOM_CREATE,
ROOM_LIST,
ROOM_JOIN,
ROOM_EXIT,
USERS_LIST,
DATA
};
enum class DataType : std::uint8_t {
TEXT,
BINARY
};
class alignas(1) Packet {
public:
union {
struct {
PacketType packetType;
RequestType requestType;
DataType dataType;
std::uint16_t packetLength;
std::uint8_t data[1495];
} __data;
std::uint8_t serialized[1500];
};
std::uint8_t* convToN() {
__data.packetLength = ::htons(__data.packetLength);
return serialized;
}
std::uint8_t* convToH() {
__data.packetLength = ::ntohs(__data.packetLength);
return serialized;
}
};
class alignas(1) 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(1) 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(1) RoomListRequestPacket : public Packet {
public:
union {
struct {
PacketType packetType;
RequestType requestType;
DataType dataType;
std::uint16_t packetLength;
std::uint32_t roomCount;
std::uint8_t name[];
} __data;
std::uint8_t serialized[1500];
};
};
class alignas(1) 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(1) 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(1) UsersListRequestPacket : public Packet {
public:
union {
struct {
PacketType packetType;
RequestType requestType;
DataType dataType;
std::uint16_t packetLength;
std::uint32_t usersCount;
std::uint8_t name[];
} __data;
std::uint8_t serialized[1500];
};
};
class alignas(1) DataPostPacket : 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(1) ContinuePacket : public Packet {
public:
union {
struct {
std::uint16_t packetLength;
std::uint8_t data[];
} __data;
std::uint8_t serialized[1500];
};
};
enum class ResponseStatusCode : std::uint16_t {
OK = 200,
CREATED = 201,
ACCEPTED = 202,
BAD_REQUEST = 400,
FORBIDDEN = 403,
NOT_FOUND = 404,
LENGTH_REQUIRED = 411,
IAM_A_TEAPOT = 418,
TOO_MANY_REQUESTS = 429,
INTERNAL_SERVER_ERROR = 500
};
class alignas(1) 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];
};
};
}

View File

@@ -15,9 +15,11 @@ public:
int send();
int recv();
Session(const Session&) = delete;
Session& operator=(Session&) = delete;
private:
std::vector<Chattr::TCPSocket> tcpSock_;
std::vector<Chattr::Socket> udpSock_;
Chattr::TCPSocket sock_;
struct Snowflake sessId_;
};
}

10
include/Socket/IOCP.hpp Normal file
View File

@@ -0,0 +1,10 @@
#pragma once
namespace Chattr {
class IOCP {
public:
IOCP();
~IOCP();
};
}

View File

@@ -14,7 +14,7 @@ public:
void init(int domain, int type, int protocol);
void destruct();
operator SOCKET() const;
operator SOCKET();
void set(const SOCKET);
void bind(sockaddr *__addr);