Shoddy Battle

Guide to building the server from source

If you are looking to run a Shoddy Battle server with the latest updates and bug fixes, then your best bet is to build the server yourself from the sources. This guide will walk you through the steps required to successfully running a server that the whole world can access. No knowledge of programming is required to build your own server, however some knowledge of Java is required if you want to customise anything. I will be using Windows 7 for this guide, but all of the programs are also available on Mac OS X and GNU/Linux.

Table of Contents

  1. Getting the latest sources
  2. Setting up the server properties
  3. Setting up a MySQL database
  4. Creating your first user
  5. Allowing other people to connect
  6. Running your server in the background
  7. Getting your server listed
  8. Troubleshooting

Getting the latest sources

To build and run the server, we're going to be using Netbeans. Netbeans is a free program that can be downloaded here. The only thing we need is Java SE, so you can download the smallest package.

Once you have Netbeans installed, open it up. To get the sources, go to the Versioning menu -> CVS -> Checkout. For CVS Root, put :pserver:anonymous@shoddybattle.cvs.sourceforge.net:/cvsroot/shoddybattle, and leave the password field blank. On the next screen, press the Browse button next to Module and expand the tree to find ShoddyBattle. Select Ok.

Image: CVS checkout window

Ignore the Branch field and select a place to save your project, then press Finish. After it has finished checking out, open the project. It should appear in the left hand side of the window. You can expand it to browse through the sources.

Image: Project window

Setting up the server properties

The first thing to do after you have checked out the sources is to edit the server properties. Click on the Files tab which is above the ShoddyBattle project, and expand ShoddyBattle so that you can open the server.properties file. After opening the file, change the server name, description, and capacity to your liking. For the unique name, head to this site and copy the randomly generated uuid. The port is something that you can choose. It should be greater than 1023, and less than 65535. For example, I will be using 30000. Keep your port number in mind for later. You can leave the rest of the file for now

Image: Server properties

Setting up a MySQL database

To keep track of user information, we are going to be using a MySQL database. You can download MySQL for your operating system here. The "essential" version will suffice. On Windows, you can choose Standard Configuration when going through the installer. You should make sure that Install As Windows Service, Launch the MySQL Server automatically, and Include Bin Directory are all checked. You can opt to set a root password here. If you do, make sure you remember it for later.

Once you have MySQL installed, you will need to run it. On Windows, a program called MySQL Command Line Client will be created that you can use to launch MySQL. On OS X or GNU/Linux, you can launch MySQL via a command line with a command such as

mysql -u root -p

assuming the mysql executable is located in your PATH. If you don't already have a database created, you will need to create one at the MySQL prompt with a command such as

CREATE DATABASE shoddybattle;

After you have created the database, enter

USE shoddybattle;

(use whatever you named your database in place of "shoddybattle"). Then, copy and paste the following commands:

CREATE TABLE `ban_history` (
  `user_name` varchar(255) NOT NULL,
  `mod_name` varchar(255) NOT NULL,
  `ban_time` datetime default NULL,
  `ban_action` varchar(255) default NULL,
  `ban_expiry` datetime default NULL,
  KEY `user_name` (`user_name`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

CREATE TABLE `ladder` (
  `player0` varchar(255) NOT NULL,
  `player1` varchar(255) NOT NULL,
  `victor` int(10) unsigned default NULL,
  KEY `player0` (`player0`),
  KEY `player1` (`player1`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

CREATE TABLE `ladder1` (
  `player0` varchar(255) NOT NULL,
  `player1` varchar(255) NOT NULL,
  `victor` int(10) unsigned default NULL,
  KEY `player1` (`player1`),
  KEY `player0` (`player0`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

CREATE TABLE `users` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `name` varchar(255) NOT NULL,
  `password` varchar(255) NOT NULL,
  `ip` varchar(255) default NULL,
  `level` int(10) unsigned default NULL,
  `unban` bigint(20) unsigned default NULL,
  `ban_level` int(10) default NULL,
  `created` datetime default NULL,
  `last_login` datetime default NULL,
  `rating` double default NULL,
  `deviation` double default NULL,
  `volatility` double default NULL,
  `estimate` double default NULL,
  `updated_rating` double default NULL,
  `updated_deviation` double default NULL,
  `updated_volatility` double default NULL,
  `rating1` double default NULL,
  `deviation1` double default NULL,
  `volatility1` double default NULL,
  `estimate1` double default NULL,
  `updated_rating1` double default NULL,
  `updated_deviation1` double default NULL,
  `updated_volatility1` double default NULL,
  PRIMARY KEY  (`id`),
  UNIQUE KEY `name` (`name`)
) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;

CREATE TABLE `users_inactive` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `name` varchar(255) NOT NULL default '',
  `password` varchar(255) NOT NULL,
  `ip` varchar(255) default NULL,
  `level` int(10) unsigned default NULL,
  `unban` bigint(20) unsigned default NULL,
  `ban_level` int(10) default NULL,
  `created` datetime default NULL,
  `last_login` datetime default NULL,
  `rating` double default NULL,
  `deviation` double default NULL,
  `volatility` double default NULL,
  `estimate` double default NULL,
  `rating1` double default NULL,
  `deviation1` double default NULL,
  `volatility1` double default NULL,
  `estimate1` double default NULL,

  PRIMARY KEY  (`id`),
  UNIQUE KEY `name` (`name`)
) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;

Image: MySQL console example

Now that you've done that, go back to server.properties and scroll to the bottom. Fill in database_user with your username for MySQL (probably root if you followed this guide). Put your password for database_password. If you never selected a password, the default root password is blank. For server_database, put the name of the database you created (in my case, shoddybattle)

Creating your first user

Now that you have your database set up, you are going to need to create your first account to be an administrator. Make sure that you have built your project by hitting the blue hammer icon in NetBeans (F11). Now, open up a command line and navigate to the folder where you have the sources. Then, run the following command at a command line:

java -cp dist/ShoddyBattle.jar shoddybattle.AccountEditor USERNAME PASSWORD 2

substituting USERNAME and PASSWORD for your desired username and password. If you get a message like 'java' is not recognized as an internal or external command, you will need to locate your java executable first. For example, C:\Program Files\Java\jdk1.x.x_xx\bin\java.exe. Once you have found this file, drag it to your command line and then enter the rest of the command.

Image: Adding an administrator account

If all has gone right, you should now be able to run your server. Press the large green arrow icon in Netbeans or hit F6 to run. You should see some output at the bottom of the window, hopefully without any errors. Now you can try to connect to your server. Open the Shoddy Battle client and go to the advanced window. Enter localhost for the host and whichever port you selected earlier for the port. Hopefully you are now connected to your server. You should be able to log in with the username you picked earlier.

Allowing other people to connect

You now have your server running and you can connect, but your friends are unable to join! To resolve this problem, you need to enable port forwarding. If you have a router or firewall software set up, it is blocking others from accessing your server. There are hundreds of different routers with different methods of enabling port forwarding, so your best bet is to check out portforward.com. This site contains guides for how to use port forwarding on many different routers.

Once you have figured it out for your router, you will need to forward the port that you chose earlier to the computer on your local network that the server will be running on. To find the address of your server computer, you can use the command "ipconfig /all" on Windows from the command prompt. On OS X or GNU/Linux you can use the command ifconfig. Your local address will usually begin with 192.168.x.x.

Image: Example of port forwarding using Tomato firmware

In addition, you may also have firewall settings that are blocking your server from connecting to others. If you have a firewall running, you will need to add port exceptions for the port you selected for both TCP and UDP. The process will vary depending on your firewall software. As an example, on Windows XP this is found under Security Centre -> Manage settings for Windows Firewall -> Exceptions -> Add port.

Running your server in the background

If you've been following along, you should now have a fully operational server. However, you don't want to have to boot up NetBeans and leave it running whenever you want to run your server. The easiest way to fix this is to download the default Shoddy Battle server package from here. Make sure that any previous version of the Shoddy Battle server package is uninstalled before preceding. After the installer is complete, navigate to the folder where you just installed the package.

You can delete all the files that are at the root level of this folder. Then, copy the version of server.properites that you have created to this folder. Next, from the source folder, copy the folders dist and server to the package folder. Your directory structure should now look like this:

Image: Folder structure

If you can't find the dist folder in your source folder, trying going into NetBeans and hit Build Main Project (F11). If you ever need to update the server source in the future, you simply need to replace the file ShoddyBattle.jar, which is located in the dist folder, with your newer version. Now that you have the new version in place, you can start your Shoddy Battle server. In Windows, you do this by using the Services program found in the Control Panel. Note that you must have administrative privileges to use Services. On OS X or GNU/Linux, can run shoddybattle start at the command line.

Image: Services window

Everything should now be running smoothly. If you are unable to connect to your server, check the wrapper.log file in the server package directory

Getting your server listed

Got other people to join your server and looking to have your server put up on the server list? Go to our forum and send a PM to either ColinJF or bearzly containing your server's name, your ip address or host name (i.e. the one you would find from whatismyip.com), the port your server is running on, and the server capacity that you would like to be listed.

If you have followed this guide, you should now have a Shoddy Battle server fully set up!

Troubleshooting

More will be added here as people ask questions

Other people can't connect to my server!!! What should I do?

Make sure you have read the section on port forwarding carefully. You need to forward both TCP and UDP traffic on the port you chose in the server.properties file. Also make sure that you have the correct internal IP address. It may help to set up a static IP address if possible. If you have set up port forwarding on your router and you are stilling having problems, check your firewall settings. You may need to alter them to allow Shoddy Battle to connect to other people.