Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Sharkey
Manage
Activity
Members
Labels
Plan
Issues
339
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
24
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TransFem.org
Sharkey
Commits
a431dde5
Commit
a431dde5
authored
1 year ago
by
syuilo
Browse files
Options
Downloads
Patches
Plain Diff
refactor(reversi): refactoring of reversi backend
parent
4f95b8d9
No related branches found
Branches containing commit
No related tags found
Tags containing commit
10 merge requests
!449
release 2024.3.1
,
!448
Release 2023.3.1 - Codename #NotDeadYet
,
!34
Merge Beta3
,
!35
fix: admin css
,
!36
Fix Like button not working on renotes/boosts
,
!37
merge develope
,
!57
Merge Latest Changes
,
!62
fix: background overlaying
,
!68
2023.9.1.beta5
,
!112
update develop with stable changes
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
packages/backend/src/core/ReversiService.ts
+26
-51
26 additions, 51 deletions
packages/backend/src/core/ReversiService.ts
with
26 additions
and
51 deletions
packages/backend/src/core/ReversiService.ts
+
26
−
51
View file @
a431dde5
...
...
@@ -104,23 +104,7 @@ export class ReversiService implements OnApplicationShutdown, OnModuleInit {
if
(
invitations
.
includes
(
targetUser
.
id
))
{
await
this
.
redisClient
.
zrem
(
`reversi:matchSpecific:
${
me
.
id
}
`
,
targetUser
.
id
);
const
game
=
await
this
.
reversiGamesRepository
.
insert
({
id
:
this
.
idService
.
gen
(),
user1Id
:
targetUser
.
id
,
user2Id
:
me
.
id
,
user1Ready
:
false
,
user2Ready
:
false
,
isStarted
:
false
,
isEnded
:
false
,
logs
:
[],
map
:
Reversi
.
maps
.
eighteight
.
data
,
bw
:
'
random
'
,
isLlotheo
:
false
,
}).
then
(
x
=>
this
.
reversiGamesRepository
.
findOneByOrFail
(
x
.
identifiers
[
0
]));
this
.
cacheGame
(
game
);
const
packed
=
await
this
.
reversiGameEntityService
.
packDetail
(
game
,
{
id
:
targetUser
.
id
});
this
.
globalEventService
.
publishReversiStream
(
targetUser
.
id
,
'
matched
'
,
{
game
:
packed
});
const
game
=
await
this
.
matched
(
targetUser
.
id
,
me
.
id
);
return
game
;
}
else
{
...
...
@@ -147,23 +131,7 @@ export class ReversiService implements OnApplicationShutdown, OnModuleInit {
const
invitorId
=
invitations
[
Math
.
floor
(
Math
.
random
()
*
invitations
.
length
)];
await
this
.
redisClient
.
zrem
(
`reversi:matchSpecific:
${
me
.
id
}
`
,
invitorId
);
const
game
=
await
this
.
reversiGamesRepository
.
insert
({
id
:
this
.
idService
.
gen
(),
user1Id
:
invitorId
,
user2Id
:
me
.
id
,
user1Ready
:
false
,
user2Ready
:
false
,
isStarted
:
false
,
isEnded
:
false
,
logs
:
[],
map
:
Reversi
.
maps
.
eighteight
.
data
,
bw
:
'
random
'
,
isLlotheo
:
false
,
}).
then
(
x
=>
this
.
reversiGamesRepository
.
findOneByOrFail
(
x
.
identifiers
[
0
]));
this
.
cacheGame
(
game
);
const
packed
=
await
this
.
reversiGameEntityService
.
packDetail
(
game
,
{
id
:
invitorId
});
this
.
globalEventService
.
publishReversiStream
(
invitorId
,
'
matched
'
,
{
game
:
packed
});
const
game
=
await
this
.
matched
(
invitorId
,
me
.
id
);
return
game
;
}
...
...
@@ -183,23 +151,7 @@ export class ReversiService implements OnApplicationShutdown, OnModuleInit {
await
this
.
redisClient
.
zrem
(
'
reversi:matchAny
'
,
me
.
id
,
matchedUserId
);
const
game
=
await
this
.
reversiGamesRepository
.
insert
({
id
:
this
.
idService
.
gen
(),
user1Id
:
matchedUserId
,
user2Id
:
me
.
id
,
user1Ready
:
false
,
user2Ready
:
false
,
isStarted
:
false
,
isEnded
:
false
,
logs
:
[],
map
:
Reversi
.
maps
.
eighteight
.
data
,
bw
:
'
random
'
,
isLlotheo
:
false
,
}).
then
(
x
=>
this
.
reversiGamesRepository
.
findOneByOrFail
(
x
.
identifiers
[
0
]));
this
.
cacheGame
(
game
);
const
packed
=
await
this
.
reversiGameEntityService
.
packDetail
(
game
,
{
id
:
matchedUserId
});
this
.
globalEventService
.
publishReversiStream
(
matchedUserId
,
'
matched
'
,
{
game
:
packed
});
const
game
=
await
this
.
matched
(
matchedUserId
,
me
.
id
);
return
game
;
}
else
{
...
...
@@ -268,6 +220,29 @@ export class ReversiService implements OnApplicationShutdown, OnModuleInit {
}
}
@
bindThis
private
async
matched
(
parentId
:
MiUser
[
'
id
'
],
childId
:
MiUser
[
'
id
'
]):
Promise
<
MiReversiGame
>
{
const
game
=
await
this
.
reversiGamesRepository
.
insert
({
id
:
this
.
idService
.
gen
(),
user1Id
:
parentId
,
user2Id
:
childId
,
user1Ready
:
false
,
user2Ready
:
false
,
isStarted
:
false
,
isEnded
:
false
,
logs
:
[],
map
:
Reversi
.
maps
.
eighteight
.
data
,
bw
:
'
random
'
,
isLlotheo
:
false
,
}).
then
(
x
=>
this
.
reversiGamesRepository
.
findOneByOrFail
(
x
.
identifiers
[
0
]));
this
.
cacheGame
(
game
);
const
packed
=
await
this
.
reversiGameEntityService
.
packDetail
(
game
,
{
id
:
parentId
});
this
.
globalEventService
.
publishReversiStream
(
parentId
,
'
matched
'
,
{
game
:
packed
});
return
game
;
}
@
bindThis
private
async
startGame
(
game
:
MiReversiGame
)
{
let
bw
:
number
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment