Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
PlayWallServer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
PlayWall
PlayWallServer
Commits
e26c9bff
Commit
e26c9bff
authored
8 years ago
by
Tobias Ullerich
Browse files
Options
Downloads
Patches
Plain Diff
Improve Code, add new protocol text file
parent
dbb07084
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/resources/protocol.txt
+23
-0
23 additions, 0 deletions
src/main/resources/protocol.txt
src/main/scala/de/tobias/playpad/server/server/project/sync/ProjectSyncHandler.scala
+25
-22
25 additions, 22 deletions
...aypad/server/server/project/sync/ProjectSyncHandler.scala
with
48 additions
and
22 deletions
src/main/resources/protocol.txt
0 → 100644
+
23
−
0
View file @
e26c9bff
===================================
Project Add:
===================================
{
id
name
}
===================================
Project Update:
===================================
{
id
field (name)
value
}
===================================
Project Remove:
===================================
{
id
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/main/scala/de/tobias/playpad/server/server/project/sync/ProjectSyncHandler.scala
+
25
−
22
View file @
e26c9bff
...
...
@@ -17,6 +17,8 @@ import scala.collection.{Map, mutable}
*/
@WebSocket
class
ProjectSyncHandler
(
sessionDao
:
Dao
[
account.Session
,
Int
],
connection
:
Connection
)
{
val
SESSION_KEY_HEADER
=
"key"
// TODO mutable.HashSet --> Set
private
var
sessions
:
Map
[
Account
,
mutable.HashSet
[
Session
]]
=
new
mutable
.
HashMap
[
Account
,
mutable.HashSet
[
Session
]]()
...
...
@@ -27,33 +29,33 @@ import scala.collection.{Map, mutable}
)
@OnWebSocketConnect
def
onConnect
(
serverSession
:
Session
)
:
Unit
=
{
val
key
=
serverSession
.
getUpgradeRequest
.
getHeader
(
"key"
)
val
key
=
serverSession
.
getUpgradeRequest
.
getHeader
(
SESSION_KEY_HEADER
)
if
(
key
==
null
)
{
serverSession
.
close
(
500
,
"Invalid Key"
)
}
val
session
s
=
sessionDao
.
queryForEq
(
"
key
"
,
key
)
if
(
session
s
.
size
()
==
1
)
{
val
session
=
sessions
.
get
(
0
)
if
(!
this
.
sessions
.
contains
(
s
ession
.
getAccount
))
{
this
.
sessions
+=
(
s
ession
.
getAccount
->
new
mutable
.
HashSet
[
Session
]())
val
session
=
account
.
Session
.
getSession
(
key
,
sessionDao
)
session
match
{
case
Some
(
s
)
=>
if
(!
this
.
sessions
.
contains
(
s
.
getAccount
))
{
this
.
sessions
+=
(
s
.
getAccount
->
new
mutable
.
HashSet
[
Session
]())
}
this
.
sessions
(
session
.
getAccount
)
+=
serverSession
}
else
{
serverSession
.
close
(
500
,
"Invalid Key"
)
this
.
sessions
(
s
.
getAccount
)
+=
serverSession
case
None
=>
serverSession
.
close
(
500
,
"Invalid Key"
)
}
}
@OnWebSocketClose
def
onClose
(
serverSession
:
Session
,
status
:
Int
,
reason
:
String
)
:
Unit
=
{
val
key
=
serverSession
.
getUpgradeRequest
.
getHeader
(
"key"
)
val
key
=
serverSession
.
getUpgradeRequest
.
getHeader
(
SESSION_KEY_HEADER
)
if
(
key
==
null
)
{
serverSession
.
close
(
500
,
"Invalid Key"
)
}
val
sessions
=
sessionDao
.
queryForEq
(
"key"
,
key
)
if
(
sessions
.
size
()
==
1
)
{
val
session
=
sessions
.
get
(
0
)
this
.
sessions
(
session
.
getAccount
)
-=
serverSession
val
session
=
account
.
Session
.
getSession
(
key
,
sessionDao
)
session
match
{
case
Some
(
s
)
=>
this
.
sessions
(
s
.
getAccount
)
-=
serverSession
case
None
=>
serverSession
.
close
(
500
,
"Invalid Key"
)
}
}
...
...
@@ -62,7 +64,7 @@ import scala.collection.{Map, mutable}
// Store in Database
try
{
// Push to clients
val
key
=
serverSession
.
getUpgradeRequest
.
getHeader
(
"key"
)
val
key
=
serverSession
.
getUpgradeRequest
.
getHeader
(
SESSION_KEY_HEADER
)
if
(
key
!=
null
)
{
val
parser
=
new
JsonParser
()
...
...
@@ -80,12 +82,13 @@ import scala.collection.{Map, mutable}
serverSession
.
close
(
500
,
"Invalid Key"
)
}
val
session
s
=
sessionDao
.
queryForEq
(
"
key
"
,
key
)
if
(
session
s
.
size
()
==
1
)
{
val
session
=
sessions
.
get
(
0
)
this
.
sessions
(
s
ession
.
getAccount
)
val
session
=
account
.
Session
.
getSession
(
key
,
sessionDao
)
session
match
{
case
Some
(
s
)
=>
this
.
sessions
(
s
.
getAccount
)
.
filter
(
s
=>
s
!=
serverSession
)
.
foreach
(
s
=>
s
.
getRemote
.
sendStringByFuture
(
text
))
case
None
=>
serverSession
.
close
(
500
,
"Invalid Key"
)
}
}
catch
{
case
e
:
Exception
=>
e
.
printStackTrace
()
...
...
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