Exemple #1
0
    public static ClientObject CreateInstance()
    {
        ClientObject clientObject = new ClientObject();
        Client       c            = NetManager.GetInstance().CreateClient(NModuleManager.GetInstance());

        c.PackageFactory = new Core.Net.PackageFactoryEx();
        clientObject.c   = c;
        cache.Add(clientObject.GetPid(), clientObject);
        cache_by_client.Add(c, clientObject);

//        #if DEBUG_CORE
        Logger.Log("client object create. pid:" + clientObject.GetPid());
//        #endif

        return(clientObject);
    }
Exemple #2
0
    public UInt32 Send(Client c, int messageid)
    {
        ClientObject obj;

        ClientObject.cache_by_client.TryGetValue(c, out obj);

        IntPtr    L = XLuaManager.Instance.GetLuaEnv().rawL;
        NFunction f = NModuleManager.GetInstance().GetFunctin(messageid);

        if (f != null)
        {
            Package p = c.PackageFactory.CreatePackage();
            p.MessageID = messageid;
            p.Header.SetExtData(c.NextSendPackageExtData);
//            Logger.Log("send message id is " + messageid);
            FormatPackage(p, f, L);
            c.Send(p);
            if (null != this.OnSend)
            {
                this.OnSend(messageid, p.Header.GetExtData(), p.Header.GetSeqNum());
            }

#if UNITY_EDITOR
            StringBuilder sb = new StringBuilder();
            sb.Append(f.Nm.Name);
            sb.Append(".");
            sb.Append(f.Name);
            if (!m_allSendMessage.ContainsKey(messageid))
            {
                m_allSendMessage.Add(messageid, sb.ToString());
                if (!m_allHandleMessage.ContainsKey(sb.ToString()))
                {
//                    Logger.Log(string.Format("<color=#ff9900ff><<<need handle message>>>,id:{0} name:{1}</color>", messageid, sb.ToString()));
                    m_allHandleMessage.Add(sb.ToString(), 1);
                }
            }
            //Logger.Log(string.Format("<color=#00ababff><<<send>>>,msgid:{0}({1})</color>", messageid, sb.ToString()), Logger.LogLevel.Important);
#endif
            return(p.Header.GetExtData());
        }
        return(0);
    }