fly-pigs31
2025-06-25 ee384bc89e3d20dd5706dc48ab86c56d6524b012
添加通用消息结构体
1个文件已添加
72 ■■■■■ 已修改文件
Server/common_type.h 72 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Server/common_type.h
New file
@@ -0,0 +1,72 @@
#ifndef TCPDATATYPE_H
#define TCPDATATYPE_H
/*请求类型*/
enum class ActionType
{
    HeartCheck = 100,
    Login = 110,
    Register = 120,
    Msg = 200,
    Download = 300
};
/*参考HTTP的响应码*/
enum class ResponseCode
{
    ResponseOK = 200,      // 请求成功。
    BadRequest = 400,      // 客户端请求的语法错误,服务器无法理解
    Unauthorized = 401,    // 请求要求用户的身份认证
    Forbidden = 403,       // 服务器理解请求客户端的请求,但是拒绝执行此请求
    NotFound = 404,        // 服务器无法找到请求的资源
    MethodNotAllowed = 405 // 客户端请求中的方法被禁止
};
/*消息体*/
struct Head
{
    ActionType type;
    int len;
    int version;
    Head(ActionType ptype, int plen, int pversion)
    {
        len = plen;
        type = ptype;
        version = pversion;
    }
};
struct HeartCheckReq // 心跳请求包
{
    ActionType type;
    int len;
    HeartCheckReq()
    {
        type = ActionType::HeartCheck;
        len = sizeof(HeartCheckReq);
    }
};
struct HeartCheckRes // 心跳响应包
{
    ActionType type;
    int len;
    HeartCheckRes()
    {
        type = ActionType::HeartCheck;
        len = sizeof(HeartCheckRes);
    }
};
struct RegisterRequest
{
    Head head;
    char name[64];
    char password[64];
    char email[32];
    char phone[32];
};
struct LoginRequest
{
    Head head;
    char name[64];
    char password[64];
};
#endif