Esempio n. 1
0
        /// <summary>
        /// 种子交换
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="context"></param>
        /// <param name="t"></param>
        public byte[] SendSeed <T>(ActorContext context, byte cryptobyte, byte[] clientkeys, byte[] serverkeys, T t)
        {
            var headers = new NameValueCollection
            {
                { "c", context.Request.C },
                { "i", MessageType.Rep },
                { "o", Convert.ToString(context.Request.O) },
                { "code", Convert.ToString((int)StatusCode.Ok) }
            };

            //通知类型


            headers["format"] = context.ResponseCovnert;

            if (Equals(context.ResponseCovnert, "protobuf"))
            {
                headers["responsetype"] = typeof(T).Name;
            }

            var body = DistrictContainer.ServerIoc.ResolveKeyed <IResponseConvert>(context.ResponseCovnert)
                       .SerializeObject(t);

            if (Logger.IsDebugEnabled && body != null)
            {
                Logger.Debug($"S2C #{context.Token.Rid}# #{context.RemoteIp}# {string.Join("&", headers.AllKeys.Select(a => a + "=" + headers[a]))} {Encoding.UTF8.GetString(body)}");
            }

            return(ActorNetService.Seed(context, headers, cryptobyte, clientkeys, serverkeys, body));
        }