Commit 68673d01 authored by mercury233's avatar mercury233

fix

parent a61b6982
config.json
/ygocore/
#################
......
{
"ip": "123.45.67.89",
"port": 233,
"version": 4917,
"version": 4918,
"modules": {
"welcome": "YGOPRO Server",
"tips": "http://mercury233.me/ygosrv233/tips.json",
......
......@@ -16,7 +16,7 @@
"underscore": "*",
"underscore.string": "*",
"request": "*",
"bunyan": "*",
"bunyan": "*"
},
"license": "GPLv3",
"main": "ygopro-server.js",
......
......@@ -98,7 +98,7 @@ class Room
#积分
return if @deleted
index = _.indexOf(Room.all, this)
Room.all[index] = null unless index == -1
#Room.all[index] = null unless index == -1
Room.all.splice(index, 1) unless index == -1
@deleted = true
......
......@@ -131,9 +131,6 @@
return;
}
index = _.indexOf(Room.all, this);
if (index !== -1) {
Room.all[index] = null;
}
if (index !== -1) {
Room.all.splice(index, 1);
}
......
......@@ -12,8 +12,6 @@ _ = require 'underscore'
_.str = require 'underscore.string'
_.mixin(_.str.exports());
#Inotify = require('inotify').Inotify
request = require 'request'
bunyan = require 'bunyan'
......@@ -257,13 +255,8 @@ ygopro.stoc_follow 'JOIN_GAME', false, (buffer, info, client, server)->
for w in client.room.watchers
w.write data if w #a WTF fix
#watcher.on 'error', (error)->
watcher.on 'error', (error)->
#log.error "watcher error", error
###
watcher.on 'close', (had_error)->
for w in client.room.ws_watchers
w.close()
###
#登场台词
if settings.modules.dialogues
......@@ -374,14 +367,6 @@ ygopro.stoc_follow 'DUEL_START', false, (buffer, info, client, server)->
client.room.dueling_players = []
for player in client.room.players when player.pos != 7
client.room.dueling_players[player.pos] = player
#if !player.main
#log.error 'WTF', client
#else
#player.deck = mycard.load_card_usages_from_cards(player.main, player.side)
#if !client.room.dueling_players[0] or !client.room.dueling_players[1]
#log.error 'incomplete room', client.room.dueling_players, client.room.players
if settings.modules.tips
ygopro.stoc_send_random_tip(client)
......@@ -448,6 +433,7 @@ if settings.modules.http
istart: if room.started then 'start' else 'wait'
)
response.end("loadroom( " + roomsjson + " );");
# todo: 增加JSONP支持
else if u.query.operation == 'getroomjson'
response.writeHead(200);
......@@ -473,37 +459,3 @@ if settings.modules.http
response.writeHead(404);
response.end();
http_server.listen settings.modules.http.port
#清理90s没活动的房间
###
inotify = new Inotify()
inotify.addWatch
path: 'ygocore/replay',
watch_for: Inotify.IN_CLOSE_WRITE | Inotify.IN_CREATE | Inotify.IN_MODIFY,
callback: (event)->
mask = event.mask
if event.name
port = parseInt path.basename(event.name, '.yrp')
room = Room.find_by_port port
if room
if mask & Inotify.IN_CREATE
else if mask & Inotify.IN_CLOSE_WRITE
fs.unlink path.join('ygocore/replay'), (err)->
else if mask & Inotify.IN_MODIFY
room.alive = true
else
log.error "event without filename"
###
###
setInterval ()->
for room in Room.all
if room.alive
room.alive = false
else
log.info "kill room", room.port
for player in room.players
ygopro.stoc_send_chat(player, "由于长时间没有活动被关闭") unless player.closed
room.process.kill()
, 900000
###
\ No newline at end of file
......@@ -273,7 +273,7 @@
});
return ygopro.ctos_send(watcher, 'HS_TOOBSERVER');
});
return watcher.on('data', function(data) {
watcher.on('data', function(data) {
var j, len, ref, results, w;
client.room.watcher_buffers.push(data);
ref = client.room.watchers;
......@@ -288,12 +288,7 @@
}
return results;
});
/*
watcher.on 'close', (had_error)->
for w in client.room.ws_watchers
w.close()
*/
return watcher.on('error', function(error) {});
}
});
......@@ -595,40 +590,4 @@
http_server.listen(settings.modules.http.port);
}
/*
inotify = new Inotify()
inotify.addWatch
path: 'ygocore/replay',
watch_for: Inotify.IN_CLOSE_WRITE | Inotify.IN_CREATE | Inotify.IN_MODIFY,
callback: (event)->
mask = event.mask
if event.name
port = parseInt path.basename(event.name, '.yrp')
room = Room.find_by_port port
if room
if mask & Inotify.IN_CREATE
else if mask & Inotify.IN_CLOSE_WRITE
fs.unlink path.join('ygocore/replay'), (err)->
else if mask & Inotify.IN_MODIFY
room.alive = true
else
log.error "event without filename"
*/
/*
setInterval ()->
for room in Room.all
if room.alive
room.alive = false
else
log.info "kill room", room.port
for player in room.players
ygopro.stoc_send_chat(player, "由于长时间没有活动被关闭") unless player.closed
room.process.kill()
, 900000
*/
}).call(this);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment