[Megameknet-cvs] MegaMekNET/src/server/campaign/commands CyclopsCommand.java,1.3,1.4
Status: Inactive
Brought to you by:
mcwizard
From: Immanuel S. <im...@us...> - 2005-04-09 12:56:47
|
Update of /cvsroot/megameknet/MegaMekNET/src/server/campaign/commands In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10580/src/server/campaign/commands Modified Files: CyclopsCommand.java Log Message: more cyclops changes Index: CyclopsCommand.java =================================================================== RCS file: /cvsroot/megameknet/MegaMekNET/src/server/campaign/commands/CyclopsCommand.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** CyclopsCommand.java 9 Apr 2005 09:47:44 -0000 1.3 --- CyclopsCommand.java 9 Apr 2005 12:56:39 -0000 1.4 *************** *** 16,25 **** import java.net.MalformedURLException; import java.net.URL; import java.util.LinkedList; import java.util.List; import server.campaign.CampaignMain; import server.cyclops.Cyclops; - import common.House; - import common.Planet; --- 16,24 ---- import java.net.MalformedURLException; import java.net.URL; + import java.util.Collection; import java.util.LinkedList; import java.util.List; import server.campaign.CampaignMain; import server.cyclops.Cyclops; *************** *** 45,54 **** " player.writeFromList[#playerspercall] - Send all players to cyclops.<br>" + " player.write#player - Send the player to cyclops.<br>" + ! " planet.initFromList - Send all planets to cyclops.<br>" + ! " planet.init#planet - Send the 'planet' to cyclops.<br>" + ! " house.initFromList - Send all houses to cyclops.<br>" + " house.updateFromList - Send all houses to cyclops as update.<br>" + ! " house.init#house - Send the 'house' to cyclops.<br>" + ! " house.update#house - Send the 'house' to cyclops as update."; } --- 44,54 ---- " player.writeFromList[#playerspercall] - Send all players to cyclops.<br>" + " player.write#player - Send the player to cyclops.<br>" + ! " planet.writeFromList - Send all planets to cyclops.<br>" + ! " planet.write#planet - Send the 'planet' to cyclops.<br>" + ! " house.writeFromList - Send all houses to cyclops.<br>" + " house.updateFromList - Send all houses to cyclops as update.<br>" + ! " house.write#house - Send the 'house' to cyclops.<br>" + ! " house.update#house - Send the 'house' to cyclops as update.<br>" + ! " unitTemplate.writeFromList - Send all megamek entities."; } *************** *** 60,63 **** --- 60,69 ---- String command = param[0]; String report = null; + Object o = null; + int packageSize = 0; + + if (command.endsWith("FromList") && param.length > 1) + packageSize = Integer.parseInt(param[1]); + if (command.equals("host")) { if (param.length < 2) *************** *** 72,116 **** } } else if (command.equals("player.writeFromList")) { ! if (param.length > 1) { ! int packagesize = Integer.parseInt(param[1]); ! List all = new LinkedList(CampaignMain.cm.getAllPlayers().values()); ! for (int i = 0; i < (all.size()+packagesize-1)/packagesize && report == null; ++i) { ! List l = all.subList(i*packagesize, (i+1)*packagesize); ! System.out.println("index "+(i*packagesize)+" to "+((i+1)*packagesize)); ! report = Cyclops.player_writeFromList(l); ! } ! ! } else ! report = Cyclops.player_writeFromList(CampaignMain.cm.getAllPlayers().values()); } else if (command.equals("player.write")) { if (param.length < 2) throw new IllegalUsageException(); ! report = Cyclops.player_write(CampaignMain.cm.getPlayer(param[1])); ! } else if (command.equals("planet.initFromList")) { ! report = Cyclops.planet_initFromList(CampaignMain.cm.getData().getAllPlanets()); ! } else if (command.equals("house.initFromList")) { ! report = Cyclops.house_initFromList(CampaignMain.cm.getData().getAllHouses()); ! } else if (command.equals("house.updateFromList")) { ! report = Cyclops.house_updateFromList(CampaignMain.cm.getData().getAllHouses()); ! } else if (command.equals("planet.init") || command.equals("planet.update")) { if (param.length < 2) throw new IllegalUsageException(); ! Planet p = CampaignMain.cm.getPlanetFromPartialString(param[1], userName); ! if (p == null) ! return; ! if (command.equals("planet.init")) ! report = Cyclops.planet_init(p); ! else ! report = Cyclops.planet_update(p); ! } else if (command.equals("house.init") || command.equals("house.update")) { if (param.length < 2) throw new IllegalUsageException(); ! House house = CampaignMain.cm.getHouseForName(param[1]); ! if (command.equals("house.init")) ! report = Cyclops.house_init(house); ! else ! report = Cyclops.house_update(house); } else throw new IllegalUsageException(); if (report != null) send("Cyclops report error: "+report, userName); --- 78,116 ---- } } else if (command.equals("player.writeFromList")) { ! if (param.length > 1) ! packageSize = Integer.parseInt(param[1]); ! o = CampaignMain.cm.getAllPlayers().values(); } else if (command.equals("player.write")) { if (param.length < 2) throw new IllegalUsageException(); ! o = CampaignMain.cm.getPlayer(param[1]); ! } else if (command.equals("planet.writeFromList")) { ! o = CampaignMain.cm.getData().getAllPlanets(); ! } else if (command.startsWith("house.") && command.endsWith("FromList")) { ! o = CampaignMain.cm.getData().getAllHouses(); ! } else if (command.equals("planet.write") || command.equals("planet.update")) { if (param.length < 2) throw new IllegalUsageException(); ! o = CampaignMain.cm.getPlanetFromPartialString(param[1], userName); ! } else if (command.equals("house.write") || command.equals("house.update")) { if (param.length < 2) throw new IllegalUsageException(); ! o = CampaignMain.cm.getHouseForName(param[1]); ! } else if (command.equals("unitTemplate.writeFromList")) { ! report = Cyclops.unitTemplate_writeFromList(); } else throw new IllegalUsageException(); + if (o != null) { + if (packageSize > 0 && o instanceof Collection && param.length > 1) { + List all = new LinkedList((Collection)o); + for (int i = 0; i < (all.size()+packageSize-1)/packageSize && report == null; ++i) { + int upperBound = Math.min((i+1)*packageSize, all.size()); + List l = all.subList(i*packageSize, upperBound); + System.out.println("index "+(i*packageSize)+" to "+upperBound); + report = Cyclops.invoke(command, l); + } + } else + report = Cyclops.invoke(command, o); + } if (report != null) send("Cyclops report error: "+report, userName); |