This repository was archived by the owner on May 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver-script.js
More file actions
99 lines (72 loc) · 2.29 KB
/
server-script.js
File metadata and controls
99 lines (72 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
const app = require('express')(),
http = require('http').Server(app),
io = require('socket.io')(http),
os = require('os'),
readline = require('readline'),
rl = readline.createInterface(process.stdin, process.stdout);
var engine = require('./js/engine.js'),
ifaces = os.networkInterfaces(),
address = ifaces['Wi-Fi'][1].address;
/*----FILE SEND----*/
app.get('/', function(req, res){
res.sendFile(__dirname + '/index.html');
});
app.get('/favicon.ico', function(req, res){
res.sendFile(__dirname + '/favicon.ico');
});
app.get('/css/style.css', function(req, res){
res.sendFile(__dirname + '/css/style.css');
});
app.get('/js/client-script.js', function(req, res){
res.sendFile(__dirname + '/js/client-script.js');
});
app.get('/js/libs/three.min.js', function(req, res){
res.sendFile(__dirname + '/js/libs/three.min.js');
});
app.get('/js/libs/stl_loader.js', function(req, res){
res.sendFile(__dirname + '/js/libs/stl_loader.js');
});
/*----FILE SEND----*/
/*----THE GOOD STUFF----*/
io.on('connection', function(socket){
/*----CHEAT CHEET----*?
socket.emit('string', 'data');
|sends 'data' with string attached. the string will
|tell the recipient what to do with said data
socket.broadcast.emit('string', 'data');
|sends 'data' with attached string to ALL
|clients/servers connected
socket.on('string', function('data'){
//things to do with this data//
});
|when the client/server with this code recieves
|the 'string', it will perform a series of actions
|with the attached 'data'
?*----CHEET SHEET----*/
console.log('connected: [' + socket.id + ']');
socket.on('data-req', function(){
socket.emit('g_rules', engine.g_rules);
socket.emit('CREATE', engine.s_bodies);
});
socket.on('disconnect', function(){
console.log('disconnected: [' + socket.id + ']');
io.emit('removePlayer', socket.id);
});
});
/*----THE GOOD STUFF----*/
/*----PORT SET----*/
rl.setPrompt('>');
console.log('define server-port:');
rl.prompt();
rl.on('line', function(line){
var port = Number(line);
var ip_address ='0.0.0.0';
http.listen(port, ip_address, function(){
console.log('----Server Created----');
console.log('IP-host:' + address);
console.log('server-port: ' + port);
});
}).on('close', function(){
process.exit(0);
});
/*----PORT SET---*/