7.0 KiB
🚀 Advanced Chat Server & Client
A feature-rich, production-ready chat server and client built with Python and WebSockets. Supports both centralized server mode and peer-to-peer (P2P) LAN communication with file sharing capabilities. Works on local development and hosted deployment (Ubuntu).
✨ Features
Core Features
- ✅ Unified Client: Single client for both Server and P2P LAN modes
- ✅ Peer-to-Peer (P2P): Chat without a server on your local network
- ✅ File Sharing: Send and receive files up to 50MB in both modes
- ✅ Real-time Messaging: Instant communication with low latency
- ✅ Multiple Rooms: Join different channels with password protection
- ✅ User Authentication: Secure identification for server-based chat
- ✅ Admin System: Comprehensive moderation tools
- ✅ SSL/TLS Support: Encrypted connections for server mode
Advanced Features
-
Account & Registration
- User registration with password hashing
- Secure authentication
- Nickname management
-
Room Management
- Create public and private rooms
- Password-protected rooms
- Room topics and announcements
- User lists per room
-
Invite System
- Generate time-limited invite codes
- Configurable max uses
- Invite tracking and revocation
-
Message Search
- Full-text search across messages
- Filter by room, user, and date
- Search history
-
Message Replies
- Thread-based conversations
- Quote original messages
- Reply tracking
-
User Blocks
- Block/ignore users
- Temporary or permanent blocks
- Block list management
-
Command Aliases
- Create custom command shortcuts
- Alias usage tracking
- Personal alias management
-
Room Announcements
- Broadcast important messages
- Time-limited announcements
- Announcement history
-
Scheduled Messages
- Schedule messages for future delivery
- Multiple time formats (HH:MM, +1h, +30m, +7d)
- Cancel scheduled messages
-
Room Bookmarks
- Save favorite rooms/commands
- Quick access to bookmarks
- Usage statistics
-
Message Export
- Export room history
- Export user messages
- Multiple export formats
-
Room Backups
- Password-protected backups
- Full room state preservation
- Backup restoration
-
Notification Rules
- Keyword notifications
- User-specific notifications
- @mention support
- Cooldown periods
-
Offline Messages
- Queue messages for offline users
- Automatic delivery on reconnect
- Message expiration
-
Admin System
- Admin privilege management
- Clear chat history
- User management
- System monitoring
🛠️ Installation
Prerequisites
- Python 3.8 or higher
- pip (Python package manager)
- Optional (for Advanced Features):
cryptography: Required for End-to-End Encryption (E2EE)Pillow: Required for ASCII Image Art featuresprompt-toolkit
Windows (Local Development)
- Clone or download this repository
- Run the setup script:
setup_windows.bat - Edit
.envfile with your configuration - Start the server:
python server.py - In a new terminal, start the client:
python client.py
Manual Installation
# Install dependencies
pip install -r requirements.txt
# Copy environment template
cp .env.example .env
# Edit .env with your configuration
# Start server
python server.py
# In another terminal, start client
python client.py
⚙️ Configuration
Edit the .env file to configure the server:
# Server Configuration
HOST=0.0.0.0 # Bind to all interfaces
PORT=8765 # WebSocket port
MAX_HISTORY=100 # Messages to keep in history
# Admin Configuration
ADMIN_PASSWORD=admin123 # Change this!
# SSL Configuration (optional)
USE_SSL=false
SSL_CERT_PATH=/path/to/cert.pem
SSL_KEY_PATH=/path/to/key.pem
# Database
DB_PATH=chat.db
# Logging
LOG_LEVEL=INFO
LOG_FILE=chat_server.log
# Security
MAX_MESSAGE_LENGTH=4096
MAX_NICKNAME_LENGTH=32
RATE_LIMIT_MESSAGES=120
RATE_LIMIT_WINDOW=60
# Session
SESSION_TIMEOUT=3600
KEEPALIVE_INTERVAL=30
RECONNECT_TIMEOUT=300
# Backups
BACKUP_DIR=./backups
AUTO_BACKUP_ENABLED=false
AUTO_BACKUP_INTERVAL=86400
🎮 Usage
Server
Start the server with default settings:
python server.py
Or with custom options:
python server.py --host 0.0.0.0 --port 8765 --admin-pass mypassword
Client
Start the unified client:
python client.py
The client will prompt you to choose a server:
- On default it will say wss://server.wholeworldcoding.com/radio
- If you are running the server locally please type: ws:/localhost:8765
File Sharing
To share a file:
- Type
/send <file_path> - Others in the room will see a file offer
- They can type
/accept <file_id>to download
Files are saved to the ./downloads folder by default.
Commands
Type /help in the client to see all available commands.
🔒 Security Features
- Password Hashing: PBKDF2-HMAC-SHA256 with salt
- SSL/TLS Support: Encrypted connections
- Rate Limiting: Prevent spam and abuse (120 msg / 60s)
- Input Validation: Sanitize all user inputs
- Session Management: Automatic timeout and cleanup
- Admin Controls: Privilege-based access control
🌐 Deployment
Local Network
- Start server on your machine
- Find your local IP address
- Clients connect to:
ws://YOUR_LOCAL_IP:8765
Public Internet (Ubuntu Server)
- Deploy the server
- Configure firewall to allow port 8765
- Clients connect to:
wss://yourdomain.com:8765
📊 Monitoring
Systemd Service (Ubuntu)
sudo systemctl status chatserversudo journalctl -u chatserver -f
Log Files
tail -f chat_server.log
🗄️ Database
The server uses SQLite for persistence (chat.db).
🐛 Troubleshooting
Connection Issues
- Cannot connect to server: Check if server is running and firewall status.
- SSL/TLS errors: Verify certificate paths in
.env. - Database errors: Check disk space and permissions.
📝 Development
Project Structure
radio/
├── server.py # Main server application
├── client.py # Unified client (Server & P2P Mode)
├── config.py # Configuration management
├── requirements.txt # Python dependencies
├── .env.example # Environment template
├── .env # Your configuration
├── setup_windows.bat # Windows setup script
├── README.md # Main documentation
├── docs/ # Detailed documentation files
├── chat.db # SQLite database
└── logs/ # Log files directory
Contributing
Contributions are welcome! Please fork the repository, create a feature branch, and submit a pull request.
📜 License
This project is open source and available under the MIT License.
Made with ❤️ for the chat community