packets can now be sent from client to match server

#story[1188]
This commit is contained in:
hba56
2017-08-30 15:26:54 +12:00
parent b2bd4fdc1c
commit 83f756d7d8
6 changed files with 130 additions and 33 deletions
@@ -4,16 +4,11 @@ import javafx.fxml.FXML;
import javafx.scene.control.TextField;
import javafx.scene.layout.AnchorPane;
import mock.app.Event;
import org.xml.sax.SAXException;
import mock.exceptions.EventConstructionException;
import shared.exceptions.InvalidBoatDataException;
import shared.exceptions.InvalidRaceDataException;
import shared.exceptions.InvalidRegattaDataException;
import shared.exceptions.XMLReaderException;
import visualiser.network.MatchBrowserInterface;
import javax.xml.bind.JAXBException;
import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;
import java.net.DatagramSocket;
import java.net.Socket;
import java.net.URL;
import java.util.ResourceBundle;
@@ -36,6 +31,7 @@ public class HostController extends Controller {
AnchorPane hostWrapper;
private Event game;
private DatagramSocket udpSocket;
@Override
@@ -50,12 +46,25 @@ public class HostController extends Controller {
try {
this.game = new Event(false);
connectSocket("localhost", 4942);
alertMatchBrowser();
} catch (EventConstructionException e) {
Logger.getGlobal().log(Level.SEVERE, "Could not create Event.", e);
throw new RuntimeException(e);
}
}
/**
* Sends info to the match browser so clients can see it
*/
public void alertMatchBrowser(){
MatchBrowserInterface matchBrowserInterface = new MatchBrowserInterface();
try{
matchBrowserInterface.sendOutGameInfo(this.game.getHostedGameData(), udpSocket);
}catch (IOException e){
System.err.println("failed to send out hosted game info");
}
}
public void endEvent() throws IOException {
game.endEvent();
}
@@ -80,8 +89,9 @@ public class HostController extends Controller {
/**
* Hosts a game.
*/
public void hostGame(){
public void hostGame(DatagramSocket udpSocket){
hostWrapper.setVisible(true);
this.udpSocket = udpSocket;
}
public void menuBtnPressed(){
@@ -11,6 +11,7 @@ import javafx.scene.layout.AnchorPane;
import visualiser.model.RaceConnection;
import java.io.IOException;
import java.net.DatagramSocket;
import java.net.Socket;
import java.net.URL;
import java.util.ResourceBundle;
@@ -39,6 +40,9 @@ public class LobbyController extends Controller {
private ObservableList<RaceConnection> connections;
//the socket for match browser
private DatagramSocket udpSocket;
@Override
public void initialize(URL location, ResourceBundle resources) {
@@ -120,7 +124,8 @@ public class LobbyController extends Controller {
/**
* Enter the lobby page.
*/
public void enterLobby(){
public void enterLobby(DatagramSocket udpSocket){
lobbyWrapper.setVisible(true);
this.udpSocket = udpSocket;
}
}
@@ -3,12 +3,13 @@ package visualiser.Controllers;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.layout.AnchorPane;
import visualiser.app.App;
import visualiser.gameController.ControllerClient;
import visualiser.model.VisualiserBoat;
import visualiser.model.VisualiserRaceEvent;
import visualiser.network.MatchBrowserInterface;
import java.io.IOException;
import java.net.DatagramSocket;
import java.net.Socket;
import java.net.URL;
import java.util.ResourceBundle;
@@ -27,11 +28,20 @@ public class MainController extends Controller {
@FXML private HostController hostController;
@FXML private LobbyController lobbyController;
private MatchBrowserInterface matchBrowserInterface;
private DatagramSocket udpSocket;
/**
* Ctor.
*/
public MainController() {
this.matchBrowserInterface = new MatchBrowserInterface();
try{
this.udpSocket = matchBrowserInterface.setupMatchBowserConnection();
}catch (IOException e){
System.err.println("Error in setting up connection with match browser");
}
}
@@ -74,12 +84,12 @@ public class MainController extends Controller {
/**
* Transitions into lobby screen
*/
public void enterLobby(){ lobbyController.enterLobby(); }
public void enterLobby(){ lobbyController.enterLobby(udpSocket); }
/**
* Transitions into host game screen
*/
public void hostGame(){ hostController.hostGame(); }
public void hostGame(){ hostController.hostGame(udpSocket); }
/**
* Sets up the css for the start of the program