/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~网络~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ /// <summary> /// 网络压力 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OnNetPageClick(object sender, EventArgs e) { if (m_tabNet_Start.Text == "停止") { m_tabNet_Start.Enabled = false; ClientNetManager.Instance.CloseAll(); m_tabNet_Start.Text = "开始"; m_tabNet_Start.Enabled = true; EnableTabPage(true, m_tabNet); EnableNetTabPage(true); EventController.TriggerEvent(ClientEventID.SWITCH_PRESSURE, ePressureType.Net, false); } else { sPressureNetInfo info = new sPressureNetInfo(); info.ip = this.m_tabNet_IP.Text; info.port = ushort.Parse(this.m_tabNet_Port.Text); info.client_count = ushort.Parse(this.m_tabNet_ClientCount.Text); info.send_count_per_second = ushort.Parse(this.m_tabNet_SendCountPerSecond.Text); info.send_size_per_packet = ushort.Parse(this.m_tabNet_SendSizePerSecond.Text); ServerConfig.net_info.net_server_ip = info.ip; ServerConfig.net_info.net_server_port = info.port; ServerConfig.net_info.net_client_count = info.client_count; m_tabNet_Start.Enabled = false; EnableTabPage(false, m_tabNet); EnableNetTabPage(false); m_pressure_type = ePressureType.Net; m_tabNet_Start.Text = "停止"; EventController.TriggerEvent(ClientEventID.SWITCH_PRESSURE, ePressureType.Net, true, info); ClientNetManager.Instance.StartConnect(info.ip, info.port, info.client_count, 5); m_tabNet_Start.Enabled = true; } }
private void OnGameEvent(GameEvent evt) { switch (evt.type) { case ClientEventID.NET_CONNECTED_OPEN: { if (!m_active) { break; } long conn_idx = evt.Get <long>(0); if (!m_connectes.Contains(conn_idx)) { m_connectes.Add(conn_idx); } } break; case ClientEventID.NET_CONNECTED_CLOSE: { if (!m_active) { break; } long conn_idx = evt.Get <long>(0); m_connectes.Remove(conn_idx); } break; case ClientEventID.SWITCH_PRESSURE: { ePressureType type = evt.Get <ePressureType>(0); bool is_start = evt.Get <bool>(1); if (type == ePressureType.Net && is_start) { m_pressure_info = evt.Get <sPressureNetInfo>(2); this.Start(); } else { this.Stop(); } } break; case ClientEventID.RECV_DATA: { if (!m_active) { break; } long conn_idx = evt.Get <long>(0); ushort header = evt.Get <ushort>(1); ByteArray data = evt.Get <ByteArray>(2); if (header == gs2c.msg.ENCRYPT) { m_had_recv_encrypt = true; PacketBase packet = PacketPools.Get(header); packet.Read(data); GlobalID.ENCRYPT_KEY = (packet as gs2c.EncryptInfo).key; PacketPools.Recover(packet); } } break; } }