Ejemplo n.º 1
0
 /// <summary>
 /// 连接服务器回调
 /// </summary>
 private void OnUdpConnected(uint conv, NErrorCode code)
 {
     GameLog.Log("OnUdpConnected,conv:{0}, code:{1}", conv, code);
     if (code == NErrorCode.SUCCESS)
     {
         State = ConnectState.Connected;
         if (m_thread == null)
         {
             // 新建一个线程
             GameLog.Log("[OnUdpConnected]新建一个线程");
             m_thread = new Thread(ThreadProcess);
             m_thread.Start();
         }
         else
         {
             // 恢复线程
             GameLog.Log("[OnUdpConnected]恢复线程");
             m_threadResetEvent.Set();
         }
         m_timerTick = FrameTimer.Create(Tick, 1, -1);
         InitKCP(conv);
         if (OnConnected != null)
         {
             OnConnected();
         }
     }
     else
     {
         ConnectFailed(code);
     }
 }
Ejemplo n.º 2
0
 // 断开连接
 private void ConnectFailed(NErrorCode code)
 {
     Clear();
     if (OnConnectFailed != null)
     {
         OnConnectFailed(code);
     }
 }
Ejemplo n.º 3
0
 internal static NErrorCode ExceptionEncode <TIn>(TIn input, Action <TIn> func)
 {
     try
     {
         func(input);
         return(NErrorCode.Ok);
     }
     catch (Exception e)
     {
         return(NErrorCode.Thrown(e));
     }
 }
Ejemplo n.º 4
0
 internal static NErrorCode ExceptionEncode <TIn, TOut>(ref TOut destination, TIn input, Func <TIn, TOut> func)
 {
     try
     {
         destination = func(input);
         return(NErrorCode.Ok);
     }
     catch (Exception e)
     {
         return(NErrorCode.Thrown(e));
     }
 }
Ejemplo n.º 5
0
 // udp重连回调
 private void OnUdpReconnected(uint conv, NErrorCode code)
 {
     if (code == NErrorCode.SUCCESS)
     {
         State = ConnectState.Connected;
         // 恢复线程
         m_threadResetEvent.Set();
         m_timerTick = FrameTimer.Create(Tick, 1, -1);
     }
     else
     {
         if (code == NErrorCode.ERROR && m_udpClient.DisconnectType == KDisconnectType.FromChange)
         {
             Reconnect();
         }
         else
         {
             ConnectFailed(code);
         }
     }
 }