Show server IP while wait for connection
This commit is contained in:
parent
df7982d202
commit
cfbbbde701
@ -36,6 +36,7 @@ public class GameCanvas extends DoubleBufferedCanvas implements Runnable, Networ
|
||||
|
||||
private final boolean serverInstance;
|
||||
private SocketHelper socketHelper;
|
||||
private String inetAddress;
|
||||
|
||||
private boolean gameStarted, serverMove;
|
||||
private int serverWinCount, clientWinCount, winState;
|
||||
@ -69,8 +70,12 @@ public class GameCanvas extends DoubleBufferedCanvas implements Runnable, Networ
|
||||
wind.drawInfo(g, metrics);
|
||||
} else {
|
||||
g.setColor(Color.WHITE);
|
||||
final int x = (Constants.WIDTH - metrics.stringWidth(WAIT_MESSAGE)) / 2;
|
||||
g.drawString(WAIT_MESSAGE, x, Constants.HEIGHT - metrics.getHeight() * 2);
|
||||
final String str;
|
||||
if (serverInstance && (inetAddress != null)) {
|
||||
str = WAIT_MESSAGE + " " + inetAddress;
|
||||
} else str = WAIT_MESSAGE;
|
||||
final int x = (Constants.WIDTH - metrics.stringWidth(str)) / 2;
|
||||
g.drawString(str, x, Constants.HEIGHT - metrics.getHeight() * 2);
|
||||
}
|
||||
}
|
||||
|
||||
@ -121,6 +126,7 @@ public class GameCanvas extends DoubleBufferedCanvas implements Runnable, Networ
|
||||
private void initNetwork() {
|
||||
try {
|
||||
if (serverInstance) {
|
||||
inetAddress = GameServer.getInetAddress();
|
||||
GameServer server = new GameServer(this);
|
||||
socketHelper = server.getHelper();
|
||||
} else {
|
||||
|
@ -2,7 +2,9 @@ package com.annimon.turrets.network;
|
||||
|
||||
import static com.annimon.turrets.Constants.PORT;
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.ServerSocket;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -21,4 +23,8 @@ public class GameServer {
|
||||
public SocketHelper getHelper() {
|
||||
return helper;
|
||||
}
|
||||
|
||||
public static String getInetAddress() throws UnknownHostException {
|
||||
return InetAddress.getLocalHost().getHostAddress();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user