📄 user.java
字号:
public int getID () {
return id;
}
// ***************************** STATE-QUERY and SET
/**
* sets right for this user
* @param right the rightset for this user
* @see freecs.interfaces.IUserRights
*/
public void setPermission (int right) {
this.permissionMap = right;
}
/**
* grants a specific right to this user additional to previous ones
* @param right
* @see freecs.interfaces.IUserRights
*/
public void givePermission (int right) {
this.permissionMap = this.permissionMap | (right - (this.permissionMap & right));
}
/**
* removes right of this user
* @param right
* @see freecs.interfaces.IUserRights
*/
public void takePermission (int right) {
this.permissionMap = this.permissionMap - (this.permissionMap & right);
}
/**
* determines if this user has the given right
* @param the right in question for this user
* @return true if all flaggs in right are set for this user
*/
public boolean hasRight (int right) {
return ((this.permissionMap & right) == right);
}
public boolean hasRole (int role) {
return this.permissionMap == role;
}
/**
* set away-state
* @param b true if user is away; false otherwhise
*/
public void setAway (boolean b) {
if (b) awayStart = System.currentTimeMillis ();
else awayTime += System.currentTimeMillis () - awayStart;
away = b;
}
/**
* set away-state
* @return away true if user is away; false otherwhise
*/
public boolean isAway () {
return away;
}
/**
* returns the time this user switched to the away-state
* @return the away-time of this user
*/
public long awayTime () {
return awayTime;
}
/**
* checks if this user is punished
* @return true if the user is punished
*/
public boolean isPunished () {
return isPunished;
}
/**
* sets the punishment-state of this user
* @param p if true, the user will be switched into punished mode
*/
public void setPunish (boolean p) {
isPunished = p;
}
/**
* sets the invitation of a user for this user
* @param u the user inviting this user
* @return true if the user doesn't ignore the other user
*/
public boolean invitedFrom (User u) {
if (userIsIgnored(u)) return false;
this.invitedTo = u.getGroup ();
this.invitedBy = u;
return true;
}
/**
* unsets the invitation-state of this user
*/
public void unsetInvitedTo () {
invitedBy = null;
invitedTo = null;
}
/**
* returns the user which has invited this user
* @return the inviter of this user
*/
public User invitedBy () {
return invitedBy;
}
/**
* returns the group to which this user was invited to
* @return the group this user is invited to
*/
public Group invitedTo () {
return invitedTo;
}
/**
* get the color-code for this user
* @return the color-code for this user
*/
public String getColCode () {
return colCode;
}
/**
* Set the colorcode for this user. This method is only for internal
* use (e.g. assigning a colorcode automatically from the database). A
* colorchange triggered by the user must be done by changeColCode
* @param cCode the colorcode this user will recieve
*/
public void setColCode (String cCode) {
colCode = cCode;
}
/**
* This is used for user-triggered colorchanges. It checks the validity of
* a color-code.
* FIXME: the check should be more accurate, it should be configurable
* and it possible should consider the background-color of every layout
* @param cCode the color-code wanted
* @return true if allowed, if not false
*/
public boolean changeColCode (String cCode) {
long now = System.currentTimeMillis ();
if ((now - lastColChange) < Server.srv.COLOR_CHANGE_INTERVAL) return false;
colCode = cCode;
lastColChange = now;
return true;
}
/**
* returns the templateset this user has choosen
* @return the templateset this user has choosen
*/
public TemplateSet getTemplateSet () {
if (this.ts == null) ts = Server.srv.templatemanager.getTemplateSet ("default");
return ts;
}
/**
* set the templateset to use for this user
* @param ts the templateset to use
*/
public void setTemplateSet (TemplateSet ts) {
this.ts = ts;
}
/**
* if linkedName == null the props of this user get checked
* for a link. If a link is present, the link get's constructed
* and stored in linkedName
* FIXME: this should also consider the use of this users templateset
* @return linkedName of this user or just the name if no link is present
*/
public String getLinkedName() {
if (linkedName != null) return linkedName;
if (!userProps.containsKey ("link")) return name;
String link = (String) userProps.get ("link");
StringBuffer sb = new StringBuffer();
sb.append("<a href=\"");
sb.append(link);
sb.append("\" target=\"_blank\">");
sb.append(name);
sb.append("</a>");
linkedName=sb.toString();
return (linkedName);
}
/**
* return the value of the given property of this user
* @param k the name of the property
* FIXME: this should also use the templateset of this user
* @return the value of the property of this user
*/
public Object getProperty (String k) {
if (k.equals ("isaway")) {
return (away ? "away" : "");
} else if (k.equals("awaymessage")) {
if (!away)
return ("");
String msg = getAwayMessage();
if (msg.equals(""))
return (Boolean.FALSE);
return (msg);
} else if (k.equals ("sessionstart.hour")) {
return Server.srv.formatTimeStamp (sessionStart, "HH");
} else if (k.equals ("sessionstart.minute")) {
return Server.srv.formatTimeStamp (sessionStart, "mm");
} else if (k.equals ("idletime")) {
long diff = System.currentTimeMillis () - lastActive;
diff = Math.round (diff / 1000);
return (String.valueOf (diff));
} else if (k.equals ("sessiontime")) {
long l = (System.currentTimeMillis () - sessionStart) / 1000 / 60;
StringBuffer tsb = new StringBuffer ();
if (l > 60) {
long stdn = l / 60;
if (stdn == 1)
tsb.append ("einer Stunde ");
else {
tsb.append (stdn);
tsb.append (" Stunden ");
}
tsb.append (l % 60);
tsb.append (" Minuten");
} else if (l == 1) {
tsb.append ("einer Minute");
} else {
tsb.append (l);
tsb.append (" Minuten");
}
return tsb.toString ();
}
if (k.equals ("room")) return grp.getName ();
return userProps.get (k);
}
/**
* set the property of this user to the value given
* @param k the property to set for this user
* @param v the value for this property of this user
*/
public void setProperty (String k, Object v) {
userProps.put (k, v);
}
/**
* retuns the timestamp this user logged in
* @return the timestamp
*/
public long getSessionStart () {
return sessionStart;
}
/**
* set the HTTP/1.1 capability of this user
* @param b true if this users client is HTTP/1.1 capable
*/
public void setHTTP11 (boolean b) {
isHTTP11 = b;
}
/**
* get the name of this user
* @return string with username
*/
public String getName () {
return (name);
}
/**
* adds a freind relation for this user
* @param fname the name of the friend
*/
public void addFriend (String fname) {
if (friendsList.contains (fname)) return;
UserManager.mgr.addFriendship (this, fname);
friendsList.addElement (fname);
}
/**
* returns the number of friends of this user
* @return the number of freinds of this user
*/
public int numberOfFriends () {
return friendsList.size ();
}
/**
* returns an Enumeration containing all friends of this user.
* @return Enumeration contaioning all friends of this user
*/
public Enumeration friends () {
return friendsList.elements ();
}
/**
* give a message when the user-object gets finalized by the garbage-collector
*/
public void finalize () {
StringBuffer tsb = new StringBuffer (this.toString ()).append (" got finalized **************");
Server.log (tsb.toString (), Server.MSG_STATE, Server.LVL_VERBOSE);
}
public String toString() {
StringBuffer tsb = new StringBuffer ("[User ").append (name).append ("]");
return (tsb.toString ());
}
public boolean equals (User u) {
if (u==null) return false;
if (id != Integer.MIN_VALUE && id == u.getID ()) return true;
if (name.equalsIgnoreCase (u.getName ())) return true;
return (false);
}
public int hashCode () {
if (hashCode != Integer.MIN_VALUE)
return hashCode;
if (id != Integer.MIN_VALUE)
hashCode = id;
else
hashCode = name.toLowerCase().hashCode ();
return (hashCode);
}
/**
* returns the number of questions this user has asked within this group
* @return the number of questions this user has asked within this group
*/
public int getQuestionCounter () {
return questionCounter;
}
/**
* increments the questioncounter of this user
*/
public void incrementQuestionCounter () {
questionCounter++;
}
/**
* returns true if this userobject is logged out
* @return true if this userobject is logged out
*/
public boolean isLoggedOut () {
return loggedOut;
}
/**
* stores the last user to which this user sent a private-message
* @param pu the user who sent the private-message to this user
*/
public void setPrivateUser (User pu) {
this.ownPrivateUser = pu;
}
/**
* returns the stored user to which this user sent a private message last time
* @return the stored user to which this user sent a private message last time
*/
public User getPrivateUser () {
return ownPrivateUser;
}
/**
* stores the last user which sent a private-message to this user
* @param pu the user who sent the private-message to this user
*/
public void setForeignPrivateUser (User pu) {
this.foreignPrivateUser = pu;
}
/**
* returns the stored user which sent a private message to this user last time
* @return the stored user which sent a private message to this user last time
*/
public User getForeignPrivateUser () {
return foreignPrivateUser;
}
/**
* checks the references of this user and unsets them if
* the user referd to is logged out
*/
public void checkReferences() {
if (foreignPrivateUser != null && foreignPrivateUser.isLoggedOut())
foreignPrivateUser = null;
if (ownPrivateUser != null && ownPrivateUser.isLoggedOut())
ownPrivateUser = null;
if (invitedBy != null && invitedBy.isLoggedOut()) {
invitedBy = null;
invitedTo = null;
}
}
/**
* Stores the message given by the command /away do display it, when the user
* returns from away-state (or when /w is called for this user...)
* @param param
*/
public void setAwayMessage(String param) {
awayMessage = param;
}
/**
* returns the stored awaymessage
* @return the stored awaymessage
*/
public String getAwayMessage () {
return awayMessage == null ? "" : awayMessage;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -