Commit 2e5e115b authored by nanahira's avatar nanahira

add no_watch

parent cc0fba76
Pipeline #43388 passed with stages
in 3 minutes and 21 seconds
......@@ -110,3 +110,5 @@ hostinfoStartLp: 8000
hostinfoStartHand: 5
hostinfoDrawCount: 1
hostinfoTimeLimit: 240
hostinfoNoWatch: 0
hostinfoAutoDeath: 0
......@@ -178,6 +178,8 @@ export const TRANSLATIONS = {
botlist_menu_single: 'Single',
botlist_menu_match: 'Match',
botlist_menu_back: 'Back',
watch_denied: 'Duel has begun, spectating is unallowed',
watch_denied_room: 'Spectating is unallowed in this room',
},
'zh-CN': {
update_required: '请更新你的客户端版本',
......
......@@ -34,8 +34,9 @@ export class JoinRoomlist {
.filter(
(room) =>
(room.native ||
(room.duelStage !== DuelStage.Begin && room.challongeInfo)) &&
!room.name.includes('$'),
(room.duelStage !== DuelStage.Begin && !room.windbot)) &&
!room.name.includes('$') &&
!(room.duelStage !== DuelStage.Begin && room.hostinfo?.no_watch),
)
.map((room) => room.name);
......
......@@ -258,6 +258,9 @@ export class DefaultHostInfoProvider {
return {};
}
return { duel_rule: duelRule };
})
.registerRoomMode('(NOWATCH|NW)', {
no_watch: 1,
});
}
}
......@@ -11,4 +11,6 @@ export const DefaultHostinfo: HostInfo = {
start_hand: 5,
draw_count: 1,
time_limit: 240,
no_watch: 0,
auto_death: 0,
};
import { YGOProCtosHsToObserver, ChatColor } from 'ygopro-msg-encode';
import { Context } from '../app';
import { RoomManager } from './room-manager';
export class NoWatchToObserverGuard {
constructor(private ctx: Context) {}
async init() {
this.ctx.middleware(YGOProCtosHsToObserver, async (_msg, client, next) => {
const room = this.ctx.get(() => RoomManager).findByName(client.roomName);
if (!room?.hostinfo?.no_watch) {
return next();
}
await client.sendChat('#{watch_denied_room}', ChatColor.BABYBLUE);
return;
});
}
}
......@@ -5,6 +5,7 @@ import { DefaultHostInfoProvider } from './default-hostinfo-provder';
import { RoomManager } from './room-manager';
import { DefaultDeckChecker } from './default-deck-checker';
import { ZombieRoomCleaner } from './zombie-room-cleaner';
import { NoWatchToObserverGuard } from './no-watch-to-observer-guard';
export const RoomModule = createAppContext<ContextState>()
.provide(DefaultHostInfoProvider)
......@@ -12,4 +13,5 @@ export const RoomModule = createAppContext<ContextState>()
.provide(RoomManager)
.provide(DefaultDeckChecker)
.provide(ZombieRoomCleaner)
.provide(NoWatchToObserverGuard)
.define();
......@@ -109,6 +109,12 @@ import cryptoRandomString from 'crypto-random-string';
import { RoomCurrentFieldInfo, RoomInfo } from './room-info';
import { KoishiFragment, readCardWithReader } from '../utility';
declare module 'ygopro-msg-encode' {
export interface HostInfo {
no_watch?: number;
}
}
const { OcgcoreScriptConstants } = _OcgcoreConstants;
export type RoomFinalizor = (self: Room) => Awaitable<any>;
......@@ -388,6 +394,9 @@ export class Room {
if (isPlayer) {
this.players[firstEmptyPlayerSlot] = client;
client.pos = firstEmptyPlayerSlot;
} else if (this.hostinfo.no_watch) {
// not allowing watchers
return client.die('#{watch_denied}', ChatColor.RED);
} else {
this.watchers.add(client);
client.pos = NetPlayerType.OBSERVER;
......
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