Building the Server

From DSP Wiki
Revision as of 05:40, 30 July 2012 by Darkweb (Talk | contribs) (removing quotes from db name)

Jump to: navigation, search

Installing & Setting up the DS Server on Windows

Prerequisites

In this section we will download every program/tool we will need to setup and maintain the servers. Do not install these yet.

MySQL Community Server

Navicat Lite

Visual Studio 2010 (Full or Express)

Tortoise SVN

Visual C++ Redistributable Runtimes 2010

.Net 3.5 Runtime (already comes with Win 7)

.Net 3.5sp1 Runtime (already comes with Win 7)

.Net 4 Runtime

SQL Developer Package


Installation

MySql

Choose Typical Installation

After the main installation, select Launch the MySQL Instance Configuration Wizard

Select Detailed Configuration

Select Developer Machine

Select Multifunctional Database

Standard Installation Directory

Select Manual Setting and 1000 Concurrent connections

Select Enable TCP/IP Networking, Port Number 3306, and Enable Strict Mode

Select Best Support for Multilingualism

Select Install as Windows Service, Launch the MySQL Server automatically, and Include Bin Directory in Windows PATH.

Select Modify Security Settings, and enter a new password twice. Write down the MySQL password. (DO NOT LEAVE BLANK.)

Select Next, Execute, then Finish

Navicat Lite

Use default installation options.

Visual Studio 2010

Use default installation options. You may be forced to restart (sometimes twice) during the installation.

Tortoise SVN

Use default installation options. You can skip the step to reboot since we'll reboot once everything else is installed.

Visual C++ Redistributable Runtime 2010

Use default installation options.

.Net 3.5, 3.5 SP1, and 4.0

Use default installation options.

SQL Developer Package

Don't lose it, as we'll come back to it later.


At this point everything should be installed that needs to be and you can restart your PC to finalize them.



Downloading the Server Source Code

In this section we will use Tortoise SVN to download the latest SVN source code for the server.

Open Windows Explorer (right click the start button and choose Windows Explorer)

Right click on any folder select SVN Checkout

In the "URL of repository" put in the following url:

http://onetimexi.googlecode.com/svn/trunk/

Set the "Checkout directory" to

C:\dsp.

Click OK.

Wait for the download to finish.

Click OK to close Tortoise SVN.

Close windows explorer

At this point you have downloaded all of the source code for the latest version.



Setting up the Database

In this section we will use the data that you downloaded to build a database in MySQL.

Using a command script

If you follow this step, you may skip the next one.

Paste the following into notepad and save it as DSP_Import.cmd in your dsp\sql folder:

