Пример #1
0
        public static void InitServer()
        {
            m_dataDic = new Dictionary <string, string>();
            Binary binary = HttpGetService.GetAsBinary(DataCenter.ServerAddr + "giraservice?func=getall");

            if (binary != null)
            {
                int dataLength = binary.ReadInt();
                for (int i = 0; i < dataLength; i++)
                {
                    String xmlName    = binary.ReadString();
                    int    nextBisLen = binary.ReadInt();
                    byte[] byts       = new byte[nextBisLen];
                    binary.ReadBytes(byts);
                    String xmlStr = System.Text.Encoding.Default.GetString(byts);
                    m_dataDic[xmlName] = xmlStr;
                }
            }
        }
Пример #2
0
        /// <summary>
        /// 获取弹幕信息
        /// </summary>
        /// <param name="chatData">聊天信息</param>
        /// <param name="body">包体</param>
        /// <param name="bodyLength">包体长度</param>
        /// <returns></returns>
        public static int GetChatData(ChatData chatData, byte[] body, int bodyLength)
        {
            Binary br = new Binary();

            br.Write(body, bodyLength);
            chatData.m_aes        = br.ReadString();
            chatData.m_tokens     = br.ReadString();
            chatData.m_from       = br.ReadString();
            chatData.m_to         = br.ReadString();
            chatData.m_content    = br.ReadString();
            chatData.m_bodyLength = br.ReadInt();
            if (chatData.m_bodyLength > 0)
            {
                chatData.m_body = new byte[chatData.m_bodyLength];
                br.ReadBytes(chatData.m_body);
            }
            br.Close();
            return(1);
        }
Пример #3
0
        /// <summary>
        /// 收到消息
        /// </summary>
        /// <param name="br">流</param>
        /// <param name="socketID">套接字ID</param>
        /// <param name="localSID">本地套接字ID</param>
        /// <param name="len">长度</param>
        public virtual void OnCallBack(Binary br, int socketID, int localSID, int len)
        {
            int headSize     = sizeof(int) * 4 + sizeof(short) * 3 + sizeof(byte) * 2;
            int functionID   = br.ReadShort();
            int sessionID    = br.ReadInt();
            int requestID    = br.ReadInt();
            int state        = br.ReadByte();
            int compressType = br.ReadByte();
            int bodyLength   = br.ReadInt();

            byte[] body = new byte[len - headSize];
            br.ReadBytes(body);
            if (compressType == COMPRESSTYPE_GZIP)
            {
                using (MemoryStream dms = new MemoryStream())
                {
                    using (MemoryStream cms = new MemoryStream(body))
                    {
                        using (GZipStream gzip = new GZipStream(cms, CompressionMode.Decompress))
                        {
                            byte[] buffer = new byte[1024];
                            int    size   = 0;
                            while ((size = gzip.Read(buffer, 0, buffer.Length)) > 0)
                            {
                                dms.Write(buffer, 0, size);
                            }
                            body = dms.ToArray();
                        }
                    }
                }
            }
            CMessage message = new CMessage(GroupID, ServiceID, functionID, sessionID, requestID, socketID, state, compressType, bodyLength, body);

            OnReceive(message);
            OnWaitMessageHandle(message);
            body = null;
        }