Commit 9947112d authored by nanahira's avatar nanahira

Merge branch 'plugins' into mc

parents 2e38ee98 e8ef0195
# ignore
jsconfig.json
coffeelint.json
.vscode/
password.json
config.*.json
config.user.bak
/bak
/config
/ygopro
/windbot
/decks
/decks_save*
/replays
/node_modules
/ssl
/ygosrv233
/challonge
/logs
/plugins
test*
*.heapsnapshot
*.tmp
*.bak
*.log
*.map
Thumbs.db
ehthumbs.db
Desktop.ini
$RECYCLE.BIN/
.DS_Store
.git* .git*
.dockerignore .dockerignore
Dockerfile* Dockerfile*
......
...@@ -19,6 +19,7 @@ config.user.bak ...@@ -19,6 +19,7 @@ config.user.bak
/ygosrv233 /ygosrv233
/challonge /challonge
/logs /logs
/plugins
test* test*
*.heapsnapshot *.heapsnapshot
......
...@@ -131,11 +131,11 @@ try ...@@ -131,11 +131,11 @@ try
catch e catch e
log.info e unless e.code == 'ENOENT' log.info e unless e.code == 'ENOENT'
setting_save = (settings) -> setting_save = global.setting_save = (settings) ->
fs.writeFileSync(settings.file, JSON.stringify(settings, null, 2)) fs.writeFileSync(settings.file, JSON.stringify(settings, null, 2))
return return
setting_change = (settings, path, val) -> setting_change = global.setting_change = (settings, path, val) ->
# path should be like "modules:welcome" # path should be like "modules:welcome"
log.info("setting changed", path, val) if _.isString(val) log.info("setting changed", path, val) if _.isString(val)
path=path.split(':') path=path.split(':')
...@@ -159,7 +159,7 @@ catch ...@@ -159,7 +159,7 @@ catch
config = {} config = {}
settings = global.settings = merge(default_config, config, { arrayMerge: (destination, source) -> source }) settings = global.settings = merge(default_config, config, { arrayMerge: (destination, source) -> source })
auth = require './ygopro-auth.js' auth = global.auth = require './ygopro-auth.js'
#import old configs #import old configs
imported = false imported = false
...@@ -227,29 +227,29 @@ if imported ...@@ -227,29 +227,29 @@ if imported
# 读取数据 # 读取数据
default_data = loadJSON('./data/default_data.json') default_data = loadJSON('./data/default_data.json')
try try
tips = loadJSON('./config/tips.json') tips = global.tips = loadJSON('./config/tips.json')
catch catch
tips = default_data.tips tips = global.tips = default_data.tips
setting_save(tips) setting_save(tips)
try try
dialogues = loadJSON('./config/dialogues.json') dialogues = global.dialogues = loadJSON('./config/dialogues.json')
catch catch
dialogues = default_data.dialogues dialogues = global.dialogues = default_data.dialogues
setting_save(dialogues) setting_save(dialogues)
try try
badwords = loadJSON('./config/badwords.json') badwords = global.badwords = loadJSON('./config/badwords.json')
catch catch
badwords = default_data.badwords badwords = global.badwords = default_data.badwords
setting_save(badwords) setting_save(badwords)
try try
duel_log = loadJSON('./config/duel_log.json') duel_log = global.duel_log = loadJSON('./config/duel_log.json')
catch catch
duel_log = default_data.duel_log duel_log = global.duel_log = default_data.duel_log
setting_save(duel_log) setting_save(duel_log)
try try
chat_color = loadJSON('./config/chat_color.json') chat_color = global.chat_color = loadJSON('./config/chat_color.json')
catch catch
chat_color = default_data.chat_color chat_color = global.chat_color = default_data.chat_color
setting_save(chat_color) setting_save(chat_color)
try try
...@@ -260,7 +260,7 @@ catch ...@@ -260,7 +260,7 @@ catch
#settings.version = settings.version_default #settings.version = settings.version_default
log.info "ygopro version 0x"+settings.version.toString(16), "(from config)" log.info "ygopro version 0x"+settings.version.toString(16), "(from config)"
# load the lflist of current date # load the lflist of current date
lflists = [] lflists = global.lflists = []
# expansions/lflist # expansions/lflist
try try
for list in fs.readFileSync('ygopro/expansions/lflist.conf', 'utf8').match(/!.*/g) for list in fs.readFileSync('ygopro/expansions/lflist.conf', 'utf8').match(/!.*/g)
...@@ -296,11 +296,11 @@ if settings.modules.windbot.enabled ...@@ -296,11 +296,11 @@ if settings.modules.windbot.enabled
if settings.modules.heartbeat_detection.enabled if settings.modules.heartbeat_detection.enabled
long_resolve_cards = loadJSON('./data/long_resolve_cards.json') long_resolve_cards = global.long_resolve_cards = loadJSON('./data/long_resolve_cards.json')
# 组件 # 组件
ygopro = require './ygopro.js' ygopro = global.ygopro = require './ygopro.js'
roomlist = require './roomlist.js' if settings.modules.http.websocket_roomlist roomlist = global.roomlist = require './roomlist.js' if settings.modules.http.websocket_roomlist
if settings.modules.i18n.auto_pick if settings.modules.i18n.auto_pick
geoip = require('geoip-country-lite') geoip = require('geoip-country-lite')
...@@ -416,8 +416,8 @@ if settings.modules.challonge.enabled ...@@ -416,8 +416,8 @@ if settings.modules.challonge.enabled
setInterval(refresh_challonge_cache, settings.modules.challonge.cache_ttl) setInterval(refresh_challonge_cache, settings.modules.challonge.cache_ttl)
# 获取可用内存 # 获取可用内存
memory_usage = 0 memory_usage = global.memory_usage = 0
get_memory_usage = ()-> get_memory_usage = get_memory_usage = ()->
prc_free = exec("free") prc_free = exec("free")
prc_free.stdout.on 'data', (data)-> prc_free.stdout.on 'data', (data)->
lines = data.toString().split(/\n/g) lines = data.toString().split(/\n/g)
...@@ -439,17 +439,17 @@ get_memory_usage = ()-> ...@@ -439,17 +439,17 @@ get_memory_usage = ()->
get_memory_usage() get_memory_usage()
setInterval(get_memory_usage, 3000) setInterval(get_memory_usage, 3000)
Cloud_replay_ids = [] Cloud_replay_ids = global.Cloud_replay_ids = []
ROOM_all = [] ROOM_all = global.ROOM_all = []
ROOM_players_oppentlist = {} ROOM_players_oppentlist = global.ROOM_players_oppentlist = {}
ROOM_players_banned = [] ROOM_players_banned = global.ROOM_players_banned = []
ROOM_players_scores = {} ROOM_players_scores = global.ROOM_players_scores = {}
ROOM_connected_ip = {} ROOM_connected_ip = global.ROOM_connected_ip = {}
ROOM_bad_ip = {} ROOM_bad_ip = global.ROOM_bad_ip = {}
# ban a user manually and permanently # ban a user manually and permanently
ban_user = (name) -> ban_user = global.ban_user = (name) ->
settings.ban.banned_user.push(name) settings.ban.banned_user.push(name)
setting_save(settings) setting_save(settings)
bad_ip=0 bad_ip=0
...@@ -466,7 +466,7 @@ ban_user = (name) -> ...@@ -466,7 +466,7 @@ ban_user = (name) ->
return return
# automatically ban user to use random duel # automatically ban user to use random duel
ROOM_ban_player = (name, ip, reason, countadd = 1)-> ROOM_ban_player = global.ROOM_ban_player = (name, ip, reason, countadd = 1)->
return if settings.modules.test_mode.no_ban_player return if settings.modules.test_mode.no_ban_player
bannedplayer = _.find ROOM_players_banned, (bannedplayer)-> bannedplayer = _.find ROOM_players_banned, (bannedplayer)->
ip == bannedplayer.ip ip == bannedplayer.ip
...@@ -483,28 +483,28 @@ ROOM_ban_player = (name, ip, reason, countadd = 1)-> ...@@ -483,28 +483,28 @@ ROOM_ban_player = (name, ip, reason, countadd = 1)->
#log.info("banned", name, ip, reason, bannedplayer.count) #log.info("banned", name, ip, reason, bannedplayer.count)
return return
ROOM_player_win = (name)-> ROOM_player_win = global.ROOM_player_win = (name)->
if !ROOM_players_scores[name] if !ROOM_players_scores[name]
ROOM_players_scores[name]={win:0, lose:0, flee:0, combo:0} ROOM_players_scores[name]={win:0, lose:0, flee:0, combo:0}
ROOM_players_scores[name].win = ROOM_players_scores[name].win + 1 ROOM_players_scores[name].win = ROOM_players_scores[name].win + 1
ROOM_players_scores[name].combo = ROOM_players_scores[name].combo + 1 ROOM_players_scores[name].combo = ROOM_players_scores[name].combo + 1
return return
ROOM_player_lose = (name)-> ROOM_player_lose = global.ROOM_player_lose = (name)->
if !ROOM_players_scores[name] if !ROOM_players_scores[name]
ROOM_players_scores[name]={win:0, lose:0, flee:0, combo:0} ROOM_players_scores[name]={win:0, lose:0, flee:0, combo:0}
ROOM_players_scores[name].lose = ROOM_players_scores[name].lose + 1 ROOM_players_scores[name].lose = ROOM_players_scores[name].lose + 1
ROOM_players_scores[name].combo = 0 ROOM_players_scores[name].combo = 0
return return
ROOM_player_flee = (name)-> ROOM_player_flee = global.ROOM_player_flee = (name)->
if !ROOM_players_scores[name] if !ROOM_players_scores[name]
ROOM_players_scores[name]={win:0, lose:0, flee:0, combo:0} ROOM_players_scores[name]={win:0, lose:0, flee:0, combo:0}
ROOM_players_scores[name].flee = ROOM_players_scores[name].flee + 1 ROOM_players_scores[name].flee = ROOM_players_scores[name].flee + 1
ROOM_players_scores[name].combo = 0 ROOM_players_scores[name].combo = 0
return return
ROOM_player_get_score = (player)-> ROOM_player_get_score = global.ROOM_player_get_score = (player)->
name = player.name_vpass name = player.name_vpass
score = ROOM_players_scores[name] score = ROOM_players_scores[name]
if !score if !score
...@@ -541,7 +541,7 @@ if settings.modules.random_duel.post_match_scores ...@@ -541,7 +541,7 @@ if settings.modules.random_duel.post_match_scores
return return
, 60000) , 60000)
ROOM_find_or_create_by_name = (name, player_ip)-> ROOM_find_or_create_by_name = global.ROOM_find_or_create_by_name = (name, player_ip)->
uname=name.toUpperCase() uname=name.toUpperCase()
if settings.modules.windbot.enabled and (uname[0...2] == 'AI' or (!settings.modules.random_duel.enabled and uname == '')) if settings.modules.windbot.enabled and (uname[0...2] == 'AI' or (!settings.modules.random_duel.enabled and uname == ''))
return ROOM_find_or_create_ai(name) return ROOM_find_or_create_ai(name)
...@@ -554,7 +554,7 @@ ROOM_find_or_create_by_name = (name, player_ip)-> ...@@ -554,7 +554,7 @@ ROOM_find_or_create_by_name = (name, player_ip)->
else else
return new Room(name) return new Room(name)
ROOM_find_or_create_random = (type, player_ip)-> ROOM_find_or_create_random = global.ROOM_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
if bannedplayer if bannedplayer
...@@ -594,7 +594,7 @@ ROOM_find_or_create_random = (type, player_ip)-> ...@@ -594,7 +594,7 @@ ROOM_find_or_create_random = (type, player_ip)->
if result.random_type=='M' then result.welcome = result.welcome + '\n${random_duel_enter_room_match}' if result.random_type=='M' then result.welcome = result.welcome + '\n${random_duel_enter_room_match}'
return result return result
ROOM_find_or_create_ai = (name)-> ROOM_find_or_create_ai = global.ROOM_find_or_create_ai = (name)->
if name == '' if name == ''
name = 'AI' name = 'AI'
namea = name.split('#') namea = name.split('#')
...@@ -622,21 +622,25 @@ ROOM_find_or_create_ai = (name)-> ...@@ -622,21 +622,25 @@ ROOM_find_or_create_ai = (name)->
result.private = true result.private = true
return result return result
ROOM_find_by_name = (name)-> ROOM_find_by_name = global.ROOM_find_by_name = (name)->
result = _.find ROOM_all, (room)-> result = _.find ROOM_all, (room)->
return room and room.name == name return room and room.name == name
return result return result
ROOM_find_by_title = (title)-> ROOM_find_by_title = global.ROOM_find_by_title = (title)->
result = _.find ROOM_all, (room)-> result = _.find ROOM_all, (room)->
return room and room.title == title return room and room.title == title
return result return result
ROOM_find_by_port = (port)-> ROOM_find_by_port = global.ROOM_find_by_port = (port)->
_.find ROOM_all, (room)-> _.find ROOM_all, (room)->
return room and room.port == port return room and room.port == port
ROOM_validate = (name)-> ROOM_find_by_pid = global.ROOM_find_by_pid = (pid)->
_.find ROOM_all, (room)->
return room and room.process_pid == pid
ROOM_validate = global.ROOM_validate = (name)->
client_name_and_pass = name.split('$', 2) client_name_and_pass = name.split('$', 2)
client_name = client_name_and_pass[0] client_name = client_name_and_pass[0]
client_pass = client_name_and_pass[1] client_pass = client_name_and_pass[1]
...@@ -648,7 +652,7 @@ ROOM_validate = (name)-> ...@@ -648,7 +652,7 @@ ROOM_validate = (name)->
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
ROOM_unwelcome = (room, bad_player, reason)-> ROOM_unwelcome = global.ROOM_unwelcome = (room, bad_player, reason)->
return unless room return unless room
for player in room.players for player in room.players
if player and player == bad_player if player and player == bad_player
...@@ -658,7 +662,7 @@ ROOM_unwelcome = (room, bad_player, reason)-> ...@@ -658,7 +662,7 @@ ROOM_unwelcome = (room, bad_player, reason)->
ygopro.stoc_send_chat(player, "${unwelcome_tip_part1}#{reason}${unwelcome_tip_part2}", ygopro.constants.COLORS.BABYBLUE) ygopro.stoc_send_chat(player, "${unwelcome_tip_part1}#{reason}${unwelcome_tip_part2}", ygopro.constants.COLORS.BABYBLUE)
return return
CLIENT_kick = (client) -> CLIENT_kick = global.CLIENT_kick = (client) ->
if !client if !client
return false return false
client.system_kicked = true client.system_kicked = true
...@@ -669,7 +673,7 @@ CLIENT_kick = (client) -> ...@@ -669,7 +673,7 @@ CLIENT_kick = (client) ->
client.destroy() client.destroy()
return true return true
release_disconnect = (dinfo, reconnected) -> release_disconnect = global.release_disconnect = (dinfo, reconnected) ->
if dinfo.old_client and !reconnected if dinfo.old_client and !reconnected
dinfo.old_client.destroy() dinfo.old_client.destroy()
if dinfo.old_server and !reconnected if dinfo.old_server and !reconnected
...@@ -677,7 +681,7 @@ release_disconnect = (dinfo, reconnected) -> ...@@ -677,7 +681,7 @@ release_disconnect = (dinfo, reconnected) ->
clearTimeout(dinfo.timeout) clearTimeout(dinfo.timeout)
return return
CLIENT_get_authorize_key = (client) -> CLIENT_get_authorize_key = global.CLIENT_get_authorize_key = (client) ->
if !settings.modules.mycard.enabled and client.vpass if !settings.modules.mycard.enabled and client.vpass
return client.name_vpass return client.name_vpass
else if settings.modules.mycard.enabled or settings.modules.tournament_mode.enabled or settings.modules.challonge.enabled or client.is_local else if settings.modules.mycard.enabled or settings.modules.tournament_mode.enabled or settings.modules.challonge.enabled or client.is_local
...@@ -685,7 +689,7 @@ CLIENT_get_authorize_key = (client) -> ...@@ -685,7 +689,7 @@ CLIENT_get_authorize_key = (client) ->
else else
return client.ip + ":" + client.name return client.ip + ":" + client.name
CLIENT_reconnect_unregister = (client, reconnected, exact) -> CLIENT_reconnect_unregister = global.CLIENT_reconnect_unregister = (client, reconnected, exact) ->
if !settings.modules.reconnect.enabled if !settings.modules.reconnect.enabled
return false return false
if disconnect_list[CLIENT_get_authorize_key(client)] if disconnect_list[CLIENT_get_authorize_key(client)]
...@@ -696,7 +700,7 @@ CLIENT_reconnect_unregister = (client, reconnected, exact) -> ...@@ -696,7 +700,7 @@ CLIENT_reconnect_unregister = (client, reconnected, exact) ->
return true return true
return false return false
CLIENT_reconnect_register = (client, room_id, error) -> CLIENT_reconnect_register = global.CLIENT_reconnect_register = (client, room_id, error) ->
room = ROOM_all[room_id] room = ROOM_all[room_id]
if client.had_new_reconnection if client.had_new_reconnection
return false return false
...@@ -727,7 +731,7 @@ CLIENT_reconnect_register = (client, room_id, error) -> ...@@ -727,7 +731,7 @@ CLIENT_reconnect_register = (client, room_id, error) ->
ygopro.ctos_send(client.server, 'SURRENDER') ygopro.ctos_send(client.server, 'SURRENDER')
return true return true
CLIENT_import_data = (client, old_client, room) -> CLIENT_import_data = global.CLIENT_import_data = (client, old_client, room) ->
for player,index in room.players for player,index in room.players
if player == old_client if player == old_client
room.players[index] = client room.players[index] = client
...@@ -744,7 +748,7 @@ CLIENT_import_data = (client, old_client, room) -> ...@@ -744,7 +748,7 @@ CLIENT_import_data = (client, old_client, room) ->
old_client.had_new_reconnection = true old_client.had_new_reconnection = true
return return
SERVER_clear_disconnect = (server) -> SERVER_clear_disconnect = global.SERVER_clear_disconnect = (server) ->
return false unless settings.modules.reconnect.enabled return false unless settings.modules.reconnect.enabled
for k,v of disconnect_list for k,v of disconnect_list
if v and server == v.old_server if v and server == v.old_server
...@@ -753,7 +757,7 @@ SERVER_clear_disconnect = (server) -> ...@@ -753,7 +757,7 @@ SERVER_clear_disconnect = (server) ->
return true return true
return false return false
ROOM_clear_disconnect = (room_id) -> ROOM_clear_disconnect = global.ROOM_clear_disconnect = (room_id) ->
return false unless settings.modules.reconnect.enabled return false unless settings.modules.reconnect.enabled
for k,v of disconnect_list for k,v of disconnect_list
if v and room_id == v.room_id if v and room_id == v.room_id
...@@ -762,7 +766,7 @@ ROOM_clear_disconnect = (room_id) -> ...@@ -762,7 +766,7 @@ ROOM_clear_disconnect = (room_id) ->
return true return true
return false return false
CLIENT_is_player = (client, room) -> CLIENT_is_player = global.CLIENT_is_player = (client, room) ->
is_player = false is_player = false
for player in room.players for player in room.players
if client == player if client == player
...@@ -770,7 +774,7 @@ CLIENT_is_player = (client, room) -> ...@@ -770,7 +774,7 @@ CLIENT_is_player = (client, room) ->
break break
return is_player and client.pos <= 3 return is_player and client.pos <= 3
CLIENT_is_able_to_reconnect = (client, deckbuf) -> CLIENT_is_able_to_reconnect = global.CLIENT_is_able_to_reconnect = (client, deckbuf) ->
unless settings.modules.reconnect.enabled unless settings.modules.reconnect.enabled
return false return false
if client.system_kicked if client.system_kicked
...@@ -786,20 +790,20 @@ CLIENT_is_able_to_reconnect = (client, deckbuf) -> ...@@ -786,20 +790,20 @@ CLIENT_is_able_to_reconnect = (client, deckbuf) ->
return false return false
return true return true
CLIENT_get_kick_reconnect_target = (client, deckbuf) -> CLIENT_get_kick_reconnect_target = global.CLIENT_get_kick_reconnect_target = (client, deckbuf) ->
for room in ROOM_all when room and room.duel_stage != ygopro.constants.DUEL_STAGE.BEGIN and !room.windbot for room in ROOM_all when room and room.duel_stage != ygopro.constants.DUEL_STAGE.BEGIN and !room.windbot
for player in room.get_playing_player() when !player.closed and player.name == client.name and (settings.modules.challonge.enabled or player.pass == client.pass) and (settings.modules.mycard.enabled or settings.modules.tournament_mode.enabled or player.ip == client.ip or (client.vpass and client.vpass == player.vpass)) and (!deckbuf or _.isEqual(player.start_deckbuf, deckbuf)) for player in room.get_playing_player() when !player.closed and player.name == client.name and (settings.modules.challonge.enabled or player.pass == client.pass) and (settings.modules.mycard.enabled or settings.modules.tournament_mode.enabled or player.ip == client.ip or (client.vpass and client.vpass == player.vpass)) and (!deckbuf or _.isEqual(player.start_deckbuf, deckbuf))
return player return player
return null return null
CLIENT_is_able_to_kick_reconnect = (client, deckbuf) -> CLIENT_is_able_to_kick_reconnect = global.CLIENT_is_able_to_kick_reconnect = (client, deckbuf) ->
unless settings.modules.reconnect.enabled and settings.modules.reconnect.allow_kick_reconnect unless settings.modules.reconnect.enabled and settings.modules.reconnect.allow_kick_reconnect
return false return false
if !CLIENT_get_kick_reconnect_target(client, deckbuf) if !CLIENT_get_kick_reconnect_target(client, deckbuf)
return false return false
return true return true
CLIENT_send_pre_reconnect_info = (client, room, old_client) -> CLIENT_send_pre_reconnect_info = global.CLIENT_send_pre_reconnect_info = (client, room, old_client) ->
ygopro.stoc_send_chat(client, "${pre_reconnecting_to_room}", ygopro.constants.COLORS.BABYBLUE) ygopro.stoc_send_chat(client, "${pre_reconnecting_to_room}", ygopro.constants.COLORS.BABYBLUE)
ygopro.stoc_send(client, 'JOIN_GAME', room.join_game_buffer) ygopro.stoc_send(client, 'JOIN_GAME', room.join_game_buffer)
req_pos = old_client.pos req_pos = old_client.pos
...@@ -815,7 +819,7 @@ CLIENT_send_pre_reconnect_info = (client, room, old_client) -> ...@@ -815,7 +819,7 @@ CLIENT_send_pre_reconnect_info = (client, room, old_client) ->
}) })
return return
CLIENT_send_reconnect_info = (client, server, room) -> CLIENT_send_reconnect_info = global.CLIENT_send_reconnect_info = (client, server, room) ->
client.reconnecting = true client.reconnecting = true
ygopro.stoc_send_chat(client, "${reconnecting_to_room}", ygopro.constants.COLORS.BABYBLUE) ygopro.stoc_send_chat(client, "${reconnecting_to_room}", ygopro.constants.COLORS.BABYBLUE)
switch room.duel_stage switch room.duel_stage
...@@ -842,7 +846,7 @@ CLIENT_send_reconnect_info = (client, server, room) -> ...@@ -842,7 +846,7 @@ CLIENT_send_reconnect_info = (client, server, room) ->
break break
return return
CLIENT_pre_reconnect = (client) -> CLIENT_pre_reconnect = global.CLIENT_pre_reconnect = (client) ->
if CLIENT_is_able_to_reconnect(client) if CLIENT_is_able_to_reconnect(client)
dinfo = disconnect_list[CLIENT_get_authorize_key(client)] dinfo = disconnect_list[CLIENT_get_authorize_key(client)]
client.pre_reconnecting = true client.pre_reconnecting = true
...@@ -857,7 +861,7 @@ CLIENT_pre_reconnect = (client) -> ...@@ -857,7 +861,7 @@ CLIENT_pre_reconnect = (client) ->
CLIENT_send_pre_reconnect_info(client, ROOM_all[player.rid], player) CLIENT_send_pre_reconnect_info(client, ROOM_all[player.rid], player)
return return
CLIENT_reconnect = (client) -> CLIENT_reconnect = global.CLIENT_reconnect = (client) ->
if !CLIENT_is_able_to_reconnect(client) if !CLIENT_is_able_to_reconnect(client)
ygopro.stoc_send_chat(client, "${reconnect_failed}", ygopro.constants.COLORS.RED) ygopro.stoc_send_chat(client, "${reconnect_failed}", ygopro.constants.COLORS.RED)
CLIENT_kick(client) CLIENT_kick(client)
...@@ -883,7 +887,7 @@ CLIENT_reconnect = (client) -> ...@@ -883,7 +887,7 @@ CLIENT_reconnect = (client) ->
CLIENT_reconnect_unregister(client, true) CLIENT_reconnect_unregister(client, true)
return return
CLIENT_kick_reconnect = (client, deckbuf) -> CLIENT_kick_reconnect = global.CLIENT_kick_reconnect = (client, deckbuf) ->
if !CLIENT_is_able_to_kick_reconnect(client) if !CLIENT_is_able_to_kick_reconnect(client)
ygopro.stoc_send_chat(client, "${reconnect_failed}", ygopro.constants.COLORS.RED) ygopro.stoc_send_chat(client, "${reconnect_failed}", ygopro.constants.COLORS.RED)
CLIENT_kick(client) CLIENT_kick(client)
...@@ -915,7 +919,7 @@ CLIENT_kick_reconnect = (client, deckbuf) -> ...@@ -915,7 +919,7 @@ CLIENT_kick_reconnect = (client, deckbuf) ->
if settings.modules.reconnect.enabled if settings.modules.reconnect.enabled
disconnect_list = {} # {old_client, old_server, room_id, timeout, deckbuf} disconnect_list = {} # {old_client, old_server, room_id, timeout, deckbuf}
CLIENT_heartbeat_unregister = (client) -> CLIENT_heartbeat_unregister = global.CLIENT_heartbeat_unregister = (client) ->
if !settings.modules.heartbeat_detection.enabled or !client.heartbeat_timeout if !settings.modules.heartbeat_detection.enabled or !client.heartbeat_timeout
return false return false
clearTimeout(client.heartbeat_timeout) clearTimeout(client.heartbeat_timeout)
...@@ -923,7 +927,7 @@ CLIENT_heartbeat_unregister = (client) -> ...@@ -923,7 +927,7 @@ CLIENT_heartbeat_unregister = (client) ->
#log.info(2, client.name) #log.info(2, client.name)
return true return true
CLIENT_heartbeat_register = (client, send) -> CLIENT_heartbeat_register = global.CLIENT_heartbeat_register = (client, send) ->
if !settings.modules.heartbeat_detection.enabled or client.closed or client.is_post_watcher or client.pre_reconnecting or client.reconnecting or client.waiting_for_last or client.pos > 3 or client.heartbeat_protected if !settings.modules.heartbeat_detection.enabled or client.closed or client.is_post_watcher or client.pre_reconnecting or client.reconnecting or client.waiting_for_last or client.pos > 3 or client.heartbeat_protected
return false return false
if client.heartbeat_timeout if client.heartbeat_timeout
...@@ -946,10 +950,10 @@ CLIENT_heartbeat_register = (client, send) -> ...@@ -946,10 +950,10 @@ CLIENT_heartbeat_register = (client, send) ->
#log.info(1, client.name) #log.info(1, client.name)
return true return true
CLIENT_is_banned_by_mc = (client) -> CLIENT_is_banned_by_mc = global.CLIENT_is_banned_by_mc = (client) ->
return client.ban_mc and client.ban_mc.banned and moment().isBefore(client.ban_mc.until) return client.ban_mc and client.ban_mc.banned and moment().isBefore(client.ban_mc.until)
CLIENT_send_replays = (client, room) -> CLIENT_send_replays = global.CLIENT_send_replays = (client, room) ->
return false unless settings.modules.replay_delay and not (settings.modules.tournament_mode.enabled and settings.modules.tournament_mode.replay_safe and settings.modules.tournament_mode.block_replay_to_player) and room.replays.length and room.hostinfo.mode == 1 and !client.replays_sent and !client.closed return false unless settings.modules.replay_delay and not (settings.modules.tournament_mode.enabled and settings.modules.tournament_mode.replay_safe and settings.modules.tournament_mode.block_replay_to_player) and room.replays.length and room.hostinfo.mode == 1 and !client.replays_sent and !client.closed
client.replays_sent = true client.replays_sent = true
i = 0 i = 0
...@@ -960,7 +964,7 @@ CLIENT_send_replays = (client, room) -> ...@@ -960,7 +964,7 @@ CLIENT_send_replays = (client, room) ->
ygopro.stoc_send(client, "REPLAY", buffer) ygopro.stoc_send(client, "REPLAY", buffer)
return true return true
SOCKET_flush_data = (sk, datas) -> SOCKET_flush_data = global.SOCKET_flush_data = (sk, datas) ->
if !sk or sk.closed if !sk or sk.closed
return false return false
for buffer in datas for buffer in datas
...@@ -1611,16 +1615,25 @@ net.createServer (client) -> ...@@ -1611,16 +1615,25 @@ net.createServer (client) ->
cancel = false cancel = false
if settings.modules.reconnect.enabled and client.pre_reconnecting and ygopro.constants.CTOS[ctos_proto] != 'UPDATE_DECK' if settings.modules.reconnect.enabled and client.pre_reconnecting and ygopro.constants.CTOS[ctos_proto] != 'UPDATE_DECK'
cancel = true cancel = true
if ygopro.ctos_follows[ctos_proto] and !cancel
b = ctos_buffer.slice(3, ctos_message_length - 1 + 3) b = ctos_buffer.slice(3, ctos_message_length - 1 + 3)
info = null info = null
if struct = ygopro.structs[ygopro.proto_structs.CTOS[ygopro.constants.CTOS[ctos_proto]]] if struct = ygopro.structs[ygopro.proto_structs.CTOS[ygopro.constants.CTOS[ctos_proto]]]
struct._setBuff(b) struct._setBuff(b)
info = _.clone(struct.fields) info = _.clone(struct.fields)
if ygopro.ctos_follows[ctos_proto].synchronous if ygopro.ctos_follows_before[ctos_proto] and !cancel
cancel = ygopro.ctos_follows[ctos_proto].callback b, info, client, client.server, datas for ctos_event in ygopro.ctos_follows_before[ctos_proto]
else result = ctos_event.callback b, info, client, client.server, datas
ygopro.ctos_follows[ctos_proto].callback b, info, client, client.server, datas if result and ctos_event.synchronous
cancel = true
if ygopro.ctos_follows[ctos_proto] and !cancel
result = ygopro.ctos_follows[ctos_proto].callback b, info, client, client.server, datas
if result and ygopro.ctos_follows[ctos_proto].synchronous
cancel = true
if ygopro.ctos_follows_after[ctos_proto] and !cancel
for ctos_event in ygopro.ctos_follows_after[ctos_proto]
result = ctos_event.callback b, info, client, client.server, datas
if result and ctos_event.synchronous
cancel = true
datas.push ctos_buffer.slice(0, 2 + ctos_message_length) unless cancel datas.push ctos_buffer.slice(0, 2 + ctos_message_length) unless cancel
ctos_buffer = ctos_buffer.slice(2 + ctos_message_length) ctos_buffer = ctos_buffer.slice(2 + ctos_message_length)
ctos_message_length = 0 ctos_message_length = 0
...@@ -1679,17 +1692,25 @@ net.createServer (client) -> ...@@ -1679,17 +1692,25 @@ net.createServer (client) ->
if stoc_buffer.length >= 2 + stoc_message_length if stoc_buffer.length >= 2 + stoc_message_length
#console.log "STOC", ygopro.constants.STOC[stoc_proto] #console.log "STOC", ygopro.constants.STOC[stoc_proto]
cancel = false cancel = false
stanzas = stoc_proto
if ygopro.stoc_follows[stoc_proto]
b = stoc_buffer.slice(3, stoc_message_length - 1 + 3) b = stoc_buffer.slice(3, stoc_message_length - 1 + 3)
info = null info = null
if struct = ygopro.structs[ygopro.proto_structs.STOC[ygopro.constants.STOC[stoc_proto]]] if struct = ygopro.structs[ygopro.proto_structs.STOC[ygopro.constants.STOC[stoc_proto]]]
struct._setBuff(b) struct._setBuff(b)
info = _.clone(struct.fields) info = _.clone(struct.fields)
if ygopro.stoc_follows[stoc_proto].synchronous if ygopro.stoc_follows_before[stoc_proto] and !cancel
cancel = ygopro.stoc_follows[stoc_proto].callback b, info, server.client, server, datas for stoc_event in ygopro.stoc_follows_before[stoc_proto]
else result = stoc_event.callback b, info, server.client, server, datas
ygopro.stoc_follows[stoc_proto].callback b, info, server.client, server, datas if result and stoc_event.synchronous
cancel = true
if ygopro.stoc_follows[stoc_proto] and !cancel
result = ygopro.stoc_follows[stoc_proto].callback b, info, server.client, server, datas
if result and ygopro.stoc_follows[stoc_proto].synchronous
cancel = true
if ygopro.stoc_follows_after[stoc_proto] and !cancel
for stoc_event in ygopro.stoc_follows_after[stoc_proto]
result = stoc_event.callback b, info, server.client, server, datas
if result and stoc_event.synchronous
cancel = true
datas.push stoc_buffer.slice(0, 2 + stoc_message_length) unless cancel datas.push stoc_buffer.slice(0, 2 + stoc_message_length) unless cancel
stoc_buffer = stoc_buffer.slice(2 + stoc_message_length) stoc_buffer = stoc_buffer.slice(2 + stoc_message_length)
stoc_message_length = 0 stoc_message_length = 0
...@@ -2262,7 +2283,7 @@ ygopro.stoc_follow 'JOIN_GAME', false, (buffer, info, client, server, datas)-> ...@@ -2262,7 +2283,7 @@ ygopro.stoc_follow 'JOIN_GAME', false, (buffer, info, client, server, datas)->
return return
# 登场台词 # 登场台词
load_dialogues = () -> load_dialogues = global.load_dialogues = () ->
request request
url: settings.modules.dialogues.get url: settings.modules.dialogues.get
json: true json: true
...@@ -2718,7 +2739,7 @@ ygopro.stoc_send_random_tip_to_room = (room)-> ...@@ -2718,7 +2739,7 @@ ygopro.stoc_send_random_tip_to_room = (room)->
ygopro.stoc_send_chat_to_room(room, "Tip: " + tips.tips[Math.floor(Math.random() * tips.tips.length)]) ygopro.stoc_send_chat_to_room(room, "Tip: " + tips.tips[Math.floor(Math.random() * tips.tips.length)])
return return
load_tips = ()-> load_tips = global.load_tips = ()->
request request
url: settings.modules.tips.get url: settings.modules.tips.get
json: true json: true
...@@ -2818,7 +2839,7 @@ ygopro.ctos_follow 'SURRENDER', true, (buffer, info, client, server, datas)-> ...@@ -2818,7 +2839,7 @@ ygopro.ctos_follow 'SURRENDER', true, (buffer, info, client, server, datas)->
return true return true
return false return false
report_to_big_brother = (roomname, sender, ip, level, content, match) -> report_to_big_brother = global.report_to_big_brother = (roomname, sender, ip, level, content, match) ->
return unless settings.modules.big_brother.enabled return unless settings.modules.big_brother.enabled
request.post { url : settings.modules.big_brother.post , form : { request.post { url : settings.modules.big_brother.post , form : {
accesskey: settings.modules.big_brother.accesskey, accesskey: settings.modules.big_brother.accesskey,
...@@ -3381,9 +3402,9 @@ setInterval ()-> ...@@ -3381,9 +3402,9 @@ setInterval ()->
# spawn windbot # spawn windbot
windbot_looplimit = 0 windbot_looplimit = 0
windbot_process = null windbot_process = global.windbot_process = null
spawn_windbot = () -> spawn_windbot = global.spawn_windbot = () ->
if /^win/.test(process.platform) if /^win/.test(process.platform)
windbot_bin = 'WindBot.exe' windbot_bin = 'WindBot.exe'
windbot_parameters = [] windbot_parameters = []
...@@ -3709,3 +3730,11 @@ if settings.modules.http ...@@ -3709,3 +3730,11 @@ if settings.modules.http
if settings.modules.http.websocket_roomlist and roomlist if settings.modules.http.websocket_roomlist and roomlist
roomlist.init https_server, ROOM_all roomlist.init https_server, ROOM_all
https_server.listen settings.modules.http.ssl.port https_server.listen settings.modules.http.ssl.port
if not fs.existsSync('./plugins')
fs.mkdirSync('./plugins')
plugin_list = fs.readdirSync("./plugins")
for plugin_filename in plugin_list
plugin_path = "./plugins/" + plugin_filename
require(plugin_path)
// Generated by CoffeeScript 1.12.7 // Generated by CoffeeScript 1.12.7
(function() { (function() {
var CLIENT_get_authorize_key, CLIENT_get_kick_reconnect_target, CLIENT_heartbeat_register, CLIENT_heartbeat_unregister, CLIENT_import_data, CLIENT_is_able_to_kick_reconnect, CLIENT_is_able_to_reconnect, CLIENT_is_banned_by_mc, CLIENT_is_player, CLIENT_kick, CLIENT_kick_reconnect, CLIENT_pre_reconnect, CLIENT_reconnect, CLIENT_reconnect_register, CLIENT_reconnect_unregister, CLIENT_send_pre_reconnect_info, CLIENT_send_reconnect_info, CLIENT_send_replays, Cloud_replay_ids, ROOM_all, ROOM_bad_ip, ROOM_ban_player, ROOM_clear_disconnect, ROOM_connected_ip, ROOM_find_by_name, ROOM_find_by_port, ROOM_find_by_title, ROOM_find_or_create_ai, ROOM_find_or_create_by_name, ROOM_find_or_create_random, ROOM_player_flee, ROOM_player_get_score, ROOM_player_lose, ROOM_player_win, ROOM_players_banned, ROOM_players_oppentlist, ROOM_players_scores, ROOM_unwelcome, ROOM_validate, Room, SERVER_clear_disconnect, SOCKET_flush_data, _, addCallback, auth, badwords, ban_user, bunyan, challonge, challonge_cache, challonge_module_name, challonge_queue_callbacks, chat_color, config, cppversion, crypto, date, default_config, default_data, dialogues, disconnect_list, dns, duel_log, e, exec, execFile, fs, geoip, get_callback, get_memory_usage, http, http_server, https, https_server, import_datas, imported, is_requesting, j, l, len, len1, lflists, list, loadJSON, load_dialogues, load_tips, log, long_resolve_cards, memory_usage, merge, moment, net, oldbadwords, oldconfig, olddialogues, oldduellog, oldtips, options, os, path, pgClient, pg_client, pg_query, real_windbot_server_ip, rebooted, redis, redisdb, ref, ref1, refresh_challonge_cache, release_disconnect, report_to_big_brother, request, requestListener, roomlist, setting_change, setting_save, settings, spawn, spawnSync, spawn_windbot, tips, url, users_cache, wait_room_start, wait_room_start_arena, windbot_looplimit, windbot_process, windbots, ygopro, zlib; var CLIENT_get_authorize_key, CLIENT_get_kick_reconnect_target, CLIENT_heartbeat_register, CLIENT_heartbeat_unregister, CLIENT_import_data, CLIENT_is_able_to_kick_reconnect, CLIENT_is_able_to_reconnect, CLIENT_is_banned_by_mc, CLIENT_is_player, CLIENT_kick, CLIENT_kick_reconnect, CLIENT_pre_reconnect, CLIENT_reconnect, CLIENT_reconnect_register, CLIENT_reconnect_unregister, CLIENT_send_pre_reconnect_info, CLIENT_send_reconnect_info, CLIENT_send_replays, Cloud_replay_ids, ROOM_all, ROOM_bad_ip, ROOM_ban_player, ROOM_clear_disconnect, ROOM_connected_ip, ROOM_find_by_name, ROOM_find_by_pid, ROOM_find_by_port, ROOM_find_by_title, ROOM_find_or_create_ai, ROOM_find_or_create_by_name, ROOM_find_or_create_random, ROOM_player_flee, ROOM_player_get_score, ROOM_player_lose, ROOM_player_win, ROOM_players_banned, ROOM_players_oppentlist, ROOM_players_scores, ROOM_unwelcome, ROOM_validate, Room, SERVER_clear_disconnect, SOCKET_flush_data, _, addCallback, auth, badwords, ban_user, bunyan, challonge, challonge_cache, challonge_module_name, challonge_queue_callbacks, chat_color, config, cppversion, crypto, date, default_config, default_data, dialogues, disconnect_list, dns, duel_log, e, exec, execFile, fs, geoip, get_callback, get_memory_usage, http, http_server, https, https_server, import_datas, imported, is_requesting, j, l, len, len1, len2, lflists, list, loadJSON, load_dialogues, load_tips, log, long_resolve_cards, m, memory_usage, merge, moment, net, oldbadwords, oldconfig, olddialogues, oldduellog, oldtips, options, os, path, pgClient, pg_client, pg_query, plugin_filename, plugin_list, plugin_path, real_windbot_server_ip, rebooted, redis, redisdb, ref, ref1, refresh_challonge_cache, release_disconnect, report_to_big_brother, request, requestListener, roomlist, setting_change, setting_save, settings, spawn, spawnSync, spawn_windbot, tips, url, users_cache, wait_room_start, wait_room_start_arena, windbot_looplimit, windbot_process, windbots, ygopro, zlib;
net = require('net'); net = require('net');
...@@ -128,11 +128,11 @@ ...@@ -128,11 +128,11 @@
} }
} }
setting_save = function(settings) { setting_save = global.setting_save = function(settings) {
fs.writeFileSync(settings.file, JSON.stringify(settings, null, 2)); fs.writeFileSync(settings.file, JSON.stringify(settings, null, 2));
}; };
setting_change = function(settings, path, val) { setting_change = global.setting_change = function(settings, path, val) {
var key, target; var key, target;
if (_.isString(val)) { if (_.isString(val)) {
log.info("setting changed", path, val); log.info("setting changed", path, val);
...@@ -166,7 +166,7 @@ ...@@ -166,7 +166,7 @@
} }
}); });
auth = require('./ygopro-auth.js'); auth = global.auth = require('./ygopro-auth.js');
imported = false; imported = false;
...@@ -246,37 +246,37 @@ ...@@ -246,37 +246,37 @@
default_data = loadJSON('./data/default_data.json'); default_data = loadJSON('./data/default_data.json');
try { try {
tips = loadJSON('./config/tips.json'); tips = global.tips = loadJSON('./config/tips.json');
} catch (error1) { } catch (error1) {
tips = default_data.tips; tips = global.tips = default_data.tips;
setting_save(tips); setting_save(tips);
} }
try { try {
dialogues = loadJSON('./config/dialogues.json'); dialogues = global.dialogues = loadJSON('./config/dialogues.json');
} catch (error1) { } catch (error1) {
dialogues = default_data.dialogues; dialogues = global.dialogues = default_data.dialogues;
setting_save(dialogues); setting_save(dialogues);
} }
try { try {
badwords = loadJSON('./config/badwords.json'); badwords = global.badwords = loadJSON('./config/badwords.json');
} catch (error1) { } catch (error1) {
badwords = default_data.badwords; badwords = global.badwords = default_data.badwords;
setting_save(badwords); setting_save(badwords);
} }
try { try {
duel_log = loadJSON('./config/duel_log.json'); duel_log = global.duel_log = loadJSON('./config/duel_log.json');
} catch (error1) { } catch (error1) {
duel_log = default_data.duel_log; duel_log = global.duel_log = default_data.duel_log;
setting_save(duel_log); setting_save(duel_log);
} }
try { try {
chat_color = loadJSON('./config/chat_color.json'); chat_color = global.chat_color = loadJSON('./config/chat_color.json');
} catch (error1) { } catch (error1) {
chat_color = default_data.chat_color; chat_color = global.chat_color = default_data.chat_color;
setting_save(chat_color); setting_save(chat_color);
} }
...@@ -288,7 +288,7 @@ ...@@ -288,7 +288,7 @@
log.info("ygopro version 0x" + settings.version.toString(16), "(from config)"); log.info("ygopro version 0x" + settings.version.toString(16), "(from config)");
} }
lflists = []; lflists = global.lflists = [];
try { try {
ref = fs.readFileSync('ygopro/expansions/lflist.conf', 'utf8').match(/!.*/g); ref = fs.readFileSync('ygopro/expansions/lflist.conf', 'utf8').match(/!.*/g);
...@@ -347,13 +347,13 @@ ...@@ -347,13 +347,13 @@
} }
if (settings.modules.heartbeat_detection.enabled) { if (settings.modules.heartbeat_detection.enabled) {
long_resolve_cards = loadJSON('./data/long_resolve_cards.json'); long_resolve_cards = global.long_resolve_cards = loadJSON('./data/long_resolve_cards.json');
} }
ygopro = require('./ygopro.js'); ygopro = global.ygopro = require('./ygopro.js');
if (settings.modules.http.websocket_roomlist) { if (settings.modules.http.websocket_roomlist) {
roomlist = require('./roomlist.js'); roomlist = global.roomlist = require('./roomlist.js');
} }
if (settings.modules.i18n.auto_pick) { if (settings.modules.i18n.auto_pick) {
...@@ -482,9 +482,9 @@ ...@@ -482,9 +482,9 @@
} }
} }
memory_usage = 0; memory_usage = global.memory_usage = 0;
get_memory_usage = function() { get_memory_usage = get_memory_usage = function() {
var prc_free; var prc_free;
prc_free = exec("free"); prc_free = exec("free");
prc_free.stdout.on('data', function(data) { prc_free.stdout.on('data', function(data) {
...@@ -511,21 +511,21 @@ ...@@ -511,21 +511,21 @@
setInterval(get_memory_usage, 3000); setInterval(get_memory_usage, 3000);
Cloud_replay_ids = []; Cloud_replay_ids = global.Cloud_replay_ids = [];
ROOM_all = []; ROOM_all = global.ROOM_all = [];
ROOM_players_oppentlist = {}; ROOM_players_oppentlist = global.ROOM_players_oppentlist = {};
ROOM_players_banned = []; ROOM_players_banned = global.ROOM_players_banned = [];
ROOM_players_scores = {}; ROOM_players_scores = global.ROOM_players_scores = {};
ROOM_connected_ip = {}; ROOM_connected_ip = global.ROOM_connected_ip = {};
ROOM_bad_ip = {}; ROOM_bad_ip = global.ROOM_bad_ip = {};
ban_user = function(name) { ban_user = global.ban_user = function(name) {
var bad_ip, len2, len3, m, n, player, ref2, room; var bad_ip, len2, len3, m, n, player, ref2, room;
settings.ban.banned_user.push(name); settings.ban.banned_user.push(name);
setting_save(settings); setting_save(settings);
...@@ -550,7 +550,7 @@ ...@@ -550,7 +550,7 @@
} }
}; };
ROOM_ban_player = function(name, ip, reason, countadd) { ROOM_ban_player = global.ROOM_ban_player = function(name, ip, reason, countadd) {
var bannedplayer, bantime; var bannedplayer, bantime;
if (countadd == null) { if (countadd == null) {
countadd = 1; countadd = 1;
...@@ -583,7 +583,7 @@ ...@@ -583,7 +583,7 @@
} }
}; };
ROOM_player_win = function(name) { ROOM_player_win = global.ROOM_player_win = function(name) {
if (!ROOM_players_scores[name]) { if (!ROOM_players_scores[name]) {
ROOM_players_scores[name] = { ROOM_players_scores[name] = {
win: 0, win: 0,
...@@ -596,7 +596,7 @@ ...@@ -596,7 +596,7 @@
ROOM_players_scores[name].combo = ROOM_players_scores[name].combo + 1; ROOM_players_scores[name].combo = ROOM_players_scores[name].combo + 1;
}; };
ROOM_player_lose = function(name) { ROOM_player_lose = global.ROOM_player_lose = function(name) {
if (!ROOM_players_scores[name]) { if (!ROOM_players_scores[name]) {
ROOM_players_scores[name] = { ROOM_players_scores[name] = {
win: 0, win: 0,
...@@ -609,7 +609,7 @@ ...@@ -609,7 +609,7 @@
ROOM_players_scores[name].combo = 0; ROOM_players_scores[name].combo = 0;
}; };
ROOM_player_flee = function(name) { ROOM_player_flee = global.ROOM_player_flee = function(name) {
if (!ROOM_players_scores[name]) { if (!ROOM_players_scores[name]) {
ROOM_players_scores[name] = { ROOM_players_scores[name] = {
win: 0, win: 0,
...@@ -622,7 +622,7 @@ ...@@ -622,7 +622,7 @@
ROOM_players_scores[name].combo = 0; ROOM_players_scores[name].combo = 0;
}; };
ROOM_player_get_score = function(player) { ROOM_player_get_score = global.ROOM_player_get_score = function(player) {
var name, score, total; var name, score, total;
name = player.name_vpass; name = player.name_vpass;
score = ROOM_players_scores[name]; score = ROOM_players_scores[name];
...@@ -671,7 +671,7 @@ ...@@ -671,7 +671,7 @@
}, 60000); }, 60000);
} }
ROOM_find_or_create_by_name = function(name, player_ip) { ROOM_find_or_create_by_name = global.ROOM_find_or_create_by_name = function(name, player_ip) {
var room, uname; var room, uname;
uname = name.toUpperCase(); uname = name.toUpperCase();
if (settings.modules.windbot.enabled && (uname.slice(0, 2) === 'AI' || (!settings.modules.random_duel.enabled && uname === ''))) { if (settings.modules.windbot.enabled && (uname.slice(0, 2) === 'AI' || (!settings.modules.random_duel.enabled && uname === ''))) {
...@@ -689,7 +689,7 @@ ...@@ -689,7 +689,7 @@
} }
}; };
ROOM_find_or_create_random = function(type, player_ip) { ROOM_find_or_create_random = global.ROOM_find_or_create_random = function(type, player_ip) {
var bannedplayer, max_player, name, playerbanned, result; var bannedplayer, max_player, name, playerbanned, result;
bannedplayer = _.find(ROOM_players_banned, function(bannedplayer) { bannedplayer = _.find(ROOM_players_banned, function(bannedplayer) {
return player_ip === bannedplayer.ip; return player_ip === bannedplayer.ip;
...@@ -738,7 +738,7 @@ ...@@ -738,7 +738,7 @@
return result; return result;
}; };
ROOM_find_or_create_ai = function(name) { ROOM_find_or_create_ai = global.ROOM_find_or_create_ai = function(name) {
var ainame, namea, result, room, uname, windbot; var ainame, namea, result, room, uname, windbot;
if (name === '') { if (name === '') {
name = 'AI'; name = 'AI';
...@@ -777,7 +777,7 @@ ...@@ -777,7 +777,7 @@
return result; return result;
}; };
ROOM_find_by_name = function(name) { ROOM_find_by_name = global.ROOM_find_by_name = function(name) {
var result; var result;
result = _.find(ROOM_all, function(room) { result = _.find(ROOM_all, function(room) {
return room && room.name === name; return room && room.name === name;
...@@ -785,7 +785,7 @@ ...@@ -785,7 +785,7 @@
return result; return result;
}; };
ROOM_find_by_title = function(title) { ROOM_find_by_title = global.ROOM_find_by_title = function(title) {
var result; var result;
result = _.find(ROOM_all, function(room) { result = _.find(ROOM_all, function(room) {
return room && room.title === title; return room && room.title === title;
...@@ -793,13 +793,19 @@ ...@@ -793,13 +793,19 @@
return result; return result;
}; };
ROOM_find_by_port = function(port) { ROOM_find_by_port = global.ROOM_find_by_port = function(port) {
return _.find(ROOM_all, function(room) { return _.find(ROOM_all, function(room) {
return room && room.port === port; return room && room.port === port;
}); });
}; };
ROOM_validate = function(name) { ROOM_find_by_pid = global.ROOM_find_by_pid = function(pid) {
return _.find(ROOM_all, function(room) {
return room && room.process_pid === pid;
});
};
ROOM_validate = global.ROOM_validate = function(name) {
var client_name, client_name_and_pass, client_pass; var client_name, client_name_and_pass, client_pass;
client_name_and_pass = name.split('$', 2); client_name_and_pass = name.split('$', 2);
client_name = client_name_and_pass[0]; client_name = client_name_and_pass[0];
...@@ -819,7 +825,7 @@ ...@@ -819,7 +825,7 @@
}); });
}; };
ROOM_unwelcome = function(room, bad_player, reason) { ROOM_unwelcome = global.ROOM_unwelcome = function(room, bad_player, reason) {
var len2, m, player, ref2; var len2, m, player, ref2;
if (!room) { if (!room) {
return; return;
...@@ -836,7 +842,7 @@ ...@@ -836,7 +842,7 @@
} }
}; };
CLIENT_kick = function(client) { CLIENT_kick = global.CLIENT_kick = function(client) {
if (!client) { if (!client) {
return false; return false;
} }
...@@ -851,7 +857,7 @@ ...@@ -851,7 +857,7 @@
return true; return true;
}; };
release_disconnect = function(dinfo, reconnected) { release_disconnect = global.release_disconnect = function(dinfo, reconnected) {
if (dinfo.old_client && !reconnected) { if (dinfo.old_client && !reconnected) {
dinfo.old_client.destroy(); dinfo.old_client.destroy();
} }
...@@ -861,7 +867,7 @@ ...@@ -861,7 +867,7 @@
clearTimeout(dinfo.timeout); clearTimeout(dinfo.timeout);
}; };
CLIENT_get_authorize_key = function(client) { CLIENT_get_authorize_key = global.CLIENT_get_authorize_key = function(client) {
if (!settings.modules.mycard.enabled && client.vpass) { if (!settings.modules.mycard.enabled && client.vpass) {
return client.name_vpass; return client.name_vpass;
} else if (settings.modules.mycard.enabled || settings.modules.tournament_mode.enabled || settings.modules.challonge.enabled || client.is_local) { } else if (settings.modules.mycard.enabled || settings.modules.tournament_mode.enabled || settings.modules.challonge.enabled || client.is_local) {
...@@ -871,7 +877,7 @@ ...@@ -871,7 +877,7 @@
} }
}; };
CLIENT_reconnect_unregister = function(client, reconnected, exact) { CLIENT_reconnect_unregister = global.CLIENT_reconnect_unregister = function(client, reconnected, exact) {
if (!settings.modules.reconnect.enabled) { if (!settings.modules.reconnect.enabled) {
return false; return false;
} }
...@@ -886,7 +892,7 @@ ...@@ -886,7 +892,7 @@
return false; return false;
}; };
CLIENT_reconnect_register = function(client, room_id, error) { CLIENT_reconnect_register = global.CLIENT_reconnect_register = function(client, room_id, error) {
var dinfo, room, tmot; var dinfo, room, tmot;
room = ROOM_all[room_id]; room = ROOM_all[room_id];
if (client.had_new_reconnection) { if (client.had_new_reconnection) {
...@@ -918,7 +924,7 @@ ...@@ -918,7 +924,7 @@
return true; return true;
}; };
CLIENT_import_data = function(client, old_client, room) { CLIENT_import_data = global.CLIENT_import_data = function(client, old_client, room) {
var index, key, len2, len3, m, n, player, ref2; var index, key, len2, len3, m, n, player, ref2;
ref2 = room.players; ref2 = room.players;
for (index = m = 0, len2 = ref2.length; m < len2; index = ++m) { for (index = m = 0, len2 = ref2.length; m < len2; index = ++m) {
...@@ -945,7 +951,7 @@ ...@@ -945,7 +951,7 @@
old_client.had_new_reconnection = true; old_client.had_new_reconnection = true;
}; };
SERVER_clear_disconnect = function(server) { SERVER_clear_disconnect = global.SERVER_clear_disconnect = function(server) {
var k, v; var k, v;
if (!settings.modules.reconnect.enabled) { if (!settings.modules.reconnect.enabled) {
return false; return false;
...@@ -961,7 +967,7 @@ ...@@ -961,7 +967,7 @@
return false; return false;
}; };
ROOM_clear_disconnect = function(room_id) { ROOM_clear_disconnect = global.ROOM_clear_disconnect = function(room_id) {
var k, v; var k, v;
if (!settings.modules.reconnect.enabled) { if (!settings.modules.reconnect.enabled) {
return false; return false;
...@@ -977,7 +983,7 @@ ...@@ -977,7 +983,7 @@
return false; return false;
}; };
CLIENT_is_player = function(client, room) { CLIENT_is_player = global.CLIENT_is_player = function(client, room) {
var is_player, len2, m, player, ref2; var is_player, len2, m, player, ref2;
is_player = false; is_player = false;
ref2 = room.players; ref2 = room.players;
...@@ -991,7 +997,7 @@ ...@@ -991,7 +997,7 @@
return is_player && client.pos <= 3; return is_player && client.pos <= 3;
}; };
CLIENT_is_able_to_reconnect = function(client, deckbuf) { CLIENT_is_able_to_reconnect = global.CLIENT_is_able_to_reconnect = function(client, deckbuf) {
var disconnect_info, room; var disconnect_info, room;
if (!settings.modules.reconnect.enabled) { if (!settings.modules.reconnect.enabled) {
return false; return false;
...@@ -1014,7 +1020,7 @@ ...@@ -1014,7 +1020,7 @@
return true; return true;
}; };
CLIENT_get_kick_reconnect_target = function(client, deckbuf) { CLIENT_get_kick_reconnect_target = global.CLIENT_get_kick_reconnect_target = function(client, deckbuf) {
var len2, len3, m, n, player, ref2, room; var len2, len3, m, n, player, ref2, room;
for (m = 0, len2 = ROOM_all.length; m < len2; m++) { for (m = 0, len2 = ROOM_all.length; m < len2; m++) {
room = ROOM_all[m]; room = ROOM_all[m];
...@@ -1031,7 +1037,7 @@ ...@@ -1031,7 +1037,7 @@
return null; return null;
}; };
CLIENT_is_able_to_kick_reconnect = function(client, deckbuf) { CLIENT_is_able_to_kick_reconnect = global.CLIENT_is_able_to_kick_reconnect = function(client, deckbuf) {
if (!(settings.modules.reconnect.enabled && settings.modules.reconnect.allow_kick_reconnect)) { if (!(settings.modules.reconnect.enabled && settings.modules.reconnect.allow_kick_reconnect)) {
return false; return false;
} }
...@@ -1041,7 +1047,7 @@ ...@@ -1041,7 +1047,7 @@
return true; return true;
}; };
CLIENT_send_pre_reconnect_info = function(client, room, old_client) { CLIENT_send_pre_reconnect_info = global.CLIENT_send_pre_reconnect_info = function(client, room, old_client) {
var len2, m, player, ref2, req_pos; var len2, m, player, ref2, req_pos;
ygopro.stoc_send_chat(client, "${pre_reconnecting_to_room}", ygopro.constants.COLORS.BABYBLUE); ygopro.stoc_send_chat(client, "${pre_reconnecting_to_room}", ygopro.constants.COLORS.BABYBLUE);
ygopro.stoc_send(client, 'JOIN_GAME', room.join_game_buffer); ygopro.stoc_send(client, 'JOIN_GAME', room.join_game_buffer);
...@@ -1062,7 +1068,7 @@ ...@@ -1062,7 +1068,7 @@
} }
}; };
CLIENT_send_reconnect_info = function(client, server, room) { CLIENT_send_reconnect_info = global.CLIENT_send_reconnect_info = function(client, server, room) {
client.reconnecting = true; client.reconnecting = true;
ygopro.stoc_send_chat(client, "${reconnecting_to_room}", ygopro.constants.COLORS.BABYBLUE); ygopro.stoc_send_chat(client, "${reconnecting_to_room}", ygopro.constants.COLORS.BABYBLUE);
switch (room.duel_stage) { switch (room.duel_stage) {
...@@ -1093,7 +1099,7 @@ ...@@ -1093,7 +1099,7 @@
} }
}; };
CLIENT_pre_reconnect = function(client) { CLIENT_pre_reconnect = global.CLIENT_pre_reconnect = function(client) {
var dinfo, player; var dinfo, player;
if (CLIENT_is_able_to_reconnect(client)) { if (CLIENT_is_able_to_reconnect(client)) {
dinfo = disconnect_list[CLIENT_get_authorize_key(client)]; dinfo = disconnect_list[CLIENT_get_authorize_key(client)];
...@@ -1110,7 +1116,7 @@ ...@@ -1110,7 +1116,7 @@
} }
}; };
CLIENT_reconnect = function(client) { CLIENT_reconnect = global.CLIENT_reconnect = function(client) {
var current_old_server, dinfo, room; var current_old_server, dinfo, room;
if (!CLIENT_is_able_to_reconnect(client)) { if (!CLIENT_is_able_to_reconnect(client)) {
ygopro.stoc_send_chat(client, "${reconnect_failed}", ygopro.constants.COLORS.RED); ygopro.stoc_send_chat(client, "${reconnect_failed}", ygopro.constants.COLORS.RED);
...@@ -1138,7 +1144,7 @@ ...@@ -1138,7 +1144,7 @@
CLIENT_reconnect_unregister(client, true); CLIENT_reconnect_unregister(client, true);
}; };
CLIENT_kick_reconnect = function(client, deckbuf) { CLIENT_kick_reconnect = global.CLIENT_kick_reconnect = function(client, deckbuf) {
var current_old_server, player, room; var current_old_server, player, room;
if (!CLIENT_is_able_to_kick_reconnect(client)) { if (!CLIENT_is_able_to_kick_reconnect(client)) {
ygopro.stoc_send_chat(client, "${reconnect_failed}", ygopro.constants.COLORS.RED); ygopro.stoc_send_chat(client, "${reconnect_failed}", ygopro.constants.COLORS.RED);
...@@ -1173,7 +1179,7 @@ ...@@ -1173,7 +1179,7 @@
disconnect_list = {}; disconnect_list = {};
} }
CLIENT_heartbeat_unregister = function(client) { CLIENT_heartbeat_unregister = global.CLIENT_heartbeat_unregister = function(client) {
if (!settings.modules.heartbeat_detection.enabled || !client.heartbeat_timeout) { if (!settings.modules.heartbeat_detection.enabled || !client.heartbeat_timeout) {
return false; return false;
} }
...@@ -1182,7 +1188,7 @@ ...@@ -1182,7 +1188,7 @@
return true; return true;
}; };
CLIENT_heartbeat_register = function(client, send) { CLIENT_heartbeat_register = global.CLIENT_heartbeat_register = function(client, send) {
if (!settings.modules.heartbeat_detection.enabled || client.closed || client.is_post_watcher || client.pre_reconnecting || client.reconnecting || client.waiting_for_last || client.pos > 3 || client.heartbeat_protected) { if (!settings.modules.heartbeat_detection.enabled || client.closed || client.is_post_watcher || client.pre_reconnecting || client.reconnecting || client.waiting_for_last || client.pos > 3 || client.heartbeat_protected) {
return false; return false;
} }
...@@ -1209,11 +1215,11 @@ ...@@ -1209,11 +1215,11 @@
return true; return true;
}; };
CLIENT_is_banned_by_mc = function(client) { CLIENT_is_banned_by_mc = global.CLIENT_is_banned_by_mc = function(client) {
return client.ban_mc && client.ban_mc.banned && moment().isBefore(client.ban_mc.until); return client.ban_mc && client.ban_mc.banned && moment().isBefore(client.ban_mc.until);
}; };
CLIENT_send_replays = function(client, room) { CLIENT_send_replays = global.CLIENT_send_replays = function(client, room) {
var buffer, i, len2, m, ref2; var buffer, i, len2, m, ref2;
if (!(settings.modules.replay_delay && !(settings.modules.tournament_mode.enabled && settings.modules.tournament_mode.replay_safe && settings.modules.tournament_mode.block_replay_to_player) && room.replays.length && room.hostinfo.mode === 1 && !client.replays_sent && !client.closed)) { if (!(settings.modules.replay_delay && !(settings.modules.tournament_mode.enabled && settings.modules.tournament_mode.replay_safe && settings.modules.tournament_mode.block_replay_to_player) && room.replays.length && room.hostinfo.mode === 1 && !client.replays_sent && !client.closed)) {
return false; return false;
...@@ -1232,7 +1238,7 @@ ...@@ -1232,7 +1238,7 @@
return true; return true;
}; };
SOCKET_flush_data = function(sk, datas) { SOCKET_flush_data = global.SOCKET_flush_data = function(sk, datas) {
var buffer, len2, m; var buffer, len2, m;
if (!sk || sk.closed) { if (!sk || sk.closed) {
return false; return false;
...@@ -2031,7 +2037,7 @@ ...@@ -2031,7 +2037,7 @@
} }
client.pre_establish_buffers = new Array(); client.pre_establish_buffers = new Array();
client.on('data', function(ctos_buffer) { client.on('data', function(ctos_buffer) {
var b, bad_ip_count, buffer, cancel, ctos_message_length, ctos_proto, datas, info, len2, len3, looplimit, m, n, room, struct; var b, bad_ip_count, buffer, cancel, ctos_event, ctos_message_length, ctos_proto, datas, info, len2, len3, len4, len5, looplimit, m, n, o, p, ref2, ref3, result, room, struct;
if (client.is_post_watcher) { if (client.is_post_watcher) {
room = ROOM_all[client.rid]; room = ROOM_all[client.rid];
if (room && !CLIENT_is_banned_by_mc(client)) { if (room && !CLIENT_is_banned_by_mc(client)) {
...@@ -2065,17 +2071,36 @@ ...@@ -2065,17 +2071,36 @@
if (settings.modules.reconnect.enabled && client.pre_reconnecting && ygopro.constants.CTOS[ctos_proto] !== 'UPDATE_DECK') { if (settings.modules.reconnect.enabled && client.pre_reconnecting && ygopro.constants.CTOS[ctos_proto] !== 'UPDATE_DECK') {
cancel = true; cancel = true;
} }
if (ygopro.ctos_follows[ctos_proto] && !cancel) {
b = ctos_buffer.slice(3, ctos_message_length - 1 + 3); b = ctos_buffer.slice(3, ctos_message_length - 1 + 3);
info = null; info = null;
if (struct = ygopro.structs[ygopro.proto_structs.CTOS[ygopro.constants.CTOS[ctos_proto]]]) { if (struct = ygopro.structs[ygopro.proto_structs.CTOS[ygopro.constants.CTOS[ctos_proto]]]) {
struct._setBuff(b); struct._setBuff(b);
info = _.clone(struct.fields); info = _.clone(struct.fields);
} }
if (ygopro.ctos_follows[ctos_proto].synchronous) { if (ygopro.ctos_follows_before[ctos_proto] && !cancel) {
cancel = ygopro.ctos_follows[ctos_proto].callback(b, info, client, client.server, datas); ref2 = ygopro.ctos_follows_before[ctos_proto];
} else { for (m = 0, len2 = ref2.length; m < len2; m++) {
ygopro.ctos_follows[ctos_proto].callback(b, info, client, client.server, datas); ctos_event = ref2[m];
result = ctos_event.callback(b, info, client, client.server, datas);
if (result && ctos_event.synchronous) {
cancel = true;
}
}
}
if (ygopro.ctos_follows[ctos_proto] && !cancel) {
result = ygopro.ctos_follows[ctos_proto].callback(b, info, client, client.server, datas);
if (result && ygopro.ctos_follows[ctos_proto].synchronous) {
cancel = true;
}
}
if (ygopro.ctos_follows_after[ctos_proto] && !cancel) {
ref3 = ygopro.ctos_follows_after[ctos_proto];
for (n = 0, len3 = ref3.length; n < len3; n++) {
ctos_event = ref3[n];
result = ctos_event.callback(b, info, client, client.server, datas);
if (result && ctos_event.synchronous) {
cancel = true;
}
} }
} }
if (!cancel) { if (!cancel) {
...@@ -2108,20 +2133,20 @@ ...@@ -2108,20 +2133,20 @@
return; return;
} }
if (client.established) { if (client.established) {
for (m = 0, len2 = datas.length; m < len2; m++) { for (o = 0, len4 = datas.length; o < len4; o++) {
buffer = datas[m]; buffer = datas[o];
client.server.write(buffer); client.server.write(buffer);
} }
} else { } else {
for (n = 0, len3 = datas.length; n < len3; n++) { for (p = 0, len5 = datas.length; p < len5; p++) {
buffer = datas[n]; buffer = datas[p];
client.pre_establish_buffers.push(buffer); client.pre_establish_buffers.push(buffer);
} }
} }
} }
}); });
server.on('data', function(stoc_buffer) { server.on('data', function(stoc_buffer) {
var b, buffer, cancel, datas, info, len2, looplimit, m, stanzas, stoc_message_length, stoc_proto, struct; var b, buffer, cancel, datas, info, len2, len3, len4, looplimit, m, n, o, ref2, ref3, result, stoc_event, stoc_message_length, stoc_proto, struct;
stoc_message_length = 0; stoc_message_length = 0;
stoc_proto = 0; stoc_proto = 0;
datas = []; datas = [];
...@@ -2146,18 +2171,36 @@ ...@@ -2146,18 +2171,36 @@
} else { } else {
if (stoc_buffer.length >= 2 + stoc_message_length) { if (stoc_buffer.length >= 2 + stoc_message_length) {
cancel = false; cancel = false;
stanzas = stoc_proto;
if (ygopro.stoc_follows[stoc_proto]) {
b = stoc_buffer.slice(3, stoc_message_length - 1 + 3); b = stoc_buffer.slice(3, stoc_message_length - 1 + 3);
info = null; info = null;
if (struct = ygopro.structs[ygopro.proto_structs.STOC[ygopro.constants.STOC[stoc_proto]]]) { if (struct = ygopro.structs[ygopro.proto_structs.STOC[ygopro.constants.STOC[stoc_proto]]]) {
struct._setBuff(b); struct._setBuff(b);
info = _.clone(struct.fields); info = _.clone(struct.fields);
} }
if (ygopro.stoc_follows[stoc_proto].synchronous) { if (ygopro.stoc_follows_before[stoc_proto] && !cancel) {
cancel = ygopro.stoc_follows[stoc_proto].callback(b, info, server.client, server, datas); ref2 = ygopro.stoc_follows_before[stoc_proto];
} else { for (m = 0, len2 = ref2.length; m < len2; m++) {
ygopro.stoc_follows[stoc_proto].callback(b, info, server.client, server, datas); stoc_event = ref2[m];
result = stoc_event.callback(b, info, server.client, server, datas);
if (result && stoc_event.synchronous) {
cancel = true;
}
}
}
if (ygopro.stoc_follows[stoc_proto] && !cancel) {
result = ygopro.stoc_follows[stoc_proto].callback(b, info, server.client, server, datas);
if (result && ygopro.stoc_follows[stoc_proto].synchronous) {
cancel = true;
}
}
if (ygopro.stoc_follows_after[stoc_proto] && !cancel) {
ref3 = ygopro.stoc_follows_after[stoc_proto];
for (n = 0, len3 = ref3.length; n < len3; n++) {
stoc_event = ref3[n];
result = stoc_event.callback(b, info, server.client, server, datas);
if (result && stoc_event.synchronous) {
cancel = true;
}
} }
} }
if (!cancel) { if (!cancel) {
...@@ -2179,8 +2222,8 @@ ...@@ -2179,8 +2222,8 @@
} }
} }
if (server.client && !server.client.closed) { if (server.client && !server.client.closed) {
for (m = 0, len2 = datas.length; m < len2; m++) { for (o = 0, len4 = datas.length; o < len4; o++) {
buffer = datas[m]; buffer = datas[o];
server.client.write(buffer); server.client.write(buffer);
} }
} }
...@@ -2798,7 +2841,7 @@ ...@@ -2798,7 +2841,7 @@
} }
}); });
load_dialogues = function() { load_dialogues = global.load_dialogues = function() {
request({ request({
url: settings.modules.dialogues.get, url: settings.modules.dialogues.get,
json: true json: true
...@@ -3422,7 +3465,7 @@ ...@@ -3422,7 +3465,7 @@
} }
}; };
load_tips = function() { load_tips = global.load_tips = function() {
request({ request({
url: settings.modules.tips.get, url: settings.modules.tips.get,
json: true json: true
...@@ -3567,7 +3610,7 @@ ...@@ -3567,7 +3610,7 @@
return false; return false;
}); });
report_to_big_brother = function(roomname, sender, ip, level, content, match) { report_to_big_brother = global.report_to_big_brother = function(roomname, sender, ip, level, content, match) {
if (!settings.modules.big_brother.enabled) { if (!settings.modules.big_brother.enabled) {
return; return;
} }
...@@ -4360,9 +4403,9 @@ ...@@ -4360,9 +4403,9 @@
windbot_looplimit = 0; windbot_looplimit = 0;
windbot_process = null; windbot_process = global.windbot_process = null;
spawn_windbot = function() { spawn_windbot = global.spawn_windbot = function() {
var windbot_bin, windbot_parameters; var windbot_bin, windbot_parameters;
if (/^win/.test(process.platform)) { if (/^win/.test(process.platform)) {
windbot_bin = 'WindBot.exe'; windbot_bin = 'WindBot.exe';
...@@ -4773,4 +4816,16 @@ ...@@ -4773,4 +4816,16 @@
} }
} }
if (!fs.existsSync('./plugins')) {
fs.mkdirSync('./plugins');
}
plugin_list = fs.readdirSync("./plugins");
for (m = 0, len2 = plugin_list.length; m < len2; m++) {
plugin_filename = plugin_list[m];
plugin_path = "./plugins/" + plugin_filename;
require(plugin_path);
}
}).call(this); }).call(this);
...@@ -37,26 +37,55 @@ for name, declaration of structs_declaration ...@@ -37,26 +37,55 @@ for name, declaration of structs_declaration
#消息跟踪函数 需要重构, 另暂时只支持异步, 同步没做. #消息跟踪函数 需要重构, 另暂时只支持异步, 同步没做.
@stoc_follows = {} @stoc_follows = {}
@stoc_follows_before = {}
@stoc_follows_after = {}
@ctos_follows = {} @ctos_follows = {}
@stoc_follow = (proto, synchronous, callback)-> @ctos_follows_before = {}
if typeof proto == 'string' @ctos_follows_after = {}
for key, value of @constants.STOC
@replace_proto = (proto, tp) ->
if typeof(proto) != "string"
return proto
changed_proto = proto
for key, value of @constants[tp]
if value == proto if value == proto
proto = key changed_proto = key
break break
throw "unknown proto" if !@constants.STOC[proto] throw "unknown proto" if !@constants[tp][changed_proto]
@stoc_follows[proto] = {callback: callback, synchronous: synchronous} return changed_proto
@stoc_follow = (proto, synchronous, callback)->
changed_proto = @replace_proto(proto, "STOC")
@stoc_follows[changed_proto] = {callback: callback, synchronous: synchronous}
return
@stoc_follow_before = (proto, synchronous, callback)->
changed_proto = @replace_proto(proto, "STOC")
if !@stoc_follows_before[changed_proto]
@stoc_follows_before[changed_proto] = []
@stoc_follows_before[changed_proto].push({callback: callback, synchronous: synchronous})
return
@stoc_follow_after = (proto, synchronous, callback)->
changed_proto = @replace_proto(proto, "STOC")
if !@stoc_follows_after[changed_proto]
@stoc_follows_after[changed_proto] = []
@stoc_follows_after[changed_proto].push({callback: callback, synchronous: synchronous})
return return
@ctos_follow = (proto, synchronous, callback)-> @ctos_follow = (proto, synchronous, callback)->
if typeof proto == 'string' changed_proto = @replace_proto(proto, "CTOS")
for key, value of @constants.CTOS @ctos_follows[changed_proto] = {callback: callback, synchronous: synchronous}
if value == proto return
proto = key @ctos_follow_before = (proto, synchronous, callback)->
break changed_proto = @replace_proto(proto, "CTOS")
throw "unknown proto" if !@constants.CTOS[proto] if !@ctos_follows_before[changed_proto]
@ctos_follows[proto] = {callback: callback, synchronous: synchronous} @ctos_follows_before[changed_proto] = []
@ctos_follows_before[changed_proto].push({callback: callback, synchronous: synchronous})
return
@ctos_follow_after = (proto, synchronous, callback)->
changed_proto = @replace_proto(proto, "CTOS")
if !@ctos_follows_after[changed_proto]
@ctos_follows_after[changed_proto] = []
@ctos_follows_after[changed_proto].push({callback: callback, synchronous: synchronous})
return return
#消息发送函数,至少要把俩合起来.... #消息发送函数,至少要把俩合起来....
@stoc_send = (socket, proto, info)-> @stoc_send = (socket, proto, info)->
......
...@@ -58,48 +58,100 @@ ...@@ -58,48 +58,100 @@
this.stoc_follows = {}; this.stoc_follows = {};
this.stoc_follows_before = {};
this.stoc_follows_after = {};
this.ctos_follows = {}; this.ctos_follows = {};
this.stoc_follow = function(proto, synchronous, callback) { this.ctos_follows_before = {};
var key, ref, value;
if (typeof proto === 'string') { this.ctos_follows_after = {};
ref = this.constants.STOC;
this.replace_proto = function(proto, tp) {
var changed_proto, key, ref, value;
if (typeof proto !== "string") {
return proto;
}
changed_proto = proto;
ref = this.constants[tp];
for (key in ref) { for (key in ref) {
value = ref[key]; value = ref[key];
if (value === proto) { if (value === proto) {
proto = key; changed_proto = key;
break; break;
} }
} }
if (!this.constants.STOC[proto]) { if (!this.constants[tp][changed_proto]) {
throw "unknown proto"; throw "unknown proto";
} }
} return changed_proto;
this.stoc_follows[proto] = { };
this.stoc_follow = function(proto, synchronous, callback) {
var changed_proto;
changed_proto = this.replace_proto(proto, "STOC");
this.stoc_follows[changed_proto] = {
callback: callback, callback: callback,
synchronous: synchronous synchronous: synchronous
}; };
}; };
this.ctos_follow = function(proto, synchronous, callback) { this.stoc_follow_before = function(proto, synchronous, callback) {
var key, ref, value; var changed_proto;
if (typeof proto === 'string') { changed_proto = this.replace_proto(proto, "STOC");
ref = this.constants.CTOS; if (!this.stoc_follows_before[changed_proto]) {
for (key in ref) { this.stoc_follows_before[changed_proto] = [];
value = ref[key];
if (value === proto) {
proto = key;
break;
}
} }
if (!this.constants.CTOS[proto]) { this.stoc_follows_before[changed_proto].push({
throw "unknown proto"; callback: callback,
synchronous: synchronous
});
};
this.stoc_follow_after = function(proto, synchronous, callback) {
var changed_proto;
changed_proto = this.replace_proto(proto, "STOC");
if (!this.stoc_follows_after[changed_proto]) {
this.stoc_follows_after[changed_proto] = [];
} }
this.stoc_follows_after[changed_proto].push({
callback: callback,
synchronous: synchronous
});
};
this.ctos_follow = function(proto, synchronous, callback) {
var changed_proto;
changed_proto = this.replace_proto(proto, "CTOS");
this.ctos_follows[changed_proto] = {
callback: callback,
synchronous: synchronous
};
};
this.ctos_follow_before = function(proto, synchronous, callback) {
var changed_proto;
changed_proto = this.replace_proto(proto, "CTOS");
if (!this.ctos_follows_before[changed_proto]) {
this.ctos_follows_before[changed_proto] = [];
} }
this.ctos_follows[proto] = { this.ctos_follows_before[changed_proto].push({
callback: callback, callback: callback,
synchronous: synchronous synchronous: synchronous
});
}; };
this.ctos_follow_after = function(proto, synchronous, callback) {
var changed_proto;
changed_proto = this.replace_proto(proto, "CTOS");
if (!this.ctos_follows_after[changed_proto]) {
this.ctos_follows_after[changed_proto] = [];
}
this.ctos_follows_after[changed_proto].push({
callback: callback,
synchronous: synchronous
});
}; };
this.stoc_send = function(socket, proto, info) { this.stoc_send = function(socket, proto, info) {
......
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