示例#1
0
        private uint Serialize(NpCloudRequestParameter data, uint uid, MemoryStream stream)
        {
            NpMessagePack.Pack <object>(data.content, stream);
            uint uid2 = this.GetUId(uid);

            byte[] bytes = BitConverter.GetBytes(uid2);
            if (BitConverter.IsLittleEndian)
            {
                Array.Reverse(bytes);
            }
            stream.Write(bytes, 0, bytes.Length);
            HMACSHA512 hmacsha = new HMACSHA512(Encoding.ASCII.GetBytes(this.HASH_KEY));

            byte[] array = hmacsha.ComputeHash(stream.ToArray());
            stream.SetLength(stream.Length - 4L);
            stream.Write(array, 0, array.Length);
            stream.Write(bytes, 0, bytes.Length);
            Dictionary <string, string> dictionary = new Dictionary <string, string>();

            dictionary["data"] = Convert.ToBase64String(stream.ToArray());
            data.content       = new Dictionary <string, object>
            {
                {
                    "param",
                    dictionary
                }
            };
            stream.Seek(0L, SeekOrigin.Begin);
            stream.SetLength(0L);
            NpMessagePack.Pack <object>(data, stream);
            return(uid2);
        }
示例#2
0
        private byte[] CreateSystemBuffer(NpCloudRequestParameter parameter, NpCloudHeaderType type)
        {
            MemoryStream memoryStream = new MemoryStream();

            NpMessagePack.Pack <object>(parameter, memoryStream);
            return(this.AddHeaderBuffer(memoryStream.GetBuffer(), type));
        }
示例#3
0
        private byte[] CreateSystemBuffer(uint uid, NpCloudRequestParameter parameter, NpCloudHeaderType type)
        {
            MemoryStream memoryStream = new MemoryStream();

            this.Serialize(parameter, uid, memoryStream);
            return(this.AddHeaderBuffer(memoryStream.GetBuffer(), type));
        }
示例#4
0
        protected byte[] CreateLoginParameter(NpCloudSetting setting, object option)
        {
            string[] array = setting.ProjectId.Split(new char[]
            {
                '.'
            });
            string str = setting.ProjectId;

            if (array.Length > 1)
            {
                str = array[1];
            }
            NpCloudRequestParameter npCloudRequestParameter = new NpCloudRequestParameter();

            npCloudRequestParameter.content = new Dictionary <string, object>
            {
                {
                    "projectId",
                    setting.ProjectId
                },
                {
                    "projectPass",
                    str + "pass"
                },
                {
                    "userId",
                    setting.UserId
                }
            };
            Dictionary <string, object> dictionary = new Dictionary <string, object>();

            dictionary.Add("value", NpCloudCommandType.login.ToString());
            if (option != null)
            {
                dictionary.Add("option", option);
            }
            npCloudRequestParameter.command = dictionary;
            npCloudRequestParameter.type    = "direct";
            MemoryStream memoryStream = new MemoryStream();

            NpMessagePack.Pack <object>(npCloudRequestParameter, memoryStream);
            return(this.AddHeaderBuffer(memoryStream.GetBuffer(), NpCloudHeaderType.CommonMsg));
        }