1 18 package net.sf.drftpd.event.listeners; 19 20 import java.io.FileNotFoundException ; 21 import java.io.IOException ; 22 import java.util.Collection ; 23 import java.util.Iterator ; 24 25 import net.sf.drftpd.FatalException; 26 import net.sf.drftpd.NoAvailableSlaveException; 27 import net.sf.drftpd.SFVFile; 28 import net.sf.drftpd.event.Event; 29 import net.sf.drftpd.event.FtpListener; 30 import net.sf.drftpd.event.TransferEvent; 31 import net.sf.drftpd.master.ConnectionManager; 32 import net.sf.drftpd.master.UploaderPosition; 33 import net.sf.drftpd.master.usermanager.NoSuchUserException; 34 import net.sf.drftpd.master.usermanager.User; 35 import net.sf.drftpd.master.usermanager.UserFileException; 36 import net.sf.drftpd.remotefile.LinkedRemoteFileInterface; 37 38 import org.drftpd.plugins.SiteBot; 39 40 44 public class RaceStatistics implements FtpListener { 45 46 private ConnectionManager _cm; 47 48 public RaceStatistics() { 49 } 50 51 public void actionPerformed(Event event) { 52 if (!event.getCommand().equals("STOR")) 53 return; 54 TransferEvent direvent = (TransferEvent) event; 55 LinkedRemoteFileInterface dir; 56 try { 57 dir = direvent.getDirectory().getParentFile(); 58 } catch (FileNotFoundException e) { 59 throw new FatalException(e); 60 } 61 SFVFile sfvfile; 62 try { 63 sfvfile = dir.lookupSFVFile(); 64 } catch (FileNotFoundException ex) { 66 return; 68 } catch (NoAvailableSlaveException e) { 69 return; 71 } catch (IOException e) { 72 return; 74 } 75 76 if (!sfvfile.hasFile(direvent.getDirectory().getName())) 77 return; 78 79 if (sfvfile.getStatus().isFinished()) 81 return; 82 Collection racers = SiteBot.userSort(sfvfile.getFiles(), "bytes", "high"); 83 if (racers.size() <= 1) 84 return; int count = 1; 86 for (Iterator iter = racers.iterator(); iter.hasNext(); count++) { 87 UploaderPosition racer = (UploaderPosition) iter.next(); 88 User user; 89 try { 90 user = _cm.getUserManager().getUserByName(racer.getUsername()); 91 } catch (NoSuchUserException ex) { 92 continue; 95 } catch (UserFileException ex) { 96 continue; 99 } 100 if (count == 1) 101 user.addRacesWon(); 102 else if (count == racers.size()) 103 user.addRacesLost(); 104 else 105 user.addRacesParticipated(); 106 } 107 } 108 109 112 public void init(ConnectionManager connectionManager) { 113 _cm = connectionManager; 114 } 115 116 public void unload() { 117 118 } 119 120 } 121 | Popular Tags |