Original source by WilliamDraco.
This document provides instructions to setup nwsync from the beginning, including an http server. This is aimed at a windows user who needs only basic features, but most instructions are platform agnostic.
Disclaimer: I am not affiliated with Beamdog and have written these instructions based on my own experiences. While I have tried to cover a few corner cases where I can, it’s not even the same field as my day job so problems may still occur.
1. Set up a http server
The best http server method is to pay a service for proper webhosting. The service needs to provide public-facing http access to download files. Clients make many connections/requests during transfer, and so services which charge per-connection/per-http request should be avoided. If you have such an option, skip to step 2.
This is the setup of a no-cost option for nwserver hosts to create a ‘self-serve’ nwsync host. This self-serve option is restricted by the nwsync host’s upload speeds or limits, and will be subject to any ISP restrictions that the nwsync host has i.e. many residential service contracts ban file hosting. Note that the nwserver host and the nwsync host do not need to be the same computer/network/continent.
http vs https - As of v1.79 (8193.0), both are supported. The below establishes an http-only server which is sufficient in practice for nwsync. Should https become a requirement this guide will be extended to enable https.
Enable port forwarding of inbound traffic over port 80 towards the nwsync host. This is an option on most internet routers, but each router software is different. If you don’t know how to port forward for your particular brand/model, google search something like Port Forwarding *router name*
Nginx is a popular, trusted webserver and the setup is very easy for the most basic of servers that we need.
- Download the appropriate version, extract it directly to an application directory. There is no install process for Nginx.
- Open this directory and find nginx.exe. In that same directory Right-Click-> New -> Text Document. Name it "nginx.txt". Open the text file and put the following:
- Save and close the file. Then, rename the file nginx.bat. Windows will warn you about changing extensions - accept it.
- You should now have both nginx.exe and nginx.bat next to each other.
- Run nginx.bat from inside that directory. A cmd window will open.
- Open your web browser of choice and type the host's public IP address into the search bar. For example, http://188.8.131.52 (this is the IP of Google Search). You can find the public IP by navigating to https://www.whatismyip.com/ from the host computer.
- If this presents the "Welcome to nginx" page, Everything is working thus-far. If not check the following:
- Confirm your port-forwarding options and check any firewalls which might be blocking connections.
- It’s also wise to test using an ‘outside' connection - Either get a friend to attempt it from home or use a mobile phone on data (not Wi-Fi).
- In the cmd window opened at step 2, type nginx -s quit . This will gracefully shut down nginx.
- There is no feedback that Nginx is closed. On windows use the following command in the same cmd window - it should show ‘no matching tasks’ if the shutdown was successful
tasklist /fi "imagename eq nginx.exe”
While I do not have personal experience with Linux, here is a simple installation steps I’ve found to install nginx (based on ubuntu):
- Installation is as simple as:
sudo apt update
sudo apt install nginx
- To start nginx:
sudo systemctl start nginx
- To stop nginx:
sudo systemctl stop nginx
- Testing the current operations is the same as steps 3-4 for windows above.
Note this installs the nginx as a service, which should start automatically at boot. This behavior can be controlled using the systemctl keywords “enable” and “disable”. You can always check the current status using:
sudo systemctl status nginx
Nginx has a large feature set as a webserver, but most of those options are unnecessary for this simple purpose and can be ignored.
2. Preparing nwsync
- Download nwsync https://github.com/Beamdog/nwsync/releases . Extract and place all components into a folder (Note: the latest version, v0.3.2, does not include a required .dll file which will give an unrecognisable error later. The newer .exe is preferable, but please also download and extract the .dll files from an earlier version, and place them inside this same folder)
- While not a strict nwsync requirement, for basic use nwsync should be installed on a computer that can run the nwn module via nwserver (even if not the one that does run the module), because it will auto-locate the needed hak/tlk files the same way that nwserver does. This will look something like:
- Module in documents/nwn/module
- Haks in documents/nwn/hak
- Tlk in documents/nwn/tlk
- Many people find that nwsync takes exceptionally long (days) when prepared on low-resource hardware (such as a low-power laptop or a small Virtual Machine). My guess is related to limited RAM, or slow hard drives choking the process. Suggest you prepare nwsync on a well-provisioned computer (and then transfer/move the prepared data to your hosting solution, as applicable)
- Download my unofficial gui wrapper https://github.com/WilliamDraco/nwsync_gui/releases . This prepares and runs the command line options for nwsync for you. Place the nwsync_gui.exe into the same directory as nwsync (or it can find nwsync via PATH, if you know what that is)
- If you are familiar/comfortable with the nwsync command lines, skip the gui and run the commands directly. Then, proceed to step 3. Running nwserver
- Run nwsync_gui.exe
- Choose a Source - Select your modulename.mod file
- All sorts of package files (mod, erf, hak) can be nwsync’d to meet different needs, but for the basic case just select mod.
- If you want to include Portraits, Music or Ambient Sounds in your nwsync, pack them within a hak file and include it in the module - This is due to a limitation in nwsync_gui that is planned to be resolved in the future.
- Choose a Destination folder
- If you complete the ‘Set up a http server’ step above you should select the 'html' folder inside the nginx directory and then create a subfolder such as 'nwsyncdata'. The remainder of the walkthrough will assume you did this.
- If you are using a paid/hosted http solution, this is a temporary destination until you can upload to your host. How you upload to your host will depend on the host itself.
- Click the large "RUN NWSYNC WRITE" button and wait for it to finish. This can take a while - Let it run.
3. Running nwserver to serve nwsync content
Nwserver command-line option
On windows, the user interface for nwserver does not have an option to enable nwsync. Therefore, nwserver must be launched with command-line options to use nwsync. Linux has only ever had the console/terminal option.
See http://neverwinternights.info/dedicatedserver.htm for information on the Command-Line options, and how to use them on windows if unfamiliar.
nwsync adds a new command-line option in addition to the above:
- Self-hosted: This is the public IP address that you got during the 'set up a http server' step 3
- Paid-hosting: The address you use to access your webhost content by browser, which is likely via a domain name like ‘www.paidhosting.com’
- The name of the subfolder set-up during the 'Preparing nwsync' step 5. If you did not create a subfolder, simply exclude /subfolder
- Following the examples above the complete command would be
- Always ensure the webhost (nginx) is running/available prior to starting nwserver.
- Run nwserver including the new command-line option per the above.
Note that, per the nwsync instructions, at present nwserver continues to use content files (hak/tlk/etc) the same way as it used to. Therefore your server must still have access to a copy of those files in order to run correctly. Nwserver cannot read nwsync data - it merely tells the client where they can find the data for themselves.
4.What if I have a dynamic IP (Self-hosting)?
If you’ve chosen to self-host and the nwsync-host has a connection which uses a dynamic IP, the -nwsyncurl command would have to change frequently in order to match the IP as it moved around. This is a tedious process to follow. While a static IP would be preferable, a dynamic IP can be mitigated using a DNS service.
Any dns service is fine, and if you want to purchase your own domain name and manage the DNS to resolve to your dynamic IP you are welcome to do so, however a free option for this walkthrough is to use www.duckdns.org:
- Follow the above link and register using any of the available options.
- Once logged-in, under the 'Domains' header you'll see an option to create a domain with a custom name. Enter your choice of name (Players don’t need to know it/remember it, so it is okay to be complicated, difficult to read or long) and click the green "add domain" button. e.g. http://modulename.duckdns.org
- Your domain will appear in the list and should autofill with your current IP address if available. Now, instead of using your public IP in the -nwsyncurl, instead use this domain name. Example:
- Back on the duckdns website, go to the ‘install’ header found near the top of the page.
- Follow the instructions provided to select your operating system and implement a script/program that will auto-update the duckdns entry every 5 minutes in order to adjust when the dynamic IP address changes. For beginners on windows, the 'Windows - GUI' option is recommended.
- Ensure the script/program is active/running prior to launching nwserver
5. Updating nwsync content
When the time comes to update the content being served to players, do the following:
- Update the custom content the same way as previously (Add/remove content from haks, or add/remove haks from module) and save.
- Run nwsync_gui.exe (it should remember your previous selections - if not, reselect source/destination)
- Click "RUN NWSYNC WRITE" button and wait - It will be significantly faster than the first time but may still take a while as it checks for differences and updates as required.
- Restart nwserver (noting that it does not have to be offline while the new nwsync data is being written written)
- Remember to update your nwserver .hak/.tlk files, as nwserver cannot currently read from nwsync.
Other nwsync functions
This nwsync sub-program operates on a repository (folder containing nwsync data) and checks the data for a number of simple errors, alongside deleting data no longer in use.
If you consider the nwsync repository like a filing cabinet - Each time you “write” the program:
- Considers the list of documents you gave it (the source)
- Checks the filing cabinet for whether each of the documents exists (Note a different ‘version’ of a document is considered a ‘different document’)
- If the document doesn’t exist, it adds it to the filing cabinet
- Once done, it uses the source list as an index of the cabinet, so it knows which draw/section of the filing cabinet a document is in.
Note that in the above analogy, at no point does nwsync remove any contents from the filing cabinet. But what happens if you remove a document from your source list? Will it stay in the cabinet forever?
Yes, the repository/filing cabinet will keep every copy of a file ever put into it - Unless you prune it. Pruning is simply the process whereby nwsync checks the contents of the cabinet against the current index (or indexes, as you can have multiple manifests in one repository) of the cabinet. Where a document is no longer on any index, that document gets thrown away.
This is primarily useful to remove the wasted storage space for unused documents. Note: It may provide a minimal speed increase, but should not be considered “the point”.
Lastly, this nwsync sub-program outputs the checksum reference and filename of each document within a specific manifest (not repository). To stick with the above analogy - This prints out the index file in a human-readable format.
I’m… not quite sure what the use case is for this but there you go.