// theming.cpp : Defines the entry point for the DLL application. // #include "bzfsAPI.h" #include #include #include std::list themes; BZ_GET_PLUGIN_VERSION class ThemeSet : public bz_CustomSlashCommandHandler { public: virtual bool handle ( int playerID, bzApiString /*command*/, bzApiString /*message*/, bzAPIStringList* params ) { bz_PlayerRecord *player = bz_getPlayerByIndex(playerID); if (!player) return true; if ( !player->admin ) { bz_sendTextMessage(BZ_SERVER,playerID,"You do not have permission to run /themeset"); bz_freePlayerRecord(player); return true; } if ( params->size() != 1) { bz_sendTextMessage(BZ_SERVER,playerID,"/themeset takes exactly 1 argument"); bz_freePlayerRecord(player); return true; } bool exists = false; for ( std::list::iterator i = themes.begin(); i != themes.end(); i++ ) if ( *i == params->get(1).c_str() ) exists = true; if (!exists) { bz_sendTextMessage(BZ_SERVER,playerID,(std::string("Theme ") + params->get(1).c_str() + " does not exist.").c_str()); bz_freePlayerRecord(player); return true; } bz_sendTextMessage(BZ_SERVER,BZ_ALLUSERS,(std::string("Theme ") + params->get(1).c_str() + " has been set.").c_str()); std::ifstream themeFile((std::string("themes/") + params->get(1).c_str() + ".thm").c_str()); std::string varName; while (themeFile >> varName) { std::string varValue; themeFile >> varValue; bz_setBZDBString(varName.c_str(), varValue.c_str()); } bz_freePlayerRecord(player); return true; } }; ThemeSet themeset; ThemeSet themereset; BZF_PLUGIN_CALL int bz_Load ( const char* /*commandLine*/ ) { bz_debugMessage(4,"theming plugin loaded"); std::ifstream themeIndex("themes.txt"); std::string theme; while (themeIndex >> theme) themes.push_back(theme); bz_registerCustomSlashCommand ( "themeset", &themeset ); bz_registerCustomSlashCommand ( "themereset", &themereset ); return 0; } BZF_PLUGIN_CALL int bz_Unload ( void ) { bz_registerCustomSlashCommand ( "themereset", &themereset ); bz_registerCustomSlashCommand ( "themeset", &themeset ); bz_debugMessage(4,"theming plugin unloaded"); return 0; } // Local Variables: *** // mode:C++ *** // tab-width: 8 *** // c-basic-offset: 2 *** // indent-tabs-mode: t *** // End: *** // ex: shiftwidth=2 tabstop=8