重构NetManager支持MessagePair,新增TSRPCWsClient。

This commit is contained in:
janing
2025-12-18 13:25:04 +08:00
parent c12e439add
commit fb940452db
41 changed files with 976 additions and 681 deletions

View File

@@ -0,0 +1,21 @@
import { MsgReqLogin } from '../../../Shared/protocols/MsgReqLogin';
import { MsgResLogin } from '../../../Shared/protocols/MsgResLogin';
import { MessagePair } from '../MessagePairBase';
/**
* 登录消息对实现
*/
export class LoginMessagePair extends MessagePair<MsgReqLogin, MsgResLogin> {
readonly requestName = 'ReqLogin';
readonly responseName = 'ResLogin';
isValidRequest(msg: any): msg is MsgReqLogin {
return msg && typeof msg.playerId === 'string';
}
isValidResponse(msg: any): msg is MsgResLogin {
return msg &&
typeof msg.success === 'boolean' &&
typeof msg.message === 'string';
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "8a0f8893-e078-4885-8407-70944f67d185",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,23 @@
import { MsgReqMove } from '../../../Shared/protocols/MsgReqMove';
import { MsgResMove } from '../../../Shared/protocols/MsgResMove';
import { MessagePair } from '../MessagePairBase';
/**
* 移动消息对实现
*/
export class MoveMessagePair extends MessagePair<MsgReqMove, MsgResMove> {
readonly requestName = 'ReqMove';
readonly responseName = 'ResMove';
isValidRequest(msg: any): msg is MsgReqMove {
return msg &&
typeof msg.x === 'number' &&
typeof msg.y === 'number';
}
isValidResponse(msg: any): msg is MsgResMove {
return msg &&
typeof msg.success === 'boolean' &&
typeof msg.message === 'string';
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "f95aa765-9371-4644-9694-8eb8dd7d8930",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,19 @@
import { MsgReqSend } from '../../../Shared/protocols/MsgReqSend';
import { MsgResSend } from '../../../Shared/protocols/MsgResSend';
import { MessagePair } from '../MessagePairBase';
/**
* 发送消息对实现
*/
export class SendMessagePair extends MessagePair<MsgReqSend, MsgResSend> {
readonly requestName = 'ReqSend';
readonly responseName = 'ResSend';
isValidRequest(msg: any): msg is MsgReqSend {
return msg && typeof msg.content === 'string';
}
isValidResponse(msg: any): msg is MsgResSend {
return msg && msg.time instanceof Date;
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "d9ef0dad-c949-4a46-9306-d4a060a40a3b",
"files": [],
"subMetas": {},
"userData": {}
}