PlayerSpec{{ static final char SEP = ':'; /** Create a PlayerSpec */ public static PlayerSpec create(String n, String add, int p){ return new PlayerSpec(n,add,p); } /** Change the Address of this Player */ public PlayerSpec changeAddress(String add){ return create(name,add,port); } /** Tag Name */ public PlayerSpec tagName(int n){ return create(name+SEP+n,address,port); } /** Returns a Predicate that compares another PlayerSpec by name */ public List.Pred sameNamePred(){ return new SameName(); } /** Predicate for PlayerSpecs that compares Names */ private class SameName extends List.Pred{ public boolean huh(PlayerSpec that) { return name.equals(that.name); } } /** Returns a Predicate that compares names, ignoring a tag */ public List.Pred samePrefixPred(){ return new PrefixName(); } /** Predicate for PlayerSpecs that compares name prefixes */ private class PrefixName extends List.Pred{ public boolean huh(PlayerSpec that){ String n = that.name; int idx = n.lastIndexOf(SEP); if(idx >= 0)n = n.substring(0,idx); return name.equals(n); } } }} PlayersFile{{ /** Get the List of PlayerSpecs */ public List getPlayerSpecs(){ return players; } }} PasswordEntry{{ /** Add to the given Map */ public Map addTo(Map m){ return m.put(name,passhash); } }} PasswordFile{{ /** Get a Map of Player-Name / Password-Hash */ public Map getPasswordMap(){ return passwds.fold(new List.Fold>(){ public Map fold(PasswordEntry e, Map m){ return e.addTo(m); } }, Map.create()); } /** Write out the Passwords to a File */ public void write(String file) throws IOException{ PrintStream out = new PrintStream(new FileOutputStream(file)); out.println(this.toString()); out.close(); } }} TeamSpec{{ /** Create a Team Spec from a Few Strings. THe String members should * be a semi-colon separated list of member names. */ public static TeamSpec create(String name, String pass, String members){ return new TeamSpec(name, scg.Util.encrypt(pass), List.create(members.split(";")).map(new List.Map(){ public String map(String s){ return s.trim(); } })); } /** Returns a Predicate that compares another TeamSpec by name */ public List.Pred sameNamePred(){ return new SameName(); } /** Predicate for TeamSpecs that compares Names */ private class SameName extends List.Pred{ public boolean huh(TeamSpec that) { return name.equals(that.name); } } }} TeamFile{{ /** Write out the Teams to a File */ public void write(String file) throws IOException{ PrintStream out = new PrintStream(new FileOutputStream(file)); out.println(this.toString()); out.close(); } }}