0001: /*
0002: * This file is part of DrFTPD, Distributed FTP Daemon.
0003: *
0004: * DrFTPD is free software; you can redistribute it and/or modify
0005: * it under the terms of the GNU General Public License as published by
0006: * the Free Software Foundation; either version 2 of the License, or
0007: * (at your option) any later version.
0008: *
0009: * DrFTPD is distributed in the hope that it will be useful,
0010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
0011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0012: * GNU General Public License for more details.
0013: *
0014: * You should have received a copy of the GNU General Public License
0015: * along with DrFTPD; if not, write to the Free Software
0016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0017: */
0018: package net.sf.drftpd.master.usermanager;
0019:
0020: import java.util.ArrayList;
0021: import java.util.Calendar;
0022: import java.util.Date;
0023: import java.util.Iterator;
0024: import java.util.List;
0025: import java.util.Map;
0026:
0027: import net.sf.drftpd.DuplicateElementException;
0028: import net.sf.drftpd.event.UserEvent;
0029: import net.sf.drftpd.util.CalendarUtils;
0030:
0031: import org.apache.log4j.Logger;
0032: import org.drftpd.Bytes;
0033: import org.drftpd.GlobalContext;
0034: import org.drftpd.commands.Nuke;
0035: import org.drftpd.commands.Request;
0036: import org.drftpd.commands.UserManagement;
0037: import org.drftpd.dynamicdata.Key;
0038: import org.drftpd.dynamicdata.KeyedMap;
0039: import org.drftpd.plugins.RaceStatistics;
0040: import org.drftpd.plugins.Statistics;
0041: import org.drftpd.plugins.Trial;
0042: import org.drftpd.usermanager.HostMaskCollection;
0043: import org.drftpd.usermanager.User;
0044: import org.drftpd.usermanager.UserFileException;
0045:
0046: /**
0047: * Implements basic functionality for the User interface.
0048: *
0049: * @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya </a>
0050: * @author mog
0051: * @version $Id: AbstractUser.java 1265 2005-09-13 03:34:32Z tdsoul $
0052: */
0053: public abstract class AbstractUser extends User {
0054: private static final Logger logger = Logger
0055: .getLogger(AbstractUser.class);
0056:
0057: private KeyedMap _data;
0058:
0059: protected long _downloadedMilliseconds;
0060:
0061: protected long _downloadedMillisecondsDay;
0062:
0063: protected long _downloadedMillisecondsMonth;
0064:
0065: protected long _downloadedMillisecondsWeek;
0066:
0067: /**
0068: * Should problably be named group for consistency, this would reset group
0069: * for JSXUser though.
0070: */
0071: private String _group = "nogroup";
0072:
0073: protected long _uploadedMilliseconds;
0074:
0075: protected long _uploadedMillisecondsDay;
0076:
0077: protected long _uploadedMillisecondsMonth;
0078:
0079: protected long _uploadedMillisecondsWeek;
0080:
0081: protected String comment;
0082:
0083: protected long created;
0084:
0085: protected long credits;
0086:
0087: protected long downloadedBytes;
0088:
0089: protected long downloadedBytesDay;
0090:
0091: protected long downloadedBytesMonth;
0092:
0093: protected long downloadedBytesWeek;
0094:
0095: protected int downloadedFiles;
0096:
0097: protected int downloadedFilesDay;
0098:
0099: protected int downloadedFilesMonth;
0100:
0101: protected int downloadedFilesWeek;
0102:
0103: protected short groupLeechSlots;
0104:
0105: protected ArrayList groups = new ArrayList();
0106:
0107: protected short groupSlots;
0108:
0109: protected int idleTime = 0; // no limit
0110:
0111: protected ArrayList<String> ipMasks = new ArrayList<String>();
0112:
0113: protected long lastAccessTime = 0;
0114:
0115: protected long lastNuked;
0116:
0117: protected long lastReset;
0118:
0119: //action counters
0120: protected int logins;
0121:
0122: //login limits
0123: protected int maxLogins;
0124:
0125: protected int maxLoginsPerIP;
0126:
0127: protected int maxSimDownloads;
0128:
0129: protected int maxSimUploads;
0130:
0131: protected long nukedBytes;
0132:
0133: protected int racesLost;
0134:
0135: protected int racesParticipated;
0136:
0137: protected int racesWon;
0138:
0139: protected float ratio = 3.0F;
0140:
0141: protected int requests;
0142:
0143: protected int requestsFilled;
0144:
0145: protected String tagline = "";
0146:
0147: protected int timesNuked;
0148:
0149: protected long uploadedBytes;
0150:
0151: protected long uploadedBytesDay;
0152:
0153: protected long uploadedBytesMonth;
0154:
0155: protected long uploadedBytesWeek;
0156:
0157: protected int uploadedFiles;
0158:
0159: protected int uploadedFilesDay;
0160:
0161: protected int uploadedFilesMonth;
0162:
0163: protected int uploadedFilesWeek;
0164:
0165: protected String username;
0166:
0167: protected long weeklyAllotment;
0168:
0169: public AbstractUser(String username) {
0170: this .username = username;
0171: }
0172:
0173: public void addAllMasks(HostMaskCollection hostMaskCollection) {
0174: throw new UnsupportedOperationException();
0175: }
0176:
0177: public void addIPMask(String mask) throws DuplicateElementException {
0178: if (ipMasks.contains(mask)) {
0179: throw new DuplicateElementException("IP mask already added");
0180: }
0181:
0182: ipMasks.add(mask);
0183: }
0184:
0185: public void addSecondaryGroup(String group)
0186: throws DuplicateElementException {
0187: if (groups.contains(group)) {
0188: throw new DuplicateElementException(
0189: "User is already a member of that group");
0190: }
0191:
0192: if (groups.contains(group)) {
0193: return;
0194: }
0195:
0196: groups.add(group);
0197: }
0198:
0199: public boolean equals(Object obj) {
0200: return (obj instanceof User) ? ((User) obj).getName().equals(
0201: getName()) : false;
0202: }
0203:
0204: public long getCredits() {
0205: return credits;
0206: }
0207:
0208: public long getDownloadedBytes() {
0209: return downloadedBytes;
0210: }
0211:
0212: public long getDownloadedBytesDay() {
0213: return downloadedBytesDay;
0214: }
0215:
0216: public long getDownloadedBytesForTrialPeriod(int period) {
0217: switch (period) {
0218: case Trial.PERIOD_DAILY:
0219: return this .downloadedBytesDay;
0220:
0221: case Trial.PERIOD_MONTHLY:
0222: return this .downloadedBytesMonth;
0223:
0224: case Trial.PERIOD_WEEKLY:
0225: return this .downloadedBytesWeek;
0226:
0227: case Trial.PERIOD_ALL:
0228: return this .downloadedBytes;
0229: }
0230:
0231: throw new RuntimeException();
0232: }
0233:
0234: public long getDownloadedBytesMonth() {
0235: return downloadedBytesMonth;
0236: }
0237:
0238: public long getDownloadedBytesWeek() {
0239: return downloadedBytesWeek;
0240: }
0241:
0242: public int getDownloadedFiles() {
0243: return downloadedFiles;
0244: }
0245:
0246: public int getDownloadedFilesDay() {
0247: return downloadedFilesDay;
0248: }
0249:
0250: public int getDownloadedFilesForTrialPeriod(int period) {
0251: switch (period) {
0252: case Trial.PERIOD_DAILY:
0253: return this .downloadedFilesDay;
0254:
0255: case Trial.PERIOD_MONTHLY:
0256: return this .downloadedFilesMonth;
0257:
0258: case Trial.PERIOD_WEEKLY:
0259: return this .downloadedFilesWeek;
0260:
0261: case Trial.PERIOD_ALL:
0262: return this .downloadedFiles;
0263: }
0264:
0265: throw new RuntimeException();
0266: }
0267:
0268: public int getDownloadedFilesMonth() {
0269: return downloadedFilesMonth;
0270: }
0271:
0272: public int getDownloadedFilesWeek() {
0273: return downloadedFilesWeek;
0274: }
0275:
0276: public long getDownloadedTime() {
0277: return _downloadedMilliseconds;
0278: }
0279:
0280: public long getDownloadedTimeForTrialPeriod(int period) {
0281: switch (period) {
0282: case Trial.PERIOD_DAILY:
0283: return _downloadedMillisecondsDay;
0284:
0285: case Trial.PERIOD_MONTHLY:
0286: return _downloadedMillisecondsMonth;
0287:
0288: case Trial.PERIOD_WEEKLY:
0289: return _downloadedMillisecondsWeek;
0290:
0291: case Trial.PERIOD_ALL:
0292: return _downloadedMilliseconds;
0293: }
0294:
0295: throw new RuntimeException();
0296: }
0297:
0298: public String getGroup() {
0299: if (_group == null) {
0300: return "nogroup";
0301: }
0302:
0303: return _group;
0304: }
0305:
0306: public List getGroups() {
0307: return groups;
0308: }
0309:
0310: public HostMaskCollection getHostMaskCollection() {
0311: return new HostMaskCollection(ipMasks);
0312: }
0313:
0314: public int getIdleTime() {
0315: return idleTime;
0316: }
0317:
0318: public KeyedMap<Key, Object> getKeyedMap() {
0319: _data = new KeyedMap<Key, Object>();
0320:
0321: _data.setObject(Nuke.LASTNUKED, lastNuked);
0322: _data.setObject(Nuke.NUKED, timesNuked);
0323: _data.setObject(Nuke.NUKEDBYTES, nukedBytes);
0324:
0325: _data.setObject(Request.REQUESTS, requests);
0326: _data.setObject(Request.REQUESTSFILLED, requestsFilled);
0327:
0328: _data.setObject(UserManagement.COMMENT, getComment());
0329: _data.setObject(UserManagement.CREATED, new Date(created));
0330: _data.setObject(UserManagement.RATIO, new Float(ratio));
0331: _data.setObject(UserManagement.TAGLINE, tagline);
0332: _data.setObject(UserManagement.LEECHSLOTS, groupLeechSlots);
0333: _data.setObject(UserManagement.GROUPSLOTS, groupSlots);
0334: _data.setObject(UserManagement.MAXSIMUP, maxSimUploads);
0335: _data.setObject(UserManagement.MAXSIMDN, maxSimDownloads);
0336: _data.setObject(UserManagement.MAXLOGINS, maxLogins);
0337: _data.setObject(UserManagement.MAXLOGINSIP, maxLoginsPerIP);
0338: _data.setObject(UserManagement.WKLY_ALLOTMENT, weeklyAllotment);
0339: _data.setObject(UserManagement.LASTSEEN, new Date(
0340: lastAccessTime));
0341:
0342: _data.setObject(RaceStatistics.RACES, racesParticipated);
0343: _data.setObject(RaceStatistics.RACESLOST, racesLost);
0344: _data.setObject(RaceStatistics.RACESWON, racesWon);
0345:
0346: _data.setObject(Statistics.LOGINS, logins);
0347: return _data;
0348: }
0349:
0350: public String getComment() {
0351: if (comment == null) {
0352: return "no comment";
0353: }
0354: return comment;
0355: }
0356:
0357: public long getLastAccessTime() {
0358: return lastAccessTime;
0359: }
0360:
0361: public long getLastReset() {
0362: return lastReset;
0363: }
0364:
0365: public void setLastReset(long lastReset) {
0366: this .lastReset = lastReset;
0367: }
0368:
0369: public int getLogins() {
0370: return logins;
0371: }
0372:
0373: public int getMaxLogins() {
0374: return maxLogins;
0375: }
0376:
0377: public int getMaxLoginsPerIP() {
0378: return maxLoginsPerIP;
0379: }
0380:
0381: public long getUploadedBytes() {
0382: return uploadedBytes;
0383: }
0384:
0385: public long getUploadedBytesDay() {
0386: return uploadedBytesDay;
0387: }
0388:
0389: public long getUploadedBytesForTrialPeriod(int period) {
0390: switch (period) {
0391: case Trial.PERIOD_DAILY:
0392: return this .uploadedBytesDay;
0393:
0394: case Trial.PERIOD_MONTHLY:
0395: return this .uploadedBytesMonth;
0396:
0397: case Trial.PERIOD_WEEKLY:
0398: return this .uploadedBytesWeek;
0399:
0400: case Trial.PERIOD_ALL:
0401: return this .uploadedBytes;
0402: }
0403:
0404: throw new RuntimeException();
0405: }
0406:
0407: public long getUploadedBytesMonth() {
0408: return uploadedBytesMonth;
0409: }
0410:
0411: public long getUploadedBytesWeek() {
0412: return uploadedBytesWeek;
0413: }
0414:
0415: public int getUploadedFiles() {
0416: return uploadedFiles;
0417: }
0418:
0419: public int getUploadedFilesDay() {
0420: return uploadedFilesDay;
0421: }
0422:
0423: public int getUploadedFilesForTrialPeriod(int period) {
0424: switch (period) {
0425: case Trial.PERIOD_DAILY:
0426: return this .uploadedFilesDay;
0427:
0428: case Trial.PERIOD_MONTHLY:
0429: return this .uploadedFilesMonth;
0430:
0431: case Trial.PERIOD_WEEKLY:
0432: return this .uploadedFilesWeek;
0433:
0434: case Trial.PERIOD_ALL:
0435: return this .uploadedFiles;
0436: }
0437:
0438: throw new RuntimeException();
0439: }
0440:
0441: public int getUploadedFilesMonth() {
0442: return uploadedFilesMonth;
0443: }
0444:
0445: public int getUploadedFilesWeek() {
0446: return uploadedFilesWeek;
0447: }
0448:
0449: public long getUploadedTime() {
0450: return _uploadedMilliseconds;
0451: }
0452:
0453: public long getUploadedTimeForTrialPeriod(int period) {
0454: switch (period) {
0455: case Trial.PERIOD_DAILY:
0456: return _uploadedMillisecondsDay;
0457:
0458: case Trial.PERIOD_MONTHLY:
0459: return _uploadedMillisecondsMonth;
0460:
0461: case Trial.PERIOD_WEEKLY:
0462: return _uploadedMillisecondsWeek;
0463:
0464: case Trial.PERIOD_ALL:
0465: return _uploadedMilliseconds;
0466: }
0467:
0468: throw new RuntimeException();
0469: }
0470:
0471: public String getName() {
0472: return username;
0473: }
0474:
0475: public long getWeeklyAllotment() {
0476: return this .weeklyAllotment;
0477: }
0478:
0479: public int hashCode() {
0480: return getName().hashCode();
0481: }
0482:
0483: public boolean isAdmin() {
0484: return isMemberOf("siteop");
0485: }
0486:
0487: public boolean isDeleted() {
0488: return isMemberOf("deleted");
0489: }
0490:
0491: public boolean isExempt() {
0492: return isMemberOf("exempt");
0493: }
0494:
0495: public boolean isGroupAdmin() {
0496: return isMemberOf("gadmin");
0497: }
0498:
0499: public boolean isMemberOf(String group) {
0500: if (getGroup().equals(group)) {
0501: return true;
0502: }
0503:
0504: for (Iterator iter = getGroups().iterator(); iter.hasNext();) {
0505: if (group.equals((String) iter.next())) {
0506: return true;
0507: }
0508: }
0509:
0510: return false;
0511: }
0512:
0513: public boolean isNuker() {
0514: return isMemberOf("nuke");
0515: }
0516:
0517: public void login() {
0518: logins += 1;
0519: }
0520:
0521: public void logout() {
0522: }
0523:
0524: public void putAllObjects(Map m) {
0525: throw new UnsupportedOperationException();
0526: }
0527:
0528: public void removeIpMask(String mask) throws NoSuchFieldException {
0529: if (!ipMasks.remove(mask)) {
0530: throw new NoSuchFieldException("User has no such ip mask");
0531: }
0532: }
0533:
0534: public void removeSecondaryGroup(String group)
0535: throws NoSuchFieldException {
0536: if (!groups.remove(group)) {
0537: throw new NoSuchFieldException(
0538: "User is not a member of that group");
0539: }
0540: }
0541:
0542: public void reset(GlobalContext gctx) throws UserFileException {
0543: reset(gctx, Calendar.getInstance());
0544: }
0545:
0546: protected void reset(GlobalContext gctx, Calendar cal)
0547: throws UserFileException {
0548: //ignore reset() if we are called from userfileconverter or the like
0549: if (gctx == null) {
0550: return;
0551: }
0552:
0553: Date lastResetDate = new Date(this .lastReset);
0554: this .lastReset = cal.getTimeInMillis();
0555:
0556: //cal = Calendar.getInstance();
0557: Calendar calTmp = (Calendar) cal.clone();
0558: calTmp.add(Calendar.DAY_OF_MONTH, -1);
0559: CalendarUtils.ceilAllLessThanDay(calTmp);
0560:
0561: //has not been reset since midnight
0562: if (lastResetDate.before(calTmp.getTime())) {
0563: resetDay(gctx, cal.getTime());
0564:
0565: //floorDayOfWeek could go into the previous month
0566: calTmp = (Calendar) cal.clone();
0567:
0568: //calTmp.add(Calendar.WEEK_OF_YEAR, 1);
0569: CalendarUtils.floorDayOfWeek(calTmp);
0570:
0571: if (lastResetDate.before(calTmp.getTime())) {
0572: resetWeek(gctx, calTmp.getTime());
0573: }
0574:
0575: CalendarUtils.floorDayOfMonth(cal);
0576:
0577: if (lastResetDate.before(cal.getTime())) {
0578: resetMonth(gctx, cal.getTime());
0579: }
0580:
0581: commit(); //throws UserFileException
0582: }
0583: }
0584:
0585: private void resetDay(GlobalContext gctx, Date resetDate) {
0586: gctx.dispatchFtpEvent(new UserEvent(this , "RESETDAY", resetDate
0587: .getTime()));
0588:
0589: this .downloadedFilesDay = 0;
0590: this .uploadedFilesDay = 0;
0591:
0592: _downloadedMillisecondsDay = 0;
0593: _uploadedMillisecondsDay = 0;
0594:
0595: this .downloadedBytesDay = 0;
0596: this .uploadedBytesDay = 0;
0597: logger.info("Reset daily stats for " + getName());
0598: }
0599:
0600: private void resetMonth(GlobalContext gctx, Date resetDate) {
0601: gctx.dispatchFtpEvent(new UserEvent(this , "RESETMONTH",
0602: resetDate.getTime()));
0603:
0604: this .downloadedFilesMonth = 0;
0605: this .uploadedFilesMonth = 0;
0606:
0607: _downloadedMillisecondsMonth = 0;
0608: _uploadedMillisecondsMonth = 0;
0609:
0610: this .downloadedBytesMonth = 0;
0611: this .uploadedBytesMonth = 0;
0612: logger.info("Reset monthly stats for " + getName());
0613: }
0614:
0615: private void resetWeek(GlobalContext gctx, Date resetDate) {
0616: logger.info("Reset weekly stats for " + getName() + "(was "
0617: + Bytes.formatBytes(uploadedBytesWeek) + " UP and "
0618: + Bytes.formatBytes(downloadedBytesWeek) + " DOWN");
0619:
0620: gctx.dispatchFtpEvent(new UserEvent(this , "RESETWEEK",
0621: resetDate.getTime()));
0622:
0623: this .downloadedFilesWeek = 0;
0624: this .uploadedFilesWeek = 0;
0625:
0626: _downloadedMillisecondsWeek = 0;
0627: _uploadedMillisecondsWeek = 0;
0628:
0629: this .downloadedBytesWeek = 0;
0630: this .uploadedBytesWeek = 0;
0631:
0632: if (getWeeklyAllotment() > 0) {
0633: setCredits(getWeeklyAllotment());
0634: }
0635: }
0636:
0637: public void setCredits(long credits) {
0638: this .credits = credits;
0639: }
0640:
0641: public void setDeleted(boolean deleted) {
0642: if (deleted) {
0643: try {
0644: addSecondaryGroup("deleted");
0645: } catch (DuplicateElementException e) {
0646: }
0647: } else {
0648: try {
0649: removeSecondaryGroup("deleted");
0650: } catch (NoSuchFieldException e) {
0651: }
0652: }
0653: }
0654:
0655: public void setDownloadedBytes(long bytes) {
0656: this .downloadedBytes = bytes;
0657: }
0658:
0659: public void setDownloadedBytesDay(long bytes) {
0660: this .downloadedBytesDay = bytes;
0661: }
0662:
0663: public void setDownloadedBytesForTrialPeriod(int period, long bytes) {
0664: switch (period) {
0665: case Trial.PERIOD_DAILY:
0666: this .downloadedBytesDay = bytes;
0667:
0668: return;
0669:
0670: case Trial.PERIOD_MONTHLY:
0671: this .downloadedBytesMonth = bytes;
0672:
0673: return;
0674:
0675: case Trial.PERIOD_WEEKLY:
0676: this .downloadedBytesWeek = bytes;
0677:
0678: return;
0679:
0680: case Trial.PERIOD_ALL:
0681: this .downloadedBytes = bytes;
0682:
0683: return;
0684: }
0685:
0686: throw new RuntimeException();
0687: }
0688:
0689: public void setDownloadedBytesMonth(long bytes) {
0690: this .downloadedBytesMonth = bytes;
0691: }
0692:
0693: public void setDownloadedBytesWeek(long bytes) {
0694: this .downloadedBytesWeek = bytes;
0695: }
0696:
0697: public void setDownloadedFiles(int files) {
0698: this .downloadedFiles = files;
0699: }
0700:
0701: public void setDownloadedFilesDay(int files) {
0702: this .downloadedFilesDay = files;
0703: }
0704:
0705: public void setDownloadedFilesForTrialPeriod(int period, int files) {
0706: switch (period) {
0707: case Trial.PERIOD_DAILY:
0708: this .downloadedFilesDay = files;
0709:
0710: return;
0711:
0712: case Trial.PERIOD_MONTHLY:
0713: this .downloadedFilesMonth = files;
0714:
0715: return;
0716:
0717: case Trial.PERIOD_WEEKLY:
0718: this .downloadedFilesWeek = files;
0719:
0720: return;
0721:
0722: case Trial.PERIOD_ALL:
0723: this .downloadedFiles = files;
0724:
0725: return;
0726: }
0727:
0728: throw new RuntimeException();
0729: }
0730:
0731: public void setDownloadedFilesMonth(int files) {
0732: this .downloadedFilesMonth = files;
0733: }
0734:
0735: public void setDownloadedFilesWeek(int files) {
0736: this .downloadedFilesWeek = files;
0737: }
0738:
0739: public void setDownloadedTime(int millis) {
0740: _downloadedMilliseconds = millis;
0741: }
0742:
0743: public void setDownloadedTime(long millis) {
0744: _downloadedMilliseconds = millis;
0745: }
0746:
0747: public void setDownloadedTimeDay(int millis) {
0748: _downloadedMillisecondsDay = millis;
0749: }
0750:
0751: public void setDownloadedTimeDay(long millis) {
0752: _downloadedMillisecondsDay = millis;
0753: }
0754:
0755: public void setDownloadedTimeForTrialPeriod(int period, long millis) {
0756: switch (period) {
0757: case Trial.PERIOD_DAILY:
0758: _downloadedMillisecondsDay = millis;
0759:
0760: return;
0761:
0762: case Trial.PERIOD_MONTHLY:
0763: _downloadedMillisecondsMonth = millis;
0764:
0765: return;
0766:
0767: case Trial.PERIOD_WEEKLY:
0768: _downloadedMillisecondsWeek = millis;
0769:
0770: return;
0771:
0772: case Trial.PERIOD_ALL:
0773: _downloadedMilliseconds = millis;
0774:
0775: return;
0776: }
0777:
0778: throw new RuntimeException();
0779: }
0780:
0781: public void setDownloadedTimeMonth(long millis) {
0782: _downloadedMillisecondsMonth = millis;
0783: }
0784:
0785: public void setDownloadedTimeWeek(long millis) {
0786: _downloadedMillisecondsWeek = millis;
0787: }
0788:
0789: public void setGroup(String group) {
0790: _group = group;
0791: }
0792:
0793: public void setGroupLeechSlots(short s) {
0794: groupLeechSlots = s;
0795: }
0796:
0797: public void setGroupSlots(short s) {
0798: groupSlots = s;
0799: }
0800:
0801: public void setIdleTime(int idleTime) {
0802: this .idleTime = idleTime;
0803: }
0804:
0805: public void setLastAccessTime(long lastAccessTime) {
0806: this .lastAccessTime = lastAccessTime;
0807: }
0808:
0809: public void setLogins(int logins) {
0810: this .logins = logins;
0811: }
0812:
0813: public void setMaxLogins(int maxLogins) {
0814: this .maxLogins = maxLogins;
0815: }
0816:
0817: public void setMaxLoginsPerIP(int maxLoginsPerIP) {
0818: this .maxLoginsPerIP = maxLoginsPerIP;
0819: }
0820:
0821: public void setNukedBytes(long nukedBytes) {
0822: this .nukedBytes = nukedBytes;
0823: }
0824:
0825: public void setUploadedBytes(long bytes) {
0826: this .uploadedBytes = bytes;
0827: }
0828:
0829: public void setUploadedBytesDay(long bytes) {
0830: this .uploadedBytesDay = bytes;
0831: }
0832:
0833: public void setUploadedBytesForTrialPeriod(int period, long bytes) {
0834: switch (period) {
0835: case Trial.PERIOD_DAILY:
0836: this .uploadedBytesDay = bytes;
0837:
0838: return;
0839:
0840: case Trial.PERIOD_MONTHLY:
0841: this .uploadedBytesMonth = bytes;
0842:
0843: return;
0844:
0845: case Trial.PERIOD_WEEKLY:
0846: this .uploadedBytesWeek = bytes;
0847:
0848: return;
0849:
0850: case Trial.PERIOD_ALL:
0851: this .uploadedBytes = bytes;
0852:
0853: return;
0854: }
0855:
0856: throw new RuntimeException();
0857: }
0858:
0859: public void setUploadedBytesMonth(long bytes) {
0860: this .uploadedBytesMonth = bytes;
0861: }
0862:
0863: public void setUploadedBytesWeek(long bytes) {
0864: this .uploadedBytesWeek = bytes;
0865: }
0866:
0867: public void setUploadedFiles(int files) {
0868: this .uploadedFiles = files;
0869: }
0870:
0871: public void setUploadedFilesDay(int files) {
0872: this .uploadedFilesDay = files;
0873: }
0874:
0875: public void setUploadedFilesForTrialPeriod(int period, int files) {
0876: switch (period) {
0877: case Trial.PERIOD_DAILY:
0878: this .uploadedFilesDay = files;
0879:
0880: return;
0881:
0882: case Trial.PERIOD_MONTHLY:
0883: this .uploadedFilesMonth = files;
0884:
0885: return;
0886:
0887: case Trial.PERIOD_WEEKLY:
0888: this .uploadedFilesWeek = files;
0889:
0890: return;
0891:
0892: case Trial.PERIOD_ALL:
0893: this .uploadedFiles = files;
0894:
0895: return;
0896: }
0897:
0898: throw new RuntimeException();
0899: }
0900:
0901: public void setUploadedFilesMonth(int files) {
0902: this .uploadedFilesMonth = files;
0903: }
0904:
0905: public void setUploadedFilesWeek(int files) {
0906: this .uploadedFilesWeek = files;
0907: }
0908:
0909: public void setUploadedTime(int millis) {
0910: _uploadedMilliseconds = millis;
0911: }
0912:
0913: public void setUploadedTime(long millis) {
0914: _uploadedMilliseconds = millis;
0915: }
0916:
0917: public void setUploadedTimeDay(int millis) {
0918: _uploadedMillisecondsDay = millis;
0919: }
0920:
0921: public void setUploadedTimeDay(long millis) {
0922: _uploadedMillisecondsDay = millis;
0923: }
0924:
0925: public void setUploadedTimeForTrialPeriod(int period, long millis) {
0926: switch (period) {
0927: case Trial.PERIOD_DAILY:
0928: _uploadedMillisecondsDay = millis;
0929:
0930: return;
0931:
0932: case Trial.PERIOD_MONTHLY:
0933: _uploadedMillisecondsMonth = millis;
0934:
0935: return;
0936:
0937: case Trial.PERIOD_WEEKLY:
0938: _uploadedMillisecondsWeek = millis;
0939:
0940: return;
0941:
0942: case Trial.PERIOD_ALL:
0943: _uploadedMilliseconds = millis;
0944:
0945: return;
0946: }
0947:
0948: throw new RuntimeException();
0949: }
0950:
0951: public void setUploadedTimeMonth(int millis) {
0952: _uploadedMillisecondsMonth = millis;
0953: }
0954:
0955: public void setUploadedTimeMonth(long millis) {
0956: _uploadedMillisecondsMonth = millis;
0957: }
0958:
0959: public void setUploadedTimeWeek(int millis) {
0960: _uploadedMillisecondsWeek = millis;
0961: }
0962:
0963: public void setUploadedTimeWeek(long millis) {
0964: _uploadedMillisecondsWeek = millis;
0965: }
0966:
0967: public void setWeeklyAllotment(long weeklyAllotment) {
0968: this .weeklyAllotment = weeklyAllotment;
0969: }
0970:
0971: public void toggleGroup(String string) {
0972: if (isMemberOf(string)) {
0973: try {
0974: removeSecondaryGroup(string);
0975: } catch (NoSuchFieldException e) {
0976: logger.error("isMemberOf() said we were in the group",
0977: e);
0978: }
0979: } else {
0980: try {
0981: addSecondaryGroup(string);
0982: } catch (DuplicateElementException e) {
0983: logger.error(
0984: "isMemberOf() said we weren't in the group", e);
0985: }
0986: }
0987: }
0988:
0989: public String toString() {
0990: return username;
0991: }
0992:
0993: public void updateCredits(long credits) {
0994: this .credits += credits;
0995: }
0996:
0997: public void updateDownloadedBytes(long bytes) {
0998: this .downloadedBytes += bytes;
0999: this .downloadedBytesDay += bytes;
1000: this .downloadedBytesWeek += bytes;
1001: this .downloadedBytesMonth += bytes;
1002: }
1003:
1004: public void updateDownloadedFiles(int i) {
1005: this .downloadedFiles += i;
1006: this .downloadedFilesDay += i;
1007: this .downloadedFilesWeek += i;
1008: this .downloadedFilesMonth += i;
1009: }
1010:
1011: public void updateDownloadedTime(long millis) {
1012: _downloadedMilliseconds += millis;
1013: _downloadedMillisecondsDay += millis;
1014: _downloadedMillisecondsWeek += millis;
1015: _downloadedMillisecondsMonth += millis;
1016: }
1017:
1018: /**
1019: * Hit user - update last access time
1020: */
1021: public void updateLastAccessTime() {
1022: lastAccessTime = System.currentTimeMillis();
1023: }
1024:
1025: public void updateUploadedBytes(long bytes) {
1026: this .uploadedBytes += bytes;
1027: this .uploadedBytesDay += bytes;
1028: this .uploadedBytesWeek += bytes;
1029: this .uploadedBytesMonth += bytes;
1030: }
1031:
1032: public void updateUploadedFiles(int i) {
1033: this .uploadedFiles += i;
1034: this .uploadedFilesDay += i;
1035: this .uploadedFilesWeek += i;
1036: this .uploadedFilesMonth += i;
1037: }
1038:
1039: public void updateUploadedTime(long millis) {
1040: _uploadedMilliseconds += millis;
1041: _uploadedMillisecondsDay += millis;
1042: _uploadedMillisecondsWeek += millis;
1043: _uploadedMillisecondsMonth += millis;
1044: }
1045:
1046: public float getMinRatio() {
1047: return getKeyedMap().containsKey(UserManagement.MINRATIO) ? getKeyedMap()
1048: .getObjectFloat(UserManagement.MINRATIO)
1049: : 3F;
1050: }
1051:
1052: public void setMinRatio(float minRatio) {
1053: getKeyedMap().setObject(UserManagement.MINRATIO, minRatio);
1054: }
1055:
1056: public float getMaxRatio() {
1057: return getKeyedMap().containsKey(UserManagement.MAXRATIO) ? getKeyedMap()
1058: .getObjectFloat(UserManagement.MAXRATIO)
1059: : 3F;
1060: }
1061:
1062: public void setMaxRatio(float maxRatio) {
1063: getKeyedMap().setObject(UserManagement.MAXRATIO, maxRatio);
1064: }
1065:
1066: public int getMaxSimUp() {
1067: return getKeyedMap().getObjectInt(UserManagement.MAXSIMUP);
1068: }
1069:
1070: public void setMaxSimUp(int maxSimUp) {
1071: getKeyedMap().setObject(UserManagement.MAXSIMUP, maxSimUp);
1072: }
1073:
1074: public int getMaxSimDown() {
1075: return getKeyedMap().getObjectInt(UserManagement.MAXSIMDN);
1076: }
1077:
1078: public void setMaxSimDown(int maxSimDown) {
1079: getKeyedMap().setObject(UserManagement.MAXSIMDN, maxSimDown);
1080: }
1081: }
|