How teahana/tic-tac-toe works
Project type and purpose
• This is a small full-stack Java “game” server that serves static HTML to a browser client and manages Single-player, Multi-player, Chat, and Authentication over TCP/IP sockets.
• It uses Maven (pom.xml), plain Java (no heavyweight framework), and a handful of HTML files as its “view.”
File structure
• Top-level:
• pom.xml – Maven build + JDK settings
• src/main/java/org/example/Server.java – TCP server bootstrap & routing
• src/main/java/org/example/Client.java – abstraction of a connected client
• src/main/java/org/example/Game.java – core game‐state & logic
• src/main/java/org/example/*.html – view templates (auth.html, chat.html, game.html, menu.html)
• No separate “frontend” project: HTML lives alongside Java code, so server both hosts static pages and manages socket endpoints.
• No database/config directory: all state likely in-memory, routing by endpoints in Server.java.
README for additional insights
• The server listens on a TCP port (default 8080).
• Endpoints: /auth, /signout, /menu, /singleplayer, /multiplayer, /chat.
• All endpoints are guarded: unauthenticated users get redirected to /auth; unknown endpoints → /menu.
a. Main components:
• Browser Client (User’s Chrome/Firefox) – loads HTML + opens socket.
• Java TCP Server (Server.java) – single container listening on port 8080.
• Static View Layer – auth.html, menu.html, chat.html, game.html.
• Controller Layer inside the server – routing logic for Auth, Menu, SinglePlayer, Multiplayer, Chat.
• Game Engine (Game.java) – encapsulates game rules, single-player AI, multi-player session management.
• Client Handler (Client.java) – represents each connected browser, manages I/O, session state.
b. Relationships & Interactions:
1. Browser Client → (HTTP/TCP) → Server: initial request for HTML + socket handshake.
2. Server’s Router → dispatch to AuthController or MenuController based on endpoint & session.
3. AuthController → verifies credentials (in-memory), sets session in Client instance.
4. Client Handler ↔ Game Engine for game state updates:
– Single-player: Game.java invoked directly
– Multi-player: Game.java coordinates multiple Client instances
5. ChatController ↔ Client instances to broadcast chat messages.
6. Server → serves HTML files from “view” folder to the browser.
c. Architectural patterns & design principles:
• MVC-style separation: HTML “views,” routing “controllers” in Server.java, “model” in Game.java & Client.java.
• Single container (no microservices), in-memory session store.
• Socket‐based message passing instead of REST.
d. Key technologies/frameworks:
• Java SE (java.net.ServerSocket / Socket)
• Maven for build (pom.xml)
• Plain HTML for front-end
• In-memory session management (Client.java instances)
Final reminder
• Be very detailed: break the server into Controller, Game Engine, Client Handler, Static View.
• Every endpoint and show how session guards route requests.
• Lifecycle of a single player connecting → authenticating → playing/chating → signing out.