irc joker
This commit is contained in:
parent
b0da213886
commit
aabf95a03a
|
@ -35,6 +35,11 @@
|
||||||
<canvas id="polls" width="400" height="400">
|
<canvas id="polls" width="400" height="400">
|
||||||
</canvas>
|
</canvas>
|
||||||
</div>
|
</div>
|
||||||
|
<div id="irc">
|
||||||
|
<p class="caption">Backend, where are thou?</p>
|
||||||
|
<ul>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
<div id="answers">
|
<div id="answers">
|
||||||
<ul>
|
<ul>
|
||||||
<li id="answer0">Montenegro</li>
|
<li id="answer0">Montenegro</li>
|
||||||
|
|
|
@ -0,0 +1,102 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||||
|
|
||||||
|
<svg
|
||||||
|
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||||
|
xmlns:cc="http://creativecommons.org/ns#"
|
||||||
|
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||||
|
xmlns:svg="http://www.w3.org/2000/svg"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||||
|
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||||
|
width="100"
|
||||||
|
height="50"
|
||||||
|
id="svg2"
|
||||||
|
version="1.1"
|
||||||
|
inkscape:version="0.48.0 r9654"
|
||||||
|
sodipodi:docname="nedap.svg"
|
||||||
|
inkscape:export-filename="/home/stephan/public_html/ds-quiz/nedap.png"
|
||||||
|
inkscape:export-xdpi="90"
|
||||||
|
inkscape:export-ydpi="90">
|
||||||
|
<defs
|
||||||
|
id="defs4">
|
||||||
|
<inkscape:perspective
|
||||||
|
sodipodi:type="inkscape:persp3d"
|
||||||
|
inkscape:vp_x="0 : 526.18109 : 1"
|
||||||
|
inkscape:vp_y="0 : 1000 : 0"
|
||||||
|
inkscape:vp_z="744.09448 : 526.18109 : 1"
|
||||||
|
inkscape:persp3d-origin="372.04724 : 350.78739 : 1"
|
||||||
|
id="perspective10" />
|
||||||
|
<inkscape:perspective
|
||||||
|
id="perspective3607"
|
||||||
|
inkscape:persp3d-origin="0.5 : 0.33333333 : 1"
|
||||||
|
inkscape:vp_z="1 : 0.5 : 1"
|
||||||
|
inkscape:vp_y="0 : 1000 : 0"
|
||||||
|
inkscape:vp_x="0 : 0.5 : 1"
|
||||||
|
sodipodi:type="inkscape:persp3d" />
|
||||||
|
</defs>
|
||||||
|
<sodipodi:namedview
|
||||||
|
id="base"
|
||||||
|
pagecolor="#313059"
|
||||||
|
bordercolor="#666666"
|
||||||
|
borderopacity="1.0"
|
||||||
|
inkscape:pageopacity="1"
|
||||||
|
inkscape:pageshadow="2"
|
||||||
|
inkscape:zoom="1.0172413"
|
||||||
|
inkscape:cx="-137.86512"
|
||||||
|
inkscape:cy="95.227274"
|
||||||
|
inkscape:document-units="px"
|
||||||
|
inkscape:current-layer="layer1"
|
||||||
|
showgrid="true"
|
||||||
|
inkscape:window-width="1916"
|
||||||
|
inkscape:window-height="1177"
|
||||||
|
inkscape:window-x="0"
|
||||||
|
inkscape:window-y="19"
|
||||||
|
inkscape:window-maximized="0">
|
||||||
|
<inkscape:grid
|
||||||
|
type="xygrid"
|
||||||
|
id="grid2816"
|
||||||
|
empspacing="5"
|
||||||
|
visible="true"
|
||||||
|
enabled="true"
|
||||||
|
snapvisiblegridlinesonly="true" />
|
||||||
|
</sodipodi:namedview>
|
||||||
|
<metadata
|
||||||
|
id="metadata7">
|
||||||
|
<rdf:RDF>
|
||||||
|
<cc:Work
|
||||||
|
rdf:about="">
|
||||||
|
<dc:format>image/svg+xml</dc:format>
|
||||||
|
<dc:type
|
||||||
|
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||||
|
<dc:title></dc:title>
|
||||||
|
</cc:Work>
|
||||||
|
</rdf:RDF>
|
||||||
|
</metadata>
|
||||||
|
<g
|
||||||
|
inkscape:label="Layer 1"
|
||||||
|
inkscape:groupmode="layer"
|
||||||
|
id="layer1"
|
||||||
|
transform="translate(0,-1002.3622)">
|
||||||
|
<rect
|
||||||
|
style="fill:#ffffff;fill-opacity:0;fill-rule:evenodd;stroke:#ffffff;stroke-opacity:1;stroke-linejoin:round;stroke-width:2;stroke-miterlimit:4;stroke-dasharray:none;stroke-linecap:butt"
|
||||||
|
id="rect2818"
|
||||||
|
width="100"
|
||||||
|
height="50"
|
||||||
|
x="0"
|
||||||
|
y="0"
|
||||||
|
transform="translate(0,1002.3622)" />
|
||||||
|
<text
|
||||||
|
xml:space="preserve"
|
||||||
|
style="font-size:37.23656082px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#ffffff;fill-opacity:1;stroke:none;font-family:TratexSvart;-inkscape-font-specification:TratexSvart"
|
||||||
|
x="2.8389449"
|
||||||
|
y="805.90045"
|
||||||
|
id="text3958"
|
||||||
|
sodipodi:linespacing="125%"
|
||||||
|
transform="scale(0.77024439,1.2982892)"><tspan
|
||||||
|
sodipodi:role="line"
|
||||||
|
id="tspan3960"
|
||||||
|
x="2.8389449"
|
||||||
|
y="805.90045">:6667</tspan></text>
|
||||||
|
</g>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 3.3 KiB |
8
quiz.css
8
quiz.css
|
@ -57,6 +57,14 @@ p {
|
||||||
font-size: 200%;
|
font-size: 200%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#irc ul {
|
||||||
|
list-style-type: none;
|
||||||
|
font-family: monospace;
|
||||||
|
font-size: 150%;
|
||||||
|
text-align: left;
|
||||||
|
width: 40em;
|
||||||
|
}
|
||||||
|
|
||||||
#answers {
|
#answers {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
bottom: 0;
|
bottom: 0;
|
||||||
|
|
38
quiz.js
38
quiz.js
|
@ -60,7 +60,7 @@ function setupWs() {
|
||||||
};
|
};
|
||||||
ws.onclose = function() {
|
ws.onclose = function() {
|
||||||
console.error('WebSocket closed');
|
console.error('WebSocket closed');
|
||||||
setupWs();
|
window.setTimeout(setupWs, 100);
|
||||||
};
|
};
|
||||||
ws.onmessage = function(event) {
|
ws.onmessage = function(event) {
|
||||||
try {
|
try {
|
||||||
|
@ -141,7 +141,7 @@ function startQuiz() {
|
||||||
if (name) {
|
if (name) {
|
||||||
playerNames[i] = name;
|
playerNames[i] = name;
|
||||||
playerScores[i] = 0;
|
playerScores[i] = 0;
|
||||||
$('#scoreboard dl').append('<dt></dt><dd><span class="score">0</span><img src="fiftyfifty.png" class="fiftyfifty"><img src="audience.png" class="audience"><img src="phone.png" class="phone"><img src="nedap.png" class="nedap"></dd>');
|
$('#scoreboard dl').append('<dt></dt><dd><span class="score">0</span><img src="fiftyfifty.png" class="fiftyfifty"><img src="audience.png" class="audience"><img src="phone.png" class="phone"><img src="nedap.png" class="nedap"><img src="irc.png" class="irc"></dd>');
|
||||||
$('#scoreboard dl dt').last().text(name);
|
$('#scoreboard dl dt').last().text(name);
|
||||||
$('#players').append('<li class="player'+i+'"><span class="name"></span><span class="score">0</span></li>');
|
$('#players').append('<li class="player'+i+'"><span class="name"></span><span class="score">0</span></li>');
|
||||||
$('#players li.player'+i+' span.name').text(name);
|
$('#players li.player'+i+' span.name').text(name);
|
||||||
|
@ -195,6 +195,10 @@ function takeJoker(activePlayer, joker) {
|
||||||
// Joker already taken
|
// Joker already taken
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
/* Hide previous special jokers */
|
||||||
|
$('#nedap').hide();
|
||||||
|
$('#irc').hide();
|
||||||
|
|
||||||
playerJokers[activePlayer][joker] = true;
|
playerJokers[activePlayer][joker] = true;
|
||||||
$('#tier').append('<img src="' + joker + '.png">');
|
$('#tier').append('<img src="' + joker + '.png">');
|
||||||
$('#scoreboard dd').eq(activePlayer).find('.' + joker).remove();
|
$('#scoreboard dd').eq(activePlayer).find('.' + joker).remove();
|
||||||
|
@ -253,7 +257,6 @@ function takeJoker(activePlayer, joker) {
|
||||||
/* Fill */
|
/* Fill */
|
||||||
ctx.fillStyle = '#ccc';
|
ctx.fillStyle = '#ccc';
|
||||||
var barHeight = (y2 - y1) * scores[i] / total;
|
var barHeight = (y2 - y1) * scores[i] / total;
|
||||||
console.log({x1:x1,y1:y1,x2:x2,y2:y2,barHeight:barHeight});
|
|
||||||
ctx.fillRect(x1, y2 - barHeight, x2 - x1, barHeight);
|
ctx.fillRect(x1, y2 - barHeight, x2 - x1, barHeight);
|
||||||
|
|
||||||
/* Outline */
|
/* Outline */
|
||||||
|
@ -274,6 +277,31 @@ console.log('scores: '+JSON.stringify(scores));
|
||||||
redraw();
|
redraw();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
if (joker === 'irc') {
|
||||||
|
sendToBackend({ irc: "activate" });
|
||||||
|
onBackendMessage = function(msg) {
|
||||||
|
if (msg.irc && msg.irc.nick && msg.irc.text) {
|
||||||
|
var ircPane = $('#irc ul');
|
||||||
|
var line = $('<li></li>');
|
||||||
|
line.text('<' + msg.irc.nick + '> ' + msg.irc.text);
|
||||||
|
line.hide();
|
||||||
|
ircPane.append(line);
|
||||||
|
line.slideDown(200);
|
||||||
|
|
||||||
|
if (ircPane.children().length > 8) {
|
||||||
|
var line1 = ircPane.children().first();
|
||||||
|
line1.slideUp(200, function() {
|
||||||
|
line1.remove();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (msg.irc && msg.irc.server && msg.irc.channel) {
|
||||||
|
$('#irc .caption').text(msg.irc.server + ' ' + msg.irc.channel);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
$('#irc ul').empty();
|
||||||
|
$('#irc').slideDown(500);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function setQuestionContents(q) {
|
function setQuestionContents(q) {
|
||||||
|
@ -404,10 +432,14 @@ function switchToGame() {
|
||||||
} else if (activePlayer !== null &&
|
} else if (activePlayer !== null &&
|
||||||
key === 'n') {
|
key === 'n') {
|
||||||
takeJoker(activePlayer, 'nedap');
|
takeJoker(activePlayer, 'nedap');
|
||||||
|
} else if (activePlayer !== null &&
|
||||||
|
key === 'i') {
|
||||||
|
takeJoker(activePlayer, 'irc');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
$('#nedap').hide();
|
$('#nedap').hide();
|
||||||
|
$('#irc').hide();
|
||||||
onBackendMessage = null;
|
onBackendMessage = null;
|
||||||
// Instantly show the question:
|
// Instantly show the question:
|
||||||
$('#game').show();
|
$('#game').show();
|
||||||
|
|
73
server.js
73
server.js
|
@ -1,9 +1,15 @@
|
||||||
var Connect = require('connect');
|
var Connect = require('connect');
|
||||||
var wss = require('websocket-server');
|
var wss = require('websocket-server');
|
||||||
var wsc = require('websocket-client');
|
var wsc = require('websocket-client');
|
||||||
|
var irc = require('irc-js');
|
||||||
|
|
||||||
var frontend;
|
var frontend;
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Nedap backend connection
|
||||||
|
*/
|
||||||
|
|
||||||
/* TODO: url */
|
/* TODO: url */
|
||||||
var nedap;
|
var nedap;
|
||||||
function connectNedap() {
|
function connectNedap() {
|
||||||
|
@ -24,7 +30,7 @@ function connectNedap() {
|
||||||
try {
|
try {
|
||||||
var msg = JSON.parse(data);
|
var msg = JSON.parse(data);
|
||||||
console.log({ fromNedap: msg });
|
console.log({ fromNedap: msg });
|
||||||
frontend.send(JSON.stringify({ nedap: msg }));
|
sendToFrontend({ nedap: msg });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e.stack);
|
console.error(e.stack);
|
||||||
}
|
}
|
||||||
|
@ -32,6 +38,56 @@ function connectNedap() {
|
||||||
}
|
}
|
||||||
connectNedap();
|
connectNedap();
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* IRC client
|
||||||
|
*/
|
||||||
|
|
||||||
|
var IRC_SERVER = 'irc.freenode.net';
|
||||||
|
var IRC_CHAN = '#pentanews';
|
||||||
|
var chat = new irc({ server: IRC_SERVER,
|
||||||
|
encoding: 'utf-8',
|
||||||
|
nick: '[Ceiling]Cat'
|
||||||
|
});
|
||||||
|
function connectChat() {
|
||||||
|
chat.connect();
|
||||||
|
}
|
||||||
|
connectChat();
|
||||||
|
chat.addListener('376', function() {
|
||||||
|
chat.join(IRC_CHAN);
|
||||||
|
});
|
||||||
|
chat.addListener('366', function(msg) {
|
||||||
|
if (msg.params[1] === IRC_CHAN) {
|
||||||
|
console.log('Successfully joined ' + IRC_CHAN);
|
||||||
|
pushIrcInfo();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
chat.addListener('privmsg', function(msg) {
|
||||||
|
console.log({PRIVMSG:msg});
|
||||||
|
var nick = msg.person.nick;
|
||||||
|
var channel = msg.params[0];
|
||||||
|
var text = msg.params[1];
|
||||||
|
if (nick && channel === IRC_CHAN && text && frontend) {
|
||||||
|
sendToFrontend({ irc: { nick: nick,
|
||||||
|
text: text
|
||||||
|
} });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
chat.addListener('disconnected', function() {
|
||||||
|
console.error('Chat disconnected!');
|
||||||
|
process.nextTick(connectChat);
|
||||||
|
});
|
||||||
|
|
||||||
|
function pushIrcInfo() {
|
||||||
|
sendToFrontend({ irc: { server: IRC_SERVER,
|
||||||
|
channel: IRC_CHAN } });
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Web server
|
||||||
|
*/
|
||||||
|
|
||||||
var server = Connect.createServer(
|
var server = Connect.createServer(
|
||||||
Connect.logger(),
|
Connect.logger(),
|
||||||
Connect.bodyDecoder(),
|
Connect.bodyDecoder(),
|
||||||
|
@ -39,6 +95,10 @@ var server = Connect.createServer(
|
||||||
Connect.errorHandler({ dumpExceptions: true, showStack: true })
|
Connect.errorHandler({ dumpExceptions: true, showStack: true })
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* WebSocket server
|
||||||
|
*/
|
||||||
|
|
||||||
wss.createServer({ server: server }).on('connection', function(conn) {
|
wss.createServer({ server: server }).on('connection', function(conn) {
|
||||||
frontend = conn;
|
frontend = conn;
|
||||||
|
|
||||||
|
@ -50,7 +110,9 @@ wss.createServer({ server: server }).on('connection', function(conn) {
|
||||||
console.log({ toNedap: msg.nedap });
|
console.log({ toNedap: msg.nedap });
|
||||||
nedap.send(JSON.stringify(msg.nedap));
|
nedap.send(JSON.stringify(msg.nedap));
|
||||||
}
|
}
|
||||||
|
else if (msg.irc === "activate") {
|
||||||
|
pushIrcInfo();
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e.stack);
|
console.error(e.stack);
|
||||||
}
|
}
|
||||||
|
@ -63,4 +125,11 @@ wss.createServer({ server: server }).on('connection', function(conn) {
|
||||||
conn.on('error', reset);
|
conn.on('error', reset);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function sendToFrontend(obj) {
|
||||||
|
if (!frontend)
|
||||||
|
return;
|
||||||
|
|
||||||
|
frontend.send(JSON.stringify(obj));
|
||||||
|
}
|
||||||
|
|
||||||
server.listen(8081);
|
server.listen(8081);
|
||||||
|
|
Loading…
Reference in New Issue