Пример #1
0
//////////////////////////////////
// temporarily moved into ServiceDB because other services needed access to
// it, eventually something better will need to be done (as the account system
// grows up)
bool ServiceDB::GiveCash( uint32 characterID, JournalRefType refTypeID, uint32 ownerFromID, uint32 ownerToID, const char *argID1,
    uint32 accountID, EVEAccountKeys accountKey, double amount, double balance, const char *reason )
{
//the only unknown it is argID1 , what is it ?
    DBQueryResult res;
    DBerror err;

    std::string eReason;
    sDatabase.DoEscapeString(eReason, reason);
    std::string eArg1;
    sDatabase.DoEscapeString(eArg1, argID1);

    if(!sDatabase.RunQuery(err,
        "INSERT INTO market_journal(characterID,refID,transDate,refTypeID,ownerID1,ownerID2,argID1,accountID,accountKey,amount,balance,reason) "
        "VALUES (%u,NULL," PRIu64 ",%u,%u,%u,\"%s\",%u,%u,%.2f,%.2f,\"%s\")",
        characterID, Win32TimeNow(), refTypeID, ownerFromID, ownerToID, eArg1.c_str(), accountID, accountKey, amount, balance, eReason.c_str()))
    {
        sLog.Error("Service DB", "Error in query : %s", err.c_str());
        return false;
    }

    return true;
}
Пример #2
0
bool CorporationDB::InsertApplication(const ApplicationInfo & aInfo) {
    if (!aInfo.valid) {
        codelog(SERVICE__ERROR, "aInfo contains invalid data");
        return false;
    }

    DBerror err;
    std::string safeMessage;
    sDatabase.DoEscapeString(safeMessage, aInfo.appText);
    if (!sDatabase.RunQuery(err,
        " INSERT INTO chrApplications ("
        " corporationID, characterID, applicationText, roles, grantableRoles, status, "
        " applicationDateTime, deleted, lastCorpUpdaterID "
        " ) VALUES ( "
        " %u, %u, '%s', " I64u ", " I64u ", %u, " I64u ", %u, %u "
        " ) ", aInfo.corpID, aInfo.charID, safeMessage.c_str(), aInfo.role,
               aInfo.grantRole, aInfo.status, aInfo.appTime, aInfo.deleted, aInfo.lastCID))
    {
        codelog(SERVICE__ERROR, "Error in query: %s", err.c_str());
        return false;
    }

    return true;
}
Пример #3
0
bool RamProxyDB::CompleteJob(const uint32 jobID, const EVERamCompletedStatus completedStatus) {
    DBerror err;

    if(!DBcore::RunQuery(err,
        "UPDATE srvRamJobs"
        " SET completedStatusID = %u"
        " WHERE jobID = %u",
        (uint32)completedStatus, jobID))
    {
        _log(DATABASE__ERROR, "Failed to complete job %u (completed status = %u): %s.", jobID, (uint32)completedStatus, err.c_str());
        return false;
    }

    return true;
}
Пример #4
0
//johnsus - characterOnline mod
void ServiceDB::SetCharacterOnlineStatus(uint32 char_id, bool onoff_status) {
    DBerror err;

    _log(CLIENT__TRACE, "ChrStatus: Setting character %u %s.", char_id, onoff_status ? "Online" : "Offline");

    if(!DBcore::RunQuery(err,
        "UPDATE srvCharacter"
        " SET online = %d"
        " WHERE characterID = %u",
        onoff_status, char_id))
    {
        codelog(SERVICE__ERROR, "Error in query: %s", err.c_str());
    }

    if( onoff_status )
    {
        _log(CLIENT__TRACE, "SrvStatus: Incrementing ConnectSinceStartup.");

        if(!DBcore::RunQuery(err, "UPDATE srvStatus SET config_value = config_value + 1 WHERE config_name = 'connectSinceStartup'"))
        {
            codelog(SERVICE__ERROR, "Error in query: %s", err.c_str());
        }
    }
}
Пример #5
0
bool BookmarkDB::DeleteBookmarkFromDatabase(uint32 ownerID, uint32 bookmarkID)
{
    DBerror err;

    if (!DBcore::RunQuery(err,
        " DELETE FROM srvBookmarks "
        " WHERE ownerID = %u AND bookmarkID = %u", ownerID, bookmarkID
        ))
    {
        SysLog::Error( "BookmarkDB::DeleteBookmarkFromDatabase()", "Error in query: %s", err.c_str() );
        return false;
    }

    return true;
}
Пример #6
0
bool ServiceDB::AddBalanceToCorp(uint32 corpID, double amount, uint32 walletKey) {
	DBerror err;
	std::string name;

	if( ( walletKey < 1000 ) || ( walletKey > 1006 ) )
	{
		walletKey = 1000;
	}

	// Care about wallet keys!
	if( walletKey == 1000 ) sprintf( name, "balance" );
	else sprintf( name, "divisionBalance%u", walletKey - 999 );

	if( !sDatabase.RunQuery( err,
		"UPDATE corporation"
		" SET %s = %s + (%lf)"
		" WHERE corporationID = %u", name.c_str(), name.c_str(), amount, corpID ) )
	{
		sLog.Error( "Service DB", "Error in query: %s", err.c_str() );
		return false;
	}

	return true;
}
Пример #7
0
bool LSCDB::DeleteMessage(uint32 messageID, uint32 readerID) {
	DBerror err;
	bool ret = true;

	if (!sDatabase.RunQuery(err,
		" DELETE FROM eveMail "
		" WHERE messageID=%u AND channelID=%u", messageID, readerID
		))
	{
		codelog(SERVICE__ERROR, "Error in query: %s", err.c_str());
		ret = false;
	}
	if (!sDatabase.RunQuery(err,
		" DELETE FROM eveMailDetails "
		" WHERE messageID=%u", messageID
		))
	{
		codelog(SERVICE__ERROR, "Error in query: %s", err.c_str());
		ret = false;
	}

	return ret;

}
Пример #8
0
uint32 ServiceDB::CreateNewAccount( const char* login, const char* pass, uint64 role )
{
    uint32 accountID;

    DBerror err;
    if( !DBcore::RunQueryLID( err, accountID,
                             "INSERT INTO srvAccount ( accountName, hash, role )"
        " VALUES ( '%s', '%s', %" PRIu64 " )",
        login, pass, role ) )
    {
        SysLog::Error( "ServiceDB", "Failed to create a new account '%s': %s.", login, err.c_str() );
        return 0;
    }

    return accountID;
}
Пример #9
0
bool AttributeMap::SaveFloatAttribute(uint32 attributeID, double value)
{
    // SAVE FLOAT ATTRIBUTE
    DBerror err;
    if(!sDatabase.RunQuery(err,
                           "REPLACE INTO entity_attributes"
                           "   (itemID, attributeID, valueInt, valueFloat)"
                           " VALUES"
                           "   (%u, %u, NULL, %f)",
                           mItem.itemID(), attributeID, value)
      ) {
        codelog(SERVICE__ERROR, "Failed to store attribute %d for item %u: %s", attributeID, mItem.itemID(), err.c_str());
        return false;
    }

    return true;
}
Пример #10
0
//temporarily relocated into ServiceDB until some things get cleaned up...
uint32 LSCDB::StoreMail(uint32 senderID, uint32 recipID, const char * subject, const char * message, uint64 sentTime) {
    DBQueryResult res;
    DBerror err;
    DBResultRow row;

    std::string escaped;
    // Escape message header
    DBcore::DoEscapeString(escaped, subject);

    // Store message header
    uint32 messageID;
    if (!DBcore::RunQueryLID(err, messageID,
        " INSERT INTO "
        " srvEveMail "
        " (channelID, senderID, subject, created) "
        " VALUES (%u, %u, '%s', %" PRIu64 ") ",
        recipID, senderID, escaped.c_str(), sentTime ))
    {
        codelog(SERVICE__ERROR, "Error in query, message header couldn't be saved: %s", err.c_str());
        return (0);
    }

    _log(SERVICE__MESSAGE, "New messageID: %u", messageID);

    // Escape message content
    DBcore::DoEscapeString(escaped, message);

    // Store message content
    if (!DBcore::RunQuery(err,
        " INSERT INTO srvEveMailDetails "
        " (messageID, mimeTypeID, attachment) VALUES (%u, 1, '%s') ",
        messageID, escaped.c_str()
        ))
    {
        codelog(SERVICE__ERROR, "Error in query, message content couldn't be saved: %s", err.c_str());
        // Delete message header
        if (!DBcore::RunQuery(err, "DELETE FROM `srvEveMail` WHERE `messageID` = %u;", messageID))
        {
            codelog(SERVICE__ERROR, "Failed to remove invalid header data for messgae id %u: %s", messageID, err.c_str());
        }
        return (0);
    }


    return (messageID);
}
Пример #11
0
bool BookmarkDB::UpdateFolderInDatabase(uint32 &folderID, std::string folderName, uint32 ownerID, uint32 creatorID)

{
    DBerror err;

    if (!DBcore::RunQuery(err,
        " UPDATE srvBookmarkFolders"
        "  SET  folderName = '%s'"
        " WHERE folderID = %u AND ownerID = %u",
         folderName.c_str(), folderID, ownerID
        ))
    {
        SysLog::Error( "BookmarkDB::UpdateFolderInDatabase()", "Error in query, Folder couldn't be saved: %s", err.c_str() );
        return 0;
    }
    else
        return 1;
}
Пример #12
0
bool BookmarkDB::SaveNewFolderToDatabase(uint32 &folderID, std::string folderName, uint32 ownerID, uint32 creatorID)

{
    DBerror err;

    if (!DBcore::RunQuery(err,
        " INSERT INTO srvBookmarkFolders"
        " (folderID, folderName, ownerID, creatorID )"
        " VALUES (%u, '%s', %u, %u) ",
        folderID, folderName.c_str(), ownerID, creatorID
        ))
    {
        SysLog::Error( "BookmarkDB::SaveNewFolderToDatabase()", "Error in query, Folder couldn't be saved: %s", err.c_str() );
        return 0;
    }
    else
        return 1;
}
Пример #13
0
// Take the channelID of a chat channel that a character specified by characterID just subscribed to
// and create a new entry in the 'channelChars' table for this subscription.
int LSCDB::WriteNewChannelSubscriptionToDatabase(uint32 characterID, uint32 channelID, uint32 corpID, uint32 allianceID, uint32 role, uint32 extra)
{
	DBQueryResult res;
	DBerror err;
	DBResultRow row;

	if (!sDatabase.RunQuery(err,
		" INSERT INTO channelChars "
		" (channelID, corpID, charID, allianceID, role, extra) VALUES (%u, %u, %u, %u, %u, %u) ",
		channelID, corpID, characterID, allianceID, role, extra
		))
	{
		_log(SERVICE__ERROR, "Error in query, Channel Subscription content couldn't be saved: %s", err.c_str());
		return 0;
	}
	else
		return 1;
}
Пример #14
0
bool BookmarkDB::SaveNewBookmarkToDatabase(uint32 &bookmarkID, uint32 ownerID, uint32 itemID,
                               uint32 typeID, uint32 flag, std::string memo, uint64 created,
                               double x, double y, double z, uint32 locationID, std::string note,
                               uint32 creatorID, uint32 folderID)
{
    DBerror err;

    if (!DBcore::RunQuery(err,
        " INSERT INTO srvBookmarks "
        " (bookmarkID, ownerID, itemID, typeID, flag, memo, created, x, y, z, locationID, note, creatorID, folderID)"
        " VALUES (%u, %u, %u, %u, %u, '%s', %" PRIu64 ", %f, %f, %f, %u, '%s', %u, %u) ",
        bookmarkID, ownerID, itemID, typeID, flag, memo.c_str(), created, x, y, z, locationID, note.c_str(), creatorID, folderID
        ))
    {
        SysLog::Error( "BookmarkDB::SaveNewBookmarkToDatabase()", "Error in query, Bookmark content couldn't be saved: %s", err.c_str() );
        return 0;
    }
    else
        return 1;
}
Пример #15
0
bool BookmarkDB::UpdateBookmarkInDatabase(uint32 bookmarkID, uint32 ownerID, std::string memo, std::string note)
{
    DBerror err;

    if (!DBcore::RunQuery(err,
        " UPDATE srvBookmarks "
        " SET "
        " memo = '%s', note = '%s'"
        " WHERE bookmarkID = %u AND ownerID = %u",
        memo.c_str(),
        note.c_str(),
        bookmarkID,
        ownerID
        ))
    {
        SysLog::Error( "BookmarkDB::UpdateBookmarkInDatabase()", "Error in query: %s", err.c_str() );
        return false;
    }

    return true;
}
Пример #16
0
bool DBcore::Open(DBerror &err, const char* iHost, const char* iUser, const char* iPassword, const char* iDatabase, int16 iPort, bool iCompress, bool iSSL) {
    MutexLock lock(MDatabase);

    pHost = iHost;
    pUser = iUser;
    pPassword = iPassword;
    pDatabase = iDatabase;
    pCompress = iCompress;
    pPort = iPort;
    pSSL = iSSL;

    int32 errnum;
    char errbuf[1024];

    if(!Open_locked(&errnum, errbuf)) {
        err.SetError(errnum, errbuf);
        return false;
    }

    return true;
}
Пример #17
0
bool AttributeMap::Delete()
{
    // Remove all attributes from the entity_default_attributes table or entity_attributes table for this item:
    DBerror err;

	if(mDefault)
	{
		if(!sDatabase.RunQuery(err,
			"DELETE"
			" FROM entity_default_attributes"
			" WHERE itemID=%u",
			mItem.itemID()
		))
		{
			sLog.Error( "AttributeMap::Delete()", "Failed to delete DEFAULT item %u: %s", mItem.itemID(), err.c_str());
			return false;
		}
	}
	else
	{
		if(!sDatabase.RunQuery(err,
			"DELETE"
			" FROM entity_attributes"
			" WHERE itemID=%u",
			mItem.itemID()
		))
		{
			sLog.Error( "AttributeMap::Delete()", "Failed to delete item %u: %s", mItem.itemID(), err.c_str());
			return false;
		}
	}

	mAttributes.clear();

	mChanged = false; // just synced with database, no need to save

    return true;
}
Пример #18
0
bool BookmarkDB::SaveNewBookmarkToDatabase(uint32 &bookmarkID, uint32 ownerID, uint32 itemID,
                               uint32 typeID, uint32 flag, std::string memo, uint64 created,
                               double x, double y, double z, uint32 locationID)
{
	DBQueryResult res;
	DBerror err;
	DBResultRow row;

    bookmarkID = GetNextAvailableBookmarkID();

	if (!sDatabase.RunQuery(err,
		" INSERT INTO bookmarks "
		" (bookmarkID, ownerID, itemID, typeID, flag, memo, created, x, y, z, locationID)"
        " VALUES (%u, %u, %u, %u, %u, '%s', "I64u", %f, %f, %f, %u) ",
        bookmarkID, ownerID, itemID, typeID, flag, memo.c_str(), created, x, y, z, locationID
		))
	{
        sLog.Error( "BookmarkDB::SaveNewBookmarkToDatabase()", "Error in query, Bookmark content couldn't be saved: %s", err.c_str() );
		return 0;
	}
	else
		return 1;
}
Пример #19
0
int main( int argc, char* argv[] )
{
#if defined( HAVE_CRTDBG_H ) && !defined( NDEBUG )
    // Under Visual Studio setup memory leak detection
    _CrtSetDbgFlag( _CRTDBG_LEAK_CHECK_DF | _CrtSetDbgFlag( _CRTDBG_REPORT_FLAG ) );
#endif /* defined( HAVE_CRTDBG_H ) && !defined( NDEBUG ) */

    printf("Copyright (C) 2006-2011 EVEmu Team. http://evemu.org/\n");
    printf("This program is free software; you can redistribute it and/or modify it under\n");
    printf("the terms of the GNU Lesser General Public License as published by the Free \n");
    printf("Software Foundation; either version 2 of the License, or (at your option) any\n");
    printf("later version.\n");
    printf("\n");
    printf("This program is distributed in the hope that it will be useful, but WITHOUT\n");
    printf("ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\n");
    printf("FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more\n");
    printf("details.\n");
    printf("\n");

    // Load server configuration
    if( !sConfig.ParseFile( CONFIG_FILE ) )
    {
        printf("ERROR: Loading server configuration '%s' failed.", CONFIG_FILE );
        //sLog.Error( "server init", "Loading server configuration '%s' failed.", CONFIG_FILE );
        std::cout << std::endl << "press any key to exit...";  std::cin.get();
        return 1;
    }

    sLog.InitializeLogging(sConfig.files.logDir);
    sLog.Log("server init", "Loading server configuration...");

    sLog.Log("", "" );
    sLog.Log("SERVER VERSION", "EVEmu " EVEMU_VERSION );
    sLog.Log("", "" );
    sLog.Log("SOURCE", "get at " EVEMU_REPOSITORY );
    sLog.Log("", "" );
    sLog.Log("SERVER INIT", "\n"
        "\tSupported Client: %s\n"
        "\tVersion %.2f\n"
        "\tBuild %d\n"
        "\tMachoNet %u",
        EVEProjectVersion,
        EVEVersionNumber,
        EVEBuildVersion,
        MachoNetVersion
    );

    //it is important to do this before doing much of anything, in case they use it.
    Timer::SetCurrentTime();

    // Load server log settings ( will be removed )
    if( load_log_settings( sConfig.files.logSettings.c_str() ) )
        sLog.Success( "server init", "Log settings loaded from %s", sConfig.files.logSettings.c_str() );
    else
        sLog.Warning( "server init", "Unable to read %s (this file is optional)", sConfig.files.logSettings.c_str() );

    // open up the log file if specified ( will be removed )
    if( !sConfig.files.logDir.empty() )
    {
        std::string logFile = sConfig.files.logDir + "eve-server.log";
        if( log_open_logfile( logFile.c_str() ) )
            sLog.Success( "server init", "Found log directory %s", sConfig.files.logDir.c_str() );
        else
            sLog.Warning( "server init", "Unable to find log directory '%s', only logging to the screen now.", sConfig.files.logDir.c_str() );
    }

    //connect to the database...
    DBerror err;
    if( !sDatabase.Open( err,
        sConfig.database.host.c_str(),
        sConfig.database.username.c_str(),
        sConfig.database.password.c_str(),
        sConfig.database.db.c_str(),
        sConfig.database.port ) )
    {
        sLog.Error( "server init", "Unable to connect to the database: %s", err.c_str() );
        std::cout << std::endl << "press any key to exit...";  std::cin.get();
        return 1;
    }
    _sDgmTypeAttrMgr = new dgmtypeattributemgr(); // needs to be after db init as its using it

    //Start up the TCP server
    EVETCPServer tcps;

    char errbuf[ TCPCONN_ERRBUF_SIZE ];
    if( tcps.Open( sConfig.net.port, errbuf ) )
    {
        sLog.Success( "server init", "TCP listener started on port %u.", sConfig.net.port );
    }
    else
    {
        sLog.Error( "server init", "Failed to start TCP listener on port %u: %s.", sConfig.net.port, errbuf );
        std::cout << std::endl << "press any key to exit...";  std::cin.get();
        return 1;
    }

    //make the item factory
    ItemFactory item_factory( sEntityList );
	sLog.Log("server init", "starting item factory");

    //now, the service manager...
    PyServiceMgr services( 888444, sEntityList, item_factory );
	sLog.Log("server init", "starting service manager");

    //setup the command dispatcher
    CommandDispatcher command_dispatcher( services );
    RegisterAllCommands( command_dispatcher );

    /*
     * Service creation and registration.
     *
     */
    sLog.Log("server init", "Creating services.");

    // Please keep the services list clean so it's easyier to find something

    services.RegisterService(new AccountService(&services));
    services.RegisterService(new AgentMgrService(&services));
    services.RegisterService(new AggressionMgrService(&services));
    services.RegisterService(new AlertService(&services));
    services.RegisterService(new AuthService(&services));
    services.RegisterService(new BillMgrService(&services));
    services.RegisterService(new BeyonceService(&services));
    services.RegisterService(new BookmarkService(&services));
    services.RegisterService(new BrowserLockdownService(&services));
    services.RegisterService(new BulkMgrService(&services));
    services.RegisterService(new CertificateMgrService(&services));
    services.RegisterService(new CharFittingMgrService(&services));
    services.RegisterService(new CharUnboundMgrService(&services));
    services.RegisterService(new CharMgrService(&services));
    services.RegisterService(new ClientStatLogger(&services));
    services.RegisterService(new ClientStatsMgr(&services));
    services.RegisterService(new ConfigService(&services));
    services.RegisterService(new CorpBookmarkMgrService(&services));
    services.RegisterService(new CorpMgrService(&services));
    services.RegisterService(new CorporationService(&services));
    services.RegisterService(new CorpRegistryService(&services));
    services.RegisterService(new CorpStationMgrService(&services));
    services.RegisterService(new ContractMgrService(&services));
    services.RegisterService(new ContractProxyService(&services));
    services.RegisterService(new DevToolsProviderService(&services));
    services.RegisterService(new DogmaIMService(&services));
    services.RegisterService(new DogmaService(&services));
    services.RegisterService(new DungeonExplorationMgrService(&services));
    services.RegisterService(new DungeonService(&services));
    services.RegisterService(new FactionWarMgrService(&services));
    services.RegisterService(new FactoryService(&services));
    services.RegisterService(new FleetProxyService(&services));
    services.RegisterService(new HoloscreenMgrService(&services));
    services.RegisterService(new InfoGatheringMgr(&services));
    services.RegisterService(new InsuranceService(&services));
    services.RegisterService(new InvBrokerService(&services));
    services.RegisterService(new JumpCloneService(&services));
    services.RegisterService(new KeeperService(&services));
    services.RegisterService(new LanguageService(&services));
    services.RegisterService(new LocalizationServerService(&services));
    services.RegisterService(new LookupService(&services));
    services.RegisterService(new LPService(&services));
    services.RegisterService(services.lsc_service = new LSCService(&services, &command_dispatcher));
    services.RegisterService(new MailMgrService(&services));
    services.RegisterService(new MailingListMgrService(&services));
    services.RegisterService(new MapService(&services));
    services.RegisterService(new MarketProxyService(&services));
    services.RegisterService(new MissionMgrService(&services));
    services.RegisterService(new NetService(&services));
    services.RegisterService(new NotificationMgrService(&services));
    services.RegisterService(services.cache_service = new ObjCacheService(&services, sConfig.files.cacheDir.c_str()));
    services.RegisterService(new OnlineStatusService(&services));
    services.RegisterService(new PaperDollService(&services));
    services.RegisterService(new PetitionerService(&services));
    services.RegisterService(new PhotoUploadService(&services));
    services.RegisterService(new PlanetMgrService(&services));
    services.RegisterService(new PosMgrService(&services));
    services.RegisterService(new RamProxyService(&services));
    services.RegisterService(new RepairService(&services));
    services.RegisterService(new ReprocessingService(&services));
    services.RegisterService(new ShipService(&services));
    services.RegisterService(new SkillMgrService(&services));
    services.RegisterService(new SlashService(&services, &command_dispatcher));
    services.RegisterService(new SovereigntyMgrService(&services));
    services.RegisterService(new Standing2Service(&services));
    services.RegisterService(new StationService(&services));
    services.RegisterService(new StationSvcService(&services));
    services.RegisterService(new TutorialService(&services));
    services.RegisterService(new UserService(&services));
    services.RegisterService(new VoiceMgrService(&services));
    services.RegisterService(new WarRegistryService(&services));

    sLog.Log("server init", "Priming cached objects.");
    services.cache_service->PrimeCache();
    sLog.Log("server init", "finished priming");

    // start up the image server
    sImageServer.Run();
	sLog.Log("server init", "started image server");

    // start up the api server
    sAPIServer.CreateServices( services );
    sAPIServer.Run();
	sLog.Log("server init", "started API server");

    // start up the image server
    sLog.Log("server init", "Loading Dynamic Database Table Objects...");

	// Create In-Memory Database Objects for Critical Systems, such as ModuleManager:
	sLog.Log("server init", "---> sDGM_Effects_Table: Loading...");
	sDGM_Effects_Table.Initialize();
	sLog.Log("server init", "---> sDGM_Type_Effects_Table: Loading...");
	sDGM_Type_Effects_Table.Initialize();
	sLog.Log("server init", "---> sDGM_Skill_Bonus_Modifiers_Table: Loading...");
	sDGM_Skill_Bonus_Modifiers_Table.Initialize();
	//sLog.Log("server init", "---> sDGM_Ship_Bonus_Modifiers_Table: Loading...");
	//sDGM_Ship_Bonus_Modifiers_Table.Initialize();
	sLog.Log("server init", "---> sDGM_Types_to_Wrecks_Table: Loading...");
	sDGM_Types_to_Wrecks_Table.Initialize();

    sLog.Log("server init", "Init done.");

	/////////////////////////////////////////////////////////////////////////////////////
	//     !!!  DO NOT PUT ANY INITIALIZATION CODE OR CALLS BELOW THIS LINE   !!!
	/////////////////////////////////////////////////////////////////////////////////////
	services.serviceDB().SetServerOnlineStatus(true);
	sLog.Success("server init", "SERVER IS NOW [ONLINE]");
	sLog.Log("INFO", "(press Ctrl+C to start controlled server shutdown)");

    /*
     * THE MAIN LOOP
     *
     * Everything except IO should happen in this loop, in this thread context.
     *
     */

    /* program events system */
    SetupSignals();

    uint32 start;
    uint32 etime;
    uint32 last_time = GetTickCount();

    EVETCPConnection* tcpc;
    while( RunLoops == true )
    {
        Timer::SetCurrentTime();
        start = GetTickCount();

        //check for timeouts in other threads
        //timeout_manager.CheckTimeouts();
        while( ( tcpc = tcps.PopConnection() ) )
        {
            Client* c = new Client( services, &tcpc );

            sEntityList.Add( &c );
        }

        sEntityList.Process();
        services.Process();

        /* UPDATE */
        last_time = GetTickCount();
        etime = last_time - start;

        // do the stuff for thread sleeping
        if( MAIN_LOOP_DELAY > etime )
            Sleep( MAIN_LOOP_DELAY - etime );
    }

    sLog.Log("server shutdown", "Main loop stopped" );

    // Shutting down EVE Client TCP listener
    tcps.Close();
    sLog.Log("server shutdown", "TCP listener stopped." );

    // Shutting down API Server:
    sAPIServer.Stop();
    sLog.Log("server shutdown", "Image Server TCP listener stopped." );

    // Shutting down Image Server:
    sImageServer.Stop();
    sLog.Log("server shutdown", "API Server TCP listener stopped." );

    services.serviceDB().SetServerOnlineStatus(false);
	sLog.Log("server shutdown", "SERVER IS NOW [OFFLINE]");

    sLog.Log("server shutdown", "Cleanup db cache" );
    delete _sDgmTypeAttrMgr;

    log_close_logfile();

    //std::cout << std::endl << "press the ENTER key to exit...";  std::cin.get();

	// Shut down the Item system ensuring ALL items get saved to the database:
	sLog.Log("server shutdown", "Shutting down Item Factory." );

	return 0;
}
Пример #20
0
bool CorporationDB::AddCorporation(Call_AddCorporation & corpInfo, uint32 charID, uint32 stationID, uint32 & corpID) {
    DBerror err;
    corpID = 0;

    std::string cName, cDesc, cTick, cURL;
    sDatabase.DoEscapeString(cName, corpInfo.corpName);
    sDatabase.DoEscapeString(cDesc, corpInfo.description);
    sDatabase.DoEscapeString(cTick, corpInfo.corpTicker);
    sDatabase.DoEscapeString(cURL, corpInfo.url);

    //TODO: we should be able to get our race ID directly from our Client
    //object eventually, instead of pulling it from this join.
    if (!sDatabase.RunQueryLID(err, corpID,
        " INSERT INTO corporation ( "
        "   corporationName, description, tickerName, url, "
        "   taxRate, minimumJoinStanding, corporationType, hasPlayerPersonnelManager, sendCharTerminationMessage, "
        "   creatorID, ceoID, stationID, raceID, allianceID, shares, memberCount, memberLimit, "
        "   allowedMemberRaceIDs, graphicID, color1, color2, color3, shape1, shape2, shape3, "
        "   typeface "
        "   ) "
        " SELECT "
        "       '%s', '%s', '%s', '%s', "
        "       %lf, 0, 2, 0, 1, "
        "       %u, %u, %u, chrBloodlines.raceID, 0, 1000, 0, 10, "
        "       chrBloodlines.raceID, 0, %s, %s, %s, %s, %s, %s, "
        "       NULL "
        "    FROM entity "
        "       LEFT JOIN bloodlineTypes USING (typeID) "
        "       LEFT JOIN chrBloodlines USING (bloodlineID) "
        "    WHERE entity.itemID = %u ",
        cName.c_str(), cDesc.c_str(), cTick.c_str(), cURL.c_str(),
        corpInfo.taxRate,
        charID, charID, stationID,
        _IoN(corpInfo.color1).c_str(),
        _IoN(corpInfo.color2).c_str(),
        _IoN(corpInfo.color3).c_str(),
        _IoN(corpInfo.shape1).c_str(),
        _IoN(corpInfo.shape2).c_str(),
        _IoN(corpInfo.shape3).c_str(),
        charID))
    {
        codelog(SERVICE__ERROR, "Error in query: %s", err.c_str());
        return false;
    }

    // It has to go into the eveStaticOwners too
    // (well, not exactly there, but it has to be cached, and i don't know how
    // that works clientside...)
    // This is a temp hack to make my life easier
    if (!sDatabase.RunQuery(err,
        " REPLACE INTO eveStaticOwners (ownerID,ownerName,typeID) "
        "   VALUES (%u, '%s', 2)",
        corpID, cName.c_str()))
    {
        codelog(SERVICE__ERROR, "Error in query: %s", err.c_str());
        return false;
    }

    // And create a channel too
    if (!sDatabase.RunQuery(err,
        " INSERT INTO channels ("
        "   channelID, ownerID, displayName, motd, comparisonKey, "
        "   memberless, password, mailingList, cspa, temporary, "
        "   mode, subscribed, estimatedMemberCount"
        " ) VALUES ("
        "   %u, %u, '%s', '%s MOTD', '%s', "
        "   1, NULL, 0, 127, 0, "
        "   1, 1, 0"
        " )",
        corpID, corpID, cName.c_str(), cName.c_str(), cTick.c_str()
        ))
    {
        codelog(SERVICE__ERROR, "Error in query: %s", err.c_str());
        // This is not a serious problem either, but would be good if the channel
        // were working...
    }

    return true;
}
Пример #21
0
PyRep *MarketDB::DeleteContract( uint32 contractID, uint32 characterID )
{
	DBerror err;

	DBQueryResult res;

	// Update the user info
	int forCorp = false;
	if(!sDatabase.RunQuery(res,
		"SELECT forCorp"
		" FROM contract"
		" WHERE contractID=%d", contractID))
	{
		codelog(MARKET__ERROR, "Error in query: %s", res.error.c_str() );
		return new PyBool(false);
	}
	DBResultRow row;

	if( !res.GetRow(row) )
	{
		codelog(MARKET__ERROR, "Contract %d not found.", contractID);
		return NULL;
	}

	forCorp = row.GetInt(0);

	if(!sDatabase.RunQuery(err, 
		"DELETE FROM contract"
		" WHERE contractID=%d", contractID ) )
	{
		codelog(MARKET__ERROR, "Error in query: %s", err.c_str() );
		return new PyBool(false);
	}

	if(!sDatabase.RunQuery(err,
		"DELETE FROM contracts_items"
		" WHERE contractID=%d", contractID ) )
	{
		codelog(MARKET__ERROR, "Error in query: %s", err.c_str() );
		return new PyBool(false);
	}

	if(!sDatabase.RunQuery(err,
		"DELETE FROM contract_bids"
		" WHERE contractID=%d", contractID ) )
	{
		codelog(MARKET__ERROR, "Error in query: %s", err.c_str() );
		return new PyBool(false);
	}

	if(!forCorp)
	{
		if(!sDatabase.RunQuery(err, 
			"UPDATE"
			" chrcontractinfo"
			" SET numOutStandingContractsNonCorp=numOutStandingContractsNonCorp-1,"
			" numOutstandingContracts=numOutstandingContracts-1"
			" WHERE characterID=%d", characterID))
		{
			codelog(MARKET__ERROR, "Error in query: %s", err.c_str() );
			return new PyBool(false);
		}
	}else{
		if(!sDatabase.RunQuery(err, 
			"UPDATE"
			" chrcontractinfo"
			" SET numOutStandingContractsForCorp=numOutStandingContractsForCorp-1,"
			" numOutstandingContracts=numOutstandingContracts-1"
			" WHERE characterID=%d", characterID))
		{
			codelog(MARKET__ERROR, "Error in query: %s", err.c_str() );
			return new PyBool(false);
		}
	}
	return new PyBool(true);
}
Пример #22
0
int main( int argc, char* argv[] )
{
#if defined( MSVC ) && !defined( NDEBUG )
    // Under Visual Studio setup memory leak detection
    _CrtSetDbgFlag( _CRTDBG_LEAK_CHECK_DF | _CrtSetDbgFlag( _CRTDBG_REPORT_FLAG ) );
#endif /* defined( MSVC ) && !defined( NDEBUG ) */

    printf("Copyright (C) 2006-2011 EVEmu Team. http://evemu.org/\n");
    printf("This program is free software; you can redistribute it and/or modify it under\n");
    printf("the terms of the GNU Lesser General Public License as published by the Free \n");
    printf("Software Foundation; either version 2 of the License, or (at your option) any\n");
    printf("later version.\n");
    printf("\n");
    printf("This program is distributed in the hope that it will be useful, but WITHOUT\n");
    printf("ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\n");
    printf("FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more\n");
    printf("details.\n");
    printf("\n");

    sLog.Log("main", "EVEmu "EVEMU_VERSION );
    sLog.Log("server init", "\n"
        "\tSupported Client: %s\n"
        "\tVersion %.2f\n"
        "\tBuild %d\n"
        "\tMachoNet %u",
        EVEProjectVersion,
        EVEVersionNumber,
        EVEBuildVersion,
        MachoNetVersion
    );

    //it is important to do this before doing much of anything, in case they use it.
    Timer::SetCurrentTime();

    // Load server configuration
    sLog.Log("server init", "Loading server configuration...");

    if( !sConfig.ParseFile( CONFIG_FILE ) )
    {
        sLog.Error( "server init", "Loading server configuration '%s' failed.", CONFIG_FILE );
        return 1;
    }

    // Load server log settings ( will be removed )
    if( load_log_settings( sConfig.files.logSettings.c_str() ) )
        sLog.Success( "server init", "Log settings loaded from %s", sConfig.files.logSettings.c_str() );
    else
        sLog.Warning( "server init", "Unable to read %s (this file is optional)", sConfig.files.logSettings.c_str() );

    // open up the log file if specified ( will be removed )
    if( !sConfig.files.log.empty() )
    {
        if( log_open_logfile( sConfig.files.log.c_str() ) )
            sLog.Success( "server init", "Opened log file %s", sConfig.files.log.c_str() );
        else
            sLog.Warning( "server init", "Unable to open log file '%s', only logging to the screen now.", sConfig.files.log.c_str() );
    }

    //connect to the database...
    DBerror err;
    if( !sDatabase.Open( err,
        sConfig.database.host.c_str(),
        sConfig.database.username.c_str(),
        sConfig.database.password.c_str(),
        sConfig.database.db.c_str(),
        sConfig.database.port ) )
    {
        sLog.Error( "server init", "Unable to connect to the database: %s", err.c_str() );
        return 1;
    }
    _sDgmTypeAttrMgr = new dgmtypeattributemgr(); // needs to be after db init as its using it

    _sDgmTypeAttrMgr = new dgmtypeattributemgr(); // needs to be after db init as its using it

    //Start up the TCP server
    EVETCPServer tcps;

    char errbuf[ TCPCONN_ERRBUF_SIZE ];
    if( tcps.Open( sConfig.net.port, errbuf ) )
    {
        sLog.Success( "server init", "TCP listener started on port %u.", sConfig.net.port );
    }
    else
    {
        sLog.Error( "server init", "Failed to start TCP listener on port %u: %s.", sConfig.net.port, errbuf );
        return 1;
    }
	//make the item factory
    ItemFactory item_factory( sEntityList );

    //now, the service manager...
    PyServiceMgr services( 888444, sEntityList, item_factory );

    //setup the command dispatcher
    CommandDispatcher command_dispatcher( services );
    RegisterAllCommands( command_dispatcher );

    /*
     * Service creation and registration.
     *
     */
    sLog.Log("server init", "Creating services.");

    services.RegisterService(new ClientStatsMgr(&services));
    services.RegisterService(new AgentMgrService(&services));
    services.RegisterService(new MissionMgrService(&services));
    services.RegisterService(new AccountService(&services));
    services.RegisterService(new UserService(&services));
    services.RegisterService(new AlertService(&services));
    services.RegisterService(new AuthService(&services));
    services.RegisterService(new BillMgrService(&services));
    services.RegisterService(new BookmarkService(&services));
    services.RegisterService(new BrowserLockDownService(&services));
    services.RegisterService(new CertificateMgrService(&services));
    services.RegisterService(new CharacterService(&services));
    services.RegisterService(new CharMgrService(&services));
    services.RegisterService(new ConfigService(&services));
    services.RegisterService(new LanguageService(&services));
    services.RegisterService(new CorpMgrService(&services));
    services.RegisterService(new CorpStationMgrService(&services));
    services.RegisterService(new CorporationService(&services));
    services.RegisterService(new CorpRegistryService(&services));
    services.RegisterService(new ContractProxyService(&services));
    services.RegisterService(new LPService(&services));
    services.RegisterService(new DogmaIMService(&services));
    services.RegisterService(new InvBrokerService(&services));
    services.RegisterService(services.lsc_service = new LSCService(&services, &command_dispatcher));
    services.RegisterService(services.cache_service = new ObjCacheService(&services, sConfig.files.cacheDir.c_str()));
    services.RegisterService(new LookupService(&services));
    services.RegisterService(new VoiceMgrService(&services));
    services.RegisterService(new ShipService(&services));
    services.RegisterService(new InsuranceService(&services));
    services.RegisterService(new BeyonceService(&services));
    services.RegisterService(new MapService(&services));
    services.RegisterService(new OnlineStatusService(&services));
    services.RegisterService(new Standing2Service(&services));
    services.RegisterService(new WarRegistryService(&services));
    services.RegisterService(new FactionWarMgrService(&services));
    services.RegisterService(new StationService(&services));
    services.RegisterService(new StationSvcService(&services));
    services.RegisterService(new JumpCloneService(&services));
    services.RegisterService(new KeeperService(&services));
    services.RegisterService(new DungeonService(&services));
    services.RegisterService(new SkillMgrService(&services));
    services.RegisterService(new TutorialService(&services));
    services.RegisterService(new PetitionerService(&services));
    services.RegisterService(new SlashService(&services, &command_dispatcher));
    services.RegisterService(new MarketProxyService(&services));
    services.RegisterService(new ContractMgrService(&services));
    services.RegisterService(new ReprocessingService(&services));
    services.RegisterService(new FactoryService(&services));
    services.RegisterService(new RamProxyService(&services));
    services.RegisterService(new PosMgrService(&services));
    services.RegisterService(new NetService(&services));
	services.RegisterService(new TradeService(&services));
	services.RegisterService(new CharUnboundMgrService(&services));
	services.RegisterService(new PaperDollService(&services));
	services.RegisterService(new PhotoUploadService(&services));
	services.RegisterService(new AggressionMgrService(&services));
	services.RegisterService(new SovereigntyMgrService(&services));

    sLog.Log("server init", "Priming cached objects.");
    services.cache_service->PrimeCache();
    sLog.Log("server init", "finished priming");

	// start up the image server
	ImageServer::get().Run();

    services.serviceDB().SetServerOnlineStatus(true);

    sLog.Log("server init", "Init done.");

    /*
     * THE MAIN LOOP
     *
     * Everything except IO should happen in this loop, in this thread context.
     *
     */

    /* program events system */
    SetupSignals();

    uint32 start;
    uint32 etime;
    uint32 last_time = GetTickCount();

    EVETCPConnection* tcpc;
    while( RunLoops == true )
    {
        Timer::SetCurrentTime();
        start = GetTickCount();

        //check for timeouts in other threads
        //timeout_manager.CheckTimeouts();
        while( ( tcpc = tcps.PopConnection() ) )
        {
            Client* c = new Client( services, &tcpc );

            sEntityList.Add( &c );
        }

        sEntityList.Process();
        services.Process();

        /* UPDATE */
        last_time = GetTickCount();
        etime = last_time - start;

        // do the stuff for thread sleeping
        if( MAIN_LOOP_DELAY > etime )
            Sleep( MAIN_LOOP_DELAY - etime );
    }

    sLog.Log("server shutdown", "Main loop stopped" );

    tcps.Close();

    sLog.Log("server shutdown", "TCP listener stopped." );

    services.serviceDB().SetServerOnlineStatus(false);

    sLog.Log("server shutdown", "Cleanup db cache" );
    delete _sDgmTypeAttrMgr;

    log_close_logfile();

    // win crap.
    //_CrtDumpMemoryLeaks();
    return 0;
}
Пример #23
0
PyRep *MarketDB::CreateContract( uint32 characterID, uint32 characterCorpID, uint32 type, uint32 avail, uint32 assigneeID, uint32 expiretime, uint32 duration, uint32 startStationID, uint32 endStationID, uint32 startSolarSystemID, uint32 endSolarSystemID, uint32 startRegionID, uint32 endRegionID, uint32 price, uint32 reward, uint32 collateral, std::string title, std::string description/*, std::vector<int32> itemsID, std::vector<int32> quantity, uint32 flag, std::vector<int32> requestItemID, std::vector<int32> requestItemQuantity*/, bool forCorp )
{
	DBerror err;
	DBQueryResult res;
	DBResultRow row;
	uint32 contractID = 0;
	uint64 timeNow = Win32TimeNow();
	uint64 timeExpired = Win32TimeNow() + ((expiretime / 60) * Win32Time_Hour);
	uint8 numDays = ((expiretime / 60) * Win32Time_Hour) / Win32Time_Day ;

	if(endStationID == 0)endStationID = startStationID;
	if(!sDatabase.RunQuery(res,
		"SELECT solarSystemID, regionID"
		" FROM stastations"
		" WHERE stationID=%d", endStationID))
	{
		codelog(MARKET__ERROR, "Error in query: %s", res.error.c_str() );
		return NULL;
	}

	if( !res.GetRow(row) )
	{
		codelog(MARKET__ERROR, "StationID %u not found", endStationID);
		return NULL;
	}
	endSolarSystemID = row.GetInt( 0 );
	endRegionID = row.GetInt( 1 );

	if(assigneeID == 0)assigneeID = characterID;

	if(!sDatabase.RunQueryLID(err, contractID,
		"INSERT INTO"
		" contract("
		" contractID,"
		" issuerID,"
		" issuerCorpID,"
		" type,"
		" avail,"
		" assigneeID,"
		" expiretime,"
		" duration,"
		" startStationID,"
		" endStationID,"
		" startSolarSystemID,"
		" endSolarSystemID,"
		" startRegionID,"
		" endRegionID,"
		" price,"
		" reward,"
		" collateral,"
		" title,"
		" description,"
		" forCorp,"
		" status,"
		" isAccepted,"
		" acceptorID,"
		" dateIssued,"
		" dateExpired,"
		" dateAccepted,"
		" dateCompleted,"
		" volume" // This should be the volume of all the items
		")VALUES("
		"NULL, %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, '%s', '%s', %u, 0, false, NULL, " I64u ", " I64u ", NULL, " I64u ", 0)",
		characterID, characterCorpID, type, avail, assigneeID, expiretime, numDays, startStationID, endStationID, startSolarSystemID, 
		endSolarSystemID, startRegionID, endRegionID, price, reward, collateral, "contract title", "contract description", forCorp, timeNow, timeExpired, timeExpired))
	{
		codelog(MARKET__ERROR, "Error in query: %s", err.c_str() );
		return NULL;
	}

	if(!forCorp)
	{
		if(!sDatabase.RunQuery(err, 
			"UPDATE"
			" chrcontractinfo"
			" SET numOutStandingContractsNonCorp=numOutStandingContractsNonCorp+1,"
			" numOutstandingContracts=numOutstandingContracts+1"
			" WHERE characterID=%d", characterID))
		{
			codelog(MARKET__ERROR, "Error in query: %s", err.c_str() );
			return NULL;
		}
	}else{
		if(!sDatabase.RunQuery(err, 
			"UPDATE"
			" chrcontractinfo"
			" SET numOutStandingContractsForCorp=numOutStandingContractsForCorp+1,"
			" numOutstandingContracts=numOutstandingContracts+1"
			" WHERE characterID=%d", characterID))
		{
			codelog(MARKET__ERROR, "Error in query: %s", err.c_str() );
			return NULL;
		}
	}
	/*uint32 max = itemsID.capacity();
	uint32 i = 0;
	for(i = 0; i <= max; i++)
	{
		if(!sDatabase.RunQuery(err,
			"INSERT INTO contracts_items("
			" itemID,"
			" contractID,"
			" characterID,"
			" quantity,"
			" flag,"
			" get"
			") VALUES("
			" %d, %d, %d, %d, 4, false)",
			itemsID.at(i), contractID, characterID, quantity.at(i)
			))
		{
			codelog(MARKET__ERROR, "Error in query: %s", res.c_str() );
			return NULL;
		}
	}
	max = requestItemID.capacity();
	for(i = 0; i <= max; i++)
	{
		if(!sDatabase.RunQuery(err,
			"INSERT INTO contracts_items("
			" itemID,"
			" contractID,"
			" characterID,"
			" quantity,"
			" flag,"
			" get"
			") VALUES("
			" %d, %d, %d, %d, 4, true)",
			requestItemID.at(i), contractID, characterID, requestItemQuantity.at(i)
			))
		{
			codelog(MARKET__ERROR, "Error in query: %s", res.c_str() );
			return NULL;
		}
	}*/
	return new PyInt( contractID );
}