重构Api接口到Msg
This commit is contained in:
11
server/src/shared/protocols/MsgReqLogin.ts
Normal file
11
server/src/shared/protocols/MsgReqLogin.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
|
||||
/**
|
||||
* 登录请求消息
|
||||
*/
|
||||
export interface MsgReqLogin {
|
||||
/** 玩家ID(用于识别玩家) */
|
||||
playerId: string;
|
||||
|
||||
/** 玩家昵称(可选,新玩家时使用) */
|
||||
playerName?: string;
|
||||
}
|
||||
10
server/src/shared/protocols/MsgReqMove.ts
Normal file
10
server/src/shared/protocols/MsgReqMove.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
/**
|
||||
* 移动请求消息
|
||||
*/
|
||||
export interface MsgReqMove {
|
||||
/** X坐标 */
|
||||
x: number;
|
||||
|
||||
/** Y坐标 */
|
||||
y: number;
|
||||
}
|
||||
7
server/src/shared/protocols/MsgReqSend.ts
Normal file
7
server/src/shared/protocols/MsgReqSend.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
/**
|
||||
* 发送消息请求
|
||||
*/
|
||||
export interface MsgReqSend {
|
||||
/** 消息内容 */
|
||||
content: string;
|
||||
}
|
||||
@@ -1,61 +1,50 @@
|
||||
import { Position } from './base';
|
||||
|
||||
/**
|
||||
* 登录请求
|
||||
*/
|
||||
export interface ReqLogin {
|
||||
/** 玩家ID(用于识别玩家) */
|
||||
playerId: string;
|
||||
|
||||
/** 玩家昵称(可选,新玩家时使用) */
|
||||
playerName?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 玩家角色信息
|
||||
*/
|
||||
export interface PlayerInfo {
|
||||
/** 玩家ID */
|
||||
id: string;
|
||||
|
||||
/** 玩家昵称 */
|
||||
name: string;
|
||||
|
||||
/** 当前位置 */
|
||||
position: Position;
|
||||
|
||||
/** 出生点 */
|
||||
spawnPoint: Position;
|
||||
|
||||
/** 当前生命值 */
|
||||
hp: number;
|
||||
|
||||
/** 最大生命值 */
|
||||
maxHp: number;
|
||||
|
||||
/** 是否存活 */
|
||||
isAlive: boolean;
|
||||
|
||||
/** 创建时间 */
|
||||
createdAt: number;
|
||||
|
||||
/** 最后登录时间 */
|
||||
lastLoginAt: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录响应
|
||||
*/
|
||||
export interface ResLogin {
|
||||
/** 是否成功 */
|
||||
success: boolean;
|
||||
|
||||
/** 消息 */
|
||||
message: string;
|
||||
|
||||
/** 玩家信息 */
|
||||
player?: PlayerInfo;
|
||||
|
||||
/** 是否新玩家 */
|
||||
isNewPlayer?: boolean;
|
||||
}
|
||||
import { Position } from './base';
|
||||
|
||||
/**
|
||||
* 玩家角色信息
|
||||
*/
|
||||
export interface PlayerInfo {
|
||||
/** 玩家ID */
|
||||
id: string;
|
||||
|
||||
/** 玩家昵称 */
|
||||
name: string;
|
||||
|
||||
/** 当前位置 */
|
||||
position: Position;
|
||||
|
||||
/** 出生点 */
|
||||
spawnPoint: Position;
|
||||
|
||||
/** 当前生命值 */
|
||||
hp: number;
|
||||
|
||||
/** 最大生命值 */
|
||||
maxHp: number;
|
||||
|
||||
/** 是否存活 */
|
||||
isAlive: boolean;
|
||||
|
||||
/** 创建时间 */
|
||||
createdAt: number;
|
||||
|
||||
/** 最后登录时间 */
|
||||
lastLoginAt: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录响应消息
|
||||
*/
|
||||
export interface MsgResLogin {
|
||||
/** 是否成功 */
|
||||
success: boolean;
|
||||
|
||||
/** 消息 */
|
||||
message: string;
|
||||
|
||||
/** 玩家信息 */
|
||||
player?: PlayerInfo;
|
||||
|
||||
/** 是否新玩家 */
|
||||
isNewPlayer?: boolean;
|
||||
}
|
||||
15
server/src/shared/protocols/MsgResMove.ts
Normal file
15
server/src/shared/protocols/MsgResMove.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { Position } from './base';
|
||||
|
||||
/**
|
||||
* 移动响应消息
|
||||
*/
|
||||
export interface MsgResMove {
|
||||
/** 是否成功 */
|
||||
success: boolean;
|
||||
|
||||
/** 消息 */
|
||||
message: string;
|
||||
|
||||
/** 新位置(成功时返回) */
|
||||
position?: Position;
|
||||
}
|
||||
7
server/src/shared/protocols/MsgResSend.ts
Normal file
7
server/src/shared/protocols/MsgResSend.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
/**
|
||||
* 发送消息响应
|
||||
*/
|
||||
export interface MsgResSend {
|
||||
/** 发送时间 */
|
||||
time: Date;
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
import { Position } from './base';
|
||||
|
||||
/**
|
||||
* 移动请求
|
||||
*/
|
||||
export interface ReqMove {
|
||||
/** 目标位置 X 坐标 */
|
||||
x: number;
|
||||
|
||||
/** 目标位置 Y 坐标 */
|
||||
y: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* 移动响应
|
||||
*/
|
||||
export interface ResMove {
|
||||
/** 是否成功 */
|
||||
success: boolean;
|
||||
|
||||
/** 消息 */
|
||||
message?: string;
|
||||
|
||||
/** 实际移动后的位置 */
|
||||
position?: Position;
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
// This is a demo code file
|
||||
// Feel free to delete it
|
||||
|
||||
export interface ReqSend {
|
||||
content: string
|
||||
}
|
||||
|
||||
export interface ResSend {
|
||||
time: Date
|
||||
}
|
||||
@@ -2,34 +2,32 @@ import { ServiceProto } from 'tsrpc-proto';
|
||||
import { MsgChat } from './MsgChat';
|
||||
import { MsgPlayerJoin } from './MsgPlayerJoin';
|
||||
import { MsgPlayerMove } from './MsgPlayerMove';
|
||||
import { ReqLogin, ResLogin } from './PtlLogin';
|
||||
import { ReqMove, ResMove } from './PtlMove';
|
||||
import { ReqSend, ResSend } from './PtlSend';
|
||||
import { MsgReqLogin } from './MsgReqLogin';
|
||||
import { MsgReqMove } from './MsgReqMove';
|
||||
import { MsgReqSend } from './MsgReqSend';
|
||||
import { MsgResLogin } from './MsgResLogin';
|
||||
import { MsgResMove } from './MsgResMove';
|
||||
import { MsgResSend } from './MsgResSend';
|
||||
|
||||
export interface ServiceType {
|
||||
api: {
|
||||
"Login": {
|
||||
req: ReqLogin,
|
||||
res: ResLogin
|
||||
},
|
||||
"Move": {
|
||||
req: ReqMove,
|
||||
res: ResMove
|
||||
},
|
||||
"Send": {
|
||||
req: ReqSend,
|
||||
res: ResSend
|
||||
}
|
||||
|
||||
},
|
||||
msg: {
|
||||
"Chat": MsgChat,
|
||||
"PlayerJoin": MsgPlayerJoin,
|
||||
"PlayerMove": MsgPlayerMove
|
||||
"PlayerMove": MsgPlayerMove,
|
||||
"ReqLogin": MsgReqLogin,
|
||||
"ReqMove": MsgReqMove,
|
||||
"ReqSend": MsgReqSend,
|
||||
"ResLogin": MsgResLogin,
|
||||
"ResMove": MsgResMove,
|
||||
"ResSend": MsgResSend
|
||||
}
|
||||
}
|
||||
|
||||
export const serviceProto: ServiceProto<ServiceType> = {
|
||||
"version": 3,
|
||||
"version": 5,
|
||||
"services": [
|
||||
{
|
||||
"id": 0,
|
||||
@@ -47,19 +45,34 @@ export const serviceProto: ServiceProto<ServiceType> = {
|
||||
"type": "msg"
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"name": "Login",
|
||||
"type": "api"
|
||||
"id": 6,
|
||||
"name": "ReqLogin",
|
||||
"type": "msg"
|
||||
},
|
||||
{
|
||||
"id": 5,
|
||||
"name": "Move",
|
||||
"type": "api"
|
||||
"id": 7,
|
||||
"name": "ReqMove",
|
||||
"type": "msg"
|
||||
},
|
||||
{
|
||||
"id": 1,
|
||||
"name": "Send",
|
||||
"type": "api"
|
||||
"id": 8,
|
||||
"name": "ReqSend",
|
||||
"type": "msg"
|
||||
},
|
||||
{
|
||||
"id": 9,
|
||||
"name": "ResLogin",
|
||||
"type": "msg"
|
||||
},
|
||||
{
|
||||
"id": 10,
|
||||
"name": "ResMove",
|
||||
"type": "msg"
|
||||
},
|
||||
{
|
||||
"id": 11,
|
||||
"name": "ResSend",
|
||||
"type": "msg"
|
||||
}
|
||||
],
|
||||
"types": {
|
||||
@@ -176,18 +189,18 @@ export const serviceProto: ServiceProto<ServiceType> = {
|
||||
}
|
||||
]
|
||||
},
|
||||
"PtlLogin/ReqLogin": {
|
||||
"MsgReqLogin/MsgReqLogin": {
|
||||
"type": "Interface",
|
||||
"properties": [
|
||||
{
|
||||
"id": 1,
|
||||
"id": 0,
|
||||
"name": "playerId",
|
||||
"type": {
|
||||
"type": "String"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"id": 1,
|
||||
"name": "playerName",
|
||||
"type": {
|
||||
"type": "String"
|
||||
@@ -196,7 +209,38 @@ export const serviceProto: ServiceProto<ServiceType> = {
|
||||
}
|
||||
]
|
||||
},
|
||||
"PtlLogin/ResLogin": {
|
||||
"MsgReqMove/MsgReqMove": {
|
||||
"type": "Interface",
|
||||
"properties": [
|
||||
{
|
||||
"id": 0,
|
||||
"name": "x",
|
||||
"type": {
|
||||
"type": "Number"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 1,
|
||||
"name": "y",
|
||||
"type": {
|
||||
"type": "Number"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"MsgReqSend/MsgReqSend": {
|
||||
"type": "Interface",
|
||||
"properties": [
|
||||
{
|
||||
"id": 0,
|
||||
"name": "content",
|
||||
"type": {
|
||||
"type": "String"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"MsgResLogin/MsgResLogin": {
|
||||
"type": "Interface",
|
||||
"properties": [
|
||||
{
|
||||
@@ -214,16 +258,16 @@ export const serviceProto: ServiceProto<ServiceType> = {
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"id": 2,
|
||||
"name": "player",
|
||||
"type": {
|
||||
"type": "Reference",
|
||||
"target": "PtlLogin/PlayerInfo"
|
||||
"target": "MsgResLogin/PlayerInfo"
|
||||
},
|
||||
"optional": true
|
||||
},
|
||||
{
|
||||
"id": 5,
|
||||
"id": 3,
|
||||
"name": "isNewPlayer",
|
||||
"type": {
|
||||
"type": "Boolean"
|
||||
@@ -232,7 +276,7 @@ export const serviceProto: ServiceProto<ServiceType> = {
|
||||
}
|
||||
]
|
||||
},
|
||||
"PtlLogin/PlayerInfo": {
|
||||
"MsgResLogin/PlayerInfo": {
|
||||
"type": "Interface",
|
||||
"properties": [
|
||||
{
|
||||
@@ -302,26 +346,7 @@ export const serviceProto: ServiceProto<ServiceType> = {
|
||||
}
|
||||
]
|
||||
},
|
||||
"PtlMove/ReqMove": {
|
||||
"type": "Interface",
|
||||
"properties": [
|
||||
{
|
||||
"id": 0,
|
||||
"name": "x",
|
||||
"type": {
|
||||
"type": "Number"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 1,
|
||||
"name": "y",
|
||||
"type": {
|
||||
"type": "Number"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"PtlMove/ResMove": {
|
||||
"MsgResMove/MsgResMove": {
|
||||
"type": "Interface",
|
||||
"properties": [
|
||||
{
|
||||
@@ -336,8 +361,7 @@ export const serviceProto: ServiceProto<ServiceType> = {
|
||||
"name": "message",
|
||||
"type": {
|
||||
"type": "String"
|
||||
},
|
||||
"optional": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
@@ -350,19 +374,7 @@ export const serviceProto: ServiceProto<ServiceType> = {
|
||||
}
|
||||
]
|
||||
},
|
||||
"PtlSend/ReqSend": {
|
||||
"type": "Interface",
|
||||
"properties": [
|
||||
{
|
||||
"id": 0,
|
||||
"name": "content",
|
||||
"type": {
|
||||
"type": "String"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"PtlSend/ResSend": {
|
||||
"MsgResSend/MsgResSend": {
|
||||
"type": "Interface",
|
||||
"properties": [
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user