Update README.md

This commit is contained in:
Maxwell Jeffress 2024-12-04 13:11:36 +11:00
parent 90cf9f4325
commit 23fc71bd45
3 changed files with 42 additions and 110 deletions

View File

@ -1,130 +1,62 @@
# Chookchat Server
Key features:
- Real-time messaging with WebSocket support
- User authentication and account management
- Persistent message history
- Simple HTTP API for basic operations
- Built-in static file serving for web clients
- Support for encryption keys
- Active user tracking and presence notifications
This is the code for Chookchat's server program. The server program:
## Requirements
* Starts a server on port 7070
- Java 17 or later
- Caddy (for HTTPS reverse proxy) - [Download from caddyserver.com](https://caddyserver.com/download)
- Some kind of OS, any should do
- 50mb free space, 30mb avaliable ram (yes I know, very bloated and inefficient)
* Hosts the web client files (index.html at the root)
## Running the Server
* Adjusts index.html based on your config file (a backup index.html is still avaliable at localhost:7070/index.html)
Prebuilt binaries are available for immediate use. Simply download the latest server release and run:
* Handles user signups
```bash
./run
* Opens a websocket allowing for flexible user input
* Handles file uploads
**Note:** Chookchat does not support HTTPS natively. We recommend the usage of a reverse proxy like Caddy (caddyserver.com) to enable HTTPS on your website, as well as a firewall to block HTTP connections.
## Server Configuration
Chookchat looks for a chookchat.config file in the directory where you start Chookchat. An example is provided in this directory. Your file must look like the following:
```
address:localhost;port:7070;security:false;serviceName:Chookchat;
```
The server will start on port 7070 by default.
## Building from Source
First, install Gradle. Unless you want to painfully compile everything manually, Gradle is your best friend.
Clone the repository and CD into the server directory. Then run:
```bash
gradle build
```
To create a distribution (you don't need to run gradle build, it will do that for you):
```bash
./gradlew installDist
```
To run the server, create the files `chatHistory` and `userDatabase` in the directory you're running it from, then run the script to start Chookchat.
Address: Where your server is hosted (a domain or IP address usually)
Port: Your server's port (default 7070, 443 if you route it through Caddy with HTTPS)
Security: Whether or not to use WSS/HTTPS (either `true` or `false`)
ServiceName: What your server's name comes up as.
## API Documentation
### HTTP Endpoints
#### Send Message
- Endpoint: `/api/send/{content}`
- Content Format: `username:{name}token:{token}message:{message}`
- Response: "Success" or error message
#### Create Account
- Endpoint: `/api/createaccount/{content}`
- Content Format: `username:{name}token:{password}`
- Response: "Success" or error message
#### Sync Messages
- Endpoint: `/api/syncmessages/{content}`
- Content Format: `username:{name}token:{token}`
- Response: Chat history or error message
#### Auth Key (being worked on for E2EE)
- Endpoint: `/api/authkey/{content}`
- Content Format: `username:{name}token:{token}authkey:{key}`
- Response: "Success" or error message
## WebSocket Interface
Connect to `/api/websocket` for real-time updates.
### WebSocket Messages
1. Server to Client:
- Ping messages: "ping"
- User updates: "!users:{user1,user2,user3}"
- Chat messages: "username: message"
2. Client to Server:
- Pong response: "pong"
- Message format: Same as HTTP send endpoint
## Setting up HTTPS with Caddy
Caddy provides automatic HTTPS and serves as a reverse proxy for your Chookchat server. [Download from caddyserver.com](https://caddyserver.com/download) or from your Linux/BSD/Illumos/Haiku/TempleOS/whatever distribution's package manager.
1. Create a `Caddyfile` in your server directory:
```
chat.yourdomain.com {
reverse_proxy localhost:7070
Chookchat uses websockets to send and recieve messages. Each websocket request (except pinging and ponging) contains JSON to show what kind of data we are sending, what user is sending it (and token while being sent to the server), and the actual message content. A chookchat websocket message to the server looks like this:
```json
{
"type": "message",
"username": "max",
"token": "(hash of password)",
"content": "dongus"
}
```
2. Start Caddy:
```bash
caddy run
And a message from the server would look like this (it's the same without the token):
```json
{
"type": "message",
"username": "max",
"content": "dongus"
}
```
The server will send a `ping` every five seconds (without JSON) to stop the connection from timing out. When you recieve this, send back a `pong`.
Caddy will automatically obtain and manage SSL certificates for your domain.
### Message Types
## Client Deployment
**message**: A message. Not much going on. It's recommended to display it like ${username}: ${content}
Place your client files in the `src/main/resources/public` directory. The server will automatically serve these static files, making the client accessible at your server's root URL.
**call**: A link to a Jitsi call. Treat this how you'd like.
## Maintenance
**file**: A file sent by a user. For now, it appears as if the `system` user has sent the file, so in a client send a message describing who's uploaded the file shortly after sending the file.
### Database Files
- `userDatabase`: Contains user credentials in format `username:token:salt`
- `chatHistory`: Stores message history
- Regular backups recommended
**connect**: A user joining the room. If this is not sent by the `system` user, ignore.
### Health Checks
- Server automatically maintains WebSocket connections
- Dead sessions are cleaned up automatically
- Active user count is logged
### Security Recommendations
- Keep database files secure
- Regular system updates
- Monitor for unusual login patterns
- Back up regularly:
```bash
#!/bin/bash
backup_dir="/path/to/backups"
date_stamp=$(date +%Y%m%d)
cp userDatabase "${backup_dir}/userDatabase_${date_stamp}"
cp chatHistory "${backup_dir}/chatHistory_${date_stamp}"
```
**users**: A list of users currently in the room, seperated by ", ". In order of who joined first. If this is not sent by the `system` user, ignore.

View File

@ -34,7 +34,7 @@ object config {
var serviceName = ""
fun getConfig() {
val configFile = File("chookpen.config")
val configFile = File("chookchat.config")
try {
val config = configFile.readLines()
var type = ""