/// <summary> /// /// </summary> /// <param name="title"></param> /// <param name="body"></param> /// <param name="duration"></param> /// <param name="animation"></param> /// <param name="direction"></param> public Notification(string title, string body, int duration, FormAnimator.AnimationMethod animation, FormAnimator.AnimationDirection direction, int scale = -1, string issue = "") { InitializeComponent(); if (duration < 0) { duration = int.MaxValue; } else { duration = duration * 1000; } lifeTimer.Interval = duration; labelTitle.Text = title; labelBody.Text = body; labelTime.Text = DateTime.Now.ToShortTimeString(); if (scale == -1) { scale = Setting.Value.Notification_Scale; } this.Scale(new SizeF((float)(scale) / 100, (float)(scale) / 100)); animation = FormAnimator.AnimationMethod.Slide; _animator = new FormAnimator(this, animation, direction, AnimationSpeed); Region = Region.FromHrgn(NativeMethods.CreateRoundRectRgn(0, 0, Width - 5, Height - 5, 2, 2)); Direction = direction; Issue = issue; }
private void ShowNotification() { int duration; int.TryParse(comboBoxDuration.SelectedItem.ToString(), out duration); if (duration <= 0) { duration = -1; } FormAnimator.AnimationMethod animationMethod = FormAnimator.AnimationMethod.Slide; foreach (FormAnimator.AnimationMethod method in Enum.GetValues(typeof(FormAnimator.AnimationMethod))) { if (string.Equals(method.ToString(), comboBoxAnimation.SelectedItem)) { animationMethod = method; break; } } FormAnimator.AnimationDirection animationDirection = FormAnimator.AnimationDirection.Up; foreach (FormAnimator.AnimationDirection direction in Enum.GetValues(typeof(FormAnimator.AnimationDirection))) { if (string.Equals(direction.ToString(), comboBoxAnimationDirection.SelectedItem)) { animationDirection = direction; break; } } Notification toastNotification = new Notification(textBoxTitle.Text, textBoxBody.Text, duration, animationMethod, animationDirection); PlayNotificationSound(comboBoxSound.Text); toastNotification.Show(); }
/// <summary> /// /// </summary> /// <param name="title"></param> /// <param name="body"></param> /// <param name="duration"></param> /// <param name="animation"></param> /// <param name="direction"></param> public Notification(string title, string body, int duration, FormAnimator.AnimationMethod animation, FormAnimator.AnimationDirection direction, int type) { InitializeComponent(); if (type == 1) { icon_stock.Visible = true; icon_expired.Visible = false; } else { icon_stock.Visible = false; icon_expired.Visible = true; } if (duration < 0) { duration = int.MaxValue; } else { duration = duration * 1000; } lifeTimer.Interval = duration; labelTitle.Text = title; labelBody.Text = body; _animator = new FormAnimator(this, animation, direction, 500); Region = Region.FromHrgn(NativeMethods.CreateRoundRectRgn(0, 0, Width - 5, Height - 5, 15, 15)); }
/// <summary> /// /// </summary> /// <param name="title"></param> /// <param name="body"></param> /// <param name="duration"></param> /// <param name="animation"></param> /// <param name="direction"></param> public Notification(string title, string body, int duration, FormAnimator.AnimationMethod animation, FormAnimator.AnimationDirection direction, PictureBox avatar = null) { InitializeComponent(); if (duration < 0) { duration = int.MaxValue; } else { duration = duration * 1000; } this.lifeTimer.Interval = duration; this.labelTitle.Text = title; this.labelBody.Text = body; if (avatar != null) { avatarBox.Image = avatar.Image; } else { avatarBox.Image = avatarBox.InitialImage; } this.animator = new FormAnimator(this, animation, direction, 500); Region = Region.FromHrgn(NativeMethods.CreateRoundRectRgn(0, 0, Width - 5, Height - 5, 20, 20)); }
public Notification(string title, string body, int duration, FormAnimator.AnimationMethod animation, FormAnimator.AnimationDirection direction, int width = 0, int height = 0) { InitializeComponent(); if (duration < 0) { duration = int.MaxValue; } else { duration = duration * 1000; } lifeTimer.Interval = duration; if (width > 0) { this.Width = width; } if (width > 0) { this.Height = height; } _animator = new FormAnimator(this, animation, direction, 500); }
public override void OnMessage(string message, EChatEntryType type) { Bot.main.Invoke((Action)(() => { var other = Bot.SteamFriends.GetFriendPersonaName(OtherSID); var opened = OpenChat(OtherSID); string date = "[" + DateTime.Now + "] "; string name = other + ": "; foreach (TabPage tab in Friends.chat.ChatTabControl.TabPages) { if ((SteamID)tab.Tag == OtherSID) { foreach (var item in tab.Controls) { Friends.chat.chatTab = (ChatTab)item; } } } int islink; islink = 0; if (message.Contains("http://") || (message.Contains("https://")) || (message.Contains("www.")) || (message.Contains("ftp."))) { string[] stan = message.Split(' '); foreach (string word in stan) { if (word.Contains("http://") || (word.Contains("https://")) || (word.Contains("www.")) || (word.Contains("ftp."))) { if (word.Contains(".")) { islink = 1; } } } } if (islink == 1) { Friends.chat.chatTab.UpdateChat("[INFO] ", "WARNING: ", "Be cautious when clicking unknown links."); } Friends.chat.chatTab.UpdateChat(date, name, message); new Thread(() => { if (opened || !Chat.hasFocus) { int duration = 3; FormAnimator.AnimationMethod animationMethod = FormAnimator.AnimationMethod.Slide; FormAnimator.AnimationDirection animationDirection = FormAnimator.AnimationDirection.Up; string title = Bot.SteamFriends.GetFriendPersonaName(OtherSID); Notification toastNotification = new Notification(title, Util.GetColorFromPersonaState(Bot, OtherSID), message, duration, animationMethod, animationDirection, Friends.chat.chatTab.avatarBox, new Action(() => { Friends.chat.BringToFront(); })); Bot.main.Invoke((Action)(() => { toastNotification.Show(); })); } }).Start(); })); }
public void TradeButtonMode(int _mode, uint _tradeID = 0) { int mode = _mode; tradeID = _tradeID; switch (mode) { case 1: // not in trade - "Invite to trade" tradeMode = 1; button_trade.Text = "Invite to Trade"; button_trade.Enabled = true; break; case 2: // User sent trade request - "Cancel trade request" tradeMode = 2; button_trade.Text = "Cancel Trade Request"; break; case 3: // Other sent trade request - "Accept trade request" button_trade.Enabled = true; tradeMode = 3; text_log.AppendText("[" + DateTime.Now + "] " + steam_name.Text + " has requested to trade with you." + Environment.NewLine); if (Friends.keepLog) { AppendLog(userSteamId, "[" + DateTime.Now + "] " + steam_name.Text + " has requested to trade with you." + Environment.NewLine); } text_log.ScrollToCaret(); if (!Chat.hasFocus) { try { string soundsFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory); string soundFile = Path.Combine(soundsFolder + "message.wav"); using (System.Media.SoundPlayer player = new System.Media.SoundPlayer(soundFile)) { player.Play(); } } catch (Exception e) { Console.WriteLine(e.Message); } Chat.Flash(); } int duration = 3; FormAnimator.AnimationMethod animationMethod = FormAnimator.AnimationMethod.Slide; FormAnimator.AnimationDirection animationDirection = FormAnimator.AnimationDirection.Up; string title = steam_name.Text; Notification toastNotification = new Notification(title, Util.GetColorFromPersonaState(bot, userSteamId), "has requested to trade with you.", duration, animationMethod, animationDirection, Friends.chat.chatTab.avatarBox, new Action(() => { Friends.chat.BringToFront(); })); toastNotification.Show(); button_trade.Text = "Accept Trade Request"; break; } }
public FormAnimation() { InitializeComponent(); FormAnimator.AnimationMethod animation = FormAnimator.AnimationMethod.Slide; FormAnimator.AnimationDirection direction = FormAnimator.AnimationDirection.Right; _animator = new FormAnimator(this, animation, direction, 500); this.Shown += FormAnimation_Shown; }
public void ShowSuccess(string title, string text, int duration = -1, FormAnimator.AnimationMethod animationMethod = FormAnimator.AnimationMethod.Fade, FormAnimator.AnimationDirection animationDirection = FormAnimator.AnimationDirection.Left) { if (duration <= 0) { duration = -1; } var toastNotification = new Notification(title, text, duration, animationMethod, animationDirection, NotificationType.Success); PlayNotificationSound("garden"); toastNotification.Show(); }
/// <summary> /// /// </summary> /// <param name="title"></param> /// <param name="body"></param> /// <param name="duration"></param> /// <param name="animation"></param> /// <param name="direction"></param> public FixedNotification(string title, string body, FormAnimator.AnimationMethod animation, FormAnimator.AnimationDirection direction) { InitializeComponent(); labelTitle.Text = title; labelBody.Text = body; _animator = new FormAnimator(this, animation, direction, 500); Region = Region.FromHrgn(NativeMethods.CreateRoundRectRgn(0, 0, Width - 5, Height - 5, 20, 20)); }
/// <summary> /// /// </summary> /// <param name="title"></param> /// <param name="body"></param> /// <param name="duration"></param> /// <param name="animation"></param> /// <param name="direction"></param> public Notification(WordsNotifier.Form1 form, int duration, FormAnimator.AnimationMethod animation, FormAnimator.AnimationDirection direction, Position position) { InitializeComponent(); _mainForm = form; if (duration < 0) { duration = int.MaxValue; } else { duration = duration * 1000; } WordsNotifier.Word w = _mainForm.GetWord(true); switch (_mainForm.GetMode()) { case WordsNotifier.Mode.Default: { _showFullWords = true; labelTitle.Text = w.word + "[" + w.part + "]"; labelBody.Text = w.translation; break; } case WordsNotifier.Mode.HideTranslation: { _showFullWords = false; labelTitle.Text = w.word + "[" + w.part + "]"; labelBody.Text = "[click to show translation]"; break; } case WordsNotifier.Mode.Inverse: { _showFullWords = false; labelTitle.Text = w.translation + "[" + w.part + "]"; labelBody.Text = "[click to show the word]"; break; } } lifeTimer.Interval = duration; _position = position; _animator = new FormAnimator(this, animation, direction, 500); _hrgn = NativeMethods.CreateRoundRectRgn(0, 0, Width - 5, Height - 5, 20, 20); Region = Region.FromHrgn(_hrgn); }
public MainForm() { //StartPosition = FormStartPosition.CenterScreen; // Set form settings here. MinimumSize = new Size(1000, 700); this.WindowState = FormWindowState.Maximized; Icon = Properties.Resources.nethis56; Title = WbTitle; Subtitle = WbSubtitle; //this.CanMaximize = true; //this.CanMinimize = true; this.BeforeBrowse -= MainForm_BeforeBrowse; this.BeforeDownload -= MainForm_BeforeDownload; this.DownloadUpdated -= MainForm_DownloadUpdated; this.BeforeBrowse += MainForm_BeforeBrowse; this.BeforeDownload += MainForm_BeforeDownload; this.DownloadUpdated += MainForm_DownloadUpdated; // Set up settings for BorderlessWindow style. BorderlessWindowProperties.BorderEffect = BorderEffect.BorderLine; BorderlessWindowProperties.ShadowEffect = ShadowEffect.Shadow; BorderlessWindowProperties.ShadowColor = Color.DimGray; // Customize the Splash with Mask property. CustomizeMaskPanel(); Thread thread = new Thread(() => { try { RunServiceProxy.MonitorProxyRun(); } catch (Exception ex) { } }); //thread.SetApartmentState(ApartmentState.STA); thread.Start(); FormAnimator.AnimationMethod animation = FormAnimator.AnimationMethod.Slide; FormAnimator.AnimationDirection direction = FormAnimator.AnimationDirection.Up; this.notification_Btn = new Notification_Btn("浏览器", "加载完成", -1, animation, direction, 0); }
//************************************************************************************* // Paramètre message, titre,durée obligatoire // Animation et direction facultatifs public static bool Show(String message, String titre, int duree, FormAnimator.AnimationMethod animationMethod = FormAnimator.AnimationMethod.Slide, FormAnimator.AnimationDirection animationDirection = FormAnimator.AnimationDirection.Up) { Notification maNotification = new Notification ( titre, // un titre message, // Le texte de la notification duree, // La durée en seconde de la visibilité de la notification animationMethod, // Le mouvement d'appartion du texte animationDirection // Le sens d'apparition de la notification ); maNotification.Show(); return(true); }
/// <summary> /// /// </summary> /// <param name="title"></param> /// <param name="body"></param> /// <param name="duration"></param> /// <param name="animation"></param> /// <param name="direction"></param> public Notification(string title, string body, int duration, FormAnimator.AnimationMethod animation, FormAnimator.AnimationDirection direction) { InitializeComponent(); if (duration < 0) { duration = int.MaxValue; } lifeTimer.Interval = duration; labelTitle.Text = title; labelBody.Text = body; _animator = new FormAnimator(this, animation, direction, 500); Region = Region.FromHrgn(NativeMethods.CreateRoundRectRgn(0, 0, Width - 5, Height - 5, 20, 20)); }
public override void OnTradeMessage(string message) { Bot.main.Invoke((Action)(() => { string send = Bot.SteamFriends.GetFriendPersonaName(OtherSID) + ": " + message + " [" + DateTime.Now.ToLongTimeString() + "]\r\n"; ShowTrade.UpdateChat(send); ChatTab.AppendLog(OtherSID, "[Trade Chat] " + send); if (!ShowTrade.focused) { int duration = 3; FormAnimator.AnimationMethod animationMethod = FormAnimator.AnimationMethod.Slide; FormAnimator.AnimationDirection animationDirection = FormAnimator.AnimationDirection.Up; string title = "[Trade Chat] " + Bot.SteamFriends.GetFriendPersonaName(OtherSID) + " says:"; Notification toastNotification = new Notification(title, message, duration, animationMethod, animationDirection, Friends.chat.chatTab.avatarBox); toastNotification.Show(); } })); }
public NotificationLauncher( int duration , int animation , int direction , string sound ) { this.Opacity = 0.0f; this.ShowInTaskbar = false; m_duration = duration; m_animationMethod = (FormAnimator.AnimationMethod)animation; m_animationDirection = (FormAnimator.AnimationDirection)direction; m_strsound = sound; NamedPipeServer PServer1 = new NamedPipeServer(@"\\.\pipe\EDRNotificator1", 0); PServer1.Start(this); }
public static void Popup(string title, string body, int duration, FormAnimator.AnimationMethod animationMethod, FormAnimator.AnimationDirection animationDirection) { //Enable below if want popup /*************************************************** * if (OpenNotifications.Count == 0) * { * PreparePopupWindows(); * } * * if (CurrentNotificationIdx > OpenNotifications.Count-1) * { * CurrentNotificationIdx = 0; * } * * for (int i = 0; i < maxPopup; i++) * { * //OpenNotifications[i].DoubleBuffered = true; * if (i != CurrentNotificationIdx) * { * //OpenNotifications[i].WindowState = FormWindowState.Minimized; * //OpenNotifications[i].Visible = false; * * } * * } * * //OpenNotifications[OpenNotificationsIdx].cefsharpBrowser.Load("dummy:"); * //OpenNotifications[OpenNotificationsIdx].cefsharpBrowser.LoadHtml(body,"about:blank"); * //OpenNotifications[OpenNotificationsIdx].cefsharpBrowser.LoadHtml("<html><body><h1>Hello world!</h1></body></html>", "http://example/"); * OpenNotifications[CurrentNotificationIdx].cefsharpBrowser.LoadHtml(body, "http://example/"); * NotificationBodies.Add(body); * //OpenNotifications[OpenNotificationsIdx].Visible = true; * //OpenNotifications[OpenNotificationsIdx].WindowState = FormWindowState.Normal; * OpenNotifications[CurrentNotificationIdx].Activate(); * OpenNotifications[CurrentNotificationIdx].cefsharpBrowser.Refresh(); * OpenNotifications[CurrentNotificationIdx].Refresh(); * CurrentNotificationIdx++; * */////////////////////// }
/// <summary> /// /// </summary> /// <param name="title"></param> /// <param name="body"></param> /// <param name="duration"></param> /// <param name="animation"></param> /// <param name="direction"></param> public Notification(string title, string body, int duration, FormAnimator.AnimationMethod animation, FormAnimator.AnimationDirection direction) { InitializeComponent(); if (duration < 0) { duration = int.MaxValue; } else { duration = duration * 1000; } lifeTimer.Interval = duration; labelTitle.Text = title; labelBody.Text = body; if (title == null || title.Length == 0) { labelBody.Location = labelTitle.Location; labelBody.Top += 5; Height = Height - labelTitle.Height; labelTitle.Visible = false; } Graphics g = labelBody.CreateGraphics(); SizeF size = g.MeasureString(body, labelBody.Font); if (Width < size.Width) { Width = (int)size.Width + 20; } if (Height < size.Height) { Height = (int)size.Height + 20; } _animator = new FormAnimator(this, animation, direction, 500); Region = Region.FromHrgn(NativeMethods.CreateRoundRectRgn(0, 0, Width - 5, Height - 5, 20, 20)); }
/// <summary> /// /// </summary> /// <param name="title"></param> /// <param name="body"></param> /// <param name="duration"></param> /// <param name="animation"></param> /// <param name="direction"></param> public Notification(string title, string body, int duration, FormAnimator.AnimationMethod animation, FormAnimator.AnimationDirection direction, NotificationType notificationType) { InitializeComponent(); if (duration < 0) { duration = int.MaxValue; } else { duration = duration * 1000; } lifeTimer.Interval = duration; labelTitle.Text = title; labelBody.Text = body; labelTitle.BackColor = (notificationType == NotificationType.Success) ? Color.FromArgb(0, 0, 192) : Color.Red; this.BackColor = (notificationType == NotificationType.Error) ? Color.FromArgb(255, 128, 128) : Color.FromArgb(128, 128, 255); _animator = new FormAnimator(this, animation, direction, 500); Region = Region.FromHrgn(NativeMethods.CreateRoundRectRgn(0, 0, Width - 5, Height - 5, 20, 20)); }
public static void Popup(string title, string body, int duration, FormAnimator.AnimationMethod animationMethod, FormAnimator.AnimationDirection animationDirection) { Notification toastNotification = new Notification(title, body, duration, animationMethod, animationDirection); toastNotification.Show(); }
void HandleSteamMessage(CallbackMsg msg) { log.Debug(msg.ToString()); msg.Handle <SteamGameCoordinator.MessageCallback>(callback => { Console.WriteLine(callback.EMsg); }); msg.Handle <ClientPlayerNicknameListHandler.ClientPlayerNicknameListCallback>(callback => { foreach (var player in callback.Nicknames) { PlayerNicknames.Add(player.steamid, player.nickname); } }); #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..."); main.Invoke((Action)(() => { main.label_status.Text = "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; main.Invoke((Action)(() => { main.label_status.Text = "Logging in to Steam..."; log.Info("Logging in to Steam..."); })); } if (callback.Result != EResult.OK) { log.Error("Login Error: " + callback.Result); main.Invoke((Action)(() => { main.label_status.Text = "Login Error: " + callback.Result; })); } if (callback.Result == EResult.InvalidPassword) { MetroFramework.MetroMessageBox.Show(main, "Your password is incorrect. Please try again.", "Invalid Password", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); main.wrongAPI = true; main.Invoke((Action)(main.Close)); return; } if (callback.Result == EResult.AccountLogonDenied) { log.Interface("This account is protected by Steam Guard. Enter the authentication code sent to the proper email: "); SteamGuard SteamGuard = new SteamGuard(); SteamGuard.ShowDialog(); logOnDetails.AuthCode = SteamGuard.AuthCode; main.Invoke((Action)(() => { main.label_status.Text = "Logging in..."; })); SteamClient.Connect(); } if (callback.Result == EResult.InvalidLoginAuthCode) { log.Interface("An Invalid Authorization Code was provided. Enter the authentication code sent to the proper email: "); SteamGuard SteamGuard = new SteamGuard("An Invalid Authorization Code was provided.\nEnter the authentication code sent to the proper email: "); SteamGuard.ShowDialog(); logOnDetails.AuthCode = SteamGuard.AuthCode; main.Invoke((Action)(() => { main.label_status.Text = "Logging in..."; })); SteamClient.Connect(); } }); msg.Handle <SteamUser.LoginKeyCallback> (callback => { log.Debug("Handling LoginKeyCallback..."); while (true) { try { log.Info("About to authenticate..."); main.Invoke((Action)(() => { main.label_status.Text = "Authenticating..."; })); bool authd = false; try { authd = SteamWeb.Authenticate(callback, SteamClient, out sessionId, out token, MyLoginKey); } catch (Exception ex) { log.Error("Error on authentication:\n" + ex); } if (authd) { log.Success("User authenticated!"); main.Invoke((Action)(() => { main.label_status.Text = "User authenticated!"; })); tradeManager = new TradeManager(apiKey, sessionId, token); tradeManager.SetTradeTimeLimits(0, 0, TradePollingInterval); tradeManager.OnTimeout += OnTradeTimeout; break; } else { log.Warn("Authentication failed, retrying in 2s..."); main.Invoke((Action)(() => { main.label_status.Text = "Authentication failed, retrying in 2s..."; })); Thread.Sleep(2000); } } catch (Exception ex) { log.Error(ex.ToString()); } } SteamFriends.SetPersonaName(SteamFriends.GetFriendPersonaName(SteamUser.SteamID)); SteamFriends.SetPersonaState(EPersonaState.Online); log.Success("Account Logged In Completely!"); main.Invoke((Action)(() => { main.label_status.Text = "Logged in completely!"; })); 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); IsLoggedIn = true; try { main.Invoke((Action)(main.Hide)); } catch (Exception) { Environment.Exit(1); } new Thread(() => { CDNCache.Initialize(); #if !DEBUG ConnectToGC(13540830642081628378); System.Threading.Thread.Sleep(2000); ConnectToGC(0); #endif while (true) { if (showFriends != null) { var numFriendsDisplayed = showFriends.GetNumFriendsDisplayed(); var numSteamFriendCount = SteamFriends.GetFriendCount(); if (numFriendsDisplayed != -1 && numFriendsDisplayed != ListFriends.Get().Count) { LoadFriends(); showFriends.UpdateFriendsHTML(); } System.Threading.Thread.Sleep(10000); } } }).Start(); }); // 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 msg.Handle <SteamUser.AccountInfoCallback>(callback => { DisplayName = callback.PersonaName; }); #region Friends msg.Handle <SteamFriends.FriendsListCallback>(callback => { foreach (SteamFriends.FriendsListCallback.Friend friend in callback.FriendList) { if (friend.SteamID.AccountType == EAccountType.Clan) { } else { if (!friends.Contains(friend.SteamID)) { new Thread(() => { main.Invoke((Action)(() => { if (showFriends == null && friend.Relationship == EFriendRelationship.RequestRecipient) { log.Info(SteamFriends.GetFriendPersonaName(friend.SteamID) + " has added you."); friends.Add(friend.SteamID); string name = SteamFriends.GetFriendPersonaName(friend.SteamID); string status = SteamFriends.GetFriendPersonaState(friend.SteamID).ToString(); if (!ListFriendRequests.Find(friend.SteamID)) { ListFriendRequests.Add(name, friend.SteamID, status); } } if (showFriends != null && friend.Relationship == EFriendRelationship.RequestRecipient) { log.Info(SteamFriends.GetFriendPersonaName(friend.SteamID) + " has added you."); friends.Add(friend.SteamID); string name = SteamFriends.GetFriendPersonaName(friend.SteamID); string status = SteamFriends.GetFriendPersonaState(friend.SteamID).ToString(); if (!ListFriendRequests.Find(friend.SteamID)) { try { ListFriendRequests.Add(name, friend.SteamID, status); log.Info("Notifying you that " + SteamFriends.GetFriendPersonaName(friend.SteamID) + " has added you."); int duration = 5; FormAnimator.AnimationMethod animationMethod = FormAnimator.AnimationMethod.Slide; FormAnimator.AnimationDirection animationDirection = FormAnimator.AnimationDirection.Up; Notification toastNotification = new Notification(name, Util.GetColorFromPersonaState(this, friend.SteamID), "has sent you a friend request.", duration, animationMethod, animationDirection); toastNotification.Show(); try { string soundsFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory); string soundFile = Path.Combine(soundsFolder + "trade_message.wav"); using (System.Media.SoundPlayer player = new System.Media.SoundPlayer(soundFile)) { player.Play(); } } catch (Exception e) { Console.WriteLine(e.Message); } } catch { Console.WriteLine("Friends list hasn't loaded yet..."); } } } })); }).Start(); } else { if (friend.Relationship == EFriendRelationship.None) { friends.Remove(friend.SteamID); GetUserHandler(friend.SteamID).OnFriendRemove(); RemoveUserHandler(friend.SteamID); } } } } LoadFriends(); }); msg.Handle <SteamFriends.PersonaStateCallback>(callback => { var status = callback.State; var sid = callback.FriendID; ListFriends.UpdateStatus(sid, status.ToString()); ListFriends.UpdateName(sid, SteamFriends.GetFriendPersonaName(sid)); GetUserHandler(sid).UpdatePersonaState(); if (showFriends != null) { showFriends.UpdateState(); showFriends.UpdateFriendHTML(sid); } }); msg.Handle <SteamFriends.FriendMsgCallback>(callback => { EChatEntryType type = callback.EntryType; if (type == EChatEntryType.Typing) { var name = SteamFriends.GetFriendPersonaName(callback.Sender); GetUserHandler(callback.Sender).SetChatStatus(name + " is typing..."); System.Threading.Thread.Sleep(30000); GetUserHandler(callback.Sender).SetChatStatus(""); } if (type == EChatEntryType.ChatMsg) { GetUserHandler(callback.Sender).SetChatStatus(""); GetUserHandler(callback.Sender).OnMessage(callback.Message, type); } }); msg.Handle <SteamFriends.ChatMsgCallback>(callback => { Console.WriteLine(SteamFriends.GetFriendPersonaName(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 { SteamTrade.RespondToTrade(callback.TradeID, false); return; } //if (CurrentTrade == null && GetUserHandler (callback.OtherClient).OnTradeRequest ()) if (CurrentTrade == null) { GetUserHandler(callback.OtherClient).SendTradeState(callback.TradeID); } else { SteamTrade.RespondToTrade(callback.TradeID, false); } }); msg.Handle <SteamTrading.TradeResultCallback>(callback => { //log.Debug ("Trade Status: " + callback.Response); if (callback.Response == EEconTradeResponse.Accepted) { //log.Info ("Trade Accepted!"); } else if (callback.Response == EEconTradeResponse.Cancel || callback.Response == EEconTradeResponse.ConnectionFailed || callback.Response == EEconTradeResponse.Declined || callback.Response == EEconTradeResponse.AlreadyHasTradeRequest || callback.Response == EEconTradeResponse.AlreadyTrading || callback.Response == EEconTradeResponse.TargetAlreadyTrading || callback.Response == EEconTradeResponse.NoResponse || callback.Response == EEconTradeResponse.TooSoon || callback.Response == EEconTradeResponse.TradeBannedInitiator || callback.Response == EEconTradeResponse.TradeBannedTarget || callback.Response == EEconTradeResponse.NotLoggedIn) { if (callback.Response == EEconTradeResponse.Cancel) { TradeResponse(callback.OtherClient, "had asked to trade with you, but has cancelled their request."); } if (callback.Response == EEconTradeResponse.ConnectionFailed) { TradeResponse(callback.OtherClient, "Lost connection to Steam. Reconnecting as soon as possible..."); } if (callback.Response == EEconTradeResponse.Declined) { TradeResponse(callback.OtherClient, "has declined your trade request."); } if (callback.Response == EEconTradeResponse.AlreadyHasTradeRequest) { TradeResponse(callback.OtherClient, "An error has occurred in sending the trade request."); } if (callback.Response == EEconTradeResponse.AlreadyTrading) { TradeResponse(callback.OtherClient, "You are already in a trade so you cannot trade someone else."); } if (callback.Response == EEconTradeResponse.TargetAlreadyTrading) { TradeResponse(callback.OtherClient, "You cannot trade the other user because they are already in trade with someone else."); } if (callback.Response == EEconTradeResponse.NoResponse) { TradeResponse(callback.OtherClient, "did not respond to the trade request."); } if (callback.Response == EEconTradeResponse.TooSoon) { TradeResponse(callback.OtherClient, "It is too soon to send a new trade request. Try again later."); } if (callback.Response == EEconTradeResponse.TradeBannedInitiator) { TradeResponse(callback.OtherClient, "You are trade-banned and cannot trade."); } if (callback.Response == EEconTradeResponse.TradeBannedTarget) { TradeResponse(callback.OtherClient, "You cannot trade with this person because they are trade-banned."); } if (callback.Response == EEconTradeResponse.NotLoggedIn) { TradeResponse(callback.OtherClient, "Trade failed to initialize because you are not logged in."); } CloseTrade(); } }); #endregion #region Disconnect msg.Handle <SteamUser.LoggedOffCallback> (callback => { IsLoggedIn = false; log.Warn("Logged Off: " + callback.Result); }); msg.Handle <SteamClient.DisconnectedCallback> (callback => { if (IsLoggedIn) { IsLoggedIn = false; CloseTrade(); log.Warn("Disconnected from Steam Network!"); main.Invoke((Action)(() => { main.label_status.Text = "Disconnected from Steam Network! Retrying..."; })); SteamClient.Connect(); main.Invoke((Action)(() => { main.label_status.Text = "Connecting to Steam..."; })); } }); #endregion if (!hasrun && IsLoggedIn) { Thread main = new Thread(GUI); main.Start(); hasrun = true; } }
public override void OnMessage(string message, EChatEntryType type) { if (Bot.main.InvokeRequired) { Bot.main.Invoke((Action)(() => { var other = Bot.SteamFriends.GetFriendPersonaName(OtherSID); OpenChat(OtherSID); string date = "[" + DateTime.Now + "] "; string name = other + ": "; foreach (TabPage tab in Friends.chat.ChatTabControl.TabPages) { if (tab.Text == other) { foreach (var item in tab.Controls) { Friends.chat.chatTab = (ChatTab)item; } } } int islink; islink = 0; if (message.Contains("http://") || (message.Contains("https://")) || (message.Contains("www.")) || (message.Contains("ftp."))) { string[] stan = message.Split(' '); foreach (string word in stan) { if (word.Contains("http://") || (word.Contains("https://")) || (word.Contains("www.")) || (word.Contains("ftp."))) { if (word.Contains(".")) { islink = 1; } } } } if (islink == 1) { Friends.chat.chatTab.UpdateChat("[INFO] ", "WARNING: ", "Do not click on links that you feel that maybe unsafe. Make sure the link is what it should be by looking at it."); } Friends.chat.chatTab.UpdateChat(date, name, message); new Thread(() => { if (!Chat.hasFocus) { int duration = 3; FormAnimator.AnimationMethod animationMethod = FormAnimator.AnimationMethod.Slide; FormAnimator.AnimationDirection animationDirection = FormAnimator.AnimationDirection.Up; string title = Bot.SteamFriends.GetFriendPersonaName(OtherSID) + " says:"; Notification toastNotification = new Notification(title, message, duration, animationMethod, animationDirection, Friends.chat.chatTab.avatarBox); Bot.main.Invoke((Action)(() => { toastNotification.Show(); })); } }).Start(); })); } else { var other = Bot.SteamFriends.GetFriendPersonaName(OtherSID); OpenChat(OtherSID); string date = "[" + DateTime.Now + "] "; string name = other + ": "; foreach (TabPage tab in Friends.chat.ChatTabControl.TabPages) { if (tab.Text == other) { foreach (var item in tab.Controls) { Friends.chat.chatTab = (ChatTab)item; } } } Friends.chat.chatTab.UpdateChat(date, name, message); } }
public static void Popup(string jsonMsg, int duration, FormAnimator.AnimationMethod animationMethod, FormAnimator.AnimationDirection animationDirection) { if (formDummy.InvokeRequired) { NotificationPanel.PopupCallback d = new NotificationPanel.PopupCallback(Popup); formDummy.Invoke(d, new object[] { jsonMsg, duration, animationMethod, animationDirection }); } else { try { NotificationMessage dictMsg = new NotificationMessage(jsonMsg); if (dictMsg.level == "" || dictMsg.contentAsWhole == "true") { if (duration == -1) { dictMsg.duration = duration; } var frmLong = (FormNotificationPanel)getFormByName("FormNotificationPanel"); if (!frmLong.Visible) { NotificationPopup.Popup(dictMsg.title, dictMsg.body, dictMsg.duration, animationMethod, animationDirection); } object[] param = new object[1]; var dictMsgFormatted = dictMsg.GetDictionaryFormatted(); param[0] = Globals.functions.Json_toJsonObj(dictMsgFormatted); NotificationPanel.updateLongNotification(param); } else { var datetime = dictMsg.GetFormattedDateTime(); if (duration == -1) { dictMsg.duration = duration; } NotificationPopup.Popup(dictMsg.title, dictMsg.body, dictMsg.duration, animationMethod, animationDirection); object[] param = new object[1]; var dictMsgFormatted = dictMsg.GetDictionaryFormatted(); param[0] = Globals.functions.Json_toJsonObj(dictMsgFormatted); NotificationPanel.updateLongNotification(param); } Globals.notification_client_numberNow++; } catch (Exception e) { Globals.log.Debug(e.ToString()); } } }
/// <summary> /// /// </summary> /// <param name="channelId"></param> /// <param name="body"></param> /// <param name="durationSeconds"></param> /// <param name="animation"></param> /// <param name="direction"></param> public Notification(string channelId, string channelName, int durationSeconds, FormAnimator.AnimationMethod animation, FormAnimator.AnimationDirection direction) { InitializeComponent(); if (durationSeconds < 0) { durationSeconds = int.MaxValue; } else { durationSeconds = durationSeconds * 1000; } lifeTimer.Interval = durationSeconds; _channelId = channelId; labelTitle.Text = channelName; _animator = new FormAnimator(this, animation, direction, 500); Region = Region.FromHrgn(NativeMethods.CreateRoundRectRgn(0, 0, Width - 5, Height - 5, 20, 20)); htmlBody.Text = "<head>" + "<style>" + " p {margin: 0}" + " .username {font-weight: bold; }" + " .incoming {color: yellow; }" + " .outgoing {color: white; }" + "</style>" + "</head>"; MouseMove += AllControls_MouseMove; foreach (Control control in this.Controls) { control.MouseMove += AllControls_MouseMove; } }
public static void ToastNotification(string header, string body, int duration = -1, FormAnimator.AnimationMethod method = FormAnimator.AnimationMethod.Slide, FormAnimator.AnimationDirection direction = FormAnimator.AnimationDirection.Up, string issue = "") { if (Setting.Value.Notification_WindowsNotification) { if (StaticHandler._Main.trayIcon == null) { StaticHandler._Main.trayIcon = new NotifyIcon() { Icon = Resources.closed, Visible = true }; } StaticHandler._Main.TempIssue = issue; StaticHandler._Main.trayIcon.BalloonTipTitle = header; StaticHandler._Main.trayIcon.BalloonTipText = body; StaticHandler._Main.trayIcon.BalloonTipClicked += new EventHandler(StaticHandler._Main.BalloonTipClick); StaticHandler._Main.trayIcon.ShowBalloonTip(duration); } else { var toastNotification = new Notification(header, body, duration, method, direction, -1, issue); PlayNotificationSound(Setting.Value.Notification_Sound); toastNotification.Show(); } }
public static void Popup(string jsonMsg, int duration, FormAnimator.AnimationMethod animationMethod, FormAnimator.AnimationDirection animationDirection) { // InvokeRequired required compares the thread ID of the // calling thread to the thread ID of the creating thread. // If these threads are different, it returns true. if (formDummy.InvokeRequired) { Notifications.PopupCallback d = new Notifications.PopupCallback(Popup); //formDummy.Invoke(d, new object[] { dictMsg, duration, animationMethod, animationDirection }); formDummy.Invoke(d, new object[] { jsonMsg, duration, animationMethod, animationDirection }); } else { var dictMsg = Globals.functions.Json_toDictionary(jsonMsg); if (!dictMsg.ContainsKey("title")) { dictMsg["title"] = ""; } if (!dictMsg.ContainsKey("content")) { dictMsg["content"] = ""; } if (!dictMsg.ContainsKey("timestamp")) { dictMsg["timestamp"] = ""; } if (!dictMsg.ContainsKey("level")) { dictMsg["level"] = ""; } dictMsg["body"] = dictMsg["content"]; if (dictMsg["level"] == "") { var title = dictMsg["title"]; var body = dictMsg["body"]; int duration2use; if (dictMsg.ContainsKey("timeout")) { Int32.TryParse(dictMsg["timeout"], out duration2use); //duration2use = dictMsg["timeout"]; } else { duration2use = duration; } int width = 0, height = 0; if (dictMsg.ContainsKey("width")) { Int32.TryParse(dictMsg["width"], out width); } if (dictMsg.ContainsKey("height")) { Int32.TryParse(dictMsg["height"], out height); } Notification toastNotification = new Notification(title, body, duration2use, animationMethod, animationDirection, width, height); toastNotification.Show(formDummy); var htmlString = Globals.htmlStringTemplatePure; htmlString = Globals.functions.HtmlWithAbsolutePaths("./ReplaceWithAbsolutePath", htmlString); htmlString = htmlString.Replace("[[body]]", body); var webBrowser1 = toastNotification.Controls["webBrowser1"] as WebBrowser; webBrowser1.DocumentText = htmlString; object[] param = new object[1]; Dictionary <string, string> dictMsgFormatted = new Dictionary <String, String>(); string[] key2copy = { "title", "body", "timestamp" }; foreach (string key in key2copy) { dictMsgFormatted.Add(key, dictMsg[key]);; } param[0] = Globals.functions.Json_toJson(dictMsgFormatted); Notifications.updateLongNotification(param); } else { //this.textBox1.Text = text; //FormDummy df = new FormDummy(); //df.Text = title; //df.Show(formDummy); var title = dictMsg["title"]; //var body = data; var body = dictMsg["body"]; var datetime = ""; if (dictMsg.ContainsKey("timestamp")) { datetime = dictMsg["timestamp"]; var datesplit = datetime.Split(' '); if (datesplit[0] == DateTime.Now.ToString("yyyy-MM-dd")) { var datetimeArray = datesplit[1].Split(':'); datetime = datetimeArray[0] + ":" + datetimeArray[1]; } } else { datetime = ""; } int duration2use; if (dictMsg.ContainsKey("timeout")) { Int32.TryParse(dictMsg["timeout"], out duration2use); //duration2use = dictMsg["timeout"]; } else { duration2use = duration; } Notification toastNotification = new Notification(title, body, duration2use, animationMethod, animationDirection); if (Globals.notification_dialog_isTransparent) { toastNotification.Opacity = Globals.notification_dialog_opacity; } else { toastNotification.Opacity = 1; } toastNotification.Show(formDummy); var htmlString = Globals.htmlStringTemplate; #if DEBUG //htmlString = File.ReadAllText(@"\\VBOXSVR\SharedLocal\AMIVOICE\projects\AmivoiceWatcher\amivoice_watcher\AmiVoiceWatcher2\AmivoiceWatcherDotNet\AmivoiceWatcherDotNet\_Src\Template\NotificationTemplate.html"); #endif htmlString = Globals.functions.HtmlWithAbsolutePaths("./ReplaceWithAbsolutePath/", htmlString); htmlString = htmlString.Replace("[[messageJson]]", Globals.functions.Json_toJson(jsonMsg)); htmlString = htmlString.Replace("[[title]]", title); htmlString = htmlString.Replace("[[body]]", body); htmlString = htmlString.Replace("[[datetime]]", datetime); var backgroundColor = "#e3f7fc"; var borderColor = "#8ed9f6"; switch (dictMsg["level"]) { case "notice": backgroundColor = "#e3f7fc"; borderColor = "#8ed9f6"; //dictMsg["image"] = Globals.notification_image.notice; break; case "error": backgroundColor = "#ffecec"; borderColor = "#f5aca6"; //dictMsg["image"] = Globals.notification_image.error; break; case "success": backgroundColor = "#e9ffd9"; borderColor = "#a6ca8a"; //dictMsg["image"] = Globals.notification_image.success; break; case "warning": backgroundColor = "#fff8c4"; borderColor = "#f2c779"; //dictMsg["image"] = Globals.notification_image.warning; break; case "question": backgroundColor = "#fff8c4"; borderColor = "#f2c779"; //dictMsg["image"] = Globals.notification_image.question; break; case "custom": backgroundColor = Globals.functions.Color2HexConverter(Globals.notification_dialog_backgroundColor); //borderColor = Globals.functions.Color2HexConverter(ControlPaint.Dark(Globals.notification_dialog_backgroundColor)); borderColor = Globals.functions.Color2HexConverter(Globals.functions.DarkerColor(Globals.notification_dialog_backgroundColor, 90f)); break; //default: // htmlString = htmlString.Replace("[[title]]", title); } htmlString = htmlString.Replace("[[background-color]]", backgroundColor); htmlString = htmlString.Replace("[[border-color]]", borderColor); string foregroundColor; if (dictMsg["level"] == "custom") { foregroundColor = Globals.functions.Color2HexConverter(Globals.functions.CalculateForegroundColor(Globals.notification_dialog_backgroundColor)); } else { foregroundColor = "#000000"; } htmlString = htmlString.Replace("[[foreground-color]]", foregroundColor); var strImage = "default"; if (dictMsg.ContainsKey("image")) { strImage = dictMsg["image"]; } else if (dictMsg.ContainsKey("icon")) { strImage = dictMsg["icon"]; } if (Globals.notification_show_icon) { if (strImage == "default") { switch (dictMsg["level"]) { case "notice": strImage = Globals.notification_image_file.notice; break; case "error": strImage = Globals.notification_image_file.error; break; case "success": strImage = Globals.notification_image_file.success; break; case "warning": strImage = Globals.notification_image_file.warning; break; case "question": strImage = Globals.notification_image_file.question; break; //default: // htmlString = htmlString.Replace("[[title]]", title); } if (!String.IsNullOrEmpty(strImage)) { htmlString = htmlString.Replace("[[image_src]]", strImage); } } else { if (!strImage.StartsWith("data:")) { strImage = Path.Combine(Globals.PathLocalAppData, "Template", "image", strImage); } htmlString = htmlString.Replace("[[image_src]]", strImage); } } if (dictMsg.ContainsKey("answers")) { htmlString = htmlString.Replace("[[answers]]", dictMsg["answers"]); } else { htmlString = htmlString.Replace("[[answers]]", ""); } if (dictMsg.ContainsKey("link")) { var splitTemp = dictMsg["link"].Split('>'); htmlString = htmlString.Replace("[[linkCaption]]", splitTemp[0]); htmlString = htmlString.Replace("[[link]]", "javascript:window.external.openLinkInDefaultBrowser('" + splitTemp[1] + "')"); } if (dictMsg.ContainsKey("links")) { htmlString = htmlString.Replace("[[links]]", dictMsg["links"]); } var webBrowser1 = toastNotification.Controls["webBrowser1"] as WebBrowser; webBrowser1.DocumentText = htmlString; } //webBrowser1.Navigating += new WebBrowserNavigatingEventHandler(toastNotification.webBrowser1_Navigating); //toastNotification.Height = webBrowser1.Size.Height*2; //webBrowser1.Height = toastNotification.ClientSize.Height; //toastNotification.Height = webBrowser1.Height; //toastNotification.Height = 500; //webBrowser1.Document.Body.ScrollRectangle.Width //Globals.log.Debug("webBrowser1.Height"); //Globals.log.Debug(webBrowser1.Height); //webBrowser1.BringToFront(); //toastNotification.TransparencyKey = System.Drawing.ColorTranslator.FromHtml(backgroundColor); //toastNotification.Opacity = Globals.notification_dialog_opacity; Globals.notification_client_numberNow++; } }
/// <summary> /// /// </summary> /// <param name="title"></param> /// <param name="body"></param> /// <param name="duration"></param> /// <param name="animation"></param> /// <param name="direction"></param> public Notification(int borrowercount, string mess, string emailpassword, string thisemail, int duration, FormAnimator.AnimationMethod animation, FormAnimator.AnimationDirection direction) { InitializeComponent(); allow = 1; if (duration < 0) { duration = int.MaxValue; } else { duration = duration * 1000; } System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath(); gp.AddEllipse(0, 0, BorrPic.Width - 3, BorrPic.Height - 3); Region rg = new Region(gp); BorrPic.Region = rg; lifeTimer.Interval = duration; // Itemname.Text = item; // itemname = item; // Bdate.Text = date; // dateborrowed = date; // Bname.Text = name; dbConnect = new DBConnect(); codeGenerator = new CodeGenerator(); thisemailadd = thisemail; // myConstant = lastname; message1 = mess; emailpass = emailpassword; BorrowersCount.Text = "" + borrowercount; _animator = new FormAnimator(this, animation, direction, 500); Region = Region.FromHrgn(NativeMethods.CreateRoundRectRgn(0, 0, Width - 5, Height - 5, 20, 20)); }
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..."); main.Invoke((Action)(() => { main.label_status.Text = "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) { main.Invoke((Action)(() => { main.label_status.Text = "Logging in to Steam..."; log.Info("Logging in to Steam..."); })); } if (callback.Result != EResult.OK) { log.Error("Login Error: " + callback.Result); main.Invoke((Action)(() => { main.label_status.Text = "Login Error: " + callback.Result; })); } if (callback.Result == EResult.InvalidPassword) { MessageBox.Show("Your password is incorrect. Please try again.", "Invalid Password", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); main.wrongAPI = true; main.Invoke((Action)(main.Close)); return; } if (callback.Result == EResult.AccountLogonDenied) { log.Interface("This account is protected by Steam Guard. Enter the authentication code sent to the proper email: "); SteamGuard SteamGuard = new SteamGuard(); SteamGuard.ShowDialog(); logOnDetails.AuthCode = SteamGuard.AuthCode; main.Invoke((Action)(() => { main.label_status.Text = "Logging in..."; })); } if (callback.Result == EResult.InvalidLoginAuthCode) { log.Interface("An Invalid Authorization Code was provided. Enter the authentication code sent to the proper email: "); SteamGuard SteamGuard = new SteamGuard("An Invalid Authorization Code was provided.\nEnter the authentication code sent to the proper email: "); SteamGuard.ShowDialog(); logOnDetails.AuthCode = SteamGuard.AuthCode; main.Invoke((Action)(() => { main.label_status.Text = "Logging in..."; })); } }); msg.Handle <SteamUser.LoginKeyCallback> (callback => { log.Debug("Handling LoginKeyCallback..."); while (true) { try { log.Info("About to authenticate..."); bool authd = false; try { authd = SteamWeb.Authenticate(callback, SteamClient, out sessionId, out token); } catch (Exception ex) { log.Error("Error on authentication:\n" + ex); } if (authd) { log.Success("User Authenticated!"); main.Invoke((Action)(() => { main.label_status.Text = "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..."); main.Invoke((Action)(() => { main.label_status.Text = "Authentication failed, retrying in 2s..."; })); Thread.Sleep(2000); } } catch (Exception ex) { log.Error(ex.ToString()); } } if (Trade.CurrentSchema == null) { log.Info("Downloading Schema..."); main.Invoke((Action)(() => { main.label_status.Text = "Downloading schema..."; })); try { Trade.CurrentSchema = Schema.FetchSchema(apiKey); } catch (Exception ex) { log.Error(ex.ToString()); MessageBox.Show("I can't fetch the schema! Your API key may be invalid or there may be a problem connecting to Steam. Please make sure you have obtained a proper API key at http://steamcommunity.com/dev/apikey", "Schema Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); main.wrongAPI = true; main.Invoke((Action)(main.Dispose)); return; } log.Success("Schema Downloaded!"); main.Invoke((Action)(() => { main.label_status.Text = "Schema downloaded!"; })); } SteamFriends.SetPersonaName(SteamFriends.GetFriendPersonaName(SteamUser.SteamID)); SteamFriends.SetPersonaState(EPersonaState.Online); log.Success("Account Logged In Completely!"); main.Invoke((Action)(() => { main.label_status.Text = "Logged in completely!"; })); IsLoggedIn = true; displayName = SteamFriends.GetPersonaName(); ConnectToGC(13540830642081628378); Thread.Sleep(500); DisconnectFromGC(); try { main.Invoke((Action)(main.Hide)); } catch (Exception) { Environment.Exit(1); } Thread.Sleep(2500); CDNCache.Initialize(); }); // 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 => { bool newFriend = false; foreach (SteamFriends.FriendsListCallback.Friend friend in callback.FriendList) { if (!friends.Contains(friend.SteamID) && !friend.SteamID.ToString().StartsWith("1")) { new Thread(() => { main.Invoke((Action)(() => { if (showFriends == null && friend.Relationship == EFriendRelationship.RequestRecipient) { log.Info(SteamFriends.GetFriendPersonaName(friend.SteamID) + " has added you."); friends.Add(friend.SteamID); newFriend = true; string name = SteamFriends.GetFriendPersonaName(friend.SteamID); string status = SteamFriends.GetFriendPersonaState(friend.SteamID).ToString(); if (!ListFriendRequests.Find(friend.SteamID)) { ListFriendRequests.Add(name, friend.SteamID, status); } } if (showFriends != null && friend.Relationship == EFriendRelationship.RequestRecipient) { log.Info(SteamFriends.GetFriendPersonaName(friend.SteamID) + " has added you."); friends.Add(friend.SteamID); /*if (friend.Relationship == EFriendRelationship.RequestRecipient && * GetUserHandler(friend.SteamID).OnFriendAdd()) * { * SteamFriends.AddFriend(friend.SteamID); * }*/ newFriend = true; string name = SteamFriends.GetFriendPersonaName(friend.SteamID); string status = SteamFriends.GetFriendPersonaState(friend.SteamID).ToString(); if (!ListFriendRequests.Find(friend.SteamID)) { try { showFriends.NotifyFriendRequest(); ListFriendRequests.Add(name, friend.SteamID, status); log.Info("Notifying you that " + SteamFriends.GetFriendPersonaName(friend.SteamID) + " has added you."); int duration = 5; FormAnimator.AnimationMethod animationMethod = FormAnimator.AnimationMethod.Slide; FormAnimator.AnimationDirection animationDirection = FormAnimator.AnimationDirection.Up; Notification toastNotification = new Notification(name, "has sent you a friend request.", duration, animationMethod, animationDirection); toastNotification.Show(); try { string soundsFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory); string soundFile = Path.Combine(soundsFolder + "trade_message.wav"); using (System.Media.SoundPlayer player = new System.Media.SoundPlayer(soundFile)) { player.Play(); } } catch (Exception e) { Console.WriteLine(e.Message); } showFriends.list_friendreq.SetObjects(ListFriendRequests.Get()); } catch { Console.WriteLine("Friends list hasn't loaded yet..."); } } } })); }).Start(); } else { if (friend.Relationship == EFriendRelationship.None) { friends.Remove(friend.SteamID); GetUserHandler(friend.SteamID).OnFriendRemove(); } } } if (!newFriend && ListFriendRequests.Get().Count == 0) { if (showFriends != null) { showFriends.HideFriendRequests(); } } }); msg.Handle <SteamFriends.PersonaStateCallback>(callback => { var status = callback.State; var sid = callback.FriendID; GetUserHandler(sid).SetStatus(status); ListFriends.UpdateStatus(sid, status.ToString()); }); msg.Handle <SteamFriends.FriendMsgCallback>(callback => { EChatEntryType type = callback.EntryType; if (callback.EntryType == EChatEntryType.Typing) { var name = SteamFriends.GetFriendPersonaName(callback.Sender); GetUserHandler(callback.Sender).SetChatStatus(name + " is typing..."); } else { GetUserHandler(callback.Sender).SetChatStatus(""); } 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); } }); msg.Handle <SteamFriends.ChatMsgCallback>(callback => { Console.WriteLine(SteamFriends.GetFriendPersonaName(callback.ChatterID) + ": " + callback.Message); }); #endregion #region Trading msg.Handle <SteamTrading.SessionStartCallback>(callback => { bool started = HandleTradeSessionStart(callback.OtherClient); //if (!started) //log.Info ("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 ()) if (CurrentTrade == null) { GetUserHandler(callback.OtherClient).SendTradeState(callback.TradeID); } else { SteamTrade.RespondToTrade(callback.TradeID, false); } }); msg.Handle <SteamTrading.TradeResultCallback>(callback => { //log.Debug ("Trade Status: " + callback.Response); if (callback.Response == EEconTradeResponse.Accepted) { //log.Info ("Trade Accepted!"); } if (callback.Response == EEconTradeResponse.Cancel || callback.Response == EEconTradeResponse.ConnectionFailed || callback.Response == EEconTradeResponse.Declined || callback.Response == EEconTradeResponse.Error || callback.Response == EEconTradeResponse.InitiatorAlreadyTrading || callback.Response == EEconTradeResponse.TargetAlreadyTrading || callback.Response == EEconTradeResponse.Timeout || callback.Response == EEconTradeResponse.TooSoon || callback.Response == EEconTradeResponse.TradeBannedInitiator || callback.Response == EEconTradeResponse.TradeBannedTarget || callback.Response == EEconTradeResponse.NotLoggedIn) // uh... { if (callback.Response == EEconTradeResponse.Cancel) { TradeResponse(callback.OtherClient, "had asked to trade with you, but has cancelled their request."); } if (callback.Response == EEconTradeResponse.ConnectionFailed) { TradeResponse(callback.OtherClient, "Lost connection to Steam. Reconnecting as soon as possible..."); } if (callback.Response == EEconTradeResponse.Declined) { TradeResponse(callback.OtherClient, "has declined your trade request."); } if (callback.Response == EEconTradeResponse.Error) { TradeResponse(callback.OtherClient, "An error has occurred in sending the trade request."); } if (callback.Response == EEconTradeResponse.InitiatorAlreadyTrading) { TradeResponse(callback.OtherClient, "You are already in a trade so you cannot trade someone else."); } if (callback.Response == EEconTradeResponse.TargetAlreadyTrading) { TradeResponse(callback.OtherClient, "You cannot trade the other user because they are already in trade with someone else."); } if (callback.Response == EEconTradeResponse.Timeout) { TradeResponse(callback.OtherClient, "did not respond to the trade request."); } if (callback.Response == EEconTradeResponse.TooSoon) { TradeResponse(callback.OtherClient, "It is too soon to send a new trade request. Try again later."); } if (callback.Response == EEconTradeResponse.TradeBannedInitiator) { TradeResponse(callback.OtherClient, "You are trade-banned and cannot trade."); } if (callback.Response == EEconTradeResponse.TradeBannedTarget) { TradeResponse(callback.OtherClient, "You cannot trade with this person because they are trade-banned."); } if (callback.Response == EEconTradeResponse.NotLoggedIn) { TradeResponse(callback.OtherClient, "Trade failed to initialize because you are not logged in."); } 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!"); main.Invoke((Action)(() => { main.label_status.Text = "Disconnected from Steam Network! Retrying..."; })); SteamClient.Connect(); main.Invoke((Action)(() => { main.label_status.Text = "Connecting to Steam..."; })); }); #endregion if (!hasrun && IsLoggedIn) { Thread main = new Thread(GUI); main.Start(); hasrun = true; } }