// 连接过程中的控制包 目前只有服务器主动断开连接 private void DealCtrlPkgOfConnected(byte[] data) { KCPPacket packet = new KCPPacket(data, data.Length); KCPPacket.KOperateStruct optInfo = packet.ParseOperatePkg(); if (optInfo == null) { return; } if (optInfo.cmd == KConnCmd.Disconnect && State == ConnectState.Connected) { // 服务器主动断开连接 DisconnectType = (KDisconnectType)optInfo.content; State = ConnectState.Disconnected; } }
private void DealConnectingRspData(byte[] data) { KCPPacket packet = new KCPPacket(data, data.Length); KCPPacket.KOperateStruct optInfo = packet.ParseOperatePkg(); if (optInfo == null) { return; } StopConnTimer(); GameLog.LogFormat("DealConnectingRspData, info:{0}", optInfo.ToString()); switch (optInfo.cmd) { // 连接成功 case KConnCmd.ConnRsp: { if (optInfo.flowID == s_flowID) { GameLog.Log("连接成功"); State = ConnectState.Connected; m_conKey = optInfo.content; m_conv = optInfo.conv; if (m_onConnected != null) { m_onConnected(m_conv, NErrorCode.SUCCESS); } } else { GameLog.Log("收到连接应答,flowID 不匹配"); } break; } // 连接失败 case KConnCmd.Disconnect: { Clear(); DisconnectType = (KDisconnectType)optInfo.content; m_onConnected(0, NErrorCode.ERROR); break; } } }
//KCP--->UDP private void SendKCPPacket(KCPPacket kcpPacket) { //this.SendPacketData(kcpPacket.fullData); udpClient.SendData(kcpPacket.fullData); }