Class for managing Steam friends.
Ejemplo n.º 1
0
		/// <summary>
		/// Initializes the <c>SteamManager</c>.
		/// This MUST be called before other Steam operations are executed.
		/// </summary>
		/// <returns><c>true</c> if everything initialized properly, <c>false</c> otherwise.</returns>
		public static bool Init()
		{
			if (Enabled)
			{
				_log.Warn("Tried to call Init method when SteamManager has already been initialized! Aborting...");
				return false;
			}
			_log = LogManager.GetLogger(typeof(SteamManager));
			try
			{
				if (!Steamworks.Load())
				{
					_log.Error("Steamworks failed to load, throwing exception!");
					throw new SteamException("Steamworks failed to load.", SteamExceptionType.SteamworksLoadFail);
				}

				Client = Steamworks.CreateInterface<ISteamClient010>("SteamClient010");
				if (Client == null)
				{
					_log.Error("Steamclient is NULL!! Throwing exception!");
					throw new SteamException("Steamclient failed to load! Is the client running? (Sharpcraft.Steam.SteamManager.Client == null!)",
											 SteamExceptionType.SteamLoadFail);
				}

				Pipe = Client.CreateSteamPipe();
				User = Client.ConnectToGlobalUser(Pipe);

				Friends = Steamworks.CastInterface<ISteamFriends002>(Client.GetISteamFriends(User, Pipe, "SteamFriends002"));

				if (Friends == null)
					return false;

				FriendList = new SteamFriendList();

				_steamWatcher = new Timer(SteamCheck, null, 0, 1000);
			}
			catch (SteamException ex)
			{
				_log.Warn("Warning! SteamManager caught a SteamException exception, returning FALSE. Steam components will NOT LOAD!");
				_log.Warn("The SteamException type was: " + System.Enum.GetName(typeof(SteamExceptionType), ex.Type));
				return false;
			}
			_log.Info("SteamManager has been initialized!");
			SteamLoaded = true;
			Enabled = true;
			return true;
		}
Ejemplo n.º 2
0
		/// <summary>
		/// Check if the Steam client is running, shut down all Steam components if it's not.
		/// </summary>
		/// <param name="state">N/A (Not Used)</param>
		private static void SteamCheck(object state)
		{
			if (string.IsNullOrEmpty(Thread.CurrentThread.Name))
				Thread.CurrentThread.Name = "SteamWatcher";
			//_log.Info("Running Steam process check..."); // Gets VERY spammy in the log.
			bool found = Process.GetProcesses().Any(process => process.ProcessName.ToLower() == "steam");
			if (!found || Friends == null)
			{
				_log.Info("Steam process not running, closing Steam components...");
				_log.Debug("Sending SteamClose event!");
				SteamClose();
				FriendList = null;
				_steamWatcher.Dispose();
				SteamLoaded = false;
				Enabled = false;
			}
		}
Ejemplo n.º 3
0
        /// <summary>
        /// Initializes the <c>SteamManager</c>.
        /// This MUST be called before other Steam operations are executed.
        /// </summary>
        /// <returns><c>true</c> if everything initialized properly, <c>false</c> otherwise.</returns>
        public static bool Init()
        {
            if (Enabled)
            {
                _log.Warn("Tried to call Init method when SteamManager has already been initialized! Aborting...");
                return false;
            }
            _log = LogManager.GetLogger(typeof(SteamManager));
            try
            {
                if (!Steamworks.Load())
                {
                    _log.Error("Steamworks failed to load, throwing exception!");
                    throw new SteamException("Steamworks failed to load.", SteamExceptionType.SteamworksLoadFail);
                }

                Client = Steamworks.CreateInterface<ISteamClient010>("SteamClient010");
                if (Client == null)
                {
                    _log.Error("Steamclient is NULL!! Throwing exception!");
                    throw new SteamException("Steamclient failed to load! Is the client running? (Sharpcraft.Steam.SteamManager.Client == null!)",
                                             SteamExceptionType.SteamLoadFail);
                }

                Pipe = Client.CreateSteamPipe();
                User = Client.ConnectToGlobalUser(Pipe);

                Friends = Steamworks.CastInterface<ISteamFriends002>(Client.GetISteamFriends(User, Pipe, "SteamFriends002"));

                if (Friends == null)
                    return false;

                FriendList = new SteamFriendList();

                _steamWatcher = new Timer(SteamCheck, null, 0, 1000);
            }
            catch (SteamException ex)
            {
                _log.Warn("Warning! SteamManager caught a SteamException exception, returning FALSE. Steam components will NOT LOAD!");
                _log.Warn("The SteamException type was: " + System.Enum.GetName(typeof(SteamExceptionType), ex.Type));
                return false;
            }
            _log.Info("SteamManager has been initialized!");
            SteamLoaded = true;
            Enabled = true;
            return true;
        }