mm201 / pkmn-classic-framework

Pokémon application logic for Generation IV and V, including servers
http://pkmnclassic.net/
Other
212 stars 43 forks source link

Time to get it working on Linux with Mono and Apache #50

Open ghost opened 6 years ago

ghost commented 6 years ago

From @ghost :

"Hey @mm201 , I've redone the install, and I've actually done this on mod_mono. I've also setup the tetrisds store.asp, great job on that btw, and I have only one issue, which is my mod_mono isn't taking requests for /pokemondpds/worldexchange/info.asp, only /pokemondpds.ashx/worldexchange/info. However, I have messaged a person who IK uses mod_mono, so let's hope it works 😛"

No information about it, just a text and no sharing of the solutions. What a shame for an opensource project communauty.

Someone here have the method to use Apache and Mono ? It's time to get it working definitively on Linux ...

I will try in my side to get it working without any documentation

InternalLoss commented 5 years ago

This never did work with Mono; iirc some of the ways that @mm201 coded means that it wont work on mod_mono w/o modification.

flutterbrony commented 5 years ago

Maybe try with the .net core ?

U-1F992 commented 2 years ago

I was able to set this up with Debian (Apache+mod_mono), and I'm reporting it briefly. But basically, just follow the instructions given in the wiki.

First, I had to install "libapache2-mod-mono", "mono-xsp" and "mono-complete".

apt install -y libapache2-mod-mono mono-complete mono-xsp

Put the files published by Visual Studio in the root of your server (e.g. /var/www/gamestats2.gs.nintendowifi.net/) and edit gamestats2.gs.nintendowifi.net.conf as follows

<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        ServerName gamestats2.gs.nintendowifi.net
        ServerAlias "gamestats2.gs.nintendowifi.net, gamestats2.gs.nintendowifi.net"

        DocumentRoot /var/www/gamestats2.gs.nintendowifi.net
        MonoAutoApplication disabled
        MonoServerPath "/usr/bin/mod-mono-server4"
        MonoApplications default "/:/var/www/gamestats2.gs.nintendowifi.net"

        <Location />
                SetHandler mono
                MonoSetServerAlias default
        </Location>
</VirtualHost>

This will stop forwarding requests to the AltWFC(gamestats_server_http.py) that you have set up beforehand, and send them to mod_mono instead.

In my environment, I could get the pkmnFoundation server running on Linux with this configuration.

Cowboyjunkie commented 2 years ago

Hi guys! I'm currently trying to get this to run on Linux. Setup: Raspian Pi OS Bullseye x64 light Mono-complete Mono-fastcgi-server4 Nginx Status so far: dwc_network_server_emulator -> up and running -> heavily modified to be a Mystery Gift Distro for Gen 4,5,6,7 -> Working Pkmn-Classic -> Database -> working web -> working gts -> partly working -> Gen4 cannot connect to GTS (last thing I see on Wireshark is the SSLv3 but Handshake seems not to work), Gen5 can connect but drops just before checking the Pokemon (last thing on Wireshark is the DNS query for the pkvldtprod) I will setup a mitm proxy in the next days and try to get to the bottom of this.

redpolline commented 1 year ago

Hello all,

It's 2023, so lets try and get this issue dealt with. I've made some patches to fix things up in my fork, but I wanted to check here before issuing a pull request.

First the short version:

It is possible to compile and run everything with Mono and Apache under Linux. You'll need to install MonoDevelop* but it is doable.

There is a bugfix for GamestatsBase in my fork that fixes an ArgumentOutOfRangeException under Mono. You'll need that to get things past the initial GTS / Battle Video status check. (Otherwise doing any search will cause the GTS to boot you back to the Global Terminal with a comm error. While the Battle Video server will simply report an error and you'll stay in the Vs. Seeker's Global Menu.)

Now the long version (Feel free to skip this if you don't want to read it.):

Short term the patches I've made will work just fine. Long term, it's very fragile. Any update to Linux or the nuget packages that the project uses will probably break things.

This is due to two things: 1) MonoDevelop being unmaintained and deprecated by Microsoft (since 2020) in favor of VSCode and their dotnet SDK. As of Debian 12 you cannot even install MonoDevelop anymore without installing a Debian 9 repo and then installing the monodevelop.com repo. (Which could go offline at anytime....) Their SDK simply isn't maintained and it generates errors when attempting to link ASP.NET, MySql.Data, System.Data.SQLite, on a netstandard2.0 target.

Really long winded explanation: We need the netstandard2.0 target to get a valid SQLite.Interop.dll for Linux / OSX. MonoDevelop however doesn't properly detect the correct target. It defaults to net40 in this case, and the target selection in the project configuration GUI is broken / unusable. It will then error out when trying link MySql.Data because it has an assembly reference for netstandard when trying to link against net40. Which lacks a netstandard facade. MonoDevelop's MSBuild won't include one until net471 minimum. But there's no way to get MonoDevelop to use a working version of netFramework when it defaults to net40. To get MonoDevelop to complete the build regardless, we need to create a new project that targets netstandard2.0, has a package reference for System.Data.SQLite, and that has no other project dependencies on it. Then we can have MSBuild pull the SQLite.Interop.dll from the new project into the projects that need the dll. Which is what my hack commit does in my fork, and why I wanted to run it by people before issuing a pull request.

2) Microsoft's new dotnet SDK cannot compile the ASP.NET projects at all under Linux / OSX. The needed SDKs just are not present nor installable. This is because Microsoft deprecated ASP.NET in favor of ASP.NET Core. Unfortunately, getting the ASP.NET projects building under ASP.NET Core requires some work. In short, although we can easily retarget the other standalone projects to netstandard2.0, (I already did, although I did not commit it for obvious reasons, doing so allowed the dotnet SDK to build about 90% of the project without any code modifications at all. It even got the correct SQLite nuget package without any code changes / hackery!) the last 10% will require some additional work which I am not familiar with, and I did not want to force on the project without asking for permission first.

What works

With the patches in my fork, the Linux / Apache / Mono build is on par with the Windows / Visual Studio build. GTS -> works Battle Video -> works Database -> works web -> works Proxying /pokemondpds/ and /syachi2ds/ gamestats2 urls without completely disabling the AltWFC gamestats2 implementation -> works. (You need to use ProxyPass / ProxyPassReverse in apache's gamestats2 virtual host.) For example:

<VirtualHost>
        ServerAdmin webmaster@localhost
        ServerName gamestats2.gs.nintendowifi.net
        ServerAlias gamestats2.gs.nintendowifi.net, gamestats2.gs.nintendowifi.net

        <IfModule mod_mono.c>
                MonoAutoApplication disabled
        </IfModule>

        ProxyPreserveHost On

        ProxyPass /pokemondpds/ http://pkgdsprod.nintendo.co.jp:8080/pokemondpds/
        ProxyPassReverse /pokemondpds/ http://pkgdsprod.nintendo.co.jp:8080/pokemondpds/
        ProxyPass /syachi2ds/ http://pkgdsprod.nintendo.co.jp:8080/syachi2ds/
        ProxyPassReverse /syachi2ds/ http://pkgdsprod.nintendo.co.jp:8080/syachi2ds/

        ProxyPass / http://127.0.0.1:9002/
        ProxyPassReverse / http://127.0.0.1:9002/
</VirtualHost>
<VirtualHost *:8080>
    ServerAdmin webmaster@localhost
    ServerName pkgdsprod.nintendo.co.jp
    ServerAlias "pkgdsprod.nintendo.co.jp, pkgdsprod.nintendo.co.jp"
    ServerAlias "pkvldtprod.nintendo.co.jp, pkvldtprod.nintendo.co.jp"
    ServerAlias "ds.pokemon-gl.com, ds.pokemon-gl.com"
    ServerAlias "de-ds.pokemon-gl.com, de-ds.pokemon-gl.com"
    ServerAlias "en-ds.pokemon-gl.com, en-ds.pokemon-gl.com"
    ServerAlias "es-ds.pokemon-gl.com, es-ds.pokemon-gl.com"
    ServerAlias "fr-ds.pokemon-gl.com, fr-ds.pokemon-gl.com"
    ServerAlias "it-ds.pokemon-gl.com, it-ds.pokemon-gl.com"
    ServerAlias "ko-ds.pokemon-gl.com, ko-ds.pokemon-gl.com"

    DocumentRoot /var/www/pkmn-classic-framework
    MonoAutoApplication disabled
    MonoServerPath "/usr/bin/mod-mono-server4"
    MonoApplications default "/:/var/www/pkmn-classic-framework"
    <Location />
        SetHandler mono
        MonoSetServerAlias default
    </Location>
</VirtualHost>

Doing it that way allows other non-pokemon games to work if Mono breaks. Or if some bug in GamestatsBase breaks some other game / feature.

Questions

1) Are these changes OK for a pull request? 2) Should I look into converting the ASP.NET projects to ASP.NET Core? 3) Suggestions? Comments?