public Status AddUser(User user) { if (user == null) { s_log.ErrorFormat("UserList.AddUser(): User is null."); return Status.Failure; } try { lock (m_userLookup) { m_userLookup.Add(user.UserId, user); } return Status.Success; } catch (ArgumentException e) { s_log.ErrorFormat("UserID {0} already in UserLst ({1})", user.UserId, e.Message); lock (m_userLookup) { m_userLookup[user.UserId] = user; } return Status.NoResult; } catch (Exception e) { s_log.ErrorFormat("Exception adding User {0}: {1}", user.ToString(), e.Message); return Status.Failure; } }
public PmSendWindow(Window owner, SenescoController controller, User targetUser, string replyText) { WindowUtils.ConfigureChildWindow(owner, this); InitializeComponent(); WindowUtils.RestoreWindowPosition(this, owner, WindowUtils.DefaultPosition.CenterOnParent); m_controller = controller; m_targetUser = targetUser; if (m_targetUser != null) m_recipientLabel.Content = String.Format("Recipient: {0}", m_targetUser.Username); // Hide the quote and splitter grid rows if there is no text to quote. if (String.IsNullOrEmpty(replyText)) { m_quoteRow.Height = new GridLength(0); m_splitterRow.Height = new GridLength(0); } else { // Otherwise put the reply text in its text box. m_replyTextBox.AppendText(replyText); // And slightly extend the window height. //this.Height *= 1.2; } }
public User GetUser() { User user = new User(); user.UserId = m_userSocket.Value.Value; //user.IconId = Icon.Value.Value; //user.Username = Nick.Value.Value; //user.Flags = UserStatus.Value.Value; return user; }
public UserConfig(Window owner, User user) { WindowUtils.ConfigureChildWindow(owner, this); InitializeComponent(); WindowUtils.RestoreWindowPosition(this, owner, WindowUtils.DefaultPosition.CenterOnParent); // Initialize the fields with the given user. SetFieldsFromUser(user); }
private void ReplyButton_Click(object sender, RoutedEventArgs e) { User replyUser = new User(); replyUser.UserId = m_sendingUserId; replyUser.Username = m_sendingNick; string replyText = WindowUtils.TextFromRichTextBox(m_pmText); PmSendWindow psw = new PmSendWindow(m_owner, m_controller, replyUser, replyText); psw.Show(); this.Close(); }
private void SetFieldsFromUser(User user) { if (user == null) return; m_nick.Text = user.Username; m_icon.Text = user.IconId.ToString(); m_ignorePrivateMsgs.IsChecked = user.IgnorePrivateMsgs; m_ignorePrivateChat.IsChecked = user.IgnorePrivateChat; m_ignoreAutoResponse.Text = user.IgnoreAutoResponse; }
private User CreateUserFromFields() { User user = new User(); user.Username = m_nick.Text; user.IgnorePrivateMsgs = m_ignorePrivateMsgs.IsChecked.Value; user.IgnorePrivateChat = m_ignorePrivateChat.IsChecked.Value; user.IgnoreAutoResponse = m_ignoreAutoResponse.Text; // If the icon string doesn't parse, set a value that won't pass validation. if (int.TryParse(m_icon.Text, out user.IconId) == false) user.IconId = -1; return user; }
public object Clone() { User user = new User(); // Clone the client fields. user.Username = this.Username; user.IconId = this.IconId; user.IgnorePrivateMsgs = this.IgnorePrivateMsgs; user.IgnorePrivateChat = this.IgnorePrivateChat; user.IgnoreAutoResponse = this.IgnoreAutoResponse; // Clone the server fields too. user.UserId = this.UserId; user.Flags = this.Flags; return user; }
/// <summary> /// Checks if the user settings are different between the current instance /// and the given User instance. /// </summary> /// <param name="user">The User to compare with.</param> /// <returns>True if the Users are different.</returns> public bool SettingsDiffer(User user) { // Only check the fields that are configured by the user. if (this.Username == user.Username && this.IconId == user.IconId && this.IgnoreAutoResponse == user.IgnoreAutoResponse && this.IgnorePrivateChat == user.IgnorePrivateChat && this.IgnorePrivateMsgs == user.IgnorePrivateMsgs) { return false; } else { return true; } }
public Status RemoveUser(User user) { if (user == null) { s_log.ErrorFormat("UserList.RemoveUser(): User is null."); return Status.Failure; } lock (m_userLookup) { if (m_userLookup.Remove(user.UserId) == false) { s_log.ErrorFormat("UserList.RemoveUser(): User not found."); return Status.Failure; } } return Status.Success; }
private void SaveButton_Click(object sender, RoutedEventArgs e) { // When saving, create the output user for the caller who invoked // this window to use as output. OutputUser = CreateUserFromFields(); // If the generated user is valid, we're done. if (OutputUser.IsValid()) { this.Close(); return; } // Don't close the window if the values are invalid. //FIXME: use styles to highlight the error fields. if (String.IsNullOrEmpty(m_nick.Text)) { m_nick.Text = "unnamed.senesco"; } else { // If the nick was okay, the icon must be invalid. // This will need better checking if there's more extensive validation. m_icon.Text = "0"; } OutputUser = null; }
public Status Connect(Server server) { if (server == null) return Status.Failure; // If connected to another server, disconnect first. if (m_server != null) m_server.Disconnect(); // If we're connecting to a new server, set up the delegates. // This is typically only the same server during the "auto-reconnect" cycle. if (m_server != server) { m_server = server; // Set up the event delegates for this Server connection. m_server.ProgressUpdated += HandleProgressUpdated; m_server.Connected += HandleConnected; m_server.Disconnected += HandleDisconnected; m_server.ChatReceived += HandleChatReceived; m_server.UserListUpdate += HandleUserListUpdate; m_server.PmReceived += HandlePmReceived; m_server.UserInfoReceived += HandleUserInfoReceived; } // Initiate server connection. if (m_server.Connect() == Status.Failure) { string message = String.Format("Connecting to {0} failed.", m_server.Address); s_log.ErrorFormat(message); LocalChatMessage(message); m_server = null; return Status.Failure; } // Print a message indicating successful connection. LocalChatMessage(String.Format("Connected to '{0}'", m_server.ServerName)); // Send initial transactions. Login login = new Login(m_server.LoginName, m_server.Password, m_server.Nick, m_server.Icon); if (m_server.SendTransaction(login) == Status.Failure) { string message = String.Format("Sending login to server failed."); s_log.ErrorFormat(message); LocalChatMessage(message); m_server = null; return Status.Failure; } // Store initial user settings. m_localUser = new User(); m_localUser.Username = m_server.Nick; m_localUser.IconId = m_server.Icon; return Status.Success; }
/// <summary> /// Call this method to update your user settings on the server. You can /// update your nick, icon number, and ignore flags. For ignoring, you /// can either ignore Private Messages or Private Chats, or both. When /// ignoring such private requests, you can also optionally specify an /// automatic ignore response, which is handled by the server. /// </summary> /// <param name="newNick">Your new nick</param> /// <param name="newIcon">Your new icon number</param> /// <param name="ignorePrivMsgs">If true, ignore PM's</param> /// <param name="ignorePrivChat">If true, ignore PC's</param> /// <param name="autoIgnoreMsg"> /// If provided, send this message to the requestor on your behalf when a request is ignored. /// </param> public Status SetUserInfo(User newUserInfo) { if (m_server == null || m_server.IsConnected == false) { string message = "Cannot set user info: not connected to server."; s_log.ErrorFormat(message); return Status.GetFailure(message); } string error; if (newUserInfo.IsValid(out error) == false) { string message = String.Format("Cannot set user info: {0}.", error); s_log.ErrorFormat(message); return Status.GetFailure(message); } // If not ignoring anything, don't send an ignore message. if (newUserInfo.IgnorePrivateMsgs == false && newUserInfo.IgnorePrivateChat == false) { newUserInfo.IgnoreAutoResponse = null; } SetUserInfo setUserInfo = new SetUserInfo( newUserInfo.Username, newUserInfo.IconId, newUserInfo.IgnorePrivateMsgs, newUserInfo.IgnorePrivateChat, newUserInfo.IgnoreAutoResponse); Status result = m_server.SendTransaction(setUserInfo); // Update the local values, since the server doesn't come back with a response. if (result == Status.Success) m_localUser = newUserInfo; return result; }
public Status SendPrivateMessage(User selectedUser, string message) { if (m_server == null || m_server.IsConnected == false) { s_log.ErrorFormat("Cannot send PM: not connected to server."); return Status.Failure; } if (selectedUser == null) { s_log.ErrorFormat("Cannot send PM: no user specified."); return Status.Failure; } m_soundController.PlaySound(SoundEffect.PmSent); return m_server.SendTransaction(new PmSend(selectedUser.UserId, message)); }
public Status GetUserInfo(User selectedUser) { if (m_server == null || m_server.IsConnected == false) { s_log.ErrorFormat("Cannot get user info: not connected to server."); return Status.Failure; } if (selectedUser == null) { s_log.ErrorFormat("Cannot get user info: no user specified."); return Status.Failure; } return m_server.SendTransaction(new GetUserInfo(selectedUser.UserId)); }
/// <summary> /// Handler for a Transaction response listing the complete userlist. /// NOTE: It is not the responsibility of the Server class to decide how /// the response data is displayed to the user. That is, do NOT /// automatically make this a chat message! /// </summary> private void HandleGetUserList(Transaction userList) { s_log.InfoFormat("Received userlist response."); if (userList == null) return; // Create a new userlist from scratch. List<User> addList = new List<User>(); foreach (HotlineObject obj in userList.Objects) { UserListEntry ule = obj as UserListEntry; if (ule == null) continue; User user = new User(ule); addList.Add(user); } // Send the new full user list as a non-delta list of "adds". OnUserListUpdate(new UserListUpdateEventArgs(addList, null, false)); }