Results 1 to 10 of 10

Thread: [cod2] Running your own libcod server using WSL2 on windows

  1. #1
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,718
    Thanks
    17
    Thanked 1,068 Times in 674 Posts

    [cod2] Running your own libcod server using WSL2 on windows

    Hello,

    This is a tutorial on how to run a libcod-enabled cod2 server on WSL2, on top of windows 10. This is a very quick and dirty tutorial.

    This tutorial assumes you have a working wsl2 install: https://www.sitepoint.com/wsl2/ up to and including the part where you set wsl --set-default-version 2

    Now, download and install ubuntu 20.04 from the windows store. This will present you with a screen asking you to enter a username. I'm using "cod2user" as my username.

    After setting a password, you get logged in to the WSL2 ubuntu 20.04 terminal.

    From here, we are running a few commands:

    Code:
    sudo apt update
    sudo apt dist-upgrade
    sudo apt install ssh
    Now we need to add our public key to the VM. Generate one using puttygen, which you can find after installing putty from https://www.chiark.greenend.org.uk/~...ty/latest.html I personally prefer using a ED25519 key.

    My public key looks something like this:

    Code:
    ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIALemzRolc4EjY9F0xp0YpfYgfKLqptc9+XRrWkGphk9 ed25519-key-20210426
    My private key is private, and I saved it using "save private key". I am not using a passphrase to protect it.

    I'm now creating the files required for the ssh key to be associated with my account on the VM:

    Code:
    mkdir .ssh
    chmod 700 .ssh
    echo "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIALemzRolc4EjY9F0xp0YpfYgfKLqptc9+XRrWkGphk9 ed25519-key-20210426" >> .ssh/authorized_keys
    chmod 600 .ssh/authorized_keys
    Now it's time to restart our ssh daemon:

    Code:
    sudo service ssh restart
    Furthermore, we need to determine the ip of the vm. Running

    Code:
    ip addr show eth0 | grep "inet "
    Gives you the ip (and subnet) of the machine. Mine is 172.31.140.5.

    From here, we switch to using winscp: https://winscp.net/eng/download.php

    Create a new site, host name is the ip you found in the previous part. Port number remains 22, user name is the user you created earlier (cod2user for this tutorial). Password remains empty.
    Click advanced, ssh, authentication and brows to your private key file you saved earlier using the "..." behind the "private key file" box.
    Click Ok, save, and connect. On first connect it will warn you about the change in the server's key file, which is fine.

    Now that we are connected through winscp (and by extension have acces to ssh), we can close the VM window.

    Setting up the machine

    Now, install some prerequisites:
    Code:
    sudo dpkg --add-architecture i386
    sudo apt update
    sudo apt install libstdc++5:i386 libmysqlclient-dev:i386 screen g++-multilib git
    Now, lets clone ourselves a git repo of libcod and compile it:
    Code:
    git clone https://github.com/voron00/libcod
    cd libcod
    ./doit.sh cod2_1_3
    cd
    With that out of the way, lets create a folder for our cod2 install to reside:
    Code:
    mkdir -p cod2/main
    Now we switch back to winscp (refresh) and go to cod2/main. Upload all stock iwd files from your local cod2 install to there. This should go rather quick as it's local network.


    Download the cod2_lnxded binary of choice from here: https://killtube.org/showthread.php?...1-0-1-2-1-3%29 My personal choice is the cod2_lnxded_1_3_nodelay_va_loc. After downloading and extracting, rename it to cod2_lnxded_1_3 and upload it to the cod2 folder (next to the main folder).

    Now we need to create the bash script that actually starts the server. Create a file in your home directory named run.sh and copy paste the content below into it:

    Code:
    #!/bin/bash
    
    sv_maxclients="32"
    fs_game=""
    fs_homepath="/home/$USER/cod2"
    cod="/home/$USER/cod2/cod2_lnxded_1_3"
    com_hunkMegs="256"
    config="configfile.cfg"
    cracked="1"
    net_port="28960"
    
    
    args=\
    "+set fs_homepath \"$fs_homepath\" "\
    "+set sv_cracked $cracked "\
    "+set fs_game $fs_game "\
    "+set net_port $net_port "\
    "+set com_hunkMegs $com_hunkMegs "\
    "+set sv_maxclients $sv_maxclients "\
    "+set fs_basepath \"$fs_homepath\" "\
    "+exec $config"
    
    LD_PRELOAD="/home/$USER/libcod/bin/libcod2_1_3.so" $cod $args +set g_gametype tdm +map mp_toujane
    Now, lets grant execute permissions to both the binary and the bash files:
    Code:
    chmod 700 run.sh
    chmod 700 cod2/cod2_lnxded_1_3
    And run the actual server:

    Code:
    ./run.sh
    You can now start your cod2 client and connect to your server using /connect [ip]. In case of this tutorial, that's /connect 172.31.140.5

    And that's all there's to it.
    "Does not work" is an error report for a bug between keyboard and chair.

    All hail Artie Effem

  2. The Following 4 Users Say Thank You to IzNoGoD For This Useful Post:

    agribilos (26th April 2021),kung foo man (27th April 2021),Miri (28th April 2021),pollo (26th April 2021)

  3. #2
    Private First Class
    Join Date
    Oct 2013
    Posts
    219
    Thanks
    56
    Thanked 105 Times in 66 Posts
    Last time i tried using WSL2 on Win10 I could only access the server locally, has that changed?

    If not then i believe remote access is possible if you install WSL2 on server 2019 and configured routing and remote access. I couldn't test this because WSL2 for server 2019 hadn't been released yet but should be now.
    Last edited by filthy_freak_; 27th April 2021 at 04:56.

  4. #3
    Assadministrator kung foo man's Avatar
    Join Date
    Jun 2012
    Location
    trailerpark
    Posts
    2,010
    Thanks
    2,102
    Thanked 1,084 Times in 753 Posts
    Does using WinSCP to upload files to the local server mean that Windows/Linux still doesn't support proper file system sharing on the same machine?

    Last time I tried it I could read files, but writing would mess things up.

    Just asking because developing libcod or CoD mod's on Windows would feel better natively than over WinSCP
    timescale 0.01

  5. #4
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,718
    Thanks
    17
    Thanked 1,068 Times in 674 Posts
    Quote Originally Posted by kung foo man View Post
    Does using WinSCP to upload files to the local server mean that Windows/Linux still doesn't support proper file system sharing on the same machine?

    Last time I tried it I could read files, but writing would mess things up.

    Just asking because developing libcod or CoD mod's on Windows would feel better natively than over WinSCP
    With the vm running, go to \\wsl$\ in your file explorer and browse from there.
    "Does not work" is an error report for a bug between keyboard and chair.

    All hail Artie Effem

  6. #5
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,718
    Thanks
    17
    Thanked 1,068 Times in 674 Posts
    Quote Originally Posted by filthy_freak_ View Post
    Last time i tried using WSL2 on Win10 I could only access the server locally, has that changed?

    If not then i believe remote access is possible if you install WSL2 on server 2019 and configured routing and remote access. I couldn't test this because WSL2 for server 2019 hadn't been released yet but should be now.
    I've got it working such that I can access it from other devices in my local network. One port-forwarding rule in my router to get internet access. It's a pain to do though. (win10 pro)
    "Does not work" is an error report for a bug between keyboard and chair.

    All hail Artie Effem

  7. #6
    Assadministrator kung foo man's Avatar
    Join Date
    Jun 2012
    Location
    trailerpark
    Posts
    2,010
    Thanks
    2,102
    Thanked 1,084 Times in 753 Posts
    Quote Originally Posted by IzNoGoD View Post
    With the vm running, go to \\wsl$\ in your file explorer and browse from there.
    Yea, browsing/reading always worked, but creating/editing files messed things up, that's what I wonder about (for active development, so people don't need to rent a Linux box or deal with VMWare)
    timescale 0.01

  8. #7
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,718
    Thanks
    17
    Thanked 1,068 Times in 674 Posts
    Quote Originally Posted by kung foo man View Post
    Yea, browsing/reading always worked, but creating/editing files messed things up, that's what I wonder about (for active development, so people don't need to rent a Linux box or deal with VMWare)
    I was able to access the files and edit them with the results affecting the vm. Also, creating a new folder worked.
    "Does not work" is an error report for a bug between keyboard and chair.

    All hail Artie Effem

  9. The Following User Says Thank You to IzNoGoD For This Useful Post:

    kung foo man (27th April 2021)

  10. #8
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,718
    Thanks
    17
    Thanked 1,068 Times in 674 Posts
    Public network connectivity.

    Option 1: Just forward the ports from your host to your vm using https://gist.github.com/xmeng1/aae4b...1ee764928f5486

    Option 2: Bridge mode.

    Code:
    Open Hyper-V Manager as administrator
    
    Select your pc, open Virtual Switch Manager
    
    Select WSL
    
    Set to external network
    
    Select the network card the traffic runs through
    
    sudo ip addr flush dev eth0
    sudo dhclient eth0
    
    Now, you gotto get nameservers working:
    
    rm /etc/resolv.conf
    echo "nameserver 8.8.8.8" >> /etc/resolv.conf
    And disable the automatic generation of it: 
    Create a file: /etc/wsl.conf
    Put this in it: 
    
    [network]
    generateResolvConf = false
    
    Now, kill the vm with wsl --shutdown from your host machine, and restart it by running wsl
    The part with
    Code:
    sudo ip addr flush dev eth0
    sudo dhclient eth0
    Might need to be re-run every boot.
    "Does not work" is an error report for a bug between keyboard and chair.

    All hail Artie Effem

  11. The Following User Says Thank You to IzNoGoD For This Useful Post:

    kung foo man (27th April 2021)

  12. #9
    ... connecting
    Join Date
    May 2019
    Posts
    8
    Thanks
    7
    Thanked 4 Times in 4 Posts
    nice job, i got it it working pretty easily
    only problem is i have to copy the file inside wsl, if i use them from /mnt/c/User.. it says .iwd not found when launching run.sh
    for the network stuff
    the poweshell script with the firewall rules didn't work
    but the bridge mode on Hyper-V did
    then you just have to open the port on the router

  13. The Following User Says Thank You to Miri For This Useful Post:

    kung foo man (1st May 2021)

  14. #10
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,718
    Thanks
    17
    Thanked 1,068 Times in 674 Posts
    Small update: If you get the "PuTTy key format too new" error trying to log in with winscp, you have to save your key in the older key file format in puttygen.

    Before saving your private key, go to key->Parameters for saving key files and set PPK Version to 2 instead of 3. Afterwards, save your key as normal.
    "Does not work" is an error report for a bug between keyboard and chair.

    All hail Artie Effem

  15. The Following User Says Thank You to IzNoGoD For This Useful Post:

    agribilos (23rd May 2021)

Posting Permissions

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