-
-
Save rymate1234/127cd9737fd9124b4249 to your computer and use it in GitHub Desktop.
Ported https://gist.github.com/seishun/6706470 into C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using SteamKit2; | |
using SteamKit2.Internal; // brings in our protobuf client messages | |
namespace DAE_WANT_STEAM_MACHINES | |
{ | |
class Program | |
{ | |
static SteamClient steamClient; | |
static SteamUser steamUser; | |
static bool isRunning; | |
static string user, pass; | |
static SteamFriends steamFriends; | |
static void Main(string[] args) | |
{ | |
if (args.Length < 2) | |
{ | |
Console.WriteLine("Enter Username:"); | |
user = Console.ReadLine(); | |
Console.WriteLine("Enter Password:"); | |
pass = Console.ReadLine(); | |
} | |
else | |
{ | |
// save our logon details | |
user = args[0]; | |
pass = args[1]; | |
} | |
// create our steamclient instance | |
steamClient = new SteamClient(); | |
// get the steamuser handler, which is used for logging on after successfully connecting | |
steamUser = steamClient.GetHandler<SteamUser>(); | |
// get the steam friends handler, which is used for interacting with friends on the network after logging on | |
steamFriends = steamClient.GetHandler<SteamFriends>(); | |
isRunning = true; | |
Console.WriteLine("Connecting to Steam..."); | |
// initiate the connection | |
steamClient.Connect(); | |
// create our callback handling loop | |
while (isRunning) | |
{ | |
// wait for a callback to be posted | |
var callback = steamClient.WaitForCallback(true); | |
// handle the callback | |
// the Handle function will only call the passed in handler | |
// if the callback type matches the generic type | |
callback.Handle<SteamClient.ConnectedCallback>(c => | |
{ | |
if (c.Result != EResult.OK) | |
{ | |
Console.WriteLine("Unable to connect to Steam: {0}", c.Result); | |
isRunning = false; | |
return; | |
} | |
Console.WriteLine("Connected to Steam! Logging in '{0}'...", user); | |
steamUser.LogOn(new SteamUser.LogOnDetails | |
{ | |
Username = user, | |
Password = pass, | |
}); | |
}); | |
callback.Handle<SteamClient.DisconnectedCallback>(c => | |
{ | |
Console.WriteLine("Disconnected from Steam"); | |
isRunning = false; | |
}); | |
callback.Handle<SteamUser.LoggedOnCallback>(c => | |
{ | |
if (c.Result != EResult.OK) | |
{ | |
if (c.Result == EResult.AccountLogonDenied) | |
{ | |
// if we recieve AccountLogonDenied or one of it's flavors (AccountLogonDeniedNoMailSent, etc) | |
// then the account we're logging into is SteamGuard protected | |
// see sample 6 for how SteamGuard can be handled | |
Console.WriteLine("Unable to logon to Steam: This account is SteamGuard protected."); | |
isRunning = false; | |
return; | |
} | |
Console.WriteLine("Unable to logon to Steam: {0} / {1}", c.Result, c.ExtendedResult); | |
isRunning = false; | |
return; | |
} | |
Console.WriteLine("Successfully logged on!"); | |
// at this point, we'd be able to perform actions on Steam | |
steamFriends.SetPersonaState(EPersonaState.Online); | |
var ui = new ClientMsgProtobuf<CMsgClientUIMode>(EMsg.ClientCurrentUIMode); | |
ui.Body.uimode.Equals(1); | |
// steamkit doesn't expose the "play game" message through any handler, so we'll just send the message manually | |
var playGame = new ClientMsgProtobuf<CMsgClientGamesPlayed>(EMsg.ClientGamesPlayed); | |
playGame.Body.games_played.Add(new CMsgClientGamesPlayed.GamePlayed | |
{ | |
game_id = new GameID(570), | |
game_flags = 5120, | |
}); | |
Console.WriteLine("Sending UI state"); | |
// send it off | |
// notice here we're sending this message directly using the SteamClient | |
steamClient.Send(ui); | |
Console.WriteLine("Playing dota 2"); | |
// send it off | |
// notice here we're sending this message directly using the SteamClient | |
steamClient.Send(playGame); | |
//steamUser.LogOff(); | |
}); | |
callback.Handle<SteamUser.LoggedOffCallback>(c => | |
{ | |
Console.WriteLine("Logged off of Steam: {0}", c.Result); | |
}); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment