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*
.dockerignore
Dockerfile*
......
......@@ -19,6 +19,7 @@ config.user.bak
/ygosrv233
/challonge
/logs
/plugins
test*
*.heapsnapshot
......
......@@ -131,11 +131,11 @@ try
catch e
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))
return
setting_change = (settings, path, val) ->
setting_change = global.setting_change = (settings, path, val) ->
# path should be like "modules:welcome"
log.info("setting changed", path, val) if _.isString(val)
path=path.split(':')
......@@ -159,7 +159,7 @@ catch
config = {}
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
imported = false
......@@ -227,29 +227,29 @@ if imported
# 读取数据
default_data = loadJSON('./data/default_data.json')
try
tips = loadJSON('./config/tips.json')
tips = global.tips = loadJSON('./config/tips.json')
catch
tips = default_data.tips
tips = global.tips = default_data.tips
setting_save(tips)
try
dialogues = loadJSON('./config/dialogues.json')
dialogues = global.dialogues = loadJSON('./config/dialogues.json')
catch
dialogues = default_data.dialogues
dialogues = global.dialogues = default_data.dialogues
setting_save(dialogues)
try
badwords = loadJSON('./config/badwords.json')
badwords = global.badwords = loadJSON('./config/badwords.json')
catch
badwords = default_data.badwords
badwords = global.badwords = default_data.badwords
setting_save(badwords)
try
duel_log = loadJSON('./config/duel_log.json')
duel_log = global.duel_log = loadJSON('./config/duel_log.json')
catch
duel_log = default_data.duel_log
duel_log = global.duel_log = default_data.duel_log
setting_save(duel_log)
try
chat_color = loadJSON('./config/chat_color.json')
chat_color = global.chat_color = loadJSON('./config/chat_color.json')
catch
chat_color = default_data.chat_color
chat_color = global.chat_color = default_data.chat_color
setting_save(chat_color)
try
......@@ -260,7 +260,7 @@ catch
#settings.version = settings.version_default
log.info "ygopro version 0x"+settings.version.toString(16), "(from config)"
# load the lflist of current date
lflists = []
lflists = global.lflists = []
# expansions/lflist
try
for list in fs.readFileSync('ygopro/expansions/lflist.conf', 'utf8').match(/!.*/g)
......@@ -296,11 +296,11 @@ if settings.modules.windbot.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'
roomlist = require './roomlist.js' if settings.modules.http.websocket_roomlist
ygopro = global.ygopro = require './ygopro.js'
roomlist = global.roomlist = require './roomlist.js' if settings.modules.http.websocket_roomlist
if settings.modules.i18n.auto_pick
geoip = require('geoip-country-lite')
......@@ -416,8 +416,8 @@ if settings.modules.challonge.enabled
setInterval(refresh_challonge_cache, settings.modules.challonge.cache_ttl)
# 获取可用内存
memory_usage = 0
get_memory_usage = ()->
memory_usage = global.memory_usage = 0
get_memory_usage = get_memory_usage = ()->
prc_free = exec("free")
prc_free.stdout.on 'data', (data)->
lines = data.toString().split(/\n/g)
......@@ -439,17 +439,17 @@ get_memory_usage = ()->
get_memory_usage()
setInterval(get_memory_usage, 3000)
Cloud_replay_ids = []
Cloud_replay_ids = global.Cloud_replay_ids = []
ROOM_all = []
ROOM_players_oppentlist = {}
ROOM_players_banned = []
ROOM_players_scores = {}
ROOM_connected_ip = {}
ROOM_bad_ip = {}
ROOM_all = global.ROOM_all = []
ROOM_players_oppentlist = global.ROOM_players_oppentlist = {}
ROOM_players_banned = global.ROOM_players_banned = []
ROOM_players_scores = global.ROOM_players_scores = {}
ROOM_connected_ip = global.ROOM_connected_ip = {}
ROOM_bad_ip = global.ROOM_bad_ip = {}
# ban a user manually and permanently
ban_user = (name) ->
ban_user = global.ban_user = (name) ->
settings.ban.banned_user.push(name)
setting_save(settings)
bad_ip=0
......@@ -466,7 +466,7 @@ ban_user = (name) ->
return
# 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
bannedplayer = _.find ROOM_players_banned, (bannedplayer)->
ip == bannedplayer.ip
......@@ -483,28 +483,28 @@ ROOM_ban_player = (name, ip, reason, countadd = 1)->
#log.info("banned", name, ip, reason, bannedplayer.count)
return
ROOM_player_win = (name)->
ROOM_player_win = global.ROOM_player_win = (name)->
if !ROOM_players_scores[name]
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].combo = ROOM_players_scores[name].combo + 1
return
ROOM_player_lose = (name)->
ROOM_player_lose = global.ROOM_player_lose = (name)->
if !ROOM_players_scores[name]
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].combo = 0
return
ROOM_player_flee = (name)->
ROOM_player_flee = global.ROOM_player_flee = (name)->
if !ROOM_players_scores[name]
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].combo = 0
return
ROOM_player_get_score = (player)->
ROOM_player_get_score = global.ROOM_player_get_score = (player)->
name = player.name_vpass
score = ROOM_players_scores[name]
if !score
......@@ -541,7 +541,7 @@ if settings.modules.random_duel.post_match_scores
return
, 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()
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)
......@@ -554,7 +554,7 @@ ROOM_find_or_create_by_name = (name, player_ip)->
else
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)->
return player_ip == bannedplayer.ip
if bannedplayer
......@@ -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}'
return result
ROOM_find_or_create_ai = (name)->
ROOM_find_or_create_ai = global.ROOM_find_or_create_ai = (name)->
if name == ''
name = 'AI'
namea = name.split('#')
......@@ -622,21 +622,25 @@ ROOM_find_or_create_ai = (name)->
result.private = true
return result
ROOM_find_by_name = (name)->
ROOM_find_by_name = global.ROOM_find_by_name = (name)->
result = _.find ROOM_all, (room)->
return room and room.name == name
return result
ROOM_find_by_title = (title)->
ROOM_find_by_title = global.ROOM_find_by_title = (title)->
result = _.find ROOM_all, (room)->
return room and room.title == title
return result
ROOM_find_by_port = (port)->
ROOM_find_by_port = global.ROOM_find_by_port = (port)->
_.find ROOM_all, (room)->
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 = client_name_and_pass[0]
client_pass = client_name_and_pass[1]
......@@ -648,7 +652,7 @@ ROOM_validate = (name)->
room_pass = room_name_and_pass[1]
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
for player in room.players
if player and player == bad_player
......@@ -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)
return
CLIENT_kick = (client) ->
CLIENT_kick = global.CLIENT_kick = (client) ->
if !client
return false
client.system_kicked = true
......@@ -669,7 +673,7 @@ CLIENT_kick = (client) ->
client.destroy()
return true
release_disconnect = (dinfo, reconnected) ->
release_disconnect = global.release_disconnect = (dinfo, reconnected) ->
if dinfo.old_client and !reconnected
dinfo.old_client.destroy()
if dinfo.old_server and !reconnected
......@@ -677,7 +681,7 @@ release_disconnect = (dinfo, reconnected) ->
clearTimeout(dinfo.timeout)
return
CLIENT_get_authorize_key = (client) ->
CLIENT_get_authorize_key = global.CLIENT_get_authorize_key = (client) ->
if !settings.modules.mycard.enabled and client.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
......@@ -685,7 +689,7 @@ CLIENT_get_authorize_key = (client) ->
else
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
return false
if disconnect_list[CLIENT_get_authorize_key(client)]
......@@ -696,7 +700,7 @@ CLIENT_reconnect_unregister = (client, reconnected, exact) ->
return true
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]
if client.had_new_reconnection
return false
......@@ -727,7 +731,7 @@ CLIENT_reconnect_register = (client, room_id, error) ->
ygopro.ctos_send(client.server, 'SURRENDER')
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
if player == old_client
room.players[index] = client
......@@ -744,7 +748,7 @@ CLIENT_import_data = (client, old_client, room) ->
old_client.had_new_reconnection = true
return
SERVER_clear_disconnect = (server) ->
SERVER_clear_disconnect = global.SERVER_clear_disconnect = (server) ->
return false unless settings.modules.reconnect.enabled
for k,v of disconnect_list
if v and server == v.old_server
......@@ -753,7 +757,7 @@ SERVER_clear_disconnect = (server) ->
return true
return false
ROOM_clear_disconnect = (room_id) ->
ROOM_clear_disconnect = global.ROOM_clear_disconnect = (room_id) ->
return false unless settings.modules.reconnect.enabled
for k,v of disconnect_list
if v and room_id == v.room_id
......@@ -762,7 +766,7 @@ ROOM_clear_disconnect = (room_id) ->
return true
return false
CLIENT_is_player = (client, room) ->
CLIENT_is_player = global.CLIENT_is_player = (client, room) ->
is_player = false
for player in room.players
if client == player
......@@ -770,7 +774,7 @@ CLIENT_is_player = (client, room) ->
break
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
return false
if client.system_kicked
......@@ -786,20 +790,20 @@ CLIENT_is_able_to_reconnect = (client, deckbuf) ->
return false
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 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 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
return false
if !CLIENT_get_kick_reconnect_target(client, deckbuf)
return false
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(client, 'JOIN_GAME', room.join_game_buffer)
req_pos = old_client.pos
......@@ -815,7 +819,7 @@ CLIENT_send_pre_reconnect_info = (client, room, old_client) ->
})
return
CLIENT_send_reconnect_info = (client, server, room) ->
CLIENT_send_reconnect_info = global.CLIENT_send_reconnect_info = (client, server, room) ->
client.reconnecting = true
ygopro.stoc_send_chat(client, "${reconnecting_to_room}", ygopro.constants.COLORS.BABYBLUE)
switch room.duel_stage
......@@ -842,7 +846,7 @@ CLIENT_send_reconnect_info = (client, server, room) ->
break
return
CLIENT_pre_reconnect = (client) ->
CLIENT_pre_reconnect = global.CLIENT_pre_reconnect = (client) ->
if CLIENT_is_able_to_reconnect(client)
dinfo = disconnect_list[CLIENT_get_authorize_key(client)]
client.pre_reconnecting = true
......@@ -857,7 +861,7 @@ CLIENT_pre_reconnect = (client) ->
CLIENT_send_pre_reconnect_info(client, ROOM_all[player.rid], player)
return
CLIENT_reconnect = (client) ->
CLIENT_reconnect = global.CLIENT_reconnect = (client) ->
if !CLIENT_is_able_to_reconnect(client)
ygopro.stoc_send_chat(client, "${reconnect_failed}", ygopro.constants.COLORS.RED)
CLIENT_kick(client)
......@@ -883,7 +887,7 @@ CLIENT_reconnect = (client) ->
CLIENT_reconnect_unregister(client, true)
return
CLIENT_kick_reconnect = (client, deckbuf) ->
CLIENT_kick_reconnect = global.CLIENT_kick_reconnect = (client, deckbuf) ->
if !CLIENT_is_able_to_kick_reconnect(client)
ygopro.stoc_send_chat(client, "${reconnect_failed}", ygopro.constants.COLORS.RED)
CLIENT_kick(client)
......@@ -915,7 +919,7 @@ CLIENT_kick_reconnect = (client, deckbuf) ->
if settings.modules.reconnect.enabled
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
return false
clearTimeout(client.heartbeat_timeout)
......@@ -923,7 +927,7 @@ CLIENT_heartbeat_unregister = (client) ->
#log.info(2, client.name)
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
return false
if client.heartbeat_timeout
......@@ -946,10 +950,10 @@ CLIENT_heartbeat_register = (client, send) ->
#log.info(1, client.name)
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)
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
client.replays_sent = true
i = 0
......@@ -960,7 +964,7 @@ CLIENT_send_replays = (client, room) ->
ygopro.stoc_send(client, "REPLAY", buffer)
return true
SOCKET_flush_data = (sk, datas) ->
SOCKET_flush_data = global.SOCKET_flush_data = (sk, datas) ->
if !sk or sk.closed
return false
for buffer in datas
......@@ -1611,16 +1615,25 @@ net.createServer (client) ->
cancel = false
if settings.modules.reconnect.enabled and client.pre_reconnecting and ygopro.constants.CTOS[ctos_proto] != 'UPDATE_DECK'
cancel = true
b = ctos_buffer.slice(3, ctos_message_length - 1 + 3)
info = null
if struct = ygopro.structs[ygopro.proto_structs.CTOS[ygopro.constants.CTOS[ctos_proto]]]
struct._setBuff(b)
info = _.clone(struct.fields)
if ygopro.ctos_follows_before[ctos_proto] and !cancel
for ctos_event in ygopro.ctos_follows_before[ctos_proto]
result = ctos_event.callback b, info, client, client.server, datas
if result and ctos_event.synchronous
cancel = true
if ygopro.ctos_follows[ctos_proto] and !cancel
b = ctos_buffer.slice(3, ctos_message_length - 1 + 3)
info = null
if struct = ygopro.structs[ygopro.proto_structs.CTOS[ygopro.constants.CTOS[ctos_proto]]]
struct._setBuff(b)
info = _.clone(struct.fields)
if ygopro.ctos_follows[ctos_proto].synchronous
cancel = ygopro.ctos_follows[ctos_proto].callback b, info, client, client.server, datas
else
ygopro.ctos_follows[ctos_proto].callback b, info, client, client.server, datas
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
ctos_buffer = ctos_buffer.slice(2 + ctos_message_length)
ctos_message_length = 0
......@@ -1679,17 +1692,25 @@ net.createServer (client) ->
if stoc_buffer.length >= 2 + stoc_message_length
#console.log "STOC", ygopro.constants.STOC[stoc_proto]
cancel = false
stanzas = stoc_proto
if ygopro.stoc_follows[stoc_proto]
b = stoc_buffer.slice(3, stoc_message_length - 1 + 3)
info = null
if struct = ygopro.structs[ygopro.proto_structs.STOC[ygopro.constants.STOC[stoc_proto]]]
struct._setBuff(b)
info = _.clone(struct.fields)
if ygopro.stoc_follows[stoc_proto].synchronous
cancel = ygopro.stoc_follows[stoc_proto].callback b, info, server.client, server, datas
else
ygopro.stoc_follows[stoc_proto].callback b, info, server.client, server, datas
b = stoc_buffer.slice(3, stoc_message_length - 1 + 3)
info = null
if struct = ygopro.structs[ygopro.proto_structs.STOC[ygopro.constants.STOC[stoc_proto]]]
struct._setBuff(b)
info = _.clone(struct.fields)
if ygopro.stoc_follows_before[stoc_proto] and !cancel
for stoc_event in ygopro.stoc_follows_before[stoc_proto]
result = stoc_event.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
stoc_buffer = stoc_buffer.slice(2 + stoc_message_length)
stoc_message_length = 0
......@@ -2262,7 +2283,7 @@ ygopro.stoc_follow 'JOIN_GAME', false, (buffer, info, client, server, datas)->
return
# 登场台词
load_dialogues = () ->
load_dialogues = global.load_dialogues = () ->
request
url: settings.modules.dialogues.get
json: true
......@@ -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)])
return
load_tips = ()->
load_tips = global.load_tips = ()->
request
url: settings.modules.tips.get
json: true
......@@ -2818,7 +2839,7 @@ ygopro.ctos_follow 'SURRENDER', true, (buffer, info, client, server, datas)->
return true
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
request.post { url : settings.modules.big_brother.post , form : {
accesskey: settings.modules.big_brother.accesskey,
......@@ -3381,9 +3402,9 @@ setInterval ()->
# spawn windbot
windbot_looplimit = 0
windbot_process = null
windbot_process = global.windbot_process = null
spawn_windbot = () ->
spawn_windbot = global.spawn_windbot = () ->
if /^win/.test(process.platform)
windbot_bin = 'WindBot.exe'
windbot_parameters = []
......@@ -3709,3 +3730,11 @@ if settings.modules.http
if settings.modules.http.websocket_roomlist and roomlist
roomlist.init https_server, ROOM_all
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
(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');
......@@ -128,11 +128,11 @@
}
}
setting_save = function(settings) {
setting_save = global.setting_save = function(settings) {
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;
if (_.isString(val)) {
log.info("setting changed", path, val);
......@@ -166,7 +166,7 @@
}
});
auth = require('./ygopro-auth.js');
auth = global.auth = require('./ygopro-auth.js');
imported = false;
......@@ -246,37 +246,37 @@
default_data = loadJSON('./data/default_data.json');
try {
tips = loadJSON('./config/tips.json');
tips = global.tips = loadJSON('./config/tips.json');
} catch (error1) {
tips = default_data.tips;
tips = global.tips = default_data.tips;
setting_save(tips);
}
try {
dialogues = loadJSON('./config/dialogues.json');
dialogues = global.dialogues = loadJSON('./config/dialogues.json');
} catch (error1) {
dialogues = default_data.dialogues;
dialogues = global.dialogues = default_data.dialogues;
setting_save(dialogues);
}
try {
badwords = loadJSON('./config/badwords.json');
badwords = global.badwords = loadJSON('./config/badwords.json');
} catch (error1) {
badwords = default_data.badwords;
badwords = global.badwords = default_data.badwords;
setting_save(badwords);
}
try {
duel_log = loadJSON('./config/duel_log.json');
duel_log = global.duel_log = loadJSON('./config/duel_log.json');
} catch (error1) {
duel_log = default_data.duel_log;
duel_log = global.duel_log = default_data.duel_log;
setting_save(duel_log);
}
try {
chat_color = loadJSON('./config/chat_color.json');
chat_color = global.chat_color = loadJSON('./config/chat_color.json');
} catch (error1) {
chat_color = default_data.chat_color;
chat_color = global.chat_color = default_data.chat_color;
setting_save(chat_color);
}
......@@ -288,7 +288,7 @@
log.info("ygopro version 0x" + settings.version.toString(16), "(from config)");
}
lflists = [];
lflists = global.lflists = [];
try {
ref = fs.readFileSync('ygopro/expansions/lflist.conf', 'utf8').match(/!.*/g);
......@@ -347,13 +347,13 @@
}
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) {
roomlist = require('./roomlist.js');
roomlist = global.roomlist = require('./roomlist.js');
}
if (settings.modules.i18n.auto_pick) {
......@@ -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;
prc_free = exec("free");
prc_free.stdout.on('data', function(data) {
......@@ -511,21 +511,21 @@
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;
settings.ban.banned_user.push(name);
setting_save(settings);
......@@ -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;
if (countadd == null) {
countadd = 1;
......@@ -583,7 +583,7 @@
}
};
ROOM_player_win = function(name) {
ROOM_player_win = global.ROOM_player_win = function(name) {
if (!ROOM_players_scores[name]) {
ROOM_players_scores[name] = {
win: 0,
......@@ -596,7 +596,7 @@
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]) {
ROOM_players_scores[name] = {
win: 0,
......@@ -609,7 +609,7 @@
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]) {
ROOM_players_scores[name] = {
win: 0,
......@@ -622,7 +622,7 @@
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;
name = player.name_vpass;
score = ROOM_players_scores[name];
......@@ -671,7 +671,7 @@
}, 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;
uname = name.toUpperCase();
if (settings.modules.windbot.enabled && (uname.slice(0, 2) === 'AI' || (!settings.modules.random_duel.enabled && uname === ''))) {
......@@ -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;
bannedplayer = _.find(ROOM_players_banned, function(bannedplayer) {
return player_ip === bannedplayer.ip;
......@@ -738,7 +738,7 @@
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;
if (name === '') {
name = 'AI';
......@@ -777,7 +777,7 @@
return result;
};
ROOM_find_by_name = function(name) {
ROOM_find_by_name = global.ROOM_find_by_name = function(name) {
var result;
result = _.find(ROOM_all, function(room) {
return room && room.name === name;
......@@ -785,7 +785,7 @@
return result;
};
ROOM_find_by_title = function(title) {
ROOM_find_by_title = global.ROOM_find_by_title = function(title) {
var result;
result = _.find(ROOM_all, function(room) {
return room && room.title === title;
......@@ -793,13 +793,19 @@
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 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;
client_name_and_pass = name.split('$', 2);
client_name = client_name_and_pass[0];
......@@ -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;
if (!room) {
return;
......@@ -836,7 +842,7 @@
}
};
CLIENT_kick = function(client) {
CLIENT_kick = global.CLIENT_kick = function(client) {
if (!client) {
return false;
}
......@@ -851,7 +857,7 @@
return true;
};
release_disconnect = function(dinfo, reconnected) {
release_disconnect = global.release_disconnect = function(dinfo, reconnected) {
if (dinfo.old_client && !reconnected) {
dinfo.old_client.destroy();
}
......@@ -861,7 +867,7 @@
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) {
return client.name_vpass;
} else if (settings.modules.mycard.enabled || settings.modules.tournament_mode.enabled || settings.modules.challonge.enabled || client.is_local) {
......@@ -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) {
return false;
}
......@@ -886,7 +892,7 @@
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;
room = ROOM_all[room_id];
if (client.had_new_reconnection) {
......@@ -918,7 +924,7 @@
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;
ref2 = room.players;
for (index = m = 0, len2 = ref2.length; m < len2; index = ++m) {
......@@ -945,7 +951,7 @@
old_client.had_new_reconnection = true;
};
SERVER_clear_disconnect = function(server) {
SERVER_clear_disconnect = global.SERVER_clear_disconnect = function(server) {
var k, v;
if (!settings.modules.reconnect.enabled) {
return false;
......@@ -961,7 +967,7 @@
return false;
};
ROOM_clear_disconnect = function(room_id) {
ROOM_clear_disconnect = global.ROOM_clear_disconnect = function(room_id) {
var k, v;
if (!settings.modules.reconnect.enabled) {
return false;
......@@ -977,7 +983,7 @@
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;
is_player = false;
ref2 = room.players;
......@@ -991,7 +997,7 @@
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;
if (!settings.modules.reconnect.enabled) {
return false;
......@@ -1014,7 +1020,7 @@
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;
for (m = 0, len2 = ROOM_all.length; m < len2; m++) {
room = ROOM_all[m];
......@@ -1031,7 +1037,7 @@
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)) {
return false;
}
......@@ -1041,7 +1047,7 @@
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;
ygopro.stoc_send_chat(client, "${pre_reconnecting_to_room}", ygopro.constants.COLORS.BABYBLUE);
ygopro.stoc_send(client, 'JOIN_GAME', room.join_game_buffer);
......@@ -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;
ygopro.stoc_send_chat(client, "${reconnecting_to_room}", ygopro.constants.COLORS.BABYBLUE);
switch (room.duel_stage) {
......@@ -1093,7 +1099,7 @@
}
};
CLIENT_pre_reconnect = function(client) {
CLIENT_pre_reconnect = global.CLIENT_pre_reconnect = function(client) {
var dinfo, player;
if (CLIENT_is_able_to_reconnect(client)) {
dinfo = disconnect_list[CLIENT_get_authorize_key(client)];
......@@ -1110,7 +1116,7 @@
}
};
CLIENT_reconnect = function(client) {
CLIENT_reconnect = global.CLIENT_reconnect = function(client) {
var current_old_server, dinfo, room;
if (!CLIENT_is_able_to_reconnect(client)) {
ygopro.stoc_send_chat(client, "${reconnect_failed}", ygopro.constants.COLORS.RED);
......@@ -1138,7 +1144,7 @@
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;
if (!CLIENT_is_able_to_kick_reconnect(client)) {
ygopro.stoc_send_chat(client, "${reconnect_failed}", ygopro.constants.COLORS.RED);
......@@ -1173,7 +1179,7 @@
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) {
return false;
}
......@@ -1182,7 +1188,7 @@
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) {
return false;
}
......@@ -1209,11 +1215,11 @@
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);
};
CLIENT_send_replays = function(client, room) {
CLIENT_send_replays = global.CLIENT_send_replays = function(client, room) {
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)) {
return false;
......@@ -1232,7 +1238,7 @@
return true;
};
SOCKET_flush_data = function(sk, datas) {
SOCKET_flush_data = global.SOCKET_flush_data = function(sk, datas) {
var buffer, len2, m;
if (!sk || sk.closed) {
return false;
......@@ -2031,7 +2037,7 @@
}
client.pre_establish_buffers = new Array();
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) {
room = ROOM_all[client.rid];
if (room && !CLIENT_is_banned_by_mc(client)) {
......@@ -2065,17 +2071,36 @@
if (settings.modules.reconnect.enabled && client.pre_reconnecting && ygopro.constants.CTOS[ctos_proto] !== 'UPDATE_DECK') {
cancel = true;
}
b = ctos_buffer.slice(3, ctos_message_length - 1 + 3);
info = null;
if (struct = ygopro.structs[ygopro.proto_structs.CTOS[ygopro.constants.CTOS[ctos_proto]]]) {
struct._setBuff(b);
info = _.clone(struct.fields);
}
if (ygopro.ctos_follows_before[ctos_proto] && !cancel) {
ref2 = ygopro.ctos_follows_before[ctos_proto];
for (m = 0, len2 = ref2.length; m < len2; m++) {
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) {
b = ctos_buffer.slice(3, ctos_message_length - 1 + 3);
info = null;
if (struct = ygopro.structs[ygopro.proto_structs.CTOS[ygopro.constants.CTOS[ctos_proto]]]) {
struct._setBuff(b);
info = _.clone(struct.fields);
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[ctos_proto].synchronous) {
cancel = ygopro.ctos_follows[ctos_proto].callback(b, info, client, client.server, datas);
} else {
ygopro.ctos_follows[ctos_proto].callback(b, info, client, client.server, datas);
}
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) {
......@@ -2108,20 +2133,20 @@
return;
}
if (client.established) {
for (m = 0, len2 = datas.length; m < len2; m++) {
buffer = datas[m];
for (o = 0, len4 = datas.length; o < len4; o++) {
buffer = datas[o];
client.server.write(buffer);
}
} else {
for (n = 0, len3 = datas.length; n < len3; n++) {
buffer = datas[n];
for (p = 0, len5 = datas.length; p < len5; p++) {
buffer = datas[p];
client.pre_establish_buffers.push(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_proto = 0;
datas = [];
......@@ -2146,18 +2171,36 @@
} else {
if (stoc_buffer.length >= 2 + stoc_message_length) {
cancel = false;
stanzas = stoc_proto;
if (ygopro.stoc_follows[stoc_proto]) {
b = stoc_buffer.slice(3, stoc_message_length - 1 + 3);
info = null;
if (struct = ygopro.structs[ygopro.proto_structs.STOC[ygopro.constants.STOC[stoc_proto]]]) {
struct._setBuff(b);
info = _.clone(struct.fields);
b = stoc_buffer.slice(3, stoc_message_length - 1 + 3);
info = null;
if (struct = ygopro.structs[ygopro.proto_structs.STOC[ygopro.constants.STOC[stoc_proto]]]) {
struct._setBuff(b);
info = _.clone(struct.fields);
}
if (ygopro.stoc_follows_before[stoc_proto] && !cancel) {
ref2 = ygopro.stoc_follows_before[stoc_proto];
for (m = 0, len2 = ref2.length; m < len2; m++) {
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].synchronous) {
cancel = ygopro.stoc_follows[stoc_proto].callback(b, info, server.client, server, datas);
} else {
ygopro.stoc_follows[stoc_proto].callback(b, info, server.client, server, datas);
}
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) {
......@@ -2179,8 +2222,8 @@
}
}
if (server.client && !server.client.closed) {
for (m = 0, len2 = datas.length; m < len2; m++) {
buffer = datas[m];
for (o = 0, len4 = datas.length; o < len4; o++) {
buffer = datas[o];
server.client.write(buffer);
}
}
......@@ -2798,7 +2841,7 @@
}
});
load_dialogues = function() {
load_dialogues = global.load_dialogues = function() {
request({
url: settings.modules.dialogues.get,
json: true
......@@ -3422,7 +3465,7 @@
}
};
load_tips = function() {
load_tips = global.load_tips = function() {
request({
url: settings.modules.tips.get,
json: true
......@@ -3567,7 +3610,7 @@
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) {
return;
}
......@@ -4360,9 +4403,9 @@
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;
if (/^win/.test(process.platform)) {
windbot_bin = 'WindBot.exe';
......@@ -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);
......@@ -37,26 +37,55 @@ for name, declaration of structs_declaration
#消息跟踪函数 需要重构, 另暂时只支持异步, 同步没做.
@stoc_follows = {}
@stoc_follows_before = {}
@stoc_follows_after = {}
@ctos_follows = {}
@ctos_follows_before = {}
@ctos_follows_after = {}
@replace_proto = (proto, tp) ->
if typeof(proto) != "string"
return proto
changed_proto = proto
for key, value of @constants[tp]
if value == proto
changed_proto = key
break
throw "unknown proto" if !@constants[tp][changed_proto]
return changed_proto
@stoc_follow = (proto, synchronous, callback)->
if typeof proto == 'string'
for key, value of @constants.STOC
if value == proto
proto = key
break
throw "unknown proto" if !@constants.STOC[proto]
@stoc_follows[proto] = {callback: callback, synchronous: synchronous}
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
@ctos_follow = (proto, synchronous, callback)->
if typeof proto == 'string'
for key, value of @constants.CTOS
if value == proto
proto = key
break
throw "unknown proto" if !@constants.CTOS[proto]
@ctos_follows[proto] = {callback: callback, synchronous: synchronous}
changed_proto = @replace_proto(proto, "CTOS")
@ctos_follows[changed_proto] = {callback: callback, synchronous: synchronous}
return
@ctos_follow_before = (proto, synchronous, callback)->
changed_proto = @replace_proto(proto, "CTOS")
if !@ctos_follows_before[changed_proto]
@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
#消息发送函数,至少要把俩合起来....
@stoc_send = (socket, proto, info)->
......@@ -171,4 +200,4 @@ for name, declaration of structs_declaration
if client
client.system_kicked = true
client.destroy()
return
\ No newline at end of file
return
......@@ -58,50 +58,102 @@
this.stoc_follows = {};
this.stoc_follows_before = {};
this.stoc_follows_after = {};
this.ctos_follows = {};
this.stoc_follow = function(proto, synchronous, callback) {
var key, ref, value;
if (typeof proto === 'string') {
ref = this.constants.STOC;
for (key in ref) {
value = ref[key];
if (value === proto) {
proto = key;
break;
}
}
if (!this.constants.STOC[proto]) {
throw "unknown proto";
this.ctos_follows_before = {};
this.ctos_follows_after = {};
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) {
value = ref[key];
if (value === proto) {
changed_proto = key;
break;
}
}
this.stoc_follows[proto] = {
if (!this.constants[tp][changed_proto]) {
throw "unknown proto";
}
return changed_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,
synchronous: synchronous
};
};
this.ctos_follow = function(proto, synchronous, callback) {
var key, ref, value;
if (typeof proto === 'string') {
ref = this.constants.CTOS;
for (key in ref) {
value = ref[key];
if (value === proto) {
proto = key;
break;
}
}
if (!this.constants.CTOS[proto]) {
throw "unknown proto";
}
this.stoc_follow_before = function(proto, synchronous, callback) {
var changed_proto;
changed_proto = this.replace_proto(proto, "STOC");
if (!this.stoc_follows_before[changed_proto]) {
this.stoc_follows_before[changed_proto] = [];
}
this.ctos_follows[proto] = {
this.stoc_follows_before[changed_proto].push({
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_before[changed_proto].push({
callback: callback,
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) {
var buffer, header, key, ref, struct, value;
if (socket.closed) {
......
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