Merge remote-tracking branch 'origin/main'

This commit is contained in:
DZY 2025-06-02 14:27:48 +08:00
commit 0cd6c87c89
2 changed files with 95 additions and 0 deletions

26
API.md Normal file
View File

@ -0,0 +1,26 @@
聊天服务器API文档
1. 服务器概述
‌服务类型‌: 混合服务(HTTP + Socket)
HTTP端口: 5001 (Flask)
Socket端口: 8888
‌数据库‌: SQLite (usr.db)
2. HTTP API接口
2.1 用户注册
‌端点‌: POST /api/register
‌请求格式‌:
json
Copy Code
{
"username": "string",
"password": "string"
}
‌成功响应‌:
json
Copy Code
{
"success": true,
"message": "User registered successfully"
}
‌错误响应‌:
403: 用户名已存在
500: 服务器内部错误

69
socketapi.md Normal file
View File

@ -0,0 +1,69 @@
# Socket API 文档
## 1. 连接信息
- 地址: localhost
- 端口: 8888
- 协议: TCP
## 2. 消息格式
所有消息均为JSON格式必须包含type字段
### 2.1 注册请求
```json
{
"type": "register",
"username": "string",
"password": "string"
}
```
### 2.2 登录请求
```json
{
"type": "login",
"username": "string",
"password": "string"
}
```
### 2.3 聊天消息
```json
{
"type": "chat",
"message": "string"
}
```
## 3. 响应格式
### 3.1 注册响应
```json
{
"success": boolean,
"message": "string"
}
```
### 3.2 登录响应
```json
{
"status": "success|error",
"message": "string"
}
```
### 3.3 聊天广播
```json
{
"type": "chat",
"user": "string",
"message": "string"
}
```
## 4. 状态码
- 200: 操作成功
- 403: 用户名已存在(注册时)
- 401: 认证失败(登录时)
- 500: 服务器内部错误