Ejemplo n.º 1
0
    private void GetContentHandleCallback(RPCContext context)
    {
        ResourcesAPIPendingState state = null;

        if (!this.m_pendingLookups.TryGetValue(context.Header.Token, out state))
        {
            base.ApiLog.LogWarning("Received unmatched lookup response");
        }
        else
        {
            this.m_pendingLookups.Remove(context.Header.Token);
            bnet.protocol.ContentHandle contentHandle = bnet.protocol.ContentHandle.ParseFrom(context.Payload);
            if ((contentHandle == null) || !contentHandle.IsInitialized)
            {
                base.ApiLog.LogWarning("Received invalid response");
                state.Callback(null, state.UserContext);
            }
            else
            {
                BattleNetErrors status = (BattleNetErrors)context.Header.Status;
                if (status != BattleNetErrors.ERROR_OK)
                {
                    object[] args = new object[] { status };
                    base.ApiLog.LogWarning("Battle.net Resources API C#: Failed lookup. Error={0}", args);
                    state.Callback(null, state.UserContext);
                }
                else
                {
                    ContentHandle handle2 = ContentHandle.FromProtocol(contentHandle);
                    state.Callback(handle2, state.UserContext);
                }
            }
        }
    }
 public bool GetFile(ContentHandle ch, DownloadCompletedCallback cb)
 {
     try
     {
         LocalStorageFileState state = new LocalStorageFileState(m_downloadId)
         {
             CH       = ch,
             Callback = cb
         };
         object[] args = new object[] { state };
         s_log.LogDebug("Starting GetFile State={0}", args);
         if (!this.LoadStateFromDrive(state))
         {
             object[] objArray2 = new object[] { state };
             s_log.LogDebug("Unable to load file from disk, starting a download. State={0}", objArray2);
             this.DownloadFromDepot(state);
         }
     }
     catch (Exception exception)
     {
         object[] objArray3 = new object[] { exception.Message };
         s_log.LogWarning("EXCEPTION (GetFile): {0}", objArray3);
         return(false);
     }
     return(true);
 }
Ejemplo n.º 3
0
 public void SetConnectionMeteringContentHandles(ConnectionMeteringContentHandles handles, LocalStorageAPI localStorage)
 {
     if (((handles == null) || !handles.IsInitialized) || (handles.ContentHandleCount == 0))
     {
         this.m_cmLogSource.LogWarning("Invalid connection metering content handle received.");
     }
     else
     {
         if (handles.ContentHandleCount != 1)
         {
             this.m_cmLogSource.LogWarning("More than 1 connection metering content handle specified!");
         }
         bnet.protocol.ContentHandle contentHandle = handles.ContentHandle[0];
         if ((contentHandle == null) || !contentHandle.IsInitialized)
         {
             this.m_cmLogSource.LogWarning("The content handle received is not valid!");
         }
         else
         {
             this.m_cmLogSource.LogDebug("Received request to enable connection metering.");
             ContentHandle ch   = ContentHandle.FromProtocol(contentHandle);
             object[]      args = new object[] { ch };
             this.m_cmLogSource.LogDebug("Requesting file from local storage. ContentHandle={0}", args);
             localStorage.GetFile(ch, new LocalStorageAPI.DownloadCompletedCallback(this.DownloadCompletedCallback));
         }
     }
 }
Ejemplo n.º 4
0
 public static MemModuleLoadRequest Deserialize(Stream stream, MemModuleLoadRequest instance, long limit)
 {
     while (limit < 0L || stream.get_Position() < limit)
     {
         int num = stream.ReadByte();
         if (num == -1)
         {
             if (limit >= 0L)
             {
                 throw new EndOfStreamException();
             }
             return(instance);
         }
         else
         {
             int num2 = num;
             if (num2 != 10)
             {
                 if (num2 != 18)
                 {
                     if (num2 != 26)
                     {
                         Key  key   = ProtocolParser.ReadKey((byte)num, stream);
                         uint field = key.Field;
                         if (field == 0u)
                         {
                             throw new ProtocolBufferException("Invalid field id: 0, something went wrong in the stream");
                         }
                         ProtocolParser.SkipKey(stream, key);
                     }
                     else
                     {
                         instance.Input = ProtocolParser.ReadBytes(stream);
                     }
                 }
                 else
                 {
                     instance.Key = ProtocolParser.ReadBytes(stream);
                 }
             }
             else if (instance.Handle == null)
             {
                 instance.Handle = ContentHandle.DeserializeLengthDelimited(stream);
             }
             else
             {
                 ContentHandle.DeserializeLengthDelimited(stream, instance.Handle);
             }
         }
     }
     if (stream.get_Position() == limit)
     {
         return(instance);
     }
     throw new ProtocolBufferException("Read past max limit");
 }
Ejemplo n.º 5
0
 public static MemModuleLoadRequest Deserialize(Stream stream, MemModuleLoadRequest instance, long limit)
 {
     while (true)
     {
         if (limit < (long)0 || stream.Position < limit)
         {
             int num = stream.ReadByte();
             if (num == -1)
             {
                 if (limit >= (long)0)
                 {
                     throw new EndOfStreamException();
                 }
                 break;
             }
             else if (num == 10)
             {
                 if (instance.Handle != null)
                 {
                     ContentHandle.DeserializeLengthDelimited(stream, instance.Handle);
                 }
                 else
                 {
                     instance.Handle = ContentHandle.DeserializeLengthDelimited(stream);
                 }
             }
             else if (num == 18)
             {
                 instance.Key = ProtocolParser.ReadBytes(stream);
             }
             else if (num == 26)
             {
                 instance.Input = ProtocolParser.ReadBytes(stream);
             }
             else
             {
                 Key key = ProtocolParser.ReadKey((byte)num, stream);
                 if (key.Field == 0)
                 {
                     throw new ProtocolBufferException("Invalid field id: 0, something went wrong in the stream");
                 }
                 ProtocolParser.SkipKey(stream, key);
             }
         }
         else
         {
             if (stream.Position != limit)
             {
                 throw new ProtocolBufferException("Read past max limit");
             }
             break;
         }
     }
     return(instance);
 }
Ejemplo n.º 6
0
 private void ResouceLookupTestCallback(ContentHandle contentHandle, object userContext)
 {
     if (contentHandle == null)
     {
         base.ApiLog.LogWarning("Lookup failed");
     }
     else
     {
         int      num  = (int)userContext;
         object[] args = new object[] { num, contentHandle.Region, contentHandle.Usage, contentHandle.Sha256Digest };
         base.ApiLog.LogDebug("Lookup done i={0} Region={1} Usage={2} SHA256={3}", args);
     }
 }
 private void ResouceLookupCallback(ContentHandle contentHandle, object userContext)
 {
     if (contentHandle == null)
     {
         base.ApiLog.LogWarning("BN resource look up failed unable to proceed");
     }
     else
     {
         object[] args = new object[] { contentHandle.Region, contentHandle.Usage, contentHandle.Sha256Digest };
         base.ApiLog.LogDebug("Lookup done Region={0} Usage={1} SHA256={2}", args);
         base.m_battleNet.LocalStorage.GetFile(contentHandle, new LocalStorageAPI.DownloadCompletedCallback(this.DownloadCompletedCallback));
     }
 }
Ejemplo n.º 8
0
        public override int GetHashCode()
        {
            int num = base.GetType().GetHashCode();

            using (List <ContentHandle> .Enumerator enumerator = this.ContentHandle.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    ContentHandle current = enumerator.get_Current();
                    num ^= current.GetHashCode();
                }
            }
            return(num);
        }
 public static void Serialize(Stream stream, ModuleLoadRequest instance)
 {
     if (instance.ModuleHandle == null)
     {
         throw new ArgumentNullException("ModuleHandle", "Required by proto specification.");
     }
     stream.WriteByte(10);
     ProtocolParser.WriteUInt32(stream, instance.ModuleHandle.GetSerializedSize());
     ContentHandle.Serialize(stream, instance.ModuleHandle);
     if (instance.HasMessage)
     {
         stream.WriteByte(18);
         ProtocolParser.WriteBytes(stream, instance.Message);
     }
 }
Ejemplo n.º 10
0
 public static void Serialize(Stream stream, ConnectionMeteringContentHandles instance)
 {
     if (instance.ContentHandle.get_Count() > 0)
     {
         using (List <ContentHandle> .Enumerator enumerator = instance.ContentHandle.GetEnumerator())
         {
             while (enumerator.MoveNext())
             {
                 ContentHandle current = enumerator.get_Current();
                 stream.WriteByte(10);
                 ProtocolParser.WriteUInt32(stream, current.GetSerializedSize());
                 bnet.protocol.ContentHandle.Serialize(stream, current);
             }
         }
     }
 }
Ejemplo n.º 11
0
        public uint GetSerializedSize()
        {
            uint num = 0u;

            if (this.ContentHandle.get_Count() > 0)
            {
                using (List <ContentHandle> .Enumerator enumerator = this.ContentHandle.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        ContentHandle current = enumerator.get_Current();
                        num += 1u;
                        uint serializedSize = current.GetSerializedSize();
                        num += serializedSize + ProtocolParser.SizeOfUInt32(serializedSize);
                    }
                }
            }
            return(num);
        }
Ejemplo n.º 12
0
        public static void OnConnectRequest(Client pClient, Header pHeader, MemoryStream pData)
        {
            ConnectRequest connectRequest = new ConnectRequest();

            if (!connectRequest.Read(pData))
            {
                return;
            }

            ConnectResponse connectResponse = new ConnectResponse();

            connectResponse.ServerId.Label = 0;
            connectResponse.ServerId.Epoch = DateTime.Now.ToUnixTime();
            connectResponse.HasClientId    = true;
            connectResponse.ClientId.Label = 1;
            connectResponse.ClientId.Epoch = connectResponse.ServerId.Epoch;
            if (connectRequest.HasClientId)
            {
                connectResponse.ClientId.Label = connectResponse.ClientId.Label;
            }
            ContentHandle contentHandle = new ContentHandle();

            byte[] region = Encoding.ASCII.GetBytes("US");
            contentHandle.Region = (uint)(region[0] << 8) | region[1];
            byte[] usage = Encoding.ASCII.GetBytes("mtrz");
            contentHandle.Usage = (uint)(usage[0] << 24) | (uint)(usage[1] << 16) | (uint)(usage[2] << 8) | usage[3];
            contentHandle.Hash  = new byte[] { 0x18, 0xe9, 0x8c, 0xde, 0x12, 0x83, 0x71, 0x49, 0x62, 0x19, 0x88, 0xce, 0xee, 0x55, 0x12, 0x3b,
                                               0xf2, 0xbe, 0x83, 0x9a, 0x6d, 0xc1, 0xd6, 0xbb, 0x00, 0xa3, 0x99, 0x52, 0x06, 0x56, 0xb2, 0xa6 };
            connectResponse.HasConnectionMeteringContentHandles = true;
            connectResponse.ConnectionMeteringContentHandles.ContentHandles.Add(contentHandle);

            pClient.PermittedServices.Add(ClientImportedServiceIds.AuthenticationServer);
            //pClient.PermittedServices.Add(ClientServiceIds.ChallengeService);
            //pClient.PermittedServices.Add(ClientServiceIds.ChannelService);
            //pClient.PermittedServices.Add(ClientServiceIds.AchievementsService);
            //pClient.PermittedServices.Add(ClientServiceIds.ReportService);

            MemoryStream response = new MemoryStream(128);

            connectResponse.Write(response);
            pClient.SendResponse(pHeader.Token, 0, 0, null, response);
        }
Ejemplo n.º 13
0
        public override void Logon(IRpcController controller, LogonRequest request, Action <LogonResponse> done)
        {
            srp = new SRP(request.Email, "123");

            var message = srp.LogonChallenge;

            var moduleLoadRequest = ModuleLoadRequest.CreateBuilder()
                                    .SetModuleHandle(ContentHandle.CreateBuilder()
                                                     .SetRegion(Region)
                                                     .SetUsage(Usage)
                                                     .SetHash(ByteString.CopyFrom(ModuleHash)))
                                    .SetMessage(ByteString.CopyFrom(message))
                                    .Build();

            client.ListenerId = request.ListenerId;

            AuthenticationClient.CreateStub(client).ModuleLoad(controller, moduleLoadRequest, ClientServiceCallback);

            new Thread(() =>
            {
                wait.WaitOne();
                if (client.ErrorCode == AuthError.None)
                {
                    done(new LogonResponse.Builder
                    {
                        Account = new EntityId.Builder {
                            High = HighId.Account, Low = 0
                        }.Build(),
                        GameAccount = new EntityId.Builder {
                            High = HighId.GameAccount, Low = 0
                        }.Build(),
                    }.Build());
                }
                else
                {
                    done(new LogonResponse());
                }
            }).Start();
        }
Ejemplo n.º 14
0
 public void SetHandle(ContentHandle val)
 {
     this.Handle = val;
 }
Ejemplo n.º 15
0
 public void AddContentHandle(ContentHandle val)
 {
     this._ContentHandle.Add(val);
 }
 public void SetModuleHandle(ContentHandle val)
 {
     this.ModuleHandle = val;
 }
Ejemplo n.º 17
0
 public ContentRefAndHandle(ContentReference _reference, ContentHandle _handle = null)
 {
     reference = _reference;
     handle    = _handle;
 }