Permalink
Browse files

Removed the need to require defining FADOR_PLUGIN.

This is done by removing the ifdef cases since fador's plugin api has been selected as the api for mineservers.
  • Loading branch information...
1 parent 026572f commit c2c7484b276f3a32932ebe4dbf6e7509e27e0798 @donno donno committed Jan 29, 2011
Showing with 35 additions and 65 deletions.
  1. +6 −8 src/mineserver.cpp
  2. +1 −2 src/mineserver.h
  3. +16 −43 src/plugin.cpp
  4. +12 −12 src/plugin.h
View
@@ -209,15 +209,15 @@ event_base* Mineserver::getEventBase()
}
void Mineserver::saveAll(){
- for(int i = 0; i<m_map.size(); i++){
+ for(std::vector<Map*>::size_type i = 0; i<m_map.size(); i++){
m_map[i]->saveWholeMap();
}
saveAllPlayers();
}
void Mineserver::saveAllPlayers()
{
- for (int i = users().size()-1; i >= 0; i--)
+ for (std::vector<User*>::size_type i = users().size()-1; i >= 0; i--)
{
if (users()[i]->logged)
{
@@ -231,9 +231,7 @@ int Mineserver::run(int argc, char *argv[])
uint32_t starttime = (uint32_t)time(0);
uint32_t tick = (uint32_t)time(0);
-#ifdef FADOR_PLUGIN
init_plugin_api();
-#endif
if (Mineserver::get()->config()->bData("system.interface.use_cli"))
{
@@ -427,7 +425,7 @@ int Mineserver::run(int argc, char *argv[])
if(m_saveInterval != 0 && timeNow-m_lastSave >= m_saveInterval)
{
//Save
- for(int i =0; i<m_map.size();i++)
+ for(std::vector<Map*>::size_type i =0; i<m_map.size();i++)
{
m_map[i]->saveWholeMap();
}
@@ -449,7 +447,7 @@ int Mineserver::run(int argc, char *argv[])
}
//Check for tree generation from saplings
- for(int i = 0; i<m_map.size(); i++)
+ for(std::vector<Map*>::size_type i = 0; i<m_map.size(); i++)
{
m_map[i]->checkGenTrees();
}
@@ -497,7 +495,7 @@ int Mineserver::run(int argc, char *argv[])
}
- for(int i = 0 ; i<m_map.size(); i++)
+ for(std::vector<Map*>::size_type i = 0 ; i<m_map.size(); i++)
{
m_map[i]->mapTime+=20;
if (m_map[i]->mapTime >= 24000)
@@ -553,7 +551,7 @@ int Mineserver::run(int argc, char *argv[])
saveAll();
/* Free memory */
- for(int i =0; i<m_map.size();i++)
+ for(std::vector<Map*>::size_type i =0; i<m_map.size();i++)
{
delete m_map[i];
delete m_physics[i];
View
@@ -56,11 +56,10 @@ class Inventory;
class Mobs;
class Mob;
-#ifdef FADOR_PLUGIN
#define MINESERVER
#include "plugin_api.h"
#undef MINESERVER
-#endif
+
struct event_base;
View
@@ -108,11 +108,7 @@ void Plugin::free()
bool Plugin::loadPlugin(const std::string name, const std::string file)
{
LIBRARY_HANDLE lhandle = NULL;
-#ifdef FADOR_PLUGIN
void (*fhandle)(mineserver_pointer_struct*) = NULL;
-#else
- void (*fhandle)(Mineserver*) = NULL;
-#endif
if (!file.empty())
{
@@ -156,34 +152,22 @@ bool Plugin::loadPlugin(const std::string name, const std::string file)
m_libraryHandles[name] = lhandle;
-#ifdef FADOR_PLUGIN
fhandle = (void (*)(mineserver_pointer_struct*)) LIBRARY_SYMBOL(lhandle, (name+"_init").c_str());
-#else
- fhandle = (void (*)(Mineserver*)) LIBRARY_SYMBOL(lhandle, (name+"_init").c_str());
-#endif
if (fhandle == NULL)
{
LOG(INFO, "Plugin", "Could not get init function handle!");
unloadPlugin(name);
return false;
}
-#ifdef FADOR_PLUGIN
fhandle(&plugin_api_pointers);
-#else
- fhandle(Mineserver::get());
-#endif
return true;
}
void Plugin::unloadPlugin(const std::string name)
{
LIBRARY_HANDLE lhandle = NULL;
-#ifdef FADOR_PLUGIN
void (*fhandle)(void) = NULL;
-#else
- void (*fhandle)(Mineserver*) = NULL;
-#endif
if (m_pluginVersions.find(name) != m_pluginVersions.end())
{
@@ -199,25 +183,15 @@ void Plugin::unloadPlugin(const std::string name)
lhandle = LIBRARY_SELF();
}
-#ifdef FADOR_PLUGIN
fhandle = (void (*)(void)) LIBRARY_SYMBOL(lhandle, (name+"_shutdown").c_str());
-#else
- fhandle = (void (*)(Mineserver*)) LIBRARY_SYMBOL(lhandle, (name+"_shutdown").c_str());
-#endif
-
if (fhandle == NULL)
{
LOG(INFO, "Plugin","Could not get shutdown function handle!");
}
else
{
LOG(INFO, "Plugin","Calling shutdown function for `"+name+"'.");
-
-#ifdef FADOR_PLUGIN
fhandle();
-#else
- fhandle(Mineserver::get());
-#endif
}
LIBRARY_CLOSE(m_libraryHandles[name]);
@@ -228,10 +202,10 @@ void Plugin::unloadPlugin(const std::string name)
}
}
-bool Plugin::hasHook(const std::string name)
+bool Plugin::hasHook(const std::string& name)
{
- std::map<const std::string, Hook*>::iterator it_a = m_hooks.begin();
- std::map<const std::string, Hook*>::iterator it_b = m_hooks.end();
+ std::map<const std::string, Hook*>::const_iterator it_a = m_hooks.begin();
+ std::map<const std::string, Hook*>::const_iterator it_b = m_hooks.end();
for (;it_a!=it_b;++it_a)
{
if (it_a->first == name)
@@ -243,12 +217,12 @@ bool Plugin::hasHook(const std::string name)
return false;
}
-void Plugin::setHook(const std::string name, Hook* hook)
+void Plugin::setHook(const std::string& name, Hook* hook)
{
m_hooks[name] = hook;
}
-Hook* Plugin::getHook(const std::string name)
+Hook* Plugin::getHook(const std::string& name)
{
if (hasHook(name))
{
@@ -260,15 +234,15 @@ Hook* Plugin::getHook(const std::string name)
}
}
-void Plugin::remHook(const std::string name)
+void Plugin::remHook(const std::string& name)
{
if (hasHook(name))
{
m_hooks.erase(name);
}
}
-bool Plugin::hasPluginVersion(const std::string name)
+bool Plugin::hasPluginVersion(const std::string& name)
{
std::map<const std::string, float>::iterator it_a = m_pluginVersions.begin();
std::map<const std::string, float>::iterator it_b = m_pluginVersions.end();
@@ -284,7 +258,7 @@ bool Plugin::hasPluginVersion(const std::string name)
return false;
}
-float Plugin::getPluginVersion(const std::string name)
+float Plugin::getPluginVersion(const std::string& name)
{
if (hasPluginVersion(name))
{
@@ -296,40 +270,39 @@ float Plugin::getPluginVersion(const std::string name)
}
}
-void Plugin::setPluginVersion(const std::string name, float version)
+void Plugin::setPluginVersion(const std::string& name, float version)
{
m_pluginVersions[name] = version;
}
-void Plugin::remPluginVersion(const std::string name)
+void Plugin::remPluginVersion(const std::string& name)
{
if (hasPluginVersion(name))
{
m_pluginVersions.erase(name);
}
}
-bool Plugin::hasPointer(const std::string name)
+bool Plugin::hasPointer(const std::string& name)
{
- std::map<const std::string, void*>::iterator it_a = m_pointers.begin();
- std::map<const std::string, void*>::iterator it_b = m_pointers.end();
+ std::map<const std::string, void*>::const_iterator it_a = m_pointers.begin();
+ std::map<const std::string, void*>::const_iterator it_b = m_pointers.end();
for (;it_a!=it_b;++it_a)
{
if (it_a->first == name)
{
return true;
}
}
-
return false;
}
-void Plugin::setPointer(const std::string name, void* pointer)
+void Plugin::setPointer(const std::string& name, void* pointer)
{
m_pointers[name] = pointer;
}
-void* Plugin::getPointer(const std::string name)
+void* Plugin::getPointer(const std::string& name)
{
if (hasPointer(name))
{
@@ -341,7 +314,7 @@ void* Plugin::getPointer(const std::string name)
}
}
-void Plugin::remPointer(const std::string name)
+void Plugin::remPointer(const std::string& name)
{
if (hasPointer(name))
{
View
@@ -85,23 +85,23 @@ class Plugin
{
public:
// Hook registry stuff
- bool hasHook(const std::string name);
- Hook* getHook(const std::string name);
- void setHook(const std::string name, Hook* hook);
- void remHook(const std::string name);
+ bool hasHook(const std::string& name);
+ Hook* getHook(const std::string& name);
+ void setHook(const std::string& name, Hook* hook);
+ void remHook(const std::string& name);
// Load/Unload plugins
bool loadPlugin(const std::string name, const std::string file="");
void unloadPlugin(const std::string name);
// Plugin version registry
- bool hasPluginVersion(const std::string name);
- float getPluginVersion(const std::string name);
- void setPluginVersion(const std::string name, float version);
- void remPluginVersion(const std::string name);
+ bool hasPluginVersion(const std::string& name);
+ float getPluginVersion(const std::string& name);
+ void setPluginVersion(const std::string& name, float version);
+ void remPluginVersion(const std::string& name);
// Pointer registry stuff
- bool hasPointer(const std::string name);
- void setPointer(const std::string name, void* pointer);
- void* getPointer(const std::string name);
- void remPointer(const std::string name);
+ bool hasPointer(const std::string& name);
+ void setPointer(const std::string& name, void* pointer);
+ void* getPointer(const std::string& name);
+ void remPointer(const std::string& name);
// Create default hooks
Plugin()
{

0 comments on commit c2c7484

Please sign in to comment.