public void MultiCastExceptSender(ChannelUser sender, IResponse message) { foreach (var user in Users.Values) { if (user.ClientRef.Session.RemoteIPEndPoint == sender.ClientRef.Session.RemoteIPEndPoint) { continue; } user.ClientRef.Send(message); } }
/// <summary> /// We only care about how to set mode in this channel /// we do not need to care about if the user is legal /// because MODEHandler will check for us /// </summary> /// <param name="changer"></param> /// <param name="cmd"></param> public void SetProperties(ChannelUser changer, ModeRequest request) { // todo check permission of each operation foreach (var op in request.ModeOperations) { switch (op) { case ModeOperationType.AddChannelUserLimits: MaxNumberUser = request.LimitNumber; break; case ModeOperationType.RemoveChannelUserLimits: MaxNumberUser = 200; break; case ModeOperationType.AddBanOnUser: AddBanOnUser(request); break; case ModeOperationType.RemoveBanOnUser: RemoveBanOnUser(request); break; case ModeOperationType.AddChannelPassword: Password = request.Password; break; case ModeOperationType.RemoveChannelPassword: Password = null; break; case ModeOperationType.AddChannelOperator: AddChannelOperator(request); break; case ModeOperationType.RemoveChannelOperator: RemoveChannelOperator(request); break; case ModeOperationType.EnableUserVoicePermission: EnableUserVoicePermission(request); break; case ModeOperationType.DisableUserVoicePermission: DisableUserVoicePermission(request); break; default: Mode.SetChannelModes(op); break; } } }
public bool IsUserBanned(ChannelUser user) { if (!BanList.ContainsKey(user.Info.NickName)) { return(false); } if (BanList[user.Info.NickName].Session.RemoteIPEndPoint != user.Session.RemoteIPEndPoint) { return(false); } return(true); }
public Channel(string name, ChannelUser creator = null) { Name = name; Creator = creator; CreateTime = DateTime.Now; Mode = new ChannelMode(); BanList = new ConcurrentDictionary <string, ChannelUser>(); Users = new ConcurrentDictionary <string, ChannelUser>(); ChannelKeyValue = new ConcurrentDictionary <string, string>(); MaxNumberUser = 200; Mode.SetDefaultModes(); }
public void AddBindOnUserAndChannel(ChannelUser joiner) { // !! we can not directly use the Contains() method that ConcurrentDictionary or // !! ConcurrentBag provide because it will not work properly. if (!Users.ContainsKey(joiner.Info.NickName)) { Users.TryAdd(joiner.Info.NickName, joiner); } if (!joiner.Info.JoinedChannels.ContainsKey(this.Name)) { joiner.Info.JoinedChannels.TryAdd(this.Name, this); } }
private void AddBanOnUser(ModeRequest request) { var result = Users.Values.Where(u => u.Info.NickName == request.NickName); if (result.Count() != 1) { return; } ChannelUser user = result.First(); if (BanList.Values.Where(u => u.Info.NickName == request.NickName).Count() == 1) { return; } BanList.TryAdd(user.Info.NickName, user); }
public void RemoveBindOnUserAndChannel(ChannelUser leaver) { //!! we should use ConcurrentDictionary here //!! FIXME: when removing user from channel, //!! we should do more checks on user not only just TryTake() if (Users.ContainsKey(leaver.Info.NickName)) // !! we takeout wrong user from channel { var kv = new KeyValuePair <string, ChannelUser>( leaver.Info.NickName, Users[leaver.Info.NickName]); Users.Remove(kv); } if (leaver.Info.JoinedChannels.ContainsKey(this.Name)) { var kv = new KeyValuePair <string, Channel>(this.Name, this); leaver.Info.JoinedChannels.Remove(kv); } }
public bool IsUserExisted(ChannelUser user) => Users.ContainsKey(user.Info.NickName);