Jump to content

L2JPHP - "One library to rule them all"


Grundor

Recommended Posts

Hello Everyone,

 

 

I bring you not a PHP-based L2 server, not a full-fledged website, but a library that will revolutionize L2J web development.

 

Introduction


Many parallel projects have been developed over the years, and L2J today is divided into several distributions, each with a different database, whether by table name, fields, etc. A standard was never established for all banks to respect a specific nomenclature, sometimes they were developed by amateur developers, who despite being skilled, never studied and do not know good practices or follow some type of standard.   

This makes it difficult to develop compatible applications with so many revisions (L2jserver, l2jbrasil, dream, sunrise, frozen, etc.) and different game versions (Interlude, Gracia, Classic, etc.). 

The big challenge of all is,  How to create web applications, in php, that are compatible with the largest number of revisions possible?

 The answer to that is Data Harmonization.

 

 

Quote

Data Harmonization is the concept that you can create applications that interpret several different data sources and that act with a single input and output pattern.

 

 

 

And the best way to do that is to work on the Model layer, which passes to controllers a single known data format. It sounds complex, but isn't it that much ?

 

 

How it works?

 

First we have to define a set of constants:

 

<?php

//PROJECT DEFAULTS
define('L2JBR_DIST', "L2JSERVER"); //Wich distribuition?
define('L2JBR_L2VERSION', "Interlude"); //Game Version 

define('L2JBR_SALT', 'change_it_for_something_else'); //This constant will be used to encription and security in the future.



//DATABASE
define('L2JBR_DB_DRIVER', "mysql");
define('L2JBR_DB_HOST', "localhost");
define('L2JBR_DB_PORT', 3306);
define('L2JBR_DB_NAME', "l2jdb");
define('L2JBR_DB_USER', "root");
define('L2JBR_DB_PWD', "");

 

When configuring the application, it will be necessary to tell which version the Models will be used for. The standard model is the L2JSERVER, as it is the base project for 99% of the other projects, and Interlude, which is the most widespread version, which already increases the initial compatibility of the library.

But there you go, you must be asking "okay, but how does it all happen?", See the example below with the Model "Characters" responsible for manipulating a character's data:

 

<?php

$CharactersModel = \L2jBrasil\L2JPHP\ModelFactory::build('Players/Characters');

$CharactersModel->get('ID'); //Get Character by ID
$CharactersModel->update('ID', ["name"=> "Grundor"]); //Update character name given ID
$CharactersModel->ban('ID'); //Apply ban routines for an character
$CharactersModel->all(['name','level'],false,10,'level'); //Get Top 10 characters

//Advanced Example:
$CharactersModel->select(['character.id','account.name'])
    ->join(\L2jBrasil\L2JPHP\ModelFactory::build('Players/Account'))
    ->orderby('level')
    ->limit(100)
    ->query()
    ->FetchAll();

 

The secret is in this "ModelFactory" class. The build method returns the requested model instance, in this case, in the Player/Character namespace. But how does he do it?

It dynamically assembles the class instance based on the configuration of the DIST and L2JBR_L2VERSION and will throw an exception if it does not exist, 

So in the example above the call to "Build" would do the same thing as:

 

<?php

$CharactersModel = \L2jBrasil\L2JPHP\Models\Dist\Interlude\L2JSERVER\Players\Characters();
//...

 

 

Which can be used directly too, without problems, since they are all independent and instantiable classes.
 

Every model will have CRUD ( Create, Read, Update and Delete  in English)   and "listing (all)" operations. In addition, models implement interfaces, these interfaces will ensure that every model, for example "Characters", of all versions, has the same more standard methods (ban, move, changeProfession, changeLevel, cleanPK, etc.), in addition it will be dynamically allowed.

 

In order to maintain compatibility, a class is being developed that will set up the "where" conditions (second parameter of the all method (listing)) so that the conversion of column names is also applied dynamically by a "field map" that mantain compatibility among all diferent databases, so nomore problens with diferent l2j or l2off distribuitions. 

 

Take a look at Characters class

 

 

<?php
/**
 * Copyright (C) 2018 L2JBrasil
 * @autor Leonan Carvalho
 * @license MIT
 */

namespace L2jBrasil\L2JPHP\Models\Dist\Interlude\L2JSERVER\Players;


