Exemplo n.º 1
0
 public JsonLinePacketServer(IJsonSerializationServerAdapter SerializationServerAdapter, CheckCommandAllowedDelegate CheckCommandAllowed, IBinaryTransformer Transformer = null, int ReadBufferSize = 8 * 1024)
 {
     this.ss = SerializationServerAdapter;
     this.c  = new Context(ReadBufferSize);
     this.CheckCommandAllowed = CheckCommandAllowed;
     this.Transformer         = Transformer;
     this.ss.ServerEvent     += (CommandName, CommandHash, Parameters) =>
     {
         var Bytes = TextEncoding.UTF8.GetBytes(String.Format(@"/svr {0} {1}" + "\r\n", CommandName + "@" + CommandHash.ToString("X8", System.Globalization.CultureInfo.InvariantCulture), Parameters));
         lock (c.WriteBufferLockee)
         {
             if (Transformer != null)
             {
                 Transformer.Transform(Bytes, 0, Bytes.Length);
             }
             c.WriteBuffer.Add(Bytes);
         }
         if (OutputByteLengthReport != null)
         {
             OutputByteLengthReport(CommandName, Bytes.Length);
         }
         if (this.ServerEvent != null)
         {
             this.ServerEvent();
         }
     };
 }
Exemplo n.º 2
0
 public JsonHttpPacketServer(IJsonSerializationServerAdapter SerializationServerAdapter, CheckCommandAllowedDelegate CheckCommandAllowed)
 {
     this.ss = SerializationServerAdapter;
     this.c  = new Context();
     this.CheckCommandAllowed = CheckCommandAllowed;
     this.ss.ServerEvent     += (CommandName, CommandHash, Parameters) =>
     {
         var rjo = new JObject();
         rjo["commandName"] = new JValue(CommandName);
         rjo["commandHash"] = new JValue(CommandHash.ToString("X8", System.Globalization.CultureInfo.InvariantCulture));
         rjo["parameters"]  = new JValue(Parameters);
         lock (c.WriteBufferLockee)
         {
             c.WriteBuffer.Add(rjo);
         }
         if (this.ServerEvent != null)
         {
             this.ServerEvent();
         }
     };
 }
Exemplo n.º 3
0
 public BinaryCountPacketServer(IBinarySerializationServerAdapter SerializationServerAdapter, CheckCommandAllowedDelegate CheckCommandAllowed, IBinaryTransformer Transformer = null, int ReadBufferSize = 8 * 1024)
 {
     this.ss = SerializationServerAdapter;
     this.c  = new Context(ReadBufferSize);
     this.CheckCommandAllowed = CheckCommandAllowed;
     this.Transformer         = Transformer;
     this.ss.ServerEvent     += (CommandName, CommandHash, Parameters) =>
     {
         var    CommandNameBytes = TextEncoding.UTF16.GetBytes(CommandName);
         Byte[] Bytes;
         using (var ms = Streams.CreateMemoryStream())
         {
             ms.WriteInt32(CommandNameBytes.Length);
             ms.Write(CommandNameBytes);
             ms.WriteUInt32(CommandHash);
             ms.WriteInt32(Parameters.Length);
             ms.Write(Parameters);
             ms.Position = 0;
             Bytes       = ms.Read((int)(ms.Length));
         }
         var BytesLength = Bytes.Length;
         lock (c.WriteBufferLockee)
         {
             if (Transformer != null)
             {
                 Transformer.Transform(Bytes, 0, BytesLength);
             }
             c.WriteBuffer.Add(Bytes);
         }
         if (OutputByteLengthReport != null)
         {
             OutputByteLengthReport(CommandName, BytesLength);
         }
         if (this.ServerEvent != null)
         {
             this.ServerEvent();
         }
     };
 }