Exemplo 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));
        }
Exemplo n.º 2
0
        public byte[] SendMessage(ActorContext context, string msg)
        {
            var headers = new NameValueCollection
            {
                { "c", context.Request.C },
                { "i", MessageType.Rep },
                { "o", Convert.ToString(context.Request.O) },
                { "code", Convert.ToString((int)StatusCode.Ok) },
                { "format", "json" }
            };

            //通知类型

            return(ActorNetService.SendMessage(context, headers, Encoding.UTF8.GetBytes(msg)));
        }
Exemplo n.º 3
0
        private byte[] SendMessage <T>(ActorContext context, NameValueCollection header, T rep)
        {
            header["format"] = context.ResponseCovnert;

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


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

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

            return(ActorNetService.SendMessage(context, header, body));
        }
Exemplo n.º 4
0
        public void PushMessage <T>(PirateSession session, T t)
        {
            var headers = new NameValueCollection
            {
                { "c", typeof(T).Name },
                { "i", MessageType.Boradcast },
                { "format", DefaultResponseCovnert } // TODO 默认解析器
            };

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


            if (Logger.IsDebugEnabled && t != null)
            {
                Logger.Debug($"S2C PUSH #{session.Id}# {string.Join("&", headers.AllKeys.Select(a => a + "=" + headers[a]))} {JsonConvert.SerializeObject(t)}");
            }

            ActorNetService.PushMessage(session.FrontendID, headers, DistrictContainer.ServerIoc.ResolveKeyed <IResponseConvert>(DefaultResponseCovnert).SerializeObject(t));
        }