Jump to content

Recommended Posts

  • Active+ Member
Posted (edited)
 

Download Center

This is the hidden content, please

This is the hidden content, please

  Server Side API

Secure your ports, the zip has basic middleware but you need to wire it up yourself as I'm using libenvpp for configuration instead of the default setup, I also use SPDLOG if you want you can wire your own logger in the API.cpp file.

 Why?

Have you ever wanted to ditch the old API because you don't like TCP? Me too! Now you can do it with this

Requirements

  • CrowCpp/Crow

Installing requirements (Using vcpkg and CMake)

Run command.

vcpkg install crow

Example Output

{
  "channels": {
    "13000": "NORM",
    "13001": "NORM",
    "13002": "NORM",
    "13003": "NORM",
    "13004": "NORM",
    "13005": "NORM",
    "13099": "NORM"
  },
  "shop_count": 0,
  "user_count": 0
}

Changes

Download the zip and paste it on your db/src

db/src/Main.cpp

This is the hidden content, please

db/src/ClientManager.h

This is the hidden content, please

To get proper status on startup you need to start your game cores AFTER the db NEVER BEFORE OR AT THE SAME TIME

Below there's an example for people using the Metin2 on LINUX project

In your docker-compose.yml or compose.yml

Add ports (18080) to your db service as well as the healthcheck, example below:

  db:
    image: ${GAME_IMAGE}
    restart: always
    env_file:
      - .env
    expose:
      - ${DB_PORT}
    ports:
      - "18080:18080"
    command: db
    volumes:
      - ./storage/log/db/:/app/log/
    depends_on:
      database:
        condition: service_healthy
    healthcheck:
      test: "curl --silent --fail http://${API_USERNAME}:${API_PASSWORD}@localhost:18080/status > /dev/null || exit 1"
      interval: 10s
      timeout: 5s
      retries: 5
    networks:
      - metin2

And all your cores should have db with service_healthy for your dependencies, example below

  ch1_first:
    image: ${GAME_IMAGE}
    restart: always
    environment:
      GAME_HOSTNAME: ch1_first
      GAME_CHANNEL: 1
      GAME_MARK_SERVER: true
      GAME_PORT: 13000
      GAME_P2P_PORT: 14000
      GAME_MAP_ALLOW: 1 3 4 5 6 21 23 24 25 26 41 43 44 45 46 91 92 93 107 112 201
    env_file:
      - .env
    expose:
      - 13000
      - 14000
    ports:
      - "13000:13000"
    command: game
    volumes:
      - ./storage/log/ch1/first/:/app/log/
      - ./storage/mark/:/app/mark/
    depends_on:
      db:
        condition: service_healthy
    networks:
      - metin2

 

Middleware Configuration

THIS WILL ONLY PLUG AND PLAY IF YOU'RE USING libenvpp

db/src/Config.cpp

This is the hidden content, please

db/src/Main.cpp

This is the hidden content, please

In your .env add

This is the hidden content, please

Usage

There's also a Laravel 12 compatible service in the downloads with the example usage below

    public function __invoke(Request $request)
    {
        $status = (new ServerApiService)->fetchStatus();

        if (! $status) {
            return 'No data';
        }

        return [
            'channels' => $status->getChannels(),
            'userCount' => $status->getUserCount(),
            'shopCount' => $status->getShopCount(),
            'ch1' => $status->getChannel(13000)->value,
        ];
    }

Credits

@ Gurgarath I basically stole his idea

Edited by soforyou
add: Laravel service
  • Metin2 Dev 26
  • Good 5
  • muscle 1
  • Love 7
Link to comment
https://metin2.dev/topic/34403-server-side-api/
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Don't use any images from : imgur, turkmmop, freakgamers, inforge, hizliresim... Or your content will be deleted without notice...
Use : https://metin2.download/media/add/

Please use https://metin2.download/ when uploading files smaller than 100MB, otherwise the approval will take longer due to manual upload.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.