mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
Finished implementing room codes.
- Fixed bug where room code wasn't parsed correctly - Added room code selection to server list screen. - Added room code to hosts lobby. - Implemented communication protocols on the game client. Tags: #story[1281]
This commit is contained in:
@@ -3,6 +3,8 @@ package seng302.gameServer;
|
||||
import com.sun.org.apache.xpath.internal.operations.Bool;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import seng302.serverRepository.ServerListing;
|
||||
import seng302.serverRepository.ServerRepositoryClient;
|
||||
|
||||
import javax.jmdns.JmDNS;
|
||||
import javax.jmdns.ServiceInfo;
|
||||
@@ -31,17 +33,20 @@ public class ServerAdvertiser {
|
||||
*/
|
||||
private static String SERVICE = "_partyatsea";
|
||||
private static String PROTOCOL = "_tcp";
|
||||
public static String SERVICE_TYPE = SERVICE + "." + PROTOCOL + ".homekit.bonjour.michaelrausch.nz.";
|
||||
public static String SERVICE_TYPE = SERVICE + "." + PROTOCOL + ".local.";
|
||||
|
||||
private static ServerAdvertiser instance = null;
|
||||
private static JmDNS jmdnsInstance = null;
|
||||
private ServiceInfo serviceInfo; // Note: Whenever this is changed, our service will be re-registered on the network.
|
||||
private ServerRepositoryClient repositoryClient;
|
||||
|
||||
private Hashtable<String ,String> props;
|
||||
|
||||
private ServerAdvertiser() throws IOException{
|
||||
jmdnsInstance = JmDNS.create(InetAddress.getByName(getLocalHostIp()));
|
||||
|
||||
repositoryClient = new ServerRepositoryClient();
|
||||
|
||||
props = new Hashtable<>();
|
||||
props.put("map", "");
|
||||
props.put("spacesLeft", "0");
|
||||
@@ -130,6 +135,9 @@ public class ServerAdvertiser {
|
||||
}
|
||||
}
|
||||
}, 0);
|
||||
|
||||
ServerListing serverListing = new ServerListing(serverName, props.get("map"), getLocalHostIp(), portNo, Integer.parseInt(props.get("capacity")));
|
||||
repositoryClient.register(serverListing);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,13 +1,32 @@
|
||||
package seng302.gameServer.messages;
|
||||
|
||||
import seng302.serverRepository.ServerListing;
|
||||
|
||||
public class ServerRegistrationMessage extends Message {
|
||||
private int size;
|
||||
|
||||
public ServerRegistrationMessage(ServerListing serverListing) {
|
||||
String serverName = serverListing.getServerName();
|
||||
String mapName = serverListing.getMapName();
|
||||
String address = serverListing.getAddress();
|
||||
int port = serverListing.getPortNumber();
|
||||
int players = serverListing.getPortNumber();
|
||||
int capacity = serverListing.getCapacity();
|
||||
String roomCode = serverListing.getRoomCode();
|
||||
|
||||
createMessage(serverName, mapName, address, port, players, capacity, roomCode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
public ServerRegistrationMessage(String serverName, String mapName, String address, int port, int players, int capacity, String roomCode){
|
||||
createMessage(serverName, mapName, address, port, players, capacity, roomCode);
|
||||
}
|
||||
|
||||
private void createMessage(String serverName, String mapName, String address, int port, int players, int capacity, String roomCode){
|
||||
size = serverName.getBytes().length + mapName.length() + address.length() + roomCode.length() + 36;
|
||||
|
||||
setHeader(new Header(MessageType.REPO_REGISTRATION_REQUEST, 0x01, (short) getSize()));
|
||||
@@ -37,4 +56,5 @@ public class ServerRegistrationMessage extends Message {
|
||||
writeCRC();
|
||||
rewind();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user