Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
T
Taiko Web
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nanahira
Taiko Web
Commits
967d882a
Commit
967d882a
authored
Apr 02, 2020
by
LoveEevee
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix multiplayer server
parent
de284d20
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
24 deletions
+24
-24
server.py
server.py
+24
-24
No files found.
server.py
View file @
967d882a
...
@@ -13,11 +13,11 @@ server_status = {
...
@@ -13,11 +13,11 @@ server_status = {
}
}
consonants
=
"bcdfghjklmnpqrstvwxyz"
consonants
=
"bcdfghjklmnpqrstvwxyz"
def
msgobj
(
type
,
value
=
None
):
def
msgobj
(
msg_
type
,
value
=
None
):
if
value
==
None
:
if
value
==
None
:
return
json
.
dumps
({
"type"
:
type
})
return
json
.
dumps
({
"type"
:
msg_
type
})
else
:
else
:
return
json
.
dumps
({
"type"
:
type
,
"value"
:
value
})
return
json
.
dumps
({
"type"
:
msg_
type
,
"value"
:
value
})
def
status_event
():
def
status_event
():
value
=
[]
value
=
[]
...
@@ -70,11 +70,11 @@ async def connection(ws, path):
...
@@ -70,11 +70,11 @@ async def connection(ws, path):
except
json
.
decoder
.
JSONDecodeError
:
except
json
.
decoder
.
JSONDecodeError
:
data
=
{}
data
=
{}
action
=
user
[
"action"
]
action
=
user
[
"action"
]
type
=
data
[
"type"
]
if
"type"
in
data
else
None
msg_
type
=
data
[
"type"
]
if
"type"
in
data
else
None
value
=
data
[
"value"
]
if
"value"
in
data
else
None
value
=
data
[
"value"
]
if
"value"
in
data
else
None
if
action
==
"ready"
:
if
action
==
"ready"
:
# Not playing or waiting
# Not playing or waiting
if
type
==
"join"
:
if
msg_
type
==
"join"
:
if
value
==
None
:
if
value
==
None
:
continue
continue
waiting
=
server_status
[
"waiting"
]
waiting
=
server_status
[
"waiting"
]
...
@@ -122,7 +122,7 @@ async def connection(ws, path):
...
@@ -122,7 +122,7 @@ async def connection(ws, path):
await
ws
.
send
(
msgobj
(
"waiting"
))
await
ws
.
send
(
msgobj
(
"waiting"
))
# Update others on waiting players
# Update others on waiting players
await
notify_status
()
await
notify_status
()
elif
type
==
"invite"
:
elif
msg_
type
==
"invite"
:
if
value
and
"id"
in
value
and
value
[
"id"
]
==
None
:
if
value
and
"id"
in
value
and
value
[
"id"
]
==
None
:
# Session invite link requested
# Session invite link requested
invite
=
get_invite
()
invite
=
get_invite
()
...
@@ -157,7 +157,7 @@ async def connection(ws, path):
...
@@ -157,7 +157,7 @@ async def connection(ws, path):
await
ws
.
send
(
msgobj
(
"gameend"
))
await
ws
.
send
(
msgobj
(
"gameend"
))
elif
action
==
"waiting"
or
action
==
"loading"
or
action
==
"loaded"
:
elif
action
==
"waiting"
or
action
==
"loading"
or
action
==
"loaded"
:
# Waiting for another user
# Waiting for another user
if
type
==
"leave"
:
if
msg_
type
==
"leave"
:
# Stop waiting
# Stop waiting
if
user
[
"session"
]:
if
user
[
"session"
]:
if
"other_user"
in
user
and
"ws"
in
user
[
"other_user"
]:
if
"other_user"
in
user
and
"ws"
in
user
[
"other_user"
]:
...
@@ -182,7 +182,7 @@ async def connection(ws, path):
...
@@ -182,7 +182,7 @@ async def connection(ws, path):
notify_status
()
notify_status
()
])
])
if
action
==
"loading"
:
if
action
==
"loading"
:
if
type
==
"gamestart"
:
if
msg_
type
==
"gamestart"
:
user
[
"action"
]
=
"loaded"
user
[
"action"
]
=
"loaded"
if
user
[
"other_user"
][
"action"
]
==
"loaded"
:
if
user
[
"other_user"
][
"action"
]
==
"loaded"
:
user
[
"action"
]
=
"playing"
user
[
"action"
]
=
"playing"
...
@@ -195,12 +195,12 @@ async def connection(ws, path):
...
@@ -195,12 +195,12 @@ async def connection(ws, path):
elif
action
==
"playing"
:
elif
action
==
"playing"
:
# Playing with another user
# Playing with another user
if
"other_user"
in
user
and
"ws"
in
user
[
"other_user"
]:
if
"other_user"
in
user
and
"ws"
in
user
[
"other_user"
]:
if
type
==
"note"
\
if
msg_
type
==
"note"
\
or
type
==
"drumroll"
\
or
msg_
type
==
"drumroll"
\
or
type
==
"branch"
\
or
msg_
type
==
"branch"
\
or
type
==
"gameresults"
:
or
msg_
type
==
"gameresults"
:
await
user
[
"other_user"
][
"ws"
]
.
send
(
msgobj
(
type
,
value
))
await
user
[
"other_user"
][
"ws"
]
.
send
(
msgobj
(
msg_
type
,
value
))
elif
type
==
"songsel"
and
user
[
"session"
]:
elif
msg_
type
==
"songsel"
and
user
[
"session"
]:
user
[
"action"
]
=
"songsel"
user
[
"action"
]
=
"songsel"
user
[
"other_user"
][
"action"
]
=
"songsel"
user
[
"other_user"
][
"action"
]
=
"songsel"
sent_msg1
=
msgobj
(
"songsel"
)
sent_msg1
=
msgobj
(
"songsel"
)
...
@@ -211,7 +211,7 @@ async def connection(ws, path):
...
@@ -211,7 +211,7 @@ async def connection(ws, path):
user
[
"other_user"
][
"ws"
]
.
send
(
sent_msg1
),
user
[
"other_user"
][
"ws"
]
.
send
(
sent_msg1
),
user
[
"other_user"
][
"ws"
]
.
send
(
sent_msg2
)
user
[
"other_user"
][
"ws"
]
.
send
(
sent_msg2
)
])
])
elif
type
==
"gameend"
:
elif
msg_
type
==
"gameend"
:
# User wants to disconnect
# User wants to disconnect
user
[
"action"
]
=
"ready"
user
[
"action"
]
=
"ready"
user
[
"other_user"
][
"action"
]
=
"ready"
user
[
"other_user"
][
"action"
]
=
"ready"
...
@@ -234,7 +234,7 @@ async def connection(ws, path):
...
@@ -234,7 +234,7 @@ async def connection(ws, path):
ws
.
send
(
status_event
())
ws
.
send
(
status_event
())
])
])
elif
action
==
"invite"
:
elif
action
==
"invite"
:
if
type
==
"leave"
:
if
msg_
type
==
"leave"
:
# Cancel session invite
# Cancel session invite
if
user
[
"session"
]
in
server_status
[
"invites"
]:
if
user
[
"session"
]
in
server_status
[
"invites"
]:
del
server_status
[
"invites"
][
user
[
"session"
]]
del
server_status
[
"invites"
][
user
[
"session"
]]
...
@@ -255,11 +255,11 @@ async def connection(ws, path):
...
@@ -255,11 +255,11 @@ async def connection(ws, path):
ws
.
send
(
msgobj
(
"left"
)),
ws
.
send
(
msgobj
(
"left"
)),
ws
.
send
(
status_event
())
ws
.
send
(
status_event
())
])
])
elif
type
==
"songsel"
and
"other_user"
in
user
:
elif
msg_
type
==
"songsel"
and
"other_user"
in
user
:
if
"ws"
in
user
[
"other_user"
]:
if
"ws"
in
user
[
"other_user"
]:
user
[
"action"
]
=
"songsel"
user
[
"action"
]
=
"songsel"
user
[
"other_user"
][
"action"
]
=
"songsel"
user
[
"other_user"
][
"action"
]
=
"songsel"
sent_msg
=
msgobj
(
type
)
sent_msg
=
msgobj
(
msg_
type
)
await
asyncio
.
wait
([
await
asyncio
.
wait
([
ws
.
send
(
sent_msg
),
ws
.
send
(
sent_msg
),
user
[
"other_user"
][
"ws"
]
.
send
(
sent_msg
)
user
[
"other_user"
][
"ws"
]
.
send
(
sent_msg
)
...
@@ -274,22 +274,22 @@ async def connection(ws, path):
...
@@ -274,22 +274,22 @@ async def connection(ws, path):
elif
action
==
"songsel"
:
elif
action
==
"songsel"
:
# Session song selection
# Session song selection
if
"other_user"
in
user
and
"ws"
in
user
[
"other_user"
]:
if
"other_user"
in
user
and
"ws"
in
user
[
"other_user"
]:
if
type
==
"songsel"
or
type
==
"catjump"
:
if
msg_type
==
"songsel"
or
msg_
type
==
"catjump"
:
# Change song select position
# Change song select position
if
user
[
"other_user"
][
"action"
]
==
"songsel"
and
type
(
value
)
is
dict
:
if
user
[
"other_user"
][
"action"
]
==
"songsel"
and
type
(
value
)
is
dict
:
value
[
"player"
]
=
user
[
"player"
]
value
[
"player"
]
=
user
[
"player"
]
sent_msg
=
msgobj
(
type
,
value
)
sent_msg
=
msgobj
(
msg_
type
,
value
)
await
asyncio
.
wait
([
await
asyncio
.
wait
([
ws
.
send
(
sent_msg
),
ws
.
send
(
sent_msg
),
user
[
"other_user"
][
"ws"
]
.
send
(
sent_msg
)
user
[
"other_user"
][
"ws"
]
.
send
(
sent_msg
)
])
])
elif
type
==
"crowns"
or
type
==
"getcrowns"
:
elif
msg_type
==
"crowns"
or
msg_
type
==
"getcrowns"
:
if
user
[
"other_user"
][
"action"
]
==
"songsel"
:
if
user
[
"other_user"
][
"action"
]
==
"songsel"
:
sent_msg
=
msgobj
(
type
,
value
)
sent_msg
=
msgobj
(
msg_
type
,
value
)
await
asyncio
.
wait
([
await
asyncio
.
wait
([
user
[
"other_user"
][
"ws"
]
.
send
(
sent_msg
)
user
[
"other_user"
][
"ws"
]
.
send
(
sent_msg
)
])
])
elif
type
==
"join"
:
elif
msg_
type
==
"join"
:
# Start game
# Start game
if
value
==
None
:
if
value
==
None
:
continue
continue
...
@@ -311,7 +311,7 @@ async def connection(ws, path):
...
@@ -311,7 +311,7 @@ async def connection(ws, path):
"id"
:
id
,
"id"
:
id
,
"diff"
:
diff
"diff"
:
diff
}]))
}]))
elif
type
==
"gameend"
:
elif
msg_
type
==
"gameend"
:
# User wants to disconnect
# User wants to disconnect
user
[
"action"
]
=
"ready"
user
[
"action"
]
=
"ready"
user
[
"session"
]
=
False
user
[
"session"
]
=
False
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment