Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var app = require('express')();
- var http = require('http').Server(app);
- var io = require('socket.io')(http);
- var mysql = require('mysql');
- var port = 80;
- var connection = mysql.createConnection({
- host : '89.203.250.131',
- user : 'socket',
- password : '',
- database : 'Dragonity.eu',
- port : 3306,
- });
- connection.connect();
- connection.on('error', function(err) {
- console.log(err);
- });
- app.get('/', function(req, res){
- res.sendFile(__dirname + "/index.html");
- });
- io.on('connection', function(socket){
- socket.on('send', function(req){
- var functionName = req.data.toString().split(';')[0];
- var functionArgs = req.data.toString().split(';')[1];
- callFunction(functionName, functionArgs);
- });
- });
- http.listen(port);
- function callFunction(functionName, args){
- if(eval("typeof "+functionName+" === 'function'")){
- eval(functionName)(args);
- }else{
- console.log('Error: Trying to execute undefined function: ' + functionName);
- }
- }
- // Functions
- function gci(args){
- var gci;
- connection.query("SELECT * FROM cases WHERE id = ?", args, function(err, rows, fields) {
- if (err) throw err;
- gci = JSON.stringify(rows[0]);
- });
- io.emit('getgci', {data: gci});
- }
- function searchc(args){
- var searchc;
- connection.query("SELECT * FROM cases WHERE name LIKE ? LIMIT 2", '%'+args+'%', function(err, rows, fields) {
- if (err) throw err;
- io.emit('getsearchc', {data: rows});
- });
- }
- function gc(args = false){
- var gc;
- connection.query("SELECT * FROM cases", function(err, rows, fields) {
- if (err) throw err;
- var cases = [];
- for(var i=0;i<rows.length;i++){
- cases.push(rows[i]);
- }
- gc = JSON.stringify(cases);
- });
- io.emit('getgc', {data: gc});
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement