summaryrefslogtreecommitdiffstats
path: root/src/Bindings/LuaNameLookup.cpp
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2015-02-07 17:46:16 +0100
committerMattes D <github@xoft.cz>2015-02-07 17:46:16 +0100
commit512b1a6b0e3d68c62f638399061e129dcf61067f (patch)
tree0201d601f4f5e125a22298b730ac4903fa264415 /src/Bindings/LuaNameLookup.cpp
parentMerge pull request #1727 from mc-server/Entities (diff)
parentAPIDump: Added client and server examples. (diff)
downloadcuberite-512b1a6b0e3d68c62f638399061e129dcf61067f.tar
cuberite-512b1a6b0e3d68c62f638399061e129dcf61067f.tar.gz
cuberite-512b1a6b0e3d68c62f638399061e129dcf61067f.tar.bz2
cuberite-512b1a6b0e3d68c62f638399061e129dcf61067f.tar.lz
cuberite-512b1a6b0e3d68c62f638399061e129dcf61067f.tar.xz
cuberite-512b1a6b0e3d68c62f638399061e129dcf61067f.tar.zst
cuberite-512b1a6b0e3d68c62f638399061e129dcf61067f.zip
Diffstat (limited to 'src/Bindings/LuaNameLookup.cpp')
-rw-r--r--src/Bindings/LuaNameLookup.cpp88
1 files changed, 88 insertions, 0 deletions
diff --git a/src/Bindings/LuaNameLookup.cpp b/src/Bindings/LuaNameLookup.cpp
new file mode 100644
index 000000000..e52d8dbdc
--- /dev/null
+++ b/src/Bindings/LuaNameLookup.cpp
@@ -0,0 +1,88 @@
+
+// LuaNameLookup.cpp
+
+// Implements the cLuaNameLookup class used as the cNetwork API callbacks for name and IP lookups from Lua
+
+#include "Globals.h"
+#include "LuaNameLookup.h"
+
+
+
+
+
+cLuaNameLookup::cLuaNameLookup(const AString & a_Query, cPluginLua & a_Plugin, int a_CallbacksTableStackPos):
+ m_Plugin(a_Plugin),
+ m_Callbacks(a_Plugin.GetLuaState(), a_CallbacksTableStackPos),
+ m_Query(a_Query)
+{
+}
+
+
+
+
+
+void cLuaNameLookup::OnNameResolved(const AString & a_Name, const AString & a_IP)
+{
+ // Check if we're still valid:
+ if (!m_Callbacks.IsValid())
+ {
+ return;
+ }
+
+ // Call the callback:
+ cPluginLua::cOperation Op(m_Plugin);
+ if (!Op().Call(cLuaState::cTableRef(m_Callbacks, "OnNameResolved"), a_Name, a_IP))
+ {
+ LOGINFO("cNetwork name lookup OnNameResolved callback failed in plugin %s looking up %s. %s resolves to %s.",
+ m_Plugin.GetName().c_str(), m_Query.c_str(), a_Name.c_str(), a_IP.c_str()
+ );
+ }
+}
+
+
+
+
+
+void cLuaNameLookup::OnError(int a_ErrorCode, const AString & a_ErrorMsg)
+{
+ // Check if we're still valid:
+ if (!m_Callbacks.IsValid())
+ {
+ return;
+ }
+
+ // Call the callback:
+ cPluginLua::cOperation Op(m_Plugin);
+ if (!Op().Call(cLuaState::cTableRef(m_Callbacks, "OnError"), m_Query, a_ErrorCode, a_ErrorMsg))
+ {
+ LOGINFO("cNetwork name lookup OnError callback failed in plugin %s looking up %s. The error is %d (%s)",
+ m_Plugin.GetName().c_str(), m_Query.c_str(), a_ErrorCode, a_ErrorMsg.c_str()
+ );
+ }
+}
+
+
+
+
+
+void cLuaNameLookup::OnFinished(void)
+{
+ // Check if we're still valid:
+ if (!m_Callbacks.IsValid())
+ {
+ return;
+ }
+
+ // Call the callback:
+ cPluginLua::cOperation Op(m_Plugin);
+ if (!Op().Call(cLuaState::cTableRef(m_Callbacks, "OnFinished"), m_Query))
+ {
+ LOGINFO("cNetwork name lookup OnFinished callback failed in plugin %s, looking up %s.",
+ m_Plugin.GetName().c_str(), m_Query.c_str()
+ );
+ }
+}
+
+
+
+