From de719939e336894a9a2ecd75c0f08a3270a7f8a2 Mon Sep 17 00:00:00 2001 From: Commander-lol <ljcapitanio@gmail.com> Date: Tue, 22 Dec 2015 18:58:19 +0000 Subject: [PATCH] Clean slate for intro site --- LICENSE | 14 ---- README.md | 29 -------- app.js | 49 ------------- local_modules/reroute.js | 13 ---- local_modules/xbridge.js | 62 ---------------- package.json | 22 ------ public/chat.html | 46 ------------ public/index.html | 150 --------------------------------------- scripts/kill_redis.sh | 1 - scripts/setup.sh | 21 ------ scripts/xscrp.sh | 19 ----- 11 files changed, 426 deletions(-) delete mode 100644 LICENSE delete mode 100644 README.md delete mode 100644 app.js delete mode 100644 local_modules/reroute.js delete mode 100644 local_modules/xbridge.js delete mode 100644 package.json delete mode 100644 public/chat.html delete mode 100644 public/index.html delete mode 100644 scripts/kill_redis.sh delete mode 100644 scripts/setup.sh delete mode 100755 scripts/xscrp.sh diff --git a/LICENSE b/LICENSE deleted file mode 100644 index 45bffbe..0000000 --- a/LICENSE +++ /dev/null @@ -1,14 +0,0 @@ -Copyright (c) 2015, Louis Capitanchik - -Permission to use, copy, modify, and/or distribute this software for any -purpose with or without fee is hereby granted, provided that the above -copyright notice and this permission notice appear in all copies. - -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - diff --git a/README.md b/README.md deleted file mode 100644 index 8a7147c..0000000 --- a/README.md +++ /dev/null @@ -1,29 +0,0 @@ -# PompeyPlays -Pompey plays video games together, everyone has fun and nothing* catches fire - -### More Info Goes Here - -## PP Websocket API -The websocket server uses the WS library built into [combi-server](https://github.com/Commander-lol/combi-server) for -standardised communications. The WS server expects JSON formatted into utf-8 text and will communicate back with such. -Binary and slimmer string based versions of the protocols will be available when combi-server has been updated to -handle those. - -### Basic JSON format -WS requests should contain two keys: a `type` key and a `payload` key; other data will be ignored. The value of the `type` -key should be a string dictating the command being sent, while the value of `payload` should be a String, Number or JSON -object depending on what the server expects for the given type. - -If you're using ws.lib, as provided by combi-server, the `socket.message(type, payload)` method handles the formatting -required, otherwise you'll need to manually create the command object. - -### PP Commands -Currently the PP server listens for the following commands (`type` parameter) and expects the described data (`payload`): -* _input_: A JSON object containing a `key` property that describes the key being input. This is a virtual key mapped to -a gamepad, and not the actual keyboard key that might have caused the message to be sent or that might be pressed as a -result. Optionally contains an `auth` property with a Web Token hash. - -### PP Events -Currently the PP server sends the following messages to clients (Listen to those that you want to handle): -* _input-response_: Sent in response to an input. Payload will be undefined unless something was wrong with the request, -safe to ignore in most cases diff --git a/app.js b/app.js deleted file mode 100644 index a017388..0000000 --- a/app.js +++ /dev/null @@ -1,49 +0,0 @@ -var exec = require("child_process").exec, - level = require("levelup"), - http = require("combi-server")({ - port: 8080, - appname: "Pompey Plays", - useAnsi: true, - websocket: { - enabled: true, - lib: true - } - }), - q = require("q"), - reroute = require("./local_modules/reroute"), - path = require("path"), - x = require("./local_modules/xbridge"), - - ni = require("os").networkInterfaces()["eth0"].reduce(function(p, c){if(c.family == "IPv4"){return c;}else{return p;}}, null); - -console.dir(ni); - -reroute.add("/", "/index.html"); -reroute.add("/log", "/chat.html"); - -http.use(reroute.middleware); - -http.static(path.join(__dirname, "public")); - -http.ws.do("input:json", function(conn, data) { - x.do(data.key) - .then(function(e) { - conn.sendPayload("input-response", x.errs[e]); - http.ws.broadcast(JSON.stringify({ - type: "chat", - payload: { - client: conn._id, - message: "pressed " + data.key, - mode: "self" - } - })) - }) - .catch(function(err) { - conn.sendPayload("input-response", { - code: 400, - message: err.message - }) - }); -}) - -http.listen(); diff --git a/local_modules/reroute.js b/local_modules/reroute.js deleted file mode 100644 index 717b9fe..0000000 --- a/local_modules/reroute.js +++ /dev/null @@ -1,13 +0,0 @@ -var reroutes = {}; - -module.exports = { - add: function (from, to) { - reroutes[from] = to; - }, - middleware: function(req, res, next) { - if (reroutes.hasOwnProperty(req.url)) { - req.url = reroutes[req.url]; - } - return next(); - } -} diff --git a/local_modules/xbridge.js b/local_modules/xbridge.js deleted file mode 100644 index 067fbed..0000000 --- a/local_modules/xbridge.js +++ /dev/null @@ -1,62 +0,0 @@ -var errmap = { - "0": { - code: 200, - message: "Ok" - }, - "1": { - code: 404, - message: "Retro Arch Not Found" - }, - "2": { - code: 400, - message: "Invalid Input Given" - } - }, - controlmap = { - gba: { - left: "Left", - right: "Right", - up: "Up", - down: "Down", - a: "x", - b: "z", - r: "w", - l: "q", - select: "Shift_R", - start: "Return" - } - }, - curControl = "gba"; - exec = require("child_process").exec, - q = require("q"); - -module.exports = { - do: function(virtualKey) { - var def = q.defer(); - if (!controlmap[curControl].hasOwnProperty(virtualKey)) { - def.reject(new Error("Invalid Virtual Keypress")); - } else { - exec("bash scripts/xscrp.sh " + controlmap[curControl][virtualKey], function(err, stdout, stderr) { - if (err) { - def.reject(err); - } else { - def.resolve(stdout.toString()); - } - }); - } - return def.promise; - }, - set controls (e) { - if (controlmap.hasOwnProperty(e)) { - curControl = e; - } else { - throw new Error("Invalid Control Scheme"); - } - }, - get controls () { - return curControl; - }, - get errs () { - return errmap; - } -} diff --git a/package.json b/package.json deleted file mode 100644 index 84b3281..0000000 --- a/package.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "name": "pompey-plays", - "version": "1.0.0", - "private": true, - "description": "Pompey plays video game multiplexing unicron badassery", - "main": "app.js", - "dependencies": { - "combi-server": "^1.3.2", - "leveldown": "^1.4.3", - "levelup": "^1.3.1", - "node-ip": "^0.1.2", - "q": "^1.4.1" - }, - "scripts": { - "start": "NODE_ENV=production node app", - "kill-redis": "bash scripts/kill_redis.sh", - "inst-ubi": "bash scripts/setup.sh" - }, - "devDependencies": {}, - "author": "Louis Capitanchik", - "license": "ISC" -} diff --git a/public/chat.html b/public/chat.html deleted file mode 100644 index cd34a8f..0000000 --- a/public/chat.html +++ /dev/null @@ -1,46 +0,0 @@ -<!DOCTYPE html> -<html> - <head> - <meta charset="utf-8"/> - <title>PP :: LOG</title> - <style> - .message { - padding: 0.5em; - } - .message:not(:last-child) { - border-bottom: 1px solid grey; - } - .message strong { - padding-left: 0.2em; - padding-right: 0.3em; - } - </style> - </head> - <body> - <div id="log"> - - </div> - <script src="/ws.lib" type="application/javascript"></script> - <script type="application/javascript"> - var socket = new CombiSocket(), - logBox = document.getElementById("log"); - socket.on("chat", function(data) { - console.log(data); - var message = document.createElement("div"), - user = document.createElement("strong"), - content = data.mode === "self" ? document.createElement("em") : document.createElement("span"); - - message.classList.add("message"); - - user.textContent = data.client; - content.textContent = data.message; - - message.appendChild(user); - message.appendChild(content); - - logBox.appendChild(message); - logBox.scrollIntoView(false); - }); - </script> - </body> -</html> diff --git a/public/index.html b/public/index.html deleted file mode 100644 index a3a0c60..0000000 --- a/public/index.html +++ /dev/null @@ -1,150 +0,0 @@ -<!DOCTYPE html> -<html> - <head> - <meta charset="utf-8"/> - <meta content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0' name='viewport' /> - <title>Pompey Plays...</title> - <style> - html, body { - height: 100%; - margin: 0; - padding: 0; - position: relative; - } - .button .box { - fill: #c3c5c4; - stroke: #555a5d; - } - .button .arrow { - fill: #555a5d; - } - - .hitbox { - fill: black; - opacity: 0; - transition: opacity 0.1s linear; - } - .hitbox:hover { - opacity: 0.3; - } - - .button text { - font-family: sans-serif; - font-size: 150%; - fill: #555a5d; - text-anchor: middle; - -webkit-user-select: none; - -moz-user-select: none; - -ms-user-select: none; - user-select: none; - } - .commands .button text { - font-size: 125%; - } - #a .box { - fill: #c92313; - } - #b .box { - fill: #f0ba24; - } - - .hitbox { - fill: black; - opacity: 0; - transition: opacity 0.1s linear; - } - .hitbox:hover { - opacity: 0.3; - } - svg { - position: absolute; - left: 0; - right: 0; - height: 100%; - width: 100%; - } - </style> - </head> - <body> - <svg viewbox="0, 0, 500, 350"> - <g class="group arrows" transform="translate(10,0)"> - <g class="button" id="left" transform="translate(0,60)"> - <path class="box" d="M 50,0 L 0,50 L 50,100 L 100,50 Z" /> - <path class="arrow" d="M 50,10 L 60,20 L 30,50 L 60,80 L 50,90 L 10,50 Z" /> - <path class="hitbox" d="M 50,0 L 0,50 L 50,100 L 100,50 Z" /> - </g> - - <g class="button" id="right" transform="translate(120,60)"> - <path class="box" d="M 50,0 L 0,50 L 50,100 L 100,50 Z" /> - <path class="arrow" d="M 50,10 L 40,20 L 70,50 L 40,80 L 50,90 L 90,50 Z" /> - <path class="hitbox" d="M 50,0 L 0,50 L 50,100 L 100,50 Z" /> - </g> - - <g class="button" id="up" transform="translate(60,0)"> - <path class="box" d="M 50,0 L 0,50 L 50,100 L 100,50 Z" /> - <path class="arrow" d="M 10,50 L 20,60 L 50,30 L 80,60 L 90,50 L 50,10 Z" /> - <path class="hitbox" d="M 50,0 L 0,50 L 50,100 L 100,50 Z" /> - </g> - - <g class="button" id="down" transform="translate(60,120)"> - <path class="box" d="M 50,0 L 0,50 L 50,100 L 100,50 Z" /> - <path class="arrow" d="M 10,50 L 20,40 L 50,70 L 80,40 L 90,50 L 50,90 Z" /> - <path class="hitbox" d="M 50,0 L 0,50 L 50,100 L 100,50 Z" /> - </g> - </g> - - <g class="group letters" transform="translate(260,0)"> - <g class="button" id="a" transform="translate(60,120)"> - <circle class="box" r="35" cx="50" cy="50"/> - <text x="50" y="50" dy="7">A</text> - <circle class="hitbox" r="35" cx="50" cy="50"/> - </g> - - <g class="button" id="b" transform="translate(120,60)"> - <circle class="box" r="35" cx="50" cy="50"/> - <text x="50" y="50" dy="7">B</text> - <circle class="hitbox" r="35" cx="50" cy="50"/> - </g> - </g> - - <g class="group commands" transform="translate(135,250)"> - <g class="button" id="select" transform="translate(0,0)"> - <rect class="box" x="1" y="30" width="98" height="40" rx="25" ry="25"/> - <text x="50" y="50" dy="7">SELECT</text> - <rect class="hitbox" x="0" y="30" width="100" height="40" rx="25" ry="25"/> - </g> - - <g class="button" id="start" transform="translate(120,0)"> - <rect class="box" x="1" y="30" width="98" height="40" rx="25" ry="25"/> - <text x="50" y="50" dy="7">START</text> - <rect class="hitbox" x="0" y="30" width="100" height="40" rx="25" ry="25"/> - </g> - </g> - </svg> - <script src="/ws.lib" type="application/javascript"></script> - <script> - var socket = new CombiSocket(), - keys = [ - "a", - "b", - "left", - "right", - "up", - "down", - "select", - "start" - ], - sendKey = function(key) { - socket.message("input", {key: key}); - }; - socket.on("input-response", function(data) { - console.log(data); - }); - - keys.map(function(e) { - document.querySelector("#" + e + " .hitbox").addEventListener("click", sendKey.bind(null, e)); - }) - - </script> - </body> -</html> diff --git a/scripts/kill_redis.sh b/scripts/kill_redis.sh deleted file mode 100644 index 9f9a13f..0000000 --- a/scripts/kill_redis.sh +++ /dev/null @@ -1 +0,0 @@ -ps -aux | grep redis | head -1 | tr -s ' ' | cut -d ' ' -f 2 | xargs kill $1 diff --git a/scripts/setup.sh b/scripts/setup.sh deleted file mode 100644 index b1a34f9..0000000 --- a/scripts/setup.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash -PDIR=`pwd` - -if ! [ -x "$(command -v xdotool)" ]; then # RetroArch doesn't do command lines nicely, has to be bundled with xdotool check - sudo add-apt-repository ppa:libretro/stable - sudo apt-get update - sudo apt-get install xdotool retroarch retroarch-* libretro-* -fi - -# Enable if switching levelDB to Redis -#if ! [ -x ~/Programs/$REDISVER/src/redis-server ]; then -# REDISVER="redis-3.0.5" -# mkdir -p ~/Programs/tmp -# mkdir -p ~/Programs/$REDISVER -# cd ~/Programs/tmp -# wget http://download.redis.io/releases/$REDISVER.tar.gz -# tar xzf $REDISVER.tar.gz -C ../ -# cd ../$REDISVER -# make -# cd $PDIR -#fi diff --git a/scripts/xscrp.sh b/scripts/xscrp.sh deleted file mode 100755 index 0c2db0b..0000000 --- a/scripts/xscrp.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/bash - -WID=`xdotool search --name RetroArch` -VALID="_z__x__q__w__Left__Right__Up__Down__Shift_R__Return_" -if [[ $WID == "" ]] -then - echo 1 -else - if [[ $VALID == *"_$1_"* ]] - then - xdotool windowactivate $WID - xdotool windowfocus $WID - xdotool keydown $1 - xdotool keyup $1 - echo 0 - else - echo 2 - fi -fi -- GitLab