use L2jBrasil\L2JPHP\Models\AbstractBaseModel;

class Characters extends AbstractBaseModel implements \L2jBrasil\L2JPHP\Models\Interfaces\Players\Characters
{
    protected $_table = 'characters';
    protected $_primary = 'charId';
    protected $_tableMap = [
        "name" => "charName",
        "id" => "charId"
    ];

    public function ban($id)
    {
        // TODO: Implement ban() method.
    }

    public function getOnline()
    {
        $onlineCol = $this->translate('online');
        $where = "{$onlineCol}  = 1";
        return $this->count($where);
    }
}

 

 

 

 

 

 

How can you help?

 

There are several revisions, all of them will need and can be implemented,

  • you can write models compatible with the revisions so that it can be used to expand the compatibility of the applications developed using this framework.
  • You may help bulding websites or tools using these library, tools, painels and more web (php) based applications using this library, to expand its coverage.

 

 

 

 

Technical information

 

Licence: MIT

PHP version supported: 7.0+

Installation method:  composer

Namespace standard: "Autoloading Standard" ( PSR-0 ) (migrating to new PSR-4 since deprecation of PSR-0)

Status: Work in Progress

Repository and Versioning: GIT

Repository link:   https://github.com/L2jBrasil/L2JPHP

 

 

Edited by Grundor
  • Like 1
  • Haha 1
Link to comment
Share on other sites

  • 3 weeks later...
  • 1 month later...
On 10/1/2020 at 12:33 PM, iTopZ said:

sql injection? repeated post requests work or 'fixed'

All transactions are made by PDO, naturally sql-injection proof for most of cases.

 

Is nice to review all code, double-checks is never enougth.

 

https://stackoverflow.com/questions/134099/are-pdo-prepared-statements-sufficient-to-prevent-sql-injection

Link to comment
Share on other sites

12 hours ago, iTopZ said:

 

SQL injection protection in most of case are implemented on input layer validation, for example:

 

<?php
$login = "a test or '1='1;";
$result = preg_replace('/[^[:alpha:]_]/', '',$login);
echo $result;

 

The L2JPHP handles the DataLayer its not intent to be a Controller, but some logics can be implemented.

 

The protection on L2JPHP is prepearing every transaction in a single statement, the data is sent in a single transaction, not two transaction, I prefer this way.

 

https://github.com/L2jBrasil/L2JPHP/blob/master/src/L2jBrasil/L2JPHP/Models/AbstractSQL.php#L108

 

If you try to send something like this will trigger an exception:

 

<?php


$dataInput = "grundor';Select * From accounts;"

$sql = "INSERT INTO accounts(login,pwd) VALUES('{$dataInput}','{$pwd}')";

 

 

 

Link to comment
Share on other sites

On 11/7/2020 at 9:16 AM, xdem said:

oh no, please no

?

On 11/7/2020 at 11:49 AM, iTopZ said:

to late.

 

It's a open-source project, feel free to make your contribuition to improve its security.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

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

    • just a few things normally the 50/50 means first 50 is collateral in case you decide to go back in your agreement, for "closing" the job, using his time etc... (meaning non-refundable)   the fact that you had to pay for this extra work any amount of money is a joke..   the poor communication from ave side is known nothing new here i guess you knew that already, and no i dont mean his classic behaviour, a professional discusses the timeframes.   there are many (even free) alternatives for updaters and is cheaper to hire somebody to slap your logo in a background..   Note: the video and the discussion made my day both dont know how client works while working on it (for metaman i get it he pays for the service he dont know how it works)   but ave was funny as fuck "i am not client dev either" 
    • You should be thankfull that he even gave u back 100, just because u cant wait, u expect full refund while that guy already almost finished, i think ave is right, i worked with him, no issues ofc delay but thats life 😁  
    • *¶¶¶+2349158681268¶¶¶ Welcome to the home of wealth and fame.*        Many have seek for wealth and it’s quiet a thing of pity +2349158681268 that some do so in wrong places which made it doubtful of the true source and it is at this juncture that i approach you with the right source of wealth which you have really seek for. ZERUZANDAH BROTHERHOOD OCCULT is an association of those that has been blessed by Lord Lucifer zeruzandah the great and have decided to educate the masses on the possible ways of acquiring the wealth, power,protection fame and every other thing you could think of without human sacrifice. Gone are the days when human blood are required for sacrifice here at zeruzandah Brotherhood, human blood sacrifice has been abolished because the money you are seeking for should be used to help and sponsor your loved ones but you have to have it at the back of your mind that there is a very great sacrifice which you must pay to pierce the heart of the spiritual world so that you can be blessed here on human Earth and that sacrifice will be according to what zeruzandah wants you to do which the Grandmaster of this temple will tell you when you’ve been in contact with him. Here at zeruzandah Brotherhood we only demand some sacrificial items and some special animal blood for sacrifice in order to please the Lord Lucifer to bless you here on Earth. If anyone from anywhere tells you that we accept anything money from you in order for you to be initiated into this Brotherhood, inform the TEMPLE GRANDMASTER +2349158681268 zeruzandah Brotherhood do not accept any money from you except you are the one to fund your sacrificial items. Contact the temple Grandmaster at +2349158681268   Spiritual grandmaster of ZERUZANDAH BROTHERHOOD +2349158681268   I WANT TO JOIN SECRET OCCULT FOR MONEY RITUALS IN NIGERIA OR GHANA TO BE RICH AND TO MAKE MONEY, WITH NO HUMAN SACRIFICE OR BLOODSHED CALL +2349158681268 FOR YOUR BUSINESS SUCCESS TO WIN ELECTIONS TO BE FAMOUS AND POWERFUL,   The ZERUZANDAH Brotherhood is a spiritual fraternal society whose aims are the cultivation of Inner Power through the study and practice of esoteric arts for the improvement of body, mind and spirit.   It unites its members in brotherhood and in the quest for wisdom, successful living and finding one’s purpose in life. It has no secret agenda .While it is a deeply spiritual organization, it promote a particular religion or belief.   The Brotherhood transmits an esoteric tradition spanning thousands of years, with a universal vision born in the East and embracing the best of the West in the quest to return to the ancient and original Tao or Source of all wisdom.   WELCOME TO ZERUZANDAH BROTHERHOOD,   The Club of the Rich and Famous; is the world oldest and largest fraternity made up of 3 Millions Members. We are one Family under one father who is the Supreme Being. In ZERUZANDAH OCCULT Brotherhood we believe that we were born in paradise and no member should struggle in this world. Hence all our new members are given Money, Wealth,Fame , Power ETC.   Fear and anxiety has drawn so many people back to unfulfilled dreams and make their quest for wealth and power shambled, it is thing of fact that money ritual Occult is not and can never be a sin because Occult is still a religion despite what ever others are thinking and zeruzandah Brotherhood is here to give life to that dead hope of acquiring your desired wealth,fame and power without human sacrifice. Contact the Spiritual Grandmaster of ZERUZANDAH Brotherhood now at +2349158681268   The wealth of this life goes to those who deserve and desire it by their decision of breaking the wicked chain of poverty. It is actually a thing of fact that poverty is real and it’s not your fault that it exists but however will be your fault and greatest mistake if you allow poverty to exist in your life because of fear. Only the brave makes the move to liberate himself from humiliating nature of poverty…   +2349158681268   You can be rich, wealthy, famous etc without human blood@ZERUZANDAH BROTHERHOOD contact the Spiritual Grandmaster now +2349158681268   The desire to remove the garment of poverty rest on your shoulder and I will advise you do so now by being an initiated member of zeruzandah Brotherhood.   For enquires, contact the Spiritual Grandmaster now@ +2349158681268   The men of the world can only see within the limit of the eye and the things of the spirit are meant for the spirit to see. You can never be that wealthy,rich and famous without controlling the Spiritual wealth and fame that Lucifer the Great Spiritual father offers to those who are humble to him. You have been admiring the wealthy people around you and wish to be so wealthy or more than they do but you are yet to discover the Secret of WEALTH. There so many things known by the rich and the wealthy which the poor don’t know and don’t want to know because of their unnecessary fear. The secret to what you seek is to join a secret occult society.   Call now for enquiries +2349158681268.
    • *¶¶¶+2349158681268¶¶¶ Welcome to the home of wealth and fame.*        Many have seek for wealth and it’s quiet a thing of pity +2349158681268 that some do so in wrong places which made it doubtful of the true source and it is at this juncture that i approach you with the right source of wealth which you have really seek for. ZERUZANDAH BROTHERHOOD OCCULT is an association of those that has been blessed by Lord Lucifer zeruzandah the great and have decided to educate the masses on the possible ways of acquiring the wealth, power,protection fame and every other thing you could think of without human sacrifice. Gone are the days when human blood are required for sacrifice here at zeruzandah Brotherhood, human blood sacrifice has been abolished because the money you are seeking for should be used to help and sponsor your loved ones but you have to have it at the back of your mind that there is a very great sacrifice which you must pay to pierce the heart of the spiritual world so that you can be blessed here on human Earth and that sacrifice will be according to what zeruzandah wants you to do which the Grandmaster of this temple will tell you when you’ve been in contact with him. Here at zeruzandah Brotherhood we only demand some sacrificial items and some special animal blood for sacrifice in order to please the Lord Lucifer to bless you here on Earth. If anyone from anywhere tells you that we accept anything money from you in order for you to be initiated into this Brotherhood, inform the TEMPLE GRANDMASTER +2349158681268 zeruzandah Brotherhood do not accept any money from you except you are the one to fund your sacrificial items. Contact the temple Grandmaster at +2349158681268   Spiritual grandmaster of ZERUZANDAH BROTHERHOOD +2349158681268   I WANT TO JOIN SECRET OCCULT FOR MONEY RITUALS IN NIGERIA OR GHANA TO BE RICH AND TO MAKE MONEY, WITH NO HUMAN SACRIFICE OR BLOODSHED CALL +2349158681268 FOR YOUR BUSINESS SUCCESS TO WIN ELECTIONS TO BE FAMOUS AND POWERFUL,   The ZERUZANDAH Brotherhood is a spiritual fraternal society whose aims are the cultivation of Inner Power through the study and practice of esoteric arts for the improvement of body, mind and spirit.   It unites its members in brotherhood and in the quest for wisdom, successful living and finding one’s purpose in life. It has no secret agenda .While it is a deeply spiritual organization, it promote a particular religion or belief.   The Brotherhood transmits an esoteric tradition spanning thousands of years, with a universal vision born in the East and embracing the best of the West in the quest to return to the ancient and original Tao or Source of all wisdom.   WELCOME TO ZERUZANDAH BROTHERHOOD,   The Club of the Rich and Famous; is the world oldest and largest fraternity made up of 3 Millions Members. We are one Family under one father who is the Supreme Being. In ZERUZANDAH OCCULT Brotherhood we believe that we were born in paradise and no member should struggle in this world. Hence all our new members are given Money, Wealth,Fame , Power ETC.   Fear and anxiety has drawn so many people back to unfulfilled dreams and make their quest for wealth and power shambled, it is thing of fact that money ritual Occult is not and can never be a sin because Occult is still a religion despite what ever others are thinking and zeruzandah Brotherhood is here to give life to that dead hope of acquiring your desired wealth,fame and power without human sacrifice. Contact the Spiritual Grandmaster of ZERUZANDAH Brotherhood now at +2349158681268   The wealth of this life goes to those who deserve and desire it by their decision of breaking the wicked chain of poverty. It is actually a thing of fact that poverty is real and it’s not your fault that it exists but however will be your fault and greatest mistake if you allow poverty to exist in your life because of fear. Only the brave makes the move to liberate himself from humiliating nature of poverty…   +2349158681268   You can be rich, wealthy, famous etc without human blood@ZERUZANDAH BROTHERHOOD contact the Spiritual Grandmaster now +2349158681268   The desire to remove the garment of poverty rest on your shoulder and I will advise you do so now by being an initiated member of zeruzandah Brotherhood.   For enquires, contact the Spiritual Grandmaster now@ +2349158681268   The men of the world can only see within the limit of the eye and the things of the spirit are meant for the spirit to see. You can never be that wealthy,rich and famous without controlling the Spiritual wealth and fame that Lucifer the Great Spiritual father offers to those who are humble to him. You have been admiring the wealthy people around you and wish to be so wealthy or more than they do but you are yet to discover the Secret of WEALTH. There so many things known by the rich and the wealthy which the poor don’t know and don’t want to know because of their unnecessary fear. The secret to what you seek is to join a secret occult society.   Call now for enquiries +2349158681268.
  • Topics

×
×
  • Create New...