Example #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PacketClientGCMsgProtobuf"/> class.
        /// </summary>
        /// <param name="eMsg">The network message type for this packet message.</param>
        /// <param name="data">The data.</param>
        public PacketClientGCMsgProtobuf( uint eMsg, byte[] data )
        {
            MsgType = eMsg;
            payload = data;

            MsgGCHdrProtoBuf protobufHeader = new MsgGCHdrProtoBuf();

            // we need to pull out the job ids, so we deserialize the protobuf header
            using ( MemoryStream ms = new MemoryStream( data ) )
            {
                protobufHeader.Deserialize( ms );
            }

            TargetJobID = protobufHeader.Proto.job_id_target;
            SourceJobID = protobufHeader.Proto.job_id_source;
        }
Example #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PacketClientGCMsg"/> class.
        /// </summary>
        /// <param name="eMsg">The network message type for this packet message.</param>
        /// <param name="data">The data.</param>
        public PacketClientGCMsg( uint eMsg, byte[] data )
        {
            MsgType = eMsg;
            payload = data;

            MsgGCHdr gcHdr = new MsgGCHdr();

            // deserialize the gc header to get our hands on the job ids
            using ( MemoryStream ms = new MemoryStream( data ) )
            {
                gcHdr.Deserialize( ms );
            }

            TargetJobID = gcHdr.TargetJobID;
            SourceJobID = gcHdr.SourceJobID;
        }
Example #3
0
            internal PurchaseResponseCallback([NotNull] JobID jobID, [NotNull] CMsgClientPurchaseResponse msg)
            {
                if ((jobID == null) || (msg == null))
                {
                    throw new ArgumentNullException(nameof(jobID) + " || " + nameof(msg));
                }

                JobID = jobID;
                PurchaseResultDetail = (EPurchaseResultDetail)msg.purchase_result_details;
                Result = (EResult)msg.eresult;

                if (msg.purchase_receipt_info == null)
                {
                    ASF.ArchiLogger.LogNullError(nameof(msg.purchase_receipt_info));

                    return;
                }

                KeyValue receiptInfo = new KeyValue();

                using (MemoryStream ms = new MemoryStream(msg.purchase_receipt_info)) {
                    if (!receiptInfo.TryReadAsBinary(ms))
                    {
                        ASF.ArchiLogger.LogNullError(nameof(ms));

                        return;
                    }
                }

                List <KeyValue> lineItems = receiptInfo["lineitems"].Children;

                if (lineItems.Count == 0)
                {
                    return;
                }

                Items = new Dictionary <uint, string>(lineItems.Count);

                foreach (KeyValue lineItem in lineItems)
                {
                    uint packageID = lineItem["PackageID"].AsUnsignedInteger();

                    if (packageID == 0)
                    {
                        // Coupons have PackageID of -1 (don't ask me why)
                        // We'll use ItemAppID in this case
                        packageID = lineItem["ItemAppID"].AsUnsignedInteger();

                        if (packageID == 0)
                        {
                            ASF.ArchiLogger.LogNullError(nameof(packageID));

                            return;
                        }
                    }

                    string gameName = lineItem["ItemDescription"].Value;

                    if (string.IsNullOrEmpty(gameName))
                    {
                        ASF.ArchiLogger.LogNullError(nameof(gameName));

                        return;
                    }

                    // Apparently steam expects client to decode sent HTML
                    gameName         = WebUtility.HtmlDecode(gameName);
                    Items[packageID] = gameName;
                }
            }
Example #4
0
File: Bot.cs Project: xaustinx/Mist
        void OnUpdateMachineAuthCallback(SteamUser.UpdateMachineAuthCallback machineAuth, JobID jobId)
        {
            byte[] hash = SHAHash(machineAuth.Data);

            StringBuilder sb = new StringBuilder();

            for (int count = 0; count < hash.Length; count++)
            {
                sb.Append(hash[count]);
            }

            MachineAuthData = sb.ToString();

            Directory.CreateDirectory(Application.StartupPath + "/sentryfiles/");
            File.WriteAllBytes(String.Format("{0}/sentryfiles/{1}.sentryfile", Application.StartupPath, logOnDetails.Username), machineAuth.Data);

            var authResponse = new SteamUser.MachineAuthDetails
            {
                BytesWritten = machineAuth.BytesToWrite,
                FileName     = machineAuth.FileName,
                FileSize     = machineAuth.BytesToWrite,
                Offset       = machineAuth.Offset,

                SentryFileHash = hash,                         // should be the sha1 hash of the sentry file we just wrote

                OneTimePassword = machineAuth.OneTimePassword, // not sure on this one yet, since we've had no examples of steam using OTPs

                LastError = 0,                                 // result from win32 GetLastError
                Result    = EResult.OK,                        // if everything went okay, otherwise ~who knows~

                JobID = jobId,                                 // so we respond to the correct server job
            };

            // send off our response
            SteamUser.SendMachineAuthResponse(authResponse);
        }
Example #5
0
        private void OnPICSChanges(SteamApps.PICSChangesCallback callback, JobID job)
        {
            if (PreviousChange == callback.CurrentChangeNumber)
            {
                return;
            }

            if (ProcessorPool.IsIdle)
            {
                Log.WriteDebug("Steam", "Cleaning processed apps and subs");

                ProcessedApps.Clear();
                ProcessedSubs.Clear();
            }

            var packageChangesCount = callback.PackageChanges.Count;
            var appChangesCount     = callback.AppChanges.Count;

            Log.WriteInfo("Steam", "Changelist {0} -> {1} ({2} apps, {3} packages)", PreviousChange, callback.CurrentChangeNumber, appChangesCount, packageChangesCount);

            PreviousChange = callback.CurrentChangeNumber;

            DbWorker.ExecuteNonQuery("INSERT INTO `Changelists` (`ChangeID`) VALUES (@ChangeID) ON DUPLICATE KEY UPDATE `Date` = CURRENT_TIMESTAMP()", new MySqlParameter("@ChangeID", callback.CurrentChangeNumber));

            if (appChangesCount == 0 && packageChangesCount == 0)
            {
                IRC.SendAnnounce("{0}ยป{1} Changelist {2}{3}{4} (empty)", Colors.RED, Colors.NORMAL, Colors.OLIVE, PreviousChange, Colors.DARK_GRAY);

                return;
            }

            SecondaryPool.QueueWorkItem(SteamProxy.Instance.OnPICSChanges, callback);

            // Packages have no tokens so we request info for them right away
            if (packageChangesCount > 0)
            {
                Apps.PICSGetProductInfo(Enumerable.Empty <SteamApps.PICSRequest>(), callback.PackageChanges.Keys.Select(package => NewPICSRequest(package)));
            }

            if (appChangesCount > 0)
            {
                // Get all app tokens
                Apps.PICSGetAccessTokens(callback.AppChanges.Keys, Enumerable.Empty <uint>());

                SecondaryPool.QueueWorkItem(delegate
                {
                    string changes = string.Empty;

                    foreach (var app in callback.AppChanges.Values)
                    {
                        if (callback.CurrentChangeNumber != app.ChangeNumber)
                        {
                            DbWorker.ExecuteNonQuery("INSERT INTO `Changelists` (`ChangeID`) VALUES (@ChangeID) ON DUPLICATE KEY UPDATE `Date` = `Date`", new MySqlParameter("@ChangeID", app.ChangeNumber));
                        }

                        DbWorker.ExecuteNonQuery("UPDATE `Apps` SET `LastUpdated` = CURRENT_TIMESTAMP() WHERE `AppID` = @AppID", new MySqlParameter("@AppID", app.ID));

                        changes += string.Format("({0}, {1}),", app.ChangeNumber, app.ID);
                    }

                    if (!changes.Equals(string.Empty))
                    {
                        changes = string.Format("INSERT INTO `ChangelistsApps` (`ChangeID`, `AppID`) VALUES {0} ON DUPLICATE KEY UPDATE `AppID` = `AppID`", changes.Remove(changes.Length - 1));

                        DbWorker.ExecuteNonQuery(changes);
                    }
                });
            }

            if (packageChangesCount > 0)
            {
                SecondaryPool.QueueWorkItem(delegate
                {
                    string changes = string.Empty;

                    foreach (var package in callback.PackageChanges.Values)
                    {
                        if (callback.CurrentChangeNumber != package.ChangeNumber)
                        {
                            DbWorker.ExecuteNonQuery("INSERT INTO `Changelists` (`ChangeID`) VALUES (@ChangeID) ON DUPLICATE KEY UPDATE `Date` = `Date`", new MySqlParameter("@ChangeID", package.ChangeNumber));
                        }

                        DbWorker.ExecuteNonQuery("UPDATE `Subs` SET `LastUpdated` = CURRENT_TIMESTAMP() WHERE `SubID` = @SubID", new MySqlParameter("@SubID", package.ID));

                        changes += string.Format("({0}, {1}),", package.ChangeNumber, package.ID);
                    }

                    if (!changes.Equals(string.Empty))
                    {
                        changes = string.Format("INSERT INTO `ChangelistsSubs` (`ChangeID`, `SubID`) VALUES {0} ON DUPLICATE KEY UPDATE `SubID` = `SubID`", changes.Remove(changes.Length - 1));

                        DbWorker.ExecuteNonQuery(changes);
                    }
                });
            }
        }
Example #6
0
        private void OnPICSProductInfo(SteamApps.PICSProductInfoCallback callback, JobID jobID)
        {
            var request = SteamProxy.Instance.IRCRequests.Find(r => r.JobID == jobID);

            if (request != null)
            {
                SteamProxy.Instance.IRCRequests.Remove(request);

                SecondaryPool.QueueWorkItem(SteamProxy.Instance.OnProductInfo, request, callback);

                return;
            }

            foreach (var app in callback.Apps)
            {
                Log.WriteInfo("Steam", "AppID: {0}", app.Key);

                var workaround = app;

                IWorkItemResult mostRecentItem;
                ProcessedApps.TryGetValue(workaround.Key, out mostRecentItem);

                var workerItem = ProcessorPool.QueueWorkItem(delegate
                {
                    if (mostRecentItem != null && !mostRecentItem.IsCompleted)
                    {
                        Log.WriteDebug("Steam", "Waiting for app {0} to finish processing", workaround.Key);

                        SmartThreadPool.WaitAll(new IWaitableResult[] { mostRecentItem });
                    }

                    new AppProcessor(workaround.Key).Process(workaround.Value);
                });

                ProcessedApps.AddOrUpdate(app.Key, workerItem, (key, oldValue) => workerItem);
            }

            foreach (var package in callback.Packages)
            {
                Log.WriteInfo("Steam", "SubID: {0}", package.Key);

                var workaround = package;

                IWorkItemResult mostRecentItem;
                ProcessedSubs.TryGetValue(workaround.Key, out mostRecentItem);

                var workerItem = ProcessorPool.QueueWorkItem(delegate
                {
                    if (mostRecentItem != null && !mostRecentItem.IsCompleted)
                    {
                        Log.WriteDebug("Steam", "Waiting for package {0} to finish processing", workaround.Key);

                        SmartThreadPool.WaitAll(new IWaitableResult[] { mostRecentItem });
                    }

                    new SubProcessor(workaround.Key).Process(workaround.Value);
                });

                ProcessedSubs.AddOrUpdate(package.Key, workerItem, (key, oldValue) => workerItem);
            }

            foreach (uint app in callback.UnknownApps)
            {
                Log.WriteInfo("Steam", "Unknown AppID: {0}", app);

                uint workaround = app;

                IWorkItemResult mostRecentItem;
                ProcessedApps.TryGetValue(workaround, out mostRecentItem);

                var workerItem = ProcessorPool.QueueWorkItem(delegate
                {
                    if (mostRecentItem != null && !mostRecentItem.IsCompleted)
                    {
                        Log.WriteDebug("Steam", "Waiting for app {0} to finish processing (unknown)", workaround);

                        SmartThreadPool.WaitAll(new IWaitableResult[] { mostRecentItem });
                    }

                    new AppProcessor(workaround).ProcessUnknown();
                });

                ProcessedApps.AddOrUpdate(app, workerItem, (key, oldValue) => workerItem);
            }

            foreach (uint package in callback.UnknownPackages)
            {
                Log.WriteInfo("Steam", "Unknown SubID: {0}", package);

                uint workaround = package;

                IWorkItemResult mostRecentItem;
                ProcessedSubs.TryGetValue(workaround, out mostRecentItem);

                var workerItem = ProcessorPool.QueueWorkItem(delegate
                {
                    if (mostRecentItem != null && !mostRecentItem.IsCompleted)
                    {
                        Log.WriteDebug("Steam", "Waiting for package {0} to finish processing (unknown)", workaround);

                        SmartThreadPool.WaitAll(new IWaitableResult[] { mostRecentItem });
                    }

                    new SubProcessor(workaround).ProcessUnknown();
                });

                ProcessedSubs.AddOrUpdate(package, workerItem, (key, oldValue) => workerItem);
            }
        }
Example #7
0
 public UGCJobResult(JobID id)
     : this()
 {
     this.ID = id;
 }
Example #8
0
 public UGCJobResult(JobID id, EResult result)
 {
     this.ID     = id;
     this.Result = result;
 }
Example #9
0
 public static bool TryRemoveJob(JobID jobID)
 {
     return(TryRemoveJob(jobID, out _));
 }
Example #10
0
        void OnUpdateMachineAuthCallback(SteamUser.UpdateMachineAuthCallback machineAuth, JobID jobId)
        {
            byte[] hash = SHAHash(machineAuth.Data);

            File.WriteAllBytes(String.Format("{0}.sentryfile", logOnDetails.Username), machineAuth.Data);

            var authResponse = new SteamUser.MachineAuthDetails
            {
                BytesWritten = machineAuth.BytesToWrite,
                FileName     = machineAuth.FileName,
                FileSize     = machineAuth.BytesToWrite,
                Offset       = machineAuth.Offset,

                SentryFileHash = hash,                         // should be the sha1 hash of the sentry file we just wrote

                OneTimePassword = machineAuth.OneTimePassword, // not sure on this one yet, since we've had no examples of steam using OTPs

                LastError = 0,                                 // result from win32 GetLastError
                Result    = EResult.OK,                        // if everything went okay, otherwise ~who knows~

                JobID = jobId,                                 // so we respond to the correct server job
            };

            // send off our response
            SteamUser.SendMachineAuthResponse(authResponse);
        }
Example #11
0
 public static JobId ToJobID(string jid)
 {
     return(TypeConverter.ToYarn(JobID.ForName(jid)));
 }
Example #12
0
 public BuildJob(JobID id)
 {
     ID = id;
 }
            internal WorkshopInfoCallback(JobID job, EResult result, IEnumerable <WorkshopItem> items)
            {
                JobID = job;

                Items.AddRange(items);
            }