Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var http = require('http').createServer(onRequest),
- io = require('socket.io').listen(http),
- mysql = require('mysql'),
- fs = require('fs');
- http.listen(8080);
- var client = mysql.createConnection( {
- host: 'localhost',
- user: 'root',
- password: ''
- } );
- function onRequest( request, response ) {
- console.log('Request received!');
- response.writeHead( 200, { 'Content-Type': 'text/html' } );
- response.end();
- }
- io.sockets.on('connection', function ( socket ) {
- socket.on( 'actionbar', function ( char_id ) {
- var table = 'character_action';
- var database = 'n_characters';
- var output = 0;
- client.query( 'USE ' + database );
- client.query( 'SELECT data FROM ' + table + ' WHERE character_id = ' + char_id, function ( err, rows ) {
- if ( err ) throw err;
- if ( rows[0]['data'].length != 0 )
- output = rows[0]['data'];
- else
- output = 0;
- socket.emit( 'result', output );
- } );
- socket.on( 'update', function ( data ) {
- console.log('Update request received!');
- client.query( 'UPDATE ' + table + ' SET data = \'' + data + '\' WHERE character_id = ' + char_id, function ( err, result ) {
- if ( err ) throw err;
- } );
- } );
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement