Advertisement
Underworld1337

Untitled

Sep 19th, 2015
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // start command
  2. // node /root/node_modules/socket.io/lib/node_server.js
  3. // node /root/wpo_server/node_modules/socket.io/lib/wpoServer.js
  4. // node /root/wpo_server/app.js
  5.  
  6. // Require HTTP module (to start server) and Socket.IO
  7. var server = require('http').createServer();
  8. var io = require('socket.io').listen('8080'), // <-- das ist unschΓΆn
  9.     mysql = require("mysql"),
  10.     squel = require("squel"),
  11.     memcache = require("memcache");
  12.     //client = require('socket.io-client');
  13. // var port = "8080"
  14. var dbhost = "";
  15. var dbuser = "";
  16. var dbpass = "";
  17. var database = "";
  18. var sqlport = "3306";
  19.  
  20.  
  21. var con =  mysql.createConnection({
  22.   host : dbhost,
  23.   user : dbuser,
  24.   password: dbpass,
  25.   database  : database,
  26.   port : sqlport
  27. });
  28. if(con.connect()){
  29.  
  30. }
  31.  
  32. // Create a Socket.IO instance, passing it our server
  33. var socket = io.listen(server);
  34. socket = socket.of('/root'); // set namespace
  35. socket.on('connection', function(socket, error){
  36.   socket.on('auth', function(sessID){
  37.     var res = authOn(sessID);
  38.     console.log(res);
  39.     var Nutzer = new user_class(res, socket.id);
  40.     console.log(Nutzer);
  41.   });
  42.  
  43.   socket.on('disconnect', function(sessID){
  44.     console.log('schaui');
  45.     //delete clients[socket.id]
  46.   });
  47.  
  48.   //console.log( client );
  49.   //console.log( io.of('/root').connected );
  50.   //console.log(client.handshake.headers.cookie);
  51.   // meine Funktionen, soweit muss man jedoch ers ma kommen :D
  52. });
  53. console.log('Juhu Server running');
  54.  
  55. // experimental js-class-constructor
  56. var cClass = function(methods){  
  57.   var rClass = function(){    
  58.     this.initialize.apply(this, arguments);          
  59.   };
  60.   for (var property in methods) {
  61.     rClass.prototype[property] = methods[property];
  62.   }
  63.   if (!rClass.prototype.initialize) rClass.prototype.initialize = function(){};      
  64.   return rClass;
  65. };
  66.  
  67. // userklasse
  68. var user_class = cClass({
  69.   initialize: function(uid,socket) {
  70.     this.uid = uid;
  71.     this.sid = socket;
  72.     //this.name = name;
  73.     this.last_activity = new Date().toString();
  74.   },
  75.   log: function() {
  76.     return "Ich bin "+this.uid+" und war "+this.last_activity+" zuletzt aktiv.";
  77.   }
  78. });
  79.  
  80. // dashboard.clients.[i].uid
  81. var lobby_class = cClass({
  82.   initialize: function() {
  83.     this.clients = [];
  84.     this.cnt = '';
  85.   },
  86.   add: function(client) {
  87.     client.push(this.clients);
  88.   }
  89. });
  90.  
  91. function authOn(sessID){
  92.   console.log('suche: '+sessID );
  93.   var cache = new memcache.Client(11211, "localhost");
  94.   cache.connect();
  95.   cache.get("sess/"+sessID, function(error, result){
  96.     if(typeof(error)==="undefined"){
  97.       if(typeof(result)!=="undefined" && result != null){
  98.         var session = JSON.parse(result);
  99.         return session.uid;
  100.       }
  101.     }else{
  102.       console.log("error : "+error);
  103.     }
  104.   });
  105. }
  106.  
  107. function authOff(uid){
  108.  
  109. }
  110.  
  111. var delay = (function(){
  112.   var timer = 0;
  113.   return function (callback, ms) {
  114.     clearTimeout (timer);
  115.     timer = setTimeout(callback, ms);
  116.   };
  117. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement