From ee384bc89e3d20dd5706dc48ab86c56d6524b012 Mon Sep 17 00:00:00 2001 From: fly-pigs31 <2316735315@qq.com> Date: 星期三, 25 六月 2025 17:13:55 +0800 Subject: [PATCH] 添加通用消息结构体 --- Server/common_type.h | 72 ++++++++++++++++++++++++++++++++++++ 1 files changed, 72 insertions(+), 0 deletions(-) diff --git a/Server/common_type.h b/Server/common_type.h new file mode 100644 index 0000000..68ac3f8 --- /dev/null +++ b/Server/common_type.h @@ -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 -- Gitblit v1.8.0