Commit 586e1c59 authored by 神楽坂玲奈's avatar 神楽坂玲奈 Committed by Ma

websocket room list

parent a032e47f
...@@ -4,6 +4,7 @@ _.mixin(_.str.exports()); ...@@ -4,6 +4,7 @@ _.mixin(_.str.exports());
spawn = require('child_process').spawn spawn = require('child_process').spawn
spawnSync = require('child_process').spawnSync spawnSync = require('child_process').spawnSync
ygopro = require './ygopro.js' ygopro = require './ygopro.js'
roomlist = require './roomlist'
bunyan = require 'bunyan' bunyan = require 'bunyan'
moment = require 'moment' moment = require 'moment'
#redis = require 'redis' #redis = require 'redis'
...@@ -65,7 +66,7 @@ class Room ...@@ -65,7 +66,7 @@ class Room
bannedplayer.reasons.push(reason) if not _.find bannedplayer.reasons, (bannedreason)-> bannedplayer.reasons.push(reason) if not _.find bannedplayer.reasons, (bannedreason)->
bannedreason==reason bannedreason==reason
bannedplayer.need_tip=true; bannedplayer.need_tip=true;
else else
bannedplayer={"ip": ip, "time": moment(), "count": 1, "reasons": [reason], "need_tip": true} bannedplayer={"ip": ip, "time": moment(), "count": 1, "reasons": [reason], "need_tip": true}
Room.players_banned.push(bannedplayer) Room.players_banned.push(bannedplayer)
log.info("banned", name, ip, reason, bannedplayer.count) log.info("banned", name, ip, reason, bannedplayer.count)
...@@ -78,9 +79,9 @@ class Room ...@@ -78,9 +79,9 @@ class Room
return room return room
else if get_memory_usage()>=90 else if get_memory_usage()>=90
return null return null
else else
return new Room(name) return new Room(name)
@find_or_create_random: (type, player_ip)-> @find_or_create_random: (type, player_ip)->
bannedplayer = _.find Room.players_banned, (bannedplayer)-> bannedplayer = _.find Room.players_banned, (bannedplayer)->
return player_ip==bannedplayer.ip return player_ip==bannedplayer.ip
...@@ -134,7 +135,7 @@ class Room ...@@ -134,7 +135,7 @@ class Room
room_pass = room_name_and_pass[1] room_pass = room_name_and_pass[1]
client_name == room_name and client_pass != room_pass client_name == room_name and client_pass != room_pass
constructor: (name) -> constructor: (name, @hostinfo) ->
@name = name @name = name
@alive = true @alive = true
@players = [] @players = []
...@@ -148,7 +149,7 @@ class Room ...@@ -148,7 +149,7 @@ class Room
@welcome = '' @welcome = ''
Room.all.push this Room.all.push this
@hostinfo = @hostinfo ||=
lflist: 0 lflist: 0
rule: if settings.modules.enable_TCG_as_default then 2 else 0 rule: if settings.modules.enable_TCG_as_default then 2 else 0
mode: 0 mode: 0
...@@ -165,7 +166,7 @@ class Room ...@@ -165,7 +166,7 @@ class Room
else if name[0...2] == 'T#' else if name[0...2] == 'T#'
@hostinfo.mode = 2 @hostinfo.mode = 2
@hostinfo.start_lp = 16000 @hostinfo.start_lp = 16000
else if (param = name.match /^(\d)(\d)(T|F)(T|F)(T|F)(\d+),(\d+),(\d+)/i) else if (param = name.match /^(\d)(\d)(T|F)(T|F)(T|F)(\d+),(\d+),(\d+)/i)
@hostinfo.rule = parseInt(param[1]) @hostinfo.rule = parseInt(param[1])
@hostinfo.mode = parseInt(param[2]) @hostinfo.mode = parseInt(param[2])
...@@ -175,11 +176,11 @@ class Room ...@@ -175,11 +176,11 @@ class Room
@hostinfo.start_lp = parseInt(param[6]) @hostinfo.start_lp = parseInt(param[6])
@hostinfo.start_hand = parseInt(param[7]) @hostinfo.start_hand = parseInt(param[7])
@hostinfo.draw_count = parseInt(param[8]) @hostinfo.draw_count = parseInt(param[8])
else if (((param = name.match /(.+)#/) != null) and ( (param[1].length<=2 and param[1].match(/(S|N|M|T)(0|1|2|T|A)/i)) or (param[1].match(/^(S|N|M|T)(0|1|2|O|T|A)(0|1|O|T)/i)) ) ) else if (((param = name.match /(.+)#/) != null) and ( (param[1].length<=2 and param[1].match(/(S|N|M|T)(0|1|2|T|A)/i)) or (param[1].match(/^(S|N|M|T)(0|1|2|O|T|A)(0|1|O|T)/i)) ) )
rule=param[1].toUpperCase() rule=param[1].toUpperCase()
#log.info "C", rule #log.info "C", rule
switch rule.charAt(0) switch rule.charAt(0)
when "M","1" when "M","1"
@hostinfo.mode = 1 @hostinfo.mode = 1
...@@ -188,7 +189,7 @@ class Room ...@@ -188,7 +189,7 @@ class Room
@hostinfo.start_lp = 16000 @hostinfo.start_lp = 16000
else else
@hostinfo.mode = 0 @hostinfo.mode = 0
switch rule.charAt(1) switch rule.charAt(1)
when "0","O" when "0","O"
@hostinfo.rule = 0 @hostinfo.rule = 0
...@@ -196,104 +197,104 @@ class Room ...@@ -196,104 +197,104 @@ class Room
@hostinfo.rule = 1 @hostinfo.rule = 1
else else
@hostinfo.rule = 2 @hostinfo.rule = 2
switch rule.charAt(2) switch rule.charAt(2)
when "1","T" when "1","T"
@hostinfo.lflist = settings.modules.TCG_banlist_id @hostinfo.lflist = settings.modules.TCG_banlist_id
else else
@hostinfo.lflist = 0 @hostinfo.lflist = 0
if ((param = parseInt(rule.charAt(3).match(/\d/))) >= 0) if ((param = parseInt(rule.charAt(3).match(/\d/))) >= 0)
@hostinfo.time_limit=param*60 @hostinfo.time_limit=param*60
switch rule.charAt(4) switch rule.charAt(4)
when "T","1" when "T","1"
@hostinfo.enable_priority = true @hostinfo.enable_priority = true
else else
@hostinfo.enable_priority = false @hostinfo.enable_priority = false
switch rule.charAt(5) switch rule.charAt(5)
when "T","1" when "T","1"
@hostinfo.no_check_deck = true @hostinfo.no_check_deck = true
else else
@hostinfo.no_check_deck = false @hostinfo.no_check_deck = false
switch rule.charAt(6) switch rule.charAt(6)
when "T","1" when "T","1"
@hostinfo.no_shuffle_deck = true @hostinfo.no_shuffle_deck = true
else else
@hostinfo.no_shuffle_deck = false @hostinfo.no_shuffle_deck = false
if ((param = parseInt(rule.charAt(7).match(/\d/))) > 0) if ((param = parseInt(rule.charAt(7).match(/\d/))) > 0)
@hostinfo.start_lp=param*4000 @hostinfo.start_lp=param*4000
if ((param = parseInt(rule.charAt(8).match(/\d/))) > 0) if ((param = parseInt(rule.charAt(8).match(/\d/))) > 0)
@hostinfo.start_hand=param @hostinfo.start_hand=param
if ((param = parseInt(rule.charAt(9).match(/\d/))) >= 0) if ((param = parseInt(rule.charAt(9).match(/\d/))) >= 0)
@hostinfo.draw_count=param @hostinfo.draw_count=param
else if ((param = name.match /(.+)#/) != null) else if ((param = name.match /(.+)#/) != null)
rule=param[1].toUpperCase() rule=param[1].toUpperCase()
#log.info "233", rule #log.info "233", rule
if (rule.match /(^|,|,)(M|MATCH)(,|,|$)/) if (rule.match /(^|,|,)(M|MATCH)(,|,|$)/)
@hostinfo.mode = 1 @hostinfo.mode = 1
if (rule.match /(^|,|,)(T|TAG)(,|,|$)/) if (rule.match /(^|,|,)(T|TAG)(,|,|$)/)
@hostinfo.mode = 2 @hostinfo.mode = 2
@hostinfo.start_lp = 16000 @hostinfo.start_lp = 16000
if (rule.match /(^|,|,)(TCGONLY|TO)(,|,|$)/) if (rule.match /(^|,|,)(TCGONLY|TO)(,|,|$)/)
@hostinfo.rule = 1 @hostinfo.rule = 1
@hostinfo.lflist = settings.modules.TCG_banlist_id @hostinfo.lflist = settings.modules.TCG_banlist_id
if (rule.match /(^|,|,)(OCGONLY|OO)(,|,|$)/) if (rule.match /(^|,|,)(OCGONLY|OO)(,|,|$)/)
@hostinfo.rule = 0 @hostinfo.rule = 0
if (rule.match /(^|,|,)(OT|TCG)(,|,|$)/) if (rule.match /(^|,|,)(OT|TCG)(,|,|$)/)
@hostinfo.rule = 2 @hostinfo.rule = 2
if (param = rule.match /(^|,|,)LP(\d+)(,|,|$)/) if (param = rule.match /(^|,|,)LP(\d+)(,|,|$)/)
start_lp = parseInt(param[2]) start_lp = parseInt(param[2])
if (start_lp <= 0) then start_lp = 1 if (start_lp <= 0) then start_lp = 1
if (start_lp >= 99999) then start_lp = 99999 if (start_lp >= 99999) then start_lp = 99999
@hostinfo.start_lp = start_lp @hostinfo.start_lp = start_lp
if (param = rule.match /(^|,|,)(TIME|TM|TI)(\d+)(,|,|$)/) if (param = rule.match /(^|,|,)(TIME|TM|TI)(\d+)(,|,|$)/)
time_limit = parseInt(param[3]) time_limit = parseInt(param[3])
if (time_limit < 0) then time_limit = 180 if (time_limit < 0) then time_limit = 180
if (time_limit >= 1 and time_limit <= 60) then time_limit = time_limit*60 if (time_limit >= 1 and time_limit <= 60) then time_limit = time_limit*60
if (time_limit >= 999) then time_limit = 999 if (time_limit >= 999) then time_limit = 999
@hostinfo.time_limit = time_limit @hostinfo.time_limit = time_limit
if (param = rule.match /(^|,|,)(START|ST)(\d+)(,|,|$)/) if (param = rule.match /(^|,|,)(START|ST)(\d+)(,|,|$)/)
start_hand = parseInt(param[3]) start_hand = parseInt(param[3])
if (start_hand <= 0) then start_hand = 1 if (start_hand <= 0) then start_hand = 1
if (start_hand >= 40) then start_hand = 40 if (start_hand >= 40) then start_hand = 40
@hostinfo.start_hand = start_hand @hostinfo.start_hand = start_hand
if (param = rule.match /(^|,|,)(DRAW|DR)(\d+)(,|,|$)/) if (param = rule.match /(^|,|,)(DRAW|DR)(\d+)(,|,|$)/)
draw_count = parseInt(param[3]) draw_count = parseInt(param[3])
if (draw_count >= 35) then draw_count = 35 if (draw_count >= 35) then draw_count = 35
@hostinfo.draw_count = draw_count @hostinfo.draw_count = draw_count
if (param = rule.match /(^|,|,)(LFLIST|LF)(\d+)(,|,|$)/) if (param = rule.match /(^|,|,)(LFLIST|LF)(\d+)(,|,|$)/)
lflist = parseInt(param[3])-1 lflist = parseInt(param[3])-1
@hostinfo.lflist = lflist @hostinfo.lflist = lflist
if (rule.match /(^|,|,)(NOLFLIST|NF)(,|,|$)/) if (rule.match /(^|,|,)(NOLFLIST|NF)(,|,|$)/)
@hostinfo.lflist = -1 @hostinfo.lflist = -1
if (rule.match /(^|,|,)(NOUNIQUE|NU)(,|,|$)/) if (rule.match /(^|,|,)(NOUNIQUE|NU)(,|,|$)/)
@hostinfo.rule = 3 @hostinfo.rule = 3
if (rule.match /(^|,|,)(NOCHECK|NC)(,|,|$)/) if (rule.match /(^|,|,)(NOCHECK|NC)(,|,|$)/)
@hostinfo.no_check_deck = true @hostinfo.no_check_deck = true
if (rule.match /(^|,|,)(NOSHUFFLE|NS)(,|,|$)/) if (rule.match /(^|,|,)(NOSHUFFLE|NS)(,|,|$)/)
@hostinfo.no_shuffle_deck = true @hostinfo.no_shuffle_deck = true
if (rule.match /(^|,|,)(IGPRIORITY|PR)(,|,|$)/) if (rule.match /(^|,|,)(IGPRIORITY|PR)(,|,|$)/)
@hostinfo.enable_priority = true @hostinfo.enable_priority = true
...@@ -308,6 +309,7 @@ class Room ...@@ -308,6 +309,7 @@ class Room
@process.stdout.setEncoding('utf8') @process.stdout.setEncoding('utf8')
@process.stdout.once 'data', (data)=> @process.stdout.once 'data', (data)=>
@established = true @established = true
roomlist.create(this)
@port = parseInt data @port = parseInt data
_.each @players, (player)=> _.each @players, (player)=>
player.server.connect @port, '127.0.0.1',=> player.server.connect @port, '127.0.0.1',=>
...@@ -350,8 +352,9 @@ class Room ...@@ -350,8 +352,9 @@ class Room
index = _.indexOf(Room.all, this) 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 Room.all.splice(index, 1) unless index == -1
roomlist.delete @name if !@private and !@started and @established
return return
get_playing_player: -> get_playing_player: ->
playing_player=[] playing_player=[]
_.each @players, (player)=> _.each @players, (player)=>
...@@ -380,6 +383,7 @@ class Room ...@@ -380,6 +383,7 @@ class Room
Room.players_oppentlist[client.remoteAddress] = null Room.players_oppentlist[client.remoteAddress] = null
if @established if @established
roomlist.update(this) unless @started
client.server.connect @port, '127.0.0.1', -> client.server.connect @port, '127.0.0.1', ->
client.server.write buffer for buffer in client.pre_establish_buffers client.server.write buffer for buffer in client.pre_establish_buffers
client.established = true client.established = true
...@@ -401,6 +405,7 @@ class Room ...@@ -401,6 +405,7 @@ class Room
Room.ban_player(client.name, client.ip, "强退") Room.ban_player(client.name, client.ip, "强退")
if @players.length if @players.length
ygopro.stoc_send_chat_to_room this, "#{client.name} #{'离开了游戏'}#{if error then ": #{error}" else ''}" ygopro.stoc_send_chat_to_room this, "#{client.name} #{'离开了游戏'}#{if error then ": #{error}" else ''}"
roomlist.update(this) unless @started
#client.room = null #client.room = null
else else
@process.kill() @process.kill()
......
// Generated by CoffeeScript 1.10.0 // Generated by CoffeeScript 1.9.3
(function() { (function() {
var Room, _, bunyan, get_memory_usage, log, moment, settings, spawn, spawnSync, ygopro; var Room, _, bunyan, get_memory_usage, log, moment, roomlist, settings, spawn, spawnSync, ygopro;
_ = require('underscore'); _ = require('underscore');
...@@ -14,6 +14,8 @@ ...@@ -14,6 +14,8 @@
ygopro = require('./ygopro.js'); ygopro = require('./ygopro.js');
roomlist = require('./roomlist');
bunyan = require('bunyan'); bunyan = require('bunyan');
moment = require('moment'); moment = require('moment');
...@@ -184,8 +186,9 @@ ...@@ -184,8 +186,9 @@
}); });
}; };
function Room(name) { function Room(name, hostinfo) {
var draw_count, error1, lflist, param, rule, start_hand, start_lp, time_limit; var draw_count, lflist, param, rule, start_hand, start_lp, time_limit;
this.hostinfo = hostinfo;
this.name = name; this.name = name;
this.alive = true; this.alive = true;
this.players = []; this.players = [];
...@@ -198,7 +201,7 @@ ...@@ -198,7 +201,7 @@
this.random_type = ''; this.random_type = '';
this.welcome = ''; this.welcome = '';
Room.all.push(this); Room.all.push(this);
this.hostinfo = { this.hostinfo || (this.hostinfo = {
lflist: 0, lflist: 0,
rule: settings.modules.enable_TCG_as_default ? 2 : 0, rule: settings.modules.enable_TCG_as_default ? 2 : 0,
mode: 0, mode: 0,
...@@ -209,7 +212,7 @@ ...@@ -209,7 +212,7 @@
start_hand: 5, start_hand: 5,
draw_count: 1, draw_count: 1,
time_limit: 180 time_limit: 180
}; });
if (name.slice(0, 2) === 'M#') { if (name.slice(0, 2) === 'M#') {
this.hostinfo.mode = 1; this.hostinfo.mode = 1;
} else if (name.slice(0, 2) === 'T#') { } else if (name.slice(0, 2) === 'T#') {
...@@ -391,6 +394,7 @@ ...@@ -391,6 +394,7 @@
this.process.stdout.once('data', (function(_this) { this.process.stdout.once('data', (function(_this) {
return function(data) { return function(data) {
_this.established = true; _this.established = true;
roomlist.create(_this);
_this.port = parseInt(data); _this.port = parseInt(data);
_.each(_this.players, function(player) { _.each(_this.players, function(player) {
player.server.connect(_this.port, '127.0.0.1', function() { player.server.connect(_this.port, '127.0.0.1', function() {
...@@ -406,7 +410,7 @@ ...@@ -406,7 +410,7 @@
}); });
}; };
})(this)); })(this));
} catch (error1) { } catch (_error) {
this.error = "建立房间失败,请重试"; this.error = "建立房间失败,请重试";
} }
} }
...@@ -447,6 +451,9 @@ ...@@ -447,6 +451,9 @@
if (index !== -1) { if (index !== -1) {
Room.all.splice(index, 1); Room.all.splice(index, 1);
} }
if (!this["private"] && !this.started && this.established) {
roomlist["delete"](this.name);
}
}; };
Room.prototype.get_playing_player = function() { Room.prototype.get_playing_player = function() {
...@@ -489,6 +496,9 @@ ...@@ -489,6 +496,9 @@
} }
} }
if (this.established) { if (this.established) {
if (!this.started) {
roomlist.update(this);
}
client.server.connect(this.port, '127.0.0.1', function() { client.server.connect(this.port, '127.0.0.1', function() {
var buffer, i, len, ref; var buffer, i, len, ref;
ref = client.pre_establish_buffers; ref = client.pre_establish_buffers;
...@@ -520,6 +530,9 @@ ...@@ -520,6 +530,9 @@
} }
if (this.players.length) { if (this.players.length) {
ygopro.stoc_send_chat_to_room(this, client.name + " " + '离开了游戏' + (error ? ": " + error : '')); ygopro.stoc_send_chat_to_room(this, client.name + " " + '离开了游戏' + (error ? ": " + error : ''));
if (!this.started) {
roomlist.update(this);
}
} else { } else {
this.process.kill(); this.process.kill();
this["delete"](); this["delete"]();
......
WebSocketServer = require('ws').Server;
server = null
room_data = (room)->
id: room.name,
title: room.title,
user: {username: room.username}
users: ({username: client.name, position: client.pos} for client in room.players),
options: room.hostinfo
init = (http_server, Room)->
server = new WebSocketServer
server: http_server
server.on 'connection', (connection) ->
connection.send JSON.stringify
event: 'init'
data: room_data(room) for room in Room.all when room.established and !room.private and !room.started
create = (room)->
broadcast('create', room_data(room))
update = (room)->
broadcast('update', room_data(room))
_delete = (room_id)->
broadcast('delete', room_id)
broadcast = (event, data)->
return if !server
message = JSON.stringify
event: event
data: data
for connection in server.clients
try
connection.send message
module.exports =
init: init
create: create
update: update
delete: _delete
\ No newline at end of file
// Generated by CoffeeScript 1.9.3
(function() {
var WebSocketServer, _delete, broadcast, create, init, room_data, server, update;
WebSocketServer = require('ws').Server;
server = null;
room_data = function(room) {
var client;
return {
id: room.name,
title: room.title,
user: {
username: room.username
},
users: (function() {
var i, len, ref, results;
ref = room.players;
results = [];
for (i = 0, len = ref.length; i < len; i++) {
client = ref[i];
results.push({
username: client.name,
position: client.pos
});
}
return results;
})(),
options: room.hostinfo
};
};
init = function(http_server, Room) {
server = new WebSocketServer({
server: http_server
});
return server.on('connection', function(connection) {
var room;
return connection.send(JSON.stringify({
event: 'init',
data: (function() {
var i, len, ref, results;
ref = Room.all;
results = [];
for (i = 0, len = ref.length; i < len; i++) {
room = ref[i];
if (room.established && !room["private"] && !room.started) {
results.push(room_data(room));
}
}
return results;
})()
}));
});
};
create = function(room) {
return broadcast('create', room_data(room));
};
update = function(room) {
return broadcast('update', room_data(room));
};
_delete = function(room_id) {
return broadcast('delete', room_id);
};
broadcast = function(event, data) {
var connection, i, len, message, ref, results;
if (!server) {
return;
}
message = JSON.stringify({
event: event,
data: data
});
ref = server.clients;
results = [];
for (i = 0, len = ref.length; i < len; i++) {
connection = ref[i];
try {
results.push(connection.send(message));
} catch (_error) {}
}
return results;
};
module.exports = {
init: init,
create: create,
update: update,
"delete": _delete
};
}).call(this);
...@@ -34,7 +34,7 @@ settings.version = parseInt(fs.readFileSync('ygopro/gframe/game.cpp', 'utf8').ma ...@@ -34,7 +34,7 @@ settings.version = parseInt(fs.readFileSync('ygopro/gframe/game.cpp', 'utf8').ma
#组件 #组件
ygopro = require './ygopro.js' ygopro = require './ygopro.js'
Room = require './room.js' Room = require './room.js'
roomlist = require './roomlist.js'
#debug模式 端口号+1 #debug模式 端口号+1
debug = false debug = false
...@@ -398,8 +398,6 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)-> ...@@ -398,8 +398,6 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)->
options = { options = {
lflist: 0 lflist: 0
time_limit: 180 time_limit: 180
title: info.pass.slice(8)
private: action == 2
rule: (opt1 >> 5) & 3 rule: (opt1 >> 5) & 3
mode: (opt1 >> 3) & 3 mode: (opt1 >> 3) & 3
enable_priority: !!((opt1 >> 2) & 1) enable_priority: !!((opt1 >> 2) & 1)
...@@ -410,6 +408,8 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)-> ...@@ -410,6 +408,8 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)->
draw_count: opt3 & 0xF draw_count: opt3 & 0xF
} }
room = new Room(name, options) room = new Room(name, options)
room.title = info.pass.slice(8)
room.private = action == 2
when 3 when 3
name = info.pass.slice(8) name = info.pass.slice(8)
room = Room.find_by_name(name) room = Room.find_by_name(name)
...@@ -697,6 +697,7 @@ ygopro.stoc_follow 'DUEL_START', false, (buffer, info, client, server)-> ...@@ -697,6 +697,7 @@ ygopro.stoc_follow 'DUEL_START', false, (buffer, info, client, server)->
return unless client.room return unless client.room
unless client.room.started #first start unless client.room.started #first start
client.room.started = true client.room.started = true
roomlist.delete room.name unless room.private
#client.room.duels = [] #client.room.duels = []
client.room.dueling_players = [] client.room.dueling_players = []
for player in client.room.players when player.pos != 7 for player in client.room.players when player.pos != 7
...@@ -869,10 +870,5 @@ if settings.modules.http ...@@ -869,10 +870,5 @@ if settings.modules.http
cert: fs.readFileSync(settings.modules.http.ssl.cert) cert: fs.readFileSync(settings.modules.http.ssl.cert)
key: fs.readFileSync(settings.modules.http.ssl.key) key: fs.readFileSync(settings.modules.http.ssl.key)
https_server = https.createServer(options, requestListener) https_server = https.createServer(options, requestListener)
WebSocketServer = require('ws').Server roomlist.init https_server, Room
websocket_server = new WebSocketServer
server: https_server
websocket_server.on 'connection', (connection) ->
console.log(room for room in Room.all when room.established)
https_server.listen settings.modules.http.ssl.port https_server.listen settings.modules.http.ssl.port
\ No newline at end of file
// Generated by CoffeeScript 1.9.3 // Generated by CoffeeScript 1.9.3
(function() { (function() {
var Graveyard, Room, WebSocketServer, _, bunyan, crypto, debug, dialogues, execFile, fs, http, http_server, https, https_server, log, moment, net, options, os, path, request, requestListener, settings, tips, tribute, url, wait_room_start, websocket_server, ygopro; var Graveyard, Room, _, bunyan, crypto, debug, dialogues, execFile, fs, http, http_server, https, https_server, log, moment, net, options, os, path, request, requestListener, roomlist, settings, tips, tribute, url, wait_room_start, ygopro;
net = require('net'); net = require('net');
...@@ -44,6 +44,8 @@ ...@@ -44,6 +44,8 @@
Room = require('./room.js'); Room = require('./room.js');
roomlist = require('./roomlist.js');
debug = false; debug = false;
log = null; log = null;
...@@ -425,8 +427,6 @@ ...@@ -425,8 +427,6 @@
options = { options = {
lflist: 0, lflist: 0,
time_limit: 180, time_limit: 180,
title: info.pass.slice(8),
"private": action === 2,
rule: (opt1 >> 5) & 3, rule: (opt1 >> 5) & 3,
mode: (opt1 >> 3) & 3, mode: (opt1 >> 3) & 3,
enable_priority: !!((opt1 >> 2) & 1), enable_priority: !!((opt1 >> 2) & 1),
...@@ -437,6 +437,8 @@ ...@@ -437,6 +437,8 @@
draw_count: opt3 & 0xF draw_count: opt3 & 0xF
}; };
room = new Room(name, options); room = new Room(name, options);
room.title = info.pass.slice(8);
room["private"] = action === 2;
break; break;
case 3: case 3:
name = info.pass.slice(8); name = info.pass.slice(8);
...@@ -786,6 +788,9 @@ ...@@ -786,6 +788,9 @@
} }
if (!client.room.started) { if (!client.room.started) {
client.room.started = true; client.room.started = true;
if (!room["private"]) {
roomlist["delete"](room.name);
}
client.room.dueling_players = []; client.room.dueling_players = [];
ref = client.room.players; ref = client.room.players;
for (k = 0, len = ref.length; k < len; k++) { for (k = 0, len = ref.length; k < len; k++) {
...@@ -1034,25 +1039,7 @@ ...@@ -1034,25 +1039,7 @@
key: fs.readFileSync(settings.modules.http.ssl.key) key: fs.readFileSync(settings.modules.http.ssl.key)
}; };
https_server = https.createServer(options, requestListener); https_server = https.createServer(options, requestListener);
WebSocketServer = require('ws').Server; roomlist.init(https_server, Room);
websocket_server = new WebSocketServer({
server: https_server
});
websocket_server.on('connection', function(connection) {
var room;
return console.log((function() {
var k, len, ref, results;
ref = Room.all;
results = [];
for (k = 0, len = ref.length; k < len; k++) {
room = ref[k];
if (room.established) {
results.push(room);
}
}
return results;
})());
});
https_server.listen(settings.modules.http.ssl.port); https_server.listen(settings.modules.http.ssl.port);
} }
} }
......
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