@ECHO OFF
REM =============================================================================
REM ====== THis script will drop the DB specificed, then create the DB  =========
REM ====== specified, and then load the DS tables into the DB. This     =========
REM ====== file needs to be run from within the \dsp\sql folder (same   =========
REM ====== folder with all the .sql files. Please edit as needed. By    =========
REM ====== default it WILL DROP the standard dspdb DB, loosing all      =========
REM ====== accounts and characters. If this is not desired, then update =========
REM ====== the file to load the new DB into a new DB name.              =========
REM =============================================================================
REM =============================================================================
REM ======                                                              =========
REM ======                     by Thrydwolf   11/5/2011                 =========
REM ====== Updated with status on the last step by bluekirby0 3/30/2012 =========
REM ======                                                              =========
REM =============================================================================
REM =============================================================================



ECHO Creating Database dspdb
REM ================================================
REM ====== Update "-p" with MySQL password =========
REM ====== Update dspdb with MySQL Databse =========
REM ================================================
mysqladmin -h localhost -u root -proot DROP dspdb


ECHO Creating Database dspdb
REM ================================================
REM ====== Update "-p" with MySQL password =========
REM ====== Update dspdb with MySQL Databse =========
REM ================================================
mysqladmin -h localhost -u root -proot CREATE dspdb


ECHO Loading dspdb with tables
REM ================================================
REM ====== Update "-p" with MySQL password =========
REM ====== Update dspdb with MySQL Databse =========
REM ================================================
FOR %%X IN (*.sql) DO ECHO Importing %%X & mysql dspdb -h localhost -u root -proot < %%X

ECHO Finished!

At a minimum you will need to change -proot in the script to where root is your mysql root password. If your password is 'foo' then you would use -pfoo instead.

You can use this script any time the svn is updated, but it will drop the table and thus delete all your player data. You may want to make manual changes instead unless you are using it purely as a test server.

Using Navicat

This is the more hands-on approach, and being comfortable doing it this way may make it easier to update individual tables later without having to learn the mysql command-line interface.

Open Navicat

Click Connection (or File, New Connection)

Connection name: DarkStar

Host Name/IP: localhost

Port: 3306

User Name: root

Password: Enter the password you wrote down during the mySQL installation.

Check Save Password

Click OK


In the connections pane double click DarkStar

Right click on DarkStar and select New Database...

Name it dspdb

Use the Default character set

Select OK.


Double click dspdb

Right click on dspdb and select Execute SQL File...

Browse to C:\dsp\sql and select abilities.sql

Click Start

Continue this process for each file in the folder.


If you have an issue with the triggers.sql file then follow this step. If not, proceed to the next step (IP address for the map server):


In Navicat Open accounts table

Click File, Design Table

Click the Triggers tab

There should a line already listed with account_delete in the Name field


If not:

click Add Trigger

Name column should be account_delete

Fires column should be Before

Check the box in the Delete column

In the definition box below add the following code:

BEGIN
   DELETE FROM `accounts_banned` WHERE `accid` = OLD.id;
   DELETE FROM `chars` WHERE `accid` = OLD.id;
END

Select Save and then close the table.

Open the chars table

Click File, Design Table

Click the Triggers tab

There should already be a line listed with char_delete in the name field.


If not:

click Add Trigger

Name column should be char_delete

Fires column should be Before

Check the box in the Delete column

In the definition box below add the following code:

BEGIN
   DELETE FROM `char_exp` WHERE `charid` = OLD.charid;
   DELETE FROM `char_jobs` WHERE `charid` = OLD.charid;
   DELETE FROM `char_equip` WHERE `charid` = OLD.charid;
   DELETE FROM `char_effects` WHERE `charid` = OLD.charid;
   DELETE FROM `char_look` WHERE `charid` = OLD.charid;
   DELETE FROM `char_stats` WHERE `charid` = OLD.charid;
   DELETE FROM `char_skills` WHERE `charid` = OLD.charid;
   DELETE FROM `char_titles` WHERE `charid` = OLD.charid;
   DELETE FROM `char_inventory` WHERE `charid` = OLD.charid;
   DELETE FROM `char_vars` WHERE `charid` = OLD.charid;
   DELETE FROM `char_bazaar_msg` WHERE `charid` = OLD.charid;
END


Select Save and then close the table.

Note: Leave Navicat open for the next section.



Configure the ZoneIP for the Map Server

Now you need to determine what IP address that will be used for the Map Server, then update MySQL with it.

Most devs & enthusiasts will not have a separate map server, but will run both map server and login server on the same PC.


Determine what IP address will be used for the map server.

If the server will be public, then use your external IP in the next step.

If the server will be internal and you want it available on other PCs in your internal network, use the internal network IP (192.168.x.x) in the next step.

If you only plan to run the client and the server on the same PC, you can use the localhost address (127.0.0.1) in the next step.

Calculate the new form from the IP address.

The IP must be entered in different form, so first we must calculate the new form. Use the formula below or This Handy Site to calculate it.


Formula = 1st Octet + 2nd Octet * 256 + 3rd Octet *256 (squared) + 4th Octet * 256 (cubed)

Example: 127.0.0.1 = 127 + 0 + 0 + 1*256(cubed) = 16777343

Example: 192.168.1.102 = 192 + 168*256 + 1*256(squared) + 102*256(cubed) = 1711384768

Example: 67.41.45.115 = 67 + 41*256 + 45*256(squared) + 115*256(cubed) = 1932339523


In Navicat double click on the table dspdb and expand

Click on Query

Right click and select New Query

Add the following code into the empty space, inserting the value calculated above. The value in the code below (16777343) would be used if only running the client from the same PC as the server.

BEGIN
    UPDATE zone_settings SET zoneip = '16777343';
END

Select Run. "256 queries should be successful!" should be the result.

I recommend you save the Query in case you need to run it again later after updating the server.

Close Navicat.

Building the Servers

In this section we will be building the Dark Star servers.

Dark Star uses 3 separate servers. A Login server, a Map/Game server, and an optional Search/Auction House server. Using the ZoneIP mentioned earlier, every map could run on its own server at a different IP address. If you have 4 computers each computer could run different areas, as long as they were all connected to the same MySQL database server.

Installing the MySQL Development Files

Extract the MySQL development package we downloaded earlier.

Copy the MySQL folder that was extracted. There should be a "mysql" folder inside with many files.

Paste that MySQL into either


32bit windows: C:\Program Files\Microsoft SDKs\Windows\v7.0A\Include


64bit windows: C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Include


Afterwords the folder structure should be ...Microsoft SDKs\Windows\v7.0A\Include\MySQL


Build the Login Server

Open Visual Studio

Click File, Open, Project/Solution (or Ctrl+Shift+O)

Navigate to C:\dsp\win32\DSConnect-Server

Select DSConnect-server.sln (usually the first one)

It may take a few minutes to load files.

Click Debug then Build Server (or F7, or Ctrl+Shift+B)

Building will take a few minutes.

Once complete, validate that there are no Errors listed in the summary line at the bottom. It should look like this:

========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

If there are any SQL errors it is probably caused by the SQL dev package was extracted to the wrong folder.

If there is a #include error, change that #include to say #include <mysql/mysql.h>


Build the Map Server

Click File, Open, Project/Solution (or Ctrl+Shift+O)

Navigate to C:\dsp\win32\DSGame-Server

Select DSGame-server.sln (usually the first one)

It may take a few minutes to load files.

Click Debug then Build Server (or F7, or Ctrl+Shift+B)

Building will take a few minutes.

Once complete, validate that there are no Errors listed in the summary line at the bottom. It should look like this:

========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

If there are any SQL errors it is probably caused by the SQL dev package was extracted to the wrong folder.

If there is a #include error, change that #include to say #include <mysql/mysql.h>


Building the Optional Search Server

Navigate to C:\dsp\win32\DSSearch-server

Select DSSearch-server.sln (usually the first one)

It may take a few minutes to load files.

Click Debug then Build Server (or F7, or Ctrl+Shift+B)

Building will take a few minutes.

Once complete, validate that there are no Errors listed in the summary line at the bottom. It should look like this:

========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

If there are any SQL errors it is probably caused by the SQL dev package was extracted to the wrong folder.

If there is a #include error, change that #include to say #include <mysql/mysql.h>


When all of the Servers are built

Verify in the C:\dsp directory that the servers you built are there:

DSConnect-server.exe for the Login Server

DSGame-server.exe for the Map Server

DSSearch-server.exe for the Search Server



Configuring the Servers

Now you will configure the Login Server and Map Server to connect to the MySQL database.

Do not mess with any other settings in these files unless you know what they are for and what they do.


Login Server Settings

In windows explorer navigate to c:\dsp\conf

Open login_darkstar.conf in a text editer (notepad)

Scroll down to the bottom and validate/update the following lines:

mysql_host: 127.0.0.1
mysql_port: 3306
mysql_login: root
mysql_password: root <-- change this to your password you wrote down during the MySQL install
mysql_database: dspdb


Map Server Settings

In windows explorer navigate to c:\dsp\conf

Open map_darkstar.conf in a text editer (notepad)

Scroll down to the bottom and validate/update the following lines:

mysql_host: 127.0.0.1
mysql_port: 3306
mysql_login: root
mysql_password: root <-- change this to your password you wrote down during the MySQL install
mysql_database: dspdb

Search Server Settings

In windows explorer navigate to c:\dsp\conf

Open search_server.conf in a text editer (notepad)

Scroll down to the bottom and validate/update the following lines:

mysql_host: 127.0.0.1
mysql_port: 3306
mysql_login: root
mysql_password: root <-- change this to your password you wrote down during the MySQL install
mysql_database: dspdb


At this point we have configured the servers to connect to the SQL database.



Starting the Servers

In this section we will launch our new servers.

Navigate to c:\dsp

Run DSConnect-server.exe as Admin

Run DSGame-server.exe as Admin

(Optional) Run DSSearch-server.exe as Admin

At this point if your servers fail to load, you probably missed a step. Go back through the steps and try to find out what you missed. It may also be helpful to look at the log files located in c:\dsp\log.


Forward Ports to Allow Others to Join (& Firewall)

In this section we will provide the port numbers that need to be forwarded to the server. This is only needed to allow people outside your local intranet to join your server.

In your router and firewall the following ports need to be opened/forwarded to your server:

54230
54231
54001

If still having trouble, disable any firewall software completely for testing. This includes the Windows firewall that comes on all modern Windows systems, which can be found in the Control Panel.


Installing & Setting up the DS Server on Linux

The server is known to build in recent Debian GNU/Linux, Ubuntu, and Fedora versions, and is tested regularly against all three platforms. It is also known to build on Gentoo.

Fedora-specific instructions may be found on the page: Fedora Linux Setup

Generic build instructions for most POSIX (GNU/Linux, and possibly FreeBSD, NetBSD, UNIX or even OSX with some additional work) systems follow. Some knowledge of how to compile software on your distribution is assumed. You may find it helpful to reference the Windows guide above if something is unclear.

Prerequisites:

A compiler with C++11 support. Currently tested with GCC and G++, and requires a minimum version of 4.6

Subversion to retrieve the source code.

patch to apply the search server patch (should be installed with subversion if your system lacks it)

Autotools (automake autoconf m4sh) and pkg-config to generate the configure script and Makefile

mysql server

mysql client library (select the developer version if your distro has one)

lua library version 5.1 or higher (select the developer version if your distro has one)

If you plan to run from a console, you may also wish to install "screen" as there is no daemon mode for the servers yet.

Preparing the Source Code

Once you have everything mentioned above installed, grab the latest source from the repository via the command:

svn co http://onetimexi.googlecode.com/svn/trunk/ dsp/

Now, find the latest version of the search server patch at The Darkstar Project Forums. Extract the diff file into the dsp folder and apply it using the command:

patch -p0 -i dssearchv6.diff

Compiling

Next is a typical autotools build. Run the autogen script, followed by configure, and then make:

sh autogen.sh
./configure --enable-debug
make

You can choose not to configure with debug enabled, but there is very little potential gain in this and it prevents many useful break statements from triggering. The Makefile also has separate targets to build each server named "dsconnect" "dsgame" and "dssearch" but will build all 3 if none are specified.

Setting Up the Database

If you do not know your mysql root password, the default on most systems is blank. It is a good idea to change this for security reasons, as your mysql root user has full permissions on all databases. The first time you run the mysql client, you should be prompted to change the password. After doing so, you will want to create a user specifically for dealing with the darkstar server database. Run mysql as follows:

mysql -u root -p

Enter your root password at the prompt. Next, create a new user as follows:

CREATE USER 'darkstar'@'localhost' IDENTIFIED BY 'password';

Substitute "password" with a password of your choice. Next, we want to create a database, and set up our new user with permissions to work with it.

CREATE DATABASE dspdb;
USE dspdb;
GRANT ALL PRIVILEGES ON dspdb.* TO 'darkstar'@'localhost';
exit

This will make it to where your new user can do anything necessary, but can only connect from localhost, so even if your password is compromised, it will be difficult to mess with the database remotely. If you need to be able to access the database remotely (like if the database is stored on a separate machine from the server), change the configuration according to the host that will be accessing the database.

Now, you need to populate the database.

cd sql
for f in *.sql
  do
     echo -n "Importing $f into the database..."
     mysql dspdb -u darkstar -ppassword < $f && echo "Success"      
  done
cd ..

To set up your ZoneIP, see the related windows section Building_the_Server#Configure_the_ZoneIP_for_the_Map_Server above for how to calculate it, and then run:

mysql -u darkstar -ppassword
USE dspdb;
UPDATE zone_settings SET zoneip = '16777343';
exit

replacing "16777343" with the value you determined in your calculation. You should see a message that 256 changes have occured after the update command.

Configuring the Server

Before running your new servers, you will need to update the configuration files to tell it how to talk to the database. You will need to update the files in the conf/ sub-folder named "login_darkstar.conf" "map_darkstar.conf" and "search_server.conf" at a minimum. Find the mysql settings in each and change as appropriate, using the new user, password and database you created earlier.

You may also wish to browse through the various configuration files for any settings that might be of interest to you, but more details on server customization can be found at Customizing Your Server.

Starting the Servers

You may now start your new servers. If you are using a desktop environment, you may wish to open 3 separate terminals and run each server in a separate one to monitor them efficiently. Otherwise, you will want to run them in screen sessions as follows:

screen -d -m -S dsconnect ./dsconnect
screen -d -m -S dsgame ./dsgame
screen -d -m -S dssearch ./dssearch

This will start and auto-detach all three servers, assigning them meaningful names to make it easy to reattach later by using the commands:

screen -r dsconnect

or

screen -r dsgame

or

screen -r dssearch

to monitor a given server. Once you've attached to a screen, you can detach by first pressing "ctrl+a" and then "d". There are many other useful ways to use screen, so do whatever suits yoru preference.

Your server is now up-and-running, and a client should be able to connect as long as there are no obvious errors on any of the server screens. If the search server is having issues, it is not vital for basic game functionality, but you will be unable to use search functions or the auction house. If you have run into any major issues, contact bluekirby0 (the current maintainer of the linux port as of the time of this writing) on IRC #darkstar@irc.rizon.net or in the forums.

Credits

The original windows guide was written by thrydwolf, and has been formatted for the wiki and updated by bluekirby0