33import java .io .BufferedReader ;
44import java .io .IOException ;
55import java .io .InputStreamReader ;
6+ import java .net .InetAddress ;
67import java .net .ServerSocket ;
78import java .net .Socket ;
89import 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