Skip to content

Commit

Permalink
Merge pull request #26 from stzups/dev
Browse files Browse the repository at this point in the history
v0.2 Basic functionality to allow for more features to be added
  • Loading branch information
griffinht authored Mar 6, 2021
2 parents 32db522 + d32de84 commit 8a8c3ff
Show file tree
Hide file tree
Showing 73 changed files with 2,178 additions and 814 deletions.
23 changes: 2 additions & 21 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,13 @@

#### General guidelines
- Make sure to respect line endings (LF)
- Tabs should be 4 spaces

## Building and running `board-server`
You will need to build and run the `board-server` project before using or contributing to the client or server.

`board-server` is written in Java. Make sure you have [Apache Maven](https://maven.apache.org/index.html) installed on your system before attempting to build the project.

#### Build Steps
- Clone or fork this repository
- Run `mvn clean package` in `board-server` to generate server artifact in the newly created `target` folder
- Set the working directory of the generated server artifact to `board-web-client` (copy the `.jar` to `board-web-client`) and run in a terminal using `java -jar board-server-xxx.jar`
- This starts an HTTP server listening on port 80, which you can connect in your browser at [localhost](http://localhost)
- Stop the server gracefully by running the `stop` command in the console or by killing the process


You may also want to create a run configuration in your IDE of choice to simplify the run process.

Modifying `board-server` will require you to recompile the project and restart the server.

Modifying `board-web-client` only requires you to refresh your browser. If you do not see your new changes, then use `Ctrl+F5` to also reset your browser cache.
- Do not use the tab character. Tabs should be represented as 4 spaces

## Contributing to `board-server`
It is recommended to use an IDE such as [IntelliJ IDEA](https://www.jetbrains.com/idea/) if you plan on contributing to `board-server`.

- Keep things IDE agnostic - avoid checking in IDE specific files (.iml, .idea, etc.) to version control

## Contributing to `board-web-client`
- Use double quotes ("") when editing HTML and single quotes ('') when editing JavaScript
- Use double quotes (" ") when editing HTML and single quotes (' ') when editing JavaScript

62 changes: 62 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
##v0.1
Add real time drawing

- Change file structure and how files are served
- Fix custom invite URL
- Automatic connection

##v0.2
Basic functionality to allow for more features to be added

###v0.2.1
Room to document based model

- Add sidebar
- Change offset points to absolute points in draw
- Refactor packets
- Refactor js
- Event based WebSocketHandler
- Change how URLs work

###v0.2.2
Add document opening/closing

- Change how queued packets work
- Documents are saved before closed
- Change protocol again

###v0.2.3
Flat file data persistence

- Remove ConsoleManager
- Add shutdown hooks for saving
- Change handshake
- Functioning Java serialization
- Complete rework of config system
- SSL support

###v0.2.4
User identity

- Change URL parsing
- Add HTTP cache as a config option
- Session management
- Sessions are linked to documents
- Improve toString debug

###v0.2.5
Multiple clients per user

- Change how sessions are handled
- Clean up script loading
- Fix hashcode issues

###v0.2.6
Design
- Clean up CSS
- Add changelog
- Add invite/connected users toolbar
- "Fix" canvas resize
- Change/clean up config system
- Improve client debug
- Better local user with different handshake
55 changes: 52 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,54 @@
welcome to the board project

:D
:D
̿̿ ̿̿ ̿̿ ̿'̿'\̵͇̿̿\з= ( ▀ ͜͞ʖ▀) =ε/̵͇̿̿/’̿’̿ ̿ ̿̿ ̿̿ ̿̿
name pending

This project is separated into the server (`board-server`) and the client (`board-web-client`). All files inside `board-web-client` can be served to the browser and are therefore public.

You will need to build and run the `board-server` project before using or contributing to the client or server.

## Building `board-server`

`board-server` is an HTTP/WebSocket server written in Java 8. Make sure you have the Java 8 JDK and [Apache Maven](https://maven.apache.org/index.html) installed on your system before attempting to build the project.

#### Build Steps
- Clone this repository to your local machine
- Run `mvn clean package` in `board-server` to generate server artifact in the newly created `target` folder

Modifying `board-server` will require you to recompile the project and restart the server.

Modifying `board-web-client` only requires you to refresh your browser. If you do not see your new changes, then use `ctrl+F5` to also reset your browser cache.

## Running `board-server`

Once you have built `board-server`, you may run it using using the following command:

java -jar board-server-xxx.jar --ssl.keystore http

- This starts an HTTP/WebSocket server listening on port 80, which you can connect in your browser at [http://localhost](http://localhost).
- All WebSocket connections run on the same port as the HTTP server, and should connect to [ws://localhost/websocket](ws://localhost/websocket).
- Stop the server gracefully to save persistent data (`ctrl+c` on Windows terminals). Killing the process may result in data loss from any unsaved persistent data.

### Properties

These can be set in several different ways:

##### `board.properties`
Create a file called `board.properties` in the working directory of the server and format as the following

key=value
other.key=value with spaces

##### Command line arguments

java -jar board-server-xxx.jar --key value --other.key "value with spaces"
File indicates a relative (<working directory>/folder/file.ext) or absolute path (C:/folder/file.ext)

| Flag | Type | Default | Description |
| --- | ---- | ------- | ----------- |
| ssl.keystore.path | file | (required) | Path to the PKCS12 `mykeystore.pfx` containing the private key for the server. Set to `http` to use HTTP without SSL encryption |
| ssl.passphrase | string | (optional) | Passphrase for `mykeystore.pfx` |
| document.root.path | file | documentRoot | Should be set to where `board-web-client` is. HTTP requests to a directory (`localhost` or `localhost/folder/`) will be served the `index.html` file of those directories HTTP requests to a file that do not specify an extension (`localhost/file`) will be served a `.html` that corresponds to the requested name
| data.root.path | file | data | Sets the folder location of the flat file storage |
| debug.log.traffic | boolean | false | Will print network throughput (read/write) into the console |
| autosave.interval | integer (seconds) | -1 | Sets how often flat file storage will be saved to disk, or negative value to disable |
| http.cache.time | integer (seconds) | 0 | How long before a cached item expires. Set to 0 for development purposes so refreshing the page will always load your new changes (equivalent of `crtl+f5`) |
2 changes: 1 addition & 1 deletion board-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>net.stzups.board</groupId>
<artifactId>board-server</artifactId>
<version>0.1-SNAPSHOT</version>
<version>0.2</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
92 changes: 82 additions & 10 deletions board-server/src/main/java/net/stzups/board/Board.java
Original file line number Diff line number Diff line change
@@ -1,39 +1,111 @@
package net.stzups.board;

import io.netty.channel.ChannelFuture;
import net.stzups.board.config.Config;
import net.stzups.board.config.ConfigBuilder;
import net.stzups.board.config.configs.ArgumentConfig;
import net.stzups.board.config.configs.PropertiesConfig;
import net.stzups.board.data.TokenGenerator;
import net.stzups.board.data.database.flatfile.FlatFileStorage;
import net.stzups.board.data.objects.Document;
import net.stzups.board.data.objects.HttpSession;
import net.stzups.board.data.objects.User;
import net.stzups.board.data.objects.UserSession;
import net.stzups.board.server.Server;

import java.io.IOException;
import java.util.logging.Logger;

public class Board {
private static Server server;
private static Logger logger;
private static Config config;

public static void main(String[] args) {
private static final String DEFAULT_DOCUMENT_NAME = "Untitled Document";

private static FlatFileStorage<Long, User> users;//user id -> user
private static FlatFileStorage<Long, Document> documents;//document id -> document
private static FlatFileStorage<Long, HttpSession> httpSessions;//http session id -> http session todo unused
private static FlatFileStorage<Long, UserSession> userSessions;//user session id -> user session

public static Document getDocument(long id) {
return documents.get(id);
}


public static void addUser(User user) {
users.put(user.getId(), user);
}

public static User getUser(long id) {
return users.get(id);
}

public static UserSession removeUserSession(long token) {
return userSessions.remove(token);
}

public static void addUserSession(UserSession userSession) {
userSessions.put(userSession.getToken(), userSession);
}

public static HttpSession getHttpSession(long token) {
return httpSessions.get(token);
}

public static void addHttpSession(HttpSession httpSession) {
httpSessions.put(httpSession.getToken(), httpSession);
}

public static Document createDocument(User owner) {
Document document = new Document(TokenGenerator.getSecureRandom().nextLong(), owner, DEFAULT_DOCUMENT_NAME);
documents.put(document.getId(), document);
return document;
}


public static void main(String[] args) throws Exception {
logger = LogFactory.getLogger("Board Server");

logger.info("Starting Board server...");

long start = System.currentTimeMillis();

new ConsoleManager();
config = new ConfigBuilder()
.addConfig(new ArgumentConfig(args))
.addConfig(new PropertiesConfig("board.properties"))
.build();

server = new Server();
server.run();
Server server = new Server();
ChannelFuture channelFuture = server.start();

try {
users = new FlatFileStorage<>("users");
documents = new FlatFileStorage<>("documents");
httpSessions = new FlatFileStorage<>("httpSessions");
userSessions = new FlatFileStorage<>("userSessions");
} catch (IOException e) {
e.printStackTrace();
return;
}

logger.info("Started Board server in " + (System.currentTimeMillis() - start) + "ms");
}

static void stop() {
logger.info("Stopping Board server...");
channelFuture.sync();

long start = System.currentTimeMillis();
start = System.currentTimeMillis();

logger.info("Stopping Board Server");

server.stop();

logger.info("Stopped Board server in " + (System.currentTimeMillis() - start) + "ms");
logger.info("Stopped Board Server in " + (System.currentTimeMillis() - start) + "ms");
}

public static Logger getLogger() {
return logger;
}

public static Config getConfig() {
return config;
}
}
32 changes: 0 additions & 32 deletions board-server/src/main/java/net/stzups/board/ConsoleManager.java

This file was deleted.

18 changes: 18 additions & 0 deletions board-server/src/main/java/net/stzups/board/RandomString.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package net.stzups.board;

import java.util.Random;

public class RandomString {
public static final char[] LOWERCASE_ALPHABET = "abcdefghijklmnopqrstuvwxyz".toCharArray();
public static final char[] NUMERIC = "0123456789".toCharArray();

private static final Random random = new Random();

public static String randomString(int length, char[] chars) {
char[] randomChars = new char[length];
for (int i = 0; i < randomChars.length; i++) {
randomChars[i] = chars[random.nextInt(chars.length)];
}
return new String(randomChars);
}
}
Loading

0 comments on commit 8a8c3ff

Please sign in to comment.