public void run() { Server.preRunOperations(this); while (true) { try { String type = in.readUTF(); if (type.equals("newObject")) { Object object = in.readObject(); if (object instanceof String) { // Adding player.. this.player = new Player((String) object, Entity.BLUE); boolean addPlayer = true; for (int i = 0; i < Server.players.size(); i++) { if (this.player.name.equals(Server.players.get(i).name)) { // Set to online! if (Server.players.get(i).online) { System.out.println( "Player " + player.name + " is already connected! " + (userID + 1)); this.player = null; addPlayer = false; } else { this.player = Server.players.get(i); System.out.println("Returning User: "******", " + (userID + 1)); this.player.online = true; addPlayer = false; } break; } } if (addPlayer) { System.out.println("New User: "******", " + (userID + 1)); Server.players.add(this.player); } } } else if (type.equals( "MoveUnit")) { // this needs to require the player to be the owner of the unit short unit = in.readShort(); double cX = in.readDouble(); double cY = in.readDouble(); double x = in.readDouble(); double y = in.readDouble(); boolean stacked = in.readBoolean(); // Pretty simple: (If the unit doesn't "exist", game will take care of that.) [Keep in // mind, this currently could easily let the player control enemy units] new PathFind( unit, cX, cY, x, y, stacked); // All commands take the liberty of adding themselves to the game stack. } else if (type.equals( "SetTarget")) { // this needs to require the player to be the owner of the unit short unit = in.readShort(); short enemy = in.readShort(); boolean stacked = in.readBoolean(); // Pretty simple: new SetTarget(unit, enemy, stacked); } else if (type.equals("AddOrder")) { short unit = in.readShort(); byte order = in.readByte(); double atX = in.readDouble(); double atY = in.readDouble(); boolean stacked = in.readBoolean(); new AddOrder(unit, order, atX, atY, stacked); } else if (type.equals("Uber")) { short unit = in.readShort(); boolean stacked = in.readBoolean(); new Uber(unit, stacked); } else if (type.equals("Exiting")) { disconnect(); return; } } catch (IOException e) { disconnect(); return; } catch (Exception e) { System.out.println("Alternate error."); e.printStackTrace(); } } }