重构NetManager支持MessagePair,新增TSRPCWsClient。
This commit is contained in:
21
client/assets/scripts/App/Msg/Pair/LoginMessagePair.ts
Normal file
21
client/assets/scripts/App/Msg/Pair/LoginMessagePair.ts
Normal 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';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "8a0f8893-e078-4885-8407-70944f67d185",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
23
client/assets/scripts/App/Msg/Pair/MoveMessagePair.ts
Normal file
23
client/assets/scripts/App/Msg/Pair/MoveMessagePair.ts
Normal 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';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "f95aa765-9371-4644-9694-8eb8dd7d8930",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
19
client/assets/scripts/App/Msg/Pair/SendMessagePair.ts
Normal file
19
client/assets/scripts/App/Msg/Pair/SendMessagePair.ts
Normal 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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "d9ef0dad-c949-4a46-9306-d4a060a40a3b",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
Reference in New Issue
Block a user