1
This commit is contained in:
parent
eff5f21d6d
commit
e80dd01574
@ -33,7 +33,9 @@ class ClientNet {
|
|||||||
this.registerMsgHandle(
|
this.registerMsgHandle(
|
||||||
msgName,
|
msgName,
|
||||||
(msg) => {
|
(msg) => {
|
||||||
this[msgName](msg);
|
if (this[msgName]) {
|
||||||
|
this[msgName](msg);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,8 +59,10 @@ class ClientNet {
|
|||||||
this.smMsgId = this.msgIdPb.lookup('SMMessageId_e');
|
this.smMsgId = this.msgIdPb.lookup('SMMessageId_e');
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
this.selfRegisterMsgHandle('SMLogin');
|
for (let id in this.smMsgId.valuesById) {
|
||||||
this.selfRegisterMsgHandle('SMPing');
|
const msgName = this.smMsgId.valuesById[id];
|
||||||
|
this.selfRegisterMsgHandle(msgName.slice(1));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,26 +129,30 @@ class ClientNet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
registerMsgHandle(msgName, cb) {
|
registerMsgHandle(msgName, cb) {
|
||||||
const msgType = this.protoPb.lookupType(msgName);
|
try {
|
||||||
const msgId = this.smMsgId.values['_' + msgName];
|
const msgType = this.protoPb.lookupType(msgName);
|
||||||
if (!msgId) {
|
const msgId = this.smMsgId.values['_' + msgName];
|
||||||
|
if (!msgId) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
const handle = {
|
||||||
|
msgId: msgId,
|
||||||
|
msgName: msgName,
|
||||||
|
msgType: msgType,
|
||||||
|
cb: cb,
|
||||||
|
uniqId: ++this.uniqId}
|
||||||
|
;
|
||||||
|
if (!this.msgHandlerMap.has(msgId)) {
|
||||||
|
this.msgHandlerMap.set(msgId, new Map([
|
||||||
|
[handle.uniqId, handle]
|
||||||
|
]));
|
||||||
|
} else {
|
||||||
|
this.msgHandlerMap.get(msgId).set(handle.uniqId, handle);
|
||||||
|
}
|
||||||
|
return handle;
|
||||||
|
} catch (err) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
const handle = {
|
|
||||||
msgId: msgId,
|
|
||||||
msgName: msgName,
|
|
||||||
msgType: msgType,
|
|
||||||
cb: cb,
|
|
||||||
uniqId: ++this.uniqId}
|
|
||||||
;
|
|
||||||
if (!this.msgHandlerMap.has(msgId)) {
|
|
||||||
this.msgHandlerMap.set(msgId, new Map([
|
|
||||||
[handle.uniqId, handle]
|
|
||||||
]));
|
|
||||||
} else {
|
|
||||||
this.msgHandlerMap.get(msgId).set(handle.uniqId, handle);
|
|
||||||
}
|
|
||||||
return handle;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unRegisterMsgHandle(handle) {
|
unRegisterMsgHandle(handle) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user