private void OnServiceMethod(SteamUnifiedMessages.ServiceMethodResponse 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 make service request: {0}", callback.Result);

                return;
            }

            // .chat about grate
            switch (request.Type)
            {
                case JobManager.IRCRequestType.TYPE_GAMESERVERS:
                    ServersCommand.OnServiceMethod(callback, request);
                    return;

                case JobManager.IRCRequestType.TYPE_PUBFILE:
                case JobManager.IRCRequestType.TYPE_PUBFILE_SILENT:
                    PubFileCommand.OnServiceMethod(callback, request);
                    return;
            }

            CommandHandler.ReplyToCommand(request.Command, "Unknown request type, I don't know what to do.");
        }
Example #2
0
        public static void OnServiceMethod(SteamUnifiedMessages.ServiceMethodResponse callback, JobManager.IRCRequest request)
        {
            var response = callback.GetDeserializedResponse<CGameServers_GetServerList_Response>();
            var servers = response.servers;

            if (!servers.Any())
            {
                CommandHandler.ReplyToCommand(request.Command, "No servers.");

                return;
            }

            if (servers.Count == 1)
            {
                var server = servers.First();

                CommandHandler.ReplyToCommand(request.Command, "{0} - {1} - {2}/{3} - Map: {4} - AppID: {5} - Version: {6} - Dir: {7} - Tags: {8} - Name: {9}",
                    server.addr, new SteamID(server.steamid).Render(true), server.players, server.max_players, server.map, server.appid, server.version, server.gamedir, server.gametype, server.name
                );

                return;
            }

            var serv = servers.Take(5).Select(x => string.Format("{0} ({1})", x.addr, x.players));

            CommandHandler.ReplyToCommand(request.Command, "{0}{1}", string.Join(", ", serv), servers.Count > 5 ? string.Format(", and {0}{1} more", servers.Count == 5000 ? ">" : "", servers.Count - 5) : "");
        }
Example #3
0
        public async Task <bool> LoginPrompt(bool background = false, string username = null, string password = null, string authCode = null, string emailCode = null)
        {
            UserConfig.RegisterConfig("steam");

            this.background = background;
            this.username   = username;
            this.password   = password;
            this.authCode   = authCode;
            this.emailCode  = emailCode;

            client  = new SteamClient();
            manager = new CallbackManager(client);
            user    = client.GetHandler <SteamUser>();
            friends = client.GetHandler <SteamFriends>();
            manager.Subscribe <SteamClient.ConnectedCallback>(OnConnected);
            manager.Subscribe <SteamClient.DisconnectedCallback>(OnDisconnected);

            manager.Subscribe <SteamUser.LoggedOnCallback>(OnLoggedOn);
            manager.Subscribe <SteamUser.LoggedOffCallback>(OnLoggedOff);
            manager.Subscribe <SteamUser.LoginKeyCallback>(OnLoginKey);

            //manager.Subscribe<SteamFriends.FriendsListCallback>(OnFriendList);
            manager.Subscribe <SteamUnifiedMessages.ServiceMethodResponse>(OnMethodResponse);

            unifiedMessages = client.GetHandler <SteamUnifiedMessages>();
            servicePlayer   = unifiedMessages.CreateService <IPlayer>();

            loginStatus = LOGIN_STATUS.AWAITING;
            Debug.WriteLine("Connecting to steam..");
            client.Connect();

            cancelCallbackTok = new CancellationTokenSource();
            Task callbackTask = new Task(() =>
            {
                while (!cancelCallbackTok.IsCancellationRequested)
                {
                    try
                    {
                        manager.RunCallbacks();
                    }
                    catch (Exception e) {
                        Console.WriteLine("Error! : " + e.Message);
                    }
                }
            }, cancelCallbackTok.Token);

            callbackTask.Start();

            return(await Task <bool> .Run(() =>
            {
                while (loginStatus == LOGIN_STATUS.AWAITING)
                {
                }
                return loginStatus == LOGIN_STATUS.SUCCESS;
            }));
        }
Example #4
0
        static void Main( string[] args )
        {
            if ( args.Length < 2 )
            {
                Console.WriteLine( "Sample8: No username and password specified!" );
                return;
            }

            // save our logon details
            user = args[0];
            pass = args[1];

            // create our steamclient instance
            steamClient = new SteamClient();
            // create the callback manager which will route callbacks to function calls
            manager = new CallbackManager( steamClient );

            // get the steamuser handler, which is used for logging on after successfully connecting
            steamUser = steamClient.GetHandler<SteamUser>();

            // get the steam unified messages handler, which is used for sending and receiving responses from the unified service api
            steamUnifiedMessages = steamClient.GetHandler<SteamUnifiedMessages>();

            // we also want to create our local service interface, which will help us build requests to the unified api
            playerService = steamUnifiedMessages.CreateService<IPlayer>();


            // register a few callbacks we're interested in
            // these are registered upon creation to a callback manager, which will then route the callbacks
            // to the functions specified
            manager.Subscribe<SteamClient.ConnectedCallback>( OnConnected );
            manager.Subscribe<SteamClient.DisconnectedCallback>( OnDisconnected );

            manager.Subscribe<SteamUser.LoggedOnCallback>( OnLoggedOn );
            manager.Subscribe<SteamUser.LoggedOffCallback>( OnLoggedOff );

            // we use the following callbacks for unified service responses
            manager.Subscribe<SteamUnifiedMessages.ServiceMethodResponse>( OnMethodResponse );

            isRunning = true;

            Console.WriteLine( "Connecting to Steam..." );

            // initiate the connection
            steamClient.Connect();

            // create our callback handling loop
            while ( isRunning )
            {
                // in order for the callbacks to get routed, they need to be handled by the manager
                manager.RunWaitCallbacks( TimeSpan.FromSeconds( 1 ) );
            }
        }
Example #5
0
    internal ArchiHandler(ArchiLogger archiLogger, SteamUnifiedMessages steamUnifiedMessages)
    {
        ArgumentNullException.ThrowIfNull(steamUnifiedMessages);

        ArchiLogger                  = archiLogger ?? throw new ArgumentNullException(nameof(archiLogger));
        UnifiedChatRoomService       = steamUnifiedMessages.CreateService <IChatRoom>();
        UnifiedClanChatRoomsService  = steamUnifiedMessages.CreateService <IClanChatRooms>();
        UnifiedEconService           = steamUnifiedMessages.CreateService <IEcon>();
        UnifiedFriendMessagesService = steamUnifiedMessages.CreateService <IFriendMessages>();
        UnifiedPlayerService         = steamUnifiedMessages.CreateService <IPlayer>();
        UnifiedTwoFactorService      = steamUnifiedMessages.CreateService <ITwoFactor>();
    }
Example #6
0
        static void Main(string[] args)
        {
            if (args.Length < 2)
            {
                Console.WriteLine("Sample8: No username and password specified!");
                return;
            }

            // save our logon details
            user = args[0];
            pass = args[1];

            // create our steamclient instance
            steamClient = new SteamClient();
            // create the callback manager which will route callbacks to function calls
            manager = new CallbackManager(steamClient);

            // get the steamuser handler, which is used for logging on after successfully connecting
            steamUser = steamClient.GetHandler <SteamUser>();

            // get the steam unified messages handler, which is used for sending and receiving responses from the unified service api
            steamUnifiedMessages = steamClient.GetHandler <SteamUnifiedMessages>();

            // we also want to create our local service interface, which will help us build requests to the unified api
            playerService = steamUnifiedMessages.CreateService <IPlayer>();


            // register a few callbacks we're interested in
            // these are registered upon creation to a callback manager, which will then route the callbacks
            // to the functions specified
            manager.Subscribe <SteamClient.ConnectedCallback>(OnConnected);
            manager.Subscribe <SteamClient.DisconnectedCallback>(OnDisconnected);

            manager.Subscribe <SteamUser.LoggedOnCallback>(OnLoggedOn);
            manager.Subscribe <SteamUser.LoggedOffCallback>(OnLoggedOff);

            // we use the following callbacks for unified service responses
            manager.Subscribe <SteamUnifiedMessages.ServiceMethodResponse>(OnMethodResponse);

            isRunning = true;

            Console.WriteLine("Connecting to Steam...");

            // initiate the connection
            steamClient.Connect();

            // create our callback handling loop
            while (isRunning)
            {
                // in order for the callbacks to get routed, they need to be handled by the manager
                manager.RunWaitCallbacks(TimeSpan.FromSeconds(1));
            }
        }
Example #7
0
        internal ArchiHandler(ArchiLogger archiLogger, SteamUnifiedMessages steamUnifiedMessages)
        {
            if ((archiLogger == null) || (steamUnifiedMessages == null))
            {
                throw new ArgumentNullException(nameof(archiLogger) + " || " + nameof(steamUnifiedMessages));
            }

            ArchiLogger                  = archiLogger;
            UnifiedChatRoomService       = steamUnifiedMessages.CreateService <IChatRoom>();
            UnifiedClanChatRoomsService  = steamUnifiedMessages.CreateService <IClanChatRooms>();
            UnifiedFriendMessagesService = steamUnifiedMessages.CreateService <IFriendMessages>();
            UnifiedPlayerService         = steamUnifiedMessages.CreateService <IPlayer>();
        }
Example #8
0
        internal SCHandler([NotNull] Logger logger, [NotNull] SteamUnifiedMessages steamUnifiedMessages)
        {
            if (logger == null || steamUnifiedMessages == null)
            {
                throw new ArgumentNullException(nameof(logger) + " || " + nameof(steamUnifiedMessages));
            }

            Logger = logger;
            UnifiedChatRoomService       = steamUnifiedMessages.CreateService <IChatRoom>();
            UnifiedClanChatRoomsService  = steamUnifiedMessages.CreateService <IClanChatRooms>();
            UnifiedEconService           = steamUnifiedMessages.CreateService <IEcon>();
            UnifiedFriendMessagesService = steamUnifiedMessages.CreateService <IFriendMessages>();
            UnifiedPlayerService         = steamUnifiedMessages.CreateService <IPlayer>();
        }
Example #9
0
        public override void Init()
        {
            steam_friends    = Instance.SteamClient.GetHandler <SteamFriends>();
            unified_messages = Instance.SteamClient.GetHandler <SteamUnifiedMessages>();

            Instance.CallbackManager.Subscribe <SteamFriends.ChatMsgCallback>(cb => OnChatMessage(cb));
            Instance.CallbackManager.Subscribe <SteamFriends.ChatEnterCallback>(cb => OnChatEnter(cb));
            Instance.CallbackManager.Subscribe <SteamFriends.PersonaStateCallback>(cb => OnPersonaState(cb));
            Instance.CallbackManager.Subscribe <SteamFriends.FriendMsgCallback>(cb => OnFriendMessage(cb));
            Instance.CallbackManager.Subscribe <SteamFriends.ClanStateCallback>(cb => OnClanState(cb));

            Instance.CallbackManager.Subscribe <SteamUnifiedMessages.ServiceMethodNotification>(cb => OnServiceMethod(cb));
            Instance.CallbackManager.Subscribe <SteamUnifiedMessages.ServiceMethodResponse>(cb => OnServiceMethodResponse(cb));

            Instance.PacketHandler.Subscribe <CMsgClientFriendsGroupsList>(EMsg.ClientFriendsGroupsList, cb => OnClientFriendsGroupsList(cb));
        }
    public void RenderOnGUI()
    {
        GUILayout.BeginArea(new Rect(Screen.width - 200, 0, 200, Screen.height));
        GUILayout.Label("Variables:");
        GUILayout.Label("m_ClientUnifiedMessageHandle: " + m_ClientUnifiedMessageHandle);
        GUILayout.EndArea();

        GUILayout.BeginVertical("box");
        m_ScrollPos = GUILayout.BeginScrollView(m_ScrollPos, GUILayout.Width(Screen.width - 215), GUILayout.Height(Screen.height - 33));

        // TODO: I don't know what I'm doing. This whole interface has essentially Zero Documentation.
        if (GUILayout.Button("SendMethod(\"Player.GetGameBadgeLevels#1\", null, 0, 1111)"))
        {
            ClientUnifiedMessageHandle ret = SteamUnifiedMessages.SendMethod("Player.GetGameBadgeLevels#1", null, 0, 1111);
            m_ClientUnifiedMessageHandle = ret;
            print("SteamUnifiedMessages.SendMethod(" + "\"Player.GetGameBadgeLevels#1\"" + ", " + null + ", " + 0 + ", " + 1111 + ") : " + ret);
        }

        if (GUILayout.Button("GetMethodResponseInfo(m_ClientUnifiedMessageHandle, out ResponseSize, out Result)"))
        {
            uint    ResponseSize;
            EResult Result;
            bool    ret = SteamUnifiedMessages.GetMethodResponseInfo(m_ClientUnifiedMessageHandle, out ResponseSize, out Result);
            print("SteamUnifiedMessages.GetMethodResponseInfo(" + m_ClientUnifiedMessageHandle + ", " + "out ResponseSize" + ", " + "out Result" + ") : " + ret + " -- " + ResponseSize + " -- " + Result);
        }

        if (GUILayout.Button("GetMethodResponseData(m_ClientUnifiedMessageHandle, new byte[1], 1, true)"))
        {
            bool ret = SteamUnifiedMessages.GetMethodResponseData(m_ClientUnifiedMessageHandle, new byte[1], 1, true);
            print("SteamUnifiedMessages.GetMethodResponseData(" + m_ClientUnifiedMessageHandle + ", " + new byte[1] + ", " + 1 + ", " + true + ") : " + ret);
        }

        if (GUILayout.Button("ReleaseMethod(m_ClientUnifiedMessageHandle)"))
        {
            bool ret = SteamUnifiedMessages.ReleaseMethod(m_ClientUnifiedMessageHandle);
            print("SteamUnifiedMessages.ReleaseMethod(" + m_ClientUnifiedMessageHandle + ") : " + ret);
        }

        if (GUILayout.Button("SendNotification(\"MsgTest.NotifyServer#1\", null, 0)"))
        {
            bool ret = SteamUnifiedMessages.SendNotification("MsgTest.NotifyServer#1", null, 0);
            print("SteamUnifiedMessages.SendNotification(" + "\"MsgTest.NotifyServer#1\"" + ", " + null + ", " + 0 + ") : " + ret);
        }

        GUILayout.EndScrollView();
        GUILayout.EndVertical();
    }
Example #11
0
        static void SteamLogin()
        {
            steamClient = new SteamClient();

            #region callbacks
            manager = new CallbackManager(steamClient);
            manager.Subscribe <SteamClient.ConnectedCallback>(OnConnected);
            manager.Subscribe <SteamClient.DisconnectedCallback>(OnDisconnected);
            manager.Subscribe <SteamUser.LoggedOnCallback>(OnLoggedOn);
            manager.Subscribe <SteamUser.UpdateMachineAuthCallback>(UpdateMachineAuthCallback); // If steam guard auth succeeded
            manager.Subscribe <SteamUser.AccountInfoCallback>(OnAccountInfo);
            manager.Subscribe <SteamUser.LoggedOffCallback>(OnLoggedOff);
            manager.Subscribe <SteamFriends.FriendMsgCallback>(OnChatMessage);
            manager.Subscribe <SteamFriends.FriendAddedCallback>(OnFriendAdded);
            manager.Subscribe <SteamFriends.FriendsListCallback>(OnFriendsList);
            manager.Subscribe <SteamGameCoordinator.MessageCallback>(OnGCMessage);
            #endregion

            #region Handlers
            steamUser            = steamClient.GetHandler <SteamUser>();
            steamFriends         = steamClient.GetHandler <SteamFriends>();
            steamCloud           = steamClient.GetHandler <SteamCloud>();
            steamGameServer      = steamClient.GetHandler <SteamGameServer>();
            steamMasterServer    = steamClient.GetHandler <SteamMasterServer>();
            steamGameCoordinator = steamClient.GetHandler <SteamGameCoordinator>();
            steamScreenshots     = steamClient.GetHandler <SteamScreenshots>();
            steamTrading         = steamClient.GetHandler <SteamTrading>();
            steamUFM             = steamClient.GetHandler <SteamUnifiedMessages>();
            steamUserStats       = steamClient.GetHandler <SteamUserStats>();
            steamWorkShop        = steamClient.GetHandler <SteamWorkshop>();
            #endregion

            isRunning = true;

            Console.Title = "Steam Bot - Connecting...";

            steamClient.Connect();

            while (isRunning)
            {
                manager.RunWaitCallbacks(TimeSpan.FromSeconds(1));
            }
            Console.ReadKey();
        }
    public void RenderOnGUI()
    {
        GUILayout.BeginArea(new Rect(Screen.width - 120, 0, 120, Screen.height));
        GUILayout.Label("Variables:");
        GUILayout.Label("m_ClientUnifiedMessageHandle: " + m_ClientUnifiedMessageHandle);
        GUILayout.EndArea();

        // TODO: I don't know what I'm doing. This whole interface has essentially Zero Documentation.
        if (GUILayout.Button("SendMethod(\"CMsgTest_MessageToServer_Request\", null, 0, 1111)"))
        {
            m_ClientUnifiedMessageHandle = SteamUnifiedMessages.SendMethod("Player.GetGameBadgeLevels#1", null, 0, 1111);
            print("SteamUnifiedMessages.SendMethod(\"CMsgTest_MessageToServer_Request\", null, 0, 1111) : " + m_ClientUnifiedMessageHandle);
        }

        if (GUILayout.Button("GetMethodResponseInfo(m_ClientUnifiedMessageHandle, out ResponseSize, out Result)"))
        {
            uint    ResponseSize;
            EResult Result;
            bool    ret = SteamUnifiedMessages.GetMethodResponseInfo(m_ClientUnifiedMessageHandle, out ResponseSize, out Result);
            print("SteamUnifiedMessages.GetMethodResponseInfo(" + m_ClientUnifiedMessageHandle + ", out ResponseSize, out Result) : " + ret + " -- " + ResponseSize + " -- " + Result);
        }

        if (GUILayout.Button("GetMethodResponseData(m_ClientUnifiedMessageHandle, new byte[1], 1, true)"))
        {
            bool ret = SteamUnifiedMessages.GetMethodResponseData(m_ClientUnifiedMessageHandle, new byte[1], 1, true);
            print("SteamUnifiedMessages.GetMethodResponseData(" + m_ClientUnifiedMessageHandle + ", new byte[1], 1, true) : " + ret);
        }

        if (GUILayout.Button("ReleaseMethod(m_ClientUnifiedMessageHandle)"))
        {
            bool ret = SteamUnifiedMessages.ReleaseMethod(m_ClientUnifiedMessageHandle);
            print("SteamUnifiedMessages.ReleaseMethod(" + m_ClientUnifiedMessageHandle + ") : " + ret);
        }

        if (GUILayout.Button("SteamUnifiedMessages.SendNotification(\"MsgTest.NotifyServer#1\", null, 0)"))
        {
            bool ret = SteamUnifiedMessages.SendNotification("MsgTest.NotifyServer#1", null, 0);
            print("SteamUnifiedMessages.SendNotification(\"MsgTest.NotifyServer#1\", null, 0) : " + ret);
        }
    }
Example #13
0
        public static void Main(string[] args)
        {
            //DebugLog.AddListener((level, msg) =>
            //{
            //    Console.WriteLine("[{0}] {1}", level, msg);
            //});

            if (args.Length < 2)
            {
                Console.WriteLine("GMPublish: No username and password specified!");
                return;
            }

            user = args[0];
            pass = args[1];

            SteamDirectory.Initialize().Wait();

            steamClient          = new SteamClient();
            manager              = new CallbackManager(steamClient);
            steamUser            = steamClient.GetHandler <SteamUser>();
            steamUnifiedMessages = steamClient.GetHandler <SteamUnifiedMessages>();

            manager.Subscribe <SteamClient.ConnectedCallback>(OnConnected);
            manager.Subscribe <SteamClient.DisconnectedCallback>(OnDisconnected);
            manager.Subscribe <SteamUser.LoggedOnCallback>(OnLoggedOn);
            manager.Subscribe <SteamUser.LoggedOffCallback>(OnLoggedOff);
            manager.Subscribe <SteamUser.UpdateMachineAuthCallback>(OnMachineAuth);

            Console.WriteLine("Connecting to Steam...");
            isRunning = true;
            steamClient.Connect();
            while (isRunning)
            {
                manager.RunWaitCallbacks(TimeSpan.FromSeconds(1));
            }
            Console.WriteLine("Done?");
            Console.ReadLine();
        }
Example #14
0
        public static void Main(string[] args)
        {
            //DebugLog.AddListener((level, msg) =>
            //{
            //    Console.WriteLine("[{0}] {1}", level, msg);
            //});

            if (args.Length < 3)
            {
                Console.WriteLine("GMPublish: missing arguments. gmpublish.exe [user] [password] [addonFolder]");
                return;
            }

            user      = args[0];
            pass      = args[1];
            addonRoot = args[2];

            steamClient          = new SteamClient();
            manager              = new CallbackManager(steamClient);
            steamUser            = steamClient.GetHandler <SteamUser>();
            steamUnifiedMessages = steamClient.GetHandler <SteamUnifiedMessages>();

            manager.Subscribe <SteamClient.ConnectedCallback>(OnConnected);
            manager.Subscribe <SteamClient.DisconnectedCallback>(OnDisconnected);
            manager.Subscribe <SteamUser.LoggedOnCallback>(OnLoggedOn);
            manager.Subscribe <SteamUser.LoggedOffCallback>(OnLoggedOff);
            manager.Subscribe <SteamUser.UpdateMachineAuthCallback>(OnMachineAuth);

            Console.WriteLine("Connecting to Steam...");
            isRunning = true;
            steamClient.Connect();
            while (isRunning)
            {
                manager.RunWaitCallbacks(TimeSpan.FromSeconds(1));
            }
            Console.WriteLine("Done?");
            Console.ReadLine();
        }
Example #15
0
        public static void OnServiceMethod(SteamUnifiedMessages.ServiceMethodResponse callback, JobManager.IRCRequest request)
        {
            var response = callback.GetDeserializedResponse<CPublishedFile_GetDetails_Response>();
            var details = response.publishedfiledetails.FirstOrDefault();

            if (request.Type == JobManager.IRCRequestType.TYPE_PUBFILE_SILENT)
            {
                if (details == null || (EResult)details.result != EResult.OK)
                {
                    return;
                }

                string title;

                if (!string.IsNullOrWhiteSpace(details.title))
                {
                    title = details.title;
                }
                else if (!string.IsNullOrEmpty(details.file_description))
                {
                    title = details.file_description;
                }
                else
                {
                    title = details.filename;
                }

                if (title.Length > 49)
                {
                    title = title.Substring(0, 49) + "…";
                }

                if (request.Command.CommandType == ECommandType.SteamChatRoom)
                {
                    Steam.Instance.Friends.SendChatRoomMessage(request.Command.ChatRoomID, EChatEntryType.ChatMsg,
                        string.Format("» {0}: {1} for {2} ({3:N0} views){4}", ((EWorkshopFileType)details.file_type), title, details.app_name, details.views, details.spoiler_tag ? " :retreat: SPOILER" : "")
                    );
                }
                else
                {
                    IRC.Instance.SendReply(request.Command.Recipient,
                        string.Format("{0}» {1}{2} {3}{4}{5} for {6}{7}{8} ({9} views)",
                            Colors.OLIVE,
                            Colors.NORMAL,
                            ((EWorkshopFileType)details.file_type),
                            Colors.BLUE,
                            title,
                            Colors.NORMAL,
                            Colors.BLUE,
                            details.app_name,
                            Colors.LIGHTGRAY,
                            details.views
                        ),
                        false
                    );
                }

                return;
            }

            if (details == null)
            {
                CommandHandler.ReplyToCommand(request.Command, "Unable to make service request for published file info: the server returned no info");

                return;
            }

            var result = (EResult)details.result;

            if (result != EResult.OK)
            {
                CommandHandler.ReplyToCommand(request.Command, "Unable to get published file info: {0}", result);

                return;
            }

            try
            {
                var json = JsonConvert.SerializeObject(details, Formatting.Indented);

                File.WriteAllText(Path.Combine(Application.Path, "ugc", string.Format("{0}.json", details.publishedfileid)), json, Encoding.UTF8);
            }
            catch (Exception e)
            {
                CommandHandler.ReplyToCommand(request.Command, "Unable to save file: {0}", e.Message);

                return;
            }

            CommandHandler.ReplyToCommand(request.Command, "{0}, Title: {1}{2}{3}, Creator: {4}{5}{6}, App: {7}{8}{9}{10}, File UGC: {11}{12}{13}, Preview UGC: {14}{15}{16} -{17} {18}",
                (EWorkshopFileType)details.file_type,
                Colors.BLUE, string.IsNullOrWhiteSpace(details.title) ? "[no title]" : details.title, Colors.NORMAL,
                Colors.BLUE, new SteamID(details.creator).Render(true), Colors.NORMAL,
                Colors.BLUE, details.creator_appid,
                details.creator_appid == details.consumer_appid ? "" : string.Format(" (consumer {0})", details.consumer_appid),
                Colors.NORMAL,
                Colors.BLUE, details.hcontent_file, Colors.NORMAL,
                Colors.BLUE, details.hcontent_preview, Colors.NORMAL,
                Colors.DARKBLUE, SteamDB.GetUGCURL(details.publishedfileid)
            );

            CommandHandler.ReplyToCommand(request.Command, true, "{0} - https://steamcommunity.com/sharedfiles/filedetails/?id={1}", details.file_url, details.publishedfileid);
        }
Example #16
0
        void OnServiceMethod( SteamUnifiedMessages.ServiceMethodResponse callback )
        {
            UGCJob ugcJob;
            bool foundJob = ugcJobs.TryGetValue( callback.JobID, out ugcJob );
            ugcJobs.Remove( callback.JobID );

            if ( !foundJob )
            {
                // didn't find a waiting UGC job for this response
                return;
            }

            if ( callback.Result != EResult.OK )
            {
                ugcJob.Callback( new UGCJobResult( callback.JobID, callback.Result ) );
                return;
            }

            var response = callback.GetDeserializedResponse<CPublishedFile_GetDetails_Response>();
            var details = response.publishedfiledetails.FirstOrDefault(); // we only ever request one pubfile at a time

            EResult pubResult = (EResult)details.result;

            if ( pubResult != EResult.OK )
            {
                ugcJob.Callback( new UGCJobResult ( callback.JobID, pubResult ) );
                return;
            }

            // cache out this ugc to file and memory

            ugcCache[details.publishedfileid] = new UGCCacheEntry
            {
                PubFileID = details.publishedfileid,
                AppID = details.consumer_appid,

                Name = details.title,
                Tags = details.tags
            };

            using ( var ms = new MemoryStream() )
            {
                Serializer.Serialize( ms, details );

                try
                {
                    File.WriteAllBytes( GetCachePath( details.publishedfileid ), ms.ToArray() );
                }
                catch ( IOException ex )
                {
                    Log.WriteError( "UGCHandler", "Unable to cache ugc for pubfile {0}: {1}", details.publishedfileid, ex.Message );
                    return;
                }
            }

            var result = new UGCJobResult
            {
                ID = callback.JobID,
                Details = details,
            };

            ugcJob.Callback( result );
        }
 void OnServiceMethod(SteamUnifiedMessages.ServiceMethodResponse callback)
 {
     if (callback.RpcName == "QueryFiles")
         HandleQueryFiles(callback.GetDeserializedResponse<CPublishedFile_QueryFiles_Response>(), callback.JobID);
 }
Example #18
0
        public static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                Console.WriteLine("GMPublish: You need to pass at least one agument!");
                return;
            }

            // Get the user and pass from the args if they are set.
            // The can be passed via args or via environment variables
            user = FindArgumentValue("-user", args, false);
            pass = FindArgumentValue("-pass", args, false);

            if (user == null)
            {
                user = Environment.GetEnvironmentVariable("GMPUBLISH_USER");
            }

            if (pass == null)
            {
                pass = Environment.GetEnvironmentVariable("GMPUBLISH_PASS");
            }

            if (user == null || pass == null)
            {
                Console.WriteLine("GMPublish: You must pass a username and password via the -user and -pass arguments OR via the GMPUBLISH_USER and GMPUBLISH_PASS environment variables.");
                Exit(8);
                return;
            }

            string gmaFilePath, iconFilePath;

            switch (args[0])
            {
            case "create":
                currentAction = Action.CREATE;

                gmaFilePath = FindArgumentValue("-addon", args, true);
                gmaFile     = GetFileInfoOrExit(gmaFilePath);

                iconFilePath = FindArgumentValue("-icon", args, true);
                iconFile     = GetFileInfoOrExit(iconFilePath);
                break;

            case "update":
                currentAction = Action.UPDATE;

                gmaFilePath = FindArgumentValue("-addon", args, true);
                gmaFile     = GetFileInfoOrExit(gmaFilePath);

                workshopId = int.Parse(FindArgumentValue("-id", args, true));

                iconFilePath = FindArgumentValue("-icon", args, false);
                if (iconFilePath != null)
                {
                    iconFile = GetFileInfoOrExit(iconFilePath);
                }
                break;

            case "list":
                currentAction = Action.LIST;
                break;

            default:
                Console.WriteLine("Invalid command please use either create, update or list");
                Exit(8);
                break;
            }

            SteamDirectory.Initialize().Wait();

            steamClient          = new SteamClient();
            manager              = new CallbackManager(steamClient);
            steamUser            = steamClient.GetHandler <SteamUser>();
            steamUnifiedMessages = steamClient.GetHandler <SteamUnifiedMessages>();

            manager.Subscribe <SteamClient.ConnectedCallback>(OnConnected);
            manager.Subscribe <SteamClient.DisconnectedCallback>(OnDisconnected);
            manager.Subscribe <SteamUser.LoggedOnCallback>(OnLoggedOn);
            manager.Subscribe <SteamUser.LoggedOffCallback>(OnLoggedOff);
            manager.Subscribe <SteamUser.UpdateMachineAuthCallback>(OnMachineAuth);

            Console.WriteLine("Connecting to Steam...");
            isRunning = true;
            steamClient.Connect();
            while (isRunning)
            {
                manager.RunWaitCallbacks(TimeSpan.FromSeconds(1));
            }
            Console.WriteLine("Done?");
            Console.ReadLine();
        }
Example #19
0
        internal ArchiHandler([JetBrains.Annotations.NotNull] ArchiLogger archiLogger, [JetBrains.Annotations.NotNull] SteamUnifiedMessages steamUnifiedMessages)
        {
            if ((archiLogger == null) || (steamUnifiedMessages == null))
            {
                throw new ArgumentNullException(nameof(archiLogger) + " || " + nameof(steamUnifiedMessages));
            }

            ArchiLogger                  = archiLogger;
            UnifiedChatRoomService       = steamUnifiedMessages.CreateService <IChatRoom>();
            UnifiedClanChatRoomsService  = steamUnifiedMessages.CreateService <IClanChatRooms>();
            UnifiedEconService           = steamUnifiedMessages.CreateService <IEcon>();
            UnifiedFriendMessagesService = steamUnifiedMessages.CreateService <IFriendMessages>();
            UnifiedPlayerService         = steamUnifiedMessages.CreateService <IPlayer>();
            UnifiedTwoFactorService      = steamUnifiedMessages.CreateService <ITwoFactor>();
        }
        public void OnServiceMethod(SteamUnifiedMessages.ServiceMethodResponse 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 get player games: {3}", Colors.OLIVE, request.Command.Nickname, Colors.NORMAL, callback.Result);

                return;
            }

            var response = callback.GetDeserializedResponse<SteamKit2.Unified.Internal.CPlayer_GetOwnedGames_Response>();

            string roulette = string.Empty;

            if (response.game_count > 2)
            {
                var game = response.games[new Random().Next((int)response.game_count)];

                roulette = string.Format("{0} - Roulette: {1}{2}{3} -{4} steam://run/{5}/", Colors.NORMAL, Colors.OLIVE, GetAppName((uint)game.appid), Colors.NORMAL, Colors.DARK_BLUE, game.appid);
            }

            CommandHandler.ReplyToCommand(request.Command, "{0}{1}{2}: {3}{4}{5} games owned -{6} {7}{8}", Colors.OLIVE, request.Command.Nickname, Colors.NORMAL, Colors.YELLOW, response.game_count, Colors.NORMAL, Colors.DARK_BLUE, SteamDB.GetCalculatorURL(request.SteamID), roulette);
        }
Example #21
0
        static void OnMethodResponse( SteamUnifiedMessages.ServiceMethodResponse callback )
        {
            if ( callback.JobID != badgeRequest )
            {
                // always double check the jobid of the response to ensure you're matching to your original request
                return;
            }

            // and check for success
            if ( callback.Result != EResult.OK )
            {
                Console.WriteLine( $"Unified service request failed with {callback.Result}" );
                return;
            }

            // retrieve the deserialized response for the request we made
            // notice the naming pattern
            // for requests: CMyService_Method_Request
            // for responses: CMyService_Method_Response
            CPlayer_GetGameBadgeLevels_Response resp = callback.GetDeserializedResponse<CPlayer_GetGameBadgeLevels_Response>();

            Console.WriteLine( $"Our player level is {resp.player_level}" );

            foreach ( var badge in resp.badges )
            {
                Console.WriteLine( $"Badge series {badge.series} is level {badge.level}" );
            }

            badgeRequest = JobID.Invalid;

            // now that we've completed our task, lets log off
            steamUser.LogOff();
        }