public void Register(wire obj, cb_t cb) { int cmd = obj._tag(); NetInstance.Login.Register(obj); NetInstance.Gate.Register(obj); Debug.Assert(!protocol_cb.ContainsKey(cmd)); protocol_cb[cmd] = cb; }
public void Register(wire obj, cb_t cb) { int cmd = obj._tag(); Debug.Log("[NetProtocol] Register:" + obj._name() + " tag:" + cmd); Debug.Assert(!protocol_obj.ContainsKey(cmd)); Debug.Assert(!protocol_cb.ContainsKey(cmd)); protocol_obj[cmd] = obj; protocol_cb[cmd] = cb; return; }
private void error(int err, wire obj) { error errobj = (error)obj; int cmd = errobj.cmd; int errno = errobj.err; if (!protocol_obj.ContainsKey(cmd)) { Debug.Log("[NetProtocol] can't has handler of cmd[" + cmd + "]"); return; } cb_t cb = protocol_cb[cmd]; cb(errno, null); return; }
private void ack_error(int err, wire obj) { a_error errobj = (a_error)obj; int cmd = errobj.cmd; int errno = errobj.err; if (!protocol_cb.ContainsKey(cmd)) { Debug.Log("[NetProtocol] can't has handler of cmd[" + cmd + "]"); return; } Module.UI.mb.Show(DB.DB.Errno.Get(errno).Value); cb_t cb = protocol_cb[cmd]; cb(errno, null); return; }
public void Update() { if (socket_status == NetSocket.CLOSE) { return; } if (socket.Status == NetSocket.DISCONNECT) { event_close(); socket_status = NetSocket.DISCONNECT; Debug.Log("[NetProtocol] Reconnect addr " + connect_addr + ":" + connect_port); socket.Connect(connect_addr, connect_port); } switch (socket_status) { case NetSocket.DISCONNECT: if (socket.Status == NetSocket.CONNECTED) { socket_status = NetSocket.CONNECTED; event_connect(); } break; } if (socket.Length < 2) { return; } if (length_val == 0) { socket.Read(buffer, 2); length_val = BitConverter.ToInt16(buffer, 0); length_val = System.Net.IPAddress.NetworkToHostOrder(length_val); } if (socket.Length < length_val) { return; } if (buffer.Length < length_val) { buffer = new byte[length_val]; } socket.Read(buffer, 4); int cmd = BitConverter.ToInt32(buffer, 0); Debug.Assert(length_val > 4); length_val -= sizeof(int); socket.Read(buffer, length_val); if (!protocol_obj.ContainsKey(cmd)) { Debug.Log("[NetProtocol] can't has handler of cmd[" + cmd + "]"); return; } wire obj = protocol_obj[cmd]; int err = obj._parse(buffer, length_val); length_val = 0; //Debug.Log("[NetProtocol] Process cmd[" + obj._name() + "]Err:" + err); if (err < 0) { return; } cb_t cb = protocol_cb[cmd]; cb(0, obj); return; }