Exemplo n.º 1
0
 public void CallAllExcludeOne(PlayerBusiness exclude, Sinan.Collections.BytesSegment buffer)
 {
     if (this.m_showAll)
     {
         foreach (var member in m_players.Values)
         {
             if (exclude != member)
             {
                 member.Call(buffer);
             }
         }
     }
     else
     {
         //副本场景.只发给本场景的组队成员
         long showID = exclude.ShowID;
         foreach (var member in m_players.Values)
         {
             if (member.ShowID == showID && exclude != member)
             {
                 member.Call(buffer);
             }
         }
     }
 }
Exemplo n.º 2
0
        public SocketToken(int id,
            Sinan.Collections.BytesSegment receiveBuffer,
            Sinan.Collections.BytesSegment sendBuffer,
            IBufferProcessor processor,
            Collections.CircularQueue<Collections.BytesSegment> sendPool = null)
        {
            m_connectID = id;
            m_sendPool = sendPool ?? new Collections.CircularQueue<Collections.BytesSegment>(64);
            m_processor = processor;
            SocketAsyncEventArgs receiver = new SocketAsyncEventArgs();
            receiver.Completed += new EventHandler<SocketAsyncEventArgs>(ReceiveCompleted);
            receiver.SetBuffer(receiveBuffer.Array, receiveBuffer.Offset, receiveBuffer.Count);

            SocketAsyncEventArgs sender = new SocketAsyncEventArgs();
            sender.Completed += new EventHandler<SocketAsyncEventArgs>(SendCompleted);
            sender.SetBuffer(sendBuffer.Array, sendBuffer.Offset, sendBuffer.Count);

            m_receiver = receiver;
            m_receiveOffset = receiver.Offset;
            m_receiveMax = receiver.Count;

            m_sender = sender;
            m_sendOffset = sender.Offset;
            m_sendMax = sender.Count;
        }
Exemplo n.º 3
0
 /// <summary>
 /// 发送给场景上所有用户
 /// </summary>
 /// <param name="command"></param>
 /// <param name="objs"></param>
 public void CallAll(Sinan.Collections.BytesSegment buffer)
 {
     SceneBusiness scene = m_scene;
     if (scene != null)
     {
         scene.CallAll(this.ShowID, buffer);
     }
 }
Exemplo n.º 4
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="id">唯一ID</param>
 /// <param name="receiveBuffer">接收缓冲区</param>
 /// <param name="sendBuffer">发送缓冲区</param>
 /// <param name="socket">连接的Socket</param>
 /// <param name="process"></param>
 public GMToken(int id,
     Sinan.Collections.BytesSegment receiveBuffer,
     Sinan.Collections.BytesSegment sendBuffer,
     Socket socket,
     IBufferProcessor process)
     : base(id, receiveBuffer, sendBuffer, process, null)
 {
     m_socket = socket;
     m_address = ((System.Net.IPEndPoint)(socket.RemoteEndPoint)).Address;
     Created = DateTime.UtcNow;
 }
Exemplo n.º 5
0
 /// <summary>
 /// 调用客户端的方法
 /// </summary>
 /// <param name="buffer">已编码的方法调用</param>
 public bool Call(Sinan.Collections.BytesSegment buffer)
 {
     UserSession user = m_session;
     if (user != null)
     {
         if (user.SendAsync(buffer) == SocketError.Success)
         {
             return true;
         }
     }
     return false;
 }
Exemplo n.º 6
0
 public int Execute(ISession session, Sinan.Collections.BytesSegment data)
 {
     List<Tuple<int, List<object>>> results = new List<Tuple<int, List<object>>>();
     int offset = data.Offset;
     int maxIndex = offset + data.Count;
     byte[] buffer = data.Array;
     while (maxIndex >= offset + 2)
     {
         // 取包长,前两字节表示
         int packetLen = buffer[offset] + (buffer[offset + 1] << 8);
         if (packetLen < m_capacity)
         {
             if (maxIndex < offset + packetLen)
             {
                 break;
             }
             try
             {
                 if (!session.Decode(buffer, offset, packetLen))
                 {
                     session.Close();
                     return -1;
                 }
                 // 取命令,第3/4字节
                 int command = buffer[offset + 2] + (buffer[offset + 3] << 8);
                 var param = AmfCodec.Decode(buffer, offset, packetLen);
                 results.Add(new Tuple<int, List<object>>(command, param));
     #if FlowLog
                 // 写流量接收记录
                 FlowLog.AddIn(command, packetLen);
     #endif
             }
             catch (AmfException ex)
             {
                 LogWrapper.Warn(session.ToString(), ex);
                 session.Close();
                 return -1;
             }
         }
         foreach (var v in results)
         {
             if (!this.Execute(session, v))
             {
                 break;
             }
         }
         offset += packetLen;
     }
     return maxIndex - offset;
 }
Exemplo n.º 7
0
 /// <summary>
 /// 发送消息给指定用户
 /// </summary>
 /// <param name="userID">用户ID</param>
 /// <param name="buffer">已编码的方法调用</param>
 public static bool Call(string userID, Sinan.Collections.BytesSegment buffer)
 {
     if (userID != null)
     {
         UserSession user;
         if (m_users.TryGetValue(userID, out user))
         {
             if (user.SendAsync(buffer) == SocketError.Success)
             {
                 return true;
             }
         }
     }
     return false;
 }
Exemplo n.º 8
0
 public void CallAll(long showID, Sinan.Collections.BytesSegment buffer)
 {
     if (m_showAll)
     {
         foreach (var member in m_players.Values)
         {
             member.Call(buffer);
         }
     }
     else
     {
         foreach (var member in m_players.Values)
         {
             if (member.ShowID == showID)
             {
                 member.Call(buffer);
             }
         }
     }
 }
Exemplo n.º 9
0
 /// <summary>
 /// 向客户端发送数据(异步方式.)
 /// </summary>
 /// <param name="buffer"></param>
 /// <returns></returns>
 public SocketError SendAsync(Sinan.Collections.BytesSegment buffer)
 {
     try
     {
         if (buffer == null)
         {
             return SocketError.NoData;
         }
         // 尝试0变1,锁定Sender;
         int state = Interlocked.CompareExchange(ref m_socketInUse, 1, 0);
         if (state == 0)
         {
             if (m_curBuff == null && m_sendPool.IsEmpty)
             {
                 m_curBuff = buffer;
             }
             else
             {
                 m_sendPool.Enqueue(buffer);
             }
             SendData();
         }
         else if (state == 1)
         {
             m_sendPool.Enqueue(buffer);
         }
         else
         {
             return SocketError.NotConnected;
         }
         //记日志
     #if FlowLog
         FlowLog.AddOut(buffer.Array, buffer.Offset);
     #endif
         return SocketError.Success;
     }
     catch
     {
         if (m_socketInUse < 2)
         {
             Thread.VolatileWrite(ref m_socketInUse, 2);
         }
         return SocketError.NotConnected;
     }
 }
Exemplo n.º 10
0
 /// <summary>
 /// Initializes a new instance of the Amf3Writer class
 /// </summary>
 /// <param name="stream"></param>
 internal Amf3Writer(Sinan.Collections.BytesSegment segment)
 {
     m_bin = segment.Array;
     m_offset = segment.Offset;
     m_maxIndex = m_offset + segment.Count;
 }
Exemplo n.º 11
0
 public bool Equals(Sinan.Collections.BytesSegment obj)
 {
     if (!object.ReferenceEquals(null, obj))
     {
         if (object.ReferenceEquals(this, obj)
             || ((this.array == obj.Array) && (this.offset == obj.Offset) && (this.count == obj.Count)))
         {
             return true;
         }
     }
     return false;
 }
Exemplo n.º 12
0
 internal UserBuffer(int id,
     SessionFactory f,
     Sinan.Collections.BytesSegment r,
     Sinan.Collections.BytesSegment s,
     int sendQueueSize = 64)
 {
     this.factory = f;
     this.BufferID = id;
     this.ReceiveBuffer = r;
     this.SendBuffer = s;
     this.SendPool = new Sinan.Collections.CircularQueue<Sinan.Collections.BytesSegment>(sendQueueSize);
 }
Exemplo n.º 13
0
 /// <summary>
 /// 调用客户端的方法
 /// </summary>
 /// <param name="buffer">已编码的方法调用</param>
 /// <param name="all">暂离队员是否接收</param>
 /// <param name="exclude">排除的队员</param>
 public bool Call(Sinan.Collections.BytesSegment buffer, bool all, PlayerBusiness exclude)
 {
     for (int i = 0; i < m_members.Length; i++)
     {
         PlayerBusiness member = m_members[i];
         if (member != null && member != exclude)
         {
             if (all || member.TeamJob != TeamJob.Away)
             {
                 member.Call(buffer);
             }
         }
     }
     return true;
 }
Exemplo n.º 14
0
 /// <summary>
 /// 调用某个家族所有在线玩家的方法
 /// </summary>
 /// <param name="familyName"></param>
 /// <param name="buffer"></param>
 public static void CallFamily(string familyName, Sinan.Collections.BytesSegment buffer)
 {
     foreach (var player in m_online.Values)
     {
         if (player.Online && player.FamilyName == familyName)
         {
             player.Call(buffer);
         }
     }
 }
Exemplo n.º 15
0
 /// <summary>
 /// 调用所有玩家的方法
 /// </summary>
 /// <param name="buffer"></param>
 public static void CallAll(Sinan.Collections.BytesSegment buffer)
 {
     foreach (var player in m_online.Values)
     {
         if (player.Online)
         {
             player.Call(buffer);
         }
     }
 }
Exemplo n.º 16
0
 /// <summary>
 /// 发送消息给其它场景上的队员
 /// </summary>
 /// <param name="buffer"></param>
 /// <returns></returns>
 public bool CallAway(Sinan.Collections.BytesSegment buffer, string sceneID)
 {
     for (int i = 0; i < m_members.Length; i++)
     {
         PlayerBusiness member = m_members[i];
         if (member != null && member.SceneID != sceneID)
         {
             member.Call(buffer);
         }
     }
     return true;
 }
Exemplo n.º 17
0
 public static string Sign(Sinan.Collections.BytesSegment value)
 {
     return Sign(value.Array, value.Offset, value.Count);
 }