Advertisement
Guest User

Untitled

a guest
Feb 24th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.27 KB | None | 0 0
  1. /**
  2. * Created by viktor on 25.06.14.
  3. */
  4.  
  5. function init(mysqlConnection) {
  6.  
  7. mysqlConnection.insert = function(table, inserts, cb) {
  8. mysqlConnection.query('INSERT INTO ' + table + ' SET ? ', inserts, function(err, rows) {
  9. if(cb) {
  10. cb(err, (err) ? null : rows.insertId);
  11. }
  12. });
  13. };
  14.  
  15. mysqlConnection.update = function(table, id, updates, cb) {
  16. if(!id) {
  17. console.log('Invalid id - ' + id);
  18. return cb('Invalid id - ' + id)
  19. }
  20. mysqlConnection.query('UPDATE ' + table + ' SET ? WHERE id = "'+id+'"', updates, function(error, result) {
  21. if(cb)
  22. cb(error, result);
  23. });
  24. };
  25.  
  26. mysqlConnection.customUpdate = function(table, column, id, updates, cb) {
  27. mysqlConnection.query('UPDATE ' + table + ' SET ? WHERE '+column+' = "'+id+'"', updates, function(error, result) {
  28. if(cb)
  29. cb(error, result);
  30. });
  31. };
  32.  
  33. return mysqlConnection;
  34. }
  35.  
  36. module.exports = init;
  37. ####
  38. var SocketController = {
  39. io: null,
  40. API: {
  41. send: function(params, cb) {
  42. if(!SocketController.io.sockets.connected[params['SID']]) {
  43. if (cb)
  44. cb('Socket not connected');
  45. return;
  46. }
  47. SocketController.io.sockets.connected[params['SID']].emit(params['event'], params['data']);
  48. },
  49. sendToAll: function(params) {
  50. SocketController.io.sockets.emit(params['event'], params['data']);
  51. },
  52. initEvents: function(socket) {
  53. socket.on('tournament_approvedToStartGame', function(tournamentGameId) {
  54. var user = Handlers.controllerHandler('user', 'getUserBySID', socket.id);
  55. if(!user) {
  56. return;
  57. }
  58. Handlers.controllerHandler('tournament', 'userIsReady', {
  59. userId: user['id'],
  60. tournamentGameId: tournamentGameId
  61. });
  62. });
  63.  
  64. socket.on('tournament_subscribeOnTournamentChanges', function(tournamentId) {
  65. var user = Handlers.controllerHandler('user', 'getUserBySID', socket.id);
  66. if(!user) {
  67. return;
  68. }
  69. Handlers.controllerHandler('tournament', 'subscribeOnTournamentChanges', {
  70. userId: user['id'],
  71. tournamentId: tournamentId,
  72. sid: socket.id
  73. });
  74. });
  75.  
  76. // socket.on('tournament_agreedPlayEarly', function() {
  77. // var user = Handlers.controllerHandler('user', 'getUserBySID', socket.id);
  78. // if(!user) {
  79. // return;
  80. // }
  81. // Handlers.controllerHandler('tournament', 'agreedPlayEarly', user['id']);
  82. // });
  83.  
  84. // socket.on('tournament_canceledPlayEarly', function() {
  85. // var user = Handlers.controllerHandler('user', 'getUserBySID', socket.id);
  86. // if(!user) {
  87. // return;
  88. // }
  89. // Handlers.controllerHandler('tournament', 'canceledPlayEarly', user['id']);
  90. // });
  91.  
  92. socket.on('tournament_tableApproved', function(tournamentId) {
  93. Handlers.controllerHandler('tournament', 'tableApproved', {
  94. socketId: socket.id,
  95. tournamentId: tournamentId
  96. });
  97. });
  98.  
  99. socket.on('tournament_setGameEnded', function(tournamentGameId) {
  100. Handlers.controllerHandler('tournament', 'getAndSetGameEnded', tournamentGameId);
  101. });
  102.  
  103. socket.on('tournament_countPlayersChanged', function(tournamentId) {
  104. Handlers.controllerHandler('tournament', 'countPlayersChanged', tournamentId);
  105. });
  106.  
  107. socket.on('tournament_askToCheckAchievement', function(tournamentId) {
  108. Handlers.controllerHandler('tournament', 'checkAchievements', tournamentId);
  109. });
  110.  
  111. // socket.on('tournament_updateEarlyGames', function(tournamentId) {
  112. // Handlers.controllerHandler('tournament', 'updateEarlyGames', tournamentId);
  113. // });
  114.  
  115. socket.on('tournament_userDisqualified', function(userId, callback) {
  116. var user = Handlers.controllerHandler('user', 'getUserBySID', socket.id);
  117. if (!user || user && user.user_role_id < 100) {
  118. return;
  119. }
  120. Handlers.controllerHandler('tournament', 'userDisqualified', userId, callback);
  121. });
  122. }
  123. }
  124. };
  125.  
  126. module.exports = function(io) {
  127. SocketController.io = io;
  128. return SocketController.API;
  129. };
  130. #####
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement