PDA

View Full Version : [cod2] Running your own libcod server using WSL2 on windows



IzNoGoD
26th April 2021, 17:05
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:



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/~sgtatham/putty/latest.html I personally prefer using a ED25519 key.

My public key looks something like this:



ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIALemzRolc4EjY9F0xp0YpfYgf KLqptc9+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:



mkdir .ssh
chmod 700 .ssh
echo "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIALemzRolc4EjY9F0xp0YpfYgf KLqptc9+XRrWkGphk9 ed25519-key-20210426" >> .ssh/authorized_keys
chmod 600 .ssh/authorized_keys


Now it's time to restart our ssh daemon:



sudo service ssh restart


Furthermore, we need to determine the ip of the vm. Running



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:


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:


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:


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?1719-Latest-cod2-linux-binaries-%281-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:



#!/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:


chmod 700 run.sh
chmod 700 cod2/cod2_lnxded_1_3


And run the actual server:



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

filthy_freak_
27th April 2021, 03:54
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.

kung foo man
27th April 2021, 07:10
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

IzNoGoD
27th April 2021, 07:44
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.

IzNoGoD
27th April 2021, 07:45
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)

kung foo man
27th April 2021, 07:47
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)

IzNoGoD
27th April 2021, 08:36
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.

IzNoGoD
27th April 2021, 10:32
Public network connectivity.

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

Option 2: Bridge mode.



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


sudo ip addr flush dev eth0
sudo dhclient eth0

Might need to be re-run every boot.

Miri
28th April 2021, 16:55
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

IzNoGoD
22nd May 2021, 20:18
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.