void CoordinateMessages(User user) { while (true) { try { if (!user.IsSocketConnected()) { this._dispatcher.Invoke(new Action(() => { UsersList.Remove(user); user.Dispose(); }), null); return; } byte[] inf = new byte[4096]; int x = user.Socket.Receive(inf, SocketFlags.None); if (x > 0) { string fileName = $"c{new Random().Next(500)}.dat"; File.WriteAllBytes(fileName, inf); this._dispatcher.Invoke(new Action(() => { System.Runtime.Serialization.IFormatter formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); Stream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read); Message message = (Message)formatter.Deserialize(stream); stream.Close(); switch (message.Category) { case Category.Naming: string newUsername = message.content; user.Username = newUsername; File.Delete(fileName); return; case Category.Message: SendMessageTo(user, message.Receiver_Username, message.File_Name); File.Delete(fileName); return; } })); } } catch (Exception ex) { MessageBox.Show($"Coordinator : {ex.Message.ToString()}"); this._dispatcher.Invoke(new Action(() => { UsersList.Remove(user); user.Dispose(); }), null); return; } } }
private async void DeleteUser(object userObj) { UsersViewModel userD = userObj as UsersViewModel; if (userD != null && userD.isValid()) { bool delRes = false; UsersService us = new UsersService(); delRes = await us.DeleteUserAsync(userD.user); if (delRes) { UsersList.Remove(userD); } } Back(); }
public void StopServer() { if (!this.IsServerActive) { return; } UsersList.Clear(); while (UsersList.Count != 0) { User user = UsersList[0]; UsersList.Remove(user); user.Dispose(); } _socket.Dispose(); _socket = null; this.IsServerActive = false; }
private void RemoveUser(object args) { if (SelectedUsersConfigDialog != null) { var answ = MessageBox.Show("Do you really want to remove selected user?", "Remove user", MessageBoxButton.YesNo, MessageBoxImage.Question); if (answ == MessageBoxResult.Yes) { CloseUser(SelectedUsersConfigDialog); var userToRemove = SelectedUsersConfigDialog as UserViewModel; UsersList.Remove(userToRemove); _model.RemoveUser(userToRemove?.GetModel()); SelectedUsersConfigDialog = null; } } }
public void RemoveUser(UserData memberData) { try { UserData removedMemberData = null; if (UsersList.ContainsKey(memberData.Name)) { UsersList.Remove(memberData.Name, out removedMemberData); } if (removedMemberData != null) { List <GroupData> userGroupMembership = GetUserGroupMembership(memberData); foreach (var group in userGroupMembership) { RemoveUserFromGroup(group, removedMemberData); } } } catch (Exception e) { Console.WriteLine(e.Message); } }
public void DeletePerson(Person person) { Application.Current.Dispatcher.Invoke((Action) delegate { UsersList.Remove(person); }); SaveChanges(); }
private void RemoveUser(Account account) { UsersList.Remove(account); }
private static void Parse(string msg) { PacketFormat Message = JsonConvert.DeserializeObject <PacketFormat>(msg); switch (Message.Option) { case PacketOption.ClientMessage: Log(new UserMessage(Message.Content, UsersList[Message.Guid])); break; case PacketOption.IsServer: Log(new ServerMessage(Message.Content)); break; case PacketOption.NameChange: if (Message.Guid != ClientInfo.Guid) { Log(new ServerMessage($"{UsersList[Message.Guid].Name} has changed their name to {Message.NewName}")); UsersList[Message.Guid].Name = Message.NewName; break; } Log(new ServerMessage($"You changed your name to {ClientInfo.Name}")); break; case PacketOption.UserBanned: if (ClientInfo.Guid == Message.Guid) { Disconnect(); Log(new ServerMessage("You've been banned:")); Log(new ServerMessage(Message.Content)); break; } Log(new ServerMessage($"{UsersList[Message.Guid]} has been banned:")); Log(new ServerMessage(Message.Content)); UsersList.Remove(Message.Guid); break; case PacketOption.UserKicked: if (ClientInfo.Guid == Message.Guid) { Disconnect(); Log(new ServerMessage("You've been kicked:")); Log(new ServerMessage(Message.Content)); break; } Log(new ServerMessage($"{UsersList[Message.Guid]} has been kicked:")); Log(new ServerMessage(Message.Content)); UsersList.Remove(Message.Guid); break; case PacketOption.UserMuted: if (ClientInfo.Guid == Message.Guid) { // disable chat box Log(new ServerMessage("You've been muted:")); } else { Log(new ServerMessage($"{UsersList[Message.Guid]} has been muted:")); } Log(new ServerMessage(Message.Content)); UsersList[Message.Guid].IsMuted = true; break; case PacketOption.UserUnmuted: Log(new ServerMessage($"{UsersList[Message.Guid]} has been unmuted")); UsersList[Message.Guid].IsMuted = false; break; case PacketOption.UserConnected: Log(new ServerMessage($"{Message.Guid} has joined")); UsersList.Add(new User(Message.NewName, Message.Guid)); break; case PacketOption.UserDisconnected: Log(new ServerMessage($"{UsersList[Message.Guid]} has disconnected")); UsersList.Remove(Message.Guid); break; case PacketOption.GetGuid: ClientInfo = new User(Message.Guid.ToString(), Message.Guid); Log(new ServerMessage($"{Message.Guid.ToString()} has joined.")); if (Message.UsersList != null) { UsersList.Add(Message.UsersList); } UsersList.Add(ClientInfo); break; case PacketOption.FriendRequest: MessageBoxButtons buttons = MessageBoxButtons.YesNo; string content = $"Friend request recieved from {UsersList[Message.Sender].Name}, Accept?"; string caption = "Sausage Chat friend request"; DialogResult result; result = MessageBox.Show(content, caption, buttons); if (result == DialogResult.Yes) { Log(new ServerMessage("Accepted friend request")); Friends["OnlineFriends"].Add(UsersList[Message.Sender]); } else { break; } PacketFormat packet = new PacketFormat(PacketOption.FriendRequestAccepted) { Sender = ClientInfo.Guid, Guid = Message.Sender }; Send(packet); break; case PacketOption.FriendRequestAccepted: Friends["OnlineFriends"].Add(UsersList[Message.Guid]); Log(new ServerMessage($"Friend request accepted by {UsersList[Message.Guid].Name}")); break; case PacketOption.FriendRequestDenied: Log(new ServerMessage("Friend request denied")); break; case PacketOption.AdminPermsRecieved: if (Message.Guid == ClientInfo.Guid) { ClientInfo.IsAdmin = true; Log(new ServerMessage($"You are now admin")); } else { Log(new ServerMessage($"{UsersList[Message.Guid]} is now admin")); } break; case PacketOption.AdminPermsRemoved: if (Message.Guid == ClientInfo.Guid) { ClientInfo.IsAdmin = false; Log(new ServerMessage($"You are no longer admin")); } else { Log(new ServerMessage($"{UsersList[Message.Guid]} is no longer admin")); } break; } }