Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Tabu-Middleware
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Container Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Dennis Willers
Tabu-Middleware
Commits
defeee15
Commit
defeee15
authored
4 years ago
by
Dennis Willers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ermittlung wie viele Spieler in einem Raum sind und wie viele Spieler welchen Team beigetreten sind
parent
79550d8f
Pipeline
#395
passed with stages
in 2 minutes and 8 seconds
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
0 deletions
+56
-0
nodemon.json
nodemon.json
+7
-0
socket.js
socket.js
+49
-0
No files found.
nodemon.json
0 → 100644
View file @
defeee15
{
"events"
:
{
"restart"
:
"sh -c 'lsof -i :${PORT:-3000} -t | xargs kill'"
,
"crash"
:
"sh -c 'lsof -i :${PORT:-3000} -t | xargs kill'"
},
"delay"
:
1500
}
This diff is collapsed.
Click to expand it.
socket.js
View file @
defeee15
...
...
@@ -11,9 +11,28 @@ Http.listen(3000, () => {
});
var
currentCard
=
{};
var
clients
=
{};
// Value = ClientID / Key = [SessionID, Team] / Team = 0 (total), 1 (red) or 2 (blue)
var
clientsInSession
=
{};
// Value = SessionID / Key = [total, red, blue}
function
getSumClients
(
sessionName
,
team
,
action
)
{
// Team = 0 (total), 1 (red) or 2 (blue) / Action = 1 (add) or -1 (remove)
if
(
!
clientsInSession
.
hasOwnProperty
(
sessionName
))
{
clientsInSession
[
sessionName
]
=
[
0
,
0
,
0
];
}
if
(
team
===
0
)
{
clientsInSession
[
sessionName
]
=
[
clientsInSession
[
sessionName
][
0
]
+
action
,
clientsInSession
[
sessionName
][
1
],
clientsInSession
[
sessionName
][
2
]];
}
if
(
team
===
1
)
{
clientsInSession
[
sessionName
]
=
[
clientsInSession
[
sessionName
][
0
]
+
action
,
clientsInSession
[
sessionName
][
1
]
+
action
,
clientsInSession
[
sessionName
][
2
]];
}
if
(
team
===
2
)
{
clientsInSession
[
sessionName
]
=
[
clientsInSession
[
sessionName
][
0
]
+
action
,
clientsInSession
[
sessionName
][
1
],
clientsInSession
[
sessionName
][
2
]
+
action
];
}
return
{
total
:
clientsInSession
[
sessionName
][
0
],
red
:
clientsInSession
[
sessionName
][
1
],
blue
:
clientsInSession
[
sessionName
][
2
]};
}
Socketio
.
on
(
"
connection
"
,
socket
=>
{
console
.
log
(
'
new Socket connect
'
);
clients
[
socket
.
id
]
=
[
null
,
null
];
for
(
var
key
in
currentCard
)
{
socket
.
emit
(
key
,
currentCard
[
key
])
...
...
@@ -43,6 +62,8 @@ Socketio.on("connection", socket => {
socket
.
emit
(
data
.
sessionName
+
"
:newRound
"
,
false
);
Socketio
.
emit
(
data
.
sessionName
+
"
:endRound
"
,
true
);
socket
.
emit
(
data
.
sessionName
+
"
:endRound
"
,
true
);
let
sumClients
=
getSumClients
(
data
.
sessionName
,
null
,
0
);
Socketio
.
emit
(
data
.
sessionName
+
"
:sessionPlayers
"
,
sumClients
);
});
socket
.
on
(
"
canPressTabooh
"
,
data
=>
{
console
.
log
(
'
CanPressTabooh from:
'
,
data
.
sessionName
,
data
.
canPressTabooh
);
...
...
@@ -54,5 +75,33 @@ Socketio.on("connection", socket => {
Socketio
.
emit
(
data
.
sessionName
+
"
:historyChanged
"
,
data
);
socket
.
emit
(
data
.
sessionName
+
"
:historyChanged
"
,
data
);
});
socket
.
on
(
"
sessionPlayers
"
,
data
=>
{
const
client
=
clients
[
socket
.
id
];
console
.
log
(
'
CLIENT:
'
,
client
,
data
.
team
);
if
(
data
.
sessionName
===
null
&&
client
[
0
]
!==
null
)
{
let
sumClients
=
getSumClients
(
client
[
0
],
client
[
1
],
-
1
);
Socketio
.
emit
(
client
[
0
]
+
"
:sessionPlayers
"
,
sumClients
);
clients
[
socket
.
id
]
=
[
null
,
null
];
}
else
{
if
(
data
.
sessionName
!==
client
[
0
]
||
data
.
team
!==
client
[
1
])
{
let
sumClients
=
getSumClients
(
client
[
0
],
client
[
1
],
-
1
);
Socketio
.
emit
(
client
[
0
]
+
"
:sessionPlayers
"
,
sumClients
);
clients
[
socket
.
id
]
=
[
data
.
sessionName
,
data
.
team
];
sumClients
=
getSumClients
(
data
.
sessionName
,
data
.
team
,
data
.
newAction
);
Socketio
.
emit
(
data
.
sessionName
+
"
:sessionPlayers
"
,
sumClients
);
socket
.
emit
(
data
.
sessionName
+
"
:sessionPlayers
"
,
sumClients
);
}
}
});
socket
.
on
(
"
disconnect
"
,
()
=>
{
const
client
=
clients
[
socket
.
id
];
console
.
log
(
"
DISCONNECT CLIENT:
"
,
client
);
if
(
client
!==
null
&&
client
[
0
]
!==
null
)
{
const
sumClients
=
getSumClients
(
client
[
0
],
client
[
1
],
-
1
);
Socketio
.
emit
(
client
[
0
]
+
"
:sessionPlayers
"
,
sumClients
);
}
delete
clients
[
socket
.
id
];
});
});
This diff is collapsed.
Click to expand it.
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