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>(); }
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>(); }
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; })); }
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)); } }
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 ) ); } }
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>(); }
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>(); }
static void FullyLoggedIn(SteamUser.LoggedOnCallback callback) { var task = Task.Run(async() => { try { await CloudStream.DeleteFile("gmpublish_icon.jpg", APPID, steamClient); await CloudStream.DeleteFile("gmpublish.gma", APPID, steamClient); var baseFolder = "./Addon"; var gmaPath = "./addon.gma"; //Path.GetTempFileName(); var addonJsonPath = Path.Combine(baseFolder, "addon.json"); if (!File.Exists(addonJsonPath)) { throw new Exception("No addon.json file found in specified folder"); } AddonJSON addon; using (FileStream addonStream = new FileStream(addonJsonPath, FileMode.Open)) { addon = addonStream.CreateFromJsonStream <AddonJSON>(); } if (addon.Icon == "") { throw new Exception("No icon file specified"); } using (Stream gmaStream = new FileStream(gmaPath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None)) { GMADCreator.Create(baseFolder, addon, gmaStream); gmaStream.Seek(0, SeekOrigin.Begin); using (var icon = new FileStream(Path.Combine(baseFolder, addon.Icon), FileMode.Open)) { var hash = SHAHash(icon); var iconSuccess = await CloudStream.UploadStream("gmpublish_icon.jpg", APPID, hash, icon.Length, steamClient, icon); if (!iconSuccess) { Console.WriteLine("JPG Upload failed"); return; } } var lzmaStream = LZMAEncodeStream.CompressStreamLZMA(gmaStream); var hashGma = SHAHash(lzmaStream); var gmaSuccess = await CloudStream.UploadStream("gmpublish.gma", APPID, hashGma, lzmaStream.Length, steamClient, lzmaStream); if (!gmaSuccess) { Console.WriteLine("GMA Upload failed"); return; } } var publishService = steamUnifiedMessages.CreateService <IPublishedFile>(); if (addon.WorkshopID == 0) { var request = new CPublishedFile_Publish_Request { appid = APPID, consumer_appid = APPID, cloudfilename = "gmpublish.gma", preview_cloudfilename = "gmpublish_icon.jpg", title = addon.Title, file_description = addon.Description, file_type = (uint)EWorkshopFileType.Community, visibility = (uint)EPublishedFileVisibility.Public, collection_type = addon.Type, }; foreach (var tag in addon.Tags) { request.tags.Add(tag); } var publishCallback = await publishService.SendMessage(publish => publish.Publish(request)); var publishResponse = publishCallback.GetDeserializedResponse <CPublishedFile_Publish_Response>(); addon.WorkshopID = publishResponse.publishedfileid; using (FileStream addonStream = new FileStream(addonJsonPath, FileMode.Create)) { addonStream.WriteObjectToStreamJson(addon); } Console.WriteLine("NEW PUBLISHED ID: " + publishResponse.publishedfileid + ". Wrote to addon.json"); } else { var request = new CPublishedFile_Update_Request { image_height = 512, image_width = 512, publishedfileid = addon.WorkshopID, appid = APPID, filename = "gmpublish.gma", preview_filename = "gmpublish_icon.jpg", title = addon.Title, file_description = addon.Description, visibility = (uint)EPublishedFileVisibility.Public, }; foreach (var tag in addon.Tags) { request.tags.Add(tag); } var updateCallback = await publishService.SendMessage(publish => publish.Update(request)); var updateResponse = updateCallback.GetDeserializedResponse <CPublishedFile_Update_Response>(); Console.WriteLine("Addon has been updated"); } } catch (Exception ex) { Console.WriteLine(ex); Console.ReadKey(); } }); task.Wait(); steamUser.LogOff(); isRunning = false; }
static void FullyLoggedIn(SteamUser.LoggedOnCallback callback) { var task = Task.Run(async() => { try { if (currentAction == Action.CREATE || currentAction == Action.UPDATE) { // Delete any previously uploaded temp files await CloudStream.DeleteFile("gmpublish_icon.jpg", APPID, steamClient); await CloudStream.DeleteFile("gmpublish.gma", APPID, steamClient); AddonInfo addonInfo; addonInfo = GetAddonInfoFromGMAFile(gmaFile.OpenRead()); using (Stream gmaStream = gmaFile.OpenRead()) { // for updates the icon file is optional if (iconFile != null && iconFile.Exists) { using (Stream iconStream = iconFile.OpenRead()) { await UploadIcon(iconStream); } } await UploadAddonGMA(gmaStream); } var publishService = steamUnifiedMessages.CreateService <IPublishedFile>(); if (currentAction == Action.CREATE) { Console.WriteLine("Creating new addon - " + addonInfo.title); var request = new CPublishedFile_Publish_Request { appid = APPID, consumer_appid = APPID, cloudfilename = "gmpublish.gma", preview_cloudfilename = "gmpublish_icon.jpg", title = addonInfo.title, file_description = addonInfo.description.Description, file_type = (uint)EWorkshopFileType.Community, visibility = (uint)EPublishedFileVisibility.Public, collection_type = addonInfo.description.Type, }; foreach (var tag in addonInfo.description.Tags) { request.tags.Add(tag); } var publishCallback = await publishService.SendMessage(publish => publish.Publish(request)); var publishResponse = publishCallback.GetDeserializedResponse <CPublishedFile_Publish_Response>(); var newId = publishResponse.publishedfileid; Console.WriteLine(publishResponse.redirect_uri); Console.WriteLine("Success! New Addon Published. Addon ID: " + newId.ToString()); Exit(1); // 1 signals success in the original gmpublish } else // currentAction == Action.UPDATE { Console.WriteLine("Updating existing addon " + workshopId + " - " + addonInfo.title); var request = new CPublishedFile_Update_Request { publishedfileid = (ulong)workshopId, appid = APPID, filename = "gmpublish.gma", title = addonInfo.title, file_description = addonInfo.description.Description, visibility = (uint)EPublishedFileVisibility.Public, }; foreach (var tag in addonInfo.description.Tags) { request.tags.Add(tag); } // only update the icon if one was supplied if (iconFile != null && iconFile.Exists) { request.image_height = 512; request.image_width = 512; request.preview_filename = "gmpublish_icon.jpg"; } var updateCallback = await publishService.SendMessage(publish => publish.Update(request)); var updateResponse = updateCallback.GetDeserializedResponse <CPublishedFile_Update_Response>(); Console.WriteLine("Success! Addon " + workshopId + " has been updated"); Exit(1); // 1 signals success in the original gmpublish } } else if (currentAction == Action.LIST) { var publishService = steamUnifiedMessages.CreateService <IPublishedFile>(); var request = new CPublishedFile_GetUserFiles_Request { appid = APPID, ids_only = false, steamid = steamClient.SteamID.ConvertToUInt64() }; Console.WriteLine("Getting published files...\n"); var listCallback = await publishService.SendMessage(publish => publish.GetUserFiles(request)); var listResponse = listCallback.GetDeserializedResponse <CPublishedFile_GetUserFiles_Response>(); Console.WriteLine("Found " + listResponse.total.ToString() + " results"); listResponse.publishedfiledetails.ForEach(publishedFile => Console.WriteLine(String.Format("\t{0}\t{1,-5:F1} MB \"{2}\" ", publishedFile.publishedfileid, publishedFile.file_size / 1000000f, publishedFile.title)) ); Exit(1); // 1 signals success in the original gmpublish } } catch (Exception ex) { Console.WriteLine(ex); Exit(2); } }); task.Wait(); steamUser.LogOff(); isRunning = false; }