Let admins delete tables from the lobby
Admins see a "削除" button on every table in the lobby. It calls the new admin-only DELETE /api/tables/:id (404 for non-admins, same-origin only), which closes the table the same way as when every human leaves. Players and spectators still at the table are told "管理者がテーブルを削除しました。" Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3f2515a9fa
commit
0318ee2b5e
5 files changed
+53
-13
No files matched your search
+12
-2
@@ -173,6 +173,15 @@ app.post('/api/tables', (req, res) => {
|
||||
res.json({ id: table.id });
|
||||
});
|
||||
|
||||
// 管理者はどのテーブルでも削除できる(着席者・観戦者にはテーブルが閉じられたことを知らせる)
|
||||
app.delete('/api/tables/:id', auth.requireAdmin, (req, res) => {
|
||||
const table = tables.get(req.params.id);
|
||||
if (!table) return res.status(404).json({ error: 'テーブルが見つかりません' });
|
||||
console.log(`[admin] テーブル「${table.name}」を削除`);
|
||||
closeTable(table, null, 'deleted');
|
||||
res.json({ ok: true });
|
||||
});
|
||||
|
||||
app.use((req, res) => res.status(404).type('text/plain').send('Not Found'));
|
||||
|
||||
// 内部情報(スタックトレース等)を返さない
|
||||
@@ -222,12 +231,13 @@ function changed(table) {
|
||||
}
|
||||
|
||||
// テーブルを削除し、残っている観戦者に知らせる(leaver: 退席した本人。すでにロビーへ戻るので知らせない)
|
||||
function closeTable(table, leaver) {
|
||||
// reason: 'empty'(人間が全員退席した)/ 'deleted'(管理者が削除した)
|
||||
function closeTable(table, leaver, reason = 'empty') {
|
||||
tables.delete(table.id);
|
||||
for (const s of roomSockets(table.id)) {
|
||||
s.leave(roomOf(table.id));
|
||||
if (s.data.tableId === table.id) s.data.tableId = null;
|
||||
if (s !== leaver) s.emit('table:closed');
|
||||
if (s !== leaver) s.emit('table:closed', { reason });
|
||||
}
|
||||
broadcastLobby();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user