summaryrefslogtreecommitdiffstats
path: root/MCServer
diff options
context:
space:
mode:
Diffstat (limited to 'MCServer')
-rw-r--r--MCServer/Plugins/APIDump/APIDesc.lua50
-rw-r--r--MCServer/Plugins/APIDump/Classes/Network.lua84
-rw-r--r--MCServer/Plugins/APIDump/Hooks/OnEntityTeleport.lua29
-rw-r--r--MCServer/Plugins/Debuggers/Debuggers.lua63
-rw-r--r--MCServer/Plugins/Debuggers/Info.lua16
-rw-r--r--MCServer/Plugins/HookNotify/HookNotify.lua17
-rw-r--r--MCServer/Plugins/InfoReg.lua3
-rw-r--r--MCServer/Plugins/NetworkTest/Info.lua54
-rw-r--r--MCServer/Plugins/NetworkTest/NetworkTest.lua257
-rw-r--r--MCServer/webadmin/files/guest.html20
-rw-r--r--MCServer/webadmin/login_template.html2
11 files changed, 550 insertions, 45 deletions
diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua
index 4c8dbd1e9..63fccb2f6 100644
--- a/MCServer/Plugins/APIDump/APIDesc.lua
+++ b/MCServer/Plugins/APIDump/APIDesc.lua
@@ -685,6 +685,28 @@ end</pre>
},
}, -- cCraftingRecipe
+ cCryptoHash =
+ {
+ Desc =
+ [[
+ Provides functions for generating cryptographic hashes.</p>
+ <p>
+ Note that all functions in this class are static, so they should be called in the dot convention:
+<pre class="prettyprint lang-lua">
+local Hash = cCryptoHash.sha1HexString("DataToHash")
+</pre></p>
+ <p>Each cryptographic hash has two variants, one returns the hash as a raw binary string, the other returns the hash as a hex-encoded string twice as long as the binary string.
+ ]],
+
+ Functions =
+ {
+ md5 = { Params = "Data", Return = "string", Notes = "(STATIC) Calculates the md5 hash of the data, returns it as a raw (binary) string of 16 characters." },
+ md5HexString = { Params = "Data", Return = "string", Notes = "(STATIC) Calculates the md5 hash of the data, returns it as a hex-encoded string of 32 characters." },
+ sha1 = { Params = "Data", Return = "string", Notes = "(STATIC) Calculates the sha1 hash of the data, returns it as a raw (binary) string of 20 characters." },
+ sha1HexString = { Params = "Data", Return = "string", Notes = "(STATIC) Calculates the sha1 hash of the data, returns it as a hex-encoded string of 40 characters." },
+ },
+ }, -- cCryptoHash
+
cEnchantments =
{
Desc = [[
@@ -903,8 +925,8 @@ end</pre>
{ Params = "DamageType, AttackerEntity, RawDamage, KnockbackAmount", Return = "", Notes = "Causes this entity to take damage of the specified type, from the specified attacker (may be nil). The final damage is calculated from RawDamage using the currently equipped armor." },
{ Params = "DamageType, ArrackerEntity, RawDamage, FinalDamage, KnockbackAmount", Return = "", Notes = "Causes this entity to take damage of the specified type, from the specified attacker (may be nil). The values are wrapped into a {{TakeDamageInfo}} structure and applied directly." },
},
- TeleportToCoords = { Params = "PosX, PosY, PosZ", Return = "", Notes = "Teleports the entity to the specified coords." },
- TeleportToEntity = { Params = "DestEntity", Return = "", Notes = "Teleports this entity to the specified destination entity." },
+ TeleportToCoords = { Params = "PosX, PosY, PosZ", Return = "", Notes = "Teleports the entity to the specified coords. Asks plugins if the teleport is allowed." },
+ TeleportToEntity = { Params = "DestEntity", Return = "", Notes = "Teleports this entity to the specified destination entity. Asks plugins if the teleport is allowed." },
},
Constants =
{
@@ -2232,6 +2254,27 @@ end
ShouldAuthenticate = { Params = "", Return = "bool", Notes = "Returns true iff the server is set to authenticate players (\"online mode\")." },
},
}, -- cServer
+
+ cStringCompression =
+ {
+ Desc = [[
+ Provides functions to compress or decompress string
+ <p>
+ All functions in this class are static, so they should be called in the dot convention:
+<pre class="prettyprint lang-lua">
+local CompressedString = cStringCompression.CompressStringGZIP("DataToCompress")
+</pre>
+ ]],
+
+ Functions =
+ {
+ CompressStringGZIP = {Params = "string", Return = "string", Notes = "Compress a string using GZIP"},
+ CompressStringZLIB = {Params = "string, factor", Return = "string", Notes = "Compresses a string using ZLIB. Factor 0 is no compression and factor 9 is maximum compression"},
+ InflateString = {Params = "string", Return = "string", Notes = "Uncompresses a string using Inflate"},
+ UncompressStringGZIP = {Params = "string", Return = "string", Notes = "Uncompress a string using GZIP"},
+ UncompressStringZLIB = {Params = "string, uncompressed length", Return = "string", Notes = "Uncompresses a string using ZLIB"},
+ },
+ },
cTeam =
{
@@ -2922,6 +2965,7 @@ end
RotateBlockFaceCW = { Params = "{{Globals#BlockFaces|eBlockFace}}", Return = "{{Globals#BlockFaces|eBlockFace}}", Notes = "Returns the {{Globals#BlockFaces|eBlockFace}} that corresponds to the given {{Globals#BlockFaces|eBlockFace}} after rotating it around the Y axis 90 degrees clockwise." },
StringSplit = {Params = "string, SeperatorsString", Return = "array table of strings", Notes = "Seperates string into multiple by splitting every time any of the characters in SeperatorsString is encountered."},
StringSplitAndTrim = {Params = "string, SeperatorsString", Return = "array table of strings", Notes = "Seperates string into multiple by splitting every time any of the characters in SeperatorsString is encountered. Each of the separate strings is trimmed (whitespace removed from the beginning and end of the string)"},
+ StringSplitWithQuotes = {Params = "string, SeperatorsString", Return = "array table of strings", Notes = "Seperates string into multiple by splitting every time any of the characters in SeperatorsString is encountered. Whitespace wrapped with single or double quotes will be ignored"},
StringToBiome = {Params = "string", Return = "{{Globals#BiomeTypes|BiomeType}}", Notes = "Converts a string representation to a {{Globals#BiomeTypes|BiomeType}} enumerated value"},
StringToDamageType = {Params = "string", Return = "{{Globals#DamageType|DamageType}}", Notes = "Converts a string representation to a {{Globals#DamageType|DamageType}} enumerated value."},
StringToDimension = {Params = "string", Return = "{{Globals#WorldDimension|Dimension}}", Notes = "Converts a string representation to a {{Globals#WorldDimension|Dimension}} enumerated value"},
@@ -2929,7 +2973,7 @@ end
StringToMobType = {Params = "string", Return = "{{Globals#MobType|MobType}}", Notes = "<b>DEPRECATED!</b> Please use cMonster:StringToMobType(). Converts a string representation to a {{Globals#MobType|MobType}} enumerated value"},
StripColorCodes = {Params = "string", Return = "string", Notes = "Removes all control codes used by MC for colors and styles"},
TrimString = {Params = "string", Return = "string", Notes = "Trims whitespace at both ends of the string"},
- md5 = {Params = "string", Return = "string", Notes = "converts a string to an md5 hash"},
+ md5 = {Params = "string", Return = "string", Notes = "<b>OBSOLETE</b>, use the {{cCryptoHash}} functions instead.<br>Converts a string to a raw binary md5 hash."},
},
ConstantGroups =
{
diff --git a/MCServer/Plugins/APIDump/Classes/Network.lua b/MCServer/Plugins/APIDump/Classes/Network.lua
index 065a743d8..c7626562d 100644
--- a/MCServer/Plugins/APIDump/Classes/Network.lua
+++ b/MCServer/Plugins/APIDump/Classes/Network.lua
@@ -31,11 +31,12 @@ local Server = cNetwork:Listen(1024, ListenCallbacks);
specific plugin-provided function is called. The callbacks are stored in tables which are passed
to the API functions, each table contains multiple callbacks for the various situations.</p>
<p>
- There are three different callback variants used: LinkCallbacks, LookupCallbacks and
- ListenCallbacks. Each is used in the situation appropriate by its name - LinkCallbacks are used
+ There are four different callback variants used: LinkCallbacks, LookupCallbacks, ListenCallbacks
+ and UDPCallbacks. Each is used in the situation appropriate by its name - LinkCallbacks are used
for handling the traffic on a single network link (plus additionally creation of such link when
- connecting as a client), LookupCallbacks are used when doing DNS and reverse-DNS lookups, and
- ListenCallbacks are used for handling incoming connections as a server.</p>
+ connecting as a client), LookupCallbacks are used when doing DNS and reverse-DNS lookups,
+ ListenCallbacks are used for handling incoming connections as a server and UDPCallbacks are used
+ for incoming UDP datagrams.</p>
<p>
LinkCallbacks have the following structure:<br/>
<pre class="prettyprint lang-lua">
@@ -111,7 +112,7 @@ local ListenCallbacks =
OnError = function (a_ErrorCode, a_ErrorMsg)
-- The specified error has occured while trying to listen
- -- No other callback will be called for this lookup from now on
+ -- No other callback will be called for this server handle from now on
-- This callback is called before the cNetwork:Listen() call returns
-- All returned values are ignored
end,
@@ -124,6 +125,25 @@ local ListenCallbacks =
end,
}
</pre></p>
+ <p>
+ UDPCallbacks have the following structure:<br/>
+<pre class="prettyprint lang-lua">
+local UDPCallbacks =
+{
+ OnError = function (a_ErrorCode, a_ErrorMsg)
+ -- The specified error has occured when trying to listen for incoming UDP datagrams
+ -- No other callback will be called for this endpoint from now on
+ -- This callback is called before the cNetwork:CreateUDPEndpoint() call returns
+ -- All returned values are ignored
+ end,
+
+ OnReceivedData = function ({{cUDPEndpoint|a_UDPEndpoint}}, a_Data, a_RemotePeer, a_RemotePort)
+ -- A datagram has been received on the {{cUDPEndpoint|endpoint}} from the specified remote peer
+ -- a_Data contains the raw received data, as a string
+ -- All returned values are ignored
+ end,
+}
+</pre>
]],
},
@@ -268,12 +288,32 @@ g_Server = nil
Functions =
{
Connect = { Params = "Host, Port, LinkCallbacks", Return = "bool", Notes = "(STATIC) Begins establishing a (client) TCP connection to the specified host. Uses the LinkCallbacks table to report progress, success, errors and incoming data. Returns false if it fails immediately (bad port value, bad hostname format), true otherwise. Host can be either an IP address or a hostname." },
+ CreateUDPEndpoint = { Params = "Port, UDPCallbacks", Return = "{{cUDPEndpoint|UDPEndpoint}}", Notes = "(STATIC) Creates a UDP endpoint that listens for incoming datagrams on the specified port, and can be used to send or broadcast datagrams. Uses the UDPCallbacks to report incoming datagrams or errors. If the endpoint cannot be created, the OnError callback is called with the error details and the returned endpoint will report IsOpen() == false. The plugin needs to store the returned endpoint object for as long as it needs the UDP port open; if the endpoint is garbage-collected by Lua, the socket will be closed and no more incoming data will be reported.<br>If the Port is zero, the OS chooses an available UDP port for the endpoint; use {{cUDPEndpoint}}:GetPort() to query the port number in such case." },
+ EnumLocalIPAddresses = { Params = "", Return = "array-table of strings", Notes = "(STATIC) Returns all local IP addresses for network interfaces currently available on the machine." },
HostnameToIP = { Params = "Host, LookupCallbacks", Return = "bool", Notes = "(STATIC) Begins a DNS lookup to find the IP address(es) for the specified host. Uses the LookupCallbacks table to report progress, success or errors. Returns false if it fails immediately (bad hostname format), true if the lookup started successfully. Host can be either a hostname or an IP address." },
IPToHostname = { Params = "Address, LookupCallbacks", Return = "bool", Notes = "(STATIC) Begins a reverse-DNS lookup to find out the hostname for the specified IP address. Uses the LookupCallbacks table to report progress, success or errors. Returns false if it fails immediately (bad address format), true if the lookup started successfully." },
Listen = { Params = "Port, ListenCallbacks", Return = "{{cServerHandle|ServerHandle}}", Notes = "(STATIC) Starts listening on the specified port. Uses the ListenCallbacks to report incoming connections or errors. Returns a {{cServerHandle}} object representing the server. If the listen operation failed, the OnError callback is called with the error details and the returned server handle will report IsListening() == false. The plugin needs to store the server handle object for as long as it needs the server running, if the server handle is garbage-collected by Lua, the listening socket will be closed and all current connections dropped." },
},
}, -- cNetwork
-
+
+ cServerHandle =
+ {
+ Desc =
+ [[
+ This class provides an interface for TCP sockets listening for a connection. In order to listen, the
+ plugin needs to use the {{cNetwork}}:Listen() function to create the listening socket.</p>
+ <p>
+ Note that when Lua garbage-collects this class, the listening socket is closed. Therefore the plugin
+ should keep it referenced in a global variable for as long as it wants the server running.
+ ]],
+
+ Functions =
+ {
+ Close = { Params = "", Return = "", Notes = "Closes the listening socket. No more connections will be accepted, and all current connections will be closed." },
+ IsListening = { Params = "", Return = "bool", Notes = "Returns true if the socket is listening." },
+ },
+ }, -- cServerHandle
+
cTCPLink =
{
Desc =
@@ -282,37 +322,49 @@ g_Server = nil
calling {{cNetwork}}:Connect() to connect to a remote server, or by listening using
{{cNetwork}}:Listen() and accepting incoming connections. The links are callback-based - when an event
such as incoming data or remote disconnect happens on the link, a specific callback is called. See the
- additional information in {{cNetwork}} documentation for details.
+ additional information in {{cNetwork}} documentation for details.</p>
+ <p>
+ The link can also optionally perform TLS encryption. Plugins can use the StartTLSClient() function to
+ start the TLS handshake as the client side. Since that call, the OnReceivedData() callback is
+ overridden internally so that the data is first routed through the TLS decryptor, and the plugin's
+ callback is only called for the decrypted data, once it starts arriving. The Send function changes its
+ behavior so that the data written by the plugin is first encrypted and only then sent over the
+ network. Note that calling Send() before the TLS handshake finishes is supported, but the data is
+ queued internally and only sent once the TLS handshake is completed.
]],
Functions =
{
+ Close = { Params = "", Return = "", Notes = "Closes the link forcefully (TCP RST). There's no guarantee that the last sent data is even being delivered. See also the Shutdown() method." },
GetLocalIP = { Params = "", Return = "string", Notes = "Returns the IP address of the local endpoint of the TCP connection." },
GetLocalPort = { Params = "", Return = "number", Notes = "Returns the port of the local endpoint of the TCP connection." },
GetRemoteIP = { Params = "", Return = "string", Notes = "Returns the IP address of the remote endpoint of the TCP connection." },
GetRemotePort = { Params = "", Return = "number", Notes = "Returns the port of the remote endpoint of the TCP connection." },
Send = { Params = "Data", Return = "", Notes = "Sends the data (raw string) to the remote peer. The data is sent asynchronously and there is no report on the success of the send operation, other than the connection being closed or reset by the underlying OS." },
+ Shutdown = { Params = "", Return = "", Notes = "Shuts the socket down for sending data. Notifies the remote peer that there will be no more data coming from us (TCP FIN). The data that is in flight will still be delivered. The underlying socket will be closed when the remote end shuts down as well, or after a timeout." },
+ StartTLSClient = { Params = "OwnCert, OwnPrivateKey, OwnPrivateKeyPassword", Return = "", Notes = "Starts a TLS handshake on the link, as a client side of the TLS. The Own___ parameters specify the client certificate and its corresponding private key and password; all three parameters are optional and no client certificate is presented to the remote peer if they are not used or all empty. Once the TLS handshake is started by this call, all incoming data is first decrypted before being sent to the OnReceivedData callback, and all outgoing data is queued until the TLS handshake completes, and then sent encrypted over the link." },
+ StartTLSServer = { Params = "Certificate, PrivateKey, PrivateKeyPassword, StartTLSData", Return = "", Notes = "Starts a TLS handshake on the link, as a server side of the TLS. The plugin needs to specify the server certificate and its corresponding private key and password. The StartTLSData can contain data that the link has already reported as received but it should be used as part of the TLS handshake. Once the TLS handshake is started by this call, all incoming data is first decrypted before being sent to the OnReceivedData callback, and all outgoing data is queued until the TLS handshake completes, and then sent encrypted over the link." },
},
}, -- cTCPLink
- cServerHandle =
+ cUDPEndpoint =
{
Desc =
[[
- This class provides an interface for TCP sockets listening for a connection. In order to listen, the
- plugin needs to use the {{cNetwork}}:Listen() function to create the listening socket.</p>
+ Represents a UDP socket that is listening for incoming datagrams on a UDP port and can send or broadcast datagrams to other peers on the network. Plugins can create an instance of the endpoint by calling {{cNetwork}}:CreateUDPEndpoint(). The endpoints are callback-based - when a datagram is read from the network, the OnRececeivedData() callback is called with details about the datagram. See the additional information in {{cNetwork}} documentation for details.</p>
<p>
- Note that when Lua garbage-collects this class, the listening socket is closed. Therefore the plugin
- should keep it referenced in a global variable for as long as it wants the server running.
+ Note that when Lua garbage-collects this class, the listening socket is closed. Therefore the plugin should keep this object referenced in a global variable for as long as it wants the endpoint open.
]],
Functions =
{
- Close = { Params = "", Return = "", Notes = "Closes the listening socket. No more connections will be accepted, and all current connections will be closed." },
- IsListening = { Params = "", Return = "bool", Notes = "Returns true if the socket is listening." },
+ Close = { Params = "", Return = "", Notes = "Closes the UDP endpoint. No more datagrams will be reported through the callbacks, the UDP port will be closed." },
+ EnableBroadcasts = { Params = "", Return = "", Notes = "Some OSes need this call before they allow UDP broadcasts on an endpoint." },
+ GetPort = { Params = "", Return = "number", Notes = "Returns the local port number of the UDP endpoint listening for incoming datagrams. Especially useful if the UDP endpoint was created with auto-assign port (0)." },
+ IsOpen = { Params = "", Return = "bool", Notes = "Returns true if the UDP endpoint is listening for incoming datagrams." },
+ Send = { Params = "RawData, RemoteHost, RemotePort", Return = "bool", Notes = "Sends the specified raw data (string) to the specified remote host. The RemoteHost can be either a hostname or an IP address; if it is a hostname, the endpoint will queue a DNS lookup first, if it is an IP address, the send operation is executed immediately. Returns true if there was no immediate error, false on any failure. Note that the return value needn't represent whether the packet was actually sent, only if it was successfully queued." },
},
-
- }, -- cServerHandle
+ }, -- cUDPEndpoint
}
diff --git a/MCServer/Plugins/APIDump/Hooks/OnEntityTeleport.lua b/MCServer/Plugins/APIDump/Hooks/OnEntityTeleport.lua
new file mode 100644
index 000000000..cdeb0947f
--- /dev/null
+++ b/MCServer/Plugins/APIDump/Hooks/OnEntityTeleport.lua
@@ -0,0 +1,29 @@
+return
+{
+ HOOK_ENTITY_TELEPORT =
+ {
+ CalledWhen = "Any entity teleports. Plugin may refuse teleport.",
+ DefaultFnName = "OnEntityTeleport", -- also used as pagename
+ Desc = [[
+ This function is called in each server tick for each {{cEntity|Entity}} that has
+ teleported. Plugins may refuse the teleport.
+ ]],
+ Params =
+ {
+ { Name = "Entity", Type = "{{cEntity}}", Notes = "The entity who has teleported. New position is set in the object after successfull teleport" },
+ { Name = "OldPosition", Type = "{{Vector3d}}", Notes = "The old position." },
+ { Name = "NewPosition", Type = "{{Vector3d}}", Notes = "The new position." },
+ },
+ Returns = [[
+ If the function returns true, teleport is prohibited.</p>
+ <p>
+ If the function returns false or no value, other plugins' callbacks are called and finally the new
+ position is permanently stored in the cEntity object.</p>
+ ]],
+ }, -- HOOK_ENTITY_TELEPORT
+}
+
+
+
+
+
diff --git a/MCServer/Plugins/Debuggers/Debuggers.lua b/MCServer/Plugins/Debuggers/Debuggers.lua
index a46072324..c8069a411 100644
--- a/MCServer/Plugins/Debuggers/Debuggers.lua
+++ b/MCServer/Plugins/Debuggers/Debuggers.lua
@@ -25,13 +25,14 @@ function Initialize(Plugin)
PM:AddHook(cPluginManager.HOOK_PLAYER_RIGHT_CLICKING_ENTITY, OnPlayerRightClickingEntity);
PM:AddHook(cPluginManager.HOOK_WORLD_TICK, OnWorldTick);
PM:AddHook(cPluginManager.HOOK_PLUGINS_LOADED, OnPluginsLoaded);
- PM:AddHook(cPluginManager.HOOK_PLUGIN_MESSAGE, OnPluginMessage);
PM:AddHook(cPluginManager.HOOK_PLAYER_JOINED, OnPlayerJoined);
PM:AddHook(cPluginManager.HOOK_PROJECTILE_HIT_BLOCK, OnProjectileHitBlock);
PM:AddHook(cPluginManager.HOOK_CHUNK_UNLOADING, OnChunkUnloading);
PM:AddHook(cPluginManager.HOOK_WORLD_STARTED, OnWorldStarted);
PM:AddHook(cPluginManager.HOOK_PROJECTILE_HIT_BLOCK, OnProjectileHitBlock);
+ -- _X: Disabled WECUI manipulation:
+ -- PM:AddHook(cPluginManager.HOOK_PLUGIN_MESSAGE, OnPluginMessage);
-- _X: Disabled so that the normal operation doesn't interfere with anything
-- PM:AddHook(cPluginManager.HOOK_CHUNK_GENERATED, OnChunkGenerated);
@@ -1476,7 +1477,7 @@ function HandleWESel(a_Split, a_Player)
SelCuboid:Expand(NumBlocks, NumBlocks, 0, 0, NumBlocks, NumBlocks)
-- Set the selection:
- local IsSuccess = cPluginManager:CallPlugin("WorldEdit", "SetPlayerCuboidSelection", a_Player, SelCuboid)
+ IsSuccess = cPluginManager:CallPlugin("WorldEdit", "SetPlayerCuboidSelection", a_Player, SelCuboid)
if not(IsSuccess) then
a_Player:SendMessage(cCompositeChat():SetMessageType(mtFailure):AddTextPart("Cannot adjust selection, WorldEdit reported failure while setting new selection"))
return true
@@ -1606,17 +1607,36 @@ end
-function HandleConsoleSchedule(a_Split)
- local prev = os.clock()
- LOG("Scheduling a task for 2 seconds in the future (current os.clock is " .. prev .. ")")
- cRoot:Get():GetDefaultWorld():ScheduleTask(40,
- function ()
- local current = os.clock()
- local diff = current - prev
- LOG("Scheduled function is called. Current os.clock is " .. current .. ", difference is " .. diff .. ")")
- end
- )
- return true, "Task scheduled"
+-- List of hashing functions to test:
+local HashFunctions =
+{
+ {"md5", md5 },
+ {"cCryptoHash.md5", cCryptoHash.md5 },
+ {"cCryptoHash.md5HexString", cCryptoHash.md5HexString },
+ {"cCryptoHash.sha1", cCryptoHash.sha1 },
+ {"cCryptoHash.sha1HexString", cCryptoHash.sha1HexString },
+}
+
+-- List of strings to try hashing:
+local HashExamples =
+{
+ "",
+ "\0",
+ "test",
+}
+
+function HandleConsoleHash(a_Split)
+ for _, str in ipairs(HashExamples) do
+ LOG("Hashing string \"" .. str .. "\":")
+ for _, hash in ipairs(HashFunctions) do
+ if not(hash[2]) then
+ LOG("Hash function " .. hash[1] .. " doesn't exist in the API!")
+ else
+ LOG(hash[1] .. "() = " .. hash[2](str))
+ end
+ end -- for hash - HashFunctions[]
+ end -- for str - HashExamples[]
+ return true
end
@@ -1704,3 +1724,20 @@ end
+
+function HandleConsoleSchedule(a_Split)
+ local prev = os.clock()
+ LOG("Scheduling a task for 2 seconds in the future (current os.clock is " .. prev .. ")")
+ cRoot:Get():GetDefaultWorld():ScheduleTask(40,
+ function ()
+ local current = os.clock()
+ local diff = current - prev
+ LOG("Scheduled function is called. Current os.clock is " .. current .. ", difference is " .. diff .. ")")
+ end
+ )
+ return true, "Task scheduled"
+end
+
+
+
+
diff --git a/MCServer/Plugins/Debuggers/Info.lua b/MCServer/Plugins/Debuggers/Info.lua
index b96ef3de5..63a4b9177 100644
--- a/MCServer/Plugins/Debuggers/Info.lua
+++ b/MCServer/Plugins/Debuggers/Info.lua
@@ -200,21 +200,29 @@ g_PluginInfo =
ConsoleCommands =
{
- ["sched"] =
+ ["hash"] =
{
- Handler = HandleConsoleSchedule,
- HelpString = "Tests the world scheduling",
+ Handler = HandleConsoleHash,
+ HelpString = "Tests the crypto hashing functions",
},
+
["loadchunk"] =
{
Handler = HandleConsoleLoadChunk,
HelpString = "Loads the specified chunk into memory",
},
+
["preparechunk"] =
{
Handler = HandleConsolePrepareChunk,
HelpString = "Prepares the specified chunk completely (load / gen / light)",
- }
+ },
+
+ ["sched"] =
+ {
+ Handler = HandleConsoleSchedule,
+ HelpString = "Tests the world scheduling",
+ },
}, -- ConsoleCommands
} -- g_PluginInfo
diff --git a/MCServer/Plugins/HookNotify/HookNotify.lua b/MCServer/Plugins/HookNotify/HookNotify.lua
index ed791090e..1d3d5088e 100644
--- a/MCServer/Plugins/HookNotify/HookNotify.lua
+++ b/MCServer/Plugins/HookNotify/HookNotify.lua
@@ -23,6 +23,7 @@ function Initialize(Plugin)
cPluginManager.AddHook(cPluginManager.HOOK_COLLECTING_PICKUP, OnCollectingPickup);
cPluginManager.AddHook(cPluginManager.HOOK_CRAFTING_NO_RECIPE, OnCraftingNoRecipe);
cPluginManager.AddHook(cPluginManager.HOOK_DISCONNECT, OnDisconnect);
+ cPluginManager.AddHook(cPluginManager.HOOK_ENTITY_TELEPORT, OnEntityTeleport);
cPluginManager.AddHook(cPluginManager.HOOK_EXECUTE_COMMAND, OnExecuteCommand);
cPluginManager.AddHook(cPluginManager.HOOK_HANDSHAKE, OnHandshake);
cPluginManager.AddHook(cPluginManager.HOOK_KILLING, OnKilling);
@@ -179,6 +180,22 @@ end
+function OnEntityTeleport(arg1,arg2,arg3)
+ if arg1.IsPlayer() then
+ -- if it's a player, get his name
+ LOG("OnEntityTeleport: Player: " .. arg1.GetName());
+ else
+ -- if it's a entity, get its type
+ LOG("OnEntityTeleport: EntityType: " .. arg1.GetEntityType());
+ end
+ LOG("OldPos: " .. arg2.x .. " / " .. arg2.y .. " / " .. arg2.z);
+ LOG("NewPos: " .. arg3.x .. " / " .. arg3.y .. " / " .. arg3.z);
+end
+
+
+
+
+
function OnExecuteCommand(...)
LogHook("OnExecuteCommand", unpack(arg));
diff --git a/MCServer/Plugins/InfoReg.lua b/MCServer/Plugins/InfoReg.lua
index 92c4a2e59..e34b79564 100644
--- a/MCServer/Plugins/InfoReg.lua
+++ b/MCServer/Plugins/InfoReg.lua
@@ -87,8 +87,7 @@ local function MultiCommandHandler(a_Split, a_Player, a_CmdString, a_CmdInfo, a_
LOG("Cannot find handler for command " .. a_CmdString .. " " .. Verb);
return false;
end
- MultiCommandHandler(a_Split, a_Player, a_CmdString .. " " .. Verb, Subcommand, a_Level + 1);
- return true;
+ return MultiCommandHandler(a_Split, a_Player, a_CmdString .. " " .. Verb, Subcommand, a_Level + 1);
end
-- Execute:
diff --git a/MCServer/Plugins/NetworkTest/Info.lua b/MCServer/Plugins/NetworkTest/Info.lua
index f366fd1be..d8c3095fe 100644
--- a/MCServer/Plugins/NetworkTest/Info.lua
+++ b/MCServer/Plugins/NetworkTest/Info.lua
@@ -50,6 +50,12 @@ g_PluginInfo =
}, -- ParameterCombinations
}, -- close
+ ips =
+ {
+ HelpString = "Prints all locally available IP addresses",
+ Handler = HandleConsoleNetIps,
+ }, -- ips
+
listen =
{
HelpString = "Creates a new listening socket on the specified port with the specified service attached to it",
@@ -84,6 +90,54 @@ g_PluginInfo =
},
}, -- lookup
+ udp =
+ {
+ Subcommands =
+ {
+ close =
+ {
+ Handler = HandleConsoleNetUdpClose,
+ ParameterCombinations =
+ {
+ {
+ Params = "[Port]",
+ Help = "Closes the UDP endpoint on the specified port [1024].",
+ }
+ },
+ }, -- close
+
+ listen =
+ {
+ Handler = HandleConsoleNetUdpListen,
+ ParameterCombinations =
+ {
+ {
+ Params = "[Port]",
+ Help = "Listens on the specified UDP port [1024], dumping the incoming datagrams into log",
+ },
+ },
+ }, -- listen
+
+ send =
+ {
+ Handler = HandleConsoleNetUdpSend,
+ ParameterCombinations =
+ {
+ {
+ Params = "[Host] [Port] [Message]",
+ Help = "Sends the message [\"hello\"] through UDP to the specified host [localhost] and port [1024]",
+ },
+ },
+ } -- send
+ }, -- Subcommands ("net udp")
+ }, -- udp
+
+ wasc =
+ {
+ HelpString = "Requests the webadmin homepage using https",
+ Handler = HandleConsoleNetWasc,
+ }, -- wasc
+
}, -- Subcommands
}, -- net
},
diff --git a/MCServer/Plugins/NetworkTest/NetworkTest.lua b/MCServer/Plugins/NetworkTest/NetworkTest.lua
index 7932f4b88..22056d4e9 100644
--- a/MCServer/Plugins/NetworkTest/NetworkTest.lua
+++ b/MCServer/Plugins/NetworkTest/NetworkTest.lua
@@ -11,6 +11,10 @@
-- g_Servers[PortNum] = cServerHandle
local g_Servers = {}
+--- Map of all UDP endpoints currently open
+-- g_UDPEndpoints[PortNum] = cUDPEndpoint
+local g_UDPEndpoints = {}
+
--- List of fortune messages for the fortune server
-- A random message is chosen for each incoming connection
-- The contents are loaded from the splashes.txt file on plugin startup
@@ -19,6 +23,62 @@ local g_Fortunes =
"Empty splashes.txt",
}
+-- HTTPS certificate to be used for the SSL server:
+local g_HTTPSCert = [[
+-----BEGIN CERTIFICATE-----
+MIIDfzCCAmegAwIBAgIJAOBHN+qOWodcMA0GCSqGSIb3DQEBBQUAMFYxCzAJBgNV
+BAYTAmN6MQswCQYDVQQIDAJjejEMMAoGA1UEBwwDbG9jMQswCQYDVQQKDAJfWDEL
+MAkGA1UECwwCT1UxEjAQBgNVBAMMCWxvY2FsaG9zdDAeFw0xNTAxMjQwODQ2MzFa
+Fw0yNTAxMjEwODQ2MzFaMF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paO2wY+bf0AbO3M24rJ2tccpMv8
+AcfXBICDiQKBgQCSxp81/I3hf7HgszaC7ZLDZMOK4M6CJz847aGFUCtsyAwCfGYb
+8zyJvK/WZDam14+lpA0IQAzPCJg/ZVZJ9uA/OivzCum2NrHNxfOiQRrLPxuokaBa
+q5k2tA02tGE53fJ6mze1DEzbnkFxqeu5gd2xdzvpOLfBxgzT8KU8PlQiuQKBgGn5
+NvCj/QZhDhYFVaW4G1ArLmiKamL3yYluUV7LiW7CaYp29gBzzsTwfKxVqhJdo5NH
+KinCrmr7vy2JGmj22a+LTkjyU/rCZQsyDxXAoDMKZ3LILwH8WocPqa4pzlL8TGzw
+urXGE+rXCwhE0Mp0Mz7YRgZHJKMcy06duG5dh11pAoGBALHbsBIDihgHPyp2eKMP
+K1f42MdKrTBiIXV80hv2OnvWVRCYvnhrqpeRMzCR1pmVbh+QhnwIMAdWq9PAVTTn
+ypusoEsG8Y5fx8xhgjs0D2yMcrmi0L0kCgHIFNoym+4pI+sv6GgxpemfrmaPNcMx
+DXi9JpaquFRJLGJ7jMCDgotL
+-----END PRIVATE KEY-----
+]]
+
--- Map of all services that can be run as servers
-- g_Services[ServiceName] = function() -> accept-callbacks
local g_Services =
@@ -66,7 +126,7 @@ local g_Services =
return
{
OnError = function (a_Link, a_ErrorCode, a_ErrorMsg)
- LOG("FortuneServer(" .. a_Port .. ": Connection to " .. a_Link:GetRemoteIP() .. ":" .. a_Link:GetRemotePort() .. " failed: " .. a_ErrorCode .. " (" .. a_ErrorMsg .. ")")
+ LOG("FortuneServer(" .. a_Port .. "): Connection to " .. a_Link:GetRemoteIP() .. ":" .. a_Link:GetRemotePort() .. " failed: " .. a_ErrorCode .. " (" .. a_ErrorMsg .. ")")
end,
OnReceivedData = function (a_Link, a_Data)
@@ -86,11 +146,56 @@ local g_Services =
-- There was an error listening on the port:
OnError = function (a_ErrorCode, a_ErrorMsg)
- LOGINFO("FortuneServer(" .. a_Port .. ": Cannot listen: " .. a_ErrorCode .. " (" .. a_ErrorMsg .. ")")
+ LOGINFO("FortuneServer(" .. a_Port .. "): Cannot listen: " .. a_ErrorCode .. " (" .. a_ErrorMsg .. ")")
end, -- OnError()
} -- Listen callbacks
end, -- fortune
+ -- HTTPS time - serves current time for each https request received
+ httpstime = function (a_Port)
+ return
+ {
+ -- A new connection has come, give it new link-callbacks:
+ OnIncomingConnection = function (a_RemoteIP, a_RemotePort)
+ local IncomingData = "" -- accumulator for the incoming data, until processed by the http
+ return
+ {
+ OnError = function (a_Link, a_ErrorCode, a_ErrorMsg)
+ LOG("https-time server(" .. a_Port .. "): Connection to " .. a_Link:GetRemoteIP() .. ":" .. a_Link:GetRemotePort() .. " failed: " .. a_ErrorCode .. " (" .. a_ErrorMsg .. ")")
+ end,
+
+ OnReceivedData = function (a_Link, a_Data)
+ IncomingData = IncomingData .. a_Data
+ if (IncomingData:find("\r\n\r\n")) then
+ -- We have received the entire request headers, just send the response and shutdown the link:
+ local Content = os.date()
+ a_Link:Send("HTTP/1.0 200 OK\r\nContent-type: text/plain\r\nContent-length: " .. #Content .. "\r\n\r\n" .. Content)
+ a_Link:Shutdown()
+ end
+ end,
+
+ OnRemoteClosed = function (a_Link)
+ LOG("httpstime: link closed by remote")
+ end
+ } -- Link callbacks
+ end, -- OnIncomingConnection()
+
+ -- Start TLS on the new link:
+ OnAccepted = function (a_Link)
+ local res, msg = a_Link:StartTLSServer(g_HTTPSCert, g_HTTPSPrivKey, "")
+ if not(res) then
+ LOG("https-time server(" .. a_Port .. "): Cannot start TLS server: " .. msg)
+ a_Link:Close()
+ end
+ end, -- OnAccepted()
+
+ -- There was an error listening on the port:
+ OnError = function (a_ErrorCode, a_ErrorMsg)
+ LOGINFO("https-time server(" .. a_Port .. "): Cannot listen: " .. a_ErrorCode .. " (" .. a_ErrorMsg .. ")")
+ end, -- OnError()
+ } -- Listen callbacks
+ end, -- httpstime
+
-- TODO: Other services (daytime, ...)
}
@@ -167,7 +272,7 @@ function HandleConsoleNetClose(a_Split)
-- Get the port to close:
local Port = tonumber(a_Split[3] or 1024)
if not(Port) then
- return true, "Bad port number: \"" .. Port .. "\"."
+ return true, "Bad port number: \"" .. a_Split[3] .. "\"."
end
-- Close the server, if there is one:
@@ -183,6 +288,19 @@ end
+function HandleConsoleNetIps(a_Split)
+ local Addresses = cNetwork:EnumLocalIPAddresses()
+ LOG("IP addresses enumerated, " .. #Addresses .. " found")
+ for idx, addr in ipairs(Addresses) do
+ LOG(" IP #" .. idx .. ": " .. addr)
+ end
+ return true
+end
+
+
+
+
+
function HandleConsoleNetLookup(a_Split)
-- Get the name to look up:
local Addr = a_Split[3] or "google.com"
@@ -229,7 +347,7 @@ function HandleConsoleNetListen(a_Split)
-- Get the params:
local Port = tonumber(a_Split[3] or 1024)
if not(Port) then
- return true, "Invalid port: \"" .. Port .. "\"."
+ return true, "Invalid port: \"" .. a_Split[3] .. "\"."
end
local Service = string.lower(a_Split[4] or "echo")
@@ -252,3 +370,134 @@ end
+
+function HandleConsoleNetUdpClose(a_Split)
+ -- Get the port to close:
+ local Port = tonumber(a_Split[4] or 1024)
+ if not(Port) then
+ return true, "Bad port number: \"" .. a_Split[4] .. "\"."
+ end
+
+ -- Close the server, if there is one:
+ if not(g_UDPEndpoints[Port]) then
+ return true, "There is no UDP endpoint currently listening on port " .. Port .. "."
+ end
+ g_UDPEndpoints[Port]:Close()
+ g_UDPEndpoints[Port] = nil
+ return true, "UDP Port " .. Port .. " closed."
+end
+
+
+
+
+
+function HandleConsoleNetUdpListen(a_Split)
+ -- Get the params:
+ local Port = tonumber(a_Split[4] or 1024)
+ if not(Port) then
+ return true, "Invalid port: \"" .. a_Split[4] .. "\"."
+ end
+
+ local Callbacks =
+ {
+ OnReceivedData = function (a_Endpoint, a_Data, a_RemotePeer, a_RemotePort)
+ LOG("Incoming UDP datagram from " .. a_RemotePeer .. " port " .. a_RemotePort .. ":\r\n" .. a_Data)
+ end,
+
+ OnError = function (a_Endpoint, a_ErrorCode, a_ErrorMsg)
+ LOG("Error in UDP endpoint: " .. a_ErrorCode .. " (" .. a_ErrorMsg .. ")")
+ end,
+ }
+
+ g_UDPEndpoints[Port] = cNetwork:CreateUDPEndpoint(Port, Callbacks)
+ return true, "UDP listener on port " .. Port .. " started."
+end
+
+
+
+
+
+function HandleConsoleNetUdpSend(a_Split)
+ -- Get the params:
+ local Host = a_Split[4] or "localhost"
+ local Port = tonumber(a_Split[5] or 1024)
+ if not(Port) then
+ return true, "Invalid port: \"" .. a_Split[5] .. "\"."
+ end
+ local Message
+ if (a_Split[6]) then
+ Message = table.concat(a_Split, " ", 6)
+ else
+ Message = "hello"
+ end
+
+ -- Define minimum callbacks for the UDP endpoint:
+ local Callbacks =
+ {
+ OnError = function (a_Endpoint, a_ErrorCode, a_ErrorMsg)
+ LOG("Error in UDP datagram sending: " .. a_ErrorCode .. " (" .. a_ErrorMsg .. ")")
+ end,
+
+ OnReceivedData = function ()
+ -- ignore
+ end,
+ }
+
+ -- Send the data:
+ local Endpoint = cNetwork:CreateUDPEndpoint(0, Callbacks)
+ Endpoint:EnableBroadcasts()
+ if not(Endpoint:Send(Message, Host, Port)) then
+ Endpoint:Close()
+ return true, "Sending UDP datagram failed"
+ end
+ Endpoint:Close()
+ return true, "UDP datagram sent"
+end
+
+
+
+
+
+function HandleConsoleNetWasc(a_Split)
+ local Callbacks =
+ {
+ OnConnected = function (a_Link)
+ LOG("Connected to webadmin, starting TLS...")
+ local res, msg = a_Link:StartTLSClient("", "", "")
+ if not(res) then
+ LOG("Failed to start TLS client: " .. msg)
+ return
+ end
+ -- We need to send a keep-alive due to #1737
+ a_Link:Send("GET / HTTP/1.0\r\nHost: localhost\r\nConnection: keep-alive\r\n\r\n")
+ end,
+
+ OnError = function (a_Link, a_ErrorCode, a_ErrorMsg)
+ LOG("Connection to webadmin failed: " .. a_ErrorCode .. " (" .. a_ErrorMsg .. ")")
+ end,
+
+ OnReceivedData = function (a_Link, a_Data)
+ LOG("Received data from webadmin:\r\n" .. a_Data)
+
+ -- Close the link once all the data is received:
+ if (a_Data == "0\r\n\r\n") then -- Poor man's end-of-data detection; works on localhost
+ -- TODO: The Close() method is not yet exported to Lua
+ -- a_Link:Close()
+ end
+ end,
+
+ OnRemoteClosed = function (a_Link)
+ LOG("Connection to webadmin was closed")
+ end,
+ }
+
+ if not(cNetwork:Connect("localhost", "8080", Callbacks)) then
+ LOG("Canot connect to webadmin")
+ end
+
+ return true
+end
+
+
+
+
diff --git a/MCServer/webadmin/files/guest.html b/MCServer/webadmin/files/guest.html
index 7ae78a3f0..4f965b75c 100644
--- a/MCServer/webadmin/files/guest.html
+++ b/MCServer/webadmin/files/guest.html
@@ -1,2 +1,18 @@
-Hello! Welcome to the MCServer WebAdmin.<br>
-This is a default message, edit <b>files/guest.html</b> to add your own custom message.
+<!DOCTYPE html>
+<html lang="en">
+
+ <head>
+ <meta charset="UTF-8" />
+ <title>Guest Information</title>
+ </head>
+
+ <body>
+ <p>
+ Hello! Welcome to the MCServer WebAdmin.
+ </p>
+ <p>
+ This is a default message, edit <b>files/guest.html</b> to add your own custom message.
+ </p>
+ </body>
+
+</html>
diff --git a/MCServer/webadmin/login_template.html b/MCServer/webadmin/login_template.html
index 7a8601065..26b260bd3 100644
--- a/MCServer/webadmin/login_template.html
+++ b/MCServer/webadmin/login_template.html
@@ -17,7 +17,7 @@
<div class="upper">
<div class="wrapper">
<div>
- <form method="get" action="webadmin/" />
+ <form method="get" action="webadmin/">
<button type="submit" value="Log in" style="width:150px;height:25px;font-family:'Source Sans Pro',sans-serif;background:transparent;border:none!important;vertical-align:middle">
<strong><img src="login.gif" style="vertical-align:bottom" /> WebAdmin Log in</strong>
</button>