Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var app = require('express')();
- var server = require('http').Server(app);
- var io = require('socket.io').listen(server);
- var MySQLEvents = require('mysql-events');
- var dsn = {
- host: "149.202.54.214",
- user: "Revocean-DB-User",
- password: "Revocean-DB-User-2016ABNP"
- };
- var mysqlEventWatcher = MySQLEvents(dsn);
- server.listen(2424);
- var pairs = new Array();
- var login = {};
- var smartphonevertification = {}
- var path = {};
- io.sockets.on('connection', function (client) {
- client.on('login', function (data) {
- if(typeof login[data["u_id"]] == "undefined")
- login[data["u_id"]] = {};
- if(typeof login[data["u_id"]][data["b_id"]] == "undefined")
- login[data["u_id"]][data["b_id"]] = {};
- login[data["u_id"]][data["b_id"]] = {socket: client, domain: data["domain"]};
- console.log(login);
- path[client.id] = {"type": "login", "u_id": data["u_id"], "b_id": data["b_id"]};
- });
- client.on('smartphonevertification', function (data) {
- if(typeof smartphonevertification[data["token"]] == "undefined")
- smartphonevertification[data["token"]] = {};
- smartphonevertification[data["token"]] = {socket: client};
- console.log(smartphonevertification);
- path[client.id] = {"type": "smartphonevertification", "token": data["token"]};
- });
- client.on('disconnect', function() {
- if(typeof path[client.id] != "undefined") {
- if(typeof path[client.id]["type"] != "undefined" && path[client.id]["type"] == "login") {
- delete login[path[client.id]["u_id"]][path[client.id]["b_id"]];
- } else if(typeof path[client.id]["type"] != "undefined" && path[client.id]["type"] == "smartphonevertification") {
- delete smartphonevertification[path[client.id]["token"]];
- }
- }
- });
- });
- var Account = mysqlEventWatcher.add(
- 'Account',
- function (oldRow, newRow) {
- if (oldRow === null) {
- if(newRow["table"] == "notifications") {
- var user = login[newRow["fields"]["n_u_id"]];
- if(typeof user != "undefined") {
- for (var key in user) {
- if(user.hasOwnProperty(key)) {
- io.sockets.connected[user[key]["socket"].id].emit('newnotification');
- }
- }
- }
- }
- } else if (newRow === null) {
- } else if (oldRow !== null && newRow !== null) {
- if(newRow["table"] == "notifications") {
- var user = login[newRow["fields"]["n_u_id"]];
- if(typeof user != "undefined") {
- for (var key in user) {
- if(user.hasOwnProperty(key)) {
- io.sockets.connected[user[key]["socket"].id].emit('notificationchanged');
- }
- }
- }
- } else if(newRow["table"] == "loginattemps") {
- if(oldRow["fields"]["la_smartphone_success"] == null && newRow["fields"]["la_smartphone_success"]) {
- var user = checkSmartphoneLogin[newRow["fields"]["la_id"]][newRow["fields"]["la_authtoken"]];
- if(typeof user != "undefined") {
- io.sockets.connected[user["socket"].id].emit('smartphone_success');
- }
- }
- }
- }
- },
- 'Active'
- );
- var Users = mysqlEventWatcher.add(
- 'Users',
- function (oldRow, newRow) {
- if (oldRow === null) {
- if(newRow["table"] == "blockedusers") {
- var user = login[newRow["fields"]["bu_u_id"]];
- if(typeof user != "undefined") {
- for (var key in user) {
- if(user.hasOwnProperty(key)) {
- io.sockets.connected[user[key]["socket"].id].emit('refreshpage');
- }
- }
- }
- }
- } else if (newRow === null) {
- if(oldRow["table"] == "blockedusers") {
- var user = login[oldRow["fields"]["bu_u_id"]];
- if(typeof user != "undefined") {
- for (var key in user) {
- if(user.hasOwnProperty(key)) {
- io.sockets.connected[user[key]["socket"].id].emit('refreshpage');
- }
- }
- }
- }
- } else if (oldRow !== null && newRow !== null) {
- if(oldRow["table"] == "usersbrowsers") {
- if(oldRow["fields"]["ub_loggedout"] == "0" && newRow["fields"]["ub_loggedout"] == "1") {
- var infos = login[oldRow["fields"]["ub_u_id"]][oldRow["fields"]["ub_b_id"]];
- if(typeof infos != "undefined") {
- if(newRow["fields"]["ub_loggedout"]) {
- io.sockets.connected[infos["socket"].id].emit('loguserout');
- }
- }
- }
- }
- if(oldRow["table"] == "users") {
- if(oldRow["fields"]["u_deleted"] == "0" && newRow["fields"]["u_deleted"] == "1") {
- var user = login[oldRow["fields"]["u_id"]];
- for (var key in user) {
- if(user.hasOwnProperty(key)) {
- io.sockets.connected[user[key]["socket"].id].emit('loguserout');
- }
- }
- }
- if(oldRow["fields"]["u_active"] == "0" && newRow["fields"]["u_active"] == "1" || oldRow["fields"]["u_active"] == "1" && newRow["fields"]["u_active"] == "0") {
- var user = login[oldRow["fields"]["u_id"]];
- for (var key in user) {
- if(user.hasOwnProperty(key)) {
- io.sockets.connected[user[key]["socket"].id].emit('refreshpage');
- }
- }
- }
- }
- if(oldRow["table"] == "smartphonevertification") {
- var user = smartphonevertification[newRow["fields"]["sv_token"]];
- if(typeof user != "undefined") {
- io.sockets.connected[user["socket"].id].emit('smartphone_success');
- }
- }
- }
- },
- 'Active'
- );
- var Events = mysqlEventWatcher.add(
- 'Events',
- function (oldRow, newRow) {
- if (oldRow === null) {
- if(newRow["table"] == "votes") {
- console.log(login);
- for(var users in login) {
- for(var key in login[users]) {
- if(login[users].hasOwnProperty(key)) {
- if(login[users][key]["domain"] == "events") {
- io.sockets.connected[login[users][key]["socket"].id].emit('updatevote',{e_id: newRow["fields"]["v_e_id"]});
- }
- }
- }
- }
- }
- } else if (newRow === null) {
- } else if (oldRow !== null && newRow !== null) {
- }
- },
- 'Active'
- );
- var Class = mysqlEventWatcher.add(
- 'Class',
- function (oldRow, newRow) {
- if((oldRow != null && oldRow["table"] == "votes") || (newRow != null && newRow["table"] == "votes")) {
- console.log(login);
- for(var users in login) {
- for(var key in login[users]) {
- if(login[users].hasOwnProperty(key)) {
- if(login[users][key]["domain"] == "class") {
- io.sockets.connected[login[users][key]["socket"].id].emit('updatevote');
- }
- }
- }
- }
- }
- if (oldRow === null) {
- } else if (newRow === null) {
- } else if (oldRow !== null && newRow !== null) {
- }
- },
- 'Active'
- );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement