barronwaffles / dwc_network_server_emulator

A Nintendo DS and Wii server emulator.
GNU Affero General Public License v3.0
1.06k stars 165 forks source link

How to setup an own server? #81

Closed wzhy90 closed 9 years ago

wzhy90 commented 9 years ago

I have clone the git to local and how can I start up the server in local? My computer is running linux

SMTDDR commented 9 years ago

Now that you've cloned it, you need to just install twisted: https://pypi.python.org/pypi/Twisted . Then, in the directory that was created by git clone, type "python master_server.py" If everything is correct, you'll see something like "waiting for connections".

Now, all this is the easy part.... the hard part is the networking manipulation needed to make a Wii console use your server instead of the ones hardcoded in the game. You'll either need a DNS server or some other way of routing traffic. Also, all games connect via SSL to naswii server so you'll need a way to patch your game to remove "s" from the "https" string inside the game code. I think brainslug does this for all games it loads. If you don't have brainslug, then you'll need some kind of RomPatcher or memory-patcher(Riivolution) and you'll need to know how to make a patch file for the game.

If you get that all squared away, the last thing you'll probably end up doing is changing this line: https://github.com/polaris-/dwc_network_server_emulator/blob/master/nas_server.py#L45 to something that's reachable by the patched games.

MrMonopoly commented 9 years ago

How do I get the clone? The clone link is not working.

SMTDDR commented 9 years ago

@MrMonopoly

On this repo, you need to do a "git clone". You'll have to read documentation on installing git for exactly how/why this work. Specifically for this repo, the command is git clone https://github.com/polaris-/dwc_network_server_emulator.git

MrMonopoly commented 9 years ago

Is there a way I can connect to the game servers on this site using an ISO?

SMTDDR commented 9 years ago

@MrMonopoly

It's definitely possible but I don't know how. Have a look at this: https://forums.dolphin-emu.org/Thread-unofficial-dolphiilution-riivolution-for-dolphin If you can get that to work for any game you have, then tell me what game you need a riivolution patch for. Now, since main.dol is illegal to distribute I'll need you to run the linux program "strings" on main.dol and then send me the output.

NOTE: It's very important that you do not link to any illegal files or ISOs in this site... or pastebin.. or anything.... so, there's not really any way to get the data to me =/

MrMonopoly commented 9 years ago

First, I don't have Linux, Second, If the game I want patched (Battalion Wars 2) is not allowed because it is [link removed] which could be illegal?

SMTDDR commented 9 years ago

@MrMonopoly

Could you edit your github comment to remove that URL? No links to illegal files. Somebody somewhere needs to patch any ROM you want. But getting into the details of that on github I suspect is bad news. You'll have find some kind of forum out there and have them do it.

kyle95wm commented 9 years ago

Okay so I cloned the github to my Raspberry Pi and installed the needed things BUT for some reason Python throws up several call host errors when a connection from the Wii is refused

I don't quite understand the setup process either

SMTDDR commented 9 years ago

@BeanJr

Here's where things get complicated. I don't know how to explain the network setup to make this work; I can only tell you what your end-goal is. You need to send the Wii's network traffic to your RPi and you need a way to verify that whatever you did to redirect traffic is actually working. The network monitoring tool "Wireshark" will come in handy here. You have to fix any errors you see.

kyle95wm commented 9 years ago

Hmmm I remember seeing somewhere in this post I had to change a line in the nas server python script to some sort of address - it was using the local loopback by default so I'm not sure if that needs to be changed to something else or if I need to leave things the way they are

On the other hand, do I set my Wii's DNS to my Pi's IP? If I do that the connection test fails on the Wii (however I can force activate the connection using Offline Network Enabler) but doing so won't make things better

I suppose what I can do to be on the safe side is to re-clone the git to my Pi (I might have messed with things I shouldn't have) and see if I can re-analyze the problem

So again, do I need to change the port 9000 address (the one thats not commented out) in the nas file?

Is there anything else that would need to be done in terms of server setup? Also once I run the master server file (I'm SSH'd into the Pi ATM) can I freely close out the connection and the server will still run?

The main problem I'm facing here is either I don't have a proper DNS setup (mind you this Pi is freshly installed and I only installed the minimum for hosting a web server from my Pi which works wonders with no-ip) so somehow I need to get my Wii to connect to my Pi and the rest would be easy

SMTDDR commented 9 years ago

@BeanJr That's true, it cannot use the loopback. Change this: https://github.com/polaris-/dwc_network_server_emulator/blob/master/nas_server.py#L45 - Make it use port 80 and make it be '0.0.0.0' instead of 127.0.0.1.

Next, you need a DNS server. You could install dnsmasq on your RPi. Probably set it up such that any DNS queries sent to it will reply with the IPaddress of the RPi. Then go ahead and put the RPi's address as the DNS servers in the Wii's network settings.

The biggest issue though, is that inside the Wii games there are URLs that need to changed such that they don't use https://(port 443) but only http://(port 80). If you have Wii HomeBrewChannel and have something called Brainslug, I'm told that it automatically makes these changes.

After this, I think you'll be a lot closer.

mm201 commented 9 years ago

You need to find a web server and DNS server on your own. They are not part of this project. I believe the main server is using Apache and dnsmasq for this.

May I inquire why you want to run your own server? Usually we discourage this since it divides the player base and makes for a worse experience for everyone.

kyle95wm commented 9 years ago

Okay I'll give this a shot

is there any setup required for dnsmasq?

Also I'm aware of the game patching requirements (I have a custom track pack that has ALTWFC support built right in)

@mm201 - it's a learning experience for me to know how this works and perhaps this could be used with friends or whatever (or in case this server and Wiim's goes down)

mm201 commented 9 years ago

@SMTDDR: The problem is, there are three separate servers (four if you count stats) listening on three different ports. Normally, a web server is used to proxy requests to each of these servers, which is why it's configured to only listen on localhost.

Port 9002 maps to gamestats.gs.nintendowifi.net Port 9000 maps to nas.nintendowifi.net, naswii.nintendowifi.net, and conntest.nintendowifi.net Port 8000 maps to sake.gs.nintendowifi.net and *.sake.gs.nintendowifi.net

kyle95wm commented 9 years ago

Okay so a little update -

I installed that DNS thing you mentioned and the connected test worked!

However I'm facing a bigger problem. The Wii can't connect to my server (error 20100)

First thing I tried was commenting out the line in the nas server file that lead to port 9000 and un-commented the port 80 one and that didn't work. I did it in the reverse order and it still isn't working

I'd love to be able to get this working, as it kind of gives me an idea of how all this is set up

kyle95wm commented 9 years ago

http://pastebin.com/BVmEDmML for your convenience

mm201 commented 9 years ago

Are you sure your Wii is configured to use your DNS? Do you have the necessary entries added so nintendowifi.net points to your server?

kyle95wm commented 9 years ago

Yes I'm sure my Wii is set to use my (newly installed) DNS

I'm a bit confused by your last part "Do you have the necessary entries added so nintendowifi.net points to your server?" I installed dnsmasq but I'm unsure of how to add entries to it (which might be part of the problem)

SMTDDR commented 9 years ago

[2014-12-11 15:49:59 | NasServer] Now listening for connections on 127.0.0.1:9000...

I know that's going to be a problem unless you have something else that redirects all port 80 destine traffice to port 9000.

And there's definitely something that has to be done for dnsmasq besides just installing it, but I haven't used it myself.

A-IOSTREAM commented 9 years ago

@BeanJr: Add this line to your /etc/dnsmasq.conf file:

address=/nintendowifi.net/0.0.0.0

(replace 0.0.0.0 with your server IP address) and then restart dnsmasq.

kyle95wm commented 9 years ago

YESSSS got it working somewhat

[2014-12-11 16:31:43 | GameSpyQRServer] [192.168.101.2:58935] Received availability request for 'mariokartwii' from 192.168.101.2:58935...

which resulted in error 23404

mm201 commented 9 years ago

Looks like your Nas server isn't listening on the correct port. Either use @SMTDDR's hack (make the Nas server listen on port 80 and all devices) or install a web server to function as a reverse proxy.

kyle95wm commented 9 years ago

Okay so for @SMTDDR 's hack to work do I uncomment the line above with the "0.0.0.0 80" thing and keep the loopback with port 9000 uncommented as well? I tried both but there were complaints fired back about the address "already in use" and got the same error

I'm SO close

FYI I already have a basic web server installed (apache) but theres nothing really to it so I'm basically started from ground 0 in terms of that

