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 # Chookchat Server
Key features: This is the code for Chookchat's server program. The server program:
- 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
## Requirements * Starts a server on port 7070
- Java 17 or later * Hosts the web client files (index.html at the root)
- 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)
## 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 * Opens a websocket allowing for flexible user input
./run
* 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. 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)
## Building from Source Security: Whether or not to use WSS/HTTPS (either `true` or `false`)
ServiceName: What your server's name comes up as.
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.
## API Documentation ## API Documentation
### HTTP Endpoints 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
#### Send Message {
- Endpoint: `/api/send/{content}` "type": "message",
- Content Format: `username:{name}token:{token}message:{message}` "username": "max",
- Response: "Success" or error message "token": "(hash of password)",
"content": "dongus"
#### 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
} }
``` ```
And a message from the server would look like this (it's the same without the token):
2. Start Caddy: ```json
```bash {
caddy run "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 **connect**: A user joining the room. If this is not sent by the `system` user, ignore.
- `userDatabase`: Contains user credentials in format `username:token:salt`
- `chatHistory`: Stores message history
- Regular backups recommended
### Health Checks **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.
- 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}"
```

View File

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