mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
Request Messages now sending to server, need to update game and send response packet.
tags: #story[1142]
This commit is contained in:
@@ -203,6 +203,9 @@ public class ServerToClientThread implements Runnable, Observer {
|
|||||||
|
|
||||||
completeRegistration(requestedType);
|
completeRegistration(requestedType);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case RACE_CUSTOMIZATION_REQUEST:
|
||||||
|
System.out.println("CUSTOMIZATION RECEIVED");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
logger.warn("Packet has been dropped", 1);
|
logger.warn("Packet has been dropped", 1);
|
||||||
|
|||||||
@@ -12,12 +12,12 @@ public class CustomizeRequestMessage extends Message {
|
|||||||
|
|
||||||
public CustomizeRequestMessage(CustomizeRequestType customizeType, double sourceID,
|
public CustomizeRequestMessage(CustomizeRequestType customizeType, double sourceID,
|
||||||
byte[] payload) {
|
byte[] payload) {
|
||||||
|
payloadLength = payload.length;
|
||||||
setHeader(new Header(MessageType.CUSTOMIZATION_REQUEST, 1, (short) getSize()));
|
setHeader(new Header(MessageType.CUSTOMIZATION_REQUEST, 1, (short) getSize()));
|
||||||
|
|
||||||
allocateBuffer();
|
allocateBuffer();
|
||||||
writeHeaderToBuffer();
|
writeHeaderToBuffer();
|
||||||
|
|
||||||
payloadLength = payload.length;
|
|
||||||
putInt((int) sourceID, 4);
|
putInt((int) sourceID, 4);
|
||||||
putInt((int) customizeType.getType(), 2);
|
putInt((int) customizeType.getType(), 2);
|
||||||
putBytes(payload);
|
putBytes(payload);
|
||||||
|
|||||||
@@ -1,8 +1,5 @@
|
|||||||
package seng302.model.stream.packets;
|
package seng302.model.stream.packets;
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by Kusal on 4/24/2017.
|
|
||||||
*/
|
|
||||||
public enum PacketType {
|
public enum PacketType {
|
||||||
HEARTBEAT,
|
HEARTBEAT,
|
||||||
RACE_STATUS,
|
RACE_STATUS,
|
||||||
@@ -21,7 +18,9 @@ public enum PacketType {
|
|||||||
BOAT_ACTION,
|
BOAT_ACTION,
|
||||||
OTHER,
|
OTHER,
|
||||||
RACE_REGISTRATION_REQUEST,
|
RACE_REGISTRATION_REQUEST,
|
||||||
RACE_REGISTRATION_RESPONSE;
|
RACE_REGISTRATION_RESPONSE,
|
||||||
|
RACE_CUSTOMIZATION_REQUEST,
|
||||||
|
RACE_CUSTOMIZATION_RESPONSE;
|
||||||
|
|
||||||
public static PacketType assignPacketType(int packetType, byte[] payload){
|
public static PacketType assignPacketType(int packetType, byte[] payload){
|
||||||
switch(packetType){
|
switch(packetType){
|
||||||
@@ -62,6 +61,10 @@ public enum PacketType {
|
|||||||
return RACE_REGISTRATION_REQUEST;
|
return RACE_REGISTRATION_REQUEST;
|
||||||
case 102:
|
case 102:
|
||||||
return RACE_REGISTRATION_RESPONSE;
|
return RACE_REGISTRATION_RESPONSE;
|
||||||
|
case 103:
|
||||||
|
return RACE_CUSTOMIZATION_REQUEST;
|
||||||
|
case 104:
|
||||||
|
return RACE_CUSTOMIZATION_RESPONSE;
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
return OTHER;
|
return OTHER;
|
||||||
|
|||||||
@@ -24,6 +24,8 @@ import org.slf4j.LoggerFactory;
|
|||||||
import seng302.gameServer.server.messages.BoatAction;
|
import seng302.gameServer.server.messages.BoatAction;
|
||||||
import seng302.gameServer.server.messages.BoatActionMessage;
|
import seng302.gameServer.server.messages.BoatActionMessage;
|
||||||
import seng302.gameServer.server.messages.ClientType;
|
import seng302.gameServer.server.messages.ClientType;
|
||||||
|
import seng302.gameServer.server.messages.CustomizeRequestMessage;
|
||||||
|
import seng302.gameServer.server.messages.CustomizeRequestType;
|
||||||
import seng302.gameServer.server.messages.Message;
|
import seng302.gameServer.server.messages.Message;
|
||||||
import seng302.gameServer.server.messages.RegistrationRequestMessage;
|
import seng302.gameServer.server.messages.RegistrationRequestMessage;
|
||||||
import seng302.gameServer.server.messages.RegistrationResponseStatus;
|
import seng302.gameServer.server.messages.RegistrationResponseStatus;
|
||||||
@@ -173,6 +175,15 @@ public class ClientToServerThread implements Runnable {
|
|||||||
clientLog("Closed connection to Server", 0);
|
clientLog("Closed connection to Server", 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void sendCustomizationRequest(CustomizeRequestType reqType, byte[] payload) {
|
||||||
|
CustomizeRequestMessage requestMessage = new CustomizeRequestMessage(reqType, this.clientId, payload);
|
||||||
|
try {
|
||||||
|
os.write(requestMessage.getBuffer());
|
||||||
|
} catch (IOException e) {
|
||||||
|
logger.error("Could not send customization request");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a request to the server asking for a source ID
|
* Sends a request to the server asking for a source ID
|
||||||
|
|||||||
@@ -136,6 +136,7 @@ public class GameClient {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
LobbyController lobbyController = fxmlLoader.getController();
|
LobbyController lobbyController = fxmlLoader.getController();
|
||||||
|
lobbyController.setSocketThread(socketThread);
|
||||||
lobbyController.setPlayerListSource(clientLobbyList);
|
lobbyController.setPlayerListSource(clientLobbyList);
|
||||||
lobbyController.setPlayerID(socketThread.getClientId());
|
lobbyController.setPlayerID(socketThread.getClientId());
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package seng302.visualiser.controllers;
|
||||||
|
|
||||||
|
import javafx.fxml.FXML;
|
||||||
|
import javafx.scene.control.Button;
|
||||||
|
import javafx.scene.control.ColorPicker;
|
||||||
|
import javafx.scene.control.TextField;
|
||||||
|
import seng302.gameServer.server.messages.CustomizeRequestType;
|
||||||
|
import seng302.visualiser.ClientToServerThread;
|
||||||
|
|
||||||
|
public class CustomizationController {
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private TextField nameField;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private ColorPicker boatColorPicker;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private Button customizeSubmit;
|
||||||
|
|
||||||
|
private ClientToServerThread socketThread;
|
||||||
|
|
||||||
|
public void initialize() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setServerThread(ClientToServerThread ctsThread) {
|
||||||
|
this.socketThread = ctsThread;
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
public void submitCustomization() {
|
||||||
|
System.out.println("Attempting to send");
|
||||||
|
socketThread.sendCustomizationRequest(CustomizeRequestType.NAME, nameField.getText().getBytes());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,5 +1,8 @@
|
|||||||
package seng302.visualiser.controllers;
|
package seng302.visualiser.controllers;
|
||||||
|
|
||||||
|
import com.sun.deploy.util.SessionState.Client;
|
||||||
|
import com.sun.media.jfxmedia.logging.Logger;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -7,13 +10,18 @@ import javafx.application.Platform;
|
|||||||
import javafx.collections.ListChangeListener;
|
import javafx.collections.ListChangeListener;
|
||||||
import javafx.collections.ObservableList;
|
import javafx.collections.ObservableList;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
|
import javafx.fxml.FXMLLoader;
|
||||||
|
import javafx.scene.Parent;
|
||||||
|
import javafx.scene.Scene;
|
||||||
import javafx.scene.control.Button;
|
import javafx.scene.control.Button;
|
||||||
import javafx.scene.control.TextArea;
|
import javafx.scene.control.TextArea;
|
||||||
import javafx.scene.image.Image;
|
import javafx.scene.image.Image;
|
||||||
import javafx.scene.image.ImageView;
|
import javafx.scene.image.ImageView;
|
||||||
import javafx.scene.text.Text;
|
import javafx.scene.text.Text;
|
||||||
|
import javafx.stage.Stage;
|
||||||
import seng302.gameServer.GameStages;
|
import seng302.gameServer.GameStages;
|
||||||
import seng302.gameServer.GameState;
|
import seng302.gameServer.GameState;
|
||||||
|
import seng302.visualiser.ClientToServerThread;
|
||||||
import seng302.visualiser.GameView;
|
import seng302.visualiser.GameView;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -72,6 +80,8 @@ public class LobbyController {
|
|||||||
private List<ImageView> imageViews = new ArrayList<>();
|
private List<ImageView> imageViews = new ArrayList<>();
|
||||||
private List<TextArea> listViews = new ArrayList<>();
|
private List<TextArea> listViews = new ArrayList<>();
|
||||||
|
|
||||||
|
private ClientToServerThread socketThread;
|
||||||
|
|
||||||
private int MAX_NUM_PLAYERS = 8;
|
private int MAX_NUM_PLAYERS = 8;
|
||||||
private Integer playerID;
|
private Integer playerID;
|
||||||
|
|
||||||
@@ -129,7 +139,23 @@ public class LobbyController {
|
|||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
public void customize() {
|
public void customize() {
|
||||||
System.out.println(playerID);
|
Parent root;
|
||||||
|
try {
|
||||||
|
FXMLLoader fxmlLoader = new FXMLLoader(LobbyController.class.getResource("/views/customizeView.fxml"));
|
||||||
|
root = fxmlLoader.load();
|
||||||
|
Stage customizeStage = new Stage();
|
||||||
|
CustomizationController cc = fxmlLoader.getController();
|
||||||
|
cc.setServerThread(this.socketThread);
|
||||||
|
customizeStage.setTitle("Customize Boat");
|
||||||
|
customizeStage.setScene(new Scene(root, 700, 450));
|
||||||
|
customizeStage.show();
|
||||||
|
} catch (IOException e) {
|
||||||
|
Logger.logMsg(4, "Failed to load Customization View from resources.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSocketThread(ClientToServerThread thread) {
|
||||||
|
this.socketThread = thread;
|
||||||
}
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<?import javafx.scene.text.*?>
|
||||||
|
<?import javafx.scene.control.*?>
|
||||||
|
<?import java.lang.*?>
|
||||||
|
<?import javafx.scene.layout.*?>
|
||||||
|
|
||||||
|
<GridPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="seng302.visualiser.controllers.CustomizationController">
|
||||||
|
<columnConstraints>
|
||||||
|
<ColumnConstraints fillWidth="false" halignment="CENTER" hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
|
||||||
|
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
|
||||||
|
</columnConstraints>
|
||||||
|
<rowConstraints>
|
||||||
|
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
||||||
|
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
||||||
|
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
||||||
|
</rowConstraints>
|
||||||
|
<children>
|
||||||
|
<TextField fx:id="nameField" GridPane.columnIndex="1" />
|
||||||
|
<ColorPicker fx:id="boatColorPicker" GridPane.columnIndex="1" GridPane.halignment="CENTER" GridPane.rowIndex="1" GridPane.valignment="CENTER" />
|
||||||
|
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="Player Name" />
|
||||||
|
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="Boat Color" GridPane.rowIndex="1" />
|
||||||
|
<Button fx:id="customizeSubmit" mnemonicParsing="false" onAction="#submitCustomization" text="Submit" GridPane.columnIndex="1" GridPane.halignment="CENTER" GridPane.rowIndex="2" GridPane.valignment="CENTER" />
|
||||||
|
</children>
|
||||||
|
</GridPane>
|
||||||
Reference in New Issue
Block a user