Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Voting
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
Voting
Commits
8a4896a0
Commit
8a4896a0
authored
Aug 21, 2021
by
Dennis Willers
🏀
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
First try make Multiplayer
parent
65845954
Pipeline
#431
passed with stages
in 2 minutes and 48 seconds
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
11 deletions
+30
-11
helpFunctions.js
helpFunctions.js
+11
-4
socket.js
socket.js
+19
-7
No files found.
helpFunctions.js
View file @
8a4896a0
...
...
@@ -31,12 +31,19 @@ function sendRequest(url, json, callback) {
});
}
/*function addMapToClient(clintList, client, mapId) {
const clientId = client.name;
}*/
function
addMapToClient
(
clientList
,
currentClient
,
mapId
,
callback
)
{
clientList
.
forEach
(
client
=>
{
if
(
client
.
name
===
currentClient
.
name
)
{
client
.
mapId
=
mapId
;
console
.
log
(
"
Client Map ID found
"
);
}
});
return
callback
(
clientList
);
}
module
.
exports
=
{
isJsonString
,
checkIfRequestHasVote
,
sendRequest
sendRequest
,
addMapToClient
};
socket.js
View file @
8a4896a0
...
...
@@ -15,6 +15,7 @@ server.on('close',function(){
server
.
on
(
'
connection
'
,
function
(
socket
){
// Identify this client
socket
.
name
=
socket
.
remoteAddress
+
"
:
"
+
socket
.
remotePort
;
socket
.
mapId
=
"
null
"
;
clients
.
push
(
socket
);
// Send a nice welcome message and announce
...
...
@@ -68,10 +69,6 @@ server.on('connection',function(socket){
});
socket
.
on
(
'
data
'
,
function
(
data
){
var
bread
=
socket
.
bytesRead
;
var
bwrite
=
socket
.
bytesWritten
;
console
.
log
(
'
Bytes read :
'
+
bread
);
console
.
log
(
'
Bytes written :
'
+
bwrite
);
console
.
log
(
'
Data sent to server :
'
+
data
);
if
(
hf
.
isJsonString
(
data
))
{
...
...
@@ -83,12 +80,17 @@ server.on('connection',function(socket){
}
hf
.
sendRequest
(
url
,
data
,
res
=>
{
if
(
res
)
{
var
is_kernel_buffer_full
=
socket
.
write
(
JSON
.
stringify
(
res
.
data
)
+
'
\n
'
);
const
req
=
JSON
.
parse
(
data
);
hf
.
addMapToClient
(
clients
,
socket
,
req
[
'
mapId
'
],
newClientList
=>
{
clients
=
newClientList
.
slice
();
sendToAllClientsAtSameMap
(
res
,
req
[
'
mapId
'
]);
});
/*var is_kernel_buffer_full = socket.write(JSON.stringify(res.data) + '\n');
if(is_kernel_buffer_full){
console.log('Data was flushed successfully from kernel buffer i.e written successfully!');
} else {
socket.pause();
}
}
*/
}
else
{
console
.
log
(
"
Res was null
"
);
}
...
...
@@ -144,6 +146,16 @@ server.on('connection',function(socket){
process
.
stdout
.
write
(
message
)
}
// Send a message to all clients playing the same map
function
sendToAllClientsAtSameMap
(
res
,
mapId
)
{
console
.
log
(
"
JSON:
"
,
JSON
.
stringify
(
res
.
data
));
clients
.
forEach
(
function
(
client
)
{
// Don't want to send it to sender
if
(
client
.
mapId
===
mapId
)
client
.
write
(
JSON
.
stringify
(
res
.
data
)
+
'
\n
'
);
});
console
.
log
(
"
Write Message to all at
"
+
mapId
+
"
:
"
+
JSON
.
stringify
(
res
.
data
));
}
});
// emits when any error occurs -> calls closed event immediately after this.
...
...
@@ -238,7 +250,7 @@ client.on('data',function(data){
// 87.78.129.86 | localhost
/*
const testClient = net.connect({host: 'localhost', port: 3000}, () => {
const
testClient
=
net
.
connect
({
host
:
'
localhost
'
,
port
:
3000
},
()
=>
{
console
.
log
(
'
connected to server!
'
);
//testClient.write('Hello World Client!\r\n');
testClient
.
write
(
JSON
.
stringify
({
"
mapId
"
:
"
7fsfRSUCQ7YwfBEdRk_GivW6qzj
"
,
"
userId
"
:
"
aKBNg9fbReqLedLiz1KFfA
"
,
"
name
"
:
"
Summer 2021 - 01
"
}));
...
...
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