Jump to content

Recommended Posts

Posted (edited)

So I was bored again...

 

L2jRest is a RESTful API for L2j

 

It is created for latest aCis but you should be able to adapt it is you wanna use it for other projects.

 

L2jRest is an open source project licensed under MIT. You can find the source here: https://github.com/Elfocrash/L2jRest

 

Why use it?

  • You can use the data of your server in your website
  • You can create an account control panel with it
  • You can expose data to your community to allow them to make third party apps

 

Technical stuff

  • It is written in Kotlin.
  • It is using the Ktor framework. Ktor is using coroutines to achieve asynchronous request handling. It is very efficient and very fast.
  • It is using Netty as the underlying server.
  • It is written in a CQRS manner with query handlers for get endpoints and command handlers for post, put, patch, delete etc.
  • It is using Koin as the IoC framework.

 

How to setup

  • Download and install Intellij IDEA
  • Git clone the project and open it with Intellij
  • Run the build Gradle task. It is configured to create a fat jar with all the dependencies included
  • Paste the jar in your project, add it in your classpath and add the following line at the bottom of your Gameserver.java: L2jRestApi.INSTANCE.start();
  • Running the gameserver will also run the api. It is running under port 6969

 

How to extend it

  • All you need to do if you wanna add more endpoints is to add a new handler and then add the Get, Post etc annotation depending on what endpoint you want this to be.

 

Current endpoints:

http://localhost:6969/api/players

http://localhost:6969/api/players/{id}

 

A couple of endpoint examples

 

Endpoints: http://localhost:6969/api/players

Response:

{
    players: [
		{
			"id": 268480927,
            "name": "Test",
            "level": 1,
            "isOnline": false,
            "pvpKills": 0,
            "pkKills": 0,
            "isNobless": false
		},
		{
			"id": 268480924,
            "name": "Test2",
            "level": 1,
            "isOnline": true,
            "pvpKills": 0,
            "pkKills": 0,
            "isNobless": false
		}
	]
}

 

Endpoint: http://localhost:6969/api/players/268480927

Response:

{
    "id": 268480927,
    "name": "Test",
    "level": 1,
    "isOnline": false,
    "pvpKills": 0,
    "pkKills": 0,
    "isNobless": false
}

 

Currently it just supports two endpoints and no authentication. I am planning to add more endpoints and ApiKey based auth tomorrow.

 

If you can't be arsed to build the project yourself but you wanna take a look anyway you can download the jar here

 

Edited by Elfocrash
  • Like 3
  • Upvote 2
Posted (edited)

Thank you a lot for that. That's what I was searching. I have one question

 

L2DatabaseFactory.getInstance().connection.use { con ->
                val statement = con.prepareStatement(SqlQueries.GetAllPlayers)
                val resultSet = statement.executeQuery()

                var player: PlayerResponse? = null
                if (resultSet.next())
                {
                    val id = resultSet.getInt("obj_Id")
                    val name = resultSet.getString("char_name")
                    val level = resultSet.getInt("level")
                    val isOnline = resultSet.getInt("online") == 1
                    val pvpKills = resultSet.getInt("pvpkills")
                    val pkKills = resultSet.getInt("pkkills")
                    val isNobless = resultSet.getInt("nobless") == 1
                    player = PlayerResponse(id, name, level, isOnline, pvpKills, pkKills, isNobless)

 

 

Wouldn't be better to take these infos from the player object itself for example?(if player is online) So it would be real time , because database values are not always real time on L2J due to delay of updating. This specific feature may isn't the best example to what I mean actually but propably you got the point.

 

Also practically could we extend this to create token authentication and the ACP(or whatever) to just be  a cool SPA with front end framework(react,vue,etc)? 

Edited by Lioy
Posted (edited)
52 minutes ago, Lioy said:

Thank you a lot for that. That's what I was searching. I have one question

 


L2DatabaseFactory.getInstance().connection.use { con ->
                val statement = con.prepareStatement(SqlQueries.GetAllPlayers)
                val resultSet = statement.executeQuery()

                var player: PlayerResponse? = null
                if (resultSet.next())
                {
                    val id = resultSet.getInt("obj_Id")
                    val name = resultSet.getString("char_name")
                    val level = resultSet.getInt("level")
                    val isOnline = resultSet.getInt("online") == 1
                    val pvpKills = resultSet.getInt("pvpkills")
                    val pkKills = resultSet.getInt("pkkills")
                    val isNobless = resultSet.getInt("nobless") == 1
                    player = PlayerResponse(id, name, level, isOnline, pvpKills, pkKills, isNobless)

 

 

Wouldn't be better to take these infos from the player object itself for example?(if player is online) So it would be real time , because database values are not always real time on L2J due to delay of updating. This specific feature may isn't the best example to what I mean actually but propably you got the point.

 

Also practically could we extend this to create token authentication and the ACP(or whatever) to be just a cool SPA with front end framework(react,vue,etc)? 

The problem is that the offline players are not loaded in memory so the dB call is inevitable. Everything that is loaded in the in memory cache will be served by the cache when possible. If the endpoint was get online players only then yeah it would be coming from the World class.

 

Auth is very simple to add. It’s basically a simple middleware.

 

originally when I started this it was to actually make a new ACP but it’s too much work and I don’t really wanna do front end anymore so I just created the api. If people wanna make their front end that’s fine by me. 

 

EDIT: Oh I now see what you mean, I read it wrong the first time. Yes it would make sense to get that info from the cache if the player is online. I will add that.

Edited by Elfocrash
Posted (edited)

PlayerInfoTable retains some informations (cause player names are needed for stuff like friendlist), you probably can add missing ones, but it means you have to update it in same time otherwise you will refer to wrong values.

 

That whole class probably can be enhanced or used differently (PlayerInfo being maybe part of Player, once player is loaded ? Like loading an id card, which avoid duplicates variables or even caring about refreshing 2 places).

 

If such stuff is edited, that would simplify the developement of a lot of customs.

Edited by Tryskell
Posted
1 minute ago, Tryskell said:

PlayerInfoTable retains some informations (cause player names are needed for stuff like friendlist), you probably can add missing ones, but it means you have to update it in same time otherwise you will refer to wrong values.

 

That whole class probably can be enhanced or used differently (maybe part of Player, once player is loaded ? Like loading an id card, which avoid duplicates variables).

The problem with having multiple points of truth is that you don't have a single one you can fully trust, that's why i trust nothing but the database and the World class. I also don't wanna touch the core at all so if I do any caching it will happen in the API level.

Posted (edited)
3 minutes ago, Elfocrash said:

The problem with having multiple points of truth is that you don't have a single one you can fully trust, that's why i trust nothing but the database and the World class. I also don't wanna touch the core at all so if I do any caching it will happen in the API level.

 

I edited my answer :), and the idea is to only have one point of entry, which would be PlayerInfo linked to a Player, like they are actually linked to an AccessLevel, a Appearance, etc. SO drop inner variables of Player, and use only PlayerInfo to refresh those values.

 

Np.

Edited by Tryskell
Posted

Changed the way handlers are registered. Now they will be scanned automatically during server startup and they will be registered based on their annotation. This means that all you have to do to add a new endpoint is to create a request handler and add the Get, Post etc annotation.

Posted

Added api key based authentication as requested. Requests will only be served when the x-api-key header is set with the configured value.

Posted
On 7/24/2019 at 1:25 AM, Elfocrash said:

Added api key based authentication as requested. Requests will only be served when the x-api-key header is set with the configured value.

 

Hey Elfo , what's the logic on this authentication? If credentials are correct then send the API key to the client? And all authorization is possible via this simple unique API key?

Just asking, because never worked with that kind of auth. (I know JWT for example , maybe I confused things somewhere)

Posted
2 minutes ago, Lioy said:

 

Hey Elfo , what's the logic on this authentication? If credentials are correct then send the API key to the client? And all authorization is possible via this simple unique API key?

Just asking, because never worked with that kind of auth. (I know JWT for example , maybe I confused things somewhere)

It's using ApiKey auth. It's not client facing auth where you get credentials and return a key. You can do that with Basic auth but you have to enable it.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Posts

    • Released new security update for Faceit anti-cheat and Gamers Club. Cheat is available again! We also added a few more slots for 1 month subscription and 6 months.
    • This post originally appeared on zupyak.   If you're diving into MLB The Show 25, you know how essential stubs are for building a powerhouse team. Whether you're aiming to snag elite players, upgrade your roster, or stock up on packs, stubs are the key to success. The good news? You don't need to spend real money to earn them. With a little strategy and effort, you can rake in stubs and dominate the diamond.  Here are the top five strategies to maximize your MLB The Show stub earnings and create the ultimate team without breaking the bank.    1. Earning Stubs with Diamond Quest Diamond Quest is a goldmine for stubs. By completing challenges in this mode, you can earn Diamond cards, which often have high sell values. Once you've earned these cards, sell them in the in-game Marketplace for a quick influx of stubs. Additionally, the packs you earn from Diamond Quest can be opened for more cards to sell or use in collections.   2. Completing Conquest Maps Conquest Maps are another excellent way to rack up stubs. Focus on capturing territories and completing map-specific goals. Many maps offer hidden rewards, including packs and stubs, which can significantly boost your earnings. You don't always need to conquer Strongholds—simply taking over territories can yield great rewards.   3. Flipping Cards in the Marketplace The Marketplace is your playground for flipping cards. Look for cards with a significant gap between their "Buy Now" and "Sell Now" prices. Place a Buy Order slightly above the current "Sell Now" price, then list the card for a "Sell Order" just below the "Buy Now" price. After the 10% Marketplace tax, you'll still make a profit. This strategy works best with high-value cards but requires patience and consistency.     4. Leveraging Player Exchanges Player Exchanges are an underrated method for earning stubs. Purchase cheap Silver cards near their quick-sell value, then exchange them for Gold players. These Gold players can either be used in your lineup or sold for a profit. This method is especially effective early in the game when Gold cards hold higher value.   5. Selling Things You Don't Need Don't let unused items clutter your inventory. Regularly check for duplicate cards, equipment, or other items you don't need. Sell these through the Marketplace to free up space and earn extra stubs. Even Bronze and Silver cards can add up over time, so don't overlook them. With these strategies, you'll be well on your way to building a dream team without spending real money. Let me know if you'd like to dive deeper into any of these methods!   Final Thoughts Building your dream team in MLB The Show 25 doesn't have to cost real money. With these five strategies—earning rewards through Diamond Quest, conquering Conquest Maps, flipping cards in the Marketplace, leveraging Player Exchanges, and selling unused items—you'll be well on your way to amassing stubs and creating a roster that rivals even the best in the game. Remember, consistency is key! Whether you're grinding through challenges or flipping cards daily, every little bit adds up over time. Stick with these methods, and soon enough, you'll have the stubs you need to dominate the diamond. Let us know which strategy works best for you—or if you've discovered any additional tips that deserve a spot on this list! Happy grinding!   
    • I don't see that ur account got unbanned https://maxcheaters.com/profile/80641-∽ave∽/  
    • Looking for gracia final/gracia epilogue server files including source.
    • Got banned for ALLEGED scamm. Unbaned because I never scammed anyone - I either deliver or refund. So You can cry as much as You like, post as much idiotic and chidlish emotes as You like, but I'm not a scammer. So...get a life kid, and fuck off Cuntw0lf. There is a reason You have "0" in Your nickname. You are a zero 😎
  • Topics

×
×
  • Create New...