Building Multiplayer Platform from source

From Popms Wiki
Jump to: navigation, search

For a general informations see: http://popms.net/en/get-involved/multiplayer-platform

Contents

[edit] How to compile the project from source

This project uses crossplatform build system - CMake. SVN client is required to download source code from the repository and commit changes. Other required tools and libraries are C++ compiler, Qt libraries, OpenSSL library, libpq and PostgreSQL.

IDEs which description is covered below are KDevelop (linux only), Microsoft C++ Visual Studio 2010 (windows only) and Eclipse CDT (java). Other IDEs, which have CMake and SVN support but which aren't covered by this page: Code::Blocks (windows, linux, mac osx). If you would have any problems with building you can look for help on the forums.

Supported versions of tools and libraries:

  • CMake >= 2.8
  • Qt >= 4.8
  • OpenSSL >= 1.0.1
  • PostgreSQL >= 9.1
  • libpq >= 9.1
  • g++ >= 4.7, visual >= 2008, clang >= 3.0

notice: http://popms.net/forums/tracker/issue-53-project-is-compilable-under-clang-but-buggy

[edit] Visual Studio 2010 (Windows)

  1. Download and install Qt libraries for Visual Studio (not SDK, size should be ~200+ MB) and CMake.
  2. Now you need to download project files from the SVN repository. You can use any SVN client for Windows (eg. QSvn, eSvn, RapidSVN) for this purpose or use extern plugin to visual like AnkhSVN. Suggested SVN client is http://tortoisesvn.net/ , we don't recommend plugins to IDE for SVN support, because it's not always possible to control all their actions (eg. they can commit some visual project files without asking user about it).
  3. When using extern SVN client follow instructions for your client and download project files from the repository (https://svn.code.sf.net/p/multiplayerplat/code/trunk).
    When using AnkhSVN download project files by: File > Open > Subversion Project..., fill with the repository adress (https://svn.code.sf.net/p/multiplayerplat/code/trunk), pick file MultiplayerPlatform.sln from the build directory and let it being downloaded. Close Visual Studio, we are going to generate project files.
  4. Generate Visual Studio project files using CMake GUI:
    Where is the source code: path to the project files eg. C:\Users\daroo\Documents\Visual Studio 2010\Projects\MultiplayerPlatform
    Where to build the binaries: pick directory for binaries eg. C:\Users\daroo\Documents\Visual Studio 2010\Projects\MultiplayerPlatform\build
    Now Configure > Use default native compilers then Configure and Generate.
  5. You can now open Visual Studio, open solution file from the "build" directory and compile the project.
  6. After you compile the project you need to copy required Qt libraries from Qt bin directory ( usually C:\Qt\4.6.0\bin ) to the directory where are located compiled executables MPClient.exe and MPServer.exe:
    Libraries required by MPClient.exe: QtCore4.dll, QtGui4.dll, QtNetwork4.dll, QtOpenGL4.dll
    Libraries required by MPServer.exe: QtCore4.dll, QtNetwork4.dll, QtSql4.dll

    Debug version of the MPClient.exe and MPServer.exe require debug version of libraries, which have names with additional letter 'd' e.g. QtCored4.dll. Instead of copying libraries you can also add Qt bin directory to the PATH environment variable. Debug version of the MPServer.exe seems to have problems with working under Windows 7 x86_64 see bug tracker for details.
  7. Copy required OpenSSL libraries from the "lib\openssl" directory to the location of MPClient.exe and MPServer.exe.
  8. #How to prepare database
  9. #How to run server

[edit] Command line (Linux)

  1. Install Subversion, Qt, OpenSSL, libpq and CMake. Command for debian:
    sudo apt-get install openssl qt-sdk subversion libpq5 libqt4-sql-psql cmake
  2. Download source code from the repository:
    svn co https://svn.code.sf.net/p/multiplayerplat/code/trunk MultiplayerPlatform
  3. Compile the project
    cd MultiplayerPlatform/build && cmake ../ && make
  4. #How to prepare database
  5. #How to run server

[edit] KDevelop (Linux)

  1. Install Subversion, Qt, OpenSSL, CMake, libpq and KDevelop. Command for debian:
    sudo apt-get install openssl qt-sdk subversion libpq5 libqt4-sql-psql cmake kdevelop
  2. Open console and go to the location you want to put project directory. Run in console to download project files to the MultiplayerPlatform directory:
    svn co https://svn.code.sf.net/p/multiplayerplat/code/trunk MultiplayerPlatform
  3. Open project in kdevelop: Project > Open / Import Project... and open file MultiplayerPlatform.kdev4 or CMakeList.txt.
  4. You should be able now to compile the project.
  5. #How to prepare database
  6. #How to run server

[edit] Eclipse CDT (windows, linux)

Following steps have been tested using CDT 8.1.0 for Eclipse Juno. Installing Qt plugin to Eclipse is not recommended - it's heavy, slow and it's better to use Designer program attached to Qt libraries instead.

  1. Windows (MinGW): Download and install java, MinGW, Qt libraries for MinGW (not SDK, size should be ~300+ MB) and CMake
    Windows (Visual): Download and install java, Qt libraries for Visual Studio (not SDK, size should be ~200+ MB) and CMake
    Linux: Download and install GNU tools (g++, gdb etc.), Qt, OpenSSL, Subversion, libpq and CMake. Sample command for debian:
    sudo apt-get install openssl qt-sdk subversion libpq5 libqt4-sql-psql cmake
  2. Windows (MinGW): Setup environment variables for mingw tools (make sure that gcc and g++ work in the windows command line).
  3. Download and install Eclipse CDT.
  4. Install SVN client plugin
    Help > Install New Software...
    Add link to subclipse site in a place "Work with: http://subclipse.tigris.org/update_1.8.x"
    From the list of plugins select and install "Subclipse".
  5. Download project file from the repository
    File > New > Other... > SVN
    Checkout Projects from SVN
    Create a new repository location
    Url: https://multiplayerplat.svn.sourceforge.net/svnroot/multiplayerplat/
    Select "trunk" (main development branch) and click finish - project should be now being downloaded from the repository.
  6. Setup external tool - eclipse project file generator
    Run > External Tools > External Tools Configurations...
    create new program and name it for example "cmake"
    Location: path to cmake, usually "C:\Program Files (x86)\CMake 2.8\bin\cmake.exe" for windows and "/usr/bin/cmake" for linux
    Working Directory: ${project_loc}

    Arguments:
    -G "Eclipse CDT4 - MinGW Makefiles" -DCMAKE_BUILD_TYPE:STRING=Debug <-- for windows
    -G "Eclipse CDT4 - Unix Makefiles" -DCMAKE_BUILD_TYPE:STRING=Debug <-- for linux

    If you have more Qt versions installed on windows you need to add more flags, to use correct version of libraries, like:
    -G "Eclipse CDT4 - MinGW Makefiles" -DQT_QMAKE_EXECUTABLE=C:\Qt\4.8.2\bin\qmake.exe

    In the "Refresh" tab select "The project containing the selected resources"
    In the "Common" tab check the "External Tools"
    Click the Apply Button
  7. Now you should be able to compile project

    Select project and click on external tool icon - cmake will generate eclipse makefiles.
    Select project > right click > Build Project OR Select project > right click > Clean Project

    You need to use this custom tool in eclipse every time you make changes to CMakeList.txt file. SVN client commands are available after Right click on resource > Team. I had problems with building aproject under 64bit linux - it doesn't link executables with libraries although it does link in command line. More informations about Eclipse generator for CMake are available on the site: http://www.cmake.org/Wiki/Eclipse_CDT4_Generator .
  8. Under Windows after you compile the project you need to copy required Qt libraries from Qt bin directory ( usually C:\Qt\4.6.0\bin ) to the directory where are located compiled executables MPClient.exe and MPServer.exe:
    Libraries required by MPClient.exe: QtCore4.dll, QtGui4.dll, QtNetwork4.dll, QtOpenGL4.dll
    Libraries required by MPServer.exe: QtCore4.dll, QtNetwork4.dll, QtSql4.dll

    Debug version of the MPClient.exe and MPServer.exe require debug version of libraries, which have names with additional letter 'd' e.g. QtCored4.dll. Instead of copying libraries you can also add Qt bin directory to the PATH environment variable. Debug version of the MPServer.exe seems to have problems with working under Windows 7 x86_64 see bug tracker for details.
  9. Under windows copy required OpenSSL libraries from the "lib\openssl" directory to the location of MPClient.exe and MPServer.exe.
  10. It might be necessary to compile PostgreSQL driver if it's not shipped with libraries. Check if you have a file named "qsqlpsql4.dll" in the plugins directory (usually "C:\Qt\4.8.2\plugins\sqldrivers"). If not then follow instructions in the documentation to compile the driver.
  11. #How to prepare database
  12. #How to run server

[edit] How to prepare database

PostgreSQL database is required if you want to run MPServer locally on your computer, which is essential for development of the system. Under windows download and install PostgreSQL. Linux distributions usually contain this popular database system in their software repository.

Create database with user and password, which is going to be used by MPServer. Windows installer comes with GUI program, which allows to perform these actions without using SQL commands. Here's a sample session under linux (debian):

sudo su postgres
psql
postgres-# create database mpdb;
CREATE DATABASE
postgres=# create user mpuser with password 'mppass';
CREATE ROLE
postgres=# grant all privileges on database mpdb to mpuser;
GRANT
postgres=# \q

Default settings used by the server are like the following:

host = localhost
user = mpuser
pass = mppass
db_name = mpdb

and they are stored in the file DB.ini . Edit this file if you want to customize these settings for your server.

[edit] How to run server

Server is a command line application and, as such, doesn't have any clickable GUI. When it's started for the first time it installs all modules and prepares tables in the database. Sample server output under linux:

daroo@debian:server$ ./MPServer 55346
10.24 12:44:38    |INFO| Testing connection to the database...
10.24 12:44:38   |DEBUG| Plugins location (including SQL drivers): "/usr/lib64/qt4/plugins" 
10.24 12:44:38    |INFO| Connected to the database using host_name: "localhost" db_name: "mpdb" , user: "mpuser" 
10.24 12:44:38    |INFO| Database contains no tables, preparing database...
NOTICE:  CREATE TABLE will create implicit sequence "mp_modules_module_id_seq" for serial column "mp_modules.module_id"
NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "mp_modules_pkey" for table "mp_modules"
10.24 12:44:38   |DEBUG| Query: "CREATE TABLE mp_modules( module_id SERIAL PRIMARY KEY, name VARCHAR(20) )" isActive: true , affected rows: -1 
10.24 12:44:38    |INFO| Database contains no views
10.24 12:44:38    |INFO| Database is ready
10.24 12:44:38   |DEBUG| Query: "SELECT name FROM mp_modules" isActive: true , affected rows: 0 
10.24 12:44:38    |INFO| Installing "Core"  [ "0.8" ] module...
(...)
10.24 12:44:39    |INFO| Module "Core"  [ "0.8" ] installed successfully
10.24 12:44:39    |INFO| Installing "Populous3"  [ "0.8" ] module...
(...)
10.24 12:44:39    |INFO| Module "Populous3"  [ "0.8" ] installed successfully
10.24 12:44:39   |DEBUG| Query: "INSERT INTO mp_modules( name ) VALUES ( 'Core' ), ( 'Populous3' )" isActive: true , affected rows: -1 
10.24 12:44:39    |INFO| Loading "Core"  [ "0.8" ] module...
10.24 12:44:39   |DEBUG| Query: "SELECT chat_room_id, name, is_public FROM mp_core_chat_rooms" isActive: true , affected rows: 1 
10.24 12:44:39    |INFO|  "/home/djania/projects/multiplayerplat-code/build/server/Data/Avatars.dat"  - Initializing the empty file for avatars DB...
10.24 12:44:39    |INFO|  "/home/djania/projects/multiplayerplat-code/build/server/Data/Avatars.dat"  - Initializing the avatar DB cache...
10.24 12:44:39   |DEBUG| AvatarDB, mdataOffset = 256 , mmetaOffset =  16640 , mavtBlockSize =  8192 , mavtBlockSpace =  2 mmetaBlockSize =  8 , mnumMetaBlocks =  2 
10.24 12:44:39   |DEBUG| AvatarDB, number of users in the cache:  0 , number of free blocks:  2 
10.24 12:44:39    |INFO| The avatar DB is ready for use. Number of stored avatars:  "0" 
10.24 12:44:39    |INFO| Module "Core"  [ "0.8" ] loaded
10.24 12:44:39    |INFO| Loading "Populous3"  [ "0.8" ] module...
10.24 12:44:39    |INFO| Module "Populous3"  [ "0.8" ] loaded
10.24 12:44:39    |INFO| Server started using port 55346.

Once you launch the server successfully you can connect to it using MPClient. To stop server press ctrl+c or send TERM signal to the process (kill <PID_of_the_MPServer>):

^C12.10 20:49:05    INFO| Quitting, closing "0" active connections...
12.10 20:49:05    INFO| Cleaning modules...
12.10 20:49:05    INFO| Closing connection to the database...
12.10 20:49:05   DEBUG| Close connection:  "qt_sql_default_connection" 
12.10 20:49:05    INFO| Quitting the program...

[edit] Common problems with connection to the database server

In case of problems with the connectivity to DB ensure that:

  1. PostgreSQL is installed, up and running - steps to install, configure and start database are specific to the operating system (they also diferes between linux ditributions).
  2. LINUX: Make sure a library libpq is present in the system.
  3. LINUX: Make sure PostgreSQL driver for Qt is present in the system.
  4. Executables have same bit architecture - i686 libpq can't be used together with x64 programs.
  5. Port number is correct - under linux it might be used explicitly, like: "psql -h localhost -p <port_number> -U mpuser -W mpdb".

Sample output, when there is Qt driver missing in the system:

[djania@debian:server]$ ./MPServer 55346
10.24 10:20:21 |WARNING| QSqlDatabase: QPSQL driver not loaded
10.24 10:20:21 |WARNING| QSqlDatabase: available drivers: QSQLITE
10.24 10:20:21    |INFO| Testing connection to the database...
10.24 10:20:21   |DEBUG| Plugins location (including SQL drivers): "/usr/lib64/qt4/plugins" 
10.24 10:20:21   |ERROR| Couldn't connect to the database, host_name: "localhost" , port: 5433 , db_name: "mpdb" , user: "mpuser" , pass length: 6 
10.24 10:20:21   |ERROR| "Driver not loaded Driver not loaded" 
10.24 10:20:21   |DEBUG| Close connection:  "qt_sql_default_connection"

Sample output, when incorrect port 5433 is used:

[djania@debian:server]$ ./MPServer 55346
10.24 10:44:49    |INFO| Testing connection to the database...
10.24 10:44:49   |DEBUG| Plugins location (including SQL drivers): "/usr/lib64/qt4/plugins" 
10.24 10:44:49   |ERROR| Couldn't connect to the database, host_name: "localhost" , port: 5433 , db_name: "mpdb" , user: "mpuser" , pass length: 6 
10.24 10:44:49   |ERROR| "could not connect to server: Connection refused
	Is the server running on host "localhost" and accepting
	TCP/IP connections on port 5433?
QPSQL: Unable to connect" 
10.24 10:44:49   |DEBUG| Close connection:  "qt_sql_default_connection"

Sample outpute, when credentials are incorrect or database server is misconfigured (database doesn't accept connections):

[djania@debian:server]$ ./MPServer 55346
10.24 11:38:19    |INFO| Testing connection to the database...
10.24 11:38:19   |DEBUG| Plugins location (including SQL drivers): "/usr/lib64/qt4/plugins" 
10.24 11:38:19   |ERROR| Couldn't connect to the database, host_name: "localhost" , port: 5432 , db_name: "mpdb" , user: "mpuser" , pass length: 6 
10.24 11:38:19   |ERROR| "FATAL:  Ident authentication failed for user "mpuser"
QPSQL: Unable to connect" 
10.24 11:38:19   |DEBUG| Close connection:  "qt_sql_default_connection"
Personal tools
Namespaces

Variants
Actions
Navigation
Tools