本文整理汇总了C#中SteamClient.WaitForCallback方法的典型用法代码示例。如果您正苦于以下问题:C# SteamClient.WaitForCallback方法的具体用法?C# SteamClient.WaitForCallback怎么用?C# SteamClient.WaitForCallback使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SteamClient
的用法示例。
在下文中一共展示了SteamClient.WaitForCallback方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Bot
public Bot(Configuration.BotInfo config, string apiKey, bool debug = false)
{
Username = config.Username;
Password = config.Password;
DisplayName = config.DisplayName;
ChatResponse = config.ChatResponse;
Admins = config.Admins;
this.apiKey = apiKey;
AuthCode = null;
TradeListener = new TradeEnterTradeListener(this);
// Hacking around https
ServicePointManager.ServerCertificateValidationCallback += SteamWeb.ValidateRemoteCertificate;
SteamClient = new SteamClient();
SteamTrade = SteamClient.GetHandler<SteamTrading>();
SteamUser = SteamClient.GetHandler<SteamUser>();
SteamFriends = SteamClient.GetHandler<SteamFriends>();
SteamClient.Connect();
Thread CallbackThread = new Thread(() => // Callback Handling
{
while (true)
{
CallbackMsg msg = SteamClient.WaitForCallback (true);
HandleSteamMessage (msg);
}
});
new Thread(() => // Trade Polling if needed
{
while (true)
{
Thread.Sleep (800);
if (CurrentTrade != null)
{
try
{
CurrentTrade.Poll ();
}
catch (Exception e)
{
Console.Write ("Error polling the trade: ");
Console.WriteLine (e);
}
}
}
}).Start ();
CallbackThread.Start();
CallbackThread.Join();
}
示例2: Bot
public Bot(Configuration.BotInfo config, string apiKey, UserHandlerCreator handlerCreator, bool debug = false)
{
Username = config.Username;
Password = config.Password;
DisplayName = config.DisplayName;
ChatResponse = config.ChatResponse;
MaximumTradeTime = config.MaximumTradeTime;
MaximiumActionGap = config.MaximumActionGap;
DisplayNamePrefix = config.DisplayNamePrefix;
TradePollingInterval = config.TradePollingInterval <= 100 ? 800 : config.TradePollingInterval;
Admins = config.Admins;
this.apiKey = apiKey;
AuthCode = null;
try
{
LogLevel = (Log.LogLevel)Enum.Parse(typeof(Log.LogLevel), config.LogLevel, true);
}
catch (ArgumentException)
{
Console.WriteLine("Invalid LogLevel provided in configuration. Defaulting to 'INFO'");
LogLevel = Log.LogLevel.Info;
}
log = new Log (config.LogFile, this.DisplayName, LogLevel);
CreateHandler = handlerCreator;
// Hacking around https
ServicePointManager.ServerCertificateValidationCallback += SteamWeb.ValidateRemoteCertificate;
log.Debug ("Initializing Steam Bot...");
SteamClient = new SteamClient();
SteamTrade = SteamClient.GetHandler<SteamTrading>();
SteamUser = SteamClient.GetHandler<SteamUser>();
SteamFriends = SteamClient.GetHandler<SteamFriends>();
log.Info ("Connecting...");
SteamClient.Connect();
Thread CallbackThread = new Thread(() => // Callback Handling
{
while (true)
{
CallbackMsg msg = SteamClient.WaitForCallback (true);
HandleSteamMessage (msg);
}
});
new Thread(() => // Trade Polling if needed
{
while (true)
{
Thread.Sleep (TradePollingInterval);
if (CurrentTrade != null)
{
try
{
CurrentTrade.Poll ();
if (CurrentTrade.OtherUserCancelled)
{
log.Info("Other user cancelled the trade.");
CurrentTrade = null;
}
}
catch (Exception e)
{
log.Error ("Error Polling Trade: " + e);
// ok then we should stop polling...
CurrentTrade = null;
}
}
}
}).Start ();
CallbackThread.Start();
log.Success ("Done Loading Bot!");
CallbackThread.Join();
}
示例3: Bot
public Bot(Configuration.BotInfo config, string apiKey, UserHandlerCreator handlerCreator, bool debug = false)
{
Username = config.Username;
Password = config.Password;
DisplayName = config.DisplayName;
ChatResponse = config.ChatResponse;
MaximumTradeTime = config.MaximumTradeTime;
MaximiumActionGap = config.MaximumActionGap;
DisplayNamePrefix = config.DisplayNamePrefix;
TradePollingInterval = config.TradePollingInterval <= 100 ? 800 : config.TradePollingInterval;
Admins = config.Admins;
this.apiKey = apiKey;
AuthCode = null;
log = new Log (config.LogFile, this);
CreateHandler = handlerCreator;
// Hacking around https
ServicePointManager.ServerCertificateValidationCallback += SteamWeb.ValidateRemoteCertificate;
log.Debug ("Initializing Steam Bot...");
SteamClient = new SteamClient();
SteamTrade = SteamClient.GetHandler<SteamTrading>();
SteamUser = SteamClient.GetHandler<SteamUser>();
SteamFriends = SteamClient.GetHandler<SteamFriends>();
log.Info ("Connecting...");
SteamClient.Connect();
Thread CallbackThread = new Thread(() => // Callback Handling
{
while (true)
{
CallbackMsg msg = SteamClient.WaitForCallback (true);
HandleSteamMessage (msg);
}
});
new Thread(() => // Trade Polling if needed
{
while (true)
{
Thread.Sleep (TradePollingInterval);
if (CurrentTrade != null)
{
try
{
CurrentTrade.Poll ();
}
catch (Exception e)
{
log.Error ("Error Polling Trade: " + e);
}
}
}
}).Start ();
CallbackThread.Start();
log.Success ("Done Loading Bot!");
CallbackThread.Join();
}
示例4: Main
static void Main(string[] args)
{
// TODO: Add check for instance already running
//login info
string userID = ConfigurationManager.AppSettings["userID"];
string userPW = ConfigurationManager.AppSettings["userPW"];
string botName = ConfigurationManager.AppSettings["botName"];
List<SteamID> chatRooms = new List<SteamID>();
ulong chatSteamID;
if (ulong.TryParse(ConfigurationManager.AppSettings["chatSteamID"], out chatSteamID))
{
//List of Chats to join
// TODO: multiple chatrooms
chatRooms.Add(chatSteamID);
}
else
{
Console.WriteLine("Exit Code 10: Failed to Load SteamID");
Environment.Exit(10);
}
//Initiliaze Steam Client
SteamClient steamClient = new SteamClient();
SteamUser steamUsr = steamClient.GetHandler<SteamUser>();
SteamFriends steamFrds = steamClient.GetHandler<SteamFriends>();
//Connect to Steam Network
steamClient.Connect();
while (true)
{
// start listening
CallbackMsg msg = steamClient.WaitForCallback(true);
msg.Handle<SteamClient.ConnectedCallback>(callback =>
{
if (callback.Result != EResult.OK)
{
Console.WriteLine("Exit Code 1: Failed to Connect to Steam Network - " + callback.Result.ToString());
Environment.Exit(1);
// connect fail
}
else
{
Console.WriteLine("Connected to Steam Network");
steamUsr.LogOn(new SteamUser.LogOnDetails
{
Username = userID,
Password = userPW,
});
}
});
msg.Handle<SteamUser.LoggedOnCallback>(callback =>
{
if (callback.Result != EResult.OK)
{
Console.WriteLine("Exit Code 2: Logon Failure - " + callback.Result.ToString());
//Environment.Exit(2);
// logon fail
}
else
{
Console.WriteLine("Logged into Steam Network");
// Join Chat
// if you set PersonaState without setting PersonaName it goes to [unknown] and GetPersonaName doesn't work?
//steamFrds.SetPersonaName(steamFrds.GetPersonaName());
steamFrds.SetPersonaName(botName);
steamFrds.SetPersonaState(EPersonaState.Online);
foreach (SteamID steamID in chatRooms)
{
steamFrds.JoinChat(steamID);
}
}
});
msg.Handle<SteamFriends.ChatEnterCallback>(callback =>
{
if (callback.EnterResponse != EChatRoomEnterResponse.Success)
{
Console.WriteLine("Exit Code 3: Failure to Enter Chat" + callback.EnterResponse.ToString());
//Environment.Exit(3);
// join chat fail
}
else
{
Console.WriteLine("Joined Chat");
foreach (SteamID steamID in chatRooms)
{
steamFrds.SendChatRoomMessage(steamID, EChatEntryType.ChatMsg, "Now listening");
}
}
});
//.........这里部分代码省略.........
示例5: Main
static void Main(string[] args)
{
Console.ForegroundColor = ConsoleColor.DarkCyan;
System.Console.Title = "TradeBot";
System.Console.WriteLine("Welcome to TradeBot!\nCreated by Jessecar.\nTurn of Steam Guard before loggin in!\n\n");
Console.ForegroundColor = ConsoleColor.White;
printConsole("Steam Username:");
String username = "jessecar96"; //Console.ReadLine();
System.Console.WriteLine("Steam Password: ");
//heckey
Console.ForegroundColor = Console.BackgroundColor;
String password = Console.ReadLine();
Console.ForegroundColor = ConsoleColor.White;
SteamClient steamClient = new SteamClient(); // initialize our client
SteamUser steamUser = steamClient.GetHandler<SteamUser>();
steamFriends = steamClient.GetHandler<SteamFriends>();
SteamTrading trade = steamClient.GetHandler<SteamTrading>();
steamClient.Connect(); // connect to the steam network
while (true)
{
if (Console.KeyAvailable)
{
printConsole(Console.ReadLine(), ConsoleColor.Yellow);
}
CallbackMsg msg = steamClient.WaitForCallback(true); // block and wait until a callback is posted
//Print out callbacks
//printConsole(msg.ToString());
//Steam Connection
msg.Handle<SteamClient.ConnectedCallback>(callback =>
{
if (callback.Result != EResult.OK)
{
printConsole("Sorry, could not connect to Steam.");
}
steamUser.LogOn(new SteamUser.LogOnDetails
{
Username = username,
Password = password,
});
});
//Login Callback
msg.Handle<SteamUser.LoggedOnCallback>(callback =>
{
if (callback.Result != EResult.OK)
{
printConsole("Incorrect username or Password. Make sure you have disabled steam guard!");
}
else
{
printConsole("Connected to Steam!\nWelcome "+steamUser.SteamID);
steamFriends.SetPersonaName("ChatBot Beta (Say hi)");
steamFriends.SetPersonaState((EPersonaState)6);
}
});
//Chat Messages
msg.Handle<SteamFriends.FriendMsgCallback>(callback =>
{
EChatEntryType type = callback.EntryType;
if (type == EChatEntryType.ChatMsg)
{
SteamID sid = callback.Sender;
if (!clients.Contains(callback.Sender))
{
printConsole("[New Client]" + callback.Sender, ConsoleColor.Magenta);
clients.Add(callback.Sender);
steamFriends.SendChatMessage(callback.Sender, EChatEntryType.ChatMsg, "Welcome to TradeBot created by Jessecar. To see a list of commands type /help");
}
if (callback.Message.StartsWith("/"))
{
string message = callback.Message.Replace("/", "");
//.........这里部分代码省略.........
示例6: Bot
public Bot(Configuration.BotInfo config, Log log, string apiKey, UserHandlerCreator handlerCreator, Login _login, bool debug = false)
{
this.main = _login;
logOnDetails = new SteamUser.LogOnDetails
{
Username = _login.Username,
Password = _login.Password
};
ChatResponse = "";
TradePollingInterval = 500;
Admins = new ulong[1];
Admins[0] = 0;
this.apiKey = apiKey;
try
{
LogLevel = (Log.LogLevel)Enum.Parse(typeof(Log.LogLevel), "Debug", true);
}
catch (ArgumentException)
{
Console.WriteLine("Invalid LogLevel provided in configuration. Defaulting to 'INFO'");
LogLevel = Log.LogLevel.Info;
}
this.log = log;
CreateHandler = handlerCreator;
BotControlClass = "SteamBot.SimpleUserHandler";
// Hacking around https
ServicePointManager.ServerCertificateValidationCallback += SteamWeb.ValidateRemoteCertificate;
log.Debug ("Initializing Steam account...");
main.Invoke((Action)(() =>
{
main.label_status.Text = "Initializing Steam account...";
}));
SteamClient = new SteamClient();
SteamClient.AddHandler(new ClientPlayerNicknameListHandler());
SteamTrade = SteamClient.GetHandler<SteamTrading>();
SteamUser = SteamClient.GetHandler<SteamUser>();
SteamFriends = SteamClient.GetHandler<SteamFriends>();
SteamGameCoordinator = SteamClient.GetHandler<SteamGameCoordinator>();
SteamNicknames = SteamClient.GetHandler<ClientPlayerNicknameListHandler>();
log.Info ("Connecting...");
main.Invoke((Action)(() =>
{
main.label_status.Text = "Connecting to Steam...";
}));
SteamClient.Connect();
Thread CallbackThread = new Thread(() => // Callback Handling
{
while (true)
{
CallbackMsg msg = SteamClient.WaitForCallback(true);
new Thread(() => HandleSteamMessage(msg)).Start();
}
});
CallbackThread.Start();
CallbackThread.Join();
log.Success("Done loading account!");
main.Invoke((Action)(() =>
{
main.label_status.Text = "Done loading account!";
}));
}
示例7: Main
static void Main( string[] args )
{
if ( args.Length < 2 )
{
Console.WriteLine( "Sample1: No username and password specified!" );
return;
}
// 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>();
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
// for this sample we'll just log off
steamUser.LogOff();
} );
callback.Handle<SteamUser.LoggedOffCallback>( c =>
{
Console.WriteLine( "Logged off of Steam: {0}", c.Result );
} );
}
}
示例8: Bot
public Bot(Configuration.BotInfo config, string apiKey, UserHandlerCreator handlerCreator, Interface gui, bool debug = false)
{
while (Interface.loginClicked == false)
{
// Wait for user to login
}
logOnDetails = new SteamUser.LogOnDetails
{
Username = Interface.username,
Password = Interface.password
};
Admins = new ulong[1];
Admins[0] = 123456789;
this.apiKey = apiKey;
LogLevel = Log.LogLevel.Info;
//log = new Log(config.LogFile, this.DisplayName, LogLevel);
CreateHandler = handlerCreator;
BotControlClass = config.BotControlClass;
// Hacking around https
ServicePointManager.ServerCertificateValidationCallback += SteamWeb.ValidateRemoteCertificate;
////log.Debug("Initializing Steam Bot...");
SteamClient = new SteamClient();
SteamTrade = SteamClient.GetHandler<SteamTrading>();
SteamUser = SteamClient.GetHandler<SteamUser>();
SteamFriends = SteamClient.GetHandler<SteamFriends>();
gui.UpdateLog("\r\nConnecting, please wait...");
////log.Info("Connecting...");
SteamClient.Connect();
Thread CallbackThread = new Thread(() => // Callback Handling
{
while (true)
{
CallbackMsg msg = SteamClient.WaitForCallback(true);
HandleSteamMessage(msg, gui);
}
});
CallbackThread.Start();
////log.Success("Done Loading Bot!");
CallbackThread.Join();
}
示例9: Bot
public Bot(Configuration.BotInfo config, string apiKey, UserHandlerCreator handlerCreator, bool debug = false)
{
logOnDetails = new SteamUser.LogOnDetails
{
Username = config.Username,
Password = config.Password
};
DisplayName = config.DisplayName;
ChatResponse = config.ChatResponse;
MaximumTradeTime = config.MaximumTradeTime;
MaximiumActionGap = config.MaximumActionGap;
DisplayNamePrefix = config.DisplayNamePrefix;
TradePollingInterval = config.TradePollingInterval <= 100 ? 800 : config.TradePollingInterval;
Admins = config.Admins;
this.apiKey = apiKey;
try
{
LogLevel = (Log.LogLevel)Enum.Parse(typeof(Log.LogLevel), config.LogLevel, true);
}
catch (ArgumentException)
{
Console.WriteLine("Invalid LogLevel provided in configuration. Defaulting to 'INFO'");
LogLevel = Log.LogLevel.Info;
}
log = new Log (config.LogFile, this.DisplayName, LogLevel);
CreateHandler = handlerCreator;
BotControlClass = config.BotControlClass;
// Hacking around https
ServicePointManager.ServerCertificateValidationCallback += SteamWeb.ValidateRemoteCertificate;
log.Debug ("Initializing Steam Bot...");
SteamClient = new SteamClient();
SteamTrade = SteamClient.GetHandler<SteamTrading>();
SteamUser = SteamClient.GetHandler<SteamUser>();
SteamFriends = SteamClient.GetHandler<SteamFriends>();
log.Info ("Connecting...");
SteamClient.Connect();
Thread CallbackThread = new Thread(() => // Callback Handling
{
while (true)
{
CallbackMsg msg = SteamClient.WaitForCallback (true);
HandleSteamMessage (msg);
}
});
CallbackThread.Start();
log.Success ("Done Loading Bot!");
CallbackThread.Join();
}
示例10: Main
static void Main(string[] args)
{
bool firstProc;
using (Mutex ChewieMutex = new Mutex
(
true,
"Chewiebot_77eef519388125870654f396ffdc9041",
out firstProc
))
{
if (firstProc)
{
//login info
string userID = ConfigurationManager.AppSettings["userID"];
string userPW = ConfigurationManager.AppSettings["userPW"];
string botName = ConfigurationManager.AppSettings["botName"];
List<SteamID> chatRooms = new List<SteamID>();
ulong chatSteamID;
if (ulong.TryParse(ConfigurationManager.AppSettings["chatSteamID"], out chatSteamID))
{
//List of Chats to join
// TODO: multiple chatrooms
SteamID sID = new SteamID(chatSteamID);
chatRooms.Add(sID);
}
else
{
Console.WriteLine("Exit Code 10: Failed to Load SteamID");
Environment.Exit(10);
}
//Initiliaze Steam Client
SteamClient steamClient = new SteamClient();
SteamUser steamUsr = steamClient.GetHandler<SteamUser>();
SteamFriends steamFrds = steamClient.GetHandler<SteamFriends>();
//Connect to Steam Network
steamClient.Connect();
while (true)
{
// start listening
CallbackMsg msg = steamClient.WaitForCallback(true);
msg.Handle<SteamClient.ConnectedCallback>(callback =>
{
if (callback.Result != EResult.OK)
{
Console.WriteLine("Exit Code 1: Failed to Connect to Steam Network - " + callback.Result.ToString());
Environment.Exit(1);
// connect fail
}
else
{
Console.WriteLine("Connected to Steam Network");
steamUsr.LogOn(new SteamUser.LogOnDetails
{
Username = userID,
Password = userPW,
});
}
});
msg.Handle<SteamUser.LoggedOnCallback>(callback =>
{
if (callback.Result != EResult.OK)
{
Console.WriteLine("Exit Code 2: Logon Failure - " + callback.Result.ToString());
//Environment.Exit(2);
// logon fail
}
else
{
Console.WriteLine("Logged into Steam Network");
// Join Chat
// if you set PersonaState without setting PersonaName it goes to [unknown] and GetPersonaName doesn't work?
//steamFrds.SetPersonaName(steamFrds.GetPersonaName());
steamFrds.SetPersonaName(botName);
steamFrds.SetPersonaState(EPersonaState.Online);
foreach (SteamID steamID in chatRooms)
{
steamFrds.JoinChat(steamID);
}
}
});
msg.Handle<SteamFriends.ChatEnterCallback>(callback =>
{
if (callback.EnterResponse != EChatRoomEnterResponse.Success)
{
Console.WriteLine("Exit Code 3: Failure to Enter Chat" + callback.EnterResponse.ToString());
//Environment.Exit(3);
// join chat fail
}
//.........这里部分代码省略.........
示例11: Main
public static void Main (string[] args)
{
#region SteamRE Init
AllArgs = args;
//Hacking around https
ServicePointManager.CertificatePolicy = new MainClass ();
Console.ForegroundColor = ConsoleColor.Magenta;
Console.WriteLine ("\n\tSteamBot Beta\n\tCreated by Jessecar96.\n\n");
Console.ForegroundColor = ConsoleColor.White;
steamClient = new SteamClient ();
steamTrade = steamClient.GetHandler<SteamTrading>();
SteamUser steamUser = steamClient.GetHandler<SteamUser> ();
steamFriends = steamClient.GetHandler<SteamFriends>();
steamClient.Connect ();
#endregion
while (true) {
CallbackMsg msg = steamClient.WaitForCallback (true);
//Console Debug
printConsole (msg.ToString(),ConsoleColor.Blue,true);
#region Logged Off Handler
msg.Handle<SteamUser.LoggedOffCallback> (callback =>
{
printConsole("Logged Off: "+callback.Result,ConsoleColor.Red);
});
#endregion
#region Steam Disconnect Handler
msg.Handle<SteamClient.DisconnectedCallback> (callback =>
{
printConsole("Disconnected.",ConsoleColor.Red);
});
#endregion
#region Steam Connect Handler
/**
* --Steam Connection Callback
*
* It's not needed to modify this section
*/
msg.Handle<SteamClient.ConnectedCallback> (callback =>
{
//Print Callback
printConsole("Steam Connected Callback: "+callback.Result, ConsoleColor.Cyan);
//Validate Result
if(callback.Result==EResult.OK){
//Get Steam Login Details
printConsole("Username: ",ConsoleColor.Cyan);
string user = Console.ReadLine();
printConsole("Password: ",ConsoleColor.Cyan);
Console.ForegroundColor = ConsoleColor.Black;
string pass = Console.ReadLine();
Console.ForegroundColor = ConsoleColor.White;
printConsole("Getting Web Cookies...",ConsoleColor.Yellow);
//Get Web Cookies
SteamWeb web = new SteamWeb();
WebCookies = web.DoLogin (user,pass);
if(WebCookies!=null){
printConsole ("SteamWeb Cookies retrived.",ConsoleColor.Green);
//Do Login
steamUser.LogOn (new SteamUser.LogOnDetails{
Username = user,
Password = pass
});
}else{
printConsole ("Error while getting SteamWeb Cookies.",ConsoleColor.Red);
}
}else{
//Failure
printConsole ("Failed to Connect to steam.",ConsoleColor.Red);
}
});
#endregion
#region Steam Login Handler
//Logged in (or not)
//.........这里部分代码省略.........
示例12: Bot
public Bot(Configuration.BotInfo config, string apiKey, UserHandlerCreator handlerCreator, bool debug = false)
{
logOnDetails = new SteamUser.LogOnDetails
{
Username = config.Username,
Password = config.Password
};
DisplayName = config.DisplayName;
ChatResponse = config.ChatResponse;
MaximumTradeTime = config.MaximumTradeTime;
MaximiumActionGap = config.MaximumActionGap;
DisplayNamePrefix = config.DisplayNamePrefix;
TradePollingInterval = config.TradePollingInterval <= 100 ? 800 : config.TradePollingInterval;
hatBuyPrice= config.HatBuyPrice;
hatSellPrice= config.HatSellPrice;
maxRequestTime= config.MaxRequestTime;
craftHatSellPrice = config.CraftHatSellPrice;
Admins = config.Admins;
this.apiKey = apiKey;
try
{
LogLevel = (Log.LogLevel)Enum.Parse(typeof(Log.LogLevel), config.LogLevel, true);
}
catch (ArgumentException)
{
Console.WriteLine("Invalid LogLevel provided in configuration. Defaulting to 'INFO'");
LogLevel = Log.LogLevel.Info;
}
log = new Log (config.LogFile, this.DisplayName, LogLevel);
CreateHandler = handlerCreator;
BotControlClass = config.BotControlClass;
// Hacking around https
ServicePointManager.ServerCertificateValidationCallback += SteamWeb.ValidateRemoteCertificate;
log.Debug ("Initializing Steam Bot...");
SteamClient = new SteamClient();
SteamTrade = SteamClient.GetHandler<SteamTrading>();
SteamUser = SteamClient.GetHandler<SteamUser>();
SteamFriends = SteamClient.GetHandler<SteamFriends>();
log.Info ("Connecting...");
SteamClient.Connect();
Thread CallbackThread = new Thread(() => // Callback Handling
{
while (true)
{
CallbackMsg msg = SteamClient.WaitForCallback (true);
HandleSteamMessage (msg);
}
});
new Thread(() =>
{
while (true)
{
Thread.Sleep(1000);
if (currentRequest.User != null)
{
DateTime RequestTimeout = RequestTime.AddSeconds(maxRequestTime);
int untilTradeTimeout = (int)Math.Round((RequestTimeout - DateTime.Now).TotalSeconds);
if (untilTradeTimeout <= 0 && (MySQL.getItem().User != null))
{
SteamFriends.SendChatMessage(currentRequest.User, EChatEntryType.ChatMsg, "Sorry, but your request took too long");
NewRequest(MySQL.RequestStatus.Timedout);
log.Warn("Request timedout");
}
}
}
}).Start();
CallbackThread.Start();
log.Success ("Done Loading Bot!");
CallbackThread.Join();
}