Difference between revisions of "Server"

From King Arthur's Gold Wiki
Jump to: navigation, search
(Linux)
(Linux)
Line 58: Line 58:
 
# First, download the server: <br /> <pre>wget http://dl.kag2d.com/kag-linux32-dedicated-latest.tar.gz</pre>
 
# First, download the server: <br /> <pre>wget http://dl.kag2d.com/kag-linux32-dedicated-latest.tar.gz</pre>
 
# Next, decompress the archive. <br /> <pre>tar -zxf kag-linux32-dedicated-latest.tar.gz</pre>
 
# Next, decompress the archive. <br /> <pre>tar -zxf kag-linux32-dedicated-latest.tar.gz</pre>
# Change to the new directory: <br /> <pre>cd kag_linux</pre>
+
# Change to the new directory: <br /> <pre>cd kag-linux32-dedicated</pre>
 
# [[Server#Configuration|Configure]] your server.
 
# [[Server#Configuration|Configure]] your server.
 
# Run your server: <br /> <pre>./KAGdedi</pre><br />To connect, either find it in the server list or connect directly using the IPaddress:PortNumber format. (The default port is 50301.) Note that domain names will not work in place of the IP address.
 
# Run your server: <br /> <pre>./KAGdedi</pre><br />To connect, either find it in the server list or connect directly using the IPaddress:PortNumber format. (The default port is 50301.) Note that domain names will not work in place of the IP address.

Revision as of 16:11, 22 August 2012

This page might not be up-to-date (build 458).

The King Arthur's Gold Server is a relatively lightweight, 32-bit command line application. Freely distributed, this program allows anybody with an internet connection and a computer to host their own King Arthur's Gold server.

Note: There is very little official documentation for the KAG server. As a result, the majority of this document was created from observation, trial and error. Use at your own risk.

Features

  • All servers are added to the official server list to be seen by anybody who chooses the "Pick a Server" option in-game.
  • Servers can be remotely controlled in game by anybody with the server's Remote Control (RCON) password.
  • Servers can be password protected. (This is separate from the RCON password.)

Requirements

Hardware

The hardware requirements for a KAG server are minimal. If a computer can run the full KAG game, it can run the KAG server.

Software

The KAG server can run on Linux, Windows, or Mac. The recommended operating system is Linux, specifically Debian.

Network

The KAG server isn't designed to work on computers without an Internet connection. It is, however, still possible to run it without one.

The KAG server uses four ports:

Description Modifiable? Firewall Tolerant?
50301/udp Used to listen for connections. yes no
50328/udp Used to communicate with clients. yes yes
80/tcp Used for autoupdates no yes
443/tcp Used for API (server list, auth, minimaps, etc) server communication no yes
Firewall tolerant means that a typical connection-oriented (SPI) firewall will allow that port through. Depending on the firewall, all ports may need to be forwarded in UDP.

The internet connection is typically the bottleneck that determines the number of users a server can support. Hosting more users than a connection can support will cause a high ping time and significant lag.

Hosting on Residential Connections

For those hosting on residential internet connections, keep in mind that many ISPs forbid running any kind of server, including a KAG server. To complicate hosting a server, they may block certain ports and dynamically assign IP addresses.

  • It is highly unlikely that they would block the ports used by the KAG server. (A local router's firewall is most likely the culprit for connectivity issues when hosting on a residential connection.)
  • This site displays the IP address of the current visitor. It can be used to determine the currently assigned public IP address.

Installation

Linux

This guide is written for 32-bit Debian Linux. To run on 64-bit Debian Linux, the ia32-libs package must be installed.

  1. First, download the server:
    wget http://dl.kag2d.com/kag-linux32-dedicated-latest.tar.gz
  2. Next, decompress the archive.
    tar -zxf kag-linux32-dedicated-latest.tar.gz
  3. Change to the new directory:
    cd kag-linux32-dedicated
  4. Configure your server.
  5. Run your server:
    ./KAGdedi

    To connect, either find it in the server list or connect directly using the IPaddress:PortNumber format. (The default port is 50301.) Note that domain names will not work in place of the IP address.

Windows

  1. First, download the server: http://kag2d.com/en/download
    Note: The downloads page only lists a linux server. Even though the server is intended to run on Linux, it will run on Windows.
  2. Next, decompress the archive. This can be done with many different programs, including PeaZip.
  3. Open the folder the archive was extracted into.
  4. Configure your server.
  5. Run your server by clicking dedicatedserver.bat.
    To connect, either find it in the server list or connect directly using the IPaddress:PortNumber format. (The default port is 50301.) Domain names will not work in place of the IP address.

Mac

Due to their similarities, the installation instructions for Linux should apply for Macs, though Mac does not currently have a dedicated server option.


If that doesn't work try this:

What you will need:

1. Portmap: http://www.macupdate.com/app/mac/27342/port-map/

2. Trelawney's Dedicated OSX Server: http://dl.dropbox.com/u/23114384/kag/osx_dedicated.zip

3. You will not need the Linux dedicated server

Part 1:

1. Make sure that KAG is in your applications folder. This should be default for most users

2. Make a copy of KAG by right clicking it and selecting "Duplicate"

3. Right click on the original KAG and select "Show Package Contents"

4. Follow the folders to the "Scripts" folder via Contents>MacOS>Base>Scripts

5. Open the "Scripts" folder and right click on the "dedicated_autoconfig.gm" file and open with textedit

6. Configure your server be sure not to miss the "sv_name" and "sv_info". Make sure the "sv_ip" is set to 0

7. Make sure the "sv_port" is equal to 50302. The default 50301 did not work for me

8. Save this file

Part 2:

1. Unzip Portmap and launch it

2. Open the following ports on both UDP and TCP:

i. 443

ii. 80

iii. 50301

iv. 50302

v. 50328

vi. 25565


All of these ports probably aren't necessary but it worked for me so that's what I'm suggesting. All the ports should have a green light. If they are yellow or red PM me or post in this thread and I might be able to help.

Part 3:

1. Unzip osx_dedicated and launch it

2. You should come to a point where it says "Make sure to edit dedicated_autoconfig.gm" and a copy of KAG launches. This is not an error or a freeze! This confused me a lot but this is what is supposed to happen.

3. Go back to your Applications folder and launch the Kag Copy not the original. You should see your server in the browser.

Configuration

The KAG server is configured using text files. Customizing a KAG server installation involves modifying the variables in these files. There are two ways to do this: manually and using Maqq's Configuration Tool. Of the two, Maqq's Tool is by far the fastest and easiest method.

One of the most important decisions a server administrator must make is whether or not to allow the Royal Guard to police their server. Please read the opening posts in these threads (In-game moderators (AKA Royal Guard) & The Royal Guard - FAQ & Public Policy) so you can make an informed decision.

If you decide you don't want guards to moderate on your server, please ensure they are turned off in your dedicated_autoconfig.gm file like this:

global sv_allow_globals_mods = 0;

Manual Configuration

Of the many editable configuration files that the KAG server depends upon, most customization is done in the dedicated_autoconfig.gm, dedicated_autostart.gm, mapcycle.cfg, and *-generator.cfg files. These are all in the kagServer/Base/Scripts directory, where kagServer is the directory the server was extracted into.

dedicated_autoconfig.gm

Of the many modifiable variables, these are some of the most important:

global m_width = 600; // Map generator width. Affects RAM usage.
global m_height = 250; // Map generator height. Affects RAM usage.
global m_seed = 0; // Map generator seed. Pick a random number.
global g_kickvote_percent = 33; // Percentage of players needed for a kick vote to pass.
global g_mapvote_percent = 51; // Percentage of team players needed for a map vote to pass.
global g_vote_time = 60; // How long (in seconds) does the voting take place.
global g_kickvote_bantime = 30; // How long (in minutes) is the player banned after a kick vote.
global sv_maxplayers = 16; // Maximum number of players allowed ingame.
global sv_port = 50301; // Server communication port, this is where it listens for incoming clients. Remember to open this port in your firewall.
global sv_password = ``; // Sets the server password.
global sv_rconpassword = ``; // Sets the server remote console password. This is important if you want to have control over your server.
global sv_require_auth = 1; // If set to 1 server checks client authentication via master server.
global sv_gold_only = 0; // If set to 1 only premium account players can join (aka Gold Server).
global sv_allow_globals_mods = 1; // If set to 1 global KAG moderators and admins can kick/ban players on server.
global sv_deltapos_modifier = 1; // Controls the threshold for delta packet updating. Value higher than 1 will reduce bandwidth, lower increase.
global sv_maxping = 450; // Max ping allowed on server after which player is kicked. Large ping players will slow down server.
global sv_maxping_warnings = 200; // Because of ping spikes, warnings are issued if a player has ping over max number.
global sv_maxhack_warnings = 25; // Maximum amount of warnings where server thinks player is hacking.
global sv_alloweditor = 1; // If set to 1 players that have RCON can start map editor on server
global sv_name = `KAG game`; // Sets the server name displayed in server browser.
global sv_info = ``; // Sets the server info displayed in server browser. If you want it multi-line simply move text to new line with enter.

dedicated_autostart.gm

// autostart on dedicated server launch


//set autostartswitch to:
//	0 for CTF 
//	1 for TDM
//	2 for Sandbox
//	3 for Zombies
//	4 for RTDM
//  10 for TEST

global autostartswitch = 0;

newWorld( "" );
switchGameState(0);

startServer();	

if (autostartswitch == 0) //ctf
{
	LoadRules("Rules/CTF/gamemode.cfg");
	LoadMapCycle( "Scripts/mapcycle.cfg" );
	LoadMap( "" );
	print(`Loaded CTF default config`);
}
else if (autostartswitch == 1) //tdm
{
	LoadRules("Rules/TDM/gamemode.cfg");
	LoadMapCycle( "Scripts/mapcycle.cfg" );
	LoadMap( "" );
	print(`Loaded TDM default config`);
}
else if (autostartswitch == 2) //sandbox
{
	LoadRules("Rules/Sandbox/gamemode.cfg");
	LoadMapCycle( "Scripts/mapcycle.cfg" );
	LoadMap( "" );
	print(`Loaded TDM default config`);
}
else if (autostartswitch == 3) //zombies (GOLD ONLY)
{
	LoadRules("Rules/Zombie_Survival/gamemode.cfg");
	LoadMapCycle( "Rules/Zombie_Survival/ZombieMapCycle.cfg" );
	LoadMap( "" );
	
	print(`Loaded zombies default config : server now in GOLD MODE`);
} else if (autostartswitch == 4) //rtdm
{
	LoadRules("Rules/RTDM/gamemode.cfg");
	LoadMapCycle( "Rules/RTDM/RTDMMapCycle.cfg" );
	LoadMap( "" );
	print(`Loaded RTDM default config`);
}else
if (autostartswitch == 10) //test
{
	LoadRules("Rules/TEST/gamemode.cfg");
	LoadMapCycle( "Scripts/mapcycle.cfg" );
	LoadMap( "" );
	print(`Loaded TEST default config`);
}

print(`Config finished loading from Scripts/Server/dedicated_autostart.gm`);

This file is very important. If you want to change rules for your server then you have to edit the global autostartswitch variable.

For an individual Rule there is the the number 10. If you want to make a Zombie Survival Server or any modded Server you need to make your server for Gold users only ( see dedicated_autoconfig.gm)

mapcycle.cfg

#KAG mapcycle;
# put map generator files, png files here, or script files
# eg. mapcycle = Maps/example1.png; Maps/example2.png; Maps/generator_flat.cfg; Maps/swordfight.gm;

mapcycle = Maps/generator_ctf_mountain.cfg;
You must separate paths to files with semicolons. Allowed files are generators, script files and maps in png format.

*-generator.cfg

Generators use "libnoise"-library.

Maqq's Server Configuration Tool

Maqq's command-line interface server configuration tool provides an interactive way of setting up a server:

Download in the root KAG directory (C:\KAG or /kag_linux , in windows and linux respectively).

  • In Windows, run KAGServer.exe and follow the onscreen instructions.
  • In linux, make it executable via chmod +x sconfig.py and run with ./sconfig.py . Daemonisation tools applicable to dedicatedserver.sh (screen, tmux, nohup etc) still useable with this program

Reusing Generated Configs

These commands reuse the generated configuration files:[1]

  • If you're using linux, type this in the console:
./KAGdedi autostart Scripts/custom_autostart.gm autoconfig Scripts/custom_autoconfig.gm
  • If you're using windows, you should consider using the [GUI version], it lets you save the configuration into a file, but if you want to use the CLI version, type this in the command prompt:
KAG autostart Scripts/custom_autostart.gm autoconfig Scripts/custom_autoconfig.gm

Download Maqq's Server Config Tool

Remote Control

A server can be controlled in-game. While connected to the server, press the HOME key to open the console. Typing "/rcon /login password", where password is the RCON password set by sv_rconpassword, will allow the current user to send commands to the server. These commands must be prefixed by "/rcon". For example, to use the /list command, type. "/rcon /list".

A full list of available rcon commands can be found here.

Security Levels

King Arthur's Gold uses a system called 'Security Levels' (or 'seclevs' for short) to manage player access to various features on its servers. There are default, hardcoded levels setup but it is strongly advised that server owners take the time to setup their own specific seclev definitions.


Read more...

Blacklisting & Whitelisting

A player blacklists is the list of players who are not allowed to play on a given server. A whitelist is the inverse of a blacklist; if enabled, only those on the whitelist will be allowed to play.

How to Create a Blacklist or Whitelist

The contents of the file securitysetup.cfg in kagServer/Base/Security (where kagServer is the path to the kagServer's directory) should look something like this:

# Security setup

# Set to 1 to allow only the names in the whitelist or 0 to disallow the names in the blacklist
whitelist_active = 0
whitelist_file = Security/whitelist.cfg
blacklist_file = Security/blacklist.cfg

# Path to file where security levels are defined
seclevs_file = Security/seclevs.cfg

Note: The whitelist overrides the blacklist if enabled.

Whitelist

If you are using the whitelist, then at the path specified in whitelist_file you can create a file that looks something like this:

# Whitelist format: name; anothername; yetanothername;
whitelist =
name;
anothername;
yetanothername;

Simply add usernames in this way to allow only those players access to the server.

Blacklist

If you are using the blacklist, then at the path specified in blacklist_file you can create a file that looks something like this:

# Blacklist format: name; IP; expiration time and date h:m:s:d:M:y; reason;
# IP of 0.0.0.0 means no IP is banned, and the user is just banned by username.
# Blank username means no user is banned for that entry and it's just by IP.
# The time is in C++ struct tm format except for the year, which is human readable. Get relative times from /listbans on the console. 
# 	eg: 10:30:0:31:11:2050 is 10:30 AM on the 31st of December 2050AD

blacklist =
name1; 0.0.0.0; 10:30:0:31:11:2050; Banned;
name2; 12.34.45.78; 10:30:0:31:11:2050; Banned;

Simply add player details in the format described to ban them from the server. Alternatively, just use the ban menus or rcon commands in game to ban users. Note that January is the 0th month

Managing Instability

As Alpha software frequently is, the KAG server is very unstable. Recent builds have been especially prone to crashing whenever left running for more than 24 hours (build 360+ has been much more stable, but it varies from release to release due to new features mixed with bug fixes). As such, it is recommended practice run the server in a keepalive script, which will restart it whenever it crashes. (In addition, many people restart their server once a day, during the hours of least usage, to help decrease the risk of a crash while the server is being played upon.)

Trelawney's Keepalive Script for Linux

This script, dedi.sh, will restart the KAG server 5 seconds after it crashes. Download it here.
If retyping/using copy and paste, make sure word wrapping is turned off in you text editor. (In nano, use nano -w dedi.sh .)
Once created, be sure to make the script executable with chmod +x dedi.sh.

#!/bin/bash
echo "Running KAG dedicated server"
echo "TO SET IP/PORT/SLOTS/PASSWORD ADD THESE COMMAND PARAMS: ip 127.0.0.1 port 50213 slots 32 password pass123"
mv KAGdedi.tmp KAGdedi
chmod +x KAGdedi
until ./KAGdedi nolauncher autostart Scripts/dedicated_autostart.gm autoconfig Scripts/dedicated_autoconfig.gm; do
        echo "KAG server running"
        sleep 5
done

To use, run the script: ./dedi.sh

Adapting for Maqq's Configuration Tool

To use a configuration generated by Maqq's Configuration Tool, replace line 6 in the above script with:

./KAGdedi autostart Scripts/custom_autostart.gm autoconfig Scripts/custom_autoconfig.gm

The Beaz's Keepalive Script for Windows

This script, dedi.bat, will restart the KAG server 5 seconds after it crashes. To use, create a text file, paste/type in the script below, and save it as dedi.bat.

@ECHO off
 
:restart
echo (%time%) Server Started - close this window to prevent restart.
 
start /wait KAG.exe nolauncher autostart Scripts/dedicated_autostart.gm autoconfig Scripts/dedicated_autoconfig.gm
 
echo (%time%) WARNING: Server closed or crashed, restarting.
 
goto restart

Adapting for Maqq's Configuration Tool

To use a configuration generated by Maqq's Configuration Tool, replace line 6 in the above script with:

start /wait KAG.exe nolauncher autostart Scripts/custom_autostart.gm autoconfig Scripts/custom_autoconfig.gm

Daily Server Restarts

If a KAG server is running in a keepalive script, a scheduled task/cronjob that kills the server once a day is, effectively, a daily restart because the keepalive script will automatically restart the server.

For Linux - Cronjob

This script will kill all instances of KAGdedi at 3 AM.

  1. Use crontab -e to create a new cronjob. This will open your default text editor.
  2. In the text editor, type:
    0 3 * * * pkill -1 KAGdedi
  3. Close editor. Cronjob installed!

Checking for Updates

So far there is not a public script to restart a server when an update is available, but the following logic should be able to be combined with a restart script above to restart a server once an update is available.

nova-dhcp-host111:~ ryan$ curl -s http://update.kag2d.com/kag_linux/App/version.txt | head -n1 | cut -d ' ' -f2
1337154874-636-6e12e0f833b0
nova-dhcp-host111:~ ryan$

When that string (the 2nd whitespace-delimited element of the first line of that URL) changes, an update is available. The first number is the unix timestamp of the build, the 2nd is the code revision, the 3rd is a hex identifier used internally by the developers. You should be able to just monitor for a change. You could also use logic involving watching the first two parts of the string to see if they increment, but the format of this string may change in the future -- tl;dr: it is best to just watch if the string changes, don't try to parse it.