예제 #1
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) : "");
        }
예제 #2
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);
        }
예제 #3
0
 void OnServiceMethod(SteamUnifiedMessages.ServiceMethodResponse callback)
 {
     if (callback.RpcName == "QueryFiles")
         HandleQueryFiles(callback.GetDeserializedResponse<CPublishedFile_QueryFiles_Response>(), callback.JobID);
 }
예제 #4
0
        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);
        }
예제 #5
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();
        }
예제 #6
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 );
        }