-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
86 lines (77 loc) · 2.13 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
var http = require('http');
var express = require('express');
var Twit = require('twit');
var mongoose = require('mongoose');
var app = express();
var server = app.listen(3000);
var io = require('socket.io').listen(server);
var i=0;
var kullanicilar=[];
var nicknames = {};
var namesUsed = [];
var odalar=[];
mongoose.Promise = global.Promise;
mongoose.connect('mongodb://localhost/oyun', function(err){
if(err) {
console.log("Baglanti hatasi..");
} else {
console.log('MongoDB ye baglandi..');
}
});
var schema = mongoose.Schema({
KullaniciAdi: String,
Skor: String,
tarih: {type: Date, default: Date.now}
});
var DB = mongoose.model('Skorlar', schema);
var T = new Twit({
consumer_key: '',
consumer_secret: '',
access_token: '',
access_token_secret: '',
timeout_ms: 60*1000,
});
app.use(express.static(__dirname + '/public'));
app.get('/', function(req, res){
res.sendfile(__dirname + '/index.html');
});
app.route('/skorlar')
.get(SkorlariGetir);
app.route('/skorlar/:taskId').get(SkorlariGetir);
var Skorlar=mongoose.model('Skorlar');
function SkorlariGetir(req,res){
Skorlar.find({}, function(err, skor) {
if (err)
res.send(err);
res.json(skor);
});
}
var player_id;
var oyuncu;
io.on('connection', function(socket){
console.log('a user connected');
socket.on('disconnect', function(){
});
socket.on('mesaj',function(data){
io.to(data.oda_isim).emit('mesaj',data);
});
socket.on('OdayaGiris',function(data){
console.log(data);
socket.join(data);
});
socket.on('OyunaGiris',function(oda_isim,data){
var oda= io.nsps['/'].adapter.rooms[oda_isim];
console.log(oda);
if(oda.length==2){
io.to(oda_isim).emit('OyunaBasla');
}
});
socket.on('OyunuBitir',function(data){
io.to(data).emit('OyunuBitti');
});
socket.on('twitter_giris',function(data){
T.post('statuses/update', { status: data.GonderKullaniciAdi + ' bir skor yapti : ' + data.Skor }, function(err, data, response) {});
var kayit = new DB({KullaniciAdi: data.GonderKullaniciAdi, Skor: data.Skor});
kayit.save(function(err){});
});
});