KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > drftpd > master > usermanager > AbstractUser


1 /*
2  * This file is part of DrFTPD, Distributed FTP Daemon.
3  *
4  * DrFTPD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * DrFTPD is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with DrFTPD; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18 package net.sf.drftpd.master.usermanager;
19
20 import java.util.ArrayList JavaDoc;
21 import java.util.Calendar JavaDoc;
22 import java.util.Date JavaDoc;
23 import java.util.Iterator JavaDoc;
24 import java.util.List JavaDoc;
25
26 import net.sf.drftpd.Bytes;
27 import net.sf.drftpd.DuplicateElementException;
28 import net.sf.drftpd.HostMask;
29 import net.sf.drftpd.event.UserEvent;
30 import net.sf.drftpd.event.listeners.Trial;
31 import net.sf.drftpd.master.ConnectionManager;
32 import net.sf.drftpd.util.CalendarUtils;
33
34 import org.apache.log4j.Logger;
35 import org.apache.oro.text.GlobCompiler;
36 import org.apache.oro.text.regex.MalformedPatternException;
37 import org.apache.oro.text.regex.Pattern;
38 import org.apache.oro.text.regex.Perl5Matcher;
39
40 /**
41  * Implements basic functionality for the User interface.
42  *
43  * @author <a HREF="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
44  * @author mog
45  * @version $Id: AbstractUser.java,v 1.45 2004/06/01 17:16:49 mog Exp $
46  */

47 public abstract class AbstractUser implements User {
48     private static final Logger logger = Logger.getLogger(AbstractUser.class);
49
50     protected long _downloadedMilliseconds;
51     protected long _downloadedMillisecondsDay;
52     protected long _downloadedMillisecondsMonth;
53     protected long _downloadedMillisecondsWeek;
54     /**
55      * Should problably be named group for consistency,
56      * this would reset group for JSXUser though.
57      */

58     private String JavaDoc _group = "nogroup";
59
60     protected long _uploadedMilliseconds;
61     protected long _uploadedMillisecondsDay;
62     protected long _uploadedMillisecondsMonth;
63     protected long _uploadedMillisecondsWeek;
64
65     protected String JavaDoc comment;
66
67     protected long created;
68     protected long credits;
69     protected long downloadedBytes;
70     protected long downloadedBytesDay;
71     protected long downloadedBytesMonth;
72     protected long downloadedBytesWeek;
73
74     protected int downloadedFiles;
75     protected int downloadedFilesDay;
76     protected int downloadedFilesMonth;
77     protected int downloadedFilesWeek;
78
79     protected short groupLeechSlots;
80
81     protected ArrayList JavaDoc groups = new ArrayList JavaDoc();
82
83     protected short groupSlots;
84     protected int idleTime = 0; // no limit
85
protected ArrayList JavaDoc ipMasks = new ArrayList JavaDoc();
86     protected long lastAccessTime = 0;
87
88     protected long lastNuked;
89     protected long lastReset;
90
91     //action counters
92
protected int logins;
93     //login limits
94
protected int maxLogins;
95     protected int maxLoginsPerIP;
96     protected int maxSimDownloads;
97     protected int maxSimUploads;
98
99     protected long nukedBytes;
100     protected int racesLost;
101     protected int racesParticipated;
102
103     protected int racesWon;
104
105     protected float ratio = 3.0F;
106     protected int requests;
107     protected int requestsFilled;
108     protected String JavaDoc tagline = "";
109     protected int timesNuked;
110
111     protected long uploadedBytes;
112     protected long uploadedBytesDay;
113     protected long uploadedBytesMonth;
114     protected long uploadedBytesWeek;
115
116     protected int uploadedFiles;
117     protected int uploadedFilesDay;
118     protected int uploadedFilesMonth;
119     protected int uploadedFilesWeek;
120
121     protected String JavaDoc username;
122
123     protected long weeklyAllotment;
124
125     public AbstractUser(String JavaDoc username) {
126         this.username = username;
127     }
128
129     public void addGroup(String JavaDoc group) throws DuplicateElementException {
130         if (groups.contains(group))
131             throw new DuplicateElementException("User is already a member of that group");
132         if (groups.contains(group))
133             return;
134         groups.add(group);
135     }
136
137     public void addIPMask(String JavaDoc mask) throws DuplicateElementException {
138         if (ipMasks.contains(mask))
139             throw new DuplicateElementException("IP mask already added");
140         ipMasks.add(mask);
141     }
142
143     public void addRacesLost() {
144         racesLost++;
145     }
146
147     public void addRacesParticipated() {
148         racesParticipated++;
149     }
150
151     public void addRacesWon() {
152         racesWon++;
153     }
154
155     public void addRequests() {
156         requests++;
157     }
158
159     public void addRequestsFilled() {
160         requestsFilled++;
161     }
162     public boolean checkIP(String JavaDoc masks[], boolean useIdent) {
163
164         Perl5Matcher m = new Perl5Matcher();
165
166         for (Iterator JavaDoc e2 = ipMasks.iterator(); e2.hasNext();) {
167             String JavaDoc mask = (String JavaDoc) e2.next();
168             if (!useIdent) {
169                 mask = mask.substring(mask.indexOf('@') + 1);
170                 for (int i = 0; i < masks.length; i++) {
171                     masks[i] = masks[i].substring(masks[i].indexOf('@') + 1);
172                 }
173             }
174             Pattern p;
175             try {
176                 p = new GlobCompiler().compile(mask);
177             } catch (MalformedPatternException ex) {
178                 ex.printStackTrace();
179                 return false;
180             }
181
182             for (int i = 0; i < masks.length; i++) {
183                 if (m.matches(masks[i], p)) {
184                     return true;
185                 }
186             }
187         }
188         return false;
189     }
190
191     public boolean equals(Object JavaDoc obj) {
192         return obj instanceof User
193             ? ((User) obj).getUsername().equals(getUsername())
194             : false;
195     }
196
197     public String JavaDoc getComment() {
198         return comment;
199     }
200
201     public long getCreated() {
202         return created;
203     }
204
205     public long getCredits() {
206         return credits;
207     }
208
209     public long getDownloadedBytes() {
210         return downloadedBytes;
211     }
212
213     public long getDownloadedBytesDay() {
214         return downloadedBytesDay;
215     }
216
217     public long getDownloadedBytesForPeriod(int period) {
218         switch (period) {
219             case Trial.PERIOD_DAILY :
220                 return this.downloadedBytesDay;
221             case Trial.PERIOD_MONTHLY :
222                 return this.downloadedBytesMonth;
223             case Trial.PERIOD_WEEKLY :
224                 return this.downloadedBytesWeek;
225             case Trial.PERIOD_ALL :
226                 return this.downloadedBytes;
227         }
228         throw new RuntimeException JavaDoc();
229     }
230
231     public long getDownloadedBytesMonth() {
232         return downloadedBytesMonth;
233     }
234
235     public long getDownloadedBytesWeek() {
236         return downloadedBytesWeek;
237     }
238
239     public int getDownloadedFiles() {
240         return downloadedFiles;
241     }
242
243     public int getDownloadedFilesDay() {
244         return downloadedFilesDay;
245     }
246
247     public int getDownloadedFilesForPeriod(int period) {
248         switch (period) {
249             case Trial.PERIOD_DAILY :
250                 return this.downloadedFilesDay;
251             case Trial.PERIOD_MONTHLY :
252                 return this.downloadedFilesMonth;
253             case Trial.PERIOD_WEEKLY :
254                 return this.downloadedFilesWeek;
255             case Trial.PERIOD_ALL :
256                 return this.downloadedFiles;
257         }
258         throw new RuntimeException JavaDoc();
259     }
260
261     public int getDownloadedFilesMonth() {
262         return downloadedFilesMonth;
263     }
264
265     public int getDownloadedFilesWeek() {
266         return downloadedFilesWeek;
267     }
268
269     public long getDownloadedMilliseconds() {
270         return _downloadedMilliseconds;
271     }
272
273     public long getDownloadedMillisecondsDay() {
274         return _downloadedMillisecondsDay;
275     }
276
277     public long getDownloadedMillisecondsForPeriod(int period) {
278         switch (period) {
279             case Trial.PERIOD_DAILY :
280                 return _downloadedMillisecondsDay;
281             case Trial.PERIOD_MONTHLY :
282                 return _downloadedMillisecondsMonth;
283             case Trial.PERIOD_WEEKLY :
284                 return _downloadedMillisecondsWeek;
285             case Trial.PERIOD_ALL :
286                 return _downloadedMilliseconds;
287         }
288         throw new RuntimeException JavaDoc();
289     }
290
291     public long getDownloadedMillisecondsMonth() {
292         return _downloadedMillisecondsMonth;
293     }
294
295     public long getDownloadedMillisecondsWeek() {
296         return _downloadedMillisecondsWeek;
297     }
298
299     public short getGroupLeechSlots() {
300         return groupLeechSlots;
301     }
302
303     public String JavaDoc getGroupName() {
304         if (_group == null)
305             return "nogroup";
306         return _group;
307     }
308
309     public List JavaDoc getGroups() {
310         return groups;
311     }
312
313     public short getGroupSlots() {
314         return groupSlots;
315     }
316
317     public int getIdleTime() {
318         return idleTime;
319     }
320
321     public List JavaDoc getIpMasks() {
322         return ipMasks;
323     }
324
325     public List JavaDoc getIpMasks2() {
326         //return ipMasks;
327
ArrayList JavaDoc ret = new ArrayList JavaDoc();
328         for (Iterator JavaDoc iter = ipMasks.iterator(); iter.hasNext();) {
329             ret.add(new HostMask((String JavaDoc) iter.next()));
330         }
331         return ret;
332     }
333
334     public long getLastAccessTime() {
335         return lastAccessTime;
336     }
337
338     public long getLastNuked() {
339         return lastNuked;
340     }
341
342     public long getLastReset() {
343         return lastReset;
344     }
345
346     public int getLogins() {
347         return logins;
348     }
349
350     public int getMaxLogins() {
351         return maxLogins;
352     }
353
354     public int getMaxLoginsPerIP() {
355         return maxLoginsPerIP;
356     }
357
358     public int getMaxSimDownloads() {
359         return maxSimDownloads;
360     }
361
362     public int getMaxSimUploads() {
363         return maxSimUploads;
364     }
365
366     public long getNukedBytes() {
367         return nukedBytes;
368     }
369
370     public int getRacesLost() {
371         return racesLost;
372     }
373
374     public int getRacesParticipated() {
375         return racesParticipated;
376     }
377
378     public int getRacesWon() {
379         return racesWon;
380     }
381
382     public float getRatio() {
383         return ratio;
384     }
385
386     public int getRequests() {
387         return requests;
388     }
389
390     public int getRequestsFilled() {
391         return requestsFilled;
392     }
393
394     public String JavaDoc getTagline() {
395         return tagline;
396     }
397
398     public int getTimesNuked() {
399         return timesNuked;
400     }
401
402     public long getUploadedBytes() {
403         return uploadedBytes;
404     }
405
406     public long getUploadedBytesDay() {
407         return uploadedBytesDay;
408     }
409
410     public long getUploadedBytesForPeriod(int period) {
411         switch (period) {
412             case Trial.PERIOD_DAILY :
413                 return this.uploadedBytesDay;
414             case Trial.PERIOD_MONTHLY :
415                 return this.uploadedBytesMonth;
416             case Trial.PERIOD_WEEKLY :
417                 return this.uploadedBytesWeek;
418             case Trial.PERIOD_ALL :
419                 return this.uploadedBytes;
420         }
421         throw new RuntimeException JavaDoc();
422     }
423
424     public long getUploadedBytesMonth() {
425         return uploadedBytesMonth;
426     }
427
428     public long getUploadedBytesWeek() {
429         return uploadedBytesWeek;
430     }
431
432     public int getUploadedFiles() {
433         return uploadedFiles;
434     }
435
436     public int getUploadedFilesDay() {
437         return uploadedFilesDay;
438     }
439
440     public int getUploadedFilesForPeriod(int period) {
441         switch (period) {
442             case Trial.PERIOD_DAILY :
443                 return this.uploadedFilesDay;
444             case Trial.PERIOD_MONTHLY :
445                 return this.uploadedFilesMonth;
446             case Trial.PERIOD_WEEKLY :
447                 return this.uploadedFilesWeek;
448             case Trial.PERIOD_ALL :
449                 return this.uploadedFiles;
450         }
451         throw new RuntimeException JavaDoc();
452     }
453
454     public int getUploadedFilesMonth() {
455         return uploadedFilesMonth;
456     }
457
458     public int getUploadedFilesWeek() {
459         return uploadedFilesWeek;
460     }
461
462     public long getUploadedMilliseconds() {
463         return _uploadedMilliseconds;
464     }
465
466     public long getUploadedMillisecondsDay() {
467         return _uploadedMillisecondsDay;
468     }
469
470     public long getUploadedMillisecondsForPeriod(int period) {
471         switch (period) {
472             case Trial.PERIOD_DAILY :
473                 return _uploadedMillisecondsDay;
474             case Trial.PERIOD_MONTHLY :
475                 return _uploadedMillisecondsMonth;
476             case Trial.PERIOD_WEEKLY :
477                 return _uploadedMillisecondsWeek;
478             case Trial.PERIOD_ALL :
479                 return _uploadedMilliseconds;
480         }
481         throw new RuntimeException JavaDoc();
482     }
483
484     public long getUploadedMillisecondsMonth() {
485         return _uploadedMillisecondsMonth;
486     }
487
488     public long getUploadedMillisecondsWeek() {
489         return _uploadedMillisecondsWeek;
490     }
491
492     public String JavaDoc getUsername() {
493         return username;
494     }
495
496     public long getWeeklyAllotment() {
497         return this.weeklyAllotment;
498     }
499
500     public int hashCode() {
501         return getUsername().hashCode();
502     }
503
504     public boolean isAdmin() {
505         return isMemberOf("siteop");
506     }
507
508     public boolean isAnonymous() {
509         return isMemberOf("anonymous");
510     }
511
512     public boolean isDeleted() {
513         return isMemberOf("deleted");
514     }
515
516     public boolean isExempt() {
517         return isMemberOf("exempt");
518     }
519
520     public boolean isGroupAdmin() {
521         return isMemberOf("gadmin");
522     }
523
524     public boolean isMemberOf(String JavaDoc group) {
525         if (getGroupName().equals(group))
526             return true;
527         for (Iterator JavaDoc iter = getGroups().iterator(); iter.hasNext();) {
528             if (group.equals((String JavaDoc) iter.next()))
529                 return true;
530         }
531         return false;
532     }
533     public boolean isNuker() {
534         return isMemberOf("nuke");
535     }
536
537     public void login() {
538         logins += 1;
539     }
540
541     public void logout() {
542     }
543
544     public void removeGroup(String JavaDoc group) throws NoSuchFieldException JavaDoc {
545         if (!groups.remove(group))
546             throw new NoSuchFieldException JavaDoc("User is not a member of that group");
547     }
548
549     public void removeIpMask(String JavaDoc mask) throws NoSuchFieldException JavaDoc {
550         if (!ipMasks.remove(mask))
551             throw new NoSuchFieldException JavaDoc("User has no such ip mask");
552     }
553
554     public void reset(ConnectionManager cmgr) throws UserFileException {
555         reset(cmgr, Calendar.getInstance());
556     }
557     protected void reset(ConnectionManager cmgr, Calendar JavaDoc cal)
558         throws UserFileException {
559         //ignore reset() if we are called from userfileconverter or the like
560
if (cmgr == null)
561             return;
562
563         Date JavaDoc lastResetDate = new Date JavaDoc(this.lastReset);
564         this.lastReset = cal.getTimeInMillis();
565
566         //cal = Calendar.getInstance();
567
Calendar JavaDoc calTmp = (Calendar JavaDoc)cal.clone();
568         calTmp.add(Calendar.DAY_OF_MONTH, -1);
569         CalendarUtils.ceilAllLessThanDay(calTmp);
570
571         //has not been reset since midnight
572
if (lastResetDate.before(calTmp.getTime())) {
573             resetDay(cmgr, cal.getTime());
574
575             //floorDayOfWeek could go into the previous month
576
calTmp = (Calendar JavaDoc) cal.clone();
577             //calTmp.add(Calendar.WEEK_OF_YEAR, 1);
578
CalendarUtils.floorDayOfWeek(calTmp);
579             if (lastResetDate.before(calTmp.getTime()))
580                 resetWeek(cmgr, calTmp.getTime());
581
582             CalendarUtils.floorDayOfMonth(cal);
583             if (lastResetDate.before(cal.getTime()))
584                 resetMonth(cmgr, cal.getTime());
585
586             commit(); //throws UserFileException
587
}
588     }
589
590     private void resetDay(ConnectionManager cm, Date JavaDoc resetDate) {
591         cm.dispatchFtpEvent(
592             new UserEvent(this, "RESETDAY", resetDate.getTime()));
593
594         this.downloadedFilesDay = 0;
595         this.uploadedFilesDay = 0;
596
597         _downloadedMillisecondsDay = 0;
598         _uploadedMillisecondsDay = 0;
599
600         this.downloadedBytesDay = 0;
601         this.uploadedBytesDay = 0;
602         logger.info("Reset daily stats for " + getUsername());
603     }
604
605     private void resetMonth(ConnectionManager cm, Date JavaDoc resetDate) {
606         cm.dispatchFtpEvent(
607             new UserEvent(this, "RESETMONTH", resetDate.getTime()));
608
609         this.downloadedFilesMonth = 0;
610         this.uploadedFilesMonth = 0;
611
612         _downloadedMillisecondsMonth = 0;
613         _uploadedMillisecondsMonth = 0;
614
615         this.downloadedBytesMonth = 0;
616         this.uploadedBytesMonth = 0;
617         logger.info("Reset monthly stats for " + getUsername());
618     }
619
620     private void resetWeek(ConnectionManager cm, Date JavaDoc resetDate) {
621         logger.info(
622             "Reset weekly stats for "
623                 + getUsername()
624                 + "(was "
625                 + Bytes.formatBytes(uploadedBytesWeek)
626                 + " UP and "
627                 + Bytes.formatBytes(downloadedBytesWeek)
628                 + " DOWN");
629
630         cm.dispatchFtpEvent(
631             new UserEvent(this, "RESETWEEK", resetDate.getTime()));
632
633         this.downloadedFilesWeek = 0;
634         this.uploadedFilesWeek = 0;
635
636         _downloadedMillisecondsWeek = 0;
637         _uploadedMillisecondsWeek = 0;
638
639         this.downloadedBytesWeek = 0;
640         this.uploadedBytesWeek = 0;
641         if (getWeeklyAllotment() > 0) {
642             setCredits(getWeeklyAllotment());
643         }
644     }
645
646     public void setComment(String JavaDoc comment) {
647         this.comment = comment;
648     }
649
650     public void setCreated(long created) {
651         this.created = created;
652     }
653
654     public void setCredits(long credits) {
655         this.credits = credits;
656     }
657
658     public void setDeleted(boolean deleted) {
659         if (deleted) {
660             try {
661                 addGroup("deleted");
662             } catch (DuplicateElementException e) {
663             }
664         } else {
665             try {
666                 removeGroup("deleted");
667             } catch (NoSuchFieldException JavaDoc e) {
668             }
669         }
670     }
671
672     public void setDownloadedBytes(long bytes) {
673         this.downloadedBytes = bytes;
674     }
675
676     public void setDownloadedBytesDay(long bytes) {
677         this.downloadedBytesDay = bytes;
678     }
679
680     public void setDownloadedBytesForPeriod(int period, long bytes) {
681         switch (period) {
682             case Trial.PERIOD_DAILY :
683                 this.downloadedBytesDay = bytes;
684                 return;
685             case Trial.PERIOD_MONTHLY :
686                 this.downloadedBytesMonth = bytes;
687                 return;
688             case Trial.PERIOD_WEEKLY :
689                 this.downloadedBytesWeek = bytes;
690                 return;
691             case Trial.PERIOD_ALL :
692                 this.downloadedBytes = bytes;
693                 return;
694         }
695         throw new RuntimeException JavaDoc();
696     }
697
698     public void setDownloadedBytesMonth(long bytes) {
699         this.downloadedBytesMonth = bytes;
700     }
701
702     public void setDownloadedBytesWeek(long bytes) {
703         this.downloadedBytesWeek = bytes;
704     }
705
706     public void setDownloadedFiles(int files) {
707         this.downloadedFiles = files;
708     }
709
710     public void setDownloadedFilesDay(int files) {
711         this.downloadedFilesDay = files;
712     }
713
714     public void setDownloadedFilesForPeriod(int period, int files) {
715         switch (period) {
716             case Trial.PERIOD_DAILY :
717                 this.downloadedFilesDay = files;
718                 return;
719             case Trial.PERIOD_MONTHLY :
720                 this.downloadedFilesMonth = files;
721                 return;
722             case Trial.PERIOD_WEEKLY :
723                 this.downloadedFilesWeek = files;
724                 return;
725             case Trial.PERIOD_ALL :
726                 this.downloadedFiles = files;
727                 return;
728         }
729         throw new RuntimeException JavaDoc();
730     }
731
732     public void setDownloadedFilesMonth(int files) {
733         this.downloadedFilesMonth = files;
734     }
735
736     public void setDownloadedFilesWeek(int files) {
737         this.downloadedFilesWeek = files;
738     }
739
740     public void setDownloadedMilliseconds(long millis) {
741         _downloadedMilliseconds = millis;
742     }
743     public void setDownloadedMillisecondsDay(long millis) {
744         _downloadedMillisecondsDay = millis;
745     }
746
747     public void setDownloadedMillisecondsForPeriod(int period, long millis) {
748         switch (period) {
749             case Trial.PERIOD_DAILY :
750                 _downloadedMillisecondsDay = millis;
751                 return;
752             case Trial.PERIOD_MONTHLY :
753                 _downloadedMillisecondsMonth = millis;
754                 return;
755             case Trial.PERIOD_WEEKLY :
756                 _downloadedMillisecondsWeek = millis;
757                 return;
758             case Trial.PERIOD_ALL :
759                 _downloadedMilliseconds = millis;
760                 return;
761         }
762         throw new RuntimeException JavaDoc();
763     }
764
765     public void setDownloadedMillisecondsMonth(long millis) {
766         _downloadedMillisecondsMonth = millis;
767     }
768
769     public void setDownloadedMillisecondsWeek(long millis) {
770         _downloadedMillisecondsWeek = millis;
771     }
772
773     public void setDownloadedSeconds(int millis) {
774         _downloadedMilliseconds = millis;
775     }
776
777     public void setDownloadedSecondsDay(int millis) {
778         _downloadedMillisecondsDay = millis;
779     }
780
781     public void setDownloadedSecondsMonth(int millis) {
782         _downloadedMillisecondsMonth = millis;
783     }
784
785     public void setDownloadedSecondsWeek(int millis) {
786         _downloadedMillisecondsWeek = millis;
787     }
788
789     public void setGroup(String JavaDoc group) {
790         _group = group;
791     }
792
793     public void setGroupLeechSlots(short s) {
794         groupLeechSlots = s;
795     }
796
797     public void setGroupSlots(short s) {
798         groupSlots = s;
799     }
800
801     public void setIdleTime(int idleTime) {
802         this.idleTime = idleTime;
803     }
804
805     public void setLastAccessTime(long lastAccessTime) {
806         this.lastAccessTime = lastAccessTime;
807     }
808
809     public void setLastNuked(long lastNuked) {
810         this.lastNuked = lastNuked;
811     }
812
813     public void setLogins(int logins) {
814         this.logins = logins;
815     }
816
817     public void setMaxLogins(int maxLogins) {
818         this.maxLogins = maxLogins;
819     }
820
821     public void setMaxLoginsPerIP(int maxLoginsPerIP) {
822         this.maxLoginsPerIP = maxLoginsPerIP;
823     }
824
825     public void setMaxSimDownloads(int maxSimDownloads) {
826         this.maxSimDownloads = maxSimDownloads;
827     }
828
829     public void setMaxSimUploads(int maxSimUploads) {
830         this.maxSimUploads = maxSimUploads;
831     }
832
833     public void setNukedBytes(long nukedBytes) {
834         this.nukedBytes = nukedBytes;
835     }
836
837     public void setRatio(float ratio) {
838         this.ratio = ratio;
839     }
840
841     public void setTagline(String JavaDoc tagline) {
842         this.tagline = tagline;
843     }
844
845     public void setTimesNuked(int nuked) {
846         this.timesNuked = nuked;
847     }
848
849     public void setUploadedBytes(long bytes) {
850         this.uploadedBytes = bytes;
851     }
852
853     public void setUploadedBytesDay(long bytes) {
854         this.uploadedBytesDay = bytes;
855     }
856
857     public void setUploadedBytesForPeriod(int period, long bytes) {
858         switch (period) {
859             case Trial.PERIOD_DAILY :
860                 this.uploadedBytesDay = bytes;
861                 return;
862             case Trial.PERIOD_MONTHLY :
863                 this.uploadedBytesMonth = bytes;
864                 return;
865             case Trial.PERIOD_WEEKLY :
866                 this.uploadedBytesWeek = bytes;
867                 return;
868             case Trial.PERIOD_ALL :
869                 this.uploadedBytes = bytes;
870                 return;
871         }
872         throw new RuntimeException JavaDoc();
873     }
874
875     public void setUploadedBytesMonth(long bytes) {
876         this.uploadedBytesMonth = bytes;
877     }
878
879     public void setUploadedBytesWeek(long bytes) {
880         this.uploadedBytesWeek = bytes;
881     }
882
883     public void setUploadedFiles(int files) {
884         this.uploadedFiles = files;
885     }
886
887     public void setUploadedFilesDay(int files) {
888         this.uploadedFilesDay = files;
889     }
890
891     public void setUploadedFilesForPeriod(int period, int files) {
892         switch (period) {
893             case Trial.PERIOD_DAILY :
894                 this.uploadedFilesDay = files;
895                 return;
896             case Trial.PERIOD_MONTHLY :
897                 this.uploadedFilesMonth = files;
898                 return;
899             case Trial.PERIOD_WEEKLY :
900                 this.uploadedFilesWeek = files;
901                 return;
902             case Trial.PERIOD_ALL :
903                 this.uploadedFiles = files;
904                 return;
905         }
906         throw new RuntimeException JavaDoc();
907     }
908
909     public void setUploadedFilesMonth(int files) {
910         this.uploadedFilesMonth = files;
911     }
912
913     public void setUploadedFilesWeek(int files) {
914         this.uploadedFilesWeek = files;
915     }
916
917     public void setUploadedMilliseconds(long millis) {
918         _uploadedMilliseconds = millis;
919     }
920
921     public void setUploadedMillisecondsDay(long millis) {
922         _uploadedMillisecondsDay = millis;
923     }
924
925     public void setUploadedMillisecondsForPeriod(int period, long millis) {
926         switch (period) {
927             case Trial.PERIOD_DAILY :
928                 _uploadedMillisecondsDay = millis;
929                 return;
930             case Trial.PERIOD_MONTHLY :
931                 _uploadedMillisecondsMonth = millis;
932                 return;
933             case Trial.PERIOD_WEEKLY :
934                 _uploadedMillisecondsWeek = millis;
935                 return;
936             case Trial.PERIOD_ALL :
937                 _uploadedMilliseconds = millis;
938                 return;
939         }
940         throw new RuntimeException JavaDoc();
941     }
942
943     public void setUploadedMillisecondsMonth(long millis) {
944         _uploadedMillisecondsMonth = millis;
945     }
946
947     public void setUploadedMillisecondsWeek(long millis) {
948         _uploadedMillisecondsWeek = millis;
949     }
950
951     public void setUploadedSeconds(int millis) {
952         _uploadedMilliseconds = millis;
953     }
954
955     public void setUploadedSecondsDay(int millis) {
956         _uploadedMillisecondsDay = millis;
957     }
958
959     public void setUploadedSecondsMonth(int millis) {
960         _uploadedMillisecondsMonth = millis;
961     }
962
963     public void setUploadedSecondsWeek(int millis) {
964         _uploadedMillisecondsWeek = millis;
965     }
966
967     public void setWeeklyAllotment(long weeklyAllotment) {
968         this.weeklyAllotment = weeklyAllotment;
969     }
970
971     public void toggleGroup(String JavaDoc string) {
972         if (isMemberOf(string)) {
973             try {
974                 removeGroup(string);
975             } catch (NoSuchFieldException JavaDoc e) {
976                 logger.error("isMemberOf() said we were in the group", e);
977             }
978         } else {
979             try {
980                 addGroup(string);
981             } catch (DuplicateElementException e) {
982                 logger.error("isMemberOf() said we weren't in the group", e);
983             }
984         }
985     }
986
987     public String JavaDoc toString() {
988         return username;
989     }
990
991     public void updateCredits(long credits) {
992         this.credits += credits;
993     }
994
995     public void updateDownloadedBytes(long bytes) {
996         this.downloadedBytes += bytes;
997         this.downloadedBytesDay += bytes;
998         this.downloadedBytesWeek += bytes;
999         this.downloadedBytesMonth += bytes;
1000    }
1001
1002    public void updateDownloadedFiles(int i) {
1003        this.downloadedFiles += i;
1004        this.downloadedFilesDay += i;
1005        this.downloadedFilesWeek += i;
1006        this.downloadedFilesMonth += i;
1007    }
1008
1009    public void updateDownloadedMilliseconds(long millis) {
1010        _downloadedMilliseconds += millis;
1011        _downloadedMillisecondsDay += millis;
1012        _downloadedMillisecondsWeek += millis;
1013        _downloadedMillisecondsMonth += millis;
1014    }
1015
1016    /**
1017     * Hit user - update last access time
1018     */

1019    public void updateLastAccessTime() {
1020        lastAccessTime = System.currentTimeMillis();
1021    }
1022
1023    public void updateNukedBytes(long bytes) {
1024        this.nukedBytes += bytes;
1025    }
1026
1027    public void updateTimesNuked(int timesNuked) {
1028        this.timesNuked += timesNuked;
1029    }
1030
1031    public void updateUploadedBytes(long bytes) {
1032        this.uploadedBytes += bytes;
1033        this.uploadedBytesDay += bytes;
1034        this.uploadedBytesWeek += bytes;
1035        this.uploadedBytesMonth += bytes;
1036    }
1037
1038    public void updateUploadedFiles(int i) {
1039        this.uploadedFiles += i;
1040        this.uploadedFilesDay += i;
1041        this.uploadedFilesWeek += i;
1042        this.uploadedFilesMonth += i;
1043    }
1044
1045    public void updateUploadedMilliseconds(long millis) {
1046        _uploadedMilliseconds += millis;
1047        _uploadedMillisecondsDay += millis;
1048        _uploadedMillisecondsWeek += millis;
1049        _uploadedMillisecondsMonth += millis;
1050    }
1051
1052}
1053
Popular Tags