• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

[SQL] Multi World System

Nottinghster

Tibia World RPG Developer
Joined
Oct 24, 2007
Messages
1,570
Solutions
6
Reaction score
437
Location
Brazil - Rio de Janeiro
GitHub
Nottinghster
Let's to the Code:

Credits: 100% Rogier1337 (Drakaro)

In ioaccountsql.cp change:
Code:
Account IOAccountSQL::loadAccount(uint32_t accno)

For:
Code:
Account IOAccountSQL::loadAccount(uint32_t accno)
{
    Account acc;

    Database* mysql = Database::instance();
    DBQuery query;
    DBResult result;

    query << "SELECT id,password FROM accounts WHERE id=" << accno;
    if(mysql->connect() && mysql->storeQuery(query, result)){
        acc.accnumber = result.getDataInt("id");
        acc.password = result.getDataString("password");
#ifndef __ROGIER_MULTIWORLD__
        query << "SELECT name FROM players WHERE account_id=" << accno;
#else //__ROGIER_MULTIWORLD__
        query << "SELECT name,worldid FROM players WHERE account_id=" << accno;
#endif //__ROGIER_MULTIWORLD__
        if(mysql->storeQuery(query, result)){
            for(uint32_t i = 0; i < result.getNumRows(); ++i){
                std::string ss = result.getDataString("name", i);
                
#ifndef __ROGIER_MULTIWORLD__
                acc.charList.push_back(ss.c_str());
#else //__ROGIER_MULTIWORLD__
                int worldid = result.getDataInt("worldid", i);             
                
                query.reset();
                result.clear();
                
                query << "SELECT * FROM worlds WHERE worldid=" << worldid;
                mysql->storeQuery(query, result);
                
                struct CharInfo info;
                info.worldName = result.getDataString("worldname", i);
                info.worldIp   = result.getDataString("worldip", i);
                info.worldPort = result.getDataInt("worldport", i);

                acc.charList[ss] = info;
#endif //__ROGIER_MULTIWORLD__
            }
#ifndef __ROGIER_MULTIWORLD__
            acc.charList.sort();
#endif //__ROGIER_MULTIWORLD__
        }
    }
    return acc;
}

Now in protocollogin.cpp in function parsefirstpacket change:
Code:
std::list<std::string>::iterator it;
    for(it = account.charList.begin(); it != account.charList.end(); it++){
        output->AddString((*it));
        output->AddString(g_config.getString(ConfigManager::WORLD_NAME));
        output->AddU32(serverip);
        output->AddU16(g_config.getNumber(ConfigManager::PORT));
    }

For this:
Code:
#ifndef __ROGIER_MULTIWORLD__
    std::list<std::string>::iterator it;
    for(it = account.charList.begin(); it != account.charList.end(); it++){
        output->AddString((*it));
        output->AddString(g_config.getString(ConfigManager::WORLD_NAME));
        output->AddU32(serverip);
        output->AddU16(g_config.getNumber(ConfigManager::PORT));
    }
    
#else //__ROGIER_MULTIWORLD__

    std::map<std::string, CharInfo>::iterator it;
    for(it = account.charList.begin(); it != account.charList.end(); it++){
        output->AddString(it->first);
        output->AddString(it->second.worldName);
        output->AddU32(inet_addr(it->second.worldIp.c_str()));
        output->AddU16(it->second.worldPort);
    }
#endif //__ROGIER_MULTIWORLD__

In account.h after of
Code:
class Account

Add:
Code:
#ifdef __ROGIER_MULTIWORLD__
#include <map>

struct CharInfo
{
      std::string worldIp;
      std::string worldName;
      short       worldPort;
};
#endif //__ROGIER_MULTIWORLD__

Also in account.h replace:
Code:
std::list<std::string> charList;

For:
Code:
#ifdef __ROGIER_MULTIWORLD__
  std::list<std::string> charList;
#else //__ROGIER_MULTIWORLD__
  std::map<std::string, CharInfo> charList;
#endif //__ROGIER_MULTIWORLD__

Now go to Project> options of the project> parameters and add:
Code:
-D__ROGIER_MULTIWORLD__

Database things:
Make a new table named worlds.
Inside worlds add 4 new fields.
field 1: named `worldid` as an integer.
field 2: named `worldname` as a string.
field 3: named `worldip` as a string.
field 4: named `worldport` as an integer.

Now at players database, add a new field called `worldid` as an integer.

At the worlds u have to insert your world, dont forget to set the worldid at players database.
 
Last edited:
Hmm, nice code, i tried before take it from NOTS.

But can you say how it works? Becouse i dont understand how it works, and what i need to make 2 worlds? I should just have 1 database, and 2 servers? And what with guild, and others if there will be only 1 database?
 
@Nottinghster
Are you a ripper or what? Noob please?
This code was made by Rogier1337 (Drakaro) and was posted on 18/10/2007 on other forum

Give up, you will never become a programmer.
 
this code no is your -.- noob?

Rogier make this code

and brfwolf have maker other multi world

Credits for brfwolf and DragonSlayer
 
Last edited:
@All

I caught this code forum in Polish and did not have the proper credit, then why I modified!

Now is yes with the proper credit

@Nostradamus

No doubt of my ability!

You do not know me speaking to stay ........


Sorry!!
 
@Nottinghster
So when you don't know how made a code you broadcast that is you the owner of it? Good way of think...

And I know youm, so I can make some questions about your "skills", i can begin saying about your "good" english...
 
OMG....
Nostra~ Who are you to say that? Never you ripped any code and said you made the same?

@Topic
Nice script I already used it... But now I prefer Login Server made by SupperGillis.
 
Rogier 1337 is the offical maker of this code since he made this for the drakaro server which i was working in to at that moment.
 
Thanks coppie and nostradamus.
There is no base or thing from brwolf in here anywhere.
When making it in sql how would you make it else?


I guess u wud load it when starting the client(lolzor)
 
this code is based in multi world make by brfwolf

credits is to brfwolf

sorry bad english ;p

Just because brwolf made the code originally and the code resembles his a little, doesn't mean any code was his or that rogier even used any of his code to begin with.
How different can two codes that do the same thing be? :thumbup:
 
Just because brwolf made the code originally and the code resembles his a little, doesn't mean any code was his or that rogier even used any of his code to begin with.
How different can two codes that do the same thing be? :thumbup:

My teacher in high school said to me one thing....

It is impossible two people write two scripts equal... impossible two people to think equal...
if the script are the same with minor changes, YES the script was copied.

// my teacher of Algorithm

but your point is good ;P
 
My teacher in high school said to me one thing....

It is impossible two people write two scripts equal... impossible two people to think equal...
if the script are the same with minor changes, YES the script was copied.

// my teacher of Algorithm

but your point is good ;P

Not always, it depends on what script it is, and who writes it.
 
My teacher in high school said to me one thing....

It is impossible two people write two scripts equal... impossible two people to think equal...
if the script are the same with minor changes, YES the script was copied.

// my teacher of Algorithm

but your point is good ;P

Well many people may prefer to write x + y everytime on their code when I prefer to make a function (method or whatever you wanna call it).
 
Back
Top