Update - looks like my DNS server decided to crash - connection test failed on my Wii as I was about to double check things -sigh- how lovely

I still want to get this done so I can feel like I've accomplished something

kyle95wm commented 9 years ago

Okay so I did the forced activation of the connection and get 23404 as expected so back in business. I'm still confused about the whole "making NAS listen to port 80" and what's involved in doing that. I'm not experienced in networking, but Im going to school to learn about it (this is my first year(

SMTDDR commented 9 years ago

https://github.com/polaris-/dwc_network_server_emulator/blob/master/nas_server.py#L45

See that line? Change it to look like the commented out code above, address = ("0.0.0.0", 80) . Now that you've done this, you'll need to run this server as root because only root can bind ports lower than 1024. Note that in the professional world, running a webserver as root is a big no-no because it's hyper-dangerous but for the purposes of just learning, just do that for now.

kyle95wm commented 9 years ago

@SMTDDR tried your method and this is what happened when I ran "sudo python master_server.py" http://pastebin.com/SL2XHEnH

edit - this also gives the same error code 23404

kyle95wm commented 9 years ago

Okay I found something interesting. I noticed that when I restarted my Pi and attempted to connect it returned the same error but THIS TIME I didn't run any scripts. This all has to do with dnsmasq it seems

SMTDDR commented 9 years ago

There might be something already holding that port 80. dnsmasq should be holding port 53

kyle95wm commented 9 years ago

How could I check this? When I type "dnsmasq" I get "dnsmasq: failed to create listening socket for port 53: Permission denied" even with sudo

SMTDDR commented 9 years ago

hmm... there's a command called "lsof" you can run as root.

http://www.debian-administration.org/article/184/How_to_find_out_which_process_is_listening_upon_a_port

kyle95wm commented 9 years ago

ran that and this is what comes up

http://prntscr.com/5ftc0k

What must I do? Im not very experienced with this sort of stuff

SMTDDR commented 9 years ago

Ah! That makes sense, you installed apache and that's holding port 80. I guess for now, you should remove apache or at least shut it down.

kyle95wm commented 9 years ago

Looks like I'm in business. Say if I wanted to share this server out on the internet what ports would need to be opened on my router? (accounting for TCP/UDP/BOTH)

SMTDDR commented 9 years ago

First you'll need some kind of IP-address-reservation such that every time your RPi goes online it always gets the same IP address. Then you'd add port forwarding for all the ports you see in the altwfc output Now listening for connections All those ports. Also, port 53 for dnsmasq.

Now, there's a problem here in that the interwebz are kinda hostile. The moment you expose a machine to the public you get bombarded with DDoSes and hack attempts. Your DNS server is going to get a ton of requests from malicous people and your webserver is also going to get all kinds of hack attempts thrown at it. For me personally, the DDoS on my dnsserver were severe enough to stop my home router from working during the network flood and I ultimately gave up running stuff from my home internet.

kyle95wm commented 9 years ago

uhhhhh whats going on here? It was working fine one moment and now its completely screwed up

http://pastebin.com/UnPYjtG2

kyle95wm commented 9 years ago

Okay nvm I had to exit my SSH session and re-opened it and ran the python script again and it fixed the problem with logging into my server. I honestly don't know why it was throwing up all those errors. Sometimes the server throws back 61070 or something like that the first time I run the script then when I use ctrl+z to stop the server and re-run the above paste happens

Also please look at the thread about ban support I want to know if its possible to make a simple ban system - again testing things

SMTDDR commented 9 years ago

ctrl+z doesn't stop the process, it moves it into the background and suspends it. The ports will still be in use.

ban support is possible but complicated and prone to errors. On my instance of altwfc I have one person banned. The easiest place to do this is in NASserver code: https://github.com/polaris-/dwc_network_server_emulator/blob/master/nas_server.py#L103 . I have a globally defined python list "banned_people" and I manually put people in that list. Right after that line of code, I check if the current person is in the bannedpeople list. If they are, I change authtoken into an empty string which, funny enough, will crash Tatsunoko vs Capcom(TvC). There are attributes that are hard (but not impossible)_ to change about a Wii console. macaddr, cfc, userid, csnum appear to be unique and stay the same for all the Wii console connections I've seen so I ban using one or more of those values. Look at the file nas_server.log after at least one Wii console has connected.

