private static void OnNumberOfPlayers(SteamUserStats.NumberOfPlayersCallback callback) { JobAction job; if (!JobManager.TryRemoveJob(callback.JobID, out job) || !job.IsCommand) { return; } var request = job.CommandRequest; if (callback.Result != EResult.OK) { CommandHandler.ReplyToCommand(request.Command, "Unable to request player count: {0}{1}", Colors.RED, callback.Result); } else if (request.Target == 0) { CommandHandler.ReplyToCommand( request.Command, "{0}{1:N0}{2} people praising lord Gaben right now, influence:{3} {4}", Colors.OLIVE, callback.NumPlayers, Colors.NORMAL, Colors.DARKBLUE, SteamDB.GetAppURL(753, "graphs") ); } else { CommandHandler.ReplyToCommand( request.Command, "People playing {0}{1}{2} right now: {3}{4:N0}{5} -{6} {7}", Colors.BLUE, Steam.GetAppName(request.Target), Colors.NORMAL, Colors.OLIVE, callback.NumPlayers, Colors.NORMAL, Colors.DARKBLUE, SteamDB.GetAppURL(request.Target, "graphs") ); } }
public void Init() { ProcessorPool = new SmartThreadPool(new STPStartInfo { WorkItemPriority = WorkItemPriority.Highest, MaxWorkerThreads = 50 }); SecondaryPool = new SmartThreadPool(); ProcessorPool.Name = "Processor Pool"; SecondaryPool.Name = "Secondary Pool"; ProcessedApps = new ConcurrentDictionary<uint, IWorkItemResult>(); ProcessedSubs = new ConcurrentDictionary<uint, IWorkItemResult>(); Timer = new System.Timers.Timer(); Timer.Elapsed += OnTimer; Timer.Interval = TimeSpan.FromSeconds(1).TotalMilliseconds; Client = new SteamClient(); User = Client.GetHandler<SteamUser>(); Apps = Client.GetHandler<SteamApps>(); Friends = Client.GetHandler<SteamFriends>(); UserStats = Client.GetHandler<SteamUserStats>(); Unified = Client.GetHandler<SteamUnifiedMessages>(); CallbackManager = new CallbackManager(Client); CallbackManager.Register(new Callback<SteamClient.ConnectedCallback>(OnConnected)); CallbackManager.Register(new Callback<SteamClient.DisconnectedCallback>(OnDisconnected)); CallbackManager.Register(new Callback<SteamUser.AccountInfoCallback>(OnAccountInfo)); CallbackManager.Register(new Callback<SteamUser.LoggedOnCallback>(OnLoggedOn)); CallbackManager.Register(new Callback<SteamUser.LoggedOffCallback>(OnLoggedOff)); CallbackManager.Register(new Callback<SteamApps.LicenseListCallback>(OnLicenseListCallback)); CallbackManager.Register(new JobCallback<SteamUser.UpdateMachineAuthCallback>(OnMachineAuth)); CallbackManager.Register(new JobCallback<SteamApps.PICSProductInfoCallback>(OnPICSProductInfo)); CallbackManager.Register(new JobCallback<SteamApps.PICSTokensCallback>(OnPICSTokens)); // irc specific if (Settings.Current.FullRun == 0) { CallbackManager.Register(new JobCallback<SteamApps.PICSChangesCallback>(OnPICSChanges)); CallbackManager.Register(new JobCallback<SteamUserStats.NumberOfPlayersCallback>(SteamProxy.Instance.OnNumberOfPlayers)); CallbackManager.Register(new Callback<SteamFriends.ClanStateCallback>(SteamProxy.Instance.OnClanState)); CallbackManager.Register(new Callback<SteamFriends.ChatMsgCallback>(SteamProxy.Instance.OnChatMessage)); CallbackManager.Register(new Callback<SteamFriends.ChatMemberInfoCallback>(SteamProxy.Instance.OnChatMemberInfo)); CallbackManager.Register(new Callback<SteamUser.MarketingMessageCallback>(MarketingHandler.OnMarketingMessage)); // game coordinator if (Settings.Current.Steam.IdleAppID > 0) { GameCoordinator = new GameCoordinator(Settings.Current.Steam.IdleAppID, Client, CallbackManager); } } else { CallbackManager.Register(new JobCallback<SteamApps.PICSChangesCallback>(OnPICSChangesFullRun)); } // Use EU servers Servers = new ReadOnlyCollection<IPEndPoint>( new List<IPEndPoint> { new IPEndPoint( IPAddress.Parse( "146.66.152.12" ), 27017 ), new IPEndPoint( IPAddress.Parse( "146.66.152.12" ), 27018 ), new IPEndPoint( IPAddress.Parse( "146.66.152.12" ), 27019 ), new IPEndPoint( IPAddress.Parse( "146.66.152.13" ), 27017 ), new IPEndPoint( IPAddress.Parse( "146.66.152.13" ), 27018 ), new IPEndPoint( IPAddress.Parse( "146.66.152.13" ), 27019 ), new IPEndPoint( IPAddress.Parse( "146.66.152.14" ), 27017 ), new IPEndPoint( IPAddress.Parse( "146.66.152.14" ), 27018 ), new IPEndPoint( IPAddress.Parse( "146.66.152.14" ), 27019 ), new IPEndPoint( IPAddress.Parse( "146.66.152.15" ), 27017 ), new IPEndPoint( IPAddress.Parse( "146.66.152.15" ), 27018 ), new IPEndPoint( IPAddress.Parse( "146.66.152.15" ), 27019 ) } ); DepotProcessor.Init(); GetLastChangeNumber(); IsRunning = true; Client.Connect(Servers[ new Random().Next( Servers.Count ) ]); while (IsRunning) { CallbackManager.RunWaitCallbacks(TimeSpan.FromSeconds(1)); } }
public void OnNumberOfPlayers(SteamUserStats.NumberOfPlayersCallback callback, JobID jobID) { var request = IRCRequests.Find(r => r.JobID == jobID); if (request == null) { return; } IRCRequests.Remove(request); if (callback.Result != EResult.OK) { CommandHandler.ReplyToCommand(request.Command, "{0}{1}{2}: Unable to request player count: {3}", Colors.OLIVE, request.Command.Nickname, Colors.NORMAL, callback.Result); } else if (request.Target == 0) { CommandHandler.ReplyToCommand(request.Command, "{0}{1}{2}: {3}{4}{5} people praising lord Gaben right now, influence:{6} {7}", Colors.OLIVE, request.Command.Nickname, Colors.NORMAL, Colors.OLIVE, callback.NumPlayers.ToString("N0"), Colors.NORMAL, Colors.DARK_BLUE, SteamDB.GetGraphURL(0)); } else { string url; string name = GetAppName(request.Target); if (string.IsNullOrEmpty(name)) { name = string.Format("AppID {0}", request.Target); } using (MySqlDataReader Reader = DbWorker.ExecuteReader("SELECT `AppID` FROM `ImportantApps` WHERE `Graph` = 1 AND `AppID` = @AppID", new MySqlParameter("AppID", request.Target))) { if (Reader.Read()) { url = string.Format("{0} - graph:{1} {2}", Colors.NORMAL, Colors.DARK_BLUE, SteamDB.GetGraphURL(request.Target)); } else { url = string.Format("{0} -{1} {2}", Colors.NORMAL, Colors.DARK_BLUE, SteamDB.GetAppURL(request.Target)); } } CommandHandler.ReplyToCommand(request.Command, "{0}{1}{2}: People playing {3}{4}{5} right now: {6}{7}{8}", Colors.OLIVE, request.Command.Nickname, Colors.NORMAL, Colors.OLIVE, name, Colors.NORMAL, Colors.YELLOW, callback.NumPlayers.ToString("N0"), url); } }
public void Init() { ProcessorPool = new SmartThreadPool(new STPStartInfo { ThreadPriority = ThreadPriority.AboveNormal }); SecondaryPool = new SmartThreadPool(new STPStartInfo { ThreadPriority = ThreadPriority.BelowNormal }); ProcessorPool.Name = "Processor Pool"; SecondaryPool.Name = "Secondary Pool"; Timer = new System.Timers.Timer(); Timer.Elapsed += new System.Timers.ElapsedEventHandler(OnTimer); Timer.Interval = TimeSpan.FromSeconds(1).TotalMilliseconds; Client = new SteamClient(); User = Client.GetHandler<SteamUser>(); Apps = Client.GetHandler<SteamApps>(); Friends = Client.GetHandler<SteamFriends>(); UserStats = Client.GetHandler<SteamUserStats>(); Unified = Client.GetHandler<SteamUnifiedMessages>(); CallbackManager = new CallbackManager(Client); CallbackManager.Register(new Callback<SteamClient.ConnectedCallback>(OnConnected)); CallbackManager.Register(new Callback<SteamClient.DisconnectedCallback>(OnDisconnected)); CallbackManager.Register(new Callback<SteamUser.AccountInfoCallback>(OnAccountInfo)); CallbackManager.Register(new Callback<SteamUser.LoggedOnCallback>(OnLoggedOn)); CallbackManager.Register(new Callback<SteamUser.LoggedOffCallback>(OnLoggedOff)); CallbackManager.Register(new Callback<SteamApps.LicenseListCallback>(OnLicenseListCallback)); CallbackManager.Register(new JobCallback<SteamUser.UpdateMachineAuthCallback>(OnMachineAuth)); CallbackManager.Register(new JobCallback<SteamApps.PICSChangesCallback>(OnPICSChanges)); CallbackManager.Register(new JobCallback<SteamApps.PICSProductInfoCallback>(OnPICSProductInfo)); // irc specific if (Settings.Current.FullRun == 0) { CallbackManager.Register(new JobCallback<SteamUnifiedMessages.ServiceMethodResponse>(SteamProxy.Instance.OnServiceMethod)); CallbackManager.Register(new JobCallback<SteamUserStats.NumberOfPlayersCallback>(SteamProxy.Instance.OnNumberOfPlayers)); CallbackManager.Register(new Callback<SteamFriends.ClanStateCallback>(SteamProxy.Instance.OnClanState)); CallbackManager.Register(new Callback<SteamFriends.ChatMsgCallback>(SteamProxy.Instance.OnChatMessage)); CallbackManager.Register(new Callback<SteamFriends.ChatMemberInfoCallback>(SteamProxy.Instance.OnChatMemberInfo)); CallbackManager.Register(new Callback<SteamUser.MarketingMessageCallback>(MarketingHandler.OnMarketingMessage)); // game coordinator if (Settings.Current.Steam.IdleAppID > 0) { GameCoordinator = new GameCoordinator(Settings.Current.Steam.IdleAppID, Client, CallbackManager); } } DepotProcessor.Init(); GetLastChangeNumber(); IsRunning = true; Client.Connect(); while (IsRunning) { CallbackManager.RunWaitCallbacks(TimeSpan.FromSeconds(1)); } }