Resolve conflicts
This commit is contained in:
@ -14,10 +14,10 @@ export default async function(request: websocket.request, connection: websocket.
|
||||
subscriber.subscribe(`misskey:user-stream:${user._id}`);
|
||||
|
||||
const mute = await Mute.find({
|
||||
muter_id: user._id,
|
||||
deleted_at: { $exists: false }
|
||||
muterId: user._id,
|
||||
deletedAt: { $exists: false }
|
||||
});
|
||||
const mutedUserIds = mute.map(m => m.mutee_id.toString());
|
||||
const mutedUserIds = mute.map(m => m.muteeId.toString());
|
||||
|
||||
subscriber.on('message', async (channel, data) => {
|
||||
switch (channel.split(':')[1]) {
|
||||
@ -26,17 +26,17 @@ export default async function(request: websocket.request, connection: websocket.
|
||||
const x = JSON.parse(data);
|
||||
|
||||
if (x.type == 'post') {
|
||||
if (mutedUserIds.indexOf(x.body.user_id) != -1) {
|
||||
if (mutedUserIds.indexOf(x.body.userId) != -1) {
|
||||
return;
|
||||
}
|
||||
if (x.body.reply != null && mutedUserIds.indexOf(x.body.reply.user_id) != -1) {
|
||||
if (x.body.reply != null && mutedUserIds.indexOf(x.body.reply.userId) != -1) {
|
||||
return;
|
||||
}
|
||||
if (x.body.repost != null && mutedUserIds.indexOf(x.body.repost.user_id) != -1) {
|
||||
if (x.body.repost != null && mutedUserIds.indexOf(x.body.repost.userId) != -1) {
|
||||
return;
|
||||
}
|
||||
} else if (x.type == 'notification') {
|
||||
if (mutedUserIds.indexOf(x.body.user_id) != -1) {
|
||||
if (mutedUserIds.indexOf(x.body.userId) != -1) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -74,7 +74,7 @@ export default async function(request: websocket.request, connection: websocket.
|
||||
// Update lastUsedAt
|
||||
User.update({ _id: user._id }, {
|
||||
$set: {
|
||||
'account.last_used_at': new Date()
|
||||
'account.lastUsedAt': new Date()
|
||||
}
|
||||
});
|
||||
break;
|
||||
|
@ -1,7 +1,7 @@
|
||||
import * as websocket from 'websocket';
|
||||
import * as redis from 'redis';
|
||||
import * as CRC32 from 'crc-32';
|
||||
import Game, { pack } from '../models/othello-game';
|
||||
import OthelloGame, { pack } from '../models/othello-game';
|
||||
import { publishOthelloGameStream } from '../event';
|
||||
import Othello from '../../common/othello/core';
|
||||
import * as maps from '../../common/othello/maps';
|
||||
@ -60,14 +60,14 @@ export default function(request: websocket.request, connection: websocket.connec
|
||||
});
|
||||
|
||||
async function updateSettings(settings) {
|
||||
const game = await Game.findOne({ _id: gameId });
|
||||
const game = await OthelloGame.findOne({ _id: gameId });
|
||||
|
||||
if (game.is_started) return;
|
||||
if (!game.user1_id.equals(user._id) && !game.user2_id.equals(user._id)) return;
|
||||
if (game.user1_id.equals(user._id) && game.user1_accepted) return;
|
||||
if (game.user2_id.equals(user._id) && game.user2_accepted) return;
|
||||
if (game.isStarted) return;
|
||||
if (!game.user1Id.equals(user._id) && !game.user2Id.equals(user._id)) return;
|
||||
if (game.user1Id.equals(user._id) && game.user1Accepted) return;
|
||||
if (game.user2Id.equals(user._id) && game.user2Accepted) return;
|
||||
|
||||
await Game.update({ _id: gameId }, {
|
||||
await OthelloGame.update({ _id: gameId }, {
|
||||
$set: {
|
||||
settings
|
||||
}
|
||||
@ -77,34 +77,34 @@ export default function(request: websocket.request, connection: websocket.connec
|
||||
}
|
||||
|
||||
async function initForm(form) {
|
||||
const game = await Game.findOne({ _id: gameId });
|
||||
const game = await OthelloGame.findOne({ _id: gameId });
|
||||
|
||||
if (game.is_started) return;
|
||||
if (!game.user1_id.equals(user._id) && !game.user2_id.equals(user._id)) return;
|
||||
if (game.isStarted) return;
|
||||
if (!game.user1Id.equals(user._id) && !game.user2Id.equals(user._id)) return;
|
||||
|
||||
const set = game.user1_id.equals(user._id) ? {
|
||||
const set = game.user1Id.equals(user._id) ? {
|
||||
form1: form
|
||||
} : {
|
||||
form2: form
|
||||
};
|
||||
|
||||
await Game.update({ _id: gameId }, {
|
||||
await OthelloGame.update({ _id: gameId }, {
|
||||
$set: set
|
||||
});
|
||||
|
||||
publishOthelloGameStream(gameId, 'init-form', {
|
||||
user_id: user._id,
|
||||
userId: user._id,
|
||||
form
|
||||
});
|
||||
}
|
||||
|
||||
async function updateForm(id, value) {
|
||||
const game = await Game.findOne({ _id: gameId });
|
||||
const game = await OthelloGame.findOne({ _id: gameId });
|
||||
|
||||
if (game.is_started) return;
|
||||
if (!game.user1_id.equals(user._id) && !game.user2_id.equals(user._id)) return;
|
||||
if (game.isStarted) return;
|
||||
if (!game.user1Id.equals(user._id) && !game.user2Id.equals(user._id)) return;
|
||||
|
||||
const form = game.user1_id.equals(user._id) ? game.form2 : game.form1;
|
||||
const form = game.user1Id.equals(user._id) ? game.form2 : game.form1;
|
||||
|
||||
const item = form.find(i => i.id == id);
|
||||
|
||||
@ -112,18 +112,18 @@ export default function(request: websocket.request, connection: websocket.connec
|
||||
|
||||
item.value = value;
|
||||
|
||||
const set = game.user1_id.equals(user._id) ? {
|
||||
const set = game.user1Id.equals(user._id) ? {
|
||||
form2: form
|
||||
} : {
|
||||
form1: form
|
||||
};
|
||||
|
||||
await Game.update({ _id: gameId }, {
|
||||
await OthelloGame.update({ _id: gameId }, {
|
||||
$set: set
|
||||
});
|
||||
|
||||
publishOthelloGameStream(gameId, 'update-form', {
|
||||
user_id: user._id,
|
||||
userId: user._id,
|
||||
id,
|
||||
value
|
||||
});
|
||||
@ -132,44 +132,44 @@ export default function(request: websocket.request, connection: websocket.connec
|
||||
async function message(message) {
|
||||
message.id = Math.random();
|
||||
publishOthelloGameStream(gameId, 'message', {
|
||||
user_id: user._id,
|
||||
userId: user._id,
|
||||
message
|
||||
});
|
||||
}
|
||||
|
||||
async function accept(accept: boolean) {
|
||||
const game = await Game.findOne({ _id: gameId });
|
||||
const game = await OthelloGame.findOne({ _id: gameId });
|
||||
|
||||
if (game.is_started) return;
|
||||
if (game.isStarted) return;
|
||||
|
||||
let bothAccepted = false;
|
||||
|
||||
if (game.user1_id.equals(user._id)) {
|
||||
await Game.update({ _id: gameId }, {
|
||||
if (game.user1Id.equals(user._id)) {
|
||||
await OthelloGame.update({ _id: gameId }, {
|
||||
$set: {
|
||||
user1_accepted: accept
|
||||
user1Accepted: accept
|
||||
}
|
||||
});
|
||||
|
||||
publishOthelloGameStream(gameId, 'change-accepts', {
|
||||
user1: accept,
|
||||
user2: game.user2_accepted
|
||||
user2: game.user2Accepted
|
||||
});
|
||||
|
||||
if (accept && game.user2_accepted) bothAccepted = true;
|
||||
} else if (game.user2_id.equals(user._id)) {
|
||||
await Game.update({ _id: gameId }, {
|
||||
if (accept && game.user2Accepted) bothAccepted = true;
|
||||
} else if (game.user2Id.equals(user._id)) {
|
||||
await OthelloGame.update({ _id: gameId }, {
|
||||
$set: {
|
||||
user2_accepted: accept
|
||||
user2Accepted: accept
|
||||
}
|
||||
});
|
||||
|
||||
publishOthelloGameStream(gameId, 'change-accepts', {
|
||||
user1: game.user1_accepted,
|
||||
user1: game.user1Accepted,
|
||||
user2: accept
|
||||
});
|
||||
|
||||
if (accept && game.user1_accepted) bothAccepted = true;
|
||||
if (accept && game.user1Accepted) bothAccepted = true;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
@ -177,9 +177,9 @@ export default function(request: websocket.request, connection: websocket.connec
|
||||
if (bothAccepted) {
|
||||
// 3秒後、まだacceptされていたらゲーム開始
|
||||
setTimeout(async () => {
|
||||
const freshGame = await Game.findOne({ _id: gameId });
|
||||
if (freshGame == null || freshGame.is_started || freshGame.is_ended) return;
|
||||
if (!freshGame.user1_accepted || !freshGame.user2_accepted) return;
|
||||
const freshGame = await OthelloGame.findOne({ _id: gameId });
|
||||
if (freshGame == null || freshGame.isStarted || freshGame.isEnded) return;
|
||||
if (!freshGame.user1Accepted || !freshGame.user2Accepted) return;
|
||||
|
||||
let bw: number;
|
||||
if (freshGame.settings.bw == 'random') {
|
||||
@ -196,10 +196,10 @@ export default function(request: websocket.request, connection: websocket.connec
|
||||
|
||||
const map = freshGame.settings.map != null ? freshGame.settings.map : getRandomMap();
|
||||
|
||||
await Game.update({ _id: gameId }, {
|
||||
await OthelloGame.update({ _id: gameId }, {
|
||||
$set: {
|
||||
started_at: new Date(),
|
||||
is_started: true,
|
||||
startedAt: new Date(),
|
||||
isStarted: true,
|
||||
black: bw,
|
||||
'settings.map': map
|
||||
}
|
||||
@ -207,32 +207,32 @@ export default function(request: websocket.request, connection: websocket.connec
|
||||
|
||||
//#region 盤面に最初から石がないなどして始まった瞬間に勝敗が決定する場合があるのでその処理
|
||||
const o = new Othello(map, {
|
||||
isLlotheo: freshGame.settings.is_llotheo,
|
||||
canPutEverywhere: freshGame.settings.can_put_everywhere,
|
||||
loopedBoard: freshGame.settings.looped_board
|
||||
isLlotheo: freshGame.settings.isLlotheo,
|
||||
canPutEverywhere: freshGame.settings.canPutEverywhere,
|
||||
loopedBoard: freshGame.settings.loopedBoard
|
||||
});
|
||||
|
||||
if (o.isEnded) {
|
||||
let winner;
|
||||
if (o.winner === true) {
|
||||
winner = freshGame.black == 1 ? freshGame.user1_id : freshGame.user2_id;
|
||||
winner = freshGame.black == 1 ? freshGame.user1Id : freshGame.user2Id;
|
||||
} else if (o.winner === false) {
|
||||
winner = freshGame.black == 1 ? freshGame.user2_id : freshGame.user1_id;
|
||||
winner = freshGame.black == 1 ? freshGame.user2Id : freshGame.user1Id;
|
||||
} else {
|
||||
winner = null;
|
||||
}
|
||||
|
||||
await Game.update({
|
||||
await OthelloGame.update({
|
||||
_id: gameId
|
||||
}, {
|
||||
$set: {
|
||||
is_ended: true,
|
||||
winner_id: winner
|
||||
isEnded: true,
|
||||
winnerId: winner
|
||||
}
|
||||
});
|
||||
|
||||
publishOthelloGameStream(gameId, 'ended', {
|
||||
winner_id: winner,
|
||||
winnerId: winner,
|
||||
game: await pack(gameId, user)
|
||||
});
|
||||
}
|
||||
@ -245,16 +245,16 @@ export default function(request: websocket.request, connection: websocket.connec
|
||||
|
||||
// 石を打つ
|
||||
async function set(pos) {
|
||||
const game = await Game.findOne({ _id: gameId });
|
||||
const game = await OthelloGame.findOne({ _id: gameId });
|
||||
|
||||
if (!game.is_started) return;
|
||||
if (game.is_ended) return;
|
||||
if (!game.user1_id.equals(user._id) && !game.user2_id.equals(user._id)) return;
|
||||
if (!game.isStarted) return;
|
||||
if (game.isEnded) return;
|
||||
if (!game.user1Id.equals(user._id) && !game.user2Id.equals(user._id)) return;
|
||||
|
||||
const o = new Othello(game.settings.map, {
|
||||
isLlotheo: game.settings.is_llotheo,
|
||||
canPutEverywhere: game.settings.can_put_everywhere,
|
||||
loopedBoard: game.settings.looped_board
|
||||
isLlotheo: game.settings.isLlotheo,
|
||||
canPutEverywhere: game.settings.canPutEverywhere,
|
||||
loopedBoard: game.settings.loopedBoard
|
||||
});
|
||||
|
||||
game.logs.forEach(log => {
|
||||
@ -262,7 +262,7 @@ export default function(request: websocket.request, connection: websocket.connec
|
||||
});
|
||||
|
||||
const myColor =
|
||||
(game.user1_id.equals(user._id) && game.black == 1) || (game.user2_id.equals(user._id) && game.black == 2)
|
||||
(game.user1Id.equals(user._id) && game.black == 1) || (game.user2Id.equals(user._id) && game.black == 2)
|
||||
? true
|
||||
: false;
|
||||
|
||||
@ -272,9 +272,9 @@ export default function(request: websocket.request, connection: websocket.connec
|
||||
let winner;
|
||||
if (o.isEnded) {
|
||||
if (o.winner === true) {
|
||||
winner = game.black == 1 ? game.user1_id : game.user2_id;
|
||||
winner = game.black == 1 ? game.user1Id : game.user2Id;
|
||||
} else if (o.winner === false) {
|
||||
winner = game.black == 1 ? game.user2_id : game.user1_id;
|
||||
winner = game.black == 1 ? game.user2Id : game.user1Id;
|
||||
} else {
|
||||
winner = null;
|
||||
}
|
||||
@ -288,13 +288,13 @@ export default function(request: websocket.request, connection: websocket.connec
|
||||
|
||||
const crc32 = CRC32.str(game.logs.map(x => x.pos.toString()).join('') + pos.toString());
|
||||
|
||||
await Game.update({
|
||||
await OthelloGame.update({
|
||||
_id: gameId
|
||||
}, {
|
||||
$set: {
|
||||
crc32,
|
||||
is_ended: o.isEnded,
|
||||
winner_id: winner
|
||||
isEnded: o.isEnded,
|
||||
winnerId: winner
|
||||
},
|
||||
$push: {
|
||||
logs: log
|
||||
@ -307,16 +307,16 @@ export default function(request: websocket.request, connection: websocket.connec
|
||||
|
||||
if (o.isEnded) {
|
||||
publishOthelloGameStream(gameId, 'ended', {
|
||||
winner_id: winner,
|
||||
winnerId: winner,
|
||||
game: await pack(gameId, user)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async function check(crc32) {
|
||||
const game = await Game.findOne({ _id: gameId });
|
||||
const game = await OthelloGame.findOne({ _id: gameId });
|
||||
|
||||
if (!game.is_started) return;
|
||||
if (!game.isStarted) return;
|
||||
|
||||
// 互換性のため
|
||||
if (game.crc32 == null) return;
|
||||
|
@ -18,11 +18,11 @@ export default function(request: websocket.request, connection: websocket.connec
|
||||
case 'ping':
|
||||
if (msg.id == null) return;
|
||||
const matching = await Matching.findOne({
|
||||
parent_id: user._id,
|
||||
child_id: new mongo.ObjectID(msg.id)
|
||||
parentId: user._id,
|
||||
childId: new mongo.ObjectID(msg.id)
|
||||
});
|
||||
if (matching == null) return;
|
||||
publishUserStream(matching.child_id, 'othello_invited', await pack(matching, matching.child_id));
|
||||
publishUserStream(matching.childId, 'othello_invited', await pack(matching, matching.childId));
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
Reference in New Issue
Block a user