Пример #1
0
        private bnet.protocol.storage.ExecuteResponse GetHeroDigest(MooNetClient client, bnet.protocol.storage.ExecuteRequest request)
        {
            var results = new List <bnet.protocol.storage.OperationResult>();

            foreach (var operation in request.OperationsList)
            {
                Google.ProtocolBuffers.ByteString data = null;

                // find the requested toons entity-id.
                var stream = new MemoryStream(operation.RowId.Hash.ToByteArray());

                // contains ToonHandle in field form with one unknown field (which is not in message definition):
                // int16 unknown; uint8 realm; uint8 region; uint32 program; uint64 id;
                stream.ReadValueU16();      // unknown
                stream.ReadValueU8();       // realm
                stream.ReadValueU8();       // region
                stream.ReadValueU32(false); // program

                var toonId = stream.ReadValueU64(false);

                if (!client.Account.Toons.ContainsKey(toonId))
                {
                    Logger.Error("Can't find the requested toon: {0}", toonId);
                    continue;
                }

                var toon = client.Account.Toons[toonId];

                if (operation.ColumnId.Hash.Equals(HeroDigestColumn))
                {
                    data = toon.Digest.ToByteString();
                }
                else if (operation.ColumnId.Hash.Equals(HeroNameColumn))
                {
                    data = toon.NameText.ToByteString();
                }

                var operationResult = bnet.protocol.storage.OperationResult.CreateBuilder().SetTableId(operation.TableId);
                operationResult.AddData(
                    bnet.protocol.storage.Cell.CreateBuilder()
                    .SetColumnId(request.OperationsList[0].ColumnId)
                    .SetRowId(request.OperationsList[0].RowId)
                    .SetVersion(1)
                    .SetData(data)
                    .Build()
                    );
                results.Add(operationResult.Build());
            }

            var builder = bnet.protocol.storage.ExecuteResponse.CreateBuilder();

            foreach (var result in results)
            {
                builder.AddResults(result);
            }
            return(builder.Build());
        }
Пример #2
0
 private UntypedReceive Receiving(IHandleEventListener el)
 {
     return(message =>
     {
         if (message is Tcp.Received)
         {
             var received = message as Tcp.Received;
             el.Notify(new InboundPayload(ByteString.CopyFrom(received.Data.ToArray())));
         }
         if (message is ByteString)
         {
             var bs = message as ByteString;
             _connection.Tell(Tcp.Write.Create(IO.ByteString.Create(bs.ToByteArray())));
         }
         else
         {
             Unhandled(message);
         }
     });
 }
Пример #3
0
 private UntypedReceive WaitingForBody(IHandleEventListener el, IO.ByteString buffer, int length)
 {
     if (buffer.Count >= length)
     {
         var parts = buffer.SplitAt(length);
         el.Notify(new InboundPayload(ByteString.CopyFrom(parts.Item1.ToArray())));
         return(WaitingForPrefix(el, parts.Item2));
     }
     return(message =>
     {
         if (message is Tcp.Received)
         {
             var received = message as Tcp.Received;
             Become(WaitingForBody(el, buffer.Concat(received.Data), length));
         }
         else
         {
             HandleWrite(message);
         }
     });
 }
Пример #4
0
 public override bool Write(ByteString payload)
 {
     _connection.Tell(payload);
     return(true);
 }
Пример #5
0
 public override bool Write(ByteString payload)
 {
     _connection.Tell(payload);
     return true;
 }
Пример #6
0
 public static Google.ProtocolBuffers.ByteString StringToByteString(string str, Encoding encode)
 {
     Google.ProtocolBuffers.ByteString byte_string = Google.ProtocolBuffers.ByteString.CopyFrom(encode.GetBytes(str.ToCharArray()));
     return(byte_string);
 }
Пример #7
0
 public static string ByteStringToString(Google.ProtocolBuffers.ByteString byte_string, Encoding encode)
 {
     return(encode.GetString(ByteStringToBytes(byte_string), 0, byte_string.Length));
 }
Пример #8
0
 public static byte[] ByteStringToBytes(Google.ProtocolBuffers.ByteString byte_string)
 {
     byte[] bytes = new byte[byte_string.Length];
     byte_string.CopyTo(bytes, 0);
     return(bytes);
 }