Skip to content

Commit 972fa2a

Browse files
committed
feat: Add server IP and name display to welcome banner
1 parent 373fffe commit 972fa2a

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
push:
55
branches:
66
- main
7+
- dev
78

89
permissions:
910
contents: read

server/src/main/java/com/minitankfire/server/GameServer.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.io.BufferedReader;
44
import java.io.IOException;
55
import java.io.InputStreamReader;
6+
import java.net.InetAddress;
67
import java.net.ServerSocket;
78
import java.net.Socket;
89
import java.util.concurrent.ExecutorService;
@@ -55,6 +56,17 @@ public GameServer(int port) throws IOException {
5556
* Prints welcome banner with server information
5657
*/
5758
private void printBanner(int port) {
59+
String hostAddress;
60+
String hostName;
61+
try {
62+
InetAddress localHost = InetAddress.getLocalHost();
63+
hostAddress = localHost.getHostAddress();
64+
hostName = localHost.getHostName();
65+
} catch (Exception e) {
66+
hostAddress = "localhost";
67+
hostName = "localhost";
68+
}
69+
5870
System.out.println("╔════════════════════════════════════════════════════════════╗");
5971
System.out.println("║ 🎮 Tank Game Server - Pure Java Network Programming ║");
6072
System.out.println("╠════════════════════════════════════════════════════════════╣");
@@ -64,8 +76,10 @@ private void printBanner(int port) {
6476
System.out.println("║ ✓ Real-time Game Loop (20 FPS) ║");
6577
System.out.println("║ ✓ Concurrent State Management ║");
6678
System.out.println("╠════════════════════════════════════════════════════════════╣");
67-
System.out.println("║ Server Address: 0.0.0.0:" + String.format("%-43s", port) + "║");
68-
System.out.println("║ WebSocket URI: ws://localhost:" + String.format("%-37s", port + "/game") + "║");
79+
System.out.println("║ Server IP: " + hostAddress + String.format("%" + (50 - hostAddress.length()) + "s", "") + "║");
80+
System.out.println("║ Server Name: " + hostName + String.format("%" + (46 - hostName.length()) + "s", "") + "║");
81+
System.out.println("║ Port: " + String.format("%-52s", port) + "║");
82+
System.out.println("║ WebSocket URI: ws://" + hostName + ":" + String.format("%-32s", port + "/game") + "║");
6983
System.out.println("║ Max Clients: " + String.format("%-48s", MAX_CLIENTS) + "║");
7084
System.out.println("╚════════════════════════════════════════════════════════════╝");
7185
}

0 commit comments

Comments
 (0)