summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--source/Items/ItemBow.h2
-rw-r--r--source/ManualBindings.cpp8
-rw-r--r--source/Mobs/Wolf.cpp57
-rw-r--r--source/Mobs/Wolf.h7
-rw-r--r--source/OSSupport/IsThread.cpp7
-rw-r--r--source/OSSupport/IsThread.h13
-rw-r--r--source/PluginManager.cpp4
-rw-r--r--source/Server.cpp55
-rw-r--r--source/Server.h3
9 files changed, 119 insertions, 37 deletions
diff --git a/source/Items/ItemBow.h b/source/Items/ItemBow.h
index 79520c074..d533c21fd 100644
--- a/source/Items/ItemBow.h
+++ b/source/Items/ItemBow.h
@@ -72,7 +72,7 @@ public:
return;
}
a_Player->GetWorld()->BroadcastSpawnEntity(*Arrow);
- a_Player->GetWorld()->BroadcastSoundEffect("random.bow", (int)a_Player->GetPosX() * 8, (int)a_Player->GetPosY() * 8, (int)a_Player->GetPosZ() * 8, 0.5, Force);
+ a_Player->GetWorld()->BroadcastSoundEffect("random.bow", (int)a_Player->GetPosX() * 8, (int)a_Player->GetPosY() * 8, (int)a_Player->GetPosZ() * 8, 0.5, (float)Force);
if (!a_Player->IsGameModeCreative())
{
diff --git a/source/ManualBindings.cpp b/source/ManualBindings.cpp
index 37274e2af..f98e25880 100644
--- a/source/ManualBindings.cpp
+++ b/source/ManualBindings.cpp
@@ -1347,7 +1347,9 @@ static int tolua_cPluginManager_BindCommand(lua_State * L)
if (!self->BindCommand(Command, Plugin, Permission, HelpString))
{
- // Refused. Possibly already bound. Error message has been given, bail out silently.
+ // Refused. Possibly already bound. Error message has been given, display the callstack:
+ cLuaState LS(L);
+ LS.LogStackTrace();
return 0;
}
@@ -1409,7 +1411,9 @@ static int tolua_cPluginManager_BindConsoleCommand(lua_State * L)
if (!self->BindConsoleCommand(Command, Plugin, HelpString))
{
- // Refused. Possibly already bound. Error message has been given, bail out silently.
+ // Refused. Possibly already bound. Error message has been given, display the callstack:
+ cLuaState LS(L);
+ LS.LogStackTrace();
return 0;
}
diff --git a/source/Mobs/Wolf.cpp b/source/Mobs/Wolf.cpp
index b9db53c7f..c86250142 100644
--- a/source/Mobs/Wolf.cpp
+++ b/source/Mobs/Wolf.cpp
@@ -15,7 +15,7 @@ cWolf::cWolf(void) :
m_IsTame(false),
m_IsSitting(false),
m_IsBegging(false),
- m_Owner(""),
+ m_OwnerName(""),
m_CollarColor(14)
{
}
@@ -64,11 +64,11 @@ void cWolf::OnRightClicked(cPlayer & a_Player)
}
else if (IsTame())
{
- if (a_Player.GetName() == m_Owner) // Is the player the owner of the dog?
+ if (a_Player.GetName() == m_OwnerName) // Is the player the owner of the dog?
{
if (a_Player.GetEquippedItem().m_ItemType == E_ITEM_DYE)
{
- m_CollarColor = 15 - a_Player.GetEquippedItem().m_ItemDamage;
+ SetCollarColor(15 - a_Player.GetEquippedItem().m_ItemDamage);
if (!a_Player.IsGameModeCreative())
{
a_Player.GetInventory().RemoveOneEquippedItem();
@@ -141,38 +141,45 @@ void cWolf::Tick(float a_Dt, cChunk & a_Chunk)
}
}
}
-
+
+ if (IsTame())
+ {
+ TickFollowPlayer();
+ }
+}
+
+
+
+
+
+void cWolf::TickFollowPlayer()
+{
class cCallback :
public cPlayerListCallback
{
- virtual bool Item(cPlayer * Player) override
+ virtual bool Item(cPlayer * a_Player) override
{
- OwnerCoords = Player->GetPosition();
+ OwnerPos = a_Player->GetPosition();
return false;
}
public:
- Vector3f OwnerCoords;
+ Vector3f OwnerPos;
} Callback;
- m_World->DoWithPlayer(m_Owner, Callback);
- Vector3f OwnerCoords = Callback.OwnerCoords;
-
- if (IsTame())
+ if (m_World->DoWithPlayer(m_OwnerName, Callback))
{
- if (m_Owner != "")
+ // The player is present in the world, follow them:
+ double Distance = (Callback.OwnerPos - GetPosition()).Length();
+ if (Distance < 3)
{
- double Distance = (OwnerCoords - GetPosition()).Length();
- if (Distance < 3)
- {
- m_bMovingToDestination = false;
- }
- else if ((Distance > 30) && (!IsSitting()))
- {
- TeleportToCoords(OwnerCoords.x, OwnerCoords.y, OwnerCoords.z);
- }
- else
- {
- m_Destination = OwnerCoords;
- }
+ m_bMovingToDestination = false;
+ }
+ else if ((Distance > 30) && (!IsSitting()))
+ {
+ TeleportToCoords(Callback.OwnerPos.x, Callback.OwnerPos.y, Callback.OwnerPos.z);
+ }
+ else
+ {
+ m_Destination = Callback.OwnerPos;
}
}
}
diff --git a/source/Mobs/Wolf.h b/source/Mobs/Wolf.h
index d51d4e78a..040e2cf7a 100644
--- a/source/Mobs/Wolf.h
+++ b/source/Mobs/Wolf.h
@@ -21,13 +21,14 @@ public:
virtual void DoTakeDamage(TakeDamageInfo & a_TDI) override;
virtual void OnRightClicked(cPlayer & a_Player) override;
virtual void Tick(float a_Dt, cChunk & a_Chunk) override;
+ virtual void TickFollowPlayer();
// Get functions
bool IsSitting (void) const { return m_IsSitting; }
bool IsTame (void) const { return m_IsTame; }
bool IsBegging (void) const { return m_IsBegging; }
bool IsAngry (void) const { return m_IsAngry; }
- AString GetOwner (void) const { return m_Owner; }
+ AString GetOwner (void) const { return m_OwnerName; }
int GetCollarColor(void) const { return m_CollarColor; }
// Set functions
@@ -35,7 +36,7 @@ public:
void SetIsTame (bool a_IsTame) { m_IsTame = a_IsTame; }
void SetIsBegging (bool a_IsBegging) { m_IsBegging = a_IsBegging; }
void SetIsAngry (bool a_IsAngry) { m_IsAngry = a_IsAngry; }
- void SetOwner (AString a_NewOwner) { m_Owner = a_NewOwner; }
+ void SetOwner (AString a_NewOwner) { m_OwnerName = a_NewOwner; }
void SetCollarColor(int a_CollarColor) { m_CollarColor = a_CollarColor; }
protected:
@@ -44,7 +45,7 @@ protected:
bool m_IsTame;
bool m_IsBegging;
bool m_IsAngry;
- AString m_Owner;
+ AString m_OwnerName;
int m_CollarColor;
} ;
diff --git a/source/OSSupport/IsThread.cpp b/source/OSSupport/IsThread.cpp
index e1ef84c17..4da9f9949 100644
--- a/source/OSSupport/IsThread.cpp
+++ b/source/OSSupport/IsThread.cpp
@@ -53,7 +53,7 @@ static void SetThreadName( DWORD dwThreadID, LPCSTR szThreadName)
cIsThread::cIsThread(const AString & iThreadName) :
m_ThreadName(iThreadName),
m_ShouldTerminate(false),
- m_Handle(NULL)
+ m_Handle(NULL_HANDLE)
{
}
@@ -73,8 +73,7 @@ cIsThread::~cIsThread()
bool cIsThread::Start(void)
{
- ASSERT(m_Handle == NULL); // Has already started one thread?
-
+ ASSERT(m_Handle == NULL_HANDLE); // Has already started one thread?
#ifdef _WIN32
// Create the thread suspended, so that the mHandle variable is valid in the thread procedure
DWORD ThreadID = 0;
@@ -111,7 +110,7 @@ bool cIsThread::Start(void)
void cIsThread::Stop(void)
{
- if (m_Handle == NULL)
+ if (m_Handle == NULL_HANDLE)
{
return;
}
diff --git a/source/OSSupport/IsThread.h b/source/OSSupport/IsThread.h
index 2ea8bf6f9..b8784ea33 100644
--- a/source/OSSupport/IsThread.h
+++ b/source/OSSupport/IsThread.h
@@ -51,15 +51,28 @@ public:
protected:
AString m_ThreadName;
+ // Value used for "no handle":
+ #ifdef _WIN32
+ #define NULL_HANDLE NULL
+ #else
+ #define NULL_HANDLE 0
+ #endif
+
#ifdef _WIN32
HANDLE m_Handle;
static DWORD_PTR __stdcall thrExecute(LPVOID a_Param)
{
+ // Create a window so that the thread can be identified by 3rd party tools:
HWND IdentificationWnd = CreateWindow("STATIC", ((cIsThread *)a_Param)->m_ThreadName.c_str(), 0, 0, 0, 0, WS_OVERLAPPED, NULL, NULL, NULL, NULL);
+
+ // Run the thread:
((cIsThread *)a_Param)->Execute();
+
+ // Destroy the identification window:
DestroyWindow(IdentificationWnd);
+
return 0;
}
diff --git a/source/PluginManager.cpp b/source/PluginManager.cpp
index 3ac2366ca..c1f695163 100644
--- a/source/PluginManager.cpp
+++ b/source/PluginManager.cpp
@@ -1511,11 +1511,11 @@ bool cPluginManager::BindConsoleCommand(const AString & a_Command, cPlugin * a_P
{
if (cmd->second.m_Plugin == NULL)
{
- LOGWARNING("Console command \"%s\" is already bound internally by MCServer.", a_Command.c_str());
+ LOGWARNING("Console command \"%s\" is already bound internally by MCServer, cannot bind in plugin \"%s\".", a_Command.c_str(), a_Plugin->GetName().c_str());
}
else
{
- LOGWARNING("Console command \"%s\" is already bound to plugin \"%s\".", a_Command.c_str(), cmd->second.m_Plugin->GetName().c_str());
+ LOGWARNING("Console command \"%s\" is already bound to plugin \"%s\", cannot bind in plugin \"%s\".", a_Command.c_str(), cmd->second.m_Plugin->GetName().c_str(), a_Plugin->GetName().c_str());
}
return false;
}
diff --git a/source/Server.cpp b/source/Server.cpp
index 75ce35cb7..fe8076631 100644
--- a/source/Server.cpp
+++ b/source/Server.cpp
@@ -462,6 +462,18 @@ void cServer::ExecuteConsoleCommand(const AString & a_Cmd, cCommandOutputCallbac
return;
}
+ // "help" and "reload" are to be handled by MCS, so that they work no matter what
+ if (split[0] == "help")
+ {
+ PrintHelp(split, a_Output);
+ return;
+ }
+ if (split[0] == "reload")
+ {
+ cPluginManager::Get()->ReloadPlugins();
+ return;
+ }
+
// There is currently no way a plugin can do these (and probably won't ever be):
if (split[0].compare("chunkstats") == 0)
{
@@ -500,9 +512,52 @@ void cServer::ExecuteConsoleCommand(const AString & a_Cmd, cCommandOutputCallbac
+void cServer::PrintHelp(const AStringVector & a_Split, cCommandOutputCallback & a_Output)
+{
+ typedef std::pair<AString, AString> AStringPair;
+ typedef std::vector<AStringPair> AStringPairs;
+
+ class cCallback :
+ public cPluginManager::cCommandEnumCallback
+ {
+ public:
+ cCallback(void) : m_MaxLen(0) {}
+
+ virtual bool Command(const AString & a_Command, const cPlugin * a_Plugin, const AString & a_Permission, const AString & a_HelpString) override
+ {
+ if (!a_HelpString.empty())
+ {
+ m_Commands.push_back(AStringPair(a_Command, a_HelpString));
+ if (m_MaxLen < a_Command.length())
+ {
+ m_MaxLen = a_Command.length();
+ }
+ }
+ return false;
+ }
+
+ AStringPairs m_Commands;
+ size_t m_MaxLen;
+ } Callback;
+ cPluginManager::Get()->ForEachConsoleCommand(Callback);
+ std::sort(Callback.m_Commands.begin(), Callback.m_Commands.end());
+ for (AStringPairs::const_iterator itr = Callback.m_Commands.begin(), end = Callback.m_Commands.end(); itr != end; ++itr)
+ {
+ const AStringPair & cmd = *itr;
+ a_Output.Out(Printf("%-*s%s\n", Callback.m_MaxLen, cmd.first.c_str(), cmd.second.c_str()));
+ } // for itr - Callback.m_Commands[]
+ a_Output.Finished();
+}
+
+
+
+
+
void cServer::BindBuiltInConsoleCommands(void)
{
cPluginManager * PlgMgr = cPluginManager::Get();
+ PlgMgr->BindConsoleCommand("help", NULL, " - Shows the available commands");
+ PlgMgr->BindConsoleCommand("reload", NULL, " - Reloads all plugins");
PlgMgr->BindConsoleCommand("restart", NULL, " - Restarts the server cleanly");
PlgMgr->BindConsoleCommand("stop", NULL, " - Stops the server cleanly");
PlgMgr->BindConsoleCommand("chunkstats", NULL, " - Displays detailed chunk memory statistics");
diff --git a/source/Server.h b/source/Server.h
index 6742153ac..1b4848318 100644
--- a/source/Server.h
+++ b/source/Server.h
@@ -57,6 +57,9 @@ public: // tolua_export
/// Executes the console command, sends output through the specified callback
void ExecuteConsoleCommand(const AString & a_Cmd, cCommandOutputCallback & a_Output);
+
+ /// Lists all available console commands and their helpstrings
+ void PrintHelp(const AStringVector & a_Split, cCommandOutputCallback & a_Output);
/// Binds the built-in console commands with the plugin manager
static void BindBuiltInConsoleCommands(void);