This commit is contained in:
aozhiwei 2023-09-15 16:39:02 +08:00
parent eff5f21d6d
commit e80dd01574

View File

@ -33,7 +33,9 @@ class ClientNet {
this.registerMsgHandle(
msgName,
(msg) => {
if (this[msgName]) {
this[msgName](msg);
}
});
}
@ -57,8 +59,10 @@ class ClientNet {
this.smMsgId = this.msgIdPb.lookup('SMMessageId_e');
}
{
this.selfRegisterMsgHandle('SMLogin');
this.selfRegisterMsgHandle('SMPing');
for (let id in this.smMsgId.valuesById) {
const msgName = this.smMsgId.valuesById[id];
this.selfRegisterMsgHandle(msgName.slice(1));
}
}
}
@ -125,6 +129,7 @@ class ClientNet {
}
registerMsgHandle(msgName, cb) {
try {
const msgType = this.protoPb.lookupType(msgName);
const msgId = this.smMsgId.values['_' + msgName];
if (!msgId) {
@ -145,6 +150,9 @@ class ClientNet {
this.msgHandlerMap.get(msgId).set(handle.uniqId, handle);
}
return handle;
} catch (err) {
return null;
}
}
unRegisterMsgHandle(handle) {