Skip to content
Permalink
Browse files

Changin emotes behaviour, adding a flying pony and stuff

  • Loading branch information...
Depado committed May 17, 2014
1 parent d50fcca commit dcf79166b9b05e01f504089c3dc69ad7a81ed2af
75 app.js
@@ -4,7 +4,9 @@ var express = require('express'),
io = require('socket.io').listen(server),
nunjucks = require('nunjucks'),
validator = require('validator'),
compress = require('compression');
compress = require('compression'),
staticData = require('./static_data'),
generation = require('./generation');

// Nunjucks configuration
nunjucks.configure('views', {
@@ -19,60 +21,37 @@ app.use('/custom', express.static(__dirname + '/static'));

var usernames = {};
var anon_users = 0;
var emotes = {
':angry:': {
'image': 'angry.gif'
},
':hi:': {
'image': 'hi.gif'
},
':sigh:': {
'image': 'sigh.gif'
},
':smirk:': {
'image': 'smirk.gif'
}
};

function generate_img_string (arg) {
var str = "<img src='/custom/images/" + emotes[arg]['image'] + "'";
if('height' in emotes[arg]) {
str += "style='height:" + emotes[arg]['height'] + "px; padding-bottom:" +
emotes[arg]['height']/10 + "px;'";
}
str += ">";
return str;
}

io.set('log level', 1);
io.sockets.on('connection', function (socket) {

anon_users += 1;
io.sockets.emit('updateusers', {'usernames':usernames, 'anon': anon_users});

// Broadcasts the message sent to all users after escaping it
socket.on('sendchat', function (data) {
if(socket.username == null) {
socket.emit('server-message', 'You are not connected.');
} else if (data == '/help') {
var help_message = 'This is the help message. Only you can see this.<br />Emotes :<br />';
for (var key in emotes) {
help_message += generate_img_string(key) + " " + key + "&nbsp;&nbsp;";
};
help_message += '<br />Commands :<br />/dash : Launches a wild pony over the screen of everyone !';
socket.emit('server-message', help_message);
} else if (data == '/dash') {
io.sockets.emit('dash');
io.sockets.emit('server-message', socket.username + ' launches a wild pony !');
}else {
var data = validator.escape(data);
for(var key in emotes) {
if(data.indexOf(key) != -1) {
var re = new RegExp(key,"g");
data = data.replace(re, generate_img_string(key));
}
};
io.sockets.emit('updatechat', socket.username, data);
} else {
switch(data) {
case '/help':
socket.emit('server-message', generation.generate_help_string());
break;
case '/dash':
io.sockets.emit('dash');
io.sockets.emit('server-message', socket.username + ' launches a wild pony !');
break;
default:
var data = validator.escape(data);
for(var key in staticData.emotes) {
if(data.indexOf(key) != -1) {
var re = new RegExp(key.replace('(', '\\(').replace(')', '\\)'), "g");
console.log(re);
data = data.replace(re, generation.generate_img_string(key));
}
};
io.sockets.emit('updatechat', socket.username, data);
break;
}
}
});

@@ -96,15 +75,15 @@ io.sockets.on('connection', function (socket) {
}
socket.username = new_username;
usernames[new_username] = new_username;
io.sockets.emit('updateusers', {'usernames':usernames, 'anon': anon_users});
io.sockets.emit('updateusers', {'usernames': usernames, 'anon': anon_users});
}
});

// Removing the user in case the websocket is closed
socket.on('disconnect', function(){
if(typeof socket.username != 'undefined') {
delete usernames[socket.username];
io.sockets.emit('updateusers', {'usernames':usernames, 'anon': anon_users});
io.sockets.emit('updateusers', {'usernames': usernames, 'anon': anon_users});
socket.broadcast.emit('server-message', socket.username + ' has disconnected');
} else {
anon_users -= 1;
@@ -118,4 +97,4 @@ app.get('/', function(req, res) {
});

// Listening on port 8080
server.listen(8080, '0.0.0.0');
server.listen(8080, '0.0.0.0');
@@ -0,0 +1,23 @@
var staticData = require('./static_data');

var generate_img_string = function (arg) {
var str = "<img src='/custom/images/" + staticData.emotes[arg]['image'] + "'";
if('height' in staticData.emotes[arg]) {
str += "style='height:" + staticData.emotes[arg]['height'] + "px; padding-bottom:" +
staticData.emotes[arg]['height']/10 + "px;'";
}
str += ">";
return str;
}

var generate_help_string = function () {
var help_message = 'This is the help message. Only you can see this.<br />Emotes :<br />';
for (var key in staticData.emotes) {
help_message += generate_img_string(key) + " " + key + "&nbsp;&nbsp;";
};
help_message += '<br />Commands :<br />/dash : Launches a wild pony over the screen of everyone !';
return help_message;
}

module.exports.generate_img_string = generate_img_string;
module.exports.generate_help_string = generate_help_string;
@@ -52,4 +52,9 @@ body {
-webkit-font-smoothing : none;
font-size: 8px;
overflow: hidden;
background: url('/custom/images/bg.jpg') no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
@@ -77,16 +77,18 @@ $(function(){
var windowHeight = $(document).height();
var current_dash = 0;
socket.on('dash', function() {
current_dash += 1
current_dash += 1;
var this_dash = current_dash;
$('body').append('<img id="dash_'+ this_dash +
'" src="/custom/images/rdash.gif" style="position: absolute; bottom:' +
Math.floor((Math.random() * windowHeight) + 1) + 'px;">');
$("#dash_" + this_dash).animate({
left: windowWidth
}, 5000, function() {
var image = "/custom/images/rdash.gif";
var position = Math.floor((Math.random() * 200) + 1);
if(position > 90) {
image = "/custom/images/rdash_fly.gif";
}
$('body').append(
'<img id="dash_'+ this_dash + '" src="' + image + '" style="position: absolute; bottom:' + position + 'px;">'
);
$('#dash_' + this_dash).animate({left: windowWidth}, 5000, function() {
$('#dash_' + this_dash).remove();
});
});

});
BIN +48.5 KB static/images/bg.gif
Binary file not shown.
BIN +114 KB static/images/bg.jpg
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,16 @@
var emotes = {
'(angry)': {
'image': 'angry.gif'
},
'(hi)': {
'image': 'hi.gif'
},
'(sigh)': {
'image': 'sigh.gif'
},
'(smirk)': {
'image': 'smirk.gif'
}
};

module.exports.emotes = emotes;
@@ -10,7 +10,7 @@
<script src='/socket.io/socket.io.js'></script>
<script src='/custom/custom.js'></script>
</head>
<body>
<body background="/custom/images/bg.jpg">
<div class="container-fluid">
<div class="row">
<div class="col-md-12">

0 comments on commit dcf7916

Please sign in to comment.
You can’t perform that action at this time.