L2J Server on CentOS 8

L2J is a complex piece of software engineering, it's divided in three main components, login server, game server and datapack.

Update and Upgrade your OS

CentOS 8 comes with OpenJDK 11.

cat /etc/centos-release
dhclient
dnf update

Install OpenJDK

L2J is built using Java SE, to build you need Java JDK as well.

dnf -y install java-11-openjdk java-11-openjdk-devel
java -version
openjdk version "11.0.7" 2020-04-14 LTS
OpenJDK Runtime Environment 18.9 (build 11.0.7+10-LTS)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.7+10-LTS, mixed mode, sharing)

Install Git

L2J uses Git as version control system on BitBucket, use it to get the latest versions.

dnf install git
git --version
git version 2.18.2
					

Install the Database Server

Get latest version from here.

vi /etc/yum.repos.d/MariaDB.repo
# Paste and Save
# MariaDB 10.4 CentOS repository list - created 2020-06-01 18:42 UTC
# http://downloads.mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.4/centos8-amd64
module_hotfixes=1
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
# Run
dnf install MariaDB-server MariaDB-client
systemctl start mariadb
# Disable annonymous user, external root access, test table, etc. (optional, recommended)
mysql_secure_installation
mariadb -u root -p
MariaDB > CREATE OR REPLACE USER 'l2j'@'%' IDENTIFIED BY 'l2jserver2020';
MariaDB > GRANT ALL PRIVILEGES ON *.* TO 'l2j'@'%' IDENTIFIED BY 'l2jserver2020';
MariaDB > FLUSH PRIVILEGES;

Get the Source Code

Our official repositories are the ones listed bellow.

mkdir -p /opt/l2j/git && cd /opt/l2j/git
git clone https://bitbucket.org/l2jserver/l2j-server-login.git
Cloning into 'l2j-server-login'...
remote: Counting objects: 353, done.
remote: Compressing objects: 100% (285/285), done.
remote: Total 353 (delta 194), reused 63 (delta 26)
Receiving objects: 100% (353/353), 110.40 KiB | 324.00 KiB/s, done.
Resolving deltas: 100% (194/194), done.

git clone https://bitbucket.org/l2jserver/l2j-server-game.git
Cloning into 'l2j-server-game'...
remote: Counting objects: 162315, done.
remote: Compressing objects: 100% (26695/26695), done.
remote: Total 162315 (delta 122790), reused 157270 (delta 117810)
Receiving objects: 100% (162315/162315), 125.97 MiB | 9.93 MiB/s, done.
Resolving deltas: 100% (122790/122790), done.

git clone https://bitbucket.org/l2jserver/l2j-server-datapack.git
Cloning into 'l2j-server-datapack'...
remote: Counting objects: 278648, done.
remote: Compressing objects: 100% (66228/66228), done.
remote: Total 278648 (delta 215765), reused 269687 (delta 207236)
Receiving objects: 100% (278648/278648), 144.49 MiB | 9.63 MiB/s, done.
Resolving deltas: 100% (215765/215765), done.
Checking out files: 100% (24264/24264), done.

Build the Server from Source Code

We use Maven to build the server files.

cd /opt/l2j/git/l2j-server-login && chmod 755 mvnw && ./mvnw install
[INFO] Scanning for projects...
[INFO]
[INFO] -------------------< com.l2jserver:l2j-server-login >-------------------
[INFO] Building L2J Login Server 2.6.1.6
...

cd /opt/l2j/git/l2j-server-game && chmod 755 mvnw && ./mvnw install
[INFO] Scanning for projects...
[INFO]
[INFO] -------------------< com.l2jserver:l2j-server-game >--------------------
[INFO] Building L2J Game Server 2.6.2.0-SNAPSHOT
...

cd /opt/l2j/git/l2j-server-datapack && chmod 755 mvnw && ./mvnw install
[INFO] Scanning for projects...
[INFO]
[INFO] -----------------< com.l2jserver:l2j-server-datapack >------------------
[INFO] Building L2J DataPack 2.6.2.0-SNAPSHOT
...

Deploy the Server

The deployment process at the moment is simply unzipping the built files.

mkdir -p /opt/l2j/server/login
unzip /opt/l2j/git/l2j-server-login/target/l2jlogin-*.zip -d /opt/l2j/server/login
mkdir -p /opt/l2j/server/game
unzip /opt/l2j/git/l2j-server-game/target/l2j-server-game-*.zip -d /opt/l2j/server/game
unzip /opt/l2j/git/l2j-server-datapack/target/l2j-server-datapack-*.zip -d /opt/l2j/server/game

Get L2J CLI and Install the Database

L2J CLI is a tool developed by Zoey76 that allows us to implement automated deployments and initial configurations.

Initial Configuration

You need to give certain permissions for the server to run properly.

cd /opt/l2j/server/login && mkdir -p log
chmod 755 LoginServer_loop.sh
chmod 755 startLoginServer.sh
cd /opt/l2j/server/game && mkdir -p log
chmod 755 GameServer_loop.sh
chmod 755 startGameServer.sh

Create Administrator Account

Use the L2J CLI to create an administrator account, 8 is the maximum account level (master).

cd /opt/l2j/cli
./l2jcli.sh
account create -u Zoey76 -p -a 8
quit

Start the Server

To start the server you need to run two scripts.

cd /opt/l2j/server/login
./startLoginServer.sh
cd /opt/l2j/server/game
./startGameServer.sh

Open Server Ports

If you are not playing from localhost you may need to open the following ports.

firewall-cmd --zone=public --add-port=2106/tcp --permanent
firewall-cmd --zone=public --add-port=7777/tcp --permanent
firewall-cmd --reload

Connect to the Server

In order to connect to the server you have the following options:

HOSTS file

Edit C:\Windows\System32\drivers\etc\hosts and add this line:

127.0.0.1 l2authd.lineage2.com

BAT file

Create a .bat file with the following content:

@start l2.bin IP=127.0.0.1

Custom exe

Here is a C++ Win32 exe example:

#define _WIN32_WINNT _WIN32_WINNT_WINXP
#define NOMINMAX
#include <windows.h>
#include <cstdlib>

// Start L2 as .bin with IP as parameter.
// You can use IP or DNS as IP parameter.
// You could include other parameters.
// You can change the path to the .bin file to avoid including the L2.exe inside the System folder.
// Author: Zoey76
int _stdcall wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nShowCmd) {
	ShellExecute(0, L"open", L"cmd.exe", L"/C start l2.bin IP=127.0.0.1", 0, SW_HIDE);
}

Download compiled version from here.

More information here.