add simple fuzz test
|
@ -9,6 +9,7 @@
|
|||
},
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"start": "node index.js",
|
||||
"test": "node test.js"
|
||||
},
|
||||
"author": "Markus Scully <markusscully@gmail.com>",
|
||||
|
@ -17,9 +18,11 @@
|
|||
"box2d-html5": "^0.1.230",
|
||||
"colors": "^1.1.2",
|
||||
"express": "^4.13.4",
|
||||
"jade": "^1.11.0",
|
||||
"poly-decomp": "git://github.com/schteppe/poly-decomp.js.git",
|
||||
"recursive-readdir": "^1.3.0",
|
||||
"socket.io": "^1.4.5",
|
||||
"socket.io-client": "^1.4.5",
|
||||
"uglify-js": "^2.6.2",
|
||||
"uuid": "^2.0.1"
|
||||
}
|
||||
|
|
|
@ -1,23 +0,0 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<link rel="icon" type="image/png" href="img/favicon.png">
|
||||
<link rel="stylesheet" type="text/css" href="css/styles.css">
|
||||
|
||||
<title>
|
||||
Wingbase
|
||||
</title>
|
||||
|
||||
<script src="js/lib/socket.io.js"></script>
|
||||
<script src="js/lib/box2dweb.min.js"></script>
|
||||
<script src="https://rawgit.com/Asraelite/pallet.js/master/pallet.js"></script>
|
||||
|
||||
<script src="starbugs.min.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<canvas id="wingbase_canvas">
|
||||
Sorry, your browser does not currently support HTML5 Canvas.
|
||||
</canvas>
|
||||
</body>
|
||||
</html>
|
Before Width: | Height: | Size: 486 B After Width: | Height: | Size: 486 B |
Before Width: | Height: | Size: 649 B After Width: | Height: | Size: 649 B |
Before Width: | Height: | Size: 678 B After Width: | Height: | Size: 678 B |
Before Width: | Height: | Size: 422 B After Width: | Height: | Size: 422 B |
Before Width: | Height: | Size: 355 B After Width: | Height: | Size: 355 B |
Before Width: | Height: | Size: 154 B After Width: | Height: | Size: 154 B |
Before Width: | Height: | Size: 156 B After Width: | Height: | Size: 156 B |
Before Width: | Height: | Size: 126 B After Width: | Height: | Size: 126 B |
Before Width: | Height: | Size: 122 B After Width: | Height: | Size: 122 B |
Before Width: | Height: | Size: 124 B After Width: | Height: | Size: 124 B |
Before Width: | Height: | Size: 121 B After Width: | Height: | Size: 121 B |
Before Width: | Height: | Size: 127 B After Width: | Height: | Size: 127 B |
Before Width: | Height: | Size: 144 B After Width: | Height: | Size: 144 B |
Before Width: | Height: | Size: 167 B After Width: | Height: | Size: 167 B |
Before Width: | Height: | Size: 179 B After Width: | Height: | Size: 179 B |
Before Width: | Height: | Size: 210 B After Width: | Height: | Size: 210 B |
Before Width: | Height: | Size: 219 B After Width: | Height: | Size: 219 B |
Before Width: | Height: | Size: 233 B After Width: | Height: | Size: 233 B |
Before Width: | Height: | Size: 195 B After Width: | Height: | Size: 195 B |
Before Width: | Height: | Size: 132 B After Width: | Height: | Size: 132 B |
3
public/static/js/lib/dexie.min.js
vendored
Normal file
7
public/static/js/wingbase/db.js
Normal file
|
@ -0,0 +1,7 @@
|
|||
class DB {
|
||||
constructor() {
|
||||
this.db = new Dexie("WingbaseConfig");
|
||||
this.db.version(1).stores({config: "++id,name,age"});
|
||||
this.db.open();
|
||||
}
|
||||
}
|
|
@ -9,7 +9,7 @@ function init() {
|
|||
|
||||
game.tick();
|
||||
|
||||
game.net.connect();
|
||||
//game.net.connect();
|
||||
}
|
||||
|
||||
class Game {
|
|
@ -41,6 +41,8 @@ class Net {
|
|||
this.socket.on('effect', data => {
|
||||
game.renderer.addEffect(data);
|
||||
});
|
||||
|
||||
this.socket.on('chat', data => console.log(data));
|
||||
};
|
||||
|
||||
sendUpdate(inputs) {
|
19
public/views/game.jade
Normal file
|
@ -0,0 +1,19 @@
|
|||
doctype html
|
||||
html(lang='en')
|
||||
head
|
||||
meta(charset="UTF-8")
|
||||
link(rel="icon", type="image/png", href="img/favicon.png")
|
||||
link(rel="stylesheet", type="text/css", href="css/styles.css")
|
||||
title
|
||||
| Wingbase
|
||||
script(src="js/lib/dexie.min.js")
|
||||
script(src="socket.io/socket.io.js")
|
||||
script(src="js/lib/box2dweb.min.js")
|
||||
script(src="https://rawgit.com/Asraelite/pallet.js/master/pallet.js")
|
||||
|
||||
script(src="wingbase.min.js")
|
||||
body
|
||||
canvas#wingbase_canvas
|
||||
| Sorry, your browser does not currently support HTML5 Canvas.
|
||||
#gui
|
||||
include
|
1
public/views/index.jade
Normal file
|
@ -0,0 +1 @@
|
|||
include game.jade
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
const World = require('./world');
|
||||
|
||||
const messages = require('./messages.json');
|
||||
|
||||
class Room {
|
||||
constructor() {
|
||||
this.players = new Set();
|
||||
|
@ -14,13 +16,14 @@ class Room {
|
|||
}
|
||||
|
||||
add(player) {
|
||||
wingbase.log(`${player.name} joined ${this.name}.`);
|
||||
player.room = this;
|
||||
player.connection.room = this.name;
|
||||
this.players.add(player);
|
||||
this.setTeam(player, this.teamA.size > this.teamB.size ? 'b' : 'a');
|
||||
this.world.addPlayer(player);
|
||||
this.sendWorld(player);
|
||||
wingbase.log(`${player.name} joined ${this.name}.`);
|
||||
this.message('roomEnter', player.name);
|
||||
}
|
||||
|
||||
remove(player) {
|
||||
|
@ -63,6 +66,22 @@ class Room {
|
|||
this.players.forEach(player => player.send(msg, data));
|
||||
}
|
||||
|
||||
message(type, values) {
|
||||
if (!(values instanceof Array)) values = [values];
|
||||
|
||||
let messageList = messages[type];
|
||||
let message = messageList[Math.random() * messageList.length | 0];
|
||||
|
||||
// TODO: format name to class.
|
||||
|
||||
message = message.replace('@', values[0]);
|
||||
|
||||
this.broadcast('chat', {
|
||||
type: 'server',
|
||||
message: message
|
||||
});
|
||||
}
|
||||
|
||||
sendWorld(player) {
|
||||
let data = {
|
||||
playerShipId: player.ship.id,
|
||||
|
|
54
server/game/room/messages.json
Normal file
|
@ -0,0 +1,54 @@
|
|||
{
|
||||
"roomEnter": [
|
||||
"@ has entered the room, the cunt.",
|
||||
"Oh, looks like @ decided to show up.",
|
||||
"Here comes @.",
|
||||
"Guys, it's over, @ is here",
|
||||
"What a great time we're having. Aw crap, here's @.",
|
||||
"@ has entered the room.",
|
||||
"Some guy by the name of @ decided to show up.",
|
||||
"A wild @ appeared!",
|
||||
"Oh no, @ just arrived.",
|
||||
"Look out it's @!",
|
||||
"@ has come for a visit.",
|
||||
"Out of nowhere, @ arrives.",
|
||||
"@ has penetrated the room.",
|
||||
"@ showed up.",
|
||||
"Good news, everyone, @ is here.",
|
||||
"@ joined the room.",
|
||||
"@ has arrived to play with y'all.",
|
||||
"@ entered the room, the audacity.",
|
||||
"Someone let @ in again.",
|
||||
"@ has decided to participate.",
|
||||
"@ joined the game.",
|
||||
"You know @, the weird one? Yeah, he just joined.",
|
||||
"Uh-oh spaghetti-o, it's @.",
|
||||
"@ joined the room :/",
|
||||
"May as well leave now, @ just joined.",
|
||||
"@ decided to turn up.",
|
||||
"@ has popped by for a visit.",
|
||||
"And like that annoying friend who won't go away, @ arrives.",
|
||||
"@ now arrives, run for your lives",
|
||||
"@ joined the room. This is a \"good\" thing.",
|
||||
"For fuck's sake, @ has joined again.",
|
||||
"Well great, @ entered the room.",
|
||||
"@ has entered the room, hopefully they'll leave soon.",
|
||||
"@ didn't listen when we told them to go away and has joined.",
|
||||
"@ has entered the game. They actually did it. Wow.",
|
||||
"@ entered the room, but maybe it won't be as bad as last time.",
|
||||
"Everybody clap for @, the shithead who has joined the room.",
|
||||
"@ has come by for a visit. Joy of joys."
|
||||
],
|
||||
"roomLeave": [
|
||||
"@ has left, finally.",
|
||||
"@ has left the room.",
|
||||
"@ finally decided to leave.",
|
||||
"@ is now gone, good ridance.",
|
||||
"@ disconnected. Good.",
|
||||
"After much waiting, @ has finally left.",
|
||||
"@ is gone. Hopefully it'll stay that way.",
|
||||
"Thankfully @ has left the room.",
|
||||
"@ has exited the game :)",
|
||||
"@ left. Now hope they don't come back."
|
||||
]
|
||||
}
|
|
@ -30,8 +30,8 @@ class Ship extends Body {
|
|||
this.size = traits.size;
|
||||
|
||||
// Mounts
|
||||
traits.mounts.forEach((mount, i) => {
|
||||
let mounts = new Mount(this, mount);
|
||||
traits.mounts.forEach((data, i) => {
|
||||
let mount = new Mount(this, data);
|
||||
this.mounts.push(mount);
|
||||
});
|
||||
|
||||
|
@ -112,7 +112,7 @@ class Ship extends Body {
|
|||
name: this.player.name,
|
||||
frame: this.frame,
|
||||
power: this.power,
|
||||
mounts: this.traits.mounts,
|
||||
mounts: this.mounts.map(m => m.packFull()),
|
||||
turrets: this.turrets,
|
||||
size: this.size,
|
||||
delta: this.packDelta()
|
||||
|
|
|
@ -19,6 +19,12 @@ class Mount {
|
|||
if (!this.fixture) return;
|
||||
this.fixture.destruct();
|
||||
}
|
||||
|
||||
packFull() {
|
||||
return {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Mount;
|
||||
|
|
|
@ -20,6 +20,11 @@ class WingbaseServer extends ServerInterface {
|
|||
|
||||
this.log(`Wingbase version ${packageJson.version} running.`);
|
||||
}
|
||||
|
||||
stop() {
|
||||
this.log('Server stopping.');
|
||||
process.exit();
|
||||
}
|
||||
}
|
||||
|
||||
function init() {
|
||||
|
|
|
@ -12,18 +12,26 @@ class WebServer {
|
|||
}
|
||||
|
||||
start() {
|
||||
this.appServer.listen(8080);
|
||||
this.appServer.listen(process.env.PORT || 8080);
|
||||
|
||||
let app = this.app;
|
||||
|
||||
app.get('/starbugs.min.js', (req, res) => {
|
||||
app.set('views', './public/views');
|
||||
app.set('view engine', 'jade');
|
||||
app.engine('jade', require('jade').__express);
|
||||
|
||||
app.get('/wingbase.min.js', (req, res) => {
|
||||
minify(result => {
|
||||
res.contentType('starbugs.min.js');
|
||||
res.contentType('wingbase.min.js');
|
||||
res.end(result);
|
||||
});
|
||||
});
|
||||
|
||||
app.use(express.static('public'));
|
||||
app.get('/', (req, res) => {
|
||||
res.render('index', {});
|
||||
});
|
||||
|
||||
app.use(express.static('public/static'));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ const uglify = require('uglify-js');
|
|||
function minifyJs(callback) {
|
||||
callback = callback || function() {};
|
||||
|
||||
var dir = path.join(__dirname, '../../public/js/wingbase');
|
||||
var dir = path.join(__dirname, '../../public/static/js/wingbase');
|
||||
var cache = '';
|
||||
var scripts = [];
|
||||
|
||||
|
|
12
test.js
|
@ -1,3 +1,13 @@
|
|||
#!bin/node
|
||||
|
||||
console.log('No tests to run');
|
||||
'use strict';
|
||||
|
||||
process.env.PORT = 28256; // Unused as far as I know.
|
||||
|
||||
require('./server/')();
|
||||
|
||||
setTimeout(_ => {
|
||||
wingbase.debug('Starting tests.');
|
||||
|
||||
require('./tests');
|
||||
}, 1000);
|
||||
|
|
26
tests/fuzz.js
Normal file
|
@ -0,0 +1,26 @@
|
|||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
|
||||
function fuzz(socket) {
|
||||
let types = ['setName', 'chat', 'inputs'];
|
||||
|
||||
// Heh, they align.
|
||||
let msg = Array(25).fill().map(v => {
|
||||
let rndstr = Math.random().toString(36).substr(Math.random() * -5 - 1);
|
||||
return Array(Math.random() * 20 | 0).fill().map(v => {
|
||||
return Math.random() > 0.5 ? Math.random() * 10 : rndstr;
|
||||
});
|
||||
}).concat(Array(75).fill().map(v => {
|
||||
return Math.random() * 50;
|
||||
}));
|
||||
|
||||
for (var i = 0; i < 100; i++) {
|
||||
let type = types[Math.random() * types.length | 0];
|
||||
socket.send(type, msg[i]);
|
||||
}
|
||||
|
||||
wingbase.debug('Sent 100 random messages.');
|
||||
}
|
||||
|
||||
module.exports = fuzz;
|
17
tests/index.js
Normal file
|
@ -0,0 +1,17 @@
|
|||
'use strict';
|
||||
|
||||
const io = require('socket.io-client');
|
||||
|
||||
const fuzz = require('./fuzz.js');
|
||||
|
||||
let socket = io('http://localhost:' + process.env.PORT);
|
||||
socket.on('connect', test);
|
||||
|
||||
function test() {
|
||||
wingbase.debug('Running fuzz test.');
|
||||
fuzz(socket);
|
||||
|
||||
wingbase.debug('Ending tests.');
|
||||
|
||||
wingbase.stop();
|
||||
}
|