Running your own server: Difference between revisions

From Open RSC
Jump to navigation Jump to search
No edit summary
No edit summary
Line 134: Line 134:
[[File:Server configuration.png|frameless|Server configuration]]
[[File:Server configuration.png|frameless|Server configuration]]


[[File:Client configuration.png|frameless]Client configuration]
[[File:Client configuration.png|frameless|Client configuration]]
---------------------------------------------
---------------------------------------------


Need more help? Contact developers on Discord in #sp-diy-support https://discord.gg/vasyjJT
Need more help? Contact developers on Discord in #sp-diy-support https://discord.gg/vasyjJT

Revision as of 00:25, 15 March 2020

Known Gotchas:

- MySQL 5.7 and below (released 2015) lacks the ability to use if exists within SQL queries. Version 8, released in 2018, contains this and works fine. Same with MariaDB. If you do not use current versions of MySQL or MariaDB, importing the game server SQL database will result in an error.

- The server must be running when the client is launched as the client needs to download the config from the server to configure what features it should use. Right now it does not retry if it cannot immediately connect to the game server and will crash if one is not available.

- New installs with Docker require this set, otherwise Ubuntu's UFW can't block Docker MariaDB containers from external communication and thus bruteforce attempts: https://www.techrepublic.com/article/how-to-fix-the-docker-and-ufw-security-flaw/

       sudo nano /etc/default/docker
       DOCKER_OPTS="--iptables=false"



Obtaining a website HTTPS SSL certificate: You can buy a year of PositiveSSL HTTPS certificates for $22. Previously there was a way to use LetsEncrypt but it became a hassle with too many failure lockouts that lasted a week and wasn't reliable for production use. See: https://www.namecheap.com/security/ssl-certificates/comodo/positivessl-multi-domain/


Apache Ant is used to compile the Java files.


To set a user as an administrator, update the openrsc_players table entry for the desired player and set group_id = 0. To return them to a regular player, set them to group_id = 10.


The game client reads the contents of Cache/ip.txt and Cache/port.txt to determine what game server to connect to and fetch the configuration from.


The PC launcher always replaces the contents of the Cache folder with the official website versions that it is configured to connect to if they do not match. The PC Launcher module relies on multiple things, such as checking a file on GitLab for the launcher version, Cache folder and md5 generated text files within in the website downloads folder that a shell script is used under Deployment_Scripts to write, and will overwrite the contents of the locally downloaded Cache/ip.txt and Cache/port.txt at every launch when it checks for a md5 comparison and downloads. A better design would to not fetch the ip.txt and port.txt at all, exclude them from the md5 check, and generate them if they do not exist on PC Launcher button press instead.


To run a single game server, simply copy a desired premade server/*.conf file, edit as desired, then rename it as local.conf. If local.conf exists, that file will always override default.conf. No edits to build.xml are needed for normal operation.


It is possible to execute multiple game servers within the same system process by editing server/build.xml

       <target name="runserver">
       <java classname="com.openrsc.server.Server" fork="true">
           <arg value="default.conf"/>

with

       <target name="runserver">
       <java classname="com.openrsc.server.Server" fork="true">
           <arg value="openrsc.conf"/>
           <arg value="rsccabbage.conf"/>

For some reason, ordering rsccabbage.conf before openrsc.conf results in errors from experience. Note: delete local.conf before trying to use multiple presets at once or it will conflict.


Setting the stage of a quest ID in the database to -1 will mark it as complete for the player.


Editing the database for a logged in player will result in it not saving as when they log out, it will be overwritten.


There are several config parameters to be aware of in the framework:

Prevents login to server unless client Config has

       public static final int CLIENT_VERSION = 4;

matching

       <entry key = "client_version">4</entry>

Client has this but it may not affect anything since client doesn't download cache updates inside it anymore

       private static final int CACHE_VERSION = 4;

Only on android does this matter but I like both android and pc client Config to be near-identical

       public static final int ANDROID_CLIENT_VERSION = 45;

web server /downloads/android_version.txt

       45

android client version triggers prompt to download and install updated APK

Launcher Constants determines if the launcher jar should be entirely re-downloaded

       public static final Double VERSION_NUMBER = 20190713.203000;



Production crontab:

       0 */1 * * * make -C /opt/Game backup db=openrsc
       0 */1 * * * make -C /opt/Game backup db=cabbage
       0 */3 * * * make -C /opt/Game backup db=wiki
       0 23 * * * make -C /opt/Game clear-backups days=365
       1 */1 * * * cp -Rf /opt/Game/server/avatars /opt/Website && chmod -R 777 /opt/Website/avatars/
       */30 * * * * python3 /opt/cloudflare-ddns/cloudflare-ddns.py -z openrsc.com -z >
       @reboot make -C /opt/Website restart
       @reboot make -C /opt/Game restart-db
       @reboot make -C /opt/Game restart-game

GitLab crontab:

       0 3 * * * gitlab-rake gitlab:backup:create CRON=1



Cloudflare DDNS python script configuration: https://github.com/adrienbrignon/cloudflare-ddns

       sudo nano /opt/cloudflare-ddns/zones/openrsc.com.yml
       %YAML 1.1
       # Cloudflare DDNS example configuration
       ---
       # Your Cloudflare email address
       cf_email: '[email protected]'
       # Your Cloudflare API key
       # https://support.cloudflare.com/hc/en-us/articles/200167836-Where-do-I-find-my-Cloudflare-API-key
       cf_api_key: REMOVED
       # Cloudflare zone name
       # If you're updating 'ddns.example.com' set this to 'example.com'
       cf_zone: openrsc.com
       # List of records
       # If you're updating 'example.com' record, set its name to '@'.
       # Only write the subdomain ('ddns' for 'ddns.example.com')
       cf_records:
           - '@':
               type: A
               proxied: true
               log: ERROR
           - '@':
               type: AAAA
               proxid: true
               log: ERROR
       # This is the method used to discover the server's IP address
       cf_resolving_method: 'http'



Building and running in a dev environment:

An IntelliJ IDEA project has been included in the Game repository folder for the server, client, and launcher. Similarly, an Android Studio project has been included for the Android client.

One option for compiling and running the server and client is to use the Apache Ant build.xml files under each folder directory. Alternatively, more quick options can be set up in the IntelliJ IDEA as shown below.

Run/Debug configurations

Server configuration

Client configuration


Need more help? Contact developers on Discord in #sp-diy-support https://discord.gg/vasyjJT