StendhalLocalhostServerOnLinux: Difference between revisions

From Arianne
Jump to navigation Jump to search
imported>Kymara
Setting up MySQL: example error had wrong db name for rest of guide
imported>Kymara
Setting up MySQL: example error had wrong db name for rest of guide
(No difference)

Revision as of 11:23, 21 February 2010

This guide applies to:

  • Marauroa 2.1 and above
  • Stendhal 0.65.5 and above


Setting up a localhost server

This guide will teach you how to set up a server on your Linux machine. The server will be a local one, so people from around the world cannot get to your server. Only those who are directly connected to you via a LAN can connect to this server. The required packages are:

  • A compiled version of the Stendhal Server, version 1.48
  • GNU/Linux (This may be others, the directions should apply almost exactly to any *nix system)
  • Command-line access (ask system administrator if it's a problem)

Optionally:

  • MySQL sudo apt-get install mysql-server

Otherwise you can just use the H2 database which is shipped with Stendhal and is installation-free.

Getting the materials

Download a current version of the Stendhal server, stendhal-server-1.48.zip from arianne.sf.net.

If you want to compile it yourself from CVS or the source code provided at the downloads link, then see How to build Stendhal for more info. If you run a Linux System, then you have the necessary tools to get everything else.

Stendhal works with OpenJDK or Sun Java, you will need Java 5 or greater.

For Sun Java: Use your Package manager to download Sun Java 1.5 or greater version. At a command line, type

java -version

and if you see anything other than the new java you just installed, then you need to update the java used. At a command line, type

update-java-alternatives  --list

(using sudo if you are an ubuntu user, or as root if you are another linux user) which should give you output something like this:

  • java-1.5.0-sun 53 /usr/lib/jvm/java-1.5.0-sun
  • java-6-sun 63 /usr/lib/jvm/java-6-sun
  • java-gcj 1042 /usr/lib/jvm/java-gcj

now, lets say you want to use the java-1.5.0-sun. Then you type

update-java-alternatives  --set java-1.5.0-sun

Now run java --version again to check it worked.

Setting up MySQL

You can skip this whole step if you want the fast installation with an H2 database: Go to Makin' the cake

After you've installed MySQL, make sure you have a database ready for it. At a command line, type

mysql -u NAME -p

if you need a password for your server (by default, you don't). If you don't need a password, omit the "-u NAME -p" part. At the prompt that appears, type

create database marauroa;
grant all on marauroa.* to 'FOO'@'localhost' identified by 'BAR';

FOO and BAR are the username and password to be used by Marauroa, respectively. Replace them with whatever you want. If the user doesn't exist, it will be created. Remember these values (FOO and BAR)! If you get a problem like:

ERROR 1044 (42000): Access denied for user 'FOO'@'localhost' to database 'marauroa'

then you need to login to mysql as the root mysql user, who should have 'grant' access. As root you can then try

grant all on marauroa.* to 'FOO'@'localhost' identified by 'BAR';

again

Makin' the cake

Create the server directory

Let's create your folder to run the server from, in your home directory. NOTE: The commands given are for use in the command-line, but you can take the GUI route as well. For some commands, you must run them from the command-line, and I will tell you

cd
mkdir stendhal_server

This will create a directory called "stendhal_server" in your home directory. See how easy that was? And how easy to tell what will be in that directory? That's the beauty of organization.

Stendhal server files

Unzip the stendhal server zip which you downloaded, into the stendhal_server directory.

Now check you have the following files in the stendhal_server directory:

  • stendhal-server-1.48.jar
  • stendhal-xmlconf-1.48.jar
  • stendhal-maps-1.48.jar
  • groovy.jar
  • simple.jar
  • marauroa.jar
  • log4j.jar
  • log4j.properties
  • jython.jar
  • mysql-connector.jar optional
  • commons-lang.jar

... or in a directory called lib or libs inside the stendhal_server directory. If any are in lib or libs please move them up into the main stendhal_server directory.

If any of the latter jars are missing you can fetch them here: http://arianne.cvs.sourceforge.net/arianne/stendhal/libs/ Done!

Configure marauroa

Time to configure Marauroa and the database access. In the command-line (not in GUI!), run:

java -cp stendhal-server-1.48.jar games.stendhal.server.core.engine.GenerateINI

Now, it will ask you questions.

H2

For the fast installation

  • hit Enter to accept the defaults, that you want H2 database
  • hit Enter so that to build the key, and wait for it to say:
server.ini has been generated

MySQL

If you want to use MySQL then see below for more details: When it asks you for...

  • Which database system do you want to use? write mysql (mysql)
  • database name, hit enter to use the default (marauroa)
  • host, hit enter to use the default (localhost)
  • user, write the username you used in giving MySQL permissions (FOO)
  • password, write the password you used giving MySQL permissions (BAR)
  • port, anything above 1024. 32160 is the default for stendhal, but it can be anything above 1024
  • game, type "stendhal" (or a number for that, if a multiple-choice menu appears)
  • turn time, or how long the server takes to process each event, choose anything above 200, but below 1000. This is in milliseconds. default is 300
  • log and stats generation logs, use the default ("./") - it's in the same directory as everything else
  • RSA key size, choose anything smaller than 1024 bits, but greater than 512 (or equal to). This is to make sure that the login information is valid and secure. Like the prompt says, anything greater than 1024 can take a LONG time. But, if you have ~30 minutes to spare (more or less, depending on your comp), you could use the extra security

Well, thats everything! When it's finished, you'll have a new file, "server.ini". Don't lose it, as it contains the information to get your server up & running, as well as the key to do that. If Marauroa won't start, and nor will your server, check to see if that INI file is there (at the same directory! NOWHERE ELSE!) and if it is, try running the GenerateINI command again; the file could have change with updating the RSA keys

Starting Server

To start the stendhal server you can just type

java -jar stendhal-server-1.48.jar

Or, there is a script runserver.sh in the stendhal_server directory - you may need to make it executable first. So

cd /path/to/stendhal_server

To make it executable, in a command prompt type

chmod u+x runserver.sh

To start it from a command prompt, type

./runserver.sh

Have fun

Well, that's it! Remember, when you use a client to connect you will need to create a new account and at server name localhost.

Extras

This is the extras section! Here you have trouble shooting, and hints & tips

Troubleshooting

In general please see StendhalServerTroubleShooting.

Class not found exceptions

For example:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/log4j/Logger

Please open runserver.sh in a text editor. You'll see the classpath defined there, something like

LOCALCLASSPATH=.:data/script/:data/conf/:stendhal-server-$STENDHAL_VERSION.jar:marauroa.jar:mysql-connector.jar:log4j.jar:commons-lang.jar

In this case the user had his log4j.jar in the folder called libs but the classpath expects it to be in the main folder where runserver.sh ran from. So you can: edit the classpath, replacing log4j.jar above with libs/log4j.jar or move the file.

Note for Slackware users:

If when you try to run the server later, you get this error in the log:

 Caused by: java.net.ConnectException: Connection refused

Type:

ps xa | grep mysqld 

If it shows that mysqld is running with the option "--skip-networking" then comment it out in the "my.cnf" file (It has been reported that the line to comment out is actually: SKIP="--skip-networking", found at: /etc/rc.d/rc.mysqld ).

If you have already commented it out then perhaps you have previously started the server with:

#/etc/rc.d/rc.mysqld start 

Stop the server and then restart with:

mysqld_safe & 

Check with:

ps xa | grep mysqld

that no "--skip-networking" is present.

Then run the stendhal server again.

(Many thanks to Tam Tam. Original source: http://forums.mysql.com/read.php?39,24742,147169#msg-147169 )


Server bonuses

You are the man!

Want to be an admin? Now you can! It's easy! First create a file called "admins.list" This is a plain text file, with each name on a separate line. The name must be EXACT, or it will not work. Then go to the directory where you extracted stendhal-server-X.XX.zip, and browse to data/conf (create it if it isn't already there). Add admins.list there. You may need to adjust the classpath which your server loads from.

Be my wife? And other server extensions

Server extensions. They add much (or little) functionality to a server, that another may not have. If you want to add the Spouse extension, which adds marriage (uh-oh!) to your server, just add these to your marauroa.ini file we created earlier (note that marriage is now built in to the server and doesn't require an extension, but you can use this template for all extensions, this is just an example):

# load StendhalServerExtension(s)
groovy=games.stendhal.server.scripting.StendhalGroovyRunner
http=games.stendhal.server.StendhalHttpServer
spouse=games.stendhal.server.extension.SpouseExtension
server_extension=groovy,http,spouse

http.port = 8080

The first 3 lines (not including the comment) point to specfic classes in your code. The server_extension line tells marauroa to load those extensions at start time. After adding these, restart your server. Don't worry - the RSA keys won't break because you added these lines. I personally have 3 server extensions that I wrote as well, 2 of which are broken (help!). To add those, just add this:

my_extension=java.class.path.to.my_extension

And add "my_extension" to the end of server_extension (don't forget the comma separating everything!)

Finished

Well, that's it. You're done. Finito. Fi. Whatever. You now have your own localhost server! No one can access yet; sign up for a free dynamic dns service at www.dyndns.com and connect a server they host to your IP. Then, all people have to do is go to whatever you set as your domain name with DynDNS. Party time!