Cleaned code & updated README
This commit is contained in:
parent
95741499fd
commit
15f17ab329
16
README.md
16
README.md
@ -9,16 +9,18 @@ It's only a bit of fun. His servers are much better ;P
|
|||||||
### Setup
|
### Setup
|
||||||
Install node.js and download scripts
|
Install node.js and download scripts
|
||||||
```
|
```
|
||||||
git clone https://github.com/clerie/pixelnode
|
sudo apt-get nodejs git
|
||||||
sudo apt-get nodejs
|
git clone https://github.com/clerie/pixelnode
|
||||||
nodejs index
|
cd pixelnode/
|
||||||
|
nodejs index
|
||||||
```
|
```
|
||||||
|
Open the shown http port in a browser (you can use multiple on multiple machines).
|
||||||
|
Start playing at the shown input port.
|
||||||
|
|
||||||
Open localhost:61813 in a browser (you can use multiple).
|
### Default ports
|
||||||
|
* HTTP (for viewing) `61813`
|
||||||
|
* INPUT (for plaing) `1337`
|
||||||
|
|
||||||
### Play
|
### Play
|
||||||
Use PixelNode with the same protocol as Pixelflut:
|
Use PixelNode with the same protocol as Pixelflut:
|
||||||
https://github.com/defnull/pixelflut#pixelflut-protocol
|
https://github.com/defnull/pixelflut#pixelflut-protocol
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
14
index.js
14
index.js
@ -10,9 +10,6 @@ const myip = require('quick-local-ip');
|
|||||||
const ip4 = myip.getLocalIP4();
|
const ip4 = myip.getLocalIP4();
|
||||||
const ip6 = myip.getLocalIP6();
|
const ip6 = myip.getLocalIP6();
|
||||||
|
|
||||||
console.log(ip4);
|
|
||||||
console.log(ip6);
|
|
||||||
|
|
||||||
// define canvas
|
// define canvas
|
||||||
var canvas_size_x = 100;
|
var canvas_size_x = 100;
|
||||||
var canvas_size_y = 100;
|
var canvas_size_y = 100;
|
||||||
@ -100,7 +97,6 @@ io.on('connection', function (socket){
|
|||||||
var server = net.createServer();
|
var server = net.createServer();
|
||||||
|
|
||||||
server.on('connection', function (server_socket) {
|
server.on('connection', function (server_socket) {
|
||||||
console.log(server_socket);
|
|
||||||
conn_count++;
|
conn_count++;
|
||||||
server_socket.setEncoding('utf8');
|
server_socket.setEncoding('utf8');
|
||||||
console.log('[INPUT] new input');
|
console.log('[INPUT] new input');
|
||||||
@ -112,18 +108,12 @@ server.on('connection', function (server_socket) {
|
|||||||
if (x <= canvas_size_x && y <= canvas_size_y) {
|
if (x <= canvas_size_x && y <= canvas_size_y) {
|
||||||
if (!isNaN(x) && !isNaN(y)) {
|
if (!isNaN(x) && !isNaN(y)) {
|
||||||
if (command[3] != undefined) {
|
if (command[3] != undefined) {
|
||||||
console.log("c is there");
|
|
||||||
var color = str_to_color(command[3]);
|
var color = str_to_color(command[3]);
|
||||||
console.log(color);
|
|
||||||
if (color !== false) {
|
if (color !== false) {
|
||||||
console.log("c ok");
|
|
||||||
io.sockets.emit('draw', {type: 'pixel', x: x, y: y, color: color_to_html(color)});
|
io.sockets.emit('draw', {type: 'pixel', x: x, y: y, color: color_to_html(color)});
|
||||||
pixel_count++;
|
pixel_count++;
|
||||||
color_to_canvas_content(x, y, color);
|
color_to_canvas_content(x, y, color);
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
console.log("c not ok");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
server_socket.write('PX ' + x + ' ' + y + ' ' + get_color(x, y) + '\n');
|
server_socket.write('PX ' + x + ' ' + y + ' ' + get_color(x, y) + '\n');
|
||||||
}
|
}
|
||||||
@ -142,7 +132,7 @@ server.on('connection', function (server_socket) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// start http
|
// start http
|
||||||
http.listen(http_port, () => console.log('[HTTP] port: ' + http_port));
|
http.listen(http_port, () => console.log('[HTTP] started server at ' + ip4 + ':' + http_port));
|
||||||
|
|
||||||
// start input socket
|
// start input socket
|
||||||
server.listen(input_port, () => console.log('[INPUT] port: ' + input_port));
|
server.listen(input_port, () => console.log('[INPUT] started server at ' + ip4 + ':' + input_port));
|
||||||
|
Loading…
Reference in New Issue
Block a user