Commit 5b969a26 authored by nanahira's avatar nanahira

add no watch room support

parent 7c838b81
...@@ -52,6 +52,7 @@ ...@@ -52,6 +52,7 @@
"watch_join": "joined as spectator.", "watch_join": "joined as spectator.",
"watch_watching": "Spectating.", "watch_watching": "Spectating.",
"watch_denied": "Duel has begun, spectating is unallowed", "watch_denied": "Duel has begun, spectating is unallowed",
"watch_denied_room": "Spectating is unallowed in this room",
"rank_arena": ", Your ranking is", "rank_arena": ", Your ranking is",
"rank_blank": ", You are not ranked.", "rank_blank": ", You are not ranked.",
"exp_value_part1": ", You have ", "exp_value_part1": ", You have ",
...@@ -335,6 +336,7 @@ ...@@ -335,6 +336,7 @@
"watch_join": "加入了观战", "watch_join": "加入了观战",
"watch_watching": "观战中", "watch_watching": "观战中",
"watch_denied": "决斗已开始,不允许观战", "watch_denied": "决斗已开始,不允许观战",
"watch_denied_room": "本房间不允许观战",
"rank_arena": ",排名第", "rank_arena": ",排名第",
"rank_blank": ",暂无排名", "rank_blank": ",暂无排名",
"exp_value_part1": ",你有", "exp_value_part1": ",你有",
......
...@@ -785,6 +785,9 @@ class Room ...@@ -785,6 +785,9 @@ class Room
if (rule.match /(^|,|,)(IGPRIORITY|PR)(,|,|$)/) if (rule.match /(^|,|,)(IGPRIORITY|PR)(,|,|$)/)
@hostinfo.enable_priority = true @hostinfo.enable_priority = true
if (rule.match /(^|,|,)(NOWATCH|NW)(,|,|$)/)
@no_watch = true
param = [0, @hostinfo.lflist, @hostinfo.rule, @hostinfo.mode, (if @hostinfo.enable_priority then 'T' else 'F'), param = [0, @hostinfo.lflist, @hostinfo.rule, @hostinfo.mode, (if @hostinfo.enable_priority then 'T' else 'F'),
(if @hostinfo.no_check_deck then 'T' else 'F'), (if @hostinfo.no_shuffle_deck then 'T' else 'F'), (if @hostinfo.no_check_deck then 'T' else 'F'), (if @hostinfo.no_shuffle_deck then 'T' else 'F'),
@hostinfo.start_lp, @hostinfo.start_hand, @hostinfo.draw_count, @hostinfo.time_limit, @hostinfo.replay_mode] @hostinfo.start_lp, @hostinfo.start_hand, @hostinfo.draw_count, @hostinfo.time_limit, @hostinfo.replay_mode]
...@@ -1448,7 +1451,7 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)-> ...@@ -1448,7 +1451,7 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)->
else if room.error else if room.error
ygopro.stoc_die(client, room.error) ygopro.stoc_die(client, room.error)
else if room.started else if room.started
if settings.modules.cloud_replay.enable_halfway_watch if settings.modules.cloud_replay.enable_halfway_watch and !room.no_watch
client.setTimeout(300000) #连接后超时5分钟 client.setTimeout(300000) #连接后超时5分钟
client.rid = _.indexOf(ROOM_all, room) client.rid = _.indexOf(ROOM_all, room)
client.is_post_watcher = true client.is_post_watcher = true
...@@ -1503,7 +1506,7 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)-> ...@@ -1503,7 +1506,7 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)->
else if settings.modules.challonge.enabled else if settings.modules.challonge.enabled
pre_room = ROOM_find_by_name(info.pass) pre_room = ROOM_find_by_name(info.pass)
if pre_room and pre_room.started and settings.modules.cloud_replay.enable_halfway_watch if pre_room and pre_room.started and settings.modules.cloud_replay.enable_halfway_watch and !pre_room.no_watch
room = pre_room room = pre_room
client.setTimeout(300000) #连接后超时5分钟 client.setTimeout(300000) #连接后超时5分钟
client.rid = _.indexOf(ROOM_all, room) client.rid = _.indexOf(ROOM_all, room)
...@@ -1563,7 +1566,7 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)-> ...@@ -1563,7 +1566,7 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)->
else if room.error else if room.error
ygopro.stoc_die(client, room.error) ygopro.stoc_die(client, room.error)
else if room.started else if room.started
if settings.modules.cloud_replay.enable_halfway_watch if settings.modules.cloud_replay.enable_halfway_watch and !room.no_watch
client.setTimeout(300000) #连接后超时5分钟 client.setTimeout(300000) #连接后超时5分钟
client.rid = _.indexOf(ROOM_all, room) client.rid = _.indexOf(ROOM_all, room)
client.is_post_watcher = true client.is_post_watcher = true
...@@ -1644,7 +1647,7 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)-> ...@@ -1644,7 +1647,7 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)->
else if room.error else if room.error
ygopro.stoc_die(client, room.error) ygopro.stoc_die(client, room.error)
else if room.started else if room.started
if settings.modules.cloud_replay.enable_halfway_watch if settings.modules.cloud_replay.enable_halfway_watch and !room.no_watch
client.setTimeout(300000) #连接后超时5分钟 client.setTimeout(300000) #连接后超时5分钟
client.rid = _.indexOf(ROOM_all, room) client.rid = _.indexOf(ROOM_all, room)
client.is_post_watcher = true client.is_post_watcher = true
...@@ -1655,6 +1658,8 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)-> ...@@ -1655,6 +1658,8 @@ ygopro.ctos_follow 'JOIN_GAME', false, (buffer, info, client, server)->
client.write buffer client.write buffer
else else
ygopro.stoc_die(client, "${watch_denied}") ygopro.stoc_die(client, "${watch_denied}")
else if room.no_watch and room.players.length == (if room.hostinfo.mode == 2 then 4 else 2)
ygopro.stoc_die(client, "${watch_denied_room}")
else else
client.setTimeout(300000) #连接后超时5分钟 client.setTimeout(300000) #连接后超时5分钟
client.rid = _.indexOf(ROOM_all, room) client.rid = _.indexOf(ROOM_all, room)
...@@ -1708,7 +1713,7 @@ ygopro.stoc_follow 'JOIN_GAME', false, (buffer, info, client, server)-> ...@@ -1708,7 +1713,7 @@ ygopro.stoc_follow 'JOIN_GAME', false, (buffer, info, client, server)->
recorder.on 'error', (error)-> recorder.on 'error', (error)->
return return
if settings.modules.cloud_replay.enable_halfway_watch and !room.watcher if settings.modules.cloud_replay.enable_halfway_watch and !room.watcher and !room.no_watch
room.watcher = watcher = if settings.modules.test_mode.watch_public_hand then room.recorder else net.connect room.port, -> room.watcher = watcher = if settings.modules.test_mode.watch_public_hand then room.recorder else net.connect room.port, ->
ygopro.ctos_send watcher, 'PLAYER_INFO', { ygopro.ctos_send watcher, 'PLAYER_INFO', {
name: "the Big Brother" name: "the Big Brother"
...@@ -2002,6 +2007,9 @@ ygopro.stoc_follow 'GAME_MSG', true, (buffer, info, client, server)-> ...@@ -2002,6 +2007,9 @@ ygopro.stoc_follow 'GAME_MSG', true, (buffer, info, client, server)->
ygopro.ctos_follow 'HS_TOOBSERVER', true, (buffer, info, client, server)-> ygopro.ctos_follow 'HS_TOOBSERVER', true, (buffer, info, client, server)->
room=ROOM_all[client.rid] room=ROOM_all[client.rid]
return unless room return unless room
if room.no_watch
ygopro.stoc_send_chat(client, "${watch_denied_room}", ygopro.constants.COLORS.RED)
return true
if (!room.arena and !settings.modules.challonge.enabled) or client.is_local if (!room.arena and !settings.modules.challonge.enabled) or client.is_local
return false return false
for player in room.players for player in room.players
...@@ -2028,13 +2036,16 @@ ygopro.ctos_follow 'HS_KICK', true, (buffer, info, client, server)-> ...@@ -2028,13 +2036,16 @@ ygopro.ctos_follow 'HS_KICK', true, (buffer, info, client, server)->
ygopro.stoc_send_chat_to_room(room, "#{player.name} ${kicked_by_player}", ygopro.constants.COLORS.RED) ygopro.stoc_send_chat_to_room(room, "#{player.name} ${kicked_by_player}", ygopro.constants.COLORS.RED)
return false return false
ygopro.stoc_follow 'TYPE_CHANGE', false, (buffer, info, client, server)-> ygopro.stoc_follow 'TYPE_CHANGE', true, (buffer, info, client, server)->
selftype = info.type & 0xf selftype = info.type & 0xf
is_host = ((info.type >> 4) & 0xf) != 0 is_host = ((info.type >> 4) & 0xf) != 0
# if room and room.no_watch and selftype == 7
# ygopro.stoc_die(client, "${watch_denied_room}")
# return true
client.is_host = is_host client.is_host = is_host
client.pos = selftype client.pos = selftype
#console.log "TYPE_CHANGE to #{client.name}:", info, selftype, is_host #console.log "TYPE_CHANGE to #{client.name}:", info, selftype, is_host
return return false
ygopro.stoc_follow 'HS_PLAYER_CHANGE', false, (buffer, info, client, server)-> ygopro.stoc_follow 'HS_PLAYER_CHANGE', false, (buffer, info, client, server)->
room=ROOM_all[client.rid] room=ROOM_all[client.rid]
......
...@@ -992,6 +992,9 @@ ...@@ -992,6 +992,9 @@
if (rule.match(/(^|,|,)(IGPRIORITY|PR)(,|,|$)/)) { if (rule.match(/(^|,|,)(IGPRIORITY|PR)(,|,|$)/)) {
this.hostinfo.enable_priority = true; this.hostinfo.enable_priority = true;
} }
if (rule.match(/(^|,|,)(NOWATCH|NW)(,|,|$)/)) {
this.no_watch = true;
}
} }
param = [0, this.hostinfo.lflist, this.hostinfo.rule, this.hostinfo.mode, (this.hostinfo.enable_priority ? 'T' : 'F'), (this.hostinfo.no_check_deck ? 'T' : 'F'), (this.hostinfo.no_shuffle_deck ? 'T' : 'F'), this.hostinfo.start_lp, this.hostinfo.start_hand, this.hostinfo.draw_count, this.hostinfo.time_limit, this.hostinfo.replay_mode]; param = [0, this.hostinfo.lflist, this.hostinfo.rule, this.hostinfo.mode, (this.hostinfo.enable_priority ? 'T' : 'F'), (this.hostinfo.no_check_deck ? 'T' : 'F'), (this.hostinfo.no_shuffle_deck ? 'T' : 'F'), this.hostinfo.start_lp, this.hostinfo.start_hand, this.hostinfo.draw_count, this.hostinfo.time_limit, this.hostinfo.replay_mode];
try { try {
...@@ -1769,7 +1772,7 @@ ...@@ -1769,7 +1772,7 @@
} else if (room.error) { } else if (room.error) {
ygopro.stoc_die(client, room.error); ygopro.stoc_die(client, room.error);
} else if (room.started) { } else if (room.started) {
if (settings.modules.cloud_replay.enable_halfway_watch) { if (settings.modules.cloud_replay.enable_halfway_watch && !room.no_watch) {
client.setTimeout(300000); client.setTimeout(300000);
client.rid = _.indexOf(ROOM_all, room); client.rid = _.indexOf(ROOM_all, room);
client.is_post_watcher = true; client.is_post_watcher = true;
...@@ -1834,7 +1837,7 @@ ...@@ -1834,7 +1837,7 @@
}); });
} else if (settings.modules.challonge.enabled) { } else if (settings.modules.challonge.enabled) {
pre_room = ROOM_find_by_name(info.pass); pre_room = ROOM_find_by_name(info.pass);
if (pre_room && pre_room.started && settings.modules.cloud_replay.enable_halfway_watch) { if (pre_room && pre_room.started && settings.modules.cloud_replay.enable_halfway_watch && !pre_room.no_watch) {
room = pre_room; room = pre_room;
client.setTimeout(300000); client.setTimeout(300000);
client.rid = _.indexOf(ROOM_all, room); client.rid = _.indexOf(ROOM_all, room);
...@@ -1909,7 +1912,7 @@ ...@@ -1909,7 +1912,7 @@
} else if (room.error) { } else if (room.error) {
ygopro.stoc_die(client, room.error); ygopro.stoc_die(client, room.error);
} else if (room.started) { } else if (room.started) {
if (settings.modules.cloud_replay.enable_halfway_watch) { if (settings.modules.cloud_replay.enable_halfway_watch && !room.no_watch) {
client.setTimeout(300000); client.setTimeout(300000);
client.rid = _.indexOf(ROOM_all, room); client.rid = _.indexOf(ROOM_all, room);
client.is_post_watcher = true; client.is_post_watcher = true;
...@@ -1986,7 +1989,7 @@ ...@@ -1986,7 +1989,7 @@
} else if (room.error) { } else if (room.error) {
ygopro.stoc_die(client, room.error); ygopro.stoc_die(client, room.error);
} else if (room.started) { } else if (room.started) {
if (settings.modules.cloud_replay.enable_halfway_watch) { if (settings.modules.cloud_replay.enable_halfway_watch && !room.no_watch) {
client.setTimeout(300000); client.setTimeout(300000);
client.rid = _.indexOf(ROOM_all, room); client.rid = _.indexOf(ROOM_all, room);
client.is_post_watcher = true; client.is_post_watcher = true;
...@@ -2001,6 +2004,8 @@ ...@@ -2001,6 +2004,8 @@
} else { } else {
ygopro.stoc_die(client, "${watch_denied}"); ygopro.stoc_die(client, "${watch_denied}");
} }
} else if (room.no_watch && room.players.length === (room.hostinfo.mode === 2 ? 4 : 2)) {
ygopro.stoc_die(client, "${watch_denied_room}");
} else { } else {
client.setTimeout(300000); client.setTimeout(300000);
client.rid = _.indexOf(ROOM_all, room); client.rid = _.indexOf(ROOM_all, room);
...@@ -2060,7 +2065,7 @@ ...@@ -2060,7 +2065,7 @@
}); });
recorder.on('error', function(error) {}); recorder.on('error', function(error) {});
} }
if (settings.modules.cloud_replay.enable_halfway_watch && !room.watcher) { if (settings.modules.cloud_replay.enable_halfway_watch && !room.watcher && !room.no_watch) {
room.watcher = watcher = settings.modules.test_mode.watch_public_hand ? room.recorder : net.connect(room.port, function() { room.watcher = watcher = settings.modules.test_mode.watch_public_hand ? room.recorder : net.connect(room.port, function() {
ygopro.ctos_send(watcher, 'PLAYER_INFO', { ygopro.ctos_send(watcher, 'PLAYER_INFO', {
name: "the Big Brother" name: "the Big Brother"
...@@ -2434,6 +2439,10 @@ ...@@ -2434,6 +2439,10 @@
if (!room) { if (!room) {
return; return;
} }
if (room.no_watch) {
ygopro.stoc_send_chat(client, "${watch_denied_room}", ygopro.constants.COLORS.RED);
return true;
}
if ((!room.arena && !settings.modules.challonge.enabled) || client.is_local) { if ((!room.arena && !settings.modules.challonge.enabled) || client.is_local) {
return false; return false;
} }
...@@ -2476,12 +2485,13 @@ ...@@ -2476,12 +2485,13 @@
return false; return false;
}); });
ygopro.stoc_follow('TYPE_CHANGE', false, function(buffer, info, client, server) { ygopro.stoc_follow('TYPE_CHANGE', true, function(buffer, info, client, server) {
var is_host, selftype; var is_host, selftype;
selftype = info.type & 0xf; selftype = info.type & 0xf;
is_host = ((info.type >> 4) & 0xf) !== 0; is_host = ((info.type >> 4) & 0xf) !== 0;
client.is_host = is_host; client.is_host = is_host;
client.pos = selftype; client.pos = selftype;
return false;
}); });
ygopro.stoc_follow('HS_PLAYER_CHANGE', false, function(buffer, info, client, server) { ygopro.stoc_follow('HS_PLAYER_CHANGE', false, function(buffer, info, client, server) {
......
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