Commit Graph

4 Commits

Author SHA1 Message Date
52d4602e33 feat(chat): colorize usernames by ID; refine IDs/usernames and /name parsing
Server:
- Generate 6-char IDs from lowercase hex alphabet "abcdef0123456789"
- Default username now uses the ID as-is (no extra ToLower)
- Use strings.CutPrefix for robust “/name ” command parsing

Client:
- Add colorizeLine to apply ANSI colors based on 6-hex-digit ID
  - Colorize chat lines: "<name> (<id>): <msg>"
  - Colorize [join]/[leave] notices
  - Colorize [rename] events
  - Colorize Welcome banner
- Apply colorizeLine to incoming netMsg before appending

Notes:
- ID regex patterns accept 6 hex digits (case-insensitive), rendered in lowercase
- Keeps non-matching lines unchanged
2025-10-15 11:27:16 +07:00
2c884d030a feat(server): usernames, IDs, and commands; sanitize names; richer join/leave messages
- Add go-nanoid to generate 6-char per-connection IDs; fallback to RemoteAddr
- Introduce sanitizeUsername with rules: [A-Za-z0-9_.-], spaces→_, trim ._-, max 12 chars
- Support /name <username> to change username with validation and broadcast [rename]
- Greet client with default username user_<id> and usage hint for /name
- Broadcast joins/leaves and messages including username and ID; exclude self on join
- Handle /quit to trigger unified leave flow; consistent leave announcement
- Comment/document broadcast struct, Hub, and startTCPServer
- Increase scanner buffer and add newline-delimited send in broadcaster
2025-10-15 11:25:56 +07:00
b80c5190a3 feat(chat): CLI flags, centered header; improve server with selective broadcast and quit handling
Client/main:
- Add flags: -host (default "localhost:9000") and -server (run only server)
- When -server is set, startTCPServer(host) and exit
- Use provided host for client connection
- Center header with width-aware lipgloss styling; adjust padding

Server:
- Introduce broadcast struct {text string, exclude net.Conn}
- Hub.msgCh now chan broadcast; send messages with optional exclusion
- On join: send “[join] …” to others (exclude the joiner)
- Broadcast chat lines without exclusion; newline-delimited as before
- Handle “/quit” by breaking loop (graceful disconnect)
- On leave: broadcast “[leave] …” to all

Refactor notes:
- Remove unconditional embedded server from client startup
- Scanner loop unchanged aside from quit handling and broadcast usage
2025-10-15 11:25:16 +07:00
2651178a16 initial commit 2025-10-15 00:19:34 +07:00