Esempio n. 1
0
NetworkClient* ServerManager::handleSessionConnect(Session* session, Service* service)
{
    NetworkClient*	newClient = 0;
    ServerAddress	serverAddress;

    // Execute our statement
    int8 sql[500];
    sprintf(sql,"SELECT id, address, port, status, active FROM config_process_list WHERE address='%s' AND port=%u;", session->getAddressString(), session->getPortHost());
    DatabaseResult* result = mDatabase->ExecuteSynchSql(sql);
    

    // If we found them
    if(result->getRowCount() == 1)
    {
        // Retrieve our routes and add them to the map.
        result->GetNextRow(mServerBinding,&serverAddress);

        // put this fresh data in our list.
        newClient = new ConnectionClient();
        ConnectionClient* connClient = reinterpret_cast<ConnectionClient*>(newClient);

        ConnectionClient* oldClient = mServerAddressMap[serverAddress.mId].mConnectionClient;
        if(oldClient)
        {
            delete(oldClient);
            --mTotalConnectedServers;
        }

        connClient->setServerId(serverAddress.mId);

        memcpy(&mServerAddressMap[serverAddress.mId], &serverAddress, sizeof(ServerAddress));
        mServerAddressMap[serverAddress.mId].mConnectionClient = connClient;

        gLogger->log(LogManager::DEBUG,"*** Backend server connected id: %u\n",mServerAddressMap[serverAddress.mId].mId);

        // If this is one of the servers we're waiting for, then update our count
        if(mServerAddressMap[serverAddress.mId].mActive)
        {

            ++mTotalConnectedServers;
            if(mTotalConnectedServers == mTotalActiveServers)
            {
                mDatabase->ExecuteProcedureAsync(0, 0, "CALL sp_GalaxyStatusUpdate(%u, %u);", 2, mClusterId); // Set status to online
               
            }
        }
    }
    else
    {
        gLogger->log(LogManager::CRITICAL,"*** Backend server connect error - Server not found in DB\n");
        gLogger->log(LogManager::DEBUG,sql);
        gLogger->log(LogManager::DEBUG,"\n");
    }

    // Delete our DB objects.
    mDatabase->DestroyResult(result);

    return(newClient);
}
Esempio n. 2
0
void ZoneServer::_connectToConnectionServer(void)
{
	ProcessAddress processAddress;
	memset(&processAddress, 0, sizeof(ProcessAddress));

	// Query the DB to find out who this is.
	// setup our databinding parameters.
	DataBinding* binding = mDatabase->CreateDataBinding(5);
	binding->addField(DFT_uint32, offsetof(ProcessAddress, mType), 4);
	binding->addField(DFT_string, offsetof(ProcessAddress, mAddress), 16);
	binding->addField(DFT_uint16, offsetof(ProcessAddress, mPort), 2);
	binding->addField(DFT_uint32, offsetof(ProcessAddress, mStatus), 4);
	binding->addField(DFT_uint32, offsetof(ProcessAddress, mActive), 4);

	// Execute our statement
	DatabaseResult* result = mDatabase->ExecuteSynchSql("SELECT id, address, port, status, active FROM config_process_list WHERE name='connection';");
	uint32 count = static_cast<uint32>(result->getRowCount());

	// If we found them
	if (count == 1)
	{
		// Retrieve our routes and add them to the map.
		result->GetNextRow(binding, &processAddress);
	}

	// Delete our DB objects.
	mDatabase->DestroyDataBinding(binding);
	mDatabase->DestroyResult(result);

	// Now connect to the ConnectionServer
	DispatchClient* client = new DispatchClient();
	mRouterService->Connect(client, processAddress.mAddress, processAddress.mPort);

	// Send our registration message
	gMessageFactory->StartMessage();
	gMessageFactory->addUint32(opClusterRegisterServer);
	gMessageFactory->addString(mZoneName);

	Message* message = gMessageFactory->EndMessage();
	client->SendChannelA(message, 0, CR_Connection, 1);
}
Esempio n. 3
0
void ServerManager::_loadProcessAddressMap(void)
{
    //bool            serversOnline = false;
    ServerAddress   serverAddress;

    // retrieve our list of process addresses.
    DatabaseResult* result = mDatabase->ExecuteSynchSql("SELECT id, address, port, status, active FROM config_process_list WHERE active=1 ORDER BY id;");
    

    mTotalActiveServers = static_cast<uint32>(result->getRowCount());

    for(uint32 i = 0; i < mTotalActiveServers; i++)
    {
        // Retrieve our server data
        result->GetNextRow(mServerBinding,&serverAddress);
        memcpy(&mServerAddressMap[serverAddress.mId], &serverAddress, sizeof(ServerAddress));
        mServerAddressMap[serverAddress.mId].mConnectionClient = NULL;
    }

    // Delete our DB objects.
    mDatabase->DestroyResult(result);
}
Esempio n. 4
0
ZoneServer::ZoneServer(int8* zoneName) :
mZoneName(zoneName),
mNetworkManager(0),
mDatabaseManager(0),
mRouterService(0),
mDatabase(0)
{
	Anh_Utils::Clock::Init();
	
	// gLogger->logMsgF("ZoneServer - %s Startup %s",MSG_NORMAL,zoneName,GetBuildString());
	gLogger->logMsg("ZoneServer Startup", FOREGROUND_GREEN | FOREGROUND_RED);

	// Create and startup our core services.
	mDatabaseManager = new DatabaseManager();

	mNetworkManager = new NetworkManager();

	// Connect to the DB and start listening for the RouterServer.
	mDatabase = mDatabaseManager->Connect(DBTYPE_MYSQL,
										   (int8*)(gConfig->read<std::string>("DBServer")).c_str(),
										   gConfig->read<int>("DBPort"),
										   (int8*)(gConfig->read<std::string>("DBUser")).c_str(),
										   (int8*)(gConfig->read<std::string>("DBPass")).c_str(),
										   (int8*)(gConfig->read<std::string>("DBName")).c_str());

	//make sure our logger has db access
	gLogger->connecttoDB(mDatabaseManager);

	//create an error log
	int8 log[128];
	sprintf(log,"%s.log",zoneName);
	gLogger->createErrorLog(log,(LogLevel)(gConfig->read<int>("LogLevel",2)),
										(bool)(gConfig->read<bool>("LogToFile", true)),
										(bool)(gConfig->read<bool>("ConsoleOut",true)),
										(bool)(gConfig->read<bool>("LogAppend",true)));

	//increase the server start that will help us to organize our logs to the corresponding serverstarts (mostly for errors)
	mDatabase->ExecuteSqlAsync(0,0,"UPDATE config_process_list SET serverstartID = serverstartID+1 WHERE name like \'%s\'",zoneName);

	mRouterService = mNetworkManager->GenerateService((char*)gConfig->read<std::string>("BindAddress").c_str(), gConfig->read<uint16>("BindPort"),gConfig->read<uint32>("ServiceMessageHeap")*1024,true);

	// Grab our zoneId out of the DB for this zonename.
	uint32 zoneId = 0;
	DatabaseResult* result = mDatabase->ExecuteSynchSql("SELECT planet_id FROM planet WHERE name=\'%s\';", zoneName);

	if (!result->getRowCount())
	{
		gLogger->logMsgF("FATAL: Map \'%s\' not found.  Aborting startup.", MSG_HIGH, zoneName);
		abort();
	}

	//  Yea, I'm getting annoyed with the DataBinding for such simple tasks.  Will implement a simple interface soon.
	gLogger->logMsgF("ZoneServer initializing for zone %s", MSG_NORMAL, zoneName);


	DataBinding* binding = mDatabase->CreateDataBinding(1);
	binding->addField(DFT_uint32, 0, 4);

	result->GetNextRow(binding, &zoneId);

	mDatabase->DestroyDataBinding(binding);
	mDatabase->DestroyResult(result);

	// We need to register our IP and port in the DB so the connection server can connect to us.
	// Status:  0=offline, 1=loading, 2=online
	_updateDBServerList(1);

	// Place all startup code here.
	mMessageDispatch = new MessageDispatch(mRouterService);

	WorldConfig::Init(zoneId,mDatabase,zoneName);
	ObjectControllerCommandMap::Init(mDatabase);
	MessageLib::Init();
	ObjectFactory::Init(mDatabase);
	
	//attribute commands for foodbuffs
	FoodCommandMapClass::Init();
	
	//structuremanager callback functions 
	StructureManagerCommandMapClass::Init();

	WorldManager::Init(zoneId,this,mDatabase);

	// Init the non persistent factories. For now we take them one-by-one here, until we have a collection of them.
	// We can NOT create these factories among the already existing ones, if we want to have any kind of "ownership structure",
	// since the existing factories are impossible to delete without crashing the server.
	// NonPersistentContainerFactory::Init(mDatabase);
	(void)NonPersistentItemFactory::Instance();	// This call is just for clarity, when matching the deletion of classes.
												// The object will create itself upon first usage,
	(void)NonPersistentNpcFactory::Instance();

	(void)ForageManager::Instance();
	(void)ScoutManager::Instance();
	(void)NonPersistantObjectFactory::Instance();

	UIManager::Init(mDatabase,mMessageDispatch);
	CombatManager::Init(mDatabase);
	TravelMapHandler::Init(mDatabase,mMessageDispatch,zoneId);
	CharSheetManager::Init(mDatabase,mMessageDispatch);
	TradeManager::Init(mDatabase,mMessageDispatch);
	BuffManager::Init(mDatabase);
	MedicManager::Init(mMessageDispatch);
	AdminManager::Init(mMessageDispatch);
	EntertainerManager::Init(mDatabase,mMessageDispatch);
	GroupManager::Init(mDatabase,mMessageDispatch);
	StructureManager::Init(mDatabase,mMessageDispatch);
	// Invoked when all creature regions for spawning of lairs are loaded
	// (void)NpcManager::Instance();


	ScriptEngine::Init();

	mCharacterLoginHandler = new CharacterLoginHandler(mDatabase,mMessageDispatch);

	mObjectControllerDispatch = new ObjectControllerDispatch(mDatabase,mMessageDispatch);
}