Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Created by viktor on 25.06.14.
- */
- function init(mysqlConnection) {
- mysqlConnection.insert = function(table, inserts, cb) {
- mysqlConnection.query('INSERT INTO ' + table + ' SET ? ', inserts, function(err, rows) {
- if(cb) {
- cb(err, (err) ? null : rows.insertId);
- }
- });
- };
- mysqlConnection.update = function(table, id, updates, cb) {
- if(!id) {
- console.log('Invalid id - ' + id);
- return cb('Invalid id - ' + id)
- }
- mysqlConnection.query('UPDATE ' + table + ' SET ? WHERE id = "'+id+'"', updates, function(error, result) {
- if(cb)
- cb(error, result);
- });
- };
- mysqlConnection.customUpdate = function(table, column, id, updates, cb) {
- mysqlConnection.query('UPDATE ' + table + ' SET ? WHERE '+column+' = "'+id+'"', updates, function(error, result) {
- if(cb)
- cb(error, result);
- });
- };
- return mysqlConnection;
- }
- module.exports = init;
- ####
- var SocketController = {
- io: null,
- API: {
- send: function(params, cb) {
- if(!SocketController.io.sockets.connected[params['SID']]) {
- if (cb)
- cb('Socket not connected');
- return;
- }
- SocketController.io.sockets.connected[params['SID']].emit(params['event'], params['data']);
- },
- sendToAll: function(params) {
- SocketController.io.sockets.emit(params['event'], params['data']);
- },
- initEvents: function(socket) {
- socket.on('tournament_approvedToStartGame', function(tournamentGameId) {
- var user = Handlers.controllerHandler('user', 'getUserBySID', socket.id);
- if(!user) {
- return;
- }
- Handlers.controllerHandler('tournament', 'userIsReady', {
- userId: user['id'],
- tournamentGameId: tournamentGameId
- });
- });
- socket.on('tournament_subscribeOnTournamentChanges', function(tournamentId) {
- var user = Handlers.controllerHandler('user', 'getUserBySID', socket.id);
- if(!user) {
- return;
- }
- Handlers.controllerHandler('tournament', 'subscribeOnTournamentChanges', {
- userId: user['id'],
- tournamentId: tournamentId,
- sid: socket.id
- });
- });
- // socket.on('tournament_agreedPlayEarly', function() {
- // var user = Handlers.controllerHandler('user', 'getUserBySID', socket.id);
- // if(!user) {
- // return;
- // }
- // Handlers.controllerHandler('tournament', 'agreedPlayEarly', user['id']);
- // });
- // socket.on('tournament_canceledPlayEarly', function() {
- // var user = Handlers.controllerHandler('user', 'getUserBySID', socket.id);
- // if(!user) {
- // return;
- // }
- // Handlers.controllerHandler('tournament', 'canceledPlayEarly', user['id']);
- // });
- socket.on('tournament_tableApproved', function(tournamentId) {
- Handlers.controllerHandler('tournament', 'tableApproved', {
- socketId: socket.id,
- tournamentId: tournamentId
- });
- });
- socket.on('tournament_setGameEnded', function(tournamentGameId) {
- Handlers.controllerHandler('tournament', 'getAndSetGameEnded', tournamentGameId);
- });
- socket.on('tournament_countPlayersChanged', function(tournamentId) {
- Handlers.controllerHandler('tournament', 'countPlayersChanged', tournamentId);
- });
- socket.on('tournament_askToCheckAchievement', function(tournamentId) {
- Handlers.controllerHandler('tournament', 'checkAchievements', tournamentId);
- });
- // socket.on('tournament_updateEarlyGames', function(tournamentId) {
- // Handlers.controllerHandler('tournament', 'updateEarlyGames', tournamentId);
- // });
- socket.on('tournament_userDisqualified', function(userId, callback) {
- var user = Handlers.controllerHandler('user', 'getUserBySID', socket.id);
- if (!user || user && user.user_role_id < 100) {
- return;
- }
- Handlers.controllerHandler('tournament', 'userDisqualified', userId, callback);
- });
- }
- }
- };
- module.exports = function(io) {
- SocketController.io = io;
- return SocketController.API;
- };
- #####
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement