From 20d90452290222637232c8350fb490506d421be8 Mon Sep 17 00:00:00 2001 From: lolcat Date: Sat, 9 Mar 2024 00:08:04 -0500 Subject: [PATCH] is this thing on --- config.conf | 49 ++++++++++++++++++++++++++++ configutils.c | 6 ++++ proto.md | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++ websocket.c | 7 ++++ 4 files changed, 151 insertions(+) create mode 100644 config.conf create mode 100644 configutils.c create mode 100644 proto.md create mode 100644 websocket.c diff --git a/config.conf b/config.conf new file mode 100644 index 0000000..cf54e26 --- /dev/null +++ b/config.conf @@ -0,0 +1,49 @@ +# Welcome to the lulchat server configuration file +# Use ./lulchat-server --test-config to test your configuration before deploying + +# Specify IP and port. Use 0.0.0.0 to allow external access. +ip=localhost +port=8080 + +# Choose where to get the user's IP from. Useful if lulchat is behind a reverse proxy. +# raw: Get IP from socket +# X-Forwarded-For: Get IP from this HTTP header +ip_source=raw + +# Allowed connection hosts. +allowed_hosts=localhost,lolcat.ca + +# Postgres database connection information +pg_host=localhost +pg_login=root +pg_passwd=1234 + +# Users listed here are global administrators and cannot be demoted unless they are removed from this list. +# Separate each user by a comma. Eg: lolcat,deek,aves +admins=lolcat + +# Maximal HTTP header size in bytes before severing the connection. +# 1024 = 1kb +max_header_size=1024 + +# Maximal websocket message size in bytes. +# 1024 x 4 = 4kb +max_message_size_b=4096 + +# Maximal file upload size in bytes. +# 1024 x 100 = 100MB +max_file_upload_size=102400 + +# Use TCP keepalive on clients? If websocket ping is enabled, this might not be necessary. +tcp_keepalive=true + +# Use websocket ping on clients? Enabling this allows us to monitor the ping of users. +ws_keepalive=false + +# Enable logging? To disable, set to "false". +# To enable, specify a file path. Please make sure lulchat can write to the file. +# Use %d for day, %m for month and %y for year. +log=logs/lulchat-%d-%m-%y.log + +# Logging level. Use "info", "warn", or "error". +log_level=warn diff --git a/configutils.c b/configutils.c new file mode 100644 index 0000000..2d32240 --- /dev/null +++ b/configutils.c @@ -0,0 +1,6 @@ +#include + +int main(){ + + printf("boobs"); +} diff --git a/proto.md b/proto.md new file mode 100644 index 0000000..5ef583f --- /dev/null +++ b/proto.md @@ -0,0 +1,89 @@ +# lulchat protocol +Welcome to lulchat's protocol documentation. Here you will find everything you need to know if you want to create your own lulchat server or client. + +**Please take notice that references to webRTC in this guide should be ignored at the moment, as video and voice calls are not yet implemented.** + +## Preface +lulchat relies on HTTP, webRTC and websocket technologies. We use this in order to bypass firewall restrictions in certain areas like universities, 4G networks, CGNAT and the like. To initiate a connection to lulchat, you will at least need a capable HTTP client coupled with something that can allow you to send and receive websocket messages. webRTC support in your client not required, although recommended. However, it is required if you want to do video and voice calls. + +When we refer to data types, always assume that they are being sent over the wire in network-byte order (big endian). + +# Usernames +Usernames must only contain alphanumeric characters, numbers, and underscores. Must contain between 3 and 21 characters. The following RegexP validates all usernames: +```sh +^[A-Za-z0-9_]{1,21}$ +``` + +# Websocket +This section will teach you how to connect and commit actions on the websocket server. + +## Handshake +1. Initiate an HTTP connection to `/ws` using a capable websocket client. Most hosts will require SSL. + + In the `Sec-WebSocket-Protocol` header, include the following extensions: + ```sh + lulchat; permessage-deflate + ``` + Absence of either of those extensions will result in a failed handshake, as they are required. `permessage-deflate` enforces the use of the `deflate` compression algorithm for each message. + +2. Send a websocket `connect` message. Failing to send this message within 7 seconds will abort the connection. The only thing you can send at this point is a client `connect` message. Sending anything else, including a websocket ping, will abort the connection. Failing to authenticate using a valid username or key will abort the connection. Specifying an invalid protocol version may abort the connection. + + If the server closes the connection, a `server_message` is sent, followed by a websocket `1001` close sequence. + + On success, the client will receive a `connect_ack`. + + The user is now authenticated. + +## Server messages format specification + +### Server opcodes +```sh +0 server_message +1 connect_ack +2 channel_subscribe +3 channel_unsubscribe +4 channel_message +5 channel_message_edit +6 channel_message_delete +7 channel_server_message +8 channel_usertyping +9 channel_join +10 channel_leave +11 channel_setting_update +12 channel_message_clear +``` + +### Server message format + +#### server_message: +```sh + 0 + Message title strlen + Message title + Message +``` + +#### connect_ack: +```sh + 1 +``` + +## Client messages format specification + +### Client opcodes +```sh +0 connect +``` + +### Client message format + +#### connect: +```sh + 0 + Client version. "100" translates to "1.0.0" + Client name strlen + Client name + Username strlen + Username + PGP key +``` diff --git a/websocket.c b/websocket.c new file mode 100644 index 0000000..4fd6ae4 --- /dev/null +++ b/websocket.c @@ -0,0 +1,7 @@ +#include +#include + +int main() { + + printf("Starting websocket server...\n"); +}