mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 06:18:44 +00:00
Fixed broken pipe error.
Was caused by boat ids being over 1000 and when turned into xml having a comma placed between the hundreds and the thousands? So to fix, I just mad the max id number 999 so there should not be any issues regarding that if another broken pipe error occurs. Also switched to use the correct yacht constructor. #story[1047]
This commit is contained in:
@@ -273,7 +273,7 @@ public class ClientPacketParser {
|
||||
long messageLength = bytesToLong(Arrays.copyOfRange(payload, 12, 14));
|
||||
String xmlMessage = new String(
|
||||
(Arrays.copyOfRange(payload, 14, (int) (14 + messageLength)))).trim();
|
||||
System.out.println(xmlMessage);
|
||||
|
||||
//Create XML document Object
|
||||
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder db = null;
|
||||
@@ -375,8 +375,6 @@ public class ClientPacketParser {
|
||||
double lon = ((180d * (double) rawLon) / Math.pow(2, 31));
|
||||
long heading = bytesToLong(Arrays.copyOfRange(payload, 28, 30));
|
||||
double groundSpeed = bytesToLong(Arrays.copyOfRange(payload, 38, 40)) / 1000.0;
|
||||
System.out.println("boats = " + boats.values());
|
||||
System.out.println("boats = " + boats.keySet());
|
||||
//type 1 is a racing yacht and type 3 is a mark, needed for updating positions of the mark and boat
|
||||
if (deviceType == 1){
|
||||
Yacht boat = boats.get((int) boatId);
|
||||
|
||||
@@ -84,6 +84,7 @@ public class ClientToServerThread extends Thread {
|
||||
}
|
||||
} catch (Exception e) {
|
||||
closeSocket();
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import seng302.server.messages.BoatLocationMessage;
|
||||
import seng302.server.messages.Message;
|
||||
import seng302.server.messages.XMLMessage;
|
||||
import seng302.server.messages.XMLMessageSubType;
|
||||
import seng302.utilities.GeoPoint;
|
||||
|
||||
/**
|
||||
* A class describing a single connection to a Client for the purposes of sending and receiving on its own thread.
|
||||
@@ -57,8 +58,9 @@ public class ServerToClientThread extends Thread {
|
||||
}
|
||||
// threeWayHandshake();
|
||||
Random rand = new Random();
|
||||
sourceId = rand.nextInt(100000);
|
||||
sourceId = rand.nextInt(1000);
|
||||
Yacht yacht = new Yacht("Yacht", sourceId, sourceId.toString(), "Kap", "Kappa", "NZ");
|
||||
// Yacht yacht = new Yacht("Kappa", "Kap", new GeoPoint(57.6708220, 11.8321340), 90.0);
|
||||
GameState.addYacht(sourceId, yacht);
|
||||
GameState.addPlayer(new Player(socket, yacht));
|
||||
seqNo = 0;
|
||||
@@ -140,7 +142,7 @@ public class ServerToClientThread extends Thread {
|
||||
}
|
||||
|
||||
//@TODO calculate lat/lng values
|
||||
xml.setRegatta(new Regatta("RaceVision Test Game", 0d, 0d));
|
||||
xml.setRegatta(new Regatta("RaceVision Test Game", 57.6679590, 11.8503233));
|
||||
xml.setRace(race);
|
||||
|
||||
XMLMessage xmlMessage = new XMLMessage(xml.getRegattaAsXml(), XMLMessageSubType.REGATTA, xml.getRegattaAsXml().length());
|
||||
@@ -247,10 +249,6 @@ public class ServerToClientThread extends Thread {
|
||||
ArrayList<Yacht> yachts = new ArrayList<>(GameState.getYachts().values());
|
||||
for (Yacht yacht: yachts){
|
||||
BoatLocationMessage boatLocationMessage = new BoatLocationMessage(sourceId, getSeqNo(), yacht.getLocation().getLat(), yacht.getLocation().getLng(), yacht.getHeading(), (long) yacht.getVelocity());
|
||||
// System.out.println("yacht.getLocation().getLat() = " + yacht.getLocation().getLat());
|
||||
// System.out.println("yacht.getLocation().getLng() = " + yacht.getLocation().getLng());
|
||||
// System.out.println("yacht.getBoatName() = " + yacht.getBoatName());
|
||||
// System.out.println("yacht = " + sourceId);
|
||||
sendMessage(boatLocationMessage);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ public class Yacht {
|
||||
private Color colour;
|
||||
|
||||
private String boatType;
|
||||
private Integer sourceID;
|
||||
private Integer sourceId;
|
||||
private String hullID; //matches HullNum in the XML spec.
|
||||
private String shortName;
|
||||
private String boatName;
|
||||
@@ -73,14 +73,14 @@ public class Yacht {
|
||||
this.boatName = boatName;
|
||||
this.velocity = boatVelocity;
|
||||
this.shortName = shortName;
|
||||
this.sourceID = id;
|
||||
this.sourceId = id;
|
||||
this.location = new GeoPoint(0.0, 0.0);
|
||||
}
|
||||
|
||||
public Yacht(String boatType, Integer sourceID, String hullID, String shortName,
|
||||
public Yacht(String boatType, Integer sourceId, String hullID, String shortName,
|
||||
String boatName, String country) {
|
||||
this.boatType = boatType;
|
||||
this.sourceID = sourceID;
|
||||
this.sourceId = sourceId;
|
||||
this.hullID = hullID;
|
||||
this.shortName = shortName;
|
||||
this.boatName = boatName;
|
||||
@@ -132,8 +132,8 @@ public class Yacht {
|
||||
|
||||
public Integer getSourceId() {
|
||||
//@TODO Remove and merge with Creating Game Loop
|
||||
if (sourceID == null) return 0;
|
||||
return sourceID;
|
||||
if (sourceId == null) return 0;
|
||||
return sourceId;
|
||||
}
|
||||
|
||||
public String getHullID() {
|
||||
@@ -167,7 +167,8 @@ public class Yacht {
|
||||
}
|
||||
|
||||
public void setLegNumber(Integer legNumber) {
|
||||
if (colour != null && position != "-" && legNumber != this.legNumber&& RaceViewController.sparkLineStatus(sourceID)) {
|
||||
if (colour != null && position != "-" && legNumber != this.legNumber&& RaceViewController.sparkLineStatus(
|
||||
sourceId)) {
|
||||
RaceViewController.updateYachtPositionSparkline(this, legNumber);
|
||||
}
|
||||
this.legNumber = legNumber;
|
||||
|
||||
@@ -19,8 +19,8 @@
|
||||
<Boat Type="Yacht" SourceID="${boat.sourceId}" ShapeID="4" HullNum="${boat.hullID}" StoweName="${boat.shortName}" ShortName="${boat.shortName}"
|
||||
BoatName="${boat.boatName}" Country="${boat.country}">
|
||||
|
||||
<GPSposition Z="0" Y="${boat.location.lat}" X="${boat.location.lng}" />
|
||||
<MastTop Z="0" Y="${boat.location.lat}" X="${boat.location.lng}" />
|
||||
<GPSposition Z="0" Y="3.7" X="0" />
|
||||
<MastTop Z="0" Y="6.2" X="0" />
|
||||
</Boat>
|
||||
</#list>
|
||||
</Boats>
|
||||
|
||||
Reference in New Issue
Block a user