Results 1 to 4 of 4

Thread: How to run my Call of Duty 2 server using Libcod?

  1. #1
    Private
    Join Date
    Mar 2019
    Posts
    16
    Thanks
    2
    Thanked 3 Times in 3 Posts

    How to run my Call of Duty 2 server using Libcod?

    Hello everyone,

    Well, can someone explain to me how to run my server with libcod? I've tried this already

    Code:
    LD_PRELOAD=libcod2_1_3_nomysql.so ./cod2_lnxded...
    But it doesn't work, my directory is cd /root/mysrv ... if changes are needed, please tell me how!

    Thanks.

  2. #2
    Assadministrator kung foo man's Avatar
    Join Date
    Jun 2012
    Location
    trailerpark
    Posts
    1,963
    Thanks
    1,896
    Thanked 1,063 Times in 739 Posts
    On some systems you need to specify LD_LIBRARY_PATH, like:

    LD_LIBRARY_PATH=. LD_PRELOAD=libcod2_1_3_nomysql.so ./cod2_lnxded ...

    If that doesn't help, follow the proper tutorial: https://killtube.org/showthread.php?...u-14-04-server

    If you are using one of those years-old precompiled .so's, compile it yourself
    timescale 0.01

  3. #3
    Private
    Join Date
    Mar 2019
    Posts
    16
    Thanks
    2
    Thanked 3 Times in 3 Posts
    Oh okay, thank you ))

  4. #4
    ... connecting
    Join Date
    Jul 2019
    Posts
    7
    Thanks
    0
    Thanked 2 Times in 2 Posts
    I'm here, but was a fairly active modder at IWNation back in the days. Just started to play and mod COD2 again last week. This site is great to get started again, since I wasn't using libcod in the past. So I'm happy to share some knowledge back.

    Which Linux distro are you using? If you're using Ubuntu 18.04 64-bit (or newer) I'm glad to help you out. There are thousand ways to do this, but if you don't have any Linux experience you'll have to follow the instructions by the letter. Otherwise, you will end up with permission issues.

    Setup a COD2 server with libcod
    This guide is written with the intention to deploy a COD2 server on a remote Ubuntu 18.04 64 bit server from a Windows machine.

    1) First install Call of Duty 2 on your Windows system. You can patch it to v1.3 if you want, the official distributed Linux binaries contains the v1.3 patch content anyway.

    2) Gain terminal / SSH access to your Ubuntu server. You can use PuTTY for SSH.

    If you're using KVM to access your server, you can install OpenSSH for SSH access.

    Code:
    $ sudo apt install openssh-server
    $ sudo systemctl enable sshd
    $ sudo systemctl start sshd
    If you're behind a NAT and/or hardware firewall, you must do some port forwarding and allow SSH traffic to pass through. SSH traffic uses port 22 (TCP) by default.

    Now connect to your server using SSH and log in with your user (normally this shouldn't be the root user).

    3) You can now create the directory to store the game files. I'll prefer a directory in '/opt' for Debian (Ubuntu) based distros.

    Code:
    $ sudo mkdir /opt/cod2-server
    4) Set the owner and group of the created folder. If we don't do this, you can't manage this directory with your default non-root user. Also set a sticky bit so everything that's created in this directory inherits the correct user and group. Normally, your user and group are the same values, and should not be root! Replace <your-user> and <your-group> with your user and group respectively.

    Code:
    $ sudo chown <your-user>:<your-group> -R /opt/cod2-server
    $ chmod u+s /opt/cod2-server
    $ chmod g+s /opt/cod2-server
    5) Now the directory is made, and all permission are set correctly, we can copy over the game files. You can use WinSCP or any other compatible program to transfer files via SSH to your server. Run WinSCP, connect to your server using your username and password and navigate to the newly created '/opt/cod2-server' directory. Now copy the contents of Call of Duty game folder (default 'C:\Program Files (x86)\Activision\Call of Duty 2') to '/opt/cod2-server' directory on your server.

    6) You can delete all EXE and DLL files. Those are for Windows.

    Code:
    $ rm /opt/cod2-server/*.exe
    $ rm /opt/cod2-server/*.dll
    $ rm /opt/cod2-server/pb/*.dll
    7) Verify the copied files and ownership. It should look like this.

    Code:
    $ ls -l /opt/cod2-server
    
    -rw-rw-r-- 1 <your-user> <your-group>      67 Jun 23 17:06 cod2patch.ini
    -rw-rw-r-- 1 <your-user> <your-group>  921656 Sep  2  2005 cod.bmp
    -rw-rw-r-- 1 <your-user> <your-group>  109976 Sep  7  2005 codlogo.bmp
    drwxrwsr-x 3 <your-user> <your-group>    4096 Jun 23 17:17 Docs
    -rw-rw-r-- 1 <your-user> <your-group>    2271 Oct  2  2005 localization.txt
    drwxrwsr-x 2 <your-user> <your-group>    4096 Jun 23 22:12 main
    drwxrwsr-x 2 <your-user> <your-group>    4096 Jun 23 17:17 miles
    drwxrwsr-x 4 <your-user> <your-group>    4096 Jun 23 17:17 pb
    -rw-rw-r-- 1 <your-user> <your-group>     141 Jun  5  2006 version.inf
    8) Download a copy of the Call of Duty 2 v1.3 Linux Server binaries and upload the extracted content to your '/opt/cod2-server' directory. Make sure the ownership of the files are correct. This should be already correct if you've downloaded the binaries on your Windows machine, extracted it, and uploaded the extracted content directly to your '/opt/cod2-server' directory using WinSCP.

    9). Give the Linux binaries execution permissions.

    Code:
    $ chmod +x /opt/cod2-server/cod2_lnxded
    10) Download Voron00's libcod on your Windows machine. Extract the ZIP file and rename the extracted folder from 'libcod-master' to 'libcod'. Upload the folder to your server and place it your '/opt/cod2-server' directory using WinSCP (that is the whole folder, not the contents inside it). Finally, give the build script execution rights.

    Code:
    $ chmod +x /opt/cod2-server/libcod/doit.sh
    11) Install some additional required packages on your Ubuntu server in order to build libcod and run the COD2 server.

    Code:
    $ sudo dpkg --add-architecture i386
    
    $ sudo apt-get update
    
    $ sudo apt-get install libstdc++5:i386 
    $ sudo apt-get install libstdc++6:i386
    
    $ sudo apt-get install gcc-multilib
    $ sudo apt-get install g++-multilib
    Note that the libstdc pacakges are required for running libcod and the COD2 Linux binaries. The gcc and g++ multilib packages are needed for building libcod. Additionally, install a MySQL client if you want MySQL support in libcod. Of course, you also will need to setup a MySQL server if you do that (not explained here).

    Code:
    $ sudo apt-get install libmysqlclient-dev:i386
    12) Build libcod for Call of Duty 2 v1.3.

    Code:
    $ /opt/cod2-server/libcod/doit.sh cod2_1_3
    If everything goes right, you can find the compiled binary 'libcod2_1_3.so' in the folder '/opt/cod2-server/libcod/bin'.

    13) Now setup some start up scripts so we can automatically start the server on boot and control it as a service.

    Code:
    $ sudo vi /lib/systemd/system/cod2-server.service
    Press 'i' or 'insert' to allow editing in vim. Then copy paste the following code into vim (right click to paste when you're using PuTTY).

    Code:
    [Unit]
    Description=Call of Duty 2 server
    After=network.target
    Wants=network-online.target
    
    [Service]
    Type=simple
    User=<your-user>
    Group=<your-group>
    Environment="LD_PRELOAD=/opt/cod2-server/libcod/bin/libcod2_1_3.so"
    ExecStart=/opt/cod2-server/cod2_lnxded <additional-startup-parameters>
    Restart=always
    KillMode=process
    
    [Install]
    WantedBy=multi-user.target
    Don't forget to modify the parameters (User, Group and ExecStart). This is basic stuff for running a dedicated Call of Duty 2 server. For example:

    Code:
    ExecStart=/opt/cod2-server/cod2_lnxded +set fs_homepath "/opt/cod2-server" +set fs_basepath "/opt/cod2-server" +set fs_game "henkspermatank"  +set com_hunkmegs "512" +exec "server.cfg"
    Save and exit by pressing ESC and typing ':wq'.

    15) Set up your COD2 server accordingly. Create your fs_game directory in '/opt/cod2-server' and place a server configuration file inside it (henkspermatank and server.cfg respectively in the above example). Here's a handy server configuration generator. It's in German but it's the most complete one that I could find.

    16) Enable the service to automatically run the COD2 server on boot.

    Code:
    $ sudo systemctl daemon-reload
    $ sudo systemctl enable cod2-server
    You can control the service manually using the commands stated below.

    Code:
    $ sudo systemctl start cod2-server
    $ sudo systemctl stop cod2-server
    $ sudo systemctl status cod2-server
    17) If everything is configured correctly, you have a basic COD2 server running now. Port forwarding isn't necessary if your server is directly connected to the internet (no firewall or router). This scenario is most likely if you're renting a VPS. If you're behind a NAT and/or hardware firewall, you must do some port forwarding and allow COD2 traffic to pass through. COD2 uses the following ports: 28960 (TCP+UDP), 20500 (UDP) and 20510 (UDP).


    Debugging the COD2 server

    You can use journalctl to see the server logs. First command show the full log, the second command prints the last 100 lines of the log.

    Code:
    $ sudo journalctl -u cod2-server
    $ sudo journalctl -u cod2-server -n 100 --no-pager
    Alternatively, you can also run the server directly instead of a service to see and enter commands in the Call of Duty 2 console. Just like on Windows. Handy for debugging purposes.

    Close down the service first if it's already running.

    Code:
    $ sudo systemctl stop cod2-server
    Set the LD_PRELOAD variable to run the Linux binaries with libcod. The export command only needs to be entered once a session (and can give you warnings if you user other commands during this session). You can press CTRL+C to terminate the server.

    Code:
    $ export LD_PRELOAD=/opt/cod2-server/libcod2/bin/libcod2_1_3.so
    $ /opt/cod2-server/cod2_lnxded <additional-startup-parameters>
    Unset the LD_PRELOAD variable if you're done with debugging.

    Code:
    $ export LD_PRELOAD=
    Start the server again using the service daemon.

    Code:
    $ sudo systemctl start cod2-server

    Setting up HTTP downloads for faster mod download

    If you're running mods on your server, your clients will be in for a long ride. When users connect, the client automatically downloads installed mods on the server using a painly slow slow method (we're talking kilobytes per seconds here). Enabling HTTP downloads offers faster downloads for your clients. Use the following configuration in your COD2 server configuration file (e.g. server.cfg).

    Code:
    set sv_allowdownload "1"
    set sv_wwwdownload "1"
    set sv_wwwbaseurl "http://<your-webserver-ip-or-hostname>"
    set sv_wwwdldisconnected "0"
    You can use an external webserver serving an exact copy of all IWD mod files in your fs_game folder. The IWD files needs to be accessible from http://<your-webserver-ip-or-hostname>/<your-fs_game-directory-name>/. The client will fall back to the conventional slow download method if the webserver is missing or serving the wrong files.

    Alternatively, you can also serve the IWD files directly from your COD2 server by installing some HTTP webserver software (e.g Lighttpd, NGINX or Apache). Here's a quick guide on installing and configuring Apache to serve IWD files directly from your COD2 server using the HTTP download method. This method doesn't require mirroring the files from your fs_game folder on an external webserver.

    Install Apache and enable it run on boot.

    Code:
    $ sudo apt install apache2
    $ sudo systemctl enable apache2
    $ sudo systemctl start apache2
    Modify the default Apache configuration file to serve only IWD files from your fs_game folder. Adjust accordingly. A brief explanation to use VIM is given in step 13.

    Code:
    $ sudo vi /etc/apache2/sites-available/000-default.conf
    Code:
    <VirtualHost *:80>
            # The ServerName directive sets the request scheme, hostname and port that
            # the server uses to identify itself. This is used when creating
            # redirection URLs. In the context of virtual hosts, the ServerName
            # specifies what hostname must appear in the request's Host: header to
            # match this virtual host. For the default virtual host (this file) this
            # value is not decisive as it is used as a last resort host regardless.
            # However, you must set it for any further virtual host explicitly.
            #ServerName www.example.com
    
            ServerAdmin webmaster@localhost
            DocumentRoot /var/www/html
    
            Alias "/<your-fs_game-directory-name>" "/opt/cod2-server/<your-fs_game-directory-name>"
    
            <Directory "/opt/cod2-server/<your-fs_game-directory-name>">
                    Require all denied
    
                    <FilesMatch "\.iwd$">
                            Require all granted
                    </FilesMatch>
            </Directory>
    
            # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
            # error, crit, alert, emerg.
            # It is also possible to configure the loglevel for particular
            # modules, e.g.
            #LogLevel info ssl:warn
    
            ErrorLog ${APACHE_LOG_DIR}/error.log
            CustomLog ${APACHE_LOG_DIR}/access.log combined
    
            # For most configuration files from conf-available/, which are
            # enabled or disabled at a global level, it is possible to
            # include a line for only one particular virtual host. For example the
            # following line enables the CGI configuration for this host only
            # after it has been globally disabled with "a2disconf".
            #Include conf-available/serve-cgi-bin.conf
    </VirtualHost>
    Restart Apache.

    Code:
    $ sudo systemctl restart apache2
    If you're behind a NAT and/or hardware firewall, you must do some port forwarding and allow HTTP traffic to pass through. HTTP traffic uses port 80 (TCP) by default.


    Enable the the firewall on your server

    Enable UFW for enhanced server security. Adjust accordingly if you already have UFW running. These are instructions for a fresh, unconfigured firewall. It will reset your existing configuration if you follow these instructions!

    Code:
    $ sudo ufw disable
    $ sudo ufw reset
    
    $ sudo ufw default deny incoming
    $ sudo ufw default allow outgoing
    
    $ sudo ufw allow 22/tcp
    $ sudo ufw allow 80/tcp
    
    $ sudo ufw allow 28960/tcp
    $ sudo ufw allow 28960/udp
    $ sudo ufw allow 20500/udp
    $ sudo ufw allow 20510/udp
    
    $ sudo ufw enable
    Ports 22 and 80 are for SSH and HTTP downloads respectively. You can drop the port 80 rule if you don't run a HTTP server running to serve IWD files to your clients. It's also best practice to avoid SSH being exposed to the whole world. However, if you rent a VPS or single dedicated server you have most likely no choice.


    SSH security consideration

    If you're SSH service is directly exposed to the internet, it's strongly recommended to take a look at your current SSH authentication configuration (or what is configured for you). To access your SSH service you can either use password based authentication or SSH public key authentication (or both). Password based authentication can be bruteforced without additional software. Fail2Ban is such additional software that can improve security by (temporary) banning IP addresses with to much failed login attempts. It makes bruteforce attacks nearly impossible. SSH public key authentication uses a public and private key pair for SSH user authentication instead of passwords. It's impossible to bruteforce this authentication method using current standard machinery.

    It's up to you how you want to protect your SSH service. SSH public key authentication is the most secure solution but requires you to carry around your public key while storing it safely somewhere. Password based authentication can also be secure but only if you use Fail2Ban and can memorize a good strong password.

    Getting started with Fail2Ban
    Getting started with SSH public key authentication


    If you have any questions, feel free to ask.
    Last edited by snoopdoge90; 22nd March 2020 at 21:10.

  5. The Following User Says Thank You to snoopdoge90 For This Useful Post:

    kung foo man (3rd July 2019)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •