-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from stzups/dev
v0.2 Basic functionality to allow for more features to be added
- Loading branch information
Showing
73 changed files
with
2,178 additions
and
814 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
32
board-server/src/main/java/net/stzups/board/ConsoleManager.java
This file was deleted.
Oops, something went wrong.
18 changes: 18 additions & 0 deletions
18
board-server/src/main/java/net/stzups/board/RandomString.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
Oops, something went wrong.