Advertisement
Guest User

Untitled

a guest
Jan 17th, 2016
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********************************
  2.  * FiveHabbo project
  3.  * Recreating Habbo in Javascript
  4. ********************************/
  5. var config = require('../config.js');
  6. var users  = require('./users.js');
  7. var Socket = {
  8.     init: function() {
  9.         Socket.io = require('socket.io').listen(config.port);
  10.     },
  11.     on: function(socket, rsa, header, callback) {
  12.         socket.on(header, function(d) {
  13.             var data = JSON.parse(rsa.Decrypt(d));
  14.             callback(data);
  15.         });
  16.     },
  17.     onN: function(socket, rsa, header, callback) {
  18.         var uid = users.getIdBySocketID(socket.id);
  19.         if(uid == false) Socket.on(socket, rsa, header, callback);
  20.     },
  21.     onL: function(socket, rsa, header, callback) {
  22.         var uid = users.getIdBySocketID(socket.id);
  23.         if(uid != false) Socket.on(socket, rsa, header, callback);
  24.     },
  25.     emitClient: function(clientId, header, data) {
  26.         Socket.io.to(clientId).emit(header, data);
  27.     },
  28.     emitAll: function(header, data) {
  29.         Socket.io.sockets.emit(header, data);
  30.     },
  31.     kik: function(socketID) {
  32.         Socket.io.sockets.connected[socketID].disconnect();
  33.         var uid = users.getIdBySocketID(socketID);
  34.         if(uid != false) users.Remove(uid);
  35.     }
  36. }
  37. Socket.init();
  38. module.exports = Socket;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement