add simple fuzz test

This commit is contained in:
Asraelite 2016-03-27 20:26:53 +01:00
parent 0a90b6b77a
commit 27520842e3
59 changed files with 191 additions and 34 deletions

View file

@ -9,6 +9,7 @@
}, },
"private": true, "private": true,
"scripts": { "scripts": {
"start": "node index.js",
"test": "node test.js" "test": "node test.js"
}, },
"author": "Markus Scully <markusscully@gmail.com>", "author": "Markus Scully <markusscully@gmail.com>",
@ -17,9 +18,11 @@
"box2d-html5": "^0.1.230", "box2d-html5": "^0.1.230",
"colors": "^1.1.2", "colors": "^1.1.2",
"express": "^4.13.4", "express": "^4.13.4",
"jade": "^1.11.0",
"poly-decomp": "git://github.com/schteppe/poly-decomp.js.git", "poly-decomp": "git://github.com/schteppe/poly-decomp.js.git",
"recursive-readdir": "^1.3.0", "recursive-readdir": "^1.3.0",
"socket.io": "^1.4.5", "socket.io": "^1.4.5",
"socket.io-client": "^1.4.5",
"uglify-js": "^2.6.2", "uglify-js": "^2.6.2",
"uuid": "^2.0.1" "uuid": "^2.0.1"
} }

View file

@ -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>

View file

Before

Width:  |  Height:  |  Size: 486 B

After

Width:  |  Height:  |  Size: 486 B

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 649 B

After

Width:  |  Height:  |  Size: 649 B

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 678 B

After

Width:  |  Height:  |  Size: 678 B

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 422 B

After

Width:  |  Height:  |  Size: 422 B

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 355 B

After

Width:  |  Height:  |  Size: 355 B

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 154 B

After

Width:  |  Height:  |  Size: 154 B

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 156 B

After

Width:  |  Height:  |  Size: 156 B

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 126 B

After

Width:  |  Height:  |  Size: 126 B

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 122 B

After

Width:  |  Height:  |  Size: 122 B

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 124 B

After

Width:  |  Height:  |  Size: 124 B

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 121 B

After

Width:  |  Height:  |  Size: 121 B

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 127 B

After

Width:  |  Height:  |  Size: 127 B

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 144 B

After

Width:  |  Height:  |  Size: 144 B

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 167 B

After

Width:  |  Height:  |  Size: 167 B

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 179 B

After

Width:  |  Height:  |  Size: 179 B

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 210 B

After

Width:  |  Height:  |  Size: 210 B

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 219 B

After

Width:  |  Height:  |  Size: 219 B

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 233 B

After

Width:  |  Height:  |  Size: 233 B

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 195 B

After

Width:  |  Height:  |  Size: 195 B

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 132 B

After

Width:  |  Height:  |  Size: 132 B

Before After
Before After

3
public/static/js/lib/dexie.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View 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();
}
}

View file

@ -9,7 +9,7 @@ function init() {
game.tick(); game.tick();
game.net.connect(); //game.net.connect();
} }
class Game { class Game {

View file

@ -41,6 +41,8 @@ class Net {
this.socket.on('effect', data => { this.socket.on('effect', data => {
game.renderer.addEffect(data); game.renderer.addEffect(data);
}); });
this.socket.on('chat', data => console.log(data));
}; };
sendUpdate(inputs) { sendUpdate(inputs) {

19
public/views/game.jade Normal file
View 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
View file

@ -0,0 +1 @@
include game.jade

View file

@ -2,6 +2,8 @@
const World = require('./world'); const World = require('./world');
const messages = require('./messages.json');
class Room { class Room {
constructor() { constructor() {
this.players = new Set(); this.players = new Set();
@ -14,13 +16,14 @@ class Room {
} }
add(player) { add(player) {
wingbase.log(`${player.name} joined ${this.name}.`);
player.room = this; player.room = this;
player.connection.room = this.name; player.connection.room = this.name;
this.players.add(player); this.players.add(player);
this.setTeam(player, this.teamA.size > this.teamB.size ? 'b' : 'a'); this.setTeam(player, this.teamA.size > this.teamB.size ? 'b' : 'a');
this.world.addPlayer(player); this.world.addPlayer(player);
this.sendWorld(player); this.sendWorld(player);
wingbase.log(`${player.name} joined ${this.name}.`);
this.message('roomEnter', player.name);
} }
remove(player) { remove(player) {
@ -63,6 +66,22 @@ class Room {
this.players.forEach(player => player.send(msg, data)); 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) { sendWorld(player) {
let data = { let data = {
playerShipId: player.ship.id, playerShipId: player.ship.id,

View 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."
]
}

View file

@ -30,8 +30,8 @@ class Ship extends Body {
this.size = traits.size; this.size = traits.size;
// Mounts // Mounts
traits.mounts.forEach((mount, i) => { traits.mounts.forEach((data, i) => {
let mounts = new Mount(this, mount); let mount = new Mount(this, data);
this.mounts.push(mount); this.mounts.push(mount);
}); });
@ -112,7 +112,7 @@ class Ship extends Body {
name: this.player.name, name: this.player.name,
frame: this.frame, frame: this.frame,
power: this.power, power: this.power,
mounts: this.traits.mounts, mounts: this.mounts.map(m => m.packFull()),
turrets: this.turrets, turrets: this.turrets,
size: this.size, size: this.size,
delta: this.packDelta() delta: this.packDelta()

View file

@ -19,6 +19,12 @@ class Mount {
if (!this.fixture) return; if (!this.fixture) return;
this.fixture.destruct(); this.fixture.destruct();
} }
packFull() {
return {
}
}
} }
module.exports = Mount; module.exports = Mount;

View file

@ -20,6 +20,11 @@ class WingbaseServer extends ServerInterface {
this.log(`Wingbase version ${packageJson.version} running.`); this.log(`Wingbase version ${packageJson.version} running.`);
} }
stop() {
this.log('Server stopping.');
process.exit();
}
} }
function init() { function init() {

View file

@ -12,18 +12,26 @@ class WebServer {
} }
start() { start() {
this.appServer.listen(8080); this.appServer.listen(process.env.PORT || 8080);
let app = this.app; 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 => { minify(result => {
res.contentType('starbugs.min.js'); res.contentType('wingbase.min.js');
res.end(result); res.end(result);
}); });
}); });
app.use(express.static('public')); app.get('/', (req, res) => {
res.render('index', {});
});
app.use(express.static('public/static'));
} }
} }

View file

@ -9,7 +9,7 @@ const uglify = require('uglify-js');
function minifyJs(callback) { function minifyJs(callback) {
callback = callback || function() {}; callback = callback || function() {};
var dir = path.join(__dirname, '../../public/js/wingbase'); var dir = path.join(__dirname, '../../public/static/js/wingbase');
var cache = ''; var cache = '';
var scripts = []; var scripts = [];

12
test.js
View file

@ -1,3 +1,13 @@
#!bin/node #!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
View 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
View 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();
}