public void sendBoardMsg_Req(int[,] iArrayPC, string sNotcie)
        {
            int nChan = iArrayPC.GetLength(0);

            string strNotice = sNotcie;

            msgStruct = new CMsg((short)protocol.GM_NOTICE_REQ);

            msgStruct.WriteData(System.Text.Encoding.Default.GetBytes(strNotice), strNotice.Length);

            byte[] ret = new byte[] {
                (byte)nChan, (byte)(nChan >> 8)
            };
            msgStruct.WriteData(ret, 2);

            for (int i = 0; i < nChan; i++)
            {
                //星球
                ret = new byte[] {
                    (byte)iArrayPC[i, 0], (byte)(nChan >> 8)
                };
                msgStruct.WriteData(ret, 2);
                //频道
                ret = new byte[] {
                    (byte)iArrayPC[i, 1], (byte)(nChan >> 8)
                };
                msgStruct.WriteData(ret, 2);
            }
            msgStruct.writeLength(msgStruct.GetSize());
            client.Send(msgStruct.GetBuf(), 0, msgStruct.GetSize(), 0);
        }
示例#2
0
    public void Parse(Stream source)
    {
        CMsg cmsg       = ProtoBuf.Serializer.Deserialize <CMsg>(source);
        int  cmd        = cmsg.cmd;
        int  dest       = cmsg.dest;
        long serverTime = cmsg.serverTime;

        byte[] body = cmsg.body;

        //消息号保存进队列
        PBNO _pb = new PBNO();

        _pb.msg        = cmsg;
        _pb.pbInstance = null;

        //分发协议去解析
        _pb.pbInstance = pb.ParseData(dest, cmd, body);

        if (IsOftenData(dest, cmd))
        {
            net.PushDataScene(_pb);
        }
        else
        {
            net.PushDataQueue(_pb);
        }

        Debug.Log("收到消息 dest=" + dest + ",cmd=" + cmd);
    }
示例#3
0
    public void SerializeData(SendDataStruct data)
    {
        MemoryStream memStream = new MemoryStream();

        ProtoBuf.Serializer.Serialize(memStream, data.instance);

        byte[] body = memStream.ToArray();
        CMsg   _nnn = new CMsg();

        _nnn.dest = data.dest;
        _nnn.cmd  = data.cmd;
        if (body != null && body.Length > 0)
        {
            _nnn.body = body;
        }

        //放在消息队列里面发
        messageStruct smsg = new messageStruct();

        smsg.dest = data.dest;
        smsg.cmd  = data.cmd;
        smsg.body = PBParseManage.getSerialize <CMsg>(_nnn);

        NetWorkManage.getInstance().PushSendDataQueue(smsg);
    }
        public void SendMsg(ProtoBuf.IExtensible pMsg, Int32 n32MsgID)
        {
            if (m_Client != null)
            {
                //清除stream
                mSendStream.SetLength(0);
                mSendStream.Position = 0;


                //序列到stream
                ProtoBuf.Serializer.Serialize(mSendStream, pMsg);
                CMsg pcMsg = new CMsg((int)mSendStream.Length);
                pcMsg.SetProtocalID(n32MsgID);
                pcMsg.Add(mSendStream.ToArray(), 0, (int)mSendStream.Length);
                //ms.Close();
#if UNITY_EDITOR
#else
                try
                {
#endif

#if LOG_FILE && UNITY_EDITOR
                if (n32MsgID != 8192 && n32MsgID != 16385)
                {
                    string msgName = "";
                    if (Enum.IsDefined(typeof(GCToBS.MsgNum), n32MsgID))
                    {
                        msgName = ((GCToBS.MsgNum)n32MsgID).ToString();
                    }
                    else if (Enum.IsDefined(typeof(GCToCS.MsgNum), n32MsgID))
                    {
                        msgName = ((GCToCS.MsgNum)n32MsgID).ToString();
                    }
                    else if (Enum.IsDefined(typeof(GCToLS.MsgID), n32MsgID))
                    {
                        msgName = ((GCToLS.MsgID)n32MsgID).ToString();
                    }
                    else if (Enum.IsDefined(typeof(GCToSS.MsgNum), n32MsgID))
                    {
                        msgName = ((GCToSS.MsgNum)n32MsgID).ToString();
                    }

                    using (System.IO.StreamWriter sw = new System.IO.StreamWriter(@"E:\Log.txt", true))
                    {
                        sw.WriteLine(Time.time + "   发送消息:\t" + n32MsgID + "\t" + msgName);
                    }
                }
#endif
                m_Client.GetStream().Write(pcMsg.GetMsgBuffer(), 0, (int)pcMsg.GetMsgSize());
#if UNITY_EDITOR
#else
            }
            catch (Exception exc)
            {
                Debugger.LogError(exc.ToString());
                Close();
            }
#endif
            }
        }
示例#5
0
    public void SerializeData(SendDataStruct data)
    {
        MemoryStream memStream = new MemoryStream();

        ProtoBuf.Serializer.Serialize(memStream, data.instance);

        byte[] body = memStream.ToArray();
        CMsg   msg  = new CMsg();

        msg.dest = data.dest;
        msg.cmd  = data.cmd;
        if (body != null && body.Length > 0)
        {
            msg.body = body;
        }

        //放在消息队列里面发
        MessageStruct smsg = new MessageStruct();

        smsg.dest = data.dest;
        smsg.cmd  = data.cmd;
        smsg.body = (byte[])Serialize(msg);

        SendreceiveManage.getInstance().PushSendData(smsg);
    }
示例#6
0
    public static MessageStruct SerializeData(int dest, int cmd, global::ProtoBuf.IExtensible instance)
    {
        MemoryStream memStream = new MemoryStream();

        ProtoBuf.Serializer.Serialize(memStream, instance);

        byte[] body = memStream.ToArray();
        CMsg   msg  = new CMsg();

        msg.dest = dest;
        msg.cmd  = cmd;
        if (body != null && body.Length > 0)
        {
            msg.body = body;
        }

        //放在消息队列里面发
        MessageStruct smsg = new MessageStruct();

        smsg.dest = dest;
        smsg.cmd  = cmd;
        smsg.body = (byte[])Serialize(msg);

        return(smsg);
    }
        /*接收消息
         * */
        public int receiveMsg()
        {
            byte[] recvBuf = new byte[4096];
            short  size    = 0;

            try
            {
                if (client.Receive(recvBuf, 0, 2, 0) != 2)
                {
                    return(0);
                }

                size = (short)CMsg.toInteger(recvBuf, 2);
                if (size > 0)
                {
                    if (size > CMsg.NETWORK_MSG_SIZE)
                    {
                        Console.WriteLine("Message Too Large");
                        return(0);
                    }
                    if (client.Receive(recvBuf, 2, size - 2, 0) == size - 2)
                    {
                        System.Array.Copy(recvBuf, msgStruct.GetBuf(), size);
                        msgStruct.Clear();
                        return(size);
                    }
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(0);
            }
            return(0);
        }
示例#8
0
        public void sendBoardMsg_Req()
        {
            int    nChan     = 40;
            string strNotice = null;

            msgStruct = new CMsg((short)protocol.GM_NOTICE_REQ);
            msgStruct.WriteData(System.Text.Encoding.Default.GetBytes(strNotice), strNotice.Length);
            byte[] ret = new byte[] {
                (byte)nChan, (byte)(nChan >> 8)
            };
            msgStruct.WriteData(ret, 4);
            client.Send(msgStruct.GetBuf(), 0, msgStruct.GetSize(), 0);
            for (int i = 0; i < nChan; i++)
            {
                ulong itemdata = 0;
                ret = new byte[] {
                    (byte)LOWORD(itemdata), (byte)(LOWORD(itemdata) >> 8)
                };
                msgStruct.WriteData(ret, 2);
                ret = new byte[] {
                    (byte)HIWORD(itemdata), (byte)(HIWORD(itemdata) >> 8)
                };
                msgStruct.WriteData(ret, 2);
            }
            msgStruct.writeLength(msgStruct.GetSize());
            client.Send(msgStruct.GetBuf(), 0, msgStruct.GetSize(), 0);
        }
示例#9
0
    public void DeserializeData(ReceDataStruct source)
    {
        if (source == null)
        {
            return;
        }

        Stream stream = new MemoryStream(source.data, 0, source.datalen);

        CMsg cmsg = ProtoBuf.Serializer.Deserialize <CMsg>(stream);

        //消息号保存进队列
        MessageStruct message = new MessageStruct();

        message.cmd        = cmsg.cmd;
        message.dest       = cmsg.cmd;
        message.body       = cmsg.body;
        message.serverTime = cmsg.serverTime;

        //分发协议去解析
        if (onDispense != null)
        {
            onDispense(message);
        }

        SendreceiveManage.getInstance().PushReceData(message);

        Debug.Log("收到消息 dest=" + cmsg.dest + ",cmd=" + cmsg.cmd);
    }
示例#10
0
    //解析协议信息
    private void ParseDataByPbManage(Stream source)
    {
        CMsg cmsg       = ProtoBuf.Serializer.Deserialize <CMsg>(source);
        int  cmd        = cmsg.cmd;
        int  dest       = cmsg.dest;
        long serverTime = cmsg.serverTime;

        byte[] body = cmsg.body;
        //消息号保存进队列
        PBNO _pb = new PBNO();

        _pb.msg = cmsg;

        //分发协议去解析
        pbManage.ParseData(dest, cmd, body);

        if (IsOftenData(dest, cmd))
        {
            recDataScene.Enqueue(_pb);
        }
        else
        {
            recDataQueue.Enqueue(_pb);
        }

        Debug.Log("收到消息 dest=" + dest + ",cmd=" + cmd);
    }
示例#11
0
                public static Int32 PopMsgFromMemQueue(CMemQueue cMsgQueue, CMsg cMsg)
                {
                    Int32 n32Get = cMsgQueue.GetFront(cMsg.GetMsgBuffer(), (UInt32)s_n32MsgHeaderSize);

                    if (0 != n32Get)
                    {
                        return(n32Get);
                    }

                    Int32 n32MsgSize = cMsg.GetMsgSize();
//                    if (n32MsgSize >= cMsg.m_n32MsgSize)
//                    {
//                        return -2;
//                    }

                    Int32 n32Pop = cMsgQueue.PopFront(cMsg.GetMsgBuffer(), (UInt32)n32MsgSize);

                    if (0 != n32Pop)
                    {
                        return(-3);
                    }

                    cMsg.SetReadPos(s_n32MsgHeaderSize);
                    cMsg.SetWritePos(n32MsgSize);
                    return(0);
                }
示例#12
0
        public ActionResult AddNewBeeFloor(Guid NewBeeID, string mdTxt, string mdValue)
        {
            DisabledUser user = MyRedisDB.GetSet <DisabledUser>(MyRedisKeys.DisabledUsers).Where(d => d.UserID == CurrentUser.ID && d.ObjectType == (int)EnumObjectType.NewBee && d.AbleDate > DateTime.Now).FirstOrDefault();

            if (user != null)
            {
                return(Json(new { msg = "你被封禁至" + user.AbleDate.ToString("yyyy-MM-dd HH:ss") }));
            }
            if (string.IsNullOrEmpty(mdTxt) || string.IsNullOrEmpty(mdValue))
            {
                return(Json(new { msg = "参数错误" }));
            }
            if (mdTxt.GetByteCount() > 2500 || mdValue.GetByteCount() > 5000)
            {
                return(Json(new { msg = "参数太长" }));
            }

            NewBee newBee = NewBeeDataSvc.GetByID(NewBeeID);

            newBee.FloorCount   += 1;
            newBee.LastFloorDate = DateTime.Now;

            NewBeeFloor floor = new NewBeeFloor();

            floor.NewBeeID = NewBeeID;
            floor.MDText   = mdTxt;
            floor.MDValue  = HtmlST.Sanitize(mdValue);
            floor.OwnerID  = CurrentUser.ID;
            floor.Order    = newBee.FloorCount;
            NewBeeFloorDataSvc.Add(floor);

            NewBeeDataSvc.Update(newBee);

            if (newBee.OwnerID != CurrentUser.ID)
            {
                string key   = MyRedisKeys.Pre_CMsg + newBee.OwnerID;
                CMsg   bcmsg = MyRedisDB.GetSet <CMsg>(key).Where(m => m.ObjID == NewBeeID).FirstOrDefault();
                if (bcmsg != null)
                {
                    MyRedisDB.SetRemove(key, bcmsg);
                    bcmsg.Count += 1;
                    MyRedisDB.SetAdd(key, bcmsg);
                }
                else
                {
                    bcmsg         = new CMsg();
                    bcmsg.ObjType = (int)EnumObjectType.NewBee;
                    bcmsg.ObjID   = NewBeeID;
                    bcmsg.Count   = 1;
                    bcmsg.Date    = DateTime.Now;
                    bcmsg.Order   = floor.Order;
                    bcmsg.Title   = newBee.Title.MaxByteLength(32);
                    MyRedisDB.SetAdd(key, bcmsg);
                }
            }

            return(Json(new { msg = "done", count = newBee.FloorCount }));
        }
示例#13
0
        public ActionResult AddBlogComment(Guid blogID, string mdTxt, string mdValue)
        {
            DisabledUser user = MyRedisDB.GetSet <DisabledUser>(MyRedisKeys.DisabledUsers).Where(d => d.UserID == CurrentUser.ID && d.ObjectType == (int)EnumObjectType.姿势 && d.AbleDate > DateTime.Now).FirstOrDefault();

            if (user != null)
            {
                return(Json(new { msg = "你被封禁至" + user.AbleDate.ToString("yyyy-MM-dd HH:ss") }));
            }
            if (string.IsNullOrEmpty(mdTxt) || string.IsNullOrEmpty(mdValue))
            {
                return(Json(new { msg = "参数错误" }));
            }
            if (mdTxt.GetByteCount() > 5000 || mdValue.GetByteCount() > 10000)
            {
                return(Json(new { msg = "参数太长" }));
            }

            Blog blog = BlogDataSvc.GetByID(blogID);

            blog.CommentCount += 1;

            BlogComment comment = new BlogComment();

            comment.BlogID  = blogID;
            comment.MDText  = mdTxt;
            comment.MDValue = HtmlST.Sanitize(mdValue);
            comment.OwnerID = CurrentUser.ID;
            comment.Order   = blog.CommentCount;
            BlogCommentDataSvc.Add(comment);

            BlogDataSvc.Update(blog);

            if (blog.OwnerID != CurrentUser.ID)
            {
                string key   = MyRedisKeys.Pre_CMsg + blog.OwnerID;
                CMsg   bcmsg = MyRedisDB.GetSet <CMsg>(key).Where(m => m.ObjID == blogID).FirstOrDefault();
                if (bcmsg != null)
                {
                    MyRedisDB.SetRemove(key, bcmsg);
                    bcmsg.Count += 1;
                    MyRedisDB.SetAdd(key, bcmsg);
                }
                else
                {
                    bcmsg         = new CMsg();
                    bcmsg.ObjType = (int)EnumObjectType.姿势;
                    bcmsg.ObjID   = blogID;
                    bcmsg.Count   = 1;
                    bcmsg.Date    = DateTime.Now;
                    bcmsg.Order   = comment.Order;
                    bcmsg.Title   = blog.Title.MaxByteLength(32);
                    MyRedisDB.SetAdd(key, bcmsg);
                }
            }

            return(Json(new { msg = "done", count = blog.CommentCount }));
        }
示例#14
0
        public void sendDelayedMsg(int state, int delay, CUnit receiver)
        {
            CMsg msg = new CMsg();

            msg.state        = state;
            msg.sender       = this;
            msg.receiver     = receiver;
            msg.deliveryTime = delay;

            MsgPool.addElement(msg);
        }
示例#15
0
        public void SendMsg(IMessage pMsg, Int32 n32MsgID)
        {
            if (m_Client != null)
            {
                Debug.Log("send msg " + n32MsgID);
                ByteString bs    = pMsg.ToByteString();
                CMsg       pcMsg = new CMsg((int)bs.Length);
                pcMsg.SetProtocalID(n32MsgID);
                pcMsg.Add(bs.ToByteArray(), 0, (int)bs.Length);
#if UNITY_EDITOR
#else
                try
                {
#endif

#if LOG_FILE && UNITY_EDITOR
                if (n32MsgID != 8192 && n32MsgID != 16385)
                {
                    string msgName = "";
                    if (Enum.IsDefined(typeof(GCToBS.MsgNum), n32MsgID))
                    {
                        msgName = ((GCToBS.MsgNum)n32MsgID).ToString();
                    }
                    else if (Enum.IsDefined(typeof(GCToCS.MsgNum), n32MsgID))
                    {
                        msgName = ((GCToCS.MsgNum)n32MsgID).ToString();
                    }
                    else if (Enum.IsDefined(typeof(GCToLS.MsgID), n32MsgID))
                    {
                        msgName = ((GCToLS.MsgID)n32MsgID).ToString();
                    }
                    else if (Enum.IsDefined(typeof(GCToSS.MsgNum), n32MsgID))
                    {
                        msgName = ((GCToSS.MsgNum)n32MsgID).ToString();
                    }

                    using (System.IO.StreamWriter sw = new System.IO.StreamWriter(@"E:\Log.txt", true))
                    {
                        sw.WriteLine(Time.time + "   发送消息:\t" + n32MsgID + "\t" + msgName);
                    }
                }
#endif
                m_Client.GetStream().Write(pcMsg.GetMsgBuffer(), 0, (int)pcMsg.GetMsgSize());
#if UNITY_EDITOR
#else
            }
            catch (Exception exc)
            {
                Debug.LogError(exc.ToString());
                Close();
            }
#endif
            }
        }
示例#16
0
        public void SendMessage(CMsg msg)
        {
            if ((ushort)msg.GetMgrID() == mMgrId)
            {
                aProcessMsg(msg);
//				ProcessMsg(msg);
            }
            else
            {
                CMsgCenter.Instance.SendToMsg(msg);
            }
        }
示例#17
0
        public dynamic MsgAddEvent(int memberID, int actID)
        {
            var loginMember = db.tMember.Where(t => t.f會員編號 == memberID).FirstOrDefault();

            string[] blackList = { };
            if (!string.IsNullOrEmpty(loginMember.f會員黑名單))
            {
                blackList = loginMember.f會員黑名單.Split(',');
            }

            string[] msgs          = { };
            string[] msgsTime      = { };
            string[] msgsID        = { };
            string[] msgsPic       = { };
            string[] msgsTimeAndID = { };
            var      targetAct     = db.tActivity.Where(t => t.f活動編號 == actID).FirstOrDefault();

            if (!string.IsNullOrEmpty(targetAct.f活動留言))
            {
                msgs = targetAct.f活動留言.Split(new string[] { "_^$" }, StringSplitOptions.None); //因包含對話內容,
                                                                                               //因此利用複數特殊字元做分割
                msgsTimeAndID = targetAct.f活動留言時間.Split(',');
                msgsTime      = new string[msgsTimeAndID.Length];
                msgsID        = new string[msgsTimeAndID.Length];
                msgsPic       = new string[msgsTimeAndID.Length];
                for (int i = 0; i <= msgsTimeAndID.Length - 1; i++)
                {
                    if (string.IsNullOrEmpty(msgsTimeAndID[i]))
                    {
                        continue;
                    }
                    var temp = msgsTimeAndID[i].Split(new string[] { "_^$" }, StringSplitOptions.None);
                    msgsTime[i] = temp[0];
                    msgsID[i]   = temp[1];
                    int realID = Convert.ToInt32(msgsID[i]);
                    msgsPic[i] = db.tMember.Where(t => t.f會員編號 == realID).FirstOrDefault().f會員大頭貼;
                    if (string.IsNullOrEmpty(msgsPic[i]))//防止註冊沒有預設大頭貼
                    {
                        msgsPic[i] = "default.jpg";
                    }
                }
            }
            CMsg result = new CMsg();

            result.Msgs      = msgs;
            result.MsgsTime  = msgsTime;
            result.MsgPic    = msgsPic;
            result.MsgID     = msgsID;
            result.BlackList = blackList;
            result.ActID     = actID;
            return(result);
        }
        public void ReadThreadFunc()
        {
            while (true)
            {
                if (receiveMsg() > 0)
                {
                    parseMsg();

                    msgStruct = new CMsg((short)protocol.GM_CHANNELLIST_REQ);
                    msgStruct.writeLength(msgStruct.GetSize());
                    client.Send(msgStruct.GetBuf(), 0, msgStruct.GetSize(), 0);
                    Thread.Sleep(1000);
                }
            }
        }
示例#19
0
    //发送协议数据到服务器 只传协议号,没有内容
    public static void SendData(int dest, int cmd)
    {
#if UNITY_EDITOR
        Debug.Log("要发送协议:dest=" + dest + ",cmd=" + cmd);
#endif
        SendPBMsg smsg = new SendPBMsg();
        smsg.dest = dest;
        smsg.cmd  = cmd;
        CMsg _nnn = new CMsg();
        _nnn.dest     = dest;
        _nnn.cmd      = cmd;
        smsg.sendBody = PBParseManage.getSerialize <CMsg>(_nnn);

        sendMemory.Add(smsg);
    }
示例#20
0
        public ActionResult Socket()
        {
            try
            {
                CMsgHead head = CMsgHead.CreateBuilder()
                                .SetMsglen(2 + 2 + 1)
                                .SetMsgtype(2)
                                .Build();

                CMsgReg body = CMsgReg.CreateBuilder().
                               SetT(1)
                               .Build();

                CMsg msg = CMsg.CreateBuilder()
                           .SetMsghead(head.ToByteString().ToStringUtf8())
                           .SetMsgbody(body.ToByteString().ToStringUtf8())
                           .Build();


                Console.WriteLine("CLIENT : 对象构造完毕 ...");

                using (TcpClient client = new TcpClient())
                {
                    // client.Connect(new IPEndPoint(IPAddress.Parse("192.168.1.116"), 12345));
                    client.Connect(new IPEndPoint(IPAddress.Parse("192.168.1.30"), 5200));
                    Console.WriteLine("CLIENT : socket 连接成功 ...");

                    using (NetworkStream stream = client.GetStream())
                    {
                        //发送
                        Console.WriteLine("CLIENT : 发送数据 ...");

                        msg.WriteTo(stream);

                        //关闭
                        stream.Close();
                    }
                    client.Close();
                    Console.WriteLine("CLIENT : 关闭 ...");
                }
            }
            catch (Exception error)
            {
                Console.WriteLine("CLIENT ERROR : {0}", error.ToString());
            }

            return(View());
        }
示例#21
0
    /// <summary>
    /// 发送消息
    /// </summary>
    /// <param name="pMsg"></param>
    /// <param name="MsgID"></param>
    public void SendMessage(LuaByteBuffer data, Int32 MsgID)
    {
        if (client != null)
        {
            //清除stream (可见,我们要发送消息,一定要有发送消息发送流)
            send_streams.SetLength(0);
            send_streams.Position = 0;

            //添加到send_streams里面
            send_streams.Write(data.buffer, 0, data.buffer.Length);
            CMsg sendMessage = new CMsg((int)send_streams.Length);    //添加消息头部
            sendMessage.SetProtocalID(MsgID);
            sendMessage.Add(send_streams.ToArray(), 0, (int)send_streams.Length);
            //发送消息的最重要的代码,将网络数据流发送到指定服务器流中
            client.GetStream().Write(sendMessage.GetMsgBuffer(), 0, (int)sendMessage.GetMsgSize());
        }
    }
        public void connect_Req(string serverIP)
        {
            string userName = "******";
            string password = "******";
            short  version  = 1;
            short  version1 = 6;
            int    port     = 15010;

            try
            {
                IPAddress ipAdress = IPAddress.Parse(serverIP);
                client = new Socket(AddressFamily.InterNetwork,
                                    SocketType.Stream,
                                    ProtocolType.Tcp);

                //Console.WriteLine("Establishing Connection to {0}",serverIP);
                IPEndPoint ipReomtePoint = new IPEndPoint(ipAdress, port);

                client.Connect(ipReomtePoint);
                if (client.Connected == true)
                {
                    //Console.WriteLine("Connection established");
                    msgStruct = new CMsg((short)protocol.GW_LOGIN_REQ);
                    msgStruct.WriteData(System.Text.Encoding.Default.GetBytes(userName), userName.Length);
                    msgStruct.WriteData(System.Text.Encoding.Default.GetBytes(password), password.Length);
                    byte[] ret = new byte[] {
                        (byte)version, (byte)(version >> 8)
                    };
                    msgStruct.WriteData(ret, 1);
                    ret = new byte[] {
                        (byte)version1, (byte)(version1 >> 8)
                    };
                    msgStruct.WriteData(ret, 1);
                    msgStruct.writeLength(msgStruct.GetSize());
                    client.Send(msgStruct.GetBuf(), 0, msgStruct.GetSize(), 0);
                    ThreadStart wokerStart = new ThreadStart(ReadThreadFunc);
                    Thread      workThread = new Thread(wokerStart);
                    workThread.Start();
                }
            }
            catch (SocketException ex)
            {
                //Console.WriteLine(ex.Message);
                MessageBox.Show(ex.Message);
            }
        }
示例#23
0
 public void SendMsg(LuaByteBuffer pMsg, Int32 n32MsgID)
 {
     Debug.Log("发送消息:<color=#9400D3>" + n32MsgID + "</color>");
     if (m_Client != null)
     {
         CMsg pcMsg = new CMsg(pMsg.Length);
         pcMsg.SetProtocalID(n32MsgID);
         pcMsg.Add(pMsg.buffer, 0, pMsg.Length);
         try
         {
             m_Client.GetStream().Write(pcMsg.GetMsgBuffer(), 0, (int)pcMsg.GetMsgSize());
         }
         catch (Exception exc)
         {
             Debugger.LogError(exc.ToString());
             Close();
         }
     }
 }
示例#24
0
        // 来了消息以后,通知整个消息链
        public void aProcessMsg(CMsg msg)
        {
            if (!msgDic.ContainsKey(msg.msgId))
            {
                Debug.Log("msg not found:" + msg.msgId);
                return;
            }
            else
            {
                CMsgNode msgNode = msgDic[msg.msgId];

                // 进行广播
                do
                {
                    msgNode.behaviour.ProcessMsg(msg);

                    msgNode = msgNode.next;
                }while (msgNode != null);
            }
        }
示例#25
0
    public static MessageStruct DeserializeData(byte[] data, int datalen)
    {
        if (data == null)
        {
            return(null);
        }

        Stream stream = new MemoryStream(data, 0, datalen);

        CMsg cmsg = ProtoBuf.Serializer.Deserialize <CMsg>(stream);

        //消息号保存进队列
        MessageStruct message = new MessageStruct();

        message.cmd        = cmsg.cmd;
        message.dest       = cmsg.dest;
        message.body       = cmsg.body;
        message.serverTime = cmsg.serverTime;

        return(message);
    }
示例#26
0
    private void sendMsg(CMsg msg)
    {
        CMgrID tmpID = msg.GetMgrID();

        switch (tmpID)
        {
        case CMgrID.UIManagerID:
        {
            UIManager.Instance.SendMessage(msg);
            break;
        }

        case CMgrID.NetManagerID:
        {
            NetManager.Instance.SendMessage(msg);
            break;
        }

        case CMgrID.GameManagerID:
        {
            GameManager.Instance.SendMessage(msg);
            break;
        }

        case CMgrID.SceneManagerID:
        {
            ScenesManager.Instance.SendMessage(msg);
            break;
        }

        case CMgrID.ModelsManagerID:
        {
            ModelsManager.Instance.SendMessage(msg);
            break;
        }

        default:
            break;
        }
    }
示例#27
0
    public object DeserializeData(object source)
    {
        Debug.Log("DeserializeData");

        if (source == null)
        {
            return(null);
        }

        Stream stream = (Stream)source;

        CMsg cmsg       = ProtoBuf.Serializer.Deserialize <CMsg>(stream);
        int  cmd        = cmsg.cmd;
        int  dest       = cmsg.dest;
        long serverTime = cmsg.serverTime;

        byte[] body = cmsg.body;


        //消息号保存进队列
        PBNO _pb = new PBNO();

        _pb.msg = cmsg;

        //分发协议去解析
        PBParseManage.getInstance().ParseData(dest, cmd, body);

        if (NetWorkManage.getInstance().IsOftenData(dest, cmd))
        {
            NetWorkManage.getInstance().PushReceDataScene(_pb);
        }
        else
        {
            NetWorkManage.getInstance().PushReceDataQueue(_pb);
        }

        Debug.Log("收到消息 dest=" + dest + ",cmd=" + cmd);

        return(null);
    }
示例#28
0
    //发送协议数据到服务器
    public static void SendData <T>(int dest, int cmd, T instance) where T : global::ProtoBuf.IExtensible
    {
#if UNITY_EDITOR
        Debug.Log("要发送协议:dest=" + dest + ",cmd=" + cmd);
#endif
        byte[] body = PBParseManage.getSerialize <T>(instance);
        CMsg   _nnn = new CMsg();
        _nnn.dest = dest;
        _nnn.cmd  = cmd;
        if (body != null && body.Length > 0)
        {
            _nnn.body = body;
        }

        //放在消息队列里面发
        SendPBMsg smsg = new SendPBMsg();
        smsg.dest     = dest;
        smsg.cmd      = cmd;
        smsg.sendBody = PBParseManage.getSerialize <CMsg>(_nnn);

        sendMemory.Add(smsg);
    }
示例#29
0
    public void DeserializeData(ReceDataStruct source)
    {
        if (source == null)
        {
            return;
        }

        Stream stream = new MemoryStream(source.data, 0, source.datalen);

        CMsg cmsg       = ProtoBuf.Serializer.Deserialize <CMsg>(stream);
        int  cmd        = cmsg.cmd;
        int  dest       = cmsg.dest;
        long serverTime = cmsg.serverTime;

        byte[] body = cmsg.body;

        //消息号保存进队列
        messageStruct _pb = new messageStruct();

        _pb.cmd        = cmsg.cmd;
        _pb.dest       = cmsg.cmd;
        _pb.body       = cmsg.body;
        _pb.serverTime = cmsg.serverTime;

        //分发协议去解析
        PBParseManage.getInstance().ParseData(dest, cmd, body);

        if (NetWorkManage.getInstance().IsOftenData(dest, cmd))
        {
            NetWorkManage.getInstance().PushReceDataScene(_pb);
        }
        else
        {
            NetWorkManage.getInstance().PushReceDataQueue(_pb);
        }

        Debug.Log("收到消息 dest=" + dest + ",cmd=" + cmd);
    }
示例#30
0
 public void SendToMsg(CMsg tmpMsg)
 {
     sendMsg(tmpMsg);
 }