jespertheend / splix

MIT License
24 stars 5 forks source link

Splix on QNAP NAS? #150

Open melidron opened 1 month ago

melidron commented 1 month ago

Hello from greece I have a QNAP NAS with NGinx installed I have no idea how to use that tool so i wanted to ask if is possible to play splix.io snake game with friends only that have access to my NAS out of my network so we play all together somehow? If yes what is the right methos to do that? Thanks in advanced :)

jespertheend commented 1 month ago

Yeah I think it should be possible! I'm not entirely sure how a QNAP NAS works, but if you can get the gameserver to run on it, others should be able to access you by using the ip in the url. For example https://splix.io/#ip=ws://192.168.0.10:8080 You might not need nginx though, it is only needed if you want to host a public server with an SSL certificate. You might be able to just run the gameserver binary directly, but you'll have set 'insecure content' to 'allow' in the site settings of your browser. In chrome it looks like this:

image

Let me know if you have any questions!

melidron commented 1 month ago

how i make the gameserver run on it... QNAP is a NAS with a linux like based operating system (its own operating system) not sure what else informations would help u understand how it works

jespertheend commented 1 month ago

You should be able to download splixGameServer_linux.tar from the releases page and unarchive it. You should then be able run the executable by using ./splixGameServer from the command line and it should automatically bind to 127.0.0.1:8080 You may have to bind to a different hostname and port using ./splixGameServer --hostname 0.0.0.0 -p 8080 depending on your setup. Once it is running you can verify if you can connect to the server by visiting http://:8080/ in your browser.

melidron commented 1 month ago

i dont think there is a way to instal linux app inside QNAP NAS... the NAS understand only .qpkg files as compatible programs... According to this site there are 3 alternative methods to instal linux apps and the 2 are installing a linux distro inside QNAP... somethins that i dont want and the third metho is with Entware which i have no idea how to use it... https://www.qnap.com/en-us/how-to/faq/article/how-to-install-a-linux-application-in-my-qnap-nas-that-is-not-available-in-app-center

jespertheend commented 1 month ago

Ah sorry, I was assuming you had shell access to the QNAP NAS. I think this might help. If you can log in to the device using ssh you should be able to download the linux binary from the releases page using wget and then run it using the commands I posted earlier. Let me know if that helps.

melidron commented 1 month ago

Ah sorry, I was assuming you had shell access to the QNAP NAS. I think this might help. If you can log in to the device using ssh you should be able to download the linux binary from the releases page using wget and then run it using the commands I posted earlier. Let me know if that helps.

can u explain me please in more details how i do that with ssh? I mean a step by step guide because i dont know how to do it right? I download the linux binary .tar and then put it where in Qnap and how? the local ip for the server qnap is 192.168.2.253

jespertheend commented 1 month ago

I can give you some general steps but a lot depends on your system, so you might have to use a bit of googling/chatgpt to make this work.

First follow the steps on this page to ssh into your device. Once you're in you should be able to run commands and such on the device. I'm assuming a QNAP NAS runs on linux, so on there you can run this to download the server binary:

wget https://github.com/jespertheend/splix/releases/download/v0.14.0/splixGameServer_linux.tar

Once downloaded, assuming tar is installed, you can unarchive the file using

tar -xzf splixGameServer_linux.tar

this will create a file named splixGameServer which you can run using

./splixGameServer

or you can run ./splixGameServer --help for an overview of arguments

If you can get this to run, a little bit of extra work is needed to make sure it keeps running after you exit the ssh session (or in case the process crashes). But let's try this first to see if your device can run the binary at all.

melidron commented 1 month ago

I can give you some general steps but a lot depends on your system, so you might have to use a bit of googling/chatgpt to make this work.

First follow the steps on this page to ssh into your device. Once you're in you should be able to run commands and such on the device. I'm assuming a QNAP NAS runs on linux, so on there you can run this to download the server binary:

wget https://github.com/jespertheend/splix/releases/download/v0.14.0/splixGameServer_linux.tar

Once downloaded, assuming tar is installed, you can unarchive the file using

tar -xzf splixGameServer_linux.tar

this will create a file named splixGameServer which you can run using

./splixGameServer

or you can run ./splixGameServer --help for an overview of arguments

If you can get this to run, a little bit of extra work is needed to make sure it keeps running after you exit the ssh session (or in case the process crashes). But let's try this first to see if your device can run the binary at all.

After downloaded the file with the first command u gave me... when tried to paste the second command to unarchive the file it gave me the following errors (I guess are errors)... Make any sense? Thank You for your time u spend to help me

2024-10-17 22:27:06 (628 KB/s) - ‘splixGameServer_linux.tar’ saved [175958528/175958528]

[SEth@QNAP ~]$ tar -xzf splixGameServer_linux.tar gzip: invalid magic tar: Child returned status 1 tar: Exiting with failure status due to previous errors [SEth@QNAP ~]$ 2024-10-17 22:27:06 (628 KB/s) - ‘splixGameServer_linux.tar’ saved [175958528/175958528] -sh: syntax error near unexpected token `(' [SEth@QNAP ~]$ [SEth@QNAP ~]$ [SEth@QNAP ~]$ tar -xzf splixGameServer_linux.tar -sh: [SEth@QNAP: command not found [SEth@QNAP ~]$ gzip: invalid magic -sh: gzip:: command not found [SEth@QNAP ~]$ tar: Child returned status 1 -sh: tar:: command not found [SEth@QNAP ~]$ tar: Exiting with failure status due to previous errors -sh: tar:: command not found [SEth@QNAP ~]$ [SEth@QNAP ~]$ -sh: [SEth@QNAP: command not found [SEth@QNAP ~]$

melidron commented 1 month ago

I solved the upper issue replacing z with v in the following command... from tar -xzf splixGameServer_linux.tar to tar -xvf splixGameServer_linux.tar and gave me splixGameServer then i wrote the command u told me ./splixGameServer and gave me

[SEth@QNAP ~]$ tar -xvf splixGameServer_linux.tar splixGameServer [SEth@QNAP ~]$ ./splixGameServer error: Uncaught (in promise) AddrInUse: Address already in use (os error 98) at Object.listen (ext:deno_net/01_net.js:422:39) at WebSocketHoster.startServer (file:///home/runner/work/splix/splix/gameSer ver/src/util/WebSocketHoster.js:65:25) at WebSocketManager.startServer (file:///home/runner/work/splix/splix/gameSe rver/src/WebSocketManager.js:54:16) at Main.init (file:///home/runner/work/splix/splix/gameServer/src/Main.js:38 :25) at file:///home/runner/work/splix/splix/gameServer/src/mainInstance.js:79:8 [SEth@QNAP ~]$

Make any sense now?

jespertheend commented 1 month ago

By default when you run ./splixGameServer, the process tries to bind to 127.0.0.1:8080. If another process is already using port 8080 it will throw 'AddrInUse' which seems to be the case for you.

You can try binding to a different port/network using the --port flag like so:

./splixGameServer --port 8081

Although in your case you'll likely also want to bind to the 0.0.0.0 network to make sure connections from outside the NAS can access the server. You can do this with the --hostname 0.0.0.0 flag.

It's also possible this error is thrown then the OS doesn't allow you to bind to a network/port. But I think it will throw a different error in that case. Let me know if this works.

melidron commented 1 month ago

I wrote command ./splixGameServer --port 8081 and see what it gave me...

[SEth@QNAP ~]$ ./splixGameServer --port 8081 error: Uncaught (in promise) AddrInUse: Address already in use (os error 98) at Object.listen (ext:deno_net/01_net.js:422:39) at WebSocketHoster.startServer (file:///home/runner/work/splix/splix/gameServer/src/util/WebSocketHoster.js:65:25) at WebSocketManager.startServer (file:///home/runner/work/splix/splix/gameServer/src/WebSocketManager.js:54:16) at Main.init (file:///home/runner/work/splix/splix/gameServer/src/Main.js:38:25) at file:///home/runner/work/splix/splix/gameServer/src/mainInstance.js:79:8 [SEth@QNAP ~]$

melidron commented 1 month ago

i gave then 8088 port number and gave me than...

[SEth@QNAP ~]$ ./splixGameServer --port 8088 Listening on:

melidron commented 1 month ago

i wrote on browser https://splix.io/#ip=ws://127.0.0.1:8088 and the page open normally asking for my name and when give name and press JOIN button it says " Couldn't connect to the server :/ " Any idea?

jespertheend commented 1 month ago

but since Qnap listen in http://192.168.2.253:8080/cgi-bin/ how is possible pc of same network with Qnap connect and play splix?

To solve this problem processes can bind to different 'ports'. So in this case qnap is listening on port 8080 and you have configured splix to listen on port 8088. Other devices can specify which process they want to connect to using this port. So if you use :8088 in the url you'll connect to the splix process rather than the qnap process.

it says " Couldn't connect to the server :/ "

I think you'll have to include the --hostname 0.0.0.0 argument as well:

./splixGameServer --port 8081 --hostname 0.0.0.0

You'll also have to use the ip of the NAS in the splix.io url. 127.0.0.1 is a special ip which basically connects to your current device. So if you use 127.0.0.1 from a laptop it will try to connect to the laptop itself. Since you're trying to connect to your NAS you'll have to use the ip of your NAS instead.

Before using the ip on splix.io, you can verify if the server is running by visiting http://192.168.2.253:8088/ in your browser, it should show a blank page with the text Endpoint is a websocket. Once you've verified that that works you can try it on splix.io by visiting https://splix.io/#ip=ws://192.168.2.253:8088.

There are some extra things that can cause splix to fail to connect so it's often a good idea to just try the ip without splix first. That way you can narrow the scope of where the issue may be.

melidron commented 1 month ago

i wrote what u said... and it gives me that...

[SEth@QNAP ~]$ ./splixGameServer --port 8088 --hostname 192.168.2.253 Listening on:

jespertheend commented 1 month ago

I think you might have to use --hostname 0.0.0.0 instead of --hostname 192.168.2.253. Or did you already try that?

Also when testing in the browser you should use http:// instead of ws://, only after providing the ip on itch.io should you use ws://

melidron commented 1 month ago

oh i ll try it... didnt know... thank u again for your patience

melidron commented 1 month ago

with http://192.168.2.253:8088 the browser gave me Endpoint is a websocket but when i use https://splix.io/#ip=ws://192.168.2.253:8088 the splix.io page says " An error occured :/ "

jespertheend commented 1 month ago

I think it's probably because your browser doesn't allow secure content. Since splix.io is a https page it doesn't allow connecting to any insecure endpoints. To fix this you'd have to either allow insecure content or get a certificate. Getting a certificate is quite difficult to set up and next to impossible without also purchasing a domain name. So it's easier to try allowing insecure content first.

If you click the controlls icon in your address bar in Chrome and choose 'site settings' it will bring you to chrome://settings/content/siteDetails?site=https%3A%2F%2Fsplix.io. On there you can scroll down to 'Insecure content' and set it to 'allow'. Let me know if that fixes it.

melidron commented 1 month ago

yes...you are a true genius...it works as u said with allow setting in chrome... but how others outside networkcan play if they must allow insecure connection in their browser? is there any other method u think?

jespertheend commented 1 month ago

Unfortunately the only alternative is to get a SSL certificate and purchase a domain name. It's a lot easier to just ask anyone who wishes to join to allow insecure content in their browser.

If you want others to connect to the device you will have to port forward your QNAP NAS on your router. Instructions for this depend a lot on your what router you have, but basically what this will do is allow anyone to connect to the IP of your home address, and your router will forward all the traffic to your QNAP NAS. In this case others will not use ws://192.168.2.253:8088 to connect to the server, but instead they will use the IP of your home address and whichever port you have configured on your router. Let me know if you want to try that.

melidron commented 1 month ago

Is safe to allow something like that to happen? Also can i kill the connection/server and stop connection with other friends so be safe again? how someone stranger can find the adress of my qnap and make an unsafe connection to me? Is there a tool that search for open servers for unsafe connections?

Also in android devices I can not make chrome allow site insecure connection...do u know any way to manage it?

jespertheend commented 1 month ago

If you forward only port 8088, then yes anyone will be able to connect to your server. However, they won't be able to connect to any other ports so the rest of your network should be safe.

I searched around for a bit but I don't think there's any way to get android to allow insecure content. So it seems like getting certificates working is the only option if you want to play from mobile devices. I can give you some general pointers on how to go about that, but this is pretty advanced stuff and I can't really give a step by step guide for that because I'd probably need a lot of googling myself in order to get that to work.

melidron commented 1 month ago

I will apreciate any help u gave me... i understand is not easy to explain so much advanced things to someone that has almost no idea about things like that...Thank u a lot for your help...I admire your patience :)

jespertheend commented 1 month ago

No worries, I'm happy to help :)

If you want to try out installing certificates you can either purchase a domain name and use letsencrypt and certbot to get certificates, or you can search online on how to create self signed certificates. The downside of purchasing a domain is that it costs money and certbot is probably going to be difficult to get working without some port forwarding. The downside of self signed certificates is that anyone who wants to connect to the server will have to install them on their device. I've never done that on a phone but I can't imagine that being easy either.

I'd recommend trying a self signed certificate first. But if you're willing to pay $15/year for a domain, you might as well purchase a server and host it on something like DigitalOcean, since getting certificates there is a lot easier than on your NAS.

melidron commented 1 month ago

i prefer learn self signed certificates method...what should i do to create them and install them?

melidron commented 1 month ago

I have downloaded this tool inside Qnap unofficial store... I send u the page https://github.com/FiloSottile/mkcert it say something about create certificates... i have no idea if i need something like that and if yes how i use it... What u think?

jespertheend commented 1 month ago

Yeah that sounds like the thing you'll need. Although I'm not sure how to use that either 😅.