public void actionPerformed(ActionEvent e) { // --SEND/GET UPDATE(s) FROM SERVER-- Called whenever timer goes off (every 5 sec.) // ==== SEND ALL OF THE MESSAGES WE HAVE ==== comm.sendOutboxMessages(); // ==== SEND A REQUEST FOR A UNIVERSAL UPDATE ==== comm.sendMessage("REQUEST"); // ==== RECIEVE THE UNIVERSE/ROSTER/MARKET UPDATES ==== ArrayList<String> responses = comm.getAllMessages(); // ==== HERE IS WHERE WE UNPACK THE UPDATES FROM THE SERVER ==== for (int q = 0; q < responses.size(); q++) { String header = responses.get(q).substring(0, 4); if (header.equals("UNIV")) { theUniverse.unpack(responses.get(q)); Debug.msg("Unpacked a Universe"); theDisplay.updateDisplay(); } else if (header.equals("ROST")) { Roster.unpack(responses.get(q)); } else if (header.equals("MARK")) { theMarket.unpack(responses.get(q)); } else if (header.equals("SERV")) { Vector inParsed = ParseUtil.parseStringBySign(responses.get(q), '-'); myPlayerNum = Integer.parseInt((String) inParsed.elementAt(1)); } else Debug.msg("Unknown header recieved in ClientMain.actionPerformed() "); } }
public void unpack(String data) { Vector inParsed = ParseUtil.parseStringBySign(data, PARSE_CHAR); String header = (String) inParsed.elementAt(0); if (header.equals("SHIP")) { playerNum = Integer.parseInt((String) inParsed.elementAt(1)); numShips = Integer.parseInt((String) inParsed.elementAt(2)); destX = Integer.parseInt((String) inParsed.elementAt(3)); destY = Integer.parseInt((String) inParsed.elementAt(4)); } }