示例#1
0
文件: Task.cs 项目: fengqk/Art
        internal static void Dispatch(Manager manager, Session session, Protocol protocol)
        {            
            //Task task = new Task(manager, session, protocol);            
            //ThreadPool.AddTask(task);
			//CUI Modify in 2014/05/26
			manager.OnRecvProtocol(session, protocol);
        }
示例#2
0
文件: Protocol.cs 项目: fengqk/Art
        public static void Register(int iType, Protocol prtc)
        {
            if (m_prtcMap.ContainsKey(iType))
                return; 

            m_prtcMap.Add(iType, prtc);
        }
示例#3
0
文件: Task.cs 项目: fengqk/Art
 private Task(Manager _manager, Session _session, Protocol _protocol)
     : base()
 {
     manager = _manager;
     session = _session;
     protocol = _protocol;
     time_start = WatchDog.GetTime();
 }
示例#4
0
文件: DirClient.cs 项目: fengqk/Art
        public override void OnRecvProtocol(Session session, Protocol protocol)
        {
			//UnityEngine.Debug.Log("DirClient:OnRecvProtocol. procotol type:" + protocol.getProtocolType().ToString());
            if(protocol.getProtocolType()==DirInfo.PROTOCOL_TYPE)
		    {
                DirInfo p = protocol as DirInfo;
                if(p!=null)
                {
			        Close(session);
					m_dirInfo = p;
					m_requesting = false;
                }
		    }
        }
示例#5
0
文件: Manager.cs 项目: fengqk/Art
 public bool Send(Session session, Protocol protocol)
 {
     if (!set.Contains(session)) return false;
     return session.Send(protocol);
 }
示例#6
0
文件: Manager.cs 项目: fengqk/Art
 public virtual void OnRecvProtocol(Session session, Protocol protocol) {}
示例#7
0
文件: PingClient.cs 项目: fengqk/Art
        public override void OnRecvProtocol(Session session, Protocol protocol)
        {
            Console.WriteLine("PingClient:OnRecvProtocol. procotol type:" + protocol.getProtocolType().ToString());
            if(protocol.getProtocolType()==Challenge.PROTOCOL_TYPE)
		    {
                Challenge p = protocol as Challenge;
                if(p!=null)
                {
                    ServerStatus status = new ServerStatus();
			       // status.attr = *(Attr*)(p->nonce.begin());
                    {
                        lock (locker) 
                        {
                            status.ping = (uint)(Environment.TickCount - pingmap[session.ID]);
                        }
                    }
			        if(status.ping<=5)
				            status.ping = 5;
			        status.ping = status.ping>9999?9999:status.ping;
                    m_callback(status, session, (int)EVENT.EVENT_PINGRETURN);
			        Close(session);
			        //p.Destroy();

                }
			   
		    }
        }
示例#8
0
文件: GameClient.cs 项目: fengqk/Art
        public override void OnRecvProtocol(Session session, Protocol protocol)
        {
			try
			{
				lock (locker)
				{
					if (this.session == session)
					{
						if (protocol.getProtocolType() == KeepAlive.PROTOCOL_TYPE)
						{
							m_lastrecv = (uint)Environment.TickCount;
							m_ping = m_lastrecv - m_lastsend;
							//protocol.Destroy();
						}
						else if (protocol.getProtocolType() == (int)GNET.NetProtocolType.PROTOCOL_MARSHALDATA)
						{
							CommonData p = (CommonData)protocol;
							GNET.MarshalData md = new GNET.MarshalData();

							md.unmarshal(p.GetData());

							Protocol prtc = Protocol.DecodeMarshal(md.data);
							protocol = null;
							if (prtc != null)
								m_callback(prtc, session, (int)WM.WM_IOPROTOCOL);
						}
						else
						{
							m_callback(protocol, session, (int)WM.WM_IOPROTOCOL);
						}
					}
				}
			}
			catch (Exception e)
			{
				Debug.LogException(e);	//线程里,输出下错误信息
			}
        }
示例#9
0
文件: GameClient.cs 项目: fengqk/Art
 public bool SendProtocol(Protocol protocol) 
 { 
     return (session != null) && Send(session, protocol);
 }
示例#10
0
文件: Session.cs 项目: fengqk/Art
	    internal bool Send(Protocol protocol)
	    {
            bool osempty = (os.Count == 0);
		    lock(ilock)
		    {
			    OctetsStream o = new OctetsStream();
			    protocol.Encode(o);
			    if (protocol.SizePolicy(o.size()))
			    {
					//增加低延迟模式的处理
					if(obuffer.size () == 0 && os.Count == 0 && Output(o))
					{
						if(assoc_io != null && assoc_io.channel != null)
						{
							//直接发送数据
                            try
                            {
                                int sentcount = assoc_io.channel.Send(obuffer.buffer(), obuffer.size(), SocketFlags.None);
                                if (sentcount > 0)
                                {
                                    obuffer.erase(0, sentcount);
                                    return true;
                                }
                            }
                            catch (Exception e)
                            {
                                obuffer.clear();
                                UnityEngine.Debug.LogWarning(e.StackTrace);
                                UnityEngine.Debug.LogWarning(e.Message);
                            }
						}
					}
					else
					{
					    os.AddLast(o);
	                    if (osempty)
	                    {
	                        osempty = false;
	                    }
					    need_wakeup = true;
					}


				    return true;
			    }                
		    }
		    return false;
	    }