private void FireOnSteamGuardRequired(SteamGuardRequiredEventArgs e) { // Set to null in case this is another attempt this.AuthCode = null; EventHandler <SteamGuardRequiredEventArgs> handler = OnSteamGuardRequired; if (handler != null) { handler(this, e); } else { while (true) { if (this.AuthCode != null) { e.SteamGuard = this.AuthCode; break; } Thread.Sleep(5); } } }
private void FireOnSteamGuardRequired(SteamGuardRequiredEventArgs e) { // Set to null in case this is another attempt this.AuthCode = null; EventHandler <SteamGuardRequiredEventArgs> handler = OnSteamGuardRequired; if (handler != null) { handler(this, e); } else { if (!this.isprocess) { while (true) { if (this.AuthCode != null) { e.SteamGuard = this.AuthCode; break; } Thread.Sleep(5); } } else { // Apparently we're a process. So read in the code from stdin. this.AuthCode = Console.ReadLine(); e.SteamGuard = this.AuthCode; } } }
private void FireOnSteamGuardRequired(SteamGuardRequiredEventArgs e) { EventHandler <SteamGuardRequiredEventArgs> handler = OnSteamGuardRequired; if (handler != null) { handler(this, e); } }
private void BotOnOnSteamGuardRequired(object sender, SteamGuardRequiredEventArgs barf) { var bot = sender as Bot; var window = new SteamGuardForm(bot.DisplayName); var dialogResult = window.ShowDialog(); if (dialogResult == DialogResult.OK) { barf.SteamGuard = window.UserEnteredCode; } }
public void OnLogon(SteamUser.LoggedOnCallback e) { Log.Debug("Logged On Callback: {0}", e.Result); if (e.Result == EResult.OK) { Bot._myUserNonce = e.WebAPIUserNonce; } else { Log.Error("Login Error: {0}", e.Result); } if (e.Result == EResult.InvalidPassword) { Log.Interface("Invalid password. Press enter to log in again."); Program.PasswordRequestingBot = Bot; Program.IsMaskedInput = true; while (Program.IsMaskedInput) { Thread.Sleep(2000); } } if (e.Result == EResult.AccountLogonDenied) { Log.Interface("This account is SteamGuard enabled. Enter the code via the 'auth' command."); // try to get the steamguard auth code from the event callback SteamGuardRequiredEventArgs eva = new SteamGuardRequiredEventArgs(); Bot._fireOnSteamGuardRequired(eva); if (!string.IsNullOrEmpty(eva.SteamGuard)) { Bot.logOnDetails.AuthCode = eva.SteamGuard; } else { Bot.logOnDetails.AuthCode = Console.ReadLine(); } } if (e.Result == EResult.InvalidLoginAuthCode) { Log.Interface("The given SteamGuard code was invalid. Try again using the 'auth' command."); Bot.logOnDetails.AuthCode = Console.ReadLine(); } }
void HandleSteamMessage(ICallbackMsg msg) { Log.Debug(msg.ToString()); #region Login msg.Handle<SteamClient.ConnectedCallback> (callback => { Log.Debug ("Connection Callback: {0}", callback.Result); if (callback.Result == EResult.OK) { UserLogOn(); } else { Log.Error ("Failed to connect to Steam Community, trying again..."); SteamClient.Connect (); } }); msg.Handle<SteamUser.LoggedOnCallback> (callback => { Log.Debug("Logged On Callback: {0}", callback.Result); if (callback.Result == EResult.OK) { myUserNonce = callback.WebAPIUserNonce; } else { Log.Error("Login Error: {0}", callback.Result); } if (callback.Result == EResult.AccountLogonDenied) { Log.Interface ("This account is SteamGuard enabled. Enter the code via the `auth' command."); // try to get the steamguard auth code from the event callback var eva = new SteamGuardRequiredEventArgs(); FireOnSteamGuardRequired(eva); if (!String.IsNullOrEmpty(eva.SteamGuard)) logOnDetails.AuthCode = eva.SteamGuard; else logOnDetails.AuthCode = Console.ReadLine(); } if (callback.Result == EResult.InvalidLoginAuthCode) { Log.Interface("The given SteamGuard code was invalid. Try again using the `auth' command."); logOnDetails.AuthCode = Console.ReadLine(); } }); msg.Handle<SteamUser.LoginKeyCallback> (callback => { myUniqueId = callback.UniqueID.ToString(); UserWebLogOn(); if (Trade.CurrentSchema == null) { Log.Info ("Downloading Schema..."); Trade.CurrentSchema = Schema.FetchSchema (ApiKey, schemaLang); Log.Success ("Schema Downloaded!"); } SteamFriends.SetPersonaName (DisplayNamePrefix+DisplayName); SteamFriends.SetPersonaState (EPersonaState.Online); Log.Success ("Steam Bot Logged In Completely!"); GetUserHandler(SteamClient.SteamID).OnLoginCompleted(); }); msg.Handle<SteamUser.WebAPIUserNonceCallback>(webCallback => { Log.Debug("Received new WebAPIUserNonce."); if (webCallback.Result == EResult.OK) { myUserNonce = webCallback.Nonce; UserWebLogOn(); } else { Log.Error("WebAPIUserNonce Error: " + webCallback.Result); } }); msg.Handle<SteamUser.UpdateMachineAuthCallback>( authCallback => OnUpdateMachineAuthCallback(authCallback) ); #endregion #region Friends msg.Handle<SteamFriends.FriendsListCallback>(callback => { foreach (SteamFriends.FriendsListCallback.Friend friend in callback.FriendList) { switch (friend.SteamID.AccountType) { case EAccountType.Clan: if (friend.Relationship == EFriendRelationship.RequestRecipient) { if (GetUserHandler(friend.SteamID).OnGroupAdd()) { AcceptGroupInvite(friend.SteamID); } else { DeclineGroupInvite(friend.SteamID); } } break; default: CreateFriendsListIfNecessary(); if (friend.Relationship == EFriendRelationship.None) { friends.Remove(friend.SteamID); GetUserHandler(friend.SteamID).OnFriendRemove(); RemoveUserHandler(friend.SteamID); } else if (friend.Relationship == EFriendRelationship.RequestRecipient) { if (GetUserHandler(friend.SteamID).OnFriendAdd()) { if (!friends.Contains(friend.SteamID)) { friends.Add(friend.SteamID); } else { Log.Error("Friend was added who was already in friends list: " + friend.SteamID); } SteamFriends.AddFriend(friend.SteamID); } else { SteamFriends.RemoveFriend(friend.SteamID); RemoveUserHandler(friend.SteamID); } } break; } } }); msg.Handle<SteamFriends.FriendMsgCallback> (callback => { EChatEntryType type = callback.EntryType; if (callback.EntryType == EChatEntryType.ChatMsg) { Log.Info ("Chat Message from {0}: {1}", SteamFriends.GetFriendPersonaName (callback.Sender), callback.Message ); GetUserHandler(callback.Sender).OnMessageHandler(callback.Message, type); } }); #endregion #region Group Chat msg.Handle<SteamFriends.ChatMsgCallback>(callback => { GetUserHandler(callback.ChatterID).OnChatRoomMessage(callback.ChatRoomID, callback.ChatterID, callback.Message); }); #endregion #region Trading msg.Handle<SteamTrading.SessionStartCallback> (callback => { bool started = HandleTradeSessionStart (callback.OtherClient); if (!started) Log.Error ("Could not start the trade session."); else Log.Debug ("SteamTrading.SessionStartCallback handled successfully. Trade Opened."); }); msg.Handle<SteamTrading.TradeProposedCallback> (callback => { if (CheckCookies() == false) { SteamTrade.RespondToTrade(callback.TradeID, false); return; } try { tradeManager.InitializeTrade(SteamUser.SteamID, callback.OtherClient); } catch (WebException we) { SteamFriends.SendChatMessage(callback.OtherClient, EChatEntryType.ChatMsg, "Trade error: " + we.Message); SteamTrade.RespondToTrade(callback.TradeID, false); return; } catch (Exception) { SteamFriends.SendChatMessage(callback.OtherClient, EChatEntryType.ChatMsg, "Trade declined. Could not correctly fetch your backpack."); SteamTrade.RespondToTrade(callback.TradeID, false); return; } //if (tradeManager.OtherInventory.IsPrivate) //{ // SteamFriends.SendChatMessage(callback.OtherClient, // EChatEntryType.ChatMsg, // "Trade declined. Your backpack cannot be private."); // SteamTrade.RespondToTrade (callback.TradeID, false); // return; //} if (CurrentTrade == null && GetUserHandler (callback.OtherClient).OnTradeRequest ()) SteamTrade.RespondToTrade (callback.TradeID, true); else SteamTrade.RespondToTrade (callback.TradeID, false); }); msg.Handle<SteamTrading.TradeResultCallback> (callback => { if (callback.Response == EEconTradeResponse.Accepted) { Log.Debug("Trade Status: {0}", callback.Response); Log.Info ("Trade Accepted!"); GetUserHandler(callback.OtherClient).OnTradeRequestReply(true, callback.Response.ToString()); } else { Log.Warn("Trade failed: {0}", callback.Response); CloseTrade (); GetUserHandler(callback.OtherClient).OnTradeRequestReply(false, callback.Response.ToString()); } }); #endregion #region Disconnect msg.Handle<SteamUser.LoggedOffCallback> (callback => { IsLoggedIn = false; Log.Warn("Logged off Steam. Reason: {0}", callback.Result); }); msg.Handle<SteamClient.DisconnectedCallback> (callback => { if(IsLoggedIn) { IsLoggedIn = false; CloseTrade(); Log.Warn("Disconnected from Steam Network!"); } SteamClient.Connect (); }); #endregion #region Notifications msg.Handle<SteamNotifications.NotificationCallback>(callback => { //currently only appears to be of trade offer if (callback.Notifications.Count != 0) { foreach (var notification in callback.Notifications) { Log.Info(notification.UserNotificationType + " notification"); } } // Get offers only if cookies are valid if (CheckCookies()) tradeOfferManager.GetOffers(); }); msg.Handle<SteamNotifications.CommentNotificationCallback>(callback => { //various types of comment notifications on profile/activity feed etc //Log.Info("received CommentNotificationCallback"); //Log.Info("New Commments " + callback.CommentNotifications.CountNewComments); //Log.Info("New Commments Owners " + callback.CommentNotifications.CountNewCommentsOwner); //Log.Info("New Commments Subscriptions" + callback.CommentNotifications.CountNewCommentsSubscriptions); }); #endregion }
private void FireOnSteamGuardRequired(SteamGuardRequiredEventArgs e) { // Set to null in case this is another attempt this.AuthCode = null; EventHandler<SteamGuardRequiredEventArgs> handler = OnSteamGuardRequired; if (handler != null) handler(this, e); else { while (true) { if (this.AuthCode != null) { e.SteamGuard = this.AuthCode; break; } Thread.Sleep(5); } } }
void HandleSteamMessage(CallbackMsg msg) { log.Debug(msg.ToString()); #region Login msg.Handle<SteamClient.ConnectedCallback> (callback => { log.Debug ("Connection Callback: " + callback.Result); if (callback.Result == EResult.OK) { UserLogOn(); } else { log.Error ("Failed to connect to Steam Community, trying again..."); SteamClient.Connect (); } }); msg.Handle<SteamUser.LoggedOnCallback> (callback => { log.Debug ("Logged On Callback: " + callback.Result); if (callback.Result != EResult.OK) { log.Error ("Login Error: " + callback.Result); } if (callback.Result == EResult.AccountLogonDenied) { log.Interface ("This account is SteamGuard enabled. Enter the code via the `auth' command."); // try to get the steamguard auth code from the event callback var eva = new SteamGuardRequiredEventArgs(); FireOnSteamGuardRequired(eva); if (!String.IsNullOrEmpty(eva.SteamGuard)) logOnDetails.AuthCode = eva.SteamGuard; else logOnDetails.AuthCode = Console.ReadLine(); } if (callback.Result == EResult.InvalidLoginAuthCode) { log.Interface("The given SteamGuard code was invalid. Try again using the `auth' command."); logOnDetails.AuthCode = Console.ReadLine(); } }); msg.Handle<SteamUser.LoginKeyCallback> (callback => { while (true) { bool authd = SteamWeb.Authenticate(callback, SteamClient, out sessionId, out token); if (authd) { log.Success ("User Authenticated!"); tradeManager = new TradeManager(apiKey, sessionId, token); tradeManager.SetTradeTimeLimits(MaximumTradeTime, MaximiumActionGap, TradePollingInterval); tradeManager.OnTimeout += OnTradeTimeout; tradeManager.OnTradeEnded += OnTradeEnded; break; } else { log.Warn ("Authentication failed, retrying in 2s..."); Thread.Sleep (2000); } } if (Trade.CurrentSchema == null) { log.Info ("Downloading Schema..."); Trade.CurrentSchema = Schema.FetchSchema (apiKey); log.Success ("Schema Downloaded!"); } SteamFriends.SetPersonaName (DisplayNamePrefix+DisplayName); SteamFriends.SetPersonaState (EPersonaState.Online); log.Success ("Steam Bot Logged In Completely!"); IsLoggedIn = true; }); // handle a special JobCallback differently than the others if (msg.IsType<SteamClient.JobCallback<SteamUser.UpdateMachineAuthCallback>>()) { msg.Handle<SteamClient.JobCallback<SteamUser.UpdateMachineAuthCallback>>( jobCallback => OnUpdateMachineAuthCallback(jobCallback.Callback, jobCallback.JobID) ); } #endregion #region Friends msg.Handle<SteamFriends.FriendsListCallback> (callback => { foreach (SteamFriends.FriendsListCallback.Friend friend in callback.FriendList) { if (!friends.Contains(friend.SteamID)) { friends.Add(friend.SteamID); if (friend.Relationship == EFriendRelationship.PendingInvitee && GetUserHandler(friend.SteamID).OnFriendAdd()) { SteamFriends.AddFriend(friend.SteamID); } } else { if (friend.Relationship == EFriendRelationship.None) { friends.Remove(friend.SteamID); GetUserHandler(friend.SteamID).OnFriendRemove(); } } } }); msg.Handle<SteamFriends.FriendMsgCallback> (callback => { EChatEntryType type = callback.EntryType; if (callback.EntryType == EChatEntryType.ChatMsg || callback.EntryType == EChatEntryType.Emote) { log.Info (String.Format ("Chat Message from {0}: {1}", SteamFriends.GetFriendPersonaName (callback.Sender), callback.Message )); GetUserHandler(callback.Sender).OnMessage(callback.Message, type); } }); #endregion #region Trading msg.Handle<SteamTrading.SessionStartCallback> (callback => { bool started = HandleTradeSessionStart (callback.OtherClient); if (!started) log.Error ("Could not start the trade session."); else log.Debug ("SteamTrading.SessionStartCallback handled successfully. Trade Opened."); }); msg.Handle<SteamTrading.TradeProposedCallback> (callback => { try { tradeManager.InitializeTrade(SteamUser.SteamID, callback.OtherClient); } catch { SteamFriends.SendChatMessage(callback.OtherClient, EChatEntryType.ChatMsg, "Trade declined. Could not correctly fetch your backpack."); SteamTrade.RespondToTrade (callback.TradeID, false); return; } if (tradeManager.OtherInventory.IsPrivate) { SteamFriends.SendChatMessage(callback.OtherClient, EChatEntryType.ChatMsg, "Trade declined. Your backpack cannot be private."); SteamTrade.RespondToTrade (callback.TradeID, false); return; } if (CurrentTrade == null && GetUserHandler (callback.OtherClient).OnTradeRequest ()) SteamTrade.RespondToTrade (callback.TradeID, true); else SteamTrade.RespondToTrade (callback.TradeID, false); }); msg.Handle<SteamTrading.TradeResultCallback> (callback => { if (callback.Response == EEconTradeResponse.Accepted) { log.Debug ("Trade Status: " + callback.Response); log.Info ("Trade Accepted!"); } else { log.Warn ("Trade failed: " + callback.Response); CloseTrade (); } }); #endregion #region Disconnect msg.Handle<SteamUser.LoggedOffCallback> (callback => { IsLoggedIn = false; log.Warn ("Logged Off: " + callback.Result); }); msg.Handle<SteamClient.DisconnectedCallback> (callback => { IsLoggedIn = false; CloseTrade (); log.Warn ("Disconnected from Steam Network!"); SteamClient.Connect (); }); #endregion }
private void FireOnSteamGuardRequired(SteamGuardRequiredEventArgs e) { // Set to null in case this is another attempt this.AuthCode = null; EventHandler<SteamGuardRequiredEventArgs> handler = OnSteamGuardRequired; if (handler != null) handler(this, e); else { if (!this.isprocess) { while (true) { if (this.AuthCode != null) { e.SteamGuard = this.AuthCode; break; } Thread.Sleep(5); } } else { // Apparently we're a process. So read in the code from stdin. this.AuthCode = Console.ReadLine(); e.SteamGuard = this.AuthCode; } } }
void HandleSteamMessage(ICallbackMsg msg) { Log.Debug(msg.ToString()); #region Login msg.Handle <SteamClient.ConnectedCallback> (callback => { Log.Debug("Connection Callback: {0}", callback.Result); if (callback.Result == EResult.OK) { UserLogOn(); } else { Log.Error("Failed to connect to Steam Community, trying again..."); SteamClient.Connect(); } }); msg.Handle <SteamUser.LoggedOnCallback> (callback => { Log.Debug("Logged On Callback: {0}", callback.Result); if (callback.Result == EResult.OK) { myUserNonce = callback.WebAPIUserNonce; } else { Log.Error("Login Error: {0}", callback.Result); } if (callback.Result == EResult.AccountLogonDenied) { Log.Interface("This account is SteamGuard enabled. Enter the code via the `auth' command."); // try to get the steamguard auth code from the event callback var eva = new SteamGuardRequiredEventArgs(); FireOnSteamGuardRequired(eva); if (!String.IsNullOrEmpty(eva.SteamGuard)) { logOnDetails.AuthCode = eva.SteamGuard; } else { logOnDetails.AuthCode = Console.ReadLine(); } } if (callback.Result == EResult.InvalidLoginAuthCode) { Log.Interface("The given SteamGuard code was invalid. Try again using the `auth' command."); logOnDetails.AuthCode = Console.ReadLine(); } }); msg.Handle <SteamUser.LoginKeyCallback> (callback => { myUniqueId = callback.UniqueID.ToString(); UserWebLogOn(); SteamFriends.SetPersonaName(DisplayNamePrefix + DisplayName); SteamFriends.SetPersonaState(EPersonaState.Online); Log.Success("Steam Bot Logged In Completely!"); GetUserHandler(SteamClient.SteamID).OnLoginCompleted(); }); msg.Handle <SteamUser.WebAPIUserNonceCallback>(webCallback => { Log.Debug("Received new WebAPIUserNonce."); if (webCallback.Result == EResult.OK) { myUserNonce = webCallback.Nonce; UserWebLogOn(); } else { Log.Error("WebAPIUserNonce Error: " + webCallback.Result); } }); msg.Handle <SteamUser.UpdateMachineAuthCallback>( authCallback => OnUpdateMachineAuthCallback(authCallback) ); #endregion #region Friends msg.Handle <SteamFriends.FriendsListCallback>(callback => { foreach (SteamFriends.FriendsListCallback.Friend friend in callback.FriendList) { switch (friend.SteamID.AccountType) { case EAccountType.Clan: if (friend.Relationship == EFriendRelationship.RequestRecipient) { if (GetUserHandler(friend.SteamID).OnGroupAdd()) { AcceptGroupInvite(friend.SteamID); } else { DeclineGroupInvite(friend.SteamID); } } break; default: CreateFriendsListIfNecessary(); if (friend.Relationship == EFriendRelationship.None) { friends.Remove(friend.SteamID); GetUserHandler(friend.SteamID).OnFriendRemove(); RemoveUserHandler(friend.SteamID); } else if (friend.Relationship == EFriendRelationship.RequestRecipient) { if (GetUserHandler(friend.SteamID).OnFriendAdd()) { if (!friends.Contains(friend.SteamID)) { friends.Add(friend.SteamID); } else { Log.Error("Friend was added who was already in friends list: " + friend.SteamID); } SteamFriends.AddFriend(friend.SteamID); } else { SteamFriends.RemoveFriend(friend.SteamID); RemoveUserHandler(friend.SteamID); } } break; } } }); msg.Handle <SteamFriends.FriendMsgCallback> (callback => { EChatEntryType type = callback.EntryType; if (callback.EntryType == EChatEntryType.ChatMsg) { Log.Info("Chat Message from {0}: {1}", SteamFriends.GetFriendPersonaName(callback.Sender), callback.Message ); GetUserHandler(callback.Sender).OnMessageHandler(callback.Message, type); } }); #endregion #region Group Chat msg.Handle <SteamFriends.ChatMsgCallback>(callback => { GetUserHandler(callback.ChatterID).OnChatRoomMessage(callback.ChatRoomID, callback.ChatterID, callback.Message); }); #endregion #region Disconnect msg.Handle <SteamUser.LoggedOffCallback> (callback => { IsLoggedIn = false; Log.Warn("Logged off Steam. Reason: {0}", callback.Result); }); msg.Handle <SteamClient.DisconnectedCallback> (callback => { if (IsLoggedIn) { IsLoggedIn = false; Log.Warn("Disconnected from Steam Network!"); } SteamClient.Connect(); }); #endregion }
void HandleSteamMessage(ICallbackMsg msg) { Log.Debug(msg.ToString()); #region Login msg.Handle <SteamClient.ConnectedCallback> (callback => { Log.Debug("Connection Callback: {0}", callback.Result); if (callback.Result == EResult.OK) { UserLogOn(); } else { Log.Error("Failed to connect to Steam Community, trying again..."); SteamClient.Connect(); } }); msg.Handle <SteamUser.LoggedOnCallback> (callback => { Log.Debug("Logged On Callback: {0}", callback.Result); if (callback.Result == EResult.OK) { myUserNonce = callback.WebAPIUserNonce; } else { Log.Error("Login Error: {0}", callback.Result); } if (callback.Result == EResult.AccountLogonDenied) { Log.Interface("This account is SteamGuard enabled. Enter the code via the `auth' command."); // try to get the steamguard auth code from the event callback var eva = new SteamGuardRequiredEventArgs(); FireOnSteamGuardRequired(eva); if (!String.IsNullOrEmpty(eva.SteamGuard)) { logOnDetails.AuthCode = eva.SteamGuard; } else { logOnDetails.AuthCode = Console.ReadLine(); } } if (callback.Result == EResult.InvalidLoginAuthCode) { Log.Interface("The given SteamGuard code was invalid. Try again using the `auth' command."); logOnDetails.AuthCode = Console.ReadLine(); } }); msg.Handle <SteamUser.LoginKeyCallback> (callback => { myUniqueId = callback.UniqueID.ToString(); UserWebLogOn(); if (Trade.CurrentSchema == null) { Log.Info("Downloading Schema..."); Trade.CurrentSchema = Schema.FetchSchema(ApiKey, schemaLang); Log.Success("Schema Downloaded!"); } SteamFriends.SetPersonaName(DisplayNamePrefix + DisplayName); SteamFriends.SetPersonaState(EPersonaState.Online); Log.Success("Steam Bot Logged In Completely!"); GetUserHandler(SteamClient.SteamID).OnLoginCompleted(); }); msg.Handle <SteamUser.WebAPIUserNonceCallback>(webCallback => { Log.Debug("Received new WebAPIUserNonce."); if (webCallback.Result == EResult.OK) { myUserNonce = webCallback.Nonce; UserWebLogOn(); } else { Log.Error("WebAPIUserNonce Error: " + webCallback.Result); } }); msg.Handle <SteamUser.UpdateMachineAuthCallback>( authCallback => OnUpdateMachineAuthCallback(authCallback) ); #endregion #region Friends msg.Handle <SteamFriends.FriendsListCallback>(callback => { foreach (SteamFriends.FriendsListCallback.Friend friend in callback.FriendList) { switch (friend.SteamID.AccountType) { case EAccountType.Clan: if (friend.Relationship == EFriendRelationship.RequestRecipient) { if (GetUserHandler(friend.SteamID).OnGroupAdd()) { AcceptGroupInvite(friend.SteamID); } else { DeclineGroupInvite(friend.SteamID); } } break; default: CreateFriendsListIfNecessary(); if (friend.Relationship == EFriendRelationship.None) { friends.Remove(friend.SteamID); GetUserHandler(friend.SteamID).OnFriendRemove(); RemoveUserHandler(friend.SteamID); } else if (friend.Relationship == EFriendRelationship.RequestRecipient) { if (GetUserHandler(friend.SteamID).OnFriendAdd()) { if (!friends.Contains(friend.SteamID)) { friends.Add(friend.SteamID); } else { Log.Error("Friend was added who was already in friends list: " + friend.SteamID); } SteamFriends.AddFriend(friend.SteamID); } else { SteamFriends.RemoveFriend(friend.SteamID); RemoveUserHandler(friend.SteamID); } } break; } } }); msg.Handle <SteamFriends.FriendMsgCallback> (callback => { EChatEntryType type = callback.EntryType; if (callback.EntryType == EChatEntryType.ChatMsg) { Log.Info("Chat Message from {0}: {1}", SteamFriends.GetFriendPersonaName(callback.Sender), callback.Message ); GetUserHandler(callback.Sender).OnMessageHandler(callback.Message, type); } }); #endregion #region Group Chat msg.Handle <SteamFriends.ChatMsgCallback>(callback => { GetUserHandler(callback.ChatterID).OnChatRoomMessage(callback.ChatRoomID, callback.ChatterID, callback.Message); }); #endregion #region Trading msg.Handle <SteamTrading.SessionStartCallback> (callback => { bool started = HandleTradeSessionStart(callback.OtherClient); if (!started) { Log.Error("Could not start the trade session."); } else { Log.Debug("SteamTrading.SessionStartCallback handled successfully. Trade Opened."); } }); msg.Handle <SteamTrading.TradeProposedCallback> (callback => { if (CheckCookies() == false) { SteamTrade.RespondToTrade(callback.TradeID, false); return; } try { tradeManager.InitializeTrade(SteamUser.SteamID, callback.OtherClient); } catch (WebException we) { SteamFriends.SendChatMessage(callback.OtherClient, EChatEntryType.ChatMsg, "Trade error: " + we.Message); SteamTrade.RespondToTrade(callback.TradeID, false); return; } catch (Exception) { SteamFriends.SendChatMessage(callback.OtherClient, EChatEntryType.ChatMsg, "Trade declined. Could not correctly fetch your backpack."); SteamTrade.RespondToTrade(callback.TradeID, false); return; } //if (tradeManager.OtherInventory.IsPrivate) //{ // SteamFriends.SendChatMessage(callback.OtherClient, // EChatEntryType.ChatMsg, // "Trade declined. Your backpack cannot be private."); // SteamTrade.RespondToTrade (callback.TradeID, false); // return; //} if (CurrentTrade == null && GetUserHandler(callback.OtherClient).OnTradeRequest()) { SteamTrade.RespondToTrade(callback.TradeID, true); } else { SteamTrade.RespondToTrade(callback.TradeID, false); } }); msg.Handle <SteamTrading.TradeResultCallback> (callback => { if (callback.Response == EEconTradeResponse.Accepted) { Log.Debug("Trade Status: {0}", callback.Response); Log.Info("Trade Accepted!"); GetUserHandler(callback.OtherClient).OnTradeRequestReply(true, callback.Response.ToString()); } else { Log.Warn("Trade failed: {0}", callback.Response); CloseTrade(); GetUserHandler(callback.OtherClient).OnTradeRequestReply(false, callback.Response.ToString()); } }); #endregion #region Disconnect msg.Handle <SteamUser.LoggedOffCallback> (callback => { IsLoggedIn = false; Log.Warn("Logged off Steam. Reason: {0}", callback.Result); }); msg.Handle <SteamClient.DisconnectedCallback> (callback => { if (IsLoggedIn) { IsLoggedIn = false; CloseTrade(); Log.Warn("Disconnected from Steam Network!"); } SteamClient.Connect(); }); #endregion #region Notifications msg.Handle <SteamBot.SteamNotifications.NotificationCallback>(callback => { //currently only appears to be of trade offer if (callback.Notifications.Count != 0) { foreach (var notification in callback.Notifications) { Log.Info(notification.UserNotificationType + " notification"); } } // Get offers only if cookies are valid if (CheckCookies()) { tradeOfferManager.GetOffers(); } }); msg.Handle <SteamBot.SteamNotifications.CommentNotificationCallback>(callback => { //various types of comment notifications on profile/activity feed etc //Log.Info("received CommentNotificationCallback"); //Log.Info("New Commments " + callback.CommentNotifications.CountNewComments); //Log.Info("New Commments Owners " + callback.CommentNotifications.CountNewCommentsOwner); //Log.Info("New Commments Subscriptions" + callback.CommentNotifications.CountNewCommentsSubscriptions); }); #endregion }
void HandleSteamMessage(CallbackMsg msg) { log.Debug(msg.ToString()); #region Login msg.Handle <SteamClient.ConnectedCallback>(callback => { log.Debug("Connection Callback: " + callback.Result); if (callback.Result == EResult.OK) { UserLogOn(); } else { log.Error("Failed to connect to Steam Community, trying again..."); SteamClient.Connect(); } }); msg.Handle <SteamUser.LoggedOnCallback>(callback => { log.Debug("Logged On Callback: " + callback.Result); if (callback.Result == EResult.OK) { MyUserNonce = callback.WebAPIUserNonce; } else { log.Error("Login Error: " + callback.Result); } if (callback.Result == EResult.AccountLogonDenied) { log.Interface("This account is SteamGuard enabled. Enter the code via the `auth' command."); // try to get the steamguard auth code from the event callback var eva = new SteamGuardRequiredEventArgs(); FireOnSteamGuardRequired(eva); if (!String.IsNullOrEmpty(eva.SteamGuard)) { logOnDetails.AuthCode = eva.SteamGuard; } else { logOnDetails.AuthCode = Console.ReadLine(); } } if (callback.Result == EResult.InvalidLoginAuthCode) { log.Interface("The given SteamGuard code was invalid. Try again using the `auth' command."); logOnDetails.AuthCode = Console.ReadLine(); } }); msg.Handle <SteamUser.LoginKeyCallback>(callback => { MyUniqueId = callback.UniqueID.ToString(); UserWebLogOn(); if (Trade.CurrentSchema == null) { log.Info("Downloading Schema..."); Trade.CurrentSchema = Schema.FetchSchema(apiKey); log.Success("Schema Downloaded!"); } SteamFriends.SetPersonaName(DisplayNamePrefix + DisplayName); SteamFriends.SetPersonaState(EPersonaState.Online); log.Success("Steam Bot Logged In Completely!"); IsLoggedIn = true; GetUserHandler(SteamClient.SteamID).OnLoginCompleted(); }); msg.Handle <SteamClient.JobCallback <SteamUser.WebAPIUserNonceCallback> >(jobCallback => { log.Debug("Received new WebAPIUserNonce."); if (jobCallback.Callback.Result == EResult.OK) { MyUserNonce = jobCallback.Callback.Nonce; UserWebLogOn(); } else { log.Error("WebAPIUserNonce Error: " + jobCallback.Callback.Result); } }); // handle a special JobCallback differently than the others if (msg.IsType <SteamClient.JobCallback <SteamUser.UpdateMachineAuthCallback> >()) { msg.Handle <SteamClient.JobCallback <SteamUser.UpdateMachineAuthCallback> >( jobCallback => OnUpdateMachineAuthCallback(jobCallback.Callback, jobCallback.JobID) ); } #endregion #region Friends msg.Handle <SteamFriends.FriendsListCallback>(callback => { foreach (SteamFriends.FriendsListCallback.Friend friend in callback.FriendList) { switch (friend.SteamID.AccountType) { case EAccountType.Clan: if (friend.Relationship == EFriendRelationship.RequestRecipient) { if (GetUserHandler(friend.SteamID).OnGroupAdd()) { AcceptGroupInvite(friend.SteamID); } else { DeclineGroupInvite(friend.SteamID); } } break; default: CreateFriendsListIfNecessary(); if (friend.Relationship == EFriendRelationship.None) { friends.Remove(friend.SteamID); GetUserHandler(friend.SteamID).OnFriendRemove(); RemoveUserHandler(friend.SteamID); } else if (friend.Relationship == EFriendRelationship.RequestRecipient) { if (GetUserHandler(friend.SteamID).OnFriendAdd()) { if (!friends.Contains(friend.SteamID)) { friends.Add(friend.SteamID); } else { log.Error("Friend was added who was already in friends list: " + friend.SteamID); } SteamFriends.AddFriend(friend.SteamID); } else { SteamFriends.RemoveFriend(friend.SteamID); RemoveUserHandler(friend.SteamID); } } break; } } }); msg.Handle <SteamFriends.FriendMsgCallback>(callback => { EChatEntryType type = callback.EntryType; if (callback.EntryType == EChatEntryType.ChatMsg) { log.Info(String.Format("Chat Message from {0}: {1}", SteamFriends.GetFriendPersonaName(callback.Sender), callback.Message )); GetUserHandler(callback.Sender).OnMessage(callback.Message, type); } }); #endregion #region Group Chat //Begin KFBros stuff msg.Handle <SteamFriends.ChatMsgCallback>(callback => { GetUserHandler(callback.ChatterID).OnChatRoomMessage(callback.ChatRoomID, callback.ChatterID, callback.Message); if (callback.Message == "hi") { SteamFriends.SendChatRoomMessage(callback.ChatRoomID, EChatEntryType.ChatMsg, "hi"); } if (callback.Message.Contains("v=")) { string coolresult; string[] result = callback.Message.Split(' '); for (int i = 0; i < result.Length; ++i) { if (result[i].Contains("v=")) { coolresult = result[i]; log.Warn(coolresult.Substring(coolresult.IndexOf("v=") + 2)); string url = "https://www.googleapis.com/youtube/v3/videos?part=snippet&id=" + coolresult.Substring(coolresult.IndexOf("v=") + 2) + "&key=" + youtubeService.ApiKey; WebRequest request = HttpWebRequest.Create(url); WebResponse response = request.GetResponse(); StreamReader reader = new StreamReader(response.GetResponseStream()); string urlText = reader.ReadToEnd(); string final = "Youtube: " + urlText.Substring(urlText.IndexOf("\"title\": ") + 9, (urlText.IndexOf("\"description\":") - 6) - (urlText.IndexOf("\"title\": ") + 9)); log.Success(final); if (final.Length > 9) { SteamFriends.SendChatRoomMessage(callback.ChatRoomID, EChatEntryType.ChatMsg, final); } } } } }); //handle bot being kicked and other type of chat member state messages msg.Handle <SteamFriends.ChatMemberInfoCallback>(callback => { if (callback.StateChangeInfo.ChatterActedOn == 76561198119861272) { if (callback.StateChangeInfo.StateChange == EChatMemberStateChange.Kicked) { SteamFriends.JoinChat(callback.ChatRoomID); } } }); #endregion #region Trading msg.Handle <SteamTrading.SessionStartCallback>(callback => { bool started = HandleTradeSessionStart(callback.OtherClient); if (!started) { log.Error("Could not start the trade session."); } else { log.Debug("SteamTrading.SessionStartCallback handled successfully. Trade Opened."); } }); msg.Handle <SteamTrading.TradeProposedCallback>(callback => { if (CheckCookies() == false) { SteamTrade.RespondToTrade(callback.TradeID, false); return; } try { tradeManager.InitializeTrade(SteamUser.SteamID, callback.OtherClient); } catch (WebException we) { SteamFriends.SendChatMessage(callback.OtherClient, EChatEntryType.ChatMsg, "Trade error: " + we.Message); SteamTrade.RespondToTrade(callback.TradeID, false); return; } catch (Exception) { SteamFriends.SendChatMessage(callback.OtherClient, EChatEntryType.ChatMsg, "Trade declined. Could not correctly fetch your backpack."); SteamTrade.RespondToTrade(callback.TradeID, false); return; } //if (tradeManager.OtherInventory.IsPrivate) //{ // SteamFriends.SendChatMessage(callback.OtherClient, // EChatEntryType.ChatMsg, // "Trade declined. Your backpack cannot be private."); // SteamTrade.RespondToTrade (callback.TradeID, false); // return; //} if (CurrentTrade == null && GetUserHandler(callback.OtherClient).OnTradeRequest()) { SteamTrade.RespondToTrade(callback.TradeID, true); } else { SteamTrade.RespondToTrade(callback.TradeID, false); } }); msg.Handle <SteamTrading.TradeResultCallback>(callback => { if (callback.Response == EEconTradeResponse.Accepted) { log.Debug("Trade Status: " + callback.Response); log.Info("Trade Accepted!"); GetUserHandler(callback.OtherClient).OnTradeRequestReply(true, callback.Response.ToString()); } else { log.Warn("Trade failed: " + callback.Response); CloseTrade(); GetUserHandler(callback.OtherClient).OnTradeRequestReply(false, callback.Response.ToString()); } }); #endregion #region Disconnect msg.Handle <SteamUser.LoggedOffCallback>(callback => { IsLoggedIn = false; log.Warn("Logged Off: " + callback.Result); }); msg.Handle <SteamClient.DisconnectedCallback>(callback => { IsLoggedIn = false; CloseTrade(); log.Warn("Disconnected from Steam Network!"); SteamClient.Connect(); }); #endregion #region Notifications msg.Handle <SteamBot.SteamNotifications.NotificationCallback>(callback => { //currently only appears to be of trade offer if (callback.Notifications.Count != 0) { foreach (var notification in callback.Notifications) { log.Info(notification.UserNotificationType + " notification"); } } // Get offers only if cookies are valid if (CheckCookies()) { tradeOfferManager.GetOffers(); } }); msg.Handle <SteamBot.SteamNotifications.CommentNotificationCallback>(callback => { //various types of comment notifications on profile/activity feed etc //log.Info("received CommentNotificationCallback"); //log.Info("New Commments " + callback.CommentNotifications.CountNewComments); //log.Info("New Commments Owners " + callback.CommentNotifications.CountNewCommentsOwner); //log.Info("New Commments Subscriptions" + callback.CommentNotifications.CountNewCommentsSubscriptions); }); #endregion }
private void FireOnSteamGuardRequired(SteamGuardRequiredEventArgs e) { EventHandler<SteamGuardRequiredEventArgs> handler = OnSteamGuardRequired; if (handler != null) handler(this, e); }
void HandleSteamMessage (CallbackMsg msg) { log.Debug(msg.ToString()); #region Login msg.Handle<SteamClient.ConnectedCallback> (callback => { log.Debug ("Connection Callback: " + callback.Result); if (callback.Result == EResult.OK) { UserLogOn(); } else { log.Error ("Failed to connect to Steam Community, trying again..."); SteamClient.Connect (); } }); msg.Handle<SteamUser.LoggedOnCallback> (callback => { log.Debug ("Logged On Callback: " + callback.Result); if (callback.Result == EResult.OK) { MyLoginKey = callback.WebAPIUserNonce; } else { log.Error ("Login Error: " + callback.Result); } if (callback.Result == EResult.AccountLogonDenied) { log.Interface ("This account is SteamGuard enabled. Enter the code via the `auth' command."); // try to get the steamguard auth code from the event callback var eva = new SteamGuardRequiredEventArgs(); FireOnSteamGuardRequired(eva); if (!String.IsNullOrEmpty(eva.SteamGuard)) logOnDetails.AuthCode = eva.SteamGuard; else logOnDetails.AuthCode = Console.ReadLine(); } if (callback.Result == EResult.InvalidLoginAuthCode) { log.Interface("The given SteamGuard code was invalid. Try again using the `auth' command."); logOnDetails.AuthCode = Console.ReadLine(); } }); msg.Handle<SteamUser.LoginKeyCallback> (callback => { while (true) { bool authd = SteamWeb.Authenticate(callback, SteamClient, out sessionId, out token, MyLoginKey); if (authd) { botCookies = new CookieContainer(); botCookies.SetCookies(new Uri("http://steamcommunity.com"), string.Format("steamLogin={0}", token)); botCookies.SetCookies(new Uri("http://steamcommunity.com"), string.Format("sessionid={0};", sessionId)); GenericInventory.SetCookie(botCookies, SteamUser.SteamID); log.Success ("User Authenticated!"); BotSteamIds.Add(SteamUser.SteamID); tradeManager = new TradeManager(apiKey, sessionId, token); tradeManager.SetTradeTimeLimits(MaximumTradeTime, MaximiumActionGap, TradePollingInterval); tradeManager.OnTimeout += OnTradeTimeout; break; } else { log.Warn ("Authentication failed, retrying in 2s..."); Thread.Sleep (2000); } } SteamFriends.SetPersonaName (DisplayNamePrefix+DisplayName); SteamFriends.SetPersonaState (EPersonaState.Online); log.Success ("Steam Bot Logged In Completely!"); IsLoggedIn = true; botCookies = new CookieContainer(); botCookies.SetCookies(new Uri("http://steamcommunity.com"), string.Format("steamLogin={0}", token)); botCookies.SetCookies(new Uri("http://steamcommunity.com"), string.Format("sessionid={0}", sessionId)); GenericInventory.SetCookie(botCookies, SteamUser.SteamID); Pusher = new Pusher("51a9410427d703c5a743"); Pusher.Connected += Pusher_Connected; Pusher.Connect(); GetUserHandler(SteamClient.SteamID).OnLoginCompleted(); }); // handle a special JobCallback differently than the others if (msg.IsType<SteamClient.JobCallback<SteamUser.UpdateMachineAuthCallback>>()) { msg.Handle<SteamClient.JobCallback<SteamUser.UpdateMachineAuthCallback>>( jobCallback => OnUpdateMachineAuthCallback(jobCallback.Callback, jobCallback.JobID) ); } #endregion #region Friends msg.Handle<SteamFriends.FriendsListCallback>(callback => { foreach (SteamFriends.FriendsListCallback.Friend friend in callback.FriendList) { if (friend.SteamID.AccountType == EAccountType.Clan) { if (!groups.Contains(friend.SteamID)) { groups.Add(friend.SteamID); if (friend.Relationship == EFriendRelationship.RequestRecipient) { if (GetUserHandler(friend.SteamID).OnGroupAdd()) { AcceptGroupInvite(friend.SteamID); } else { DeclineGroupInvite(friend.SteamID); } } } else { if (friend.Relationship == EFriendRelationship.None) { groups.Remove(friend.SteamID); } } } else if (friend.SteamID.AccountType != EAccountType.Clan) { if (!friends.Contains(friend.SteamID)) { friends.Add(friend.SteamID); if (friend.Relationship == EFriendRelationship.RequestRecipient && GetUserHandler(friend.SteamID).OnFriendAdd()) { SteamFriends.AddFriend(friend.SteamID); } } else { if (friend.Relationship == EFriendRelationship.None) { friends.Remove(friend.SteamID); GetUserHandler(friend.SteamID).OnFriendRemove(); } } } } }); msg.Handle<SteamFriends.FriendMsgCallback> (callback => { EChatEntryType type = callback.EntryType; if (callback.EntryType == EChatEntryType.ChatMsg) { log.Info (String.Format ("Chat Message from {0}: {1}", SteamFriends.GetFriendPersonaName (callback.Sender), callback.Message )); GetUserHandler(callback.Sender).OnMessage(callback.Message, type); } }); #endregion #region Group Chat msg.Handle<SteamFriends.ChatMsgCallback>(callback => { GetUserHandler(callback.ChatterID).OnChatRoomMessage(callback.ChatRoomID, callback.ChatterID, callback.Message); }); #endregion #region Trading msg.Handle<SteamTrading.SessionStartCallback> (callback => { bool started = HandleTradeSessionStart (callback.OtherClient); if (!started) log.Error ("Could not start the trade session."); else log.Debug ("SteamTrading.SessionStartCallback handled successfully. Trade Opened."); }); msg.Handle<SteamTrading.TradeProposedCallback> (callback => { try { tradeManager.InitializeTrade(SteamUser.SteamID, callback.OtherClient); } catch (WebException we) { SteamFriends.SendChatMessage(callback.OtherClient, EChatEntryType.ChatMsg, "Trade error: " + we.Message); SteamTrade.RespondToTrade(callback.TradeID, false); return; } catch (Exception) { SteamFriends.SendChatMessage(callback.OtherClient, EChatEntryType.ChatMsg, "Trade declined. Could not correctly fetch your backpack."); SteamTrade.RespondToTrade(callback.TradeID, false); return; } if (CurrentTrade == null && GetUserHandler (callback.OtherClient).OnTradeRequest ()) SteamTrade.RespondToTrade (callback.TradeID, true); else SteamTrade.RespondToTrade (callback.TradeID, false); }); msg.Handle<SteamTrading.TradeResultCallback> (callback => { if (callback.Response == EEconTradeResponse.Accepted) { log.Debug ("Trade Status: " + callback.Response); log.Info ("Trade Accepted!"); GetUserHandler(callback.OtherClient).OnTradeRequestReply(true, callback.Response.ToString()); } else { log.Warn ("Trade failed: " + callback.Response); CloseTrade (); GetUserHandler(callback.OtherClient).OnTradeRequestReply(false, callback.Response.ToString()); } }); #endregion #region Disconnect msg.Handle<SteamUser.LoggedOffCallback> (callback => { IsLoggedIn = false; log.Warn ("Logged Off: " + callback.Result); }); msg.Handle<SteamClient.DisconnectedCallback> (callback => { IsLoggedIn = false; CloseTrade (); log.Warn ("Disconnected from Steam Network!"); SteamClient.Connect (); }); #endregion }
void HandleSteamMessage(CallbackMsg msg) { log.Debug(msg.ToString()); #region Login msg.Handle <SteamClient.ConnectedCallback> (callback => { log.Debug("Connection Callback: " + callback.Result); if (callback.Result == EResult.OK) { UserLogOn(); } else { log.Error("Failed to connect to Steam Community, trying again..."); SteamClient.Connect(); } }); msg.Handle <SteamUser.LoggedOnCallback> (callback => { log.Debug("Logged On Callback: " + callback.Result); if (callback.Result != EResult.OK) { log.Error("Login Error: " + callback.Result); } if (callback.Result == EResult.AccountLogonDenied) { log.Interface("This account is SteamGuard enabled. Enter the code via the `auth' command."); // try to get the steamguard auth code from the event callback var eva = new SteamGuardRequiredEventArgs(); FireOnSteamGuardRequired(eva); if (!String.IsNullOrEmpty(eva.SteamGuard)) { logOnDetails.AuthCode = eva.SteamGuard; } else { logOnDetails.AuthCode = Console.ReadLine(); } } if (callback.Result == EResult.InvalidLoginAuthCode) { log.Interface("The given SteamGuard code was invalid. Try again using the `auth' command."); logOnDetails.AuthCode = Console.ReadLine(); } }); msg.Handle <SteamUser.LoginKeyCallback> (callback => { while (true) { bool authd = SteamWeb.Authenticate(callback, SteamClient, out sessionId, out token); if (authd) { log.Success("User Authenticated!"); tradeManager = new TradeManager(apiKey, sessionId, token); tradeManager.SetTradeTimeLimits(MaximumTradeTime, MaximiumActionGap, TradePollingInterval); tradeManager.OnTimeout += OnTradeTimeout; tradeManager.OnTradeEnded += OnTradeEnded; break; } else { log.Warn("Authentication failed, retrying in 2s..."); Thread.Sleep(2000); } } if (Trade.CurrentSchema == null) { log.Info("Downloading Schema..."); Trade.CurrentSchema = Schema.FetchSchema(apiKey); log.Success("Schema Downloaded!"); } SteamFriends.SetPersonaName(DisplayNamePrefix + DisplayName); SteamFriends.SetPersonaState(EPersonaState.Online); log.Success("Steam Bot Logged In Completely!"); IsLoggedIn = true; GetUserHandler(SteamClient.SteamID).OnLoginCompleted(); }); // handle a special JobCallback differently than the others if (msg.IsType <SteamClient.JobCallback <SteamUser.UpdateMachineAuthCallback> >()) { msg.Handle <SteamClient.JobCallback <SteamUser.UpdateMachineAuthCallback> >( jobCallback => OnUpdateMachineAuthCallback(jobCallback.Callback, jobCallback.JobID) ); } #endregion #region Friends msg.Handle <SteamFriends.FriendsListCallback> (callback => { foreach (SteamFriends.FriendsListCallback.Friend friend in callback.FriendList) { if (!friends.Contains(friend.SteamID)) { friends.Add(friend.SteamID); if (friend.Relationship == EFriendRelationship.PendingInvitee && GetUserHandler(friend.SteamID).OnFriendAdd()) { SteamFriends.AddFriend(friend.SteamID); } } else { if (friend.Relationship == EFriendRelationship.None) { friends.Remove(friend.SteamID); GetUserHandler(friend.SteamID).OnFriendRemove(); } } } }); msg.Handle <SteamFriends.FriendMsgCallback> (callback => { EChatEntryType type = callback.EntryType; if (callback.EntryType == EChatEntryType.ChatMsg || callback.EntryType == EChatEntryType.Emote) { log.Info(String.Format("Chat Message from {0}: {1}", SteamFriends.GetFriendPersonaName(callback.Sender), callback.Message )); GetUserHandler(callback.Sender).OnMessage(callback.Message, type); } }); #endregion #region Group Chat msg.Handle <SteamFriends.ChatMsgCallback>(callback => { GetUserHandler(callback.ChatterID).OnChatRoomMessage(callback.ChatRoomID, callback.ChatterID, callback.Message); }); #endregion #region Trading msg.Handle <SteamTrading.SessionStartCallback> (callback => { bool started = HandleTradeSessionStart(callback.OtherClient); if (!started) { log.Error("Could not start the trade session."); } else { log.Debug("SteamTrading.SessionStartCallback handled successfully. Trade Opened."); } }); msg.Handle <SteamTrading.TradeProposedCallback> (callback => { try { tradeManager.InitializeTrade(SteamUser.SteamID, callback.OtherClient); } catch { SteamFriends.SendChatMessage(callback.OtherClient, EChatEntryType.ChatMsg, "Trade declined. Could not correctly fetch your backpack."); SteamTrade.RespondToTrade(callback.TradeID, false); return; } if (tradeManager.OtherInventory.IsPrivate) { SteamFriends.SendChatMessage(callback.OtherClient, EChatEntryType.ChatMsg, "Trade declined. Your backpack cannot be private."); SteamTrade.RespondToTrade(callback.TradeID, false); return; } if (CurrentTrade == null && GetUserHandler(callback.OtherClient).OnTradeRequest()) { SteamTrade.RespondToTrade(callback.TradeID, true); } else { SteamTrade.RespondToTrade(callback.TradeID, false); } }); msg.Handle <SteamTrading.TradeResultCallback> (callback => { if (callback.Response == EEconTradeResponse.Accepted) { log.Debug("Trade Status: " + callback.Response); log.Info("Trade Accepted!"); } else { log.Warn("Trade failed: " + callback.Response); CloseTrade(); } }); #endregion #region Disconnect msg.Handle <SteamUser.LoggedOffCallback> (callback => { IsLoggedIn = false; log.Warn("Logged Off: " + callback.Result); }); msg.Handle <SteamClient.DisconnectedCallback> (callback => { IsLoggedIn = false; CloseTrade(); log.Warn("Disconnected from Steam Network!"); SteamClient.Connect(); }); #endregion }
void HandleSteamMessage(ICallbackMsg msg) { Log.Debug(msg.ToString()); #region Login msg.Handle<SteamClient.ConnectedCallback> (callback => { Log.Debug ("Connection Callback: {0}", callback.Result); if (callback.Result == EResult.OK) { UserLogOn(); } else { Log.Error ("Failed to connect to Steam Community, trying again..."); SteamClient.Connect (); } }); msg.Handle<SteamUser.LoggedOnCallback> (callback => { Log.Debug("Logged On Callback: {0}", callback.Result); if (callback.Result == EResult.OK) { myUserNonce = callback.WebAPIUserNonce; } else { Log.Error("Login Error: {0}", callback.Result); } if (callback.Result == EResult.AccountLogonDeniedNeedTwoFactorCode) { var mobileAuthCode = GetMobileAuthCode(); if (string.IsNullOrEmpty(mobileAuthCode)) { Log.Error("Failed to generate 2FA code. Make sure you have linked the authenticator via SteamBot."); } else { logOnDetails.TwoFactorCode = mobileAuthCode; Log.Success("Generated 2FA code."); } } else if (callback.Result == EResult.TwoFactorCodeMismatch) { SteamAuth.TimeAligner.AlignTime(); logOnDetails.TwoFactorCode = SteamGuardAccount.GenerateSteamGuardCode(); Log.Success("Regenerated 2FA code."); } else if (callback.Result == EResult.AccountLogonDenied) { Log.Interface ("This account is SteamGuard enabled. Enter the code via the `auth' command."); // try to get the steamguard auth code from the event callback var eva = new SteamGuardRequiredEventArgs(); FireOnSteamGuardRequired(eva); if (!String.IsNullOrEmpty(eva.SteamGuard)) logOnDetails.AuthCode = eva.SteamGuard; else logOnDetails.AuthCode = Console.ReadLine(); } else if (callback.Result == EResult.InvalidLoginAuthCode) { Log.Interface("The given SteamGuard code was invalid. Try again using the `auth' command."); logOnDetails.AuthCode = Console.ReadLine(); } }); msg.Handle<SteamUser.LoginKeyCallback> (callback => { myUniqueId = callback.UniqueID.ToString(); UserWebLogOn(); if (Trade.CurrentSchema == null) { Log.Info ("Downloading Schema..."); Trade.CurrentSchema = Schema.FetchSchema (ApiKey, schemaLang); Log.Success ("Schema Downloaded!"); } // SteamFriends.SetPersonaName (DisplayNamePrefix+DisplayName); SteamFriends.SetPersonaState (EPersonaState.Online); Log.Success ("Steam Bot Logged In Completely!"); GetUserHandler(SteamClient.SteamID).OnLoginCompleted(); }); msg.Handle<SteamUser.WebAPIUserNonceCallback>(webCallback => { Log.Debug("Received new WebAPIUserNonce."); if (webCallback.Result == EResult.OK) { myUserNonce = webCallback.Nonce; UserWebLogOn(); } else { Log.Error("WebAPIUserNonce Error: " + webCallback.Result); } }); msg.Handle<SteamUser.UpdateMachineAuthCallback>( authCallback => OnUpdateMachineAuthCallback(authCallback) ); #endregion #region Friends msg.Handle<SteamFriends.FriendsListCallback>(callback => { foreach (SteamFriends.FriendsListCallback.Friend friend in callback.FriendList) { switch (friend.SteamID.AccountType) { case EAccountType.Clan: if (friend.Relationship == EFriendRelationship.RequestRecipient) { if (GetUserHandler(friend.SteamID).OnGroupAdd()) { AcceptGroupInvite(friend.SteamID); } else { DeclineGroupInvite(friend.SteamID); } } break; default: CreateFriendsListIfNecessary(); if (friend.Relationship == EFriendRelationship.None) { friends.Remove(friend.SteamID); GetUserHandler(friend.SteamID).OnFriendRemove(); RemoveUserHandler(friend.SteamID); } else if (friend.Relationship == EFriendRelationship.RequestRecipient) { if (GetUserHandler(friend.SteamID).OnFriendAdd()) { if (!friends.Contains(friend.SteamID)) { friends.Add(friend.SteamID); } else { Log.Error("Friend was added who was already in friends list: " + friend.SteamID); } SteamFriends.AddFriend(friend.SteamID); } else { SteamFriends.RemoveFriend(friend.SteamID); RemoveUserHandler(friend.SteamID); } } break; } } }); msg.Handle<SteamFriends.FriendMsgCallback> (callback => { EChatEntryType type = callback.EntryType; if (callback.EntryType == EChatEntryType.ChatMsg) { Log.Info ("Chat Message from {0}: {1}", SteamFriends.GetFriendPersonaName (callback.Sender), callback.Message ); GetUserHandler(callback.Sender).OnMessageHandler(callback.Message, type); } }); #endregion msg.Handle<SteamFriends.ChatMemberInfoCallback>(callback => { if (callback.StateChangeInfo.MemberInfo != null) { string User = callback.StateChangeInfo.MemberInfo.SteamID.ToString(); //Retrieves the database of users string filedata = System.IO.File.ReadAllText(@"users.json"); //Converts the JSON file to a dictionary //Log.Interface(existing); EClanPermission Status = callback.StateChangeInfo.MemberInfo.Details; //Their officer status ChatMember ChatMember = new ChatMember(); //Sets up dictionary for the JSON file //Adds a new entry to the dictionary, or overwrites an existing if (GroupChatHandler.UserDatabase.ContainsKey(User)) //if it already exists, it deletes it so it can update the data { GroupChatHandler.UserDatabase.Remove(User); } GroupChatHandler.UserDatabase.Add(User,Status); //Resaves it into a usable JSON format to later save //Shows on the screen //log.Interface(json); //log.Interface("ADDED: " + User + callback.StateChangeInfo.MemberInfo.Details.ToString()); //Saves the file System.IO.File.WriteAllText(@"users.json", JsonConvert.SerializeObject(GroupChatHandler.UserDatabase)); } }); #region Group Chat msg.Handle<SteamFriends.ChatMsgCallback>(callback => { GetUserHandler(callback.ChatterID).OnChatRoomMessage(callback.ChatRoomID, callback.ChatterID, callback.Message); }); #endregion #region Trading msg.Handle<SteamTrading.SessionStartCallback> (callback => { bool started = HandleTradeSessionStart (callback.OtherClient); if (!started) Log.Error ("Could not start the trade session."); else Log.Debug ("SteamTrading.SessionStartCallback handled successfully. Trade Opened."); }); msg.Handle<SteamTrading.TradeProposedCallback> (callback => { if (CheckCookies() == false) { SteamTrade.RespondToTrade(callback.TradeID, false); return; } try { tradeManager.InitializeTrade(SteamUser.SteamID, callback.OtherClient); } catch (WebException we) { SteamFriends.SendChatMessage(callback.OtherClient, EChatEntryType.ChatMsg, "Trade error: " + we.Message); SteamTrade.RespondToTrade(callback.TradeID, false); return; } catch (Exception) { SteamFriends.SendChatMessage(callback.OtherClient, EChatEntryType.ChatMsg, "Trade declined. Could not correctly fetch your backpack."); SteamTrade.RespondToTrade(callback.TradeID, false); return; } //if (tradeManager.OtherInventory.IsPrivate) //{ // SteamFriends.SendChatMessage(callback.OtherClient, // EChatEntryType.ChatMsg, // "Trade declined. Your backpack cannot be private."); // SteamTrade.RespondToTrade (callback.TradeID, false); // return; //} if (CurrentTrade == null && GetUserHandler (callback.OtherClient).OnTradeRequest ()) SteamTrade.RespondToTrade (callback.TradeID, true); else SteamTrade.RespondToTrade (callback.TradeID, false); }); msg.Handle<SteamTrading.TradeResultCallback> (callback => { if (callback.Response == EEconTradeResponse.Accepted) { Log.Debug("Trade Status: {0}", callback.Response); Log.Info ("Trade Accepted!"); GetUserHandler(callback.OtherClient).OnTradeRequestReply(true, callback.Response.ToString()); } else { Log.Warn("Trade failed: {0}", callback.Response); CloseTrade (); GetUserHandler(callback.OtherClient).OnTradeRequestReply(false, callback.Response.ToString()); } }); #endregion #region Disconnect msg.Handle<SteamUser.LoggedOffCallback> (callback => { IsLoggedIn = false; Log.Warn("Logged off Steam. Reason: {0}", callback.Result); }); msg.Handle<SteamClient.DisconnectedCallback> (callback => { log.Warn(IsLoggedIn.ToString()); if(IsLoggedIn) { IsLoggedIn = false; CloseTrade(); Log.Warn("Disconnected from Steam Network!"); } Log.Warn("Will attempt reconnect in 15 seconds"); Thread.Sleep(15000); //added a delay to attempted reconnection every 15 seconds Log.Warn("Attempting Reconnect"); SteamClient.Connect (); Log.Warn("Bot should be reconnecting"); }); #endregion #region Notifications msg.Handle<SteamBot.SteamNotifications.NotificationCallback>(callback => { //currently only appears to be of trade offer if (callback.Notifications.Count != 0) { foreach (var notification in callback.Notifications) { Log.Info(notification.UserNotificationType + " notification"); } } // Get offers only if cookies are valid if (CheckCookies()) tradeOfferManager.GetOffers(); }); msg.Handle<SteamBot.SteamNotifications.CommentNotificationCallback>(callback => { //various types of comment notifications on profile/activity feed etc //Log.Info("received CommentNotificationCallback"); //Log.Info("New Commments " + callback.CommentNotifications.CountNewComments); //Log.Info("New Commments Owners " + callback.CommentNotifications.CountNewCommentsOwner); //Log.Info("New Commments Subscriptions" + callback.CommentNotifications.CountNewCommentsSubscriptions); }); #endregion }
void HandleSteamMessage(CallbackMsg msg) { log.Debug(msg.ToString()); #region Login msg.Handle <SteamClient.ConnectedCallback> (callback => { log.Debug("Connection Callback: " + callback.Result); if (callback.Result == EResult.OK) { UserLogOn(); } else { log.Error("Failed to connect to Steam Community, trying again..."); SteamClient.Connect(); } }); msg.Handle <SteamUser.LoggedOnCallback> (callback => { log.Debug("Logged On Callback: " + callback.Result); if (callback.Result == EResult.OK) { MyLoginKey = callback.WebAPIUserNonce; } else { log.Error("Login Error: " + callback.Result); } if (callback.Result == EResult.AccountLogonDenied) { log.Interface("This account is SteamGuard enabled. Enter the code via the `auth' command."); // try to get the steamguard auth code from the event callback var eva = new SteamGuardRequiredEventArgs(); FireOnSteamGuardRequired(eva); if (!String.IsNullOrEmpty(eva.SteamGuard)) { logOnDetails.AuthCode = eva.SteamGuard; } else { logOnDetails.AuthCode = Console.ReadLine(); } } if (callback.Result == EResult.InvalidLoginAuthCode) { log.Interface("The given SteamGuard code was invalid. Try again using the `auth' command."); logOnDetails.AuthCode = Console.ReadLine(); } }); msg.Handle <SteamUser.LoginKeyCallback> (callback => { while (true) { bool authd = SteamWeb.Authenticate(callback, SteamClient, out sessionId, out token, MyLoginKey); if (authd) { log.Success("User Authenticated!"); tradeManager = new TradeManager(apiKey, sessionId, token); tradeManager.SetTradeTimeLimits(MaximumTradeTime, MaximiumActionGap, TradePollingInterval); tradeManager.OnTimeout += OnTradeTimeout; break; } else { log.Warn("Authentication failed, retrying in 2s..."); Thread.Sleep(2000); } } if (Trade.CurrentSchema == null) { log.Info("Downloading Schema..."); Trade.CurrentSchema = Schema.FetchSchema(apiKey); log.Success("Schema Downloaded!"); } if (BotControlClass == "SteamBot.KeybankHandler") { //string newName = DisplayNamePrefix + DisplayName + " B>6 S>6.11"; string newName = DisplayNamePrefix + DisplayName + String.Format(" B>{0} S>{1}", Convert.ToString(clsFunctions.GetKeyBuyPrice()), Convert.ToString(clsFunctions.GetKeySellPrice())); SteamFriends.SetPersonaName(newName); } else { SteamFriends.SetPersonaName(DisplayNamePrefix + DisplayName); } SteamFriends.SetPersonaState(EPersonaState.Online); log.Success("Steam Bot Logged In Completely!"); IsLoggedIn = true; this.SteamFriends.JoinChat(< GROUPCHATID >);//Gamem Tradeing Services if (BotControlClass != "SteamBot.RaffleDonatoinUserHandler") { this.SteamFriends.JoinChat(< GROUPID >); //TF2 Exchange this.SteamFriends.JoinChat(< GROUPID >); //TF2 Alliance } uid = < GROUPID >; InGroupChat = true; try { clsFunctions.AddBotToList(this, logOnDetails.Username); GetInventory(); } catch { } GetUserHandler(SteamClient.SteamID).OnLoginCompleted(); }); // handle a special JobCallback differently than the others if (msg.IsType <SteamClient.JobCallback <SteamUser.UpdateMachineAuthCallback> >()) { msg.Handle <SteamClient.JobCallback <SteamUser.UpdateMachineAuthCallback> >( jobCallback => OnUpdateMachineAuthCallback(jobCallback.Callback, jobCallback.JobID) ); } #endregion #region Friends msg.Handle <SteamFriends.FriendsListCallback>(callback => { foreach (SteamFriends.FriendsListCallback.Friend friend in callback.FriendList) { if (friend.SteamID.AccountType == EAccountType.Clan) { if (!groups.Contains(friend.SteamID)) { groups.Add(friend.SteamID); if (friend.Relationship == EFriendRelationship.RequestRecipient) { if (GetUserHandler(friend.SteamID).OnGroupAdd()) { AcceptGroupInvite(friend.SteamID); } else { DeclineGroupInvite(friend.SteamID); } } } else { if (friend.Relationship == EFriendRelationship.None) { groups.Remove(friend.SteamID); } } } else if (friend.SteamID.AccountType != EAccountType.Clan) { if (!friends.Contains(friend.SteamID)) { friends.Add(friend.SteamID); if (friend.Relationship == EFriendRelationship.RequestRecipient && GetUserHandler(friend.SteamID).OnFriendAdd()) { CreateFriendFile(friend.SteamID); if (friends.Count >= 200) { RemoveUnactiveFriends(); } SteamFriends.AddFriend(friend.SteamID); } } else { if (friend.Relationship == EFriendRelationship.None) { RemoveFriendFile(friend.SteamID); friends.Remove(friend.SteamID); GetUserHandler(friend.SteamID).OnFriendRemove(); } } } } }); msg.Handle <SteamFriends.FriendMsgCallback> (callback => { EChatEntryType type = callback.EntryType; if (callback.EntryType == EChatEntryType.ChatMsg) { log.Info(String.Format("Chat Message from {0}: {1}", SteamFriends.GetFriendPersonaName(callback.Sender), callback.Message )); GetUserHandler(callback.Sender).OnMessage(callback.Message, type); } }); #endregion #region Group Chat msg.Handle <SteamFriends.ChatMsgCallback>(callback => { GetUserHandler(callback.ChatterID).OnChatRoomMessage(callback.ChatRoomID, callback.ChatterID, callback.Message); }); #endregion #region Trading msg.Handle <SteamTrading.SessionStartCallback> (callback => { bool started = HandleTradeSessionStart(callback.OtherClient); if (!started) { log.Error("Could not start the trade session."); } else { log.Debug("SteamTrading.SessionStartCallback handled successfully. Trade Opened."); } }); msg.Handle <SteamTrading.TradeProposedCallback> (callback => { try { tradeManager.InitializeTrade(SteamUser.SteamID, callback.OtherClient); } catch (WebException we) { SteamFriends.SendChatMessage(callback.OtherClient, EChatEntryType.ChatMsg, "Trade error: " + we.Message); SteamTrade.RespondToTrade(callback.TradeID, false); return; } catch (Exception) { SteamFriends.SendChatMessage(callback.OtherClient, EChatEntryType.ChatMsg, "Trade declined. Could not correctly fetch your backpack."); SteamTrade.RespondToTrade(callback.TradeID, false); return; } //if (tradeManager.OtherInventory.IsPrivate) //{ // SteamFriends.SendChatMessage(callback.OtherClient, // EChatEntryType.ChatMsg, // "Trade declined. Your backpack cannot be private."); // SteamTrade.RespondToTrade (callback.TradeID, false); // return; //} if (CurrentTrade == null && GetUserHandler(callback.OtherClient).OnTradeRequest()) { SteamTrade.RespondToTrade(callback.TradeID, true); } else { SteamTrade.RespondToTrade(callback.TradeID, false); } }); msg.Handle <SteamTrading.TradeResultCallback> (callback => { if (callback.Response == EEconTradeResponse.Accepted) { log.Debug("Trade Status: " + callback.Response); log.Info("Trade Accepted!"); GetUserHandler(callback.OtherClient).OnTradeRequestReply(true, callback.Response.ToString()); } else { log.Warn("Trade failed: " + callback.Response); CloseTrade(); GetUserHandler(callback.OtherClient).OnTradeRequestReply(false, callback.Response.ToString()); } }); #endregion #region Disconnect msg.Handle <SteamUser.LoggedOffCallback> (callback => { IsLoggedIn = false; log.Warn("Logged Off: " + callback.Result); }); msg.Handle <SteamClient.DisconnectedCallback> (callback => { IsLoggedIn = false; CloseTrade(); log.Warn("Disconnected from Steam Network!"); SteamClient.Connect(); }); #endregion }