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

mycard auth and ssl support

parent 7e28ce74
...@@ -9,12 +9,18 @@ ...@@ -9,12 +9,18 @@
"dialogues": "http://mercury233.me/ygosrv233/dialogues.json", "dialogues": "http://mercury233.me/ygosrv233/dialogues.json",
"redis_port": 6379, "redis_port": 6379,
"enable_random_duel": false, "enable_random_duel": false,
"mycard_auth": "https://forum.touhou.cc",
"post_start_watching": true, "post_start_watching": true,
"TCG_banlist_id": 8, "TCG_banlist_id": 8,
"enable_TCG_as_default": false, "enable_TCG_as_default": false,
"http": { "http": {
"port": 7922, "port": 7922,
"password": "123456" "password": "123456",
"ssl": {
"port": 7923,
"cert": "/etc/ssl/ygopro-server.crt",
"key": "/etc/ssl/ygopro-server.key"
}
} }
} }
} }
...@@ -15,7 +15,8 @@ ...@@ -15,7 +15,8 @@
"request": "latest", "request": "latest",
"moment": "latest", "moment": "latest",
"sqlite3": "latest", "sqlite3": "latest",
"bunyan": "latest" "bunyan": "latest",
"ws": "latest"
}, },
"license": "AGPL-3.0", "license": "AGPL-3.0",
"scripts": { "scripts": {
......
...@@ -5,6 +5,7 @@ url = require 'url' ...@@ -5,6 +5,7 @@ url = require 'url'
path = require 'path' path = require 'path'
fs = require 'fs' fs = require 'fs'
os = require 'os' os = require 'os'
crypto = require 'crypto'
execFile = require('child_process').execFile execFile = require('child_process').execFile
#三方库 #三方库
...@@ -46,7 +47,7 @@ else ...@@ -46,7 +47,7 @@ else
log = bunyan.createLogger name: "mycard" log = bunyan.createLogger name: "mycard"
#定时清理关闭的连接 #定时清理关闭的连接
Graveyard = [] Graveyard = []
tribute = (socket) -> tribute = (socket) ->
setTimeout ((socket)-> Graveyard.push(socket);return)(socket), 3000 setTimeout ((socket)-> Graveyard.push(socket);return)(socket), 3000
...@@ -66,7 +67,7 @@ setInterval ()-> ...@@ -66,7 +67,7 @@ setInterval ()->
net.createServer (client) -> net.createServer (client) ->
server = new net.Socket() server = new net.Socket()
client.server = server client.server = server
client.setTimeout(300000) #5分钟 client.setTimeout(300000) #5分钟
#释放处理 #释放处理
...@@ -140,9 +141,9 @@ net.createServer (client) -> ...@@ -140,9 +141,9 @@ net.createServer (client) ->
client.room.watcher.write data client.room.watcher.write data
else else
ctos_buffer = Buffer.concat([ctos_buffer, data], ctos_buffer.length + data.length) #buffer的错误使用方式,好孩子不要学 ctos_buffer = Buffer.concat([ctos_buffer, data], ctos_buffer.length + data.length) #buffer的错误使用方式,好孩子不要学
datas = [] datas = []
looplimit = 0 looplimit = 0
while true while true
...@@ -176,7 +177,7 @@ net.createServer (client) -> ...@@ -176,7 +177,7 @@ net.createServer (client) ->
ctos_proto = 0 ctos_proto = 0
else else
break break
looplimit++ looplimit++
#log.info(looplimit) #log.info(looplimit)
if looplimit>800 if looplimit>800
...@@ -201,7 +202,7 @@ net.createServer (client) -> ...@@ -201,7 +202,7 @@ net.createServer (client) ->
#unless ygopro.stoc_follows[stoc_proto] and ygopro.stoc_follows[stoc_proto].synchronous #unless ygopro.stoc_follows[stoc_proto] and ygopro.stoc_follows[stoc_proto].synchronous
client.write data client.write data
looplimit = 0 looplimit = 0
while true while true
...@@ -232,7 +233,7 @@ net.createServer (client) -> ...@@ -232,7 +233,7 @@ net.createServer (client) ->
stoc_proto = 0 stoc_proto = 0
else else
break break
looplimit++ looplimit++
#log.info(looplimit) #log.info(looplimit)
if looplimit>800 if looplimit>800
...@@ -265,7 +266,7 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)-> ...@@ -265,7 +266,7 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)->
code: 2 code: 2
} }
client.end() client.end()
### ###
else if info.pass.toUpperCase()=="R" else if info.pass.toUpperCase()=="R"
ygopro.stoc_send_chat(client,"以下是您近期的云录像,密码处输入 R#录像编号 即可观看", 14) ygopro.stoc_send_chat(client,"以下是您近期的云录像,密码处输入 R#录像编号 即可观看", 14)
...@@ -316,7 +317,123 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)-> ...@@ -316,7 +317,123 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)->
code: 2 code: 2
} }
client.end() client.end()
else if info.pass.length and settings.modules.mycard_auth
ygopro.stoc_send_chat(client,'正在读取用户信息...', 11)
request
baseUrl: settings.modules.mycard_auth,
url: '/users/' + client.name + '.json'
qs:
api_key: '69675c315dfae3d7224688f2c56cf7d3f5016e7cf63f289d945709f11528b02e',
api_username: client.name,
skip_track_visit: true
json: true
, (error, response, body)->
if info.pass.length <= 8
ygopro.stoc_send_chat(client,'主机密码不正确 (Invalid Length)', 11)
ygopro.stoc_send client, 'ERROR_MSG',{
msg: 1
code: 2
}
client.end()
return
buffer = new Buffer(info.pass[0...8], 'base64')
check = (buf)->
checksum = 0
for i in [0...buf.length]
checksum += buf.readUInt8(i)
(checksum & 0xFF) == 0
if body and body.user
secret = body.user.id % 65535 + 1;
decrypted_buffer = new Buffer(6)
for i in [0,2,4]
decrypted_buffer.writeUInt16LE(buffer.readUInt16LE(i) ^ secret, i)
if check(decrypted_buffer)
buffer = decrypted_buffer
# buffer != decrypted_buffer ==> auth failed
if !check(buffer)
ygopro.stoc_send_chat(client,'主机密码不正确 (Checksum Failed)', 11)
ygopro.stoc_send client, 'ERROR_MSG',{
msg: 1
code: 2
}
client.end()
return
action = buffer.readUInt8(1) >> 4
if buffer != decrypted_buffer and action in [1,2,4]
ygopro.stoc_send_chat(client,'主机密码不正确 (Unauthorized)', 11)
ygopro.stoc_send client, 'ERROR_MSG',{
msg: 1
code: 2
}
client.end()
return
# 1 create public room
# 2 create private room
# 3 join room
# 4 join match
switch action
when 1,2
name = crypto.createHash('md5').update(info.pass + client.name).digest('base64')[0...10].replace('+','-').replace('/', '_');
if Room.find_by_name(name)
ygopro.stoc_send_chat(client,'主机密码不正确 (Already Existed)', 11)
ygopro.stoc_send client, 'ERROR_MSG',{
msg: 1
code: 2
}
client.end()
return
opt1 = buffer.readUInt8(2)
opt2 = buffer.readUInt8(3)
opt3 = buffer.readUInt8(5)
options = {
lflist: 0
time_limit: 180
title: info.pass.slice(8)
private: action == 2
rule: (opt1 >> 5) & 3
mode: (opt1 >> 3) & 3
enable_priority: !!((opt1 >> 2) & 1)
no_check_deck: !!((opt1 >> 1) & 1)
no_shuffle_deck: !!(opt1 & 1)
start_lp: opt2
start_hand: opt3 >> 4
draw_count: opt3 & 0xF
}
room = new Room(name, options)
when 3
name = info.pass.slice(8)
room = Room.find_by_name(name)
if(!room)
ygopro.stoc_send_chat(client,'主机密码不正确 (Not Found)', 11)
ygopro.stoc_send client, 'ERROR_MSG',{
msg: 1
code: 2
}
client.end()
return
when 4
room = Room.find_or_create_by_name('M#' + info.pass.slice(8))
else
ygopro.stoc_send_chat(client,'主机密码不正确 (Invalid Action)', 11)
ygopro.stoc_send client, 'ERROR_MSG',{
msg: 1
code: 2
}
client.end()
return
client.room = room
client.room.connect(client)
else if info.pass.length && !Room.validate(info.pass) else if info.pass.length && !Room.validate(info.pass)
#ygopro.stoc_send client, 'ERROR_MSG',{ #ygopro.stoc_send client, 'ERROR_MSG',{
# msg: 1 # msg: 1
...@@ -354,7 +471,7 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)-> ...@@ -354,7 +471,7 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)->
code: 2 code: 2
} }
client.end() client.end()
else else
#log.info 'join_game',info.pass, client.name #log.info 'join_game',info.pass, client.name
room = Room.find_or_create_by_name(info.pass, client.remoteAddress) room = Room.find_or_create_by_name(info.pass, client.remoteAddress)
...@@ -414,7 +531,7 @@ ygopro.stoc_follow 'JOIN_GAME', false, (buffer, info, client, server)-> ...@@ -414,7 +531,7 @@ ygopro.stoc_follow 'JOIN_GAME', false, (buffer, info, client, server)->
} }
ygopro.ctos_send watcher, 'HS_TOOBSERVER' ygopro.ctos_send watcher, 'HS_TOOBSERVER'
return return
watcher.on 'data', (data)-> watcher.on 'data', (data)->
return unless client.room return unless client.room
client.room.watcher_buffers.push data client.room.watcher_buffers.push data
...@@ -445,12 +562,12 @@ if settings.modules.dialogues ...@@ -445,12 +562,12 @@ if settings.modules.dialogues
ygopro.stoc_follow 'GAME_MSG', false, (buffer, info, client, server)-> ygopro.stoc_follow 'GAME_MSG', false, (buffer, info, client, server)->
msg = buffer.readInt8(0) msg = buffer.readInt8(0)
if msg>=10 and msg<30 #SELECT开头的消息 if msg>=10 and msg<30 #SELECT开头的消息
client.room.waiting_for_player=client client.room.waiting_for_player=client
client.room.last_active_time=moment() client.room.last_active_time=moment()
#log.info("#{ygopro.constants.MSG[msg]}等待#{client.room.waiting_for_player.name}") #log.info("#{ygopro.constants.MSG[msg]}等待#{client.room.waiting_for_player.name}")
#log.info 'MSG', ygopro.constants.MSG[msg] #log.info 'MSG', ygopro.constants.MSG[msg]
if ygopro.constants.MSG[msg] == 'START' if ygopro.constants.MSG[msg] == 'START'
playertype = buffer.readUInt8(1) playertype = buffer.readUInt8(1)
...@@ -466,7 +583,7 @@ ygopro.stoc_follow 'GAME_MSG', false, (buffer, info, client, server)-> ...@@ -466,7 +583,7 @@ ygopro.stoc_follow 'GAME_MSG', false, (buffer, info, client, server)->
#log.info {winner: pos, reason: reason} #log.info {winner: pos, reason: reason}
client.room.duels.push {winner: pos, reason: reason} client.room.duels.push {winner: pos, reason: reason}
### ###
#lp跟踪 #lp跟踪
if ygopro.constants.MSG[msg] == 'DAMAGE' and client.is_host if ygopro.constants.MSG[msg] == 'DAMAGE' and client.is_host
pos = buffer.readUInt8(1) pos = buffer.readUInt8(1)
...@@ -605,22 +722,22 @@ ygopro.ctos_follow 'CHAT', true, (buffer, info, client, server)-> ...@@ -605,22 +722,22 @@ ygopro.ctos_follow 'CHAT', true, (buffer, info, client, server)->
#log.warn 'ping', stdout #log.warn 'ping', stdout
ygopro.stoc_send_chat_to_room client.room, stdout ygopro.stoc_send_chat_to_room client.room, stdout
return return
when '/help' when '/help'
ygopro.stoc_send_chat(client,"YGOSrv233 指令帮助") ygopro.stoc_send_chat(client,"YGOSrv233 指令帮助")
ygopro.stoc_send_chat(client,"/help 显示这个帮助信息") ygopro.stoc_send_chat(client,"/help 显示这个帮助信息")
ygopro.stoc_send_chat(client,"/roomname 显示当前房间的名字") ygopro.stoc_send_chat(client,"/roomname 显示当前房间的名字")
ygopro.stoc_send_chat(client,"/tip 显示一条提示") if settings.modules.tips ygopro.stoc_send_chat(client,"/tip 显示一条提示") if settings.modules.tips
when '/tip' when '/tip'
ygopro.stoc_send_random_tip(client) if settings.modules.tips ygopro.stoc_send_random_tip(client) if settings.modules.tips
when '/roomname' when '/roomname'
ygopro.stoc_send_chat(client,"您当前的房间名是 " + client.room.name) if client.room ygopro.stoc_send_chat(client,"您当前的房间名是 " + client.room.name) if client.room
when '/test' when '/test'
ygopro.stoc_send_hint_card_to_room(client.room, 2333365) ygopro.stoc_send_hint_card_to_room(client.room, 2333365)
return cancel return cancel
ygopro.ctos_follow 'UPDATE_DECK', false, (buffer, info, client, server)-> ygopro.ctos_follow 'UPDATE_DECK', false, (buffer, info, client, server)->
...@@ -656,7 +773,7 @@ ygopro.stoc_follow 'SELECT_HAND', false, (buffer, info, client, server)-> ...@@ -656,7 +773,7 @@ ygopro.stoc_follow 'SELECT_HAND', false, (buffer, info, client, server)->
client.room.waiting_for_player2=client client.room.waiting_for_player2=client
client.room.last_active_time=moment().subtract(settings.modules.hang_timeout-19, 's') client.room.last_active_time=moment().subtract(settings.modules.hang_timeout-19, 's')
return return
ygopro.stoc_follow 'SELECT_TP', false, (buffer, info, client, server)-> ygopro.stoc_follow 'SELECT_TP', false, (buffer, info, client, server)->
return unless client.room and client.room.random_type return unless client.room and client.room.random_type
client.room.waiting_for_player=client client.room.waiting_for_player=client
...@@ -679,66 +796,83 @@ setInterval ()-> ...@@ -679,66 +796,83 @@ setInterval ()->
#http #http
if settings.modules.http if settings.modules.http
http_server = http.createServer (request, response)->
parseQueryString = true
u = url.parse(request.url, parseQueryString)
pass_validated = u.query.pass == settings.modules.http.password
if u.pathname == '/api/getrooms'
if u.query.pass and !pass_validated
response.writeHead(200);
response.end(u.query.callback+'( {"rooms":[{"roomid":"0","roomname":"密码错误","needpass":"true"}]} );')
else
response.writeHead(200);
roomsjson = JSON.stringify rooms: (for room in Room.all when room.established
pid: room.process.pid.toString(),
roomid: room.port.toString(),
roomname: if pass_validated then room.name else room.name.split('$',2)[0],
needpass: (room.name.indexOf('$') != -1).toString(),
users: (for player in room.players when player.pos?
id: (-1).toString(),
name: player.name,
pos: player.pos
),
istart: if room.started then 'start' else 'wait'
)
response.end(u.query.callback+"( " + roomsjson + " );")
else if u.pathname == '/api/message'
if !pass_validated
response.writeHead(200);
response.end(u.query.callback+"( '密码错误', 0 );");
return
if u.query.shout requestListener = (request, response)->
for room in Room.all parseQueryString = true
ygopro.stoc_send_chat_to_room(room, u.query.shout, 16) u = url.parse(request.url, parseQueryString)
response.writeHead(200) pass_validated = u.query.pass == settings.modules.http.password
response.end(u.query.callback+"( 'shout ok', '" + u.query.shout + "' );")
if u.pathname == '/api/getrooms'
else if u.query.stop if u.query.pass and !pass_validated
if u.query.stop == 'false' response.writeHead(200);
u.query.stop=false response.end(u.query.callback+'( {"rooms":[{"roomid":"0","roomname":"密码错误","needpass":"true"}]} );')
settings.modules.stop = u.query.stop else
response.writeHead(200) response.writeHead(200);
response.end(u.query.callback+"( 'stop ok', '" + u.query.stop + "' );") roomsjson = JSON.stringify rooms: (for room in Room.all when room.established
pid: room.process.pid.toString(),
else if u.query.welcome roomid: room.port.toString(),
settings.modules.welcome = u.query.welcome roomname: if pass_validated then room.name else room.name.split('$',2)[0],
response.writeHead(200) needpass: (room.name.indexOf('$') != -1).toString(),
response.end(u.query.callback+"( 'welcome ok', '" + u.query.welcome + "' );") users: (for player in room.players when player.pos?
id: (-1).toString(),
else if u.query.ban name: player.name,
settings.BANNED_user.push(u.query.ban) pos: player.pos
response.writeHead(200) ),
response.end(u.query.callback+"( 'ban ok', '" + u.query.ban + "' );") istart: if room.started then 'start' else 'wait'
)
else response.end(u.query.callback+"( " + roomsjson + " );")
response.writeHead(404);
response.end(); else if u.pathname == '/api/message'
if !pass_validated
response.writeHead(200);
response.end(u.query.callback+"( '密码错误', 0 );");
return
if u.query.shout
for room in Room.all
ygopro.stoc_send_chat_to_room(room, u.query.shout, 16)
response.writeHead(200)
response.end(u.query.callback+"( 'shout ok', '" + u.query.shout + "' );")
else if u.query.stop
if u.query.stop == 'false'
u.query.stop=false
settings.modules.stop = u.query.stop
response.writeHead(200)
response.end(u.query.callback+"( 'stop ok', '" + u.query.stop + "' );")
else if u.query.welcome
settings.modules.welcome = u.query.welcome
response.writeHead(200)
response.end(u.query.callback+"( 'welcome ok', '" + u.query.welcome + "' );")
else if u.query.ban
settings.BANNED_user.push(u.query.ban)
response.writeHead(200)
response.end(u.query.callback+"( 'ban ok', '" + u.query.ban + "' );")
else else
response.writeHead(404); response.writeHead(404);
response.end(); response.end();
return
else
response.writeHead(404);
response.end();
return
http_server = http.createServer(requestListener)
http_server.listen settings.modules.http.port http_server.listen settings.modules.http.port
if settings.modules.http.ssl
https = require 'https'
options =
cert: fs.readFileSync(settings.modules.http.ssl.cert)
key: fs.readFileSync(settings.modules.http.ssl.key)
https_server = https.createServer(options, requestListener)
WebSocketServer = require('ws').Server
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
\ No newline at end of file
// Generated by CoffeeScript 1.9.3 // Generated by CoffeeScript 1.9.3
(function() { (function() {
var Graveyard, Room, _, bunyan, debug, dialogues, execFile, fs, http, http_server, log, moment, net, os, path, request, settings, tips, tribute, url, wait_room_start, ygopro; 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;
net = require('net'); net = require('net');
...@@ -14,6 +14,8 @@ ...@@ -14,6 +14,8 @@
os = require('os'); os = require('os');
crypto = require('crypto');
execFile = require('child_process').execFile; execFile = require('child_process').execFile;
_ = require('underscore'); _ = require('underscore');
...@@ -342,6 +344,128 @@ ...@@ -342,6 +344,128 @@
code: 2 code: 2
}); });
client.end(); client.end();
} else if (info.pass.length && settings.modules.mycard_auth) {
ygopro.stoc_send_chat(client, '正在读取用户信息...', 11);
request({
baseUrl: settings.modules.mycard_auth,
url: '/users/' + client.name + '.json',
qs: {
api_key: '69675c315dfae3d7224688f2c56cf7d3f5016e7cf63f289d945709f11528b02e',
api_username: client.name,
skip_track_visit: true
},
json: true
}, function(error, response, body) {
var action, check, decrypted_buffer, i, k, len, name, opt1, opt2, opt3, options, ref, room, secret;
if (info.pass.length <= 8) {
ygopro.stoc_send_chat(client, '主机密码不正确 (Invalid Length)', 11);
ygopro.stoc_send(client, 'ERROR_MSG', {
msg: 1,
code: 2
});
client.end();
return;
}
buffer = new Buffer(info.pass.slice(0, 8), 'base64');
check = function(buf) {
var checksum, i, k, ref;
checksum = 0;
for (i = k = 0, ref = buf.length; 0 <= ref ? k < ref : k > ref; i = 0 <= ref ? ++k : --k) {
checksum += buf.readUInt8(i);
}
return (checksum & 0xFF) === 0;
};
if (body && body.user) {
secret = body.user.id % 65535 + 1;
decrypted_buffer = new Buffer(6);
ref = [0, 2, 4];
for (k = 0, len = ref.length; k < len; k++) {
i = ref[k];
decrypted_buffer.writeUInt16LE(buffer.readUInt16LE(i) ^ secret, i);
}
if (check(decrypted_buffer)) {
buffer = decrypted_buffer;
}
}
if (!check(buffer)) {
ygopro.stoc_send_chat(client, '主机密码不正确 (Checksum Failed)', 11);
ygopro.stoc_send(client, 'ERROR_MSG', {
msg: 1,
code: 2
});
client.end();
return;
}
action = buffer.readUInt8(1) >> 4;
if (buffer !== decrypted_buffer && (action === 1 || action === 2 || action === 4)) {
ygopro.stoc_send_chat(client, '主机密码不正确 (Unauthorized)', 11);
ygopro.stoc_send(client, 'ERROR_MSG', {
msg: 1,
code: 2
});
client.end();
return;
}
switch (action) {
case 1:
case 2:
name = crypto.createHash('md5').update(info.pass + client.name).digest('base64').slice(0, 10).replace('+', '-').replace('/', '_');
if (Room.find_by_name(name)) {
ygopro.stoc_send_chat(client, '主机密码不正确 (Already Existed)', 11);
ygopro.stoc_send(client, 'ERROR_MSG', {
msg: 1,
code: 2
});
client.end();
return;
}
opt1 = buffer.readUInt8(2);
opt2 = buffer.readUInt8(3);
opt3 = buffer.readUInt8(5);
options = {
lflist: 0,
time_limit: 180,
title: info.pass.slice(8),
"private": action === 2,
rule: (opt1 >> 5) & 3,
mode: (opt1 >> 3) & 3,
enable_priority: !!((opt1 >> 2) & 1),
no_check_deck: !!((opt1 >> 1) & 1),
no_shuffle_deck: !!(opt1 & 1),
start_lp: opt2,
start_hand: opt3 >> 4,
draw_count: opt3 & 0xF
};
room = new Room(name, options);
break;
case 3:
name = info.pass.slice(8);
room = Room.find_by_name(name);
if (!room) {
ygopro.stoc_send_chat(client, '主机密码不正确 (Not Found)', 11);
ygopro.stoc_send(client, 'ERROR_MSG', {
msg: 1,
code: 2
});
client.end();
return;
}
break;
case 4:
room = Room.find_or_create_by_name('M#' + info.pass.slice(8));
break;
default:
ygopro.stoc_send_chat(client, '主机密码不正确 (Invalid Action)', 11);
ygopro.stoc_send(client, 'ERROR_MSG', {
msg: 1,
code: 2
});
client.end();
return;
}
client.room = room;
return client.room.connect(client);
});
} else if (info.pass.length && !Room.validate(info.pass)) { } else if (info.pass.length && !Room.validate(info.pass)) {
ygopro.stoc_send_chat(client, "房间密码不正确", 11); ygopro.stoc_send_chat(client, "房间密码不正确", 11);
ygopro.stoc_send(client, 'ERROR_MSG', { ygopro.stoc_send(client, 'ERROR_MSG', {
...@@ -814,7 +938,7 @@ ...@@ -814,7 +938,7 @@
}, 1000); }, 1000);
if (settings.modules.http) { if (settings.modules.http) {
http_server = http.createServer(function(request, response) { requestListener = function(request, response) {
var k, len, parseQueryString, pass_validated, player, ref, room, roomsjson, u; var k, len, parseQueryString, pass_validated, player, ref, room, roomsjson, u;
parseQueryString = true; parseQueryString = true;
u = url.parse(request.url, parseQueryString); u = url.parse(request.url, parseQueryString);
...@@ -900,8 +1024,37 @@ ...@@ -900,8 +1024,37 @@
response.writeHead(404); response.writeHead(404);
response.end(); response.end();
} }
}); };
http_server = http.createServer(requestListener);
http_server.listen(settings.modules.http.port); http_server.listen(settings.modules.http.port);
if (settings.modules.http.ssl) {
https = require('https');
options = {
cert: fs.readFileSync(settings.modules.http.ssl.cert),
key: fs.readFileSync(settings.modules.http.ssl.key)
};
https_server = https.createServer(options, requestListener);
WebSocketServer = require('ws').Server;
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);
}
} }
}).call(this); }).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