/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~事件~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ private void OnAcceptConnect(long conn_idx) { m_sockets.Add(conn_idx); c2gs.EncryptInfo msg = PacketPools.Get(c2gs.msg.ENCRYPT) as c2gs.EncryptInfo; msg.version = 1; this.Send(conn_idx, msg); EventController.TriggerEvent(ClientEventID.NET_CONNECTED_OPEN, conn_idx); }
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~事件~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ private void OnAcceptConnect(long conn_idx) { m_cur_conn_idx = conn_idx; c2gs.EncryptInfo msg = PacketPools.Get(c2gs.msg.ENCRYPT) as c2gs.EncryptInfo; msg.version = GlobalID.GetVersion(); this.Send(msg); EventController.TriggerEvent(ClientEventID.NET_CONNECTED_OPEN, m_cur_conn_idx); }
/// <summary> /// 加密 /// </summary> private void OnClientEncrypt(long conn_idx, PacketBase packet) { if (!ClientSessionManager.Instance.HasAcceptSession(conn_idx)) { return; } c2gs.EncryptInfo msg = packet as c2gs.EncryptInfo; //版本验证 byte main_version; byte sub_version; ushort revision_version; GlobalID.SplitVersion(msg.version, out main_version, out sub_version, out revision_version); if (main_version != GlobalID.VERSION_MAIN) { ClientSessionManager.Instance.KickoutSession(conn_idx); return; } GlobalID.SetClientVersion(msg.version); //收到正常的握手协议后,才加入正式session列表 ClientSession session = ClientSessionManager.Instance.AddSession(conn_idx); if (session != null) { ClientSessionManager.Instance.CleanupAcceptSession(conn_idx); session.session_status = eSessionStatus.CREATED; gs2c.EncryptInfo rep_msg = PacketPools.Get(gs2c.msg.ENCRYPT) as gs2c.EncryptInfo; rep_msg.key = PacketEncrypt.Encrypt_Key; rep_msg.flags = 0; session.Send(rep_msg); } else { ClientSessionManager.Instance.KickoutSession(conn_idx); } }