本文整理汇总了C#中CallbackManager.RunWaitCallbacks方法的典型用法代码示例。如果您正苦于以下问题:C# CallbackManager.RunWaitCallbacks方法的具体用法?C# CallbackManager.RunWaitCallbacks怎么用?C# CallbackManager.RunWaitCallbacks使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CallbackManager
的用法示例。
在下文中一共展示了CallbackManager.RunWaitCallbacks方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LogIn
static void LogIn()
{
steamClient = new SteamClient();
callbackManager = new CallbackManager(steamClient);
steamUser = steamClient.GetHandler<SteamUser>();
steamFriends = steamClient.GetHandler<SteamFriends>();
steamTrading = steamClient.GetHandler<SteamTrading>();
new Callback<SteamClient.ConnectedCallback>(OnConnect,callbackManager);
new Callback<SteamUser.LoggedOnCallback>(OnLoggedOn, callbackManager);
new Callback<SteamUser.UpdateMachineAuthCallback>(OnMachineAuth, callbackManager);
new Callback<SteamClient.DisconnectedCallback>(OnDisconnected, callbackManager);
new Callback<SteamUser.AccountInfoCallback>(OnAccountInfo, callbackManager);
new Callback<SteamFriends.FriendMsgCallback>(OnChatMessage, callbackManager);
new Callback<SteamFriends.FriendsListCallback>(OnFriendInvite, callbackManager);
new Callback<SteamTrading.TradeProposedCallback>(OnTradeOffer, callbackManager);
new Callback<SteamTrading.SessionStartCallback>(OnTradeWindow, callbackManager);
new Callback<SteamTrading.TradeResultCallback>(OnTradeResult, callbackManager);
isRunning = true;
Console.WriteLine("Attempting to connect to steam...");
steamClient.Connect();
while(isRunning)
{
callbackManager.RunWaitCallbacks(TimeSpan.FromSeconds(1));
}
Console.ReadKey();
}
示例2: Main
static void Main( string[] args )
{
if ( args.Length < 2 )
{
Console.WriteLine( "SendMessage: No username and password specified!" );
return;
}
// exit gracefully if possible
Console.CancelKeyPress += delegate(object sender, ConsoleCancelEventArgs e) {
e.Cancel = true;
isRunning = false;
};
var url = "http://localhost:3131";
var host = new NancyHost(new Uri(url));
host.Start();
Console.WriteLine ("Server now running on: " + url);
// save our logon details
user = args[ 0 ];
pass = args[ 1 ];
manager = new CallbackManager( Steam3.SteamClient );
new Callback<SteamClient.ConnectedCallback>( OnConnected, manager );
new Callback<SteamClient.DisconnectedCallback>( OnDisconnected, manager );
new Callback<SteamUser.LoggedOnCallback>( OnLoggedOn, manager );
new Callback<SteamUser.LoggedOffCallback>( OnLoggedOff, manager );
// we use the following callbacks for friends related activities
new Callback<SteamUser.AccountInfoCallback>( OnAccountInfo, manager );
new Callback<SteamFriends.FriendsListCallback>( OnFriendsList, manager );
new Callback<SteamFriends.PersonaStateCallback>( OnPersonaState, manager );
new Callback<SteamFriends.FriendAddedCallback>( OnFriendAdded, manager );
new Callback<SteamFriends.FriendMsgCallback>( OnMsgReceived, manager );
isRunning = true;
Console.WriteLine( "Connecting to Steam..." );
// initiate the connection
Steam3.SteamClient.Connect( false );
// 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 ) );
}
Console.WriteLine( "Disconnecting from Steam..." );
Steam3.SteamUser.LogOff();
Steam3.SteamClient.Disconnect();
host.Stop();
host.Stop();
}
示例3: Main
static void Main(string[] args) {
// Print program information.
Console.WriteLine("SteamIdler, 'run' games without steam.\n(C) No STEAMGUARD Support");
// Check for username and password arguments from stdin.
if (args.Length < 3) {
// Print usage and quit.
Console.WriteLine("usage: <username> <password> <appID> [...]");
return;
}
// Set username and password from stdin.
Username = args[0];
Password = args[1];
// Add all game application IDs to list.
foreach (string GameAppID in args) {
int AppID;
if (int.TryParse(GameAppID, out AppID)) {
AppIDs.Add(Convert.ToInt32(GameAppID));
}
}
// Create SteamClient interface and CallbackManager.
steamClient = new SteamClient(System.Net.Sockets.ProtocolType.Tcp);
manager = new CallbackManager(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>();
// Register Steam callbacks.
new Callback<SteamClient.ConnectedCallback>(OnConnected, manager);
new Callback<SteamClient.DisconnectedCallback>(OnDisconnected, manager);
new Callback<SteamUser.LoggedOnCallback>(OnLoggedOn, manager);
new Callback<SteamUser.LoggedOffCallback>(OnLoggedOff, manager);
new Callback<SteamUser.AccountInfoCallback>(OnAccountInfo, manager);
// Set the program as running.
Console.WriteLine(":: Connecting to Steam..");
isRunning = true;
// Connect to Steam.
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));
}
}
示例4: Main
static void Main(string[] args)
{
Logger.filename = "RelayBot.log";
log = Logger.GetLogger();
steamClient = new SteamClient(System.Net.Sockets.ProtocolType.Tcp);
manager = new CallbackManager(steamClient);
steamUser = steamClient.GetHandler<SteamUser>();
steamFriends = steamClient.GetHandler<SteamFriends>();
bot = new Bot(steamUser, steamFriends, steamClient);
manager.Subscribe<SteamClient.ConnectedCallback>(bot.OnConnected);
manager.Subscribe<SteamClient.DisconnectedCallback>(bot.OnDisconnected);
manager.Subscribe<SteamUser.LoggedOnCallback>(bot.OnLoggedOn);
manager.Subscribe<SteamUser.LoggedOffCallback>(bot.OnLoggedOff);
manager.Subscribe<SteamUser.AccountInfoCallback>(bot.OnAccountInfo);
manager.Subscribe<SteamFriends.FriendsListCallback>(bot.OnFriendsList);
manager.Subscribe<SteamFriends.FriendAddedCallback>(bot.OnFriendAdded);
manager.Subscribe<SteamFriends.ChatInviteCallback>(bot.OnChatInvite);
manager.Subscribe<SteamFriends.ChatEnterCallback>(bot.OnChatEnter);
manager.Subscribe<SteamFriends.FriendMsgCallback>(bot.OnFriendMessage);
manager.Subscribe<SteamFriends.ChatMsgCallback>(bot.OnChatroomMessage);
manager.Subscribe<SteamFriends.ChatMemberInfoCallback>(bot.OnMemberInfo);
manager.Subscribe<SteamUser.UpdateMachineAuthCallback>(bot.OnMachineAuth);
bot.isRunning = true;
log.Info("Connecting to Steam...");
steamClient.Connect();
//callback loop
while (bot.isRunning)
{
try
{
manager.RunWaitCallbacks(TimeSpan.FromSeconds(1));
}
catch (Exception e)
{
Logger.filename = "RelayBot.log";
log.Error(String.Format("Caught exception: {0}\nMessage: {1}\nStack trace: {2}", e.GetType().ToString(), e.Message, e.StackTrace));
}
}
}
示例5: Main
static void Main( string[] args )
{
if ( args.Length < 2 )
{
Console.WriteLine( "Sample9: 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 our steamapps handler, we'll use this as an example of how async jobs can be handled
steamApps = steamClient.GetHandler<SteamApps>();
// 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 );
// notice that we're not subscribing to the SteamApps.PICSProductInfoCallback callback here (or other SteamApps callbacks)
// since this sample is using the async job directly, we no longer need to subscribe to the callback.
// however, if we still wish to use callbacks (or have existing code which subscribes to callbacks, they will
// continue to operate alongside direct async job handling. (i.e.: steamclient will still post callbacks for
// any async jobs that are completed)
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 ) );
}
}
示例6: Main
static void Main( string[] args )
{
if ( args.Length < 2 )
{
Console.WriteLine( "Sample3: No username and password specified!" );
return;
}
// save our logon details
user = args[ 0 ];
pass = args[ 1 ];
// create our steamclient instance
steamClient = new SteamClient();
// add our custom handler to our steamclient
steamClient.AddHandler( new MyHandler() );
// 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>();
// now get an instance of our custom handler
myHandler = steamClient.GetHandler<MyHandler>();
// 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
new Callback<SteamClient.ConnectedCallback>( OnConnected, manager );
new Callback<SteamClient.DisconnectedCallback>( OnDisconnected, manager );
new Callback<SteamUser.LoggedOnCallback>( OnLoggedOn, manager );
new Callback<SteamUser.LoggedOffCallback>( OnLoggedOff, manager );
// handle our own custom callback
new Callback<MyHandler.MyCallback>( OnMyCallback, manager );
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 ) );
}
}
示例7: Main
static void Main( string[] args )
{
if ( args.Length < 2 )
{
Console.WriteLine( "Sample5: No username and password specified!" );
return;
}
// save our logon details
user = args[ 0 ];
pass = args[ 1 ];
// create our steamclient instance
steamClient = new SteamClient( System.Net.Sockets.ProtocolType.Tcp );
// 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 friends handler, which is used for interacting with friends on the network after logging on
steamFriends = steamClient.GetHandler<SteamFriends>();
// 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
new Callback<SteamClient.ConnectedCallback>( OnConnected, manager );
new Callback<SteamClient.DisconnectedCallback>( OnDisconnected, manager );
new Callback<SteamUser.LoggedOnCallback>( OnLoggedOn, manager );
new Callback<SteamUser.LoggedOffCallback>( OnLoggedOff, manager );
// we use the following callbacks for friends related activities
new Callback<SteamUser.AccountInfoCallback>( OnAccountInfo, manager );
new Callback<SteamFriends.FriendsListCallback>( OnFriendsList, manager );
new Callback<SteamFriends.PersonaStateCallback>( OnPersonaState, manager );
new Callback<SteamFriends.FriendAddedCallback>( OnFriendAdded, manager );
isRunning = true;
Console.WriteLine( "Connecting to Steam..." );
// initiate the connection
steamClient.Connect( false );
// 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 ) );
}
}
示例8: Main
public static void Main()
{
Log.WriteInfo("Program", "Starting...");
Console.CancelKeyPress += delegate
{
Log.WriteInfo("Program", "Exiting...");
try
{
Client.Disconnect();
}
catch
{
Log.WriteError("Steam", "Failed to disconnect from Steam");
}
IsRunning = false;
};
TwitterToken = new Token(
ConfigurationManager.AppSettings["token_AccessToken"],
ConfigurationManager.AppSettings["token_AccessTokenSecret"],
ConfigurationManager.AppSettings["token_ConsumerKey"],
ConfigurationManager.AppSettings["token_ConsumerSecret"]
);
ITokenRateLimits tokenLimits = TwitterToken.GetRateLimit();
Log.WriteInfo("Twitter", "Remaining Twitter requests: {0} of {1}", tokenLimits.ApplicationRateLimitStatusLimit.Remaining, tokenLimits.ApplicationRateLimitStatusLimit.Limit);
Timer.Elapsed += OnTimer;
Timer.Interval = TimeSpan.FromMinutes(10).TotalMilliseconds;
var CallbackManager = new CallbackManager(Client);
CallbackManager.Register(new Callback<SteamClient.ConnectedCallback>(OnConnected));
CallbackManager.Register(new Callback<SteamClient.DisconnectedCallback>(OnDisconnected));
CallbackManager.Register(new Callback<SteamUser.LoggedOnCallback>(OnLoggedOn));
CallbackManager.Register(new Callback<SteamUser.LoggedOffCallback>(OnLoggedOff));
CallbackManager.Register(new Callback<SteamUser.AccountInfoCallback>(OnAccountInfo));
CallbackManager.Register(new Callback<SteamFriends.ClanStateCallback>(OnClanState));
Client.Connect();
while (IsRunning)
{
CallbackManager.RunWaitCallbacks(TimeSpan.FromSeconds(5));
}
}
示例9: Enter_
// static string toptlb;
// public static string steamgg(string code)
// {
// return code;
// }
public static void Enter_(string us, string pa, ToolStripLabel tlb_)
{
user = us;
pass = pa;
tlb = tlb_;
if ((user.Length < 2) || (pass.Length < 2))
{
tlb.Text = "No username and password specified!";
return;
}
// 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>();
// 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);
// this callback is triggered when the steam servers wish for the client to store the sentry file
//manager.Subscribe<SteamUser.UpdateMachineAuthCallback>(OnMachineAuth);
isRunning = true;
tlb.Text = "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));
}
}
示例10: StartSteam
public ECheckResult StartSteam()
{
_steamClient = new SteamClient();
_manager = new CallbackManager(_steamClient);
_steamUser = _steamClient.GetHandler<SteamUser>();
_manager.Subscribe<SteamClient.ConnectedCallback>(OnConnected);
_manager.Subscribe<SteamClient.DisconnectedCallback>(OnDisconnected);
_manager.Subscribe<SteamUser.LoggedOnCallback>(OnLoggedOn);
_manager.Subscribe<SteamUser.UpdateMachineAuthCallback>(OnMachineAuth);
_isRunning = true;
_steamClient.Connect();
while (_isRunning)
_manager.RunWaitCallbacks(TimeSpan.FromSeconds(1));
if (_operation == EOperationType.CreateSentry)
Thread.Sleep(500);
_steamClient.Disconnect();
return _checkResult;
}
示例11: Main
static void Main(string[] args)
{
Console.Title = "Noah-Bawt";
user = "";
pass = "";
steamClient = new SteamClient(System.Net.Sockets.ProtocolType.Tcp);
manager = new CallbackManager(steamClient);
steamUser = steamClient.GetHandler<SteamUser>();
steamFriends = steamClient.GetHandler<SteamFriends>();
new Callback<SteamClient.ConnectedCallback>(OnConnected, manager);
new Callback<SteamClient.DisconnectedCallback>(OnDisconnected, manager);
new Callback<SteamUser.LoggedOnCallback>(OnLoggedOn, manager);
new Callback<SteamUser.LoggedOffCallback>(OnLoggedOff, manager);
new Callback<SteamUser.AccountInfoCallback>(OnAccountInfo, manager);
new Callback<SteamFriends.FriendsListCallback>(OnFriendsList, manager);
new Callback<SteamFriends.PersonaStateCallback>(OnPersonaState, manager);
new Callback<SteamFriends.FriendAddedCallback>(OnFriendAdded, manager);
new Callback<SteamFriends.ChatEnterCallback>(OnChatEnter, manager);
new Callback<SteamFriends.ChatMsgCallback>(OnChatMsgRecieved, manager);
lastcmd = DateTime.Now;
isRunning = true;
Console.WriteLine("Connecting...");
steamClient.Connect();
while (isRunning)
{
manager.RunWaitCallbacks(TimeSpan.FromSeconds(1));
}
}
示例12: Connect
//.........这里部分代码省略.........
{
Username = this.Username,
Password = this.Password,
SentryFileHash = this.Sentry,
});
}
else
{
Trace.TraceError("Unable to connect to Steam");
throw new Exception("Failed to Connect");
}
});
cbManager.Subscribe<SteamClient.DisconnectedCallback>((SteamClient.DisconnectedCallback callback) => {
cancellationToken.ThrowIfCancellationRequested();
Trace.TraceInformation("Disconnected from Steam.");
if (autoReconect)
{
// delay a little to give steam some time to finalize the DC
Thread.Sleep(TimeSpan.FromSeconds(1));
// reconect
this.SteamClient.Connect();
}
});
cbManager.Subscribe<SteamUser.LoggedOnCallback>((SteamUser.LoggedOnCallback callback) => {
cancellationToken.ThrowIfCancellationRequested();
if (callback.Result == EResult.OK)
{
Trace.TraceInformation("Successfully logged on!");
// we've logged into the account
// now we need to inform the steam server that we're playing dota (in order to receive GC messages)
// steamkit doesn't expose the "play game" message through any handler, so we'll just send the message manually
var gameMsg = new ClientMsgProtobuf<CMsgClientGamesPlayed>(EMsg.ClientGamesPlayed);
gameMsg.Body.games_played.Add(new CMsgClientGamesPlayed.GamePlayed
{
game_id = new GameID(APPID), // or game_id = APPID,
});
// send it off - notice here we're sending this message directly using the SteamClient
this.SteamClient.Send(gameMsg);
// delay a little to give steam some time to establish a GC connection to us
Thread.Sleep(TimeSpan.FromSeconds(1));
// inform the dota GC that we want a session
var helloMsg = new ClientGCMsgProtobuf<CMsgClientHello>((uint)EGCBaseClientMsg.k_EMsgGCClientHello);
helloMsg.Body.engine = ESourceEngine.k_ESE_Source2;
gcHandler.Send(helloMsg, APPID);
}
else if (callback.Result == EResult.AccountLogonDenied)
{
Trace.TraceInformation("Account {0}@{1} is denied.", this.Username, callback.EmailDomain);
throw new Exception(string.Format("Account {0}@{1} is denied.", this.Username, callback.EmailDomain));
}
else
{
Trace.TraceError("Failed to Login; Result {0}", callback.Result);
throw new Exception("Failed to Login.");
}
});
cbManager.Subscribe<SteamGameCoordinator.MessageCallback>((SteamGameCoordinator.MessageCallback callback) =>
{
cancellationToken.ThrowIfCancellationRequested();
if (callback.EMsg == (uint)EGCBaseClientMsg.k_EMsgGCClientWelcome)
{
var msg = new ClientGCMsgProtobuf<CMsgClientWelcome>(callback.Message);
version = msg.Body.version;
Trace.TraceInformation("GC - Welcome Message");
completed = true;
}
});
// initiate the connection
SteamClient.Connect();
while(completed == false)
{
cancellationToken.ThrowIfCancellationRequested();
// in order for the callbacks to get routed, they need to be handled by the manager
cbManager.RunWaitCallbacks(TimeSpan.FromSeconds(1));
}
return version;
});
}
示例13: DownloadReplay
public async Task<byte[]> DownloadReplay(ulong matchId, CancellationToken cancellationToken)
{
return await Task.Run<byte[]>(async () =>
{
CMsgDOTAMatch matchDetails = null;
// get the GC handler, which is used for messaging DOTA
var gcHandler = this.SteamClient.GetHandler<SteamGameCoordinator>();
// register a few callbacks we're interested in
var cbManager = new CallbackManager(this.SteamClient);
var sub = cbManager.Subscribe<SteamGameCoordinator.MessageCallback>((SteamGameCoordinator.MessageCallback callback) =>
{
cancellationToken.ThrowIfCancellationRequested();
if (callback.EMsg == (uint)EDOTAGCMsg.k_EMsgGCMatchDetailsResponse)
{
var msg = new ClientGCMsgProtobuf<CMsgGCMatchDetailsResponse>(callback.Message);
matchDetails = msg.Body.match;
}
});
// Send Request
var request = new ClientGCMsgProtobuf<CMsgGCMatchDetailsRequest>((uint)EDOTAGCMsg.k_EMsgGCMatchDetailsRequest);
request.Body.match_id = matchId;
gcHandler.Send(request, APPID);
while (matchDetails == null)
{
cancellationToken.ThrowIfCancellationRequested();
// in order for the callbacks to get routed, they need to be handled by the manager
cbManager.RunWaitCallbacks(TimeSpan.FromSeconds(1));
}
var url = string.Format("http://replay{0}.valve.net/{1}/{2}_{3}.dem.bz2", matchDetails.cluster, APPID, matchDetails.match_id, matchDetails.replay_salt);
var webClient = new WebClient();
var compressedMatchData = await webClient.DownloadDataTaskAsync(url);
var uncompressedMatchData = CompressionFactory.BZip2.Decompress(compressedMatchData);
return uncompressedMatchData;
});
}
示例14: Main
static void Main(string[] args)
{
Console.WriteLine("Steam Trading Card Farmer\n");
if (!STCFNet.CheckForInternetConnection())
{
STCFNet.WriteError("No internet connection!");
}
Console.WriteLine("Username:");
user = Console.ReadLine();
Console.WriteLine("Password:");
pass = Console.ReadLine();
steamClient = new SteamClient();
manager = new CallbackManager(steamClient);
steamUser = steamClient.GetHandler<SteamUser>();
steamFriends = steamClient.GetHandler<SteamFriends>();
new Callback<SteamClient.ConnectedCallback>(OnConnected, manager);
new Callback<SteamClient.DisconnectedCallback>(OnDisconnected, manager);
new Callback<SteamUser.LoggedOnCallback>(OnLoggedOn, manager);
new Callback<SteamUser.LoggedOffCallback>(OnLoggedOff, manager);
new JobCallback<SteamUser.UpdateMachineAuthCallback>(OnMachineAuth, manager);
isRunning = true;
STCFNet.WriteInfo("Connecting to Steam...");
steamClient.Connect();
steamFriends.SetPersonaState(EPersonaState.Online);
while (isRunning)
{
manager.RunWaitCallbacks(TimeSpan.FromSeconds(1));
}
}
示例15: Main
static void Main( string[] args )
{
if ( args.Length < 2 )
{
Console.WriteLine( "Sample7: 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>();
// 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 );
Console.CancelKeyPress += ( s, e ) =>
{
e.Cancel = true;
Console.WriteLine( "Received {0}, disconnecting...", e.SpecialKey );
steamUser.LogOff();
};
var cellid = 0u;
// if we've previously connected and saved our cellid, load it.
if ( File.Exists( "cellid.txt" ) )
{
if ( !uint.TryParse( File.ReadAllText( "cellid.txt"), out cellid ) )
{
Console.WriteLine( "Error parsing cellid from cellid.txt. Continuing with cellid 0." );
}
else
{
Console.WriteLine( $"Using persisted cell ID {cellid}" );
}
}
SteamClient.Servers.CellID = cellid;
SteamClient.Servers.ServerListProvider = new FileStorageServerListProvider("servers_list.bin");
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 ) );
}
}