public void DestructUser(ChannelUser user)
 {
     for (int i = user.Channels.Count - 1; i >= 0; i--)
     {
         user.Channels[i].Users.Remove(user);
     }
     Users.Remove(user);
 }
        public void BuildUserRelations(ChannelUser user)
        {
            Users.Add(user);
            if (!Database.CheckUserExistance(user.Name))
            {
                Database.CreateChannelUser(user.Name);
                return;
            }

            List<string> channels = Database.GetChannelNamesWithUser(user.Name);
            foreach (Channel c in Channels.Where(c => channels.Contains(c.Name)))
            {
                c.Users.Add(user);
                user.Channels.Add(c);
            }
        }
        public ErrorCode JoinUserToChannel(Channel channel, ChannelUser user, bool super = false)
        {
            //Bubbles down to JoinUserToChannel(string, string)
            if (!super && channel.HasMode(ChannelModes.PrivateMode) && !user.HasMode(UserModes.Invited))
            {
                return ErrorCode.InsufficientAccess;
            }

            ErrorCode ret = JoinUserToChannel(channel.Name, user.Name);
            if (ret == ErrorCode.Success)
            {
                channel.Users.Add(user);
                user.Channels.Add(channel);
            }
            return ret;
        }
 public ErrorCode SetUserModes(ChannelUser user, Channel channel)
 {
     return SetUserModes(user.Name, channel.Name, user.Modes.ToString());
 }
 public ErrorCode RemoveUserFromChannel(Channel channel, ChannelUser user)
 {
     //Bubbles down to RemoveUserFromChannel(string, string)
     ErrorCode ret = RemoveUserFromChannel(channel.Name, user.Name);
     if (ret == ErrorCode.Success)
     {
         channel.Users.Remove(user);
         user.Channels.Remove(channel);
     }
     return ret;
 }
 public ErrorCode RemoveChannelUser(ChannelUser user)
 {
     ErrorCode ret = RemoveChannelUser(user.Name);
     if (ret == ErrorCode.Success)
     {
         DestructUser(user);
     }
     return ret;
 }
        public ErrorCode JoinUserToChannel(Channel channel, TSPlayer player)
        {
            //Bubbles down to JoinUserToChannel(Channel, ChannelUser)
            if (!player.IsLoggedIn)
            {
                return ErrorCode.InsufficientAccess;
            }

            ChannelUser user;

            if (Database.CheckUserExistance(player.User.Name))
            {
                user = GetUser(player.User.Name);
                return JoinUserToChannel(channel, user);
            }

            if (Database.CreateChannelUser(player.User.Name))
            {
                user = new ChannelUser(player.User.Name);
            }
            else
            {
                return ErrorCode.UserCreateFailed;
            }

            return JoinUserToChannel(channel, user);
        }
示例#8
0
 void PlayerHooks_PlayerPostLogin(PlayerPostLoginEventArgs e)
 {
     ChannelUser cu = new ChannelUser(e.Player.User.Name);
     ChannelManager.BuildUserRelations(cu);
 }