StendhalLocalhostServerOnLinux: Difference between revisions

From Arianne
Jump to navigation Jump to search
Content deleted Content added
imported>Zenix2
m Bash it up! Starting marauroa: - Added version missing warning
imported>Kribbel
m link for skipping
 
(348 intermediate revisions by 13 users not shown)
Line 1: Line 1:
{{Navigation for Stendhal Top|Building & Hosting}}

This guide applies to:
*Marauroa 3.0 and above
*Stendhal 0.95 and above
<br>
= Setting up a localhost server =
= Setting up a localhost server =
This guide will teach you how to set up a server on your Ubuntu 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:
This guide will teach you how to set up a server on your Linux machine. The required packages are:
*A compiled version of Marauroa
*A compiled version of the Stendhal Server, version {{version}}
*GNU/Linux ''(This may be others, the directions should apply almost exactly to any *nix system)''
*A compiled version of the Stendhal Server
*Command-line access ''(ask system administrator if it's a problem)''
*MySQL
*GNU/Linux (This may be others, the directions should apply almost exactly to any *nix system)
*A text editor (doesn't matter)
*Command-line access
<!-- This is heavly based on the Visual Guide to Setting up a Localhost Server on Windows XP (c) -->
== Getting the materials ==
Download a current version of Stendhal and Maruroa. Build each of those. I won't go in-depth about this, it is worth an entire tutorial for each alone. Check out [[HowToBuildMarauroa|How to build Marauroa]] and [[HowToBuildStendhal|How to build Stendhal]] for more info. If you run a Linux System, then you have the necssairy tools to get everything else. I recommend ViM for those command-line lovers, and GEdit/Kate for those GUI people. Command line access shouldn't be a problem, ask your system administrator if you do and how to get to it.


For '''easy''' H2 database configuration (which is shipped with Stendhal and is installation-free) just skip straight to '''[[StendhalLocalhostServerOnLinux#Choosing_the_Java_Virtual_Machine|Choosing the Java Virtual Machine]]'''.
= Setting up MySQL =
After you've installed MySQL, make sure you have a database ready for it:
<pre>
mysql -u NAME -p -e "create database DB_NAME;"
</pre>
Where "NAME" is the name of the user to create the database (usaully root is fine), and "DB_NAME" is the name of the database. Remember this name!
<pre>
mysql -u NAME -p -e "grant all on DB_NAME.* to 'FOO'@'localhost' identified by 'BAR';"
</pre>
This will create (or just add to) a user called 'FOO', with a password of 'BAR'. Replace those with whatever you want. If the user doesn't exist, it'll be created. Again, remember these values (FOO and BAR)!


For '''advanced''' MySQL configuration, keep reading.
= Makin' the cake =
Well, now that we have the materials ready, we need to mix them together to create a great product, no? Here are the steps to take:
#Create a server directory, to hold everything in a nice, organized way
#Get Marauroa and Stendhal Server over to the server directory
#Run the Marauroa generateini script, to get a configuration file
#Create a marauroa loading script (in BASH)
#Have fun
Now, the first and last shouldn't be to hard. Let's create that directory!


== Creating the server directory ==
== Setting up MySQL ==

I'm an organized person when it comes to my computer. Now, sometimes that means I have to go about 3-4 levels deeper into the folder hireachroy to get where I want, but at least I know where my files are for whatever project directory I'm in. Now, you don't have to do this, but I like to keep my computer not so cluttered up with files that I don't know where they belong. Let's create it 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
Install MySQL:
<pre>

cd $HOME
sudo apt-get install mysql-server
mkdir stendhal_server

</pre>
Also download the java connector library if necessary (it's called ''MySQL Connector/J'' ), and make sure a symbolic/soft link to it named ''mysql-connector.jar'' is on the classpath (e.g. in the directory called ''libs'' inside the ''stendhal_server'' directory) when running ''maraurorad'' later.

For example:

ln -s /path/to/file-name/mysql-connector-java-5.1.10.jar mysql-connector.jar

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

'''Note''': It is recommended to edit the MySQL configuration file to disallow external access if you are just going to use it for local testing, or simply use a firewall to block external access to the database.

== Choosing the Java Virtual Machine ==
Stendhal works with OpenJDK or Oracle Java, you will need Java 7 or greater.

For Sun Java: Use your Package manager to download '''OpenJDK 7''' or Oracle Java 7 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.7.0-oracle 53 /usr/lib/jvm/java-1.7.0-oracle''
*''java-gcj 1042 /usr/lib/jvm/java-gcj''
*''java-7-openjdk 1061 /usr/lib/jvm/java-7-openjdk''

now, lets say you want to use the ''java-7-openjdk''. Then you type
update-java-alternatives --set java-7-openjdk
Now run
java -version
again to check it worked.

== Get the materials ==
Download a current version of the Stendhal server, ''stendhal-server-{{version}}.zip'' from [http://arianne.sourceforge.net/?arianne_url=games/game_stendhal#downloadsection arianne.sf.net].

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

== 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.
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.


== Marauroa and Stendhal: Moving time! ==
== Stendhal server files ==
Copy-paste the following files into the server directory:
Unzip the stendhal server zip which you downloaded, into the stendhal_server directory.
*marauroa.jar
*log4j.properties
*stendhal-server-#.##.jar
*stendhal-xmlconf-#.##.jar
*stendhal-maps-#.##.jar
*log4j.jar
*groovy.jar
*simple.jar
*jython.jar
*mysql-connector.jar
<!-- there is no real order to this list, just how I remembered it -->
Done!
Done!


== MySQL & Marauroa: Let the 2 be one ==
== Run the server ==
The first time you run the server a configuration file for the server (named ''server.ini'') will be generated.
Time to configure Marauroa to point to the database you made earlier. In the command-line (not in GUI!), run:

<pre>
There is a script ''runserver.sh'' in the stendhal_server directory - you may need to make it executable first.
java -cp marauroa.jar marauroa.server.generateini
So
</pre>
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

Now, it will ask you questions.

=== H2 database ===
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

'''Warning:''' Any value for the RSA key generation small than 512 may cause the server not to work properly and refuse the client connections.

=== MySQL database ===
If you want to use MySQL then see below for more details:
When it asks you for...
When it asks you for...
*database name, enter the name you used when making it (DB_NAME)
*Which database system do you want to use? write mysql (mysql)
*database name, hit enter to use the default (marauroa)
*host, using 'localhost' is fine
*host, hit enter to use the default (localhost)
*user, use the username you used in giving permissions (FOO)
*password, use the password you used giving permissions (BAR)
*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 deafult for stendhal, but it can be anything above 1024
*RSA key size- This is to make sure that the login information is valid and secure.
*game, type "stendhal" (or a number for that, if a muliple-choice menu appears)
'''Warning:''' Any value for the RSA key generation smaller than 512 may cause the server not to work properly and refuse the client connections.
*turn time, or how long the server takes to process each event, choose anything above 200, but below 1000. This is in milliseconds
*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 vaild and secure. Like the prompt says, anything greater than 1024 can take a LONG time. But, if you have ~30 mins 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, "marauroa.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 genereateini command again; the file could have change with updating the RSA keys


Download a recent mysql-connector.jar from the [https://dev.mysql.com/downloads/connector/j/ MySQL site].
== Bash it up! Starting marauroa ==
Well, BASH is pretty much standard in the linux world. If you don't have it, or use a different shell, modify this to your needs:
<pre>
#!/bin/bash


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 not, try running the runserver.sh script again; the file could have changed when updating the RSA keys
export LOCALCLASSPATH=.:stendhal-server.jar:marauroa.jar:jython.jar:mysql-connector.jar:log4j.jar:simple.jar:groovy.jar


== Stopping the Server ==
java -cp "${LOCALCLASSPATH}" marauroa.server.marauroad -c marauroa.ini -l
In the server window just type '''CTRL+c'''
</pre>
Save it as "blah.sh", replacing blah with whatever you want. Make sure it's executeable!
''Warning! in the line with "LOCALCLASSPATH", is has 'stendhal-server.jar', this is my file, and may not be yours. Do not change the name of the .jar file, just modify that line to include the version after 'server' so it's now 'stendhal-server-0.55.jar' (this is an example, your version may be different!) Ensure that this is the same thing as your .jar file!
''In the command-line, go to the server directory and type:
<pre>
./blah.sh
</pre>
Remember to change "blah" to whatever you typed in when saving the file. This will start the server, and produce A LOT of output!


== Have fun ==
== Starting the Server again ==
To start the stendhal server again you can just type from a command prompt:
Well, that's it! Just follow the last steps of ''Bash it up!'' to start the server. Pretty easy, huh? Check out the troubleshooting and extras sections for more things to do.
./runserver.sh


'''Note:''' Remember that the server configuration file (''server.ini'') is only generated the first time you run the server unless you delete it.

== 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 =
= Extras =
This is the extras section! Here you have trouble shooting, and hints & tips
This is the extras section! Here you have trouble shooting, and hints & tips
== Troubleshooting ==
== Troubleshooting ==
In general please see [[StendhalServerTroubleShooting]].
=== Cannot find data/conf/quest.xml ===
This is fixed in current CVS. You can ignore this error because the quest diary is not finished and in game yet.


=== Class not found exceptions ===
This is an easy one. Take stendhal-server.jar, and open it via a archive manager. Click through the folders until you are at /data/conf. Click on Add (or Import in some cases) and point it to the quests.xml file found in the source code directory of stendhal. This would be stednhal-src/data/conf/quests.xml. Click OK, and close the window. Stop your server, and start it again. You should not get this error again, unless you (accidently, right?) put the wrong file or put it on the wrong directory
For example:
<pre>
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/log4j/Logger
</pre>

''<span style="color:red;">DEPRECATED:</span> "log4j.jar" is now intended to be located in "libs" directory''

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.

=== MySQL possible error ===

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 )


=== Can't login! ===
You try logging in with the account you made when you first got Stendhal. It doesn't work in your server! You see, the MySQL database we created is the user and some other info database, meaning that we have a list of users, while the main server has it's own list. Until access is publicly granted to the MySQL database over there, we must click on Create An Account and choose localhost as the server to join. 2 different accounts. That, well, sucks.
== Server bonuses ==
== Server bonuses ==
=== You are the man! ===
=== 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 seperate line. The name must be EXACT, or it will not work. Then open stendhal-server.jar, and browse to /data/conf. Add admins.list there
Want to be an admin? Now you can! It's easy! Go to the directory where you extracted stendhal-server-{{version}}.zip, and browse to data/conf. Edit admins.txt there, with each admin name on a separate line. The name must be EXACT, or it will not work. The server needs '.' on the classpath, which is already done if you are using ''runserver.sh''.
=== 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:
<pre>
# 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
</pre>
The first 3 lines (not including the comment) point to specfic classes in your code. Ther 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:
<pre>
my_extention=java.class.path.to.my_extension
</pre>
And add "my_extention" to the end of server_extention (don't forget the comma seperating everything!)


= Finished =
= 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!
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!


[[Category:Stendhal]]

Latest revision as of 13:30, 25 January 2024


This guide applies to:

  • Marauroa 3.0 and above
  • Stendhal 0.95 and above


Setting up a localhost server

This guide will teach you how to set up a server on your Linux machine. 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)

For easy H2 database configuration (which is shipped with Stendhal and is installation-free) just skip straight to Choosing the Java Virtual Machine.

For advanced MySQL configuration, keep reading.

Setting up MySQL

Install MySQL:

sudo apt-get install mysql-server

Also download the java connector library if necessary (it's called MySQL Connector/J ), and make sure a symbolic/soft link to it named mysql-connector.jar is on the classpath (e.g. in the directory called libs inside the stendhal_server directory) when running maraurorad later.

For example:

ln -s /path/to/file-name/mysql-connector-java-5.1.10.jar mysql-connector.jar

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

Note: It is recommended to edit the MySQL configuration file to disallow external access if you are just going to use it for local testing, or simply use a firewall to block external access to the database.

Choosing the Java Virtual Machine

Stendhal works with OpenJDK or Oracle Java, you will need Java 7 or greater.

For Sun Java: Use your Package manager to download OpenJDK 7 or Oracle Java 7 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.7.0-oracle 53 /usr/lib/jvm/java-1.7.0-oracle
  • java-gcj 1042 /usr/lib/jvm/java-gcj
  • java-7-openjdk 1061 /usr/lib/jvm/java-7-openjdk

now, lets say you want to use the java-7-openjdk. Then you type

update-java-alternatives  --set java-7-openjdk

Now run

java -version

again to check it worked.

Get 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.

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. Done!

Run the server

The first time you run the server a configuration file for the server (named server.ini) will be generated.

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

Now, it will ask you questions.

H2 database

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

Warning: Any value for the RSA key generation small than 512 may cause the server not to work properly and refuse the client connections.

MySQL database

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)
  • RSA key size- This is to make sure that the login information is valid and secure.

Warning: Any value for the RSA key generation smaller than 512 may cause the server not to work properly and refuse the client connections.

Download a recent mysql-connector.jar from the MySQL site.

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 not, try running the runserver.sh script again; the file could have changed when updating the RSA keys

Stopping the Server

In the server window just type CTRL+c

Starting the Server again

To start the stendhal server again you can just type from a command prompt:

./runserver.sh

Note: Remember that the server configuration file (server.ini) is only generated the first time you run the server unless you delete it.

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

DEPRECATED: "log4j.jar" is now intended to be located in "libs" directory

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.

MySQL possible error

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! Go to the directory where you extracted stendhal-server-1.48.zip, and browse to data/conf. Edit admins.txt there, with each admin name on a separate line. The name must be EXACT, or it will not work. The server needs '.' on the classpath, which is already done if you are using runserver.sh.

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!