コード例 #1
0
 internal void SendPeerMessage(RoomPeer peer, RoomMessageDefine id, object msg)
 {
     try {
         NetOutgoingMessage om = m_NetServer.CreateMessage();
         om.Write(Serialize.Encode(msg, (int)id));
         if (null != peer.GetConnection())
         {
             NetSendResult res = m_NetServer.SendMessage(om, peer.GetConnection(), NetDeliveryMethod.ReliableOrdered, 0);
             if (res == NetSendResult.Dropped)
             {
                 LogSys.Log(LOG_TYPE.ERROR, "SendPeerMessage {0} failed:dropped, User:{1}({2})", msg.ToString(), peer.Guid, peer.GetKey());
             }
         }
     } catch (Exception ex) {
         LogSys.Log(LOG_TYPE.ERROR, "Exception {0}\n{1}", ex.Message, ex.StackTrace);
     }
 }
コード例 #2
0
        internal void OnPeerDestroy(RoomPeer peer)
        {
            if (peer == null)
            {
                return;
            }
            RoomPeer dummy = null;

            if (m_KeyPeer.TryRemove(peer.GetKey(), out dummy))
            {
                if (peer.GetConnection() != null)
                {
                    if (!m_DicPeer.TryRemove(peer.GetConnection(), out dummy))
                    {
                        AddToNeedDelete(peer.GetConnection());
                    }
                }
            }
            else
            {
                AddToNeedDelete(peer.GetKey());
            }
        }
コード例 #3
0
 internal void Tick()
 {
     try {
         if (m_NeedAddKey2Peers.Count > 0)
         {
             lock (m_LockObj) {
                 foreach (KeyValuePair <uint, RoomPeer> pair in m_NeedAddKey2Peers)
                 {
                     if (m_KeyPeer.ContainsKey(pair.Key) || m_KeyPeer.TryAdd(pair.Key, pair.Value))
                     {
                         m_DeletedAddKeys.Add(pair.Key);
                     }
                 }
             }
         }
         if (m_NeedAddConnection2Peers.Count > 0)
         {
             lock (m_LockObj) {
                 foreach (KeyValuePair <NetConnection, RoomPeer> pair in m_NeedAddConnection2Peers)
                 {
                     if (m_DicPeer.ContainsKey(pair.Key) || m_DicPeer.TryAdd(pair.Key, pair.Value))
                     {
                         m_DeletedAddConnections.Add(pair.Key);
                     }
                 }
             }
         }
         if (m_DeletedAddKeys.Count > 0)
         {
             lock (m_LockObj) {
                 foreach (uint key in m_DeletedAddKeys)
                 {
                     m_NeedAddKey2Peers.Remove(key);
                 }
                 m_DeletedAddKeys.Clear();
             }
         }
         if (m_DeletedAddConnections.Count > 0)
         {
             lock (m_LockObj) {
                 foreach (NetConnection conn in m_DeletedAddConnections)
                 {
                     m_NeedAddConnection2Peers.Remove(conn);
                 }
                 m_DeletedAddConnections.Clear();
             }
         }
         if (m_NeedDeleteKeys.Count > 0)
         {
             lock (m_LockObj) {
                 foreach (uint key in m_NeedDeleteKeys)
                 {
                     RoomPeer peer = null;
                     if (!m_KeyPeer.ContainsKey(key))
                     {
                         m_DeletedKeys.Add(key);
                     }
                     else if (m_KeyPeer.TryRemove(key, out peer))
                     {
                         m_DeletedKeys.Add(key);
                         if (null != peer)
                         {
                             m_NeedDeleteConnections.Add(peer.GetConnection());
                         }
                     }
                 }
             }
         }
         if (m_NeedDeleteConnections.Count > 0)
         {
             lock (m_LockObj) {
                 foreach (NetConnection conn in m_NeedDeleteConnections)
                 {
                     RoomPeer peer = null;
                     if (!m_DicPeer.ContainsKey(conn))
                     {
                         m_DeletedConnections.Add(conn);
                     }
                     else if (m_DicPeer.TryRemove(conn, out peer))
                     {
                         m_DeletedConnections.Add(conn);
                     }
                 }
             }
         }
         if (m_DeletedKeys.Count > 0)
         {
             lock (m_LockObj) {
                 foreach (uint key in m_DeletedKeys)
                 {
                     m_NeedDeleteKeys.Remove(key);
                 }
                 m_DeletedKeys.Clear();
             }
         }
         if (m_DeletedConnections.Count > 0)
         {
             lock (m_LockObj) {
                 foreach (NetConnection conn in m_DeletedConnections)
                 {
                     m_NeedDeleteConnections.Remove(conn);
                 }
                 m_DeletedConnections.Clear();
             }
         }
     } catch (Exception ex) {
         LogSys.Log(LOG_TYPE.ERROR, "Exception {0}\n{1}", ex.Message, ex.StackTrace);
     }
 }