⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 group.java

📁 使用工具jublider开发的一个聊天室实现基本功能,
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	
	public void sendModeratorMessage (IContainer mc) {
		if (usr==null || usrArr==null || usr.size () < 1) 
			return;
		User sender = ((MessageParser) mc).getSender();
        User[] uarr = usrArr;
   		for (int i=0; i<uarr.length; i++) {
   			User cu = uarr[i];
   			if (sender.equals(cu))
   				continue;
   			cu.sendMessage (mc);
   		}
        if (mc instanceof MessageParser && plugins!=null) {
            MessageParser mp = (MessageParser) mc;
            for (int i = 0; i<plugins.length; i++) {
                try {
                    plugins[i].usrAction(mp);
                } catch (Exception e) {
                    Server.debug (plugins[i], "catched exception from plugin", e, Server.MSG_ERROR, Server.LVL_MINOR);
                }
            }
        }
	}
	
   /**
	* sends a message to all users of this group
	* @param mc the IContainer containing the content to send to all users of this group
	*/
	public void sendModeratedMessage (IContainer mc) {
		if (usr==null || usr.size () < 1) 
			return;
		sendMsg(mc);
   }

   /**
    * returns an Iterator containing all users of this group
    * @return an Iterator for looping over all groupmembers of this group
    */
   public Iterator users () {
      return usr.iterator ();
   }

    public User[] getUserArray() {
        return usrArr;
    }

	/**
	 * Check if the given user may join this group
	 * @param u The user to check the rights from
	 * @return true if the user is allowed to join, false if not
	 */
   public boolean usrMayJoin (User u) {
   		if (u==null) 
   			return false;
        if (!hasState(OPEN)
			&& !u.hasRight (IUserStates.MAY_JOIN_LOCKED_GROUP) 
			&& !susers.contains (u)) 
				return false;
		String uname = u.getName().toLowerCase();
		if (banList != null && banList.contains(uname))
			return false;
		return true;
	}
    
    public boolean usrMaySetSu (User u) {
        if ((!this.equals (u.getGroup ()) 
                && !u.hasRight (IUserStates.MAY_CHANGE_RIGHT)) 
             || !u.hasRight (this.minSetSuRole)
             || !usrIsMember(u))
           return false;
        return true;
    }
    
    public boolean usrIsMember (User u) {
        if (this.memberRoom == null
                || this.memberRoom.length == 0)
            return true;
        for (int i = 0; i < this.memberRoom.length; i++)
            if (u.getMembership(this.memberRoom[i].key)!= null)
                return true;
        return false;
    }
    
    /**
     * returns true if the given user has fulfills all creterias to join this group
     * @param u the user to join
     * @return true if all creterias are fulfilled, false if not
     */
    public boolean usrMayLock (User u) {
        if (this.hasState(IGroupState.LOCKPROTECTED))
            return false;
        if (!u.hasRight(IUserStates.MAY_LOCK_GROUP)
            && !susers.contains(u))
                return false;
        if (this.hasState(IGroupState.ENTRANCE)
            && !u.hasRight(IUserStates.MAY_LOCK_STARTING_GROUP))
                return false;
        if (hasState(IGroupState.MODERATED) 
            && !u.hasRight(IUserStates.MAY_LOCK_MODERATED_GROUP))
                return false;
        if (!usrIsMember(u))
            return false;
        return true;
    }
    
    public boolean usrMayJoinPunished (User u) {
    	if (this.joinpunishedCntr >= Server.srv.JOIN_PUNISHED_COUNTER)
    		return false;
     	return true;
    }
    
    public void incrementJoinPunishedCounter() {
        if (joinpunishedCntr == Integer.MAX_VALUE)
        	joinpunishedCntr=1;
        else
        	joinpunishedCntr++;
    }
    
    public void resetJoinPunishedCounter() {
    	joinpunishedCntr=0;
    }
    
    /**
     * increments the question-counter, counting the questions asked within this group
     */
    public void incrementQuestionCounter() {
        if (questionCntr == Integer.MAX_VALUE)
            questionCntr=1;
        else
            questionCntr++;
    }

    /**
     * returns the number of questions asked within this group
     * @return number of questions asked within this group
     */
    public int getQuestionCounter() {
        return questionCntr;
    }
    
    public void resetQuestionCounter() {
        questionCntr=0;
    }

	/**
	 * Set the group-ban-state for a user
	 * @param u The user to set the state for
	 * @param on If true, the user will be banned, if false the user will be unbanned
	 */
	public void setBanForUser (String u, boolean on) {
        if (!this.isValid())
            return;
		String uname = u.toLowerCase();
        if (on && !banList.contains (uname)) 
            banList.addElement (uname);
        else if (!on) 
            banList.removeElement (uname);
	}
	
	public Vector bannedUsers () {
		return (Vector) banList.clone();
	} 

    /**
	 * Check if the given user is banned
	 * @param u The user to check the ban-state for this room
	 * @return true if the user is banned, false if not
	 */
    public boolean usrIsBaned (User u) {
        return usrIsBaned(u.getName());
    }
    public boolean usrIsBaned (String u) {
        if (banList==null)
            return false;
        String uname = u.toLowerCase();
        return banList.contains (uname);
    }

	/**
	 * Checks if a specific user is insied this room
	 * @param u The user to search for
	 * @return true if the user is within this group, false if not
	 */
   public boolean usrIsPresent (User u) {
       if (usr==null)
           return false;
      return usr.contains (u);
   }

	/**
	 * Checks if the given user is in the SU-list for this group
	 * @param u The user to check for
	 * @return true if the user is contained in the SU-list, false if not
	 */
    public boolean usrIsSu (User u) {
        if (susers==null)
            return false;
        return susers.contains (u);
    }

	/**
	 * returns the number of superusers in this grou
	 * @return number of superusers in this group
	 */
	public int suUserCount () {
        if (susers==null)
            return 0;
		return susers.size();
	}
	
	/**
	 * returns the number of users within this group
	 * @return the number of users within this group
	 */
	public int size() {
        if (usr==null)
            return 0;
		return usr.size();
	}
    
    /**
     * set the min-right to join/open this group
     * @param r
     */
    public void setMinRight(int r) {
        this.minRight = r;
    }

    /**
     * set the array with user-names which automatically get su-rights
     * @param usrs string-array containing the usernames which recieve su-rights on joining this group
     */
    public void setAutoSu (String[] usrs) {
        if (autoSuList == null)
            autoSuList = new Vector();
        for (int i = 0; i < usrs.length; i++) {
            String usr = usrs[i].trim().toLowerCase();
            if (!autoSuList.contains(usr))
                autoSuList.add(usr);
        }
    }
    
    public void setSuForbiddenMembership (String ship) {
    	suForbiddenMembership = ship ;
    }
    public String getSuForbiddenMembership (){
    	return suForbiddenMembership ;
    }
	/**
	 * checks if a state is true for this group
	 * @param state the state which must be given
	 * @return true if the state is given, false if not
	 */
   public boolean hasState (int state) {
      return (this.state & state) == state;
   }

	/**
	 * enables the given state
	 * @param state the state to enable
	 */
   public void setState (int state) {
      this.state = this.state | (state - (this.state & state));
   }

	/**
	 * disables the given state
	 * @param state the state to disable
	 */
   public void unsetState (int state) {
      this.state = this.state - (this.state & state);
   }

    public synchronized void setMinRightSu (int minRight) {
        this.minSetSuRole = minRight;
    }
    public boolean isValid () {
        return valid;
    }
    
    public void invalidate() {
        usrArr=null;
        usr=null;
        susers=null;
        banList=null;
        autoSuList=null;
        valid=false;
    }
	/**
	 * checks if the given group is equal to this group
	 * @return true if the two groups are equal
	 */
    public boolean equals (Object g) {
        if (this == g)
            return true;
        if (g==null) 
            return false;
        if (!(g instanceof Group))
            return false;
        String n = ((Group) g).getKey ();
        if (n == null)
            return false;
        return (n.equalsIgnoreCase (this.key));
    }
    
    public String toString () {
        StringBuffer sb = new StringBuffer();
        sb.append ("[Group ");
        sb.append (key);
        sb.append (" / state: ");
        sb.append (state);
        sb.append ("]");
        return sb.toString();
    }
    
    public int hasCode() {
        return this.key.hashCode();
    }

    public void finalize() {
        if (Server.TRACE_CREATE_AND_FINALIZE)
            Server.log(this, "----------------------------------------FINALIZED", Server.MSG_STATE, Server.LVL_VERY_VERBOSE);
    }
	/**
	 * @return Returns the timelockSec.
	 */
	public int getTimelockSec() {
		return timelockSec;
	}
	/**
	 * @param timelockSec The timelockSec to set.
	 */
	public void setTimelockSec(int timelockSec) {
		this.timelockSec = timelockSec;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -