Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ✨ Add new branch to work with Docker #256

Draft
wants to merge 49 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
658fb2a
feat: ✨ Add new branch to work with Docker
gmargriff Apr 16, 2024
d9d3a75
fix: 🐛 Missing SQL folder when starting server
gmargriff Apr 17, 2024
2a86353
fix: 🐛 Changing SQL queries due to capital letters conflict
gmargriff Apr 17, 2024
f7dd52c
feat: :art: Add .env file for configuring docker-compose
gmargriff Apr 17, 2024
cfa2971
docs: :memo: Improve documentation on docker and client setup
gmargriff Apr 17, 2024
1f2e059
fix: :bug: Use ENVIRONMENT variable from .env file to run correct ser…
gmargriff Apr 17, 2024
751c0fb
Merge branch 'master' into docker
gmargriff Apr 19, 2024
681cdd0
fix: :zap: Re-enable console commands on Windows systems
gmargriff Apr 19, 2024
840cfb7
revert: :card_file_box: Revert removal of SQL files from master branch
gmargriff Apr 19, 2024
06a6f25
refactor: :recycle: Necessary changes in Merged SQL files to keep SQL…
gmargriff Apr 19, 2024
2bb0a58
fix: :zap: Make sure database started before starting servers
gmargriff Apr 23, 2024
cc5879c
docs: :memo: Improve documentation ordering for branch specifics
gmargriff Apr 23, 2024
68eec32
Merge pull request #1 from gmargriff/docker
gmargriff Apr 29, 2024
c55cd66
Merge pull request #2 from NoCode-NoLife/master
gmargriff May 25, 2024
b724216
Merge pull request #3 from gmargriff/docker
gmargriff May 25, 2024
dc8de12
Merge branch 'NoCode-NoLife:master' into docker
gmargriff Jun 7, 2024
5cedc96
Merge branch 'NoCode-NoLife:master' into master
gmargriff Jun 7, 2024
a7b736b
Merge branch 'NoCode-NoLife:master' into docker
gmargriff Jun 19, 2024
2d3b785
Merge branch 'NoCode-NoLife:master' into master
gmargriff Jun 19, 2024
fbfd852
Merge branch 'NoCode-NoLife:master' into master
gmargriff Jun 21, 2024
47660fe
Merge branch 'NoCode-NoLife:master' into docker
gmargriff Jun 21, 2024
35323dc
Merge branch 'NoCode-NoLife:master' into docker
gmargriff Jul 25, 2024
c9de2e7
Merge branch 'NoCode-NoLife:master' into master
gmargriff Jul 25, 2024
7ffd8b3
Merge branch 'NoCode-NoLife:master' into master
gmargriff Aug 8, 2024
b475db6
Merge branch 'NoCode-NoLife:master' into docker
gmargriff Aug 8, 2024
e45283e
more commands
y4my4my4m Aug 9, 2024
bf27246
Update ChatCommands.Handlers.cs
y4my4my4m Aug 10, 2024
54b0d11
Update ChatCommands.Handlers.cs
y4my4my4m Aug 10, 2024
90b9773
Update commands.conf
y4my4my4m Aug 10, 2024
6b5d9f5
Merge remote-tracking branch 'y4my4m/master' into new-branch
y4my4my4m Aug 12, 2024
bddca91
update
y4my4my4m Aug 13, 2024
13f3487
Merge branch 'master' of github.com:NoCode-NoLife/melia into new-branch
y4my4my4m Aug 13, 2024
875c132
temp fix
y4my4my4m Aug 13, 2024
e93bcfe
git ignore all again
y4my4my4m Aug 13, 2024
b2b25da
Merge pull request #4 from y4my4my4m/master
gmargriff Aug 29, 2024
2a8ff97
Merge branch 'master' into docker
gmargriff Aug 31, 2024
a382399
Merge branch 'master' into docker
gmargriff Aug 31, 2024
81d7965
fix mergeability
gmargriff Aug 31, 2024
8a5a120
Merge branch 'NoCode-NoLife:master' into docker
gmargriff Sep 2, 2024
6e298ca
Merge branch 'NoCode-NoLife:master' into docker
gmargriff Sep 3, 2024
ce4fc82
Merge branch 'NoCode-NoLife:master' into docker
gmargriff Sep 14, 2024
b5c0c37
Merge branch 'NoCode-NoLife:master' into docker
gmargriff Sep 18, 2024
50edd51
Merge branch 'NoCode-NoLife:master' into docker
gmargriff Sep 19, 2024
a683071
Merge branch 'NoCode-NoLife:master' into docker
gmargriff Sep 21, 2024
eef7545
Merge branch 'NoCode-NoLife:master' into docker
gmargriff Sep 22, 2024
29a7cd1
Merge branch 'NoCode-NoLife:master' into docker
gmargriff Sep 23, 2024
a196a76
Merge branch 'NoCode-NoLife:master' into docker
gmargriff Sep 24, 2024
43b9145
Merge branch 'NoCode-NoLife:master' into docker
gmargriff Sep 28, 2024
4c66caa
Merge branch 'NoCode-NoLife:master' into docker
gmargriff Oct 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# ENVIRONMENT determines the folder where we'll look for binaries.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it would be beneficial to include a brief explanation of what this file is, for anyone who might look inside without knowing about Docker.

# If you're using Release, change the build command to: docker compose run --rm melia-server dotnet publish
# Release performance tends to have better performance, Debug will have more info for development.

ENVIRONMENT="Debug" # Options: Release | Debug

# Database password
MYSQL_ROOT_PASSWORD="123456" # Use a strong password, change in ./user/conf/database.conf too

# Automatically restart server. If using on-failure, sets amount of retries
SERVER_RESTART="unless-stopped" # Options: no | unless-stopped | always | on-failure:5
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
/log/
/logs/
/cache/

/.mysql/
/user/**
/.env

!/user/conf/database-example.conf
!/user/conf/database-example-for-docker.conf
!/user/db/items-example.txt
!/user/scripts/scripts_custom-example.txt
!/user/scripts/scripts_content-example.txt
Expand Down
140 changes: 115 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,6 @@ with any services provided by game developers or publishers, and we don't
endorse such actions. We're here to learn and create, not to steal or
destroy.

Client
-----------------------------------------------------------------------------

Melia does not have a client of its own at this time. Instead, it's designed
to be network compatible with the latest client of the international
version of ToS, which is freely available on Steam.

State of Development
-----------------------------------------------------------------------------

Expand All @@ -29,6 +22,7 @@ of the typical features you would expect from an online RPG, but
there's still a way to go before we'd call it truly playable.

Specifically, some of the major features that are working are as follows:

- Characters (creation, deletion, etc.)
- Inventory (managing items, equipping, etc.)
- Chat
Expand All @@ -41,7 +35,116 @@ Specifically, some of the major features that are working are as follows:
- Monster spawns
- Quests

Requirements
Installation with Docker
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer you revert the changes to the readme, which is supposed to be both concise and general purpose. Long explanations about the setup are better suited for the docs folder.

-----------------------------------------------------------------------------

This branch aims to make Melia easier to setup and run in any environment.
To achieve this, we're making a few changes do add the capability of building
and running Melia on Linux, as well as building and running the server in a
few Docker containers.

For this to work, you will need [Docker](https://docs.docker.com/) installed
on your system. Recent versions of Docker comes with [Docker Compose](https://docs.docker.com/compose/)
pre-installed, so you don't have to worry about it.

After cloning or downloading this repository, rename file `.env.example` to
`.env` and change configuration as needed. Then, navigate to the project folder
(where you'll find `docker-compose.yml` ) and run:

```bash
docker compose build
```

This will download the necessary Docker Images for our project to run and
build a new image with `./Servers/Dockerfile`, where our server dependencies
are listed.

Now, you can run:

```bash
docker compose run --rm melia-server dotnet build
```

This will create our server binaries, making it ready to start with our next
command:

```bash
docker compose up -d
```

Wait for a few seconds for everything to initialize. Then, you can go to your
browser and access [http://127.0.0.1/toslive/patch/serverlist.xml] to check
if server is up and running.

You can restart server if anything goes wrong using:

```bash
docker compose restart
```

If you change anything on source code, you need to run
`docker compose run --rm melia-server dotnet build` again and restart your
server with `docker compose restart`

Database with Docker
-----------------------------------------------------------------------------

With the Docker containers, we've added a PHPMyAdmin container, which can be
accessed via [http://127.0.0.1:8080]. Default user is `root` and password
is `123456` (You can change password on `.env`, but remember to change on
`user/conf/database.conf` as well).

Client
-----------------------------------------------------------------------------

Melia does not have a client of its own at this time. Instead, it's designed
to be network compatible with the latest client of the international
version of ToS, which is freely available on Steam.

After downloading, open your client folder (Steam > Right-Click on Game >
Manage > Browse Local Files). Then, open `release/client.xml` with a text
editor.

Change the line which starts with `<GameOption ServerList [...]` to this:

```xml
<GameOption ServerListURL="http://127.0.0.1/toslive/patch/serverlist.xml" StaticConfigURL="http://127.0.0.1/toslive/patch/" NewAccountURL="http://127.0.0.1/" PaymentURL="http://127.0.0.1/" LoadingImgURL="http://127.0.0.1/toslive/patch/loadingimg/" LoadingImgCount="10"/>
```

Note: If your server is not on the same machine you're playing, change
`127.0.0.1` to your Server's LAN / WAN IP.

Now you can open your game and play.

If you're using Docker, you can't use server's console to create your
account, so, when logging in for the first time, use `new__` as a prefix
to your username.

Example:

```bash
Username: new__myaccount
Password: mypassword
```

This will create an account with username `myaccount` and password
`mypassword`. You can check the database to make sure everything is okay,
but you'll already be connected and playing. Next time, just login with
your username without the `new__` prefix.

Installation from scratch
-----------------------------------------------------------------------------

- Compile Melia
- Run `sql/main.sql` to setup the database
- Copy `system/conf/database.conf` to `user/conf/`,
adjust the necessary values and remove the rest.

Afterwards, you should be able to start Melia via the provided scripts or
directly from the bin directories. If not, or if you need a more detailed
guide, head over to our forum, the chat, or the wiki.

Requirements to build from scratch
-----------------------------------------------------------------------------

Melia is being developed in C# (.NET 8+) and uses a MySQL database for
Expand All @@ -57,18 +160,6 @@ macOS, you will need to install the SDK as well.
For more detailed instructions, please wait patiently while we give
our documentation a much-needed overhaul. It's only a matter of time.

Installation
-----------------------------------------------------------------------------

* Compile Melia
* Run `sql/main.sql` to setup the database
* Copy `system/conf/database.conf` to `user/conf/`,
adjust the necessary values and remove the rest.

Afterwards, you should be able to start Melia via the provided scripts or
directly from the bin directories. If not, or if you need a more detailed
guide, head over to our forum, the chat, or the wiki.

Contribution
-----------------------------------------------------------------------------

Expand All @@ -77,8 +168,7 @@ Check the file CONTRIBUTING.md for instructions on how you may contribute.
Links
-----------------------------------------------------------------------------

* GitHub: https://github.com/NoCode-NoLife/melia
* Wiki: https://github.com/NoCode-NoLife/melia/wiki
* Forum: https://nocodenolife.org/forum/65-melia/
* Chat: https://discord.gg/5sszEgw

- GitHub: https://github.com/NoCode-NoLife/melia
- Wiki: https://github.com/NoCode-NoLife/melia/wiki
- Forum: https://nocodenolife.org/forum/65-melia/
- Chat: https://discord.gg/5sszEgw
10 changes: 10 additions & 0 deletions Servers/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM ubuntu:22.04
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the name of this folder could be chosen better, as "Servers" has a rather general purpose ring to it, that seems misleading, seeing how it's only used for Docker.

ARG DEBIAN_FRONTEND=noninteractive

WORKDIR /

RUN apt update -y && apt upgrade -y && apt install -y dotnet-sdk-8.0 aspnetcore-runtime-8.0 git php libapache2-mod-php php-cgi php-mysql vim

WORKDIR /melia

CMD ["./start", "Debug", "BarracksServer"]
65 changes: 65 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: "melia"
services:
melia-database:
container_name: melia-database
image: mysql:8.3
networks:
- melia-network
ports:
- 3306:3306
environment:
- MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
volumes:
- ./sql:/docker-entrypoint-initdb.d
- ./.mysql/:/var/lib/mysql
restart: ${SERVER_RESTART}
env_file:
- ./.env
healthcheck:
test: "/usr/bin/mysql --user=root --password=${MYSQL_ROOT_PASSWORD} --execute \"SHOW DATABASES;\""
interval: 5s
timeout: 10s
retries: 40

melia-server:
container_name: melia-server
command: "./start ${ENVIRONMENT}"
# command: "tail -f /dev/null"
build: "./Servers"
networks:
- melia-network
volumes:
- ./:/melia
depends_on:
melia-database:
condition: service_healthy
ports:
- "2000:2000"
- "6001:6001"
- "7001:7001"
- "7002:7002"
- "80:80"
restart: ${SERVER_RESTART}
env_file:
- ./.env
phpmyadmin:
container_name: melia-dbadmin
networks:
- melia-network
image: phpmyadmin
ports:
- 8080:80
restart: ${SERVER_RESTART}
environment:
- PMA_HOST=melia-database
- PMA_USER=root
- PMA_PASSWORD=${MYSQL_ROOT_PASSWORD}
- UPLOAD_LIMIT=300M
profiles: []
env_file:
- ./.env
depends_on:
melia-database:
condition: service_healthy
networks:
melia-network:
21 changes: 10 additions & 11 deletions sql/updates/update_2024-08-11_1.sql
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
CREATE TABLE `character_etc_properties` (
`propertyId` bigint(20) NOT NULL,
CREATE TABLE IF NOT EXISTS `character_etc_properties` (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you tell me what this change is about? I feel like we'd want this to fail if the table already exists, because that's an indicator for something not being right.

`propertyId` bigint(20) NOT NULL AUTO_INCREMENT,
`characterId` bigint(20) NOT NULL,
`name` varchar(64) NOT NULL,
`type` varchar(1) NOT NULL,
`value` varchar(255) NOT NULL
`value` varchar(255) NOT NULL,
PRIMARY KEY (`propertyId`),
KEY `characterId` (`characterId`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;

ALTER TABLE `character_etc_properties`
ADD PRIMARY KEY (`propertyId`),
ADD KEY `characterId` (`characterId`);

ALTER TABLE `character_etc_properties`
MODIFY `propertyId` bigint(20) NOT NULL AUTO_INCREMENT;
-- Drop the foreign key if it exists
-- ALTER TABLE `character_etc_properties`
-- DROP FOREIGN KEY `character_etc_properties_ibfk_1`;

-- Add the foreign key constraint again
ALTER TABLE `character_etc_properties`
ADD CONSTRAINT `character_etc_properties_ibfk_1` FOREIGN KEY (`characterId`) REFERENCES `characters` (`characterId`) ON DELETE CASCADE ON UPDATE CASCADE,
ADD CONSTRAINT `character_etc_properties_ibfk_2` FOREIGN KEY (`characterId`) REFERENCES `characters` (`characterId`) ON DELETE CASCADE ON UPDATE CASCADE;
ADD CONSTRAINT `character_etc_properties_ibfk_1` FOREIGN KEY (`characterId`) REFERENCES `characters` (`characterId`) ON DELETE CASCADE ON UPDATE CASCADE;
22 changes: 16 additions & 6 deletions sql/updates/update_2024-08-11_2.sql
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
CREATE TABLE `storage_team` (
CREATE TABLE IF NOT EXISTS `storage_team` (
`accountId` bigint(20) NOT NULL,
`itemId` bigint(20) NOT NULL,
`position` int(11) NOT NULL
`position` int(11) NOT NULL,
PRIMARY KEY (`accountId`, `itemId`),
KEY `itemId` (`itemId`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;

-- Drop the first foreign key if it exists
-- ALTER TABLE `storage_team`
-- DROP FOREIGN KEY `storage_team_ibfk_1`;

-- Drop the second foreign key if it exists
-- ALTER TABLE `storage_team`
-- DROP FOREIGN KEY `storage_team_ibfk_2`;

-- Add the first foreign key constraint
ALTER TABLE `storage_team`
ADD PRIMARY KEY (`accountId`,`itemId`),
ADD KEY `itemId` (`itemId`);
ADD CONSTRAINT `storage_team_ibfk_1` FOREIGN KEY (`accountId`) REFERENCES `accounts` (`accountId`) ON DELETE CASCADE ON UPDATE CASCADE;

-- Add the second foreign key constraint
ALTER TABLE `storage_team`
ADD CONSTRAINT `storage_team_ibfk_1` FOREIGN KEY (`accountId`) REFERENCES `accounts` (`accountId`) ON DELETE CASCADE ON UPDATE CASCADE,
ADD CONSTRAINT `storage_team_ibfk_2` FOREIGN KEY (`itemId`) REFERENCES `items` (`itemUniqueId`) ON DELETE CASCADE ON UPDATE CASCADE;
ADD CONSTRAINT `storage_team_ibfk_2` FOREIGN KEY (`itemId`) REFERENCES `items` (`itemUniqueId`) ON DELETE CASCADE ON UPDATE CASCADE;
6 changes: 3 additions & 3 deletions src/BarracksServer/BarracksServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,9 @@ private void Communicator_OnRequestReceived(string sender, RequestMessage reques
var message = new ResServerListMessage(servers);
var responseMessage = new ResponseMessage(requestMessage.Id, message);

this.Communicator.Send(sender, responseMessage);
break;
}
this.Communicator.Send(sender, responseMessage);
break;
}
}
}

Expand Down
11 changes: 8 additions & 3 deletions src/Shared/Configuration/Files/Web.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.IO;
using System;
using System.IO;
using Yggdrasil.Configuration;

namespace Melia.Shared.Configuration.Files
Expand All @@ -17,8 +18,12 @@ public class WebConfFile : ConfFile
public void Load(string filePath)
{
this.Include(filePath);

this.PhpCgiFilePath = this.GetString("php_cgi_bin", Path.Combine("user", "tools", "php", "php-cgi.exe"));
if (Environment.OSVersion.Platform == PlatformID.Win32NT)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't really change anything, because the configuration value is read from the conf file regardless of the operating system. The only way you will get the usr bin path from this is if the conf option is missing.

{
this.PhpCgiFilePath = this.GetString("php_cgi_bin", Path.Combine("user", "tools", "php", "php-cgi.exe"));
} else {
this.PhpCgiFilePath = this.GetString("php_cgi_bin", "/usr/bin/php-cgi");
}
}
}
}
Loading