The challenge here though, is how you're going to figure out which player is which Wii console. I have a website where people can see who's online for TvC, the name they're using as well as the dwc_pid. People report to me what they see on that page when they encounter a cheater/lag-switcher so I can find them in my logs using the dwc_pid and from there look at all the sqlite tables to figure out which Wii owns that dwc_pid and I can ban from there.

Without my custom website, I have no idea how I'd figure out who is who or how anyone will be able to report to me. The names in TvC are not unique, anyone can use anyone else's name so the website tying together name with dwc_pid is the only way people can tell me who to ban. Kinda like how in real-life, people's names are not unique but names + SocialSecurityNumber should be unique.

So yeah, in short before you (or anyone) can ban a player they first must really understand this atlwfc code and the behavior of the game they're trying to ban for. Pretty messy and I suspect that's why there's no ban support right now =/ Even if you paid me a million dollars, I wouldn't know how to build in ban support for all games in general.

polaris- commented 9 years ago

Just want to point out there is very basic support for banning a specific profile id only, but it only works on that specific profile id. There's a field in the "users" table named "enabled". It's set to 1 by default, but if you set it to 0 then it should stop them from logging in. It would also be trivial to add a table in the database containing a list of banned console IDs, or something like that, too. An interface just needs to be added to make it easier to use.

If anyone wants to submit a pull request with some code for a ban system then I will accept it if it looks fine. It's a kind of cat and mouse game that I don't want to waste my time and energy on, though.

Edit: SMTDDR also hit the nail on the head with his comment.

kyle95wm commented 9 years ago

This is more complicated than I thought. Anyways going back a little about exposing the server to the world, I had a friend try to connect to it, and they couldn't get the DNS to work. Ive even went as far as setting my Pi and the DMZ in my router and even did some self tests with my phone as the internet for my Wii and didn't get much luck

SMTDDR commented 9 years ago

@BeanJr

When you do this, don't give your friend the IPaddr of your RPi. That's a local IP on your network, you need the external one. Go to this website to see what your IPaddr looks like to the outside world: http://www.whatsmyip.org/ (or your router's settings probably shows what it is too). This external IP is what was assigned to you by your ISP and it's what the modem is holding onto.

SMTDDR commented 9 years ago

oh, one way to check if you have the port forwarding thing set right - at least for port 80. The IP address you get in whatsmyip.org, you should be able to type that IP address in your web-browser and see "ok" on the screen. This "ok" comes from this part of the code: https://github.com/polaris-/dwc_network_server_emulator/blob/master/nas_server.py#L70 .

Your friend should also be able to put that IP in their browser to see that "ok" as well.

kyle95wm commented 9 years ago

Okay I just tested on my iPhone's 3G connection and after fixing ports and stuff in the router the ok thing comes up. Now the only problem is, why does it fail on a Wii? Ive exposed my server so that every single port is opened (DMZ) and nothing has worked thus far

SMTDDR commented 9 years ago

you can check the DNS stuff is working using the "dig" command. So, If we pretend your IPaddr is 24.1.934.112, do this: dig @24.1.934.112 naswii.nintendowifi.net and you'll get a bunch of stuff back. One of the things you should see is:

;; ANSWER SECTION:
naswii.nintendowifi.net. 300    IN  A   24.1.934.112
kyle95wm commented 9 years ago

for your interest, heres my port forwarding scheme http://prntscr.com/5g6ila

SMTDDR commented 9 years ago

That screenshot looks reasonable. I see some duplicates but I guess that won't hurt.

But yeah, try the DNS command with the external IP you have to make sure it works. As well as the external IP giving you that "ok" page.

kyle95wm commented 9 years ago

tried both and worked in both cases but its not working on the Wii (error 52232)

SMTDDR commented 9 years ago

@BeanJr

Is this error happening in the game or is this happening during the Wii's connection test (assuming this is a regular Wii, not the WiiU)?

kyle95wm commented 9 years ago

connection test

SMTDDR commented 9 years ago

Hmm, that's odd. So that DNS query I talked about, you're sure in the Answer section it returns the external IPaddr, not that local one 192...* right? And the external IPaddr also returns "ok"? That's normally what the problem is at this point.

kyle95wm commented 9 years ago

that correct