Ir para conteúdo

[sql]multi World System


GM Volcano

Posts Recomendados

Créditos : Drakaro/Rogier||OTFans.net

 

Ao code =D :

 

Em ioaccountsql.cp troque :

Account IOAccountSQL::loadAccount(uint32_t accno)

 

Por:

 

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;
}

 

Agora em protocollogin.cpp na função parsefirstpacket troque :

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));
}

 

Por :

#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__

 

Em account.h depois de :

class Account

 

Adicione :

#ifdef __ROGIER_MULTIWORLD__
#include <map>

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

 

Ainda em account.h troque :

std::list<std::string> charList;

 

Por :

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

 

Agora vá em projeto>opçoes do projeto>parametros e add :

-D__ROGIER_MULTIWORLD__

 

P/ finaliza..(n traduzi pq so noob)

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.

 

====================

Motivo por edit > Tinha um bug no code.

 

Pronto!!

Créditos la em cima!

Editado por GM Volcano
Link para o comentário
Compartilhar em outros sites

  • 2 weeks later...
  • Quem Está Navegando   0 membros estão online

    • Nenhum usuário registrado visualizando esta página.
×
×
  • Criar Novo...