yazoo321 / mmo_server_with_micronaut

Hobby project to create mmo server using Java Micronaut with JWT Auth, postgres and mongoDB support
73 stars 27 forks source link
inventory inventory-management java micronaut mmo mmorpg mongodb postgres rpg server

MMO Server implementation (work in progress)

Currently working on:

Build locally with docker

you may need to add some entries to your HOSTS file to point services from docker-compose.yml to application.yml The relevant entries are:

127.0.0.1 redis
127.0.0.1 mongo-service
127.0.0.1 kafka-broker

In windows, the hosts file can be found in: C:\Windows\System32\drivers\etc\hosts.file

In Mac, you need to edit /etc/hosts and add the same entries

Documentation within blog:

Each of the posts contains a video overview.

Stats system and level ups

UDP communication, player & motion sync

Websocket communication, player and mob motion sync

Character creation examples:

Logging into the game:

Inventory Implementation

Base components, JWT no longer in use, in favor of using Cognito or alternatives

This project branches from the Micronaut template found here: https://github.com/yazoo321/micronaut_template

To see where components are configured, see mini tutorial on youtube: https://www.youtube.com/watch?v=PF_Bg6CgMts&t=16s

JWT Authentication described here on YouTube tutorial here: https://www.youtube.com/watch?v=acAFcDWuxhI&t=8s

Dependencies

In this project we rely on Docker, you can download it here: https://docs.docker.com/desktop/windows/install/ Docker will be used to spin up the dependencies, including any DBs (postgres, mongodb) and now Kafka + Zookeeper.

Kafka

More in-depth Kafka instructions here: https://unreal-mmo-dev.com/2023/04/17/37-how-to-connect-your-java-micronaut-springboot-with-kafka-sasl/

There was a very useful video covering some details that can be found here: https://www.youtube.com/watch?v=bj5SKXanaAI

Kafka is spun up using 'docker-compose' so check the relevant entries there. the './configs' directory contains the necessary configs for SASL enabled Kafka Do note that you will need to change these for production use.

Some useful kafka CLI commands:

// create topic:
kafka-topics --create --bootstrap-server kafka1:9093 --replication-factor 1 --partitions 1 --topic test
--command-config /etc/kafka/configs/config.properties

// producer example:
kafka-console-producer --broker-list kafka1:9093 --topic test --producer.config /etc/kafka/configs/config.properties

// consumer example:
kafka-console-consumer --bootstrap-server kafka1:9093 --topic test --from-beginning --partition 0
--consumer.config /etc/kafka/configs/config.properties

Micronaut also offers some useful documentation: https://guides.micronaut.io/latest/micronaut-kafka-maven-java.html

Micronaut 2.4.1 Documentation

Feature http-client documentation

Getting started

In order to build the project run: ./gradlew build

In order to remove the docker container and its database, run docker rm -f -v <container_name>

This project is a base template for getting started with micronaut + postgres + jooq + flyway + lombok.

It contains a very simple migration file (resources/db/postgres/V1__create_user_table.sql) to create a base users table and an entry with a user. Modify this based on your requirements.

Sample request to socket

The inventory sample requests can be found in: resources/inventory/inventorySampleRequests

Motion sample requests can be found in: resources/motion/updateMotionRequest