Commit 2d43a219 authored by nanahira's avatar nanahira

Merge branch 'mc'

parents 4504d602 77e2addb
This diff is collapsed.
...@@ -11,19 +11,20 @@ ...@@ -11,19 +11,20 @@
], ],
"author": "zh99998 <zh99998@gmail.com>, mercury233 <me@mercury233.me>, Nanahira <78877@qq.com>", "author": "zh99998 <zh99998@gmail.com>, mercury233 <me@mercury233.me>, Nanahira <78877@qq.com>",
"dependencies": { "dependencies": {
"async": "^3.2.0",
"bunyan": "latest", "bunyan": "latest",
"challonge": "latest",
"deepmerge": "latest", "deepmerge": "latest",
"formidable": "latest",
"geoip-country-lite": "latest",
"load-json-file": "latest", "load-json-file": "latest",
"moment": "latest", "moment": "latest",
"pg": "^6.4.2",
"redis": "latest", "redis": "latest",
"formidable": "latest",
"request": "latest", "request": "latest",
"sqlite3": "latest",
"underscore": "latest", "underscore": "latest",
"underscore.string": "latest", "underscore.string": "latest",
"sqlite3": "latest",
"geoip-country-lite": "latest",
"challonge": "latest",
"pg": "^6.4.2",
"ws": "^1.1.1" "ws": "^1.1.1"
}, },
"license": "AGPL-3.0", "license": "AGPL-3.0",
......
...@@ -10,6 +10,7 @@ exec = require('child_process').exec ...@@ -10,6 +10,7 @@ exec = require('child_process').exec
execFile = require('child_process').execFile execFile = require('child_process').execFile
spawn = require('child_process').spawn spawn = require('child_process').spawn
spawnSync = require('child_process').spawnSync spawnSync = require('child_process').spawnSync
_async = require('async')
# 三方库 # 三方库
_ = global._ = require 'underscore' _ = global._ = require 'underscore'
...@@ -2054,7 +2055,7 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server, datas)-> ...@@ -2054,7 +2055,7 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server, datas)->
checksum += buf.readUInt8(i) checksum += buf.readUInt8(i)
(checksum & 0xFF) == 0 (checksum & 0xFF) == 0
buffer_handle_callback = (buffer, decrypted_buffer, match_permit)-> create_room_with_action = (buffer, decrypted_buffer, match_permit)->
if client.closed if client.closed
return return
action = buffer.readUInt8(1) >> 4 action = buffer.readUInt8(1) >> 4
...@@ -2179,7 +2180,30 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server, datas)-> ...@@ -2179,7 +2180,30 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server, datas)->
room.connect(client) room.connect(client)
return return
match_permit_callback = (buffer, match_permit) -> _async.auto({
match_permit: (done) ->
if(!settings.modules.arena_mode.check_permit)
done(null, null)
return
request
url: settings.modules.arena_mode.check_permit,
json: true,
qs:
username: client.name,
password: info.pass,
arena: settings.modules.arena_mode.mode
, (error, response, body)->
if client.closed
done(null, null)
return
if !error and body
done(null, boddy)
else
log.warn("Match permit request error", error)
match_permit_callback(null, null)
return
return
get_user: (done) ->
if client.closed if client.closed
return return
if id = users_cache[client.name] if id = users_cache[client.name]
...@@ -2188,7 +2212,10 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server, datas)-> ...@@ -2188,7 +2212,10 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server, datas)->
for i in [0, 2, 4] for i in [0, 2, 4]
decrypted_buffer.writeUInt16LE(buffer.readUInt16LE(i) ^ secret, i) decrypted_buffer.writeUInt16LE(buffer.readUInt16LE(i) ^ secret, i)
if check_buffer_indentity(decrypted_buffer) if check_buffer_indentity(decrypted_buffer)
return buffer_handle_callback(decrypted_buffer, decrypted_buffer, match_permit) done(null, {
original: decrypted_buffer,
decrypted: decrypted_buffer
})
#TODO: query database directly, like preload. #TODO: query database directly, like preload.
request request
...@@ -2210,36 +2237,27 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server, datas)-> ...@@ -2210,36 +2237,27 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server, datas)->
buffer = decrypted_buffer buffer = decrypted_buffer
else else
log.warn("READ USER FAIL", error, body) log.warn("READ USER FAIL", error, body)
ygopro.stoc_die(client, "${create_room_failed}") done("${create_room_failed}")
return return
# buffer != decrypted_buffer ==> auth failed # buffer != decrypted_buffer ==> auth failed
if !check_buffer_indentity(buffer) if !check_buffer_indentity(buffer)
ygopro.stoc_die(client, '${invalid_password_checksum}') done('${invalid_password_checksum}')
return return
return buffer_handle_callback(buffer, decrypted_buffer, match_permit) done(null, {
original: buffer,
decrypted: decrypted_buffer
})
return return
}, (err, data) ->
if settings.modules.arena_mode.check_permit if(client.closed)
request
url: settings.modules.arena_mode.check_permit,
json: true,
qs:
username: client.name,
password: info.pass,
arena: settings.modules.arena_mode.mode
, (error, response, body)->
if client.closed
return return
if !error and body if(err)
match_permit_callback(buffer, body) ygopro.stoc_die(client, err)
else
log.warn("Match permit request error", error)
match_permit_callback(buffer, null)
return return
else create_room_with_action(data.get_user.original, data.get_user.decrypted, match_permit)
match_permit_callback(buffer, null) )
else if settings.modules.challonge.enabled else if settings.modules.challonge.enabled
...@@ -2257,18 +2275,29 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server, datas)-> ...@@ -2257,18 +2275,29 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server, datas)->
else else
ygopro.stoc_send_chat(client, '${loading_user_info}', ygopro.constants.COLORS.BABYBLUE) ygopro.stoc_send_chat(client, '${loading_user_info}', ygopro.constants.COLORS.BABYBLUE)
client.setTimeout(300000) #连接后超时5分钟 client.setTimeout(300000) #连接后超时5分钟
_async.auto({
participant_data: (done) ->
challonge.participants._index({ challonge.participants._index({
id: settings.modules.challonge.tournament_id, id: settings.modules.challonge.tournament_id,
callback: (err, data) -> callback: done
})
return
,
match_data: (done) ->
challonge.matches._index({
id: settings.modules.challonge.tournament_id,
callback: done
})
return
}, (err, datas) ->
if client.closed if client.closed
return return
if err or !data if err or !datas.participant_data or !datas.match_data
if err
log.warn("Failed loading Challonge user info", err) log.warn("Failed loading Challonge user info", err)
ygopro.stoc_die(client, '${challonge_match_load_failed}') ygopro.stoc_die(client, '${challonge_match_load_failed}')
return return
found = false found = false
for k,user of data for k,user of datas.participant_data
if user.participant and user.participant.name and deck_name_match(user.participant.name, client.name) if user.participant and user.participant.name and deck_name_match(user.participant.name, client.name)
found = user.participant found = user.participant
break break
...@@ -2276,18 +2305,8 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server, datas)-> ...@@ -2276,18 +2305,8 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server, datas)->
ygopro.stoc_die(client, '${challonge_user_not_found}') ygopro.stoc_die(client, '${challonge_user_not_found}')
return return
client.challonge_info = found client.challonge_info = found
challonge.matches._index({
id: settings.modules.challonge.tournament_id,
callback: (err, data) ->
if client.closed
return
if err or !data
if err
log.warn("Failed loading Challonge match info", err)
ygopro.stoc_die(client, '${challonge_match_load_failed}')
return
found = false found = false
for k,match of data for k,match of datas.match_data
if match and match.match and !match.match.winnerId and match.match.state != "complete" and match.match.player1Id and match.match.player2Id and (match.match.player1Id == client.challonge_info.id or match.match.player2Id == client.challonge_info.id) if match and match.match and !match.match.winnerId and match.match.state != "complete" and match.match.player1Id and match.match.player2Id and (match.match.player1Id == client.challonge_info.id or match.match.player2Id == client.challonge_info.id)
found = match.match found = match.match
break break
...@@ -2335,9 +2354,7 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server, datas)-> ...@@ -2335,9 +2354,7 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server, datas)->
client.rid = _.indexOf(ROOM_all, room) client.rid = _.indexOf(ROOM_all, room)
room.connect(client) room.connect(client)
return return
}) )
return
})
else if !client.name or client.name=="" else if !client.name or client.name==""
ygopro.stoc_die(client, "${bad_user_name}") ygopro.stoc_die(client, "${bad_user_name}")
......
This diff is collapsed.
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