From 400a4d1083fa8ea29898a045ea1bb7815b3a4fcb Mon Sep 17 00:00:00 2001 From: Alexander Harkness Date: Sat, 27 Sep 2014 15:33:35 +0100 Subject: [PATCH 1/9] Hopefully fix #1384 Can @madmaxoft comment? --- .../Plugins/APIDump/Hooks/OnServerPing.lua | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 MCServer/Plugins/APIDump/Hooks/OnServerPing.lua diff --git a/MCServer/Plugins/APIDump/Hooks/OnServerPing.lua b/MCServer/Plugins/APIDump/Hooks/OnServerPing.lua new file mode 100644 index 000000000..8a710e047 --- /dev/null +++ b/MCServer/Plugins/APIDump/Hooks/OnServerPing.lua @@ -0,0 +1,24 @@ + (cClientHandle & a_ClientHandle, AString & a_ServerDescription, int & a_OnlinePlayersCount, int & a_MaxPlayersCount, AString & a_Favicon); + +return +{ + HOOK_SERVER_PING = + { + CalledWhen = "Client pings the server from the server list.", + DefaultFnName = "OnServerPing", -- also used as pagename + Desc = [[ + A plugin may implement an OnServerPing() function and register it as a Hook to process pings from + clients in the server server list. + ]], + Params = { + { Name = "ClientHandle", Type = "{{cClientHandle}}", Notes = "The client handle that pinged the server" }, + { Name = "ServerDescription", Type = "string", Notes = "The server description" }, + { Name = "OnlinePlayersCount", Type = "number", Notes = "The number of players currently on the server" }, + { Name = "MaxPlayersCount", Type = "number", Notes = "The current player cap for the server" }, + { Name = "Favicon", Type = "string", Notes = "The base64 encoded favicon to be displayed in the server list for compatible clients" }, + }, + Returns = [[ + The plugin may return a boolean of whether to respond to the client that pinged. + ]], + }, -- HOOK_SERVER_PING +} From 3ff7103440202694f36f4c5edd09f8c5d4abb5a5 Mon Sep 17 00:00:00 2001 From: Alexander Harkness Date: Sat, 27 Sep 2014 15:35:06 +0100 Subject: [PATCH 2/9] Remaining part of fix. --- MCServer/Plugins/APIDump/APIDesc.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index e6ee4ca10..6a3c178ef 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -1984,6 +1984,7 @@ cPluginManager.AddHook(cPluginManager.HOOK_CHAT, OnChatMessage); HOOK_PLAYER_USING_ITEM = { Notes = "Called when the player is about to right-click with a usable item in their hand." }, HOOK_POST_CRAFTING = { Notes = "Called after a valid recipe has been chosen for the current contents of the crafting grid. Plugins may modify the recipe." }, HOOK_PRE_CRAFTING = { Notes = "Called before a recipe is searched for the current contents of the crafting grid. Plugins may provide a recipe and cancel the built-in search." }, + HOOK_SERVER_PING = { Notes = "Called when a alient pings the server from the server list." }, HOOK_SPAWNED_ENTITY = { Notes = "Called after an entity is spawned in a {{cWorld|world}}. The entity is already part of the world." }, HOOK_SPAWNED_MONSTER = { Notes = "Called after a mob is spawned in a {{cWorld|world}}. The mob is already part of the world." }, HOOK_SPAWNING_ENTITY = { Notes = "Called just before an entity is spawned in a {{cWorld|world}}." }, From 9dccbe7792cfdc6ffd56348aa9092004526b3794 Mon Sep 17 00:00:00 2001 From: Alexander Harkness Date: Sat, 27 Sep 2014 15:40:33 +0100 Subject: [PATCH 3/9] Fixed line left in. --- MCServer/Plugins/APIDump/Hooks/OnServerPing.lua | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/MCServer/Plugins/APIDump/Hooks/OnServerPing.lua b/MCServer/Plugins/APIDump/Hooks/OnServerPing.lua index 8a710e047..7cfbd06ac 100644 --- a/MCServer/Plugins/APIDump/Hooks/OnServerPing.lua +++ b/MCServer/Plugins/APIDump/Hooks/OnServerPing.lua @@ -1,5 +1,3 @@ - (cClientHandle & a_ClientHandle, AString & a_ServerDescription, int & a_OnlinePlayersCount, int & a_MaxPlayersCount, AString & a_Favicon); - return { HOOK_SERVER_PING = @@ -8,7 +6,8 @@ return DefaultFnName = "OnServerPing", -- also used as pagename Desc = [[ A plugin may implement an OnServerPing() function and register it as a Hook to process pings from - clients in the server server list. + clients in the server server list. It can change the logged in players and player capacity, as well + as the server description and the favicon by editing the values passed in. ]], Params = { { Name = "ClientHandle", Type = "{{cClientHandle}}", Notes = "The client handle that pinged the server" }, @@ -18,7 +17,7 @@ return { Name = "Favicon", Type = "string", Notes = "The base64 encoded favicon to be displayed in the server list for compatible clients" }, }, Returns = [[ - The plugin may return a boolean of whether to respond to the client that pinged. + The plugin may return a boolean. ]], }, -- HOOK_SERVER_PING } From 5245bb0eba6450339c5294038e34a242638c461b Mon Sep 17 00:00:00 2001 From: Alexander Harkness Date: Sat, 27 Sep 2014 16:44:11 +0100 Subject: [PATCH 4/9] Typo fix. --- MCServer/Plugins/APIDump/APIDesc.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index 6a3c178ef..deaa28279 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -2815,7 +2815,7 @@ end Globals = { Desc = [[ - These functions are available directly, without a class instance. Any plugin cal call them at any + These functions are available directly, without a class instance. Any plugin can call them at any time. ]], Functions = From 990a467eb41c6fb1dc4a132bd6e990c97efaa2e6 Mon Sep 17 00:00:00 2001 From: Alexander Harkness Date: Sat, 27 Sep 2014 16:49:40 +0100 Subject: [PATCH 5/9] Fixed typo again. --- MCServer/Plugins/APIDump/APIDesc.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index deaa28279..f903308d1 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -1984,7 +1984,7 @@ cPluginManager.AddHook(cPluginManager.HOOK_CHAT, OnChatMessage); HOOK_PLAYER_USING_ITEM = { Notes = "Called when the player is about to right-click with a usable item in their hand." }, HOOK_POST_CRAFTING = { Notes = "Called after a valid recipe has been chosen for the current contents of the crafting grid. Plugins may modify the recipe." }, HOOK_PRE_CRAFTING = { Notes = "Called before a recipe is searched for the current contents of the crafting grid. Plugins may provide a recipe and cancel the built-in search." }, - HOOK_SERVER_PING = { Notes = "Called when a alient pings the server from the server list." }, + HOOK_SERVER_PING = { Notes = "Called when a client pings the server from the server list. Plugins may change the favicon, server description, players online and maximum players values." }, HOOK_SPAWNED_ENTITY = { Notes = "Called after an entity is spawned in a {{cWorld|world}}. The entity is already part of the world." }, HOOK_SPAWNED_MONSTER = { Notes = "Called after a mob is spawned in a {{cWorld|world}}. The mob is already part of the world." }, HOOK_SPAWNING_ENTITY = { Notes = "Called just before an entity is spawned in a {{cWorld|world}}." }, From 57e83f7d49485e254ab33ee348ce66c3981005a5 Mon Sep 17 00:00:00 2001 From: Alexander Harkness Date: Sat, 27 Sep 2014 21:27:48 +0100 Subject: [PATCH 6/9] Fixed return value descriptions. --- MCServer/Plugins/APIDump/Hooks/OnServerPing.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/MCServer/Plugins/APIDump/Hooks/OnServerPing.lua b/MCServer/Plugins/APIDump/Hooks/OnServerPing.lua index 7cfbd06ac..e4c8b054b 100644 --- a/MCServer/Plugins/APIDump/Hooks/OnServerPing.lua +++ b/MCServer/Plugins/APIDump/Hooks/OnServerPing.lua @@ -17,7 +17,9 @@ return { Name = "Favicon", Type = "string", Notes = "The base64 encoded favicon to be displayed in the server list for compatible clients" }, }, Returns = [[ - The plugin may return a boolean. + The plugin returns res, ServerDescription, OnlinePlayersCount, MaxPlayersCount, Favicon. + res is a boolean which stops other plugins being notified of the ping if it's set to true, and the others + are the same as the arguments, and if emitted change the values transmitted to the client. ]], }, -- HOOK_SERVER_PING } From e5873d4e890ab4c5cdff365790a368d99984944d Mon Sep 17 00:00:00 2001 From: Alexander Harkness Date: Sat, 27 Sep 2014 21:28:59 +0100 Subject: [PATCH 7/9] Copy edit. --- MCServer/Plugins/APIDump/Hooks/OnServerPing.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MCServer/Plugins/APIDump/Hooks/OnServerPing.lua b/MCServer/Plugins/APIDump/Hooks/OnServerPing.lua index e4c8b054b..2a6aaee27 100644 --- a/MCServer/Plugins/APIDump/Hooks/OnServerPing.lua +++ b/MCServer/Plugins/APIDump/Hooks/OnServerPing.lua @@ -7,7 +7,7 @@ return Desc = [[ A plugin may implement an OnServerPing() function and register it as a Hook to process pings from clients in the server server list. It can change the logged in players and player capacity, as well - as the server description and the favicon by editing the values passed in. + as the server description and the favicon, that are displayed to the client in the server list. ]], Params = { { Name = "ClientHandle", Type = "{{cClientHandle}}", Notes = "The client handle that pinged the server" }, From 24275e058b9e98d43c21d6754b29defc1cba28f6 Mon Sep 17 00:00:00 2001 From: Alexander Harkness Date: Sat, 27 Sep 2014 21:35:08 +0100 Subject: [PATCH 8/9] changed description to be more readable. --- MCServer/Plugins/APIDump/Hooks/OnServerPing.lua | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/MCServer/Plugins/APIDump/Hooks/OnServerPing.lua b/MCServer/Plugins/APIDump/Hooks/OnServerPing.lua index 2a6aaee27..6dcaf3f17 100644 --- a/MCServer/Plugins/APIDump/Hooks/OnServerPing.lua +++ b/MCServer/Plugins/APIDump/Hooks/OnServerPing.lua @@ -17,9 +17,8 @@ return { Name = "Favicon", Type = "string", Notes = "The base64 encoded favicon to be displayed in the server list for compatible clients" }, }, Returns = [[ - The plugin returns res, ServerDescription, OnlinePlayersCount, MaxPlayersCount, Favicon. - res is a boolean which stops other plugins being notified of the ping if it's set to true, and the others - are the same as the arguments, and if emitted change the values transmitted to the client. + The plugin can return whether to continue processing of the hook with other plugins, the server description to + be displayed to the client, the currently online players, the player cap and the base64/png favicon data, in that order. ]], }, -- HOOK_SERVER_PING } From 4a4411d4d72efd13b38df813321565898d9da60f Mon Sep 17 00:00:00 2001 From: Alexander Harkness Date: Sun, 28 Sep 2014 09:28:51 +0100 Subject: [PATCH 9/9] Add Code example. --- .../Plugins/APIDump/Hooks/OnServerPing.lua | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/MCServer/Plugins/APIDump/Hooks/OnServerPing.lua b/MCServer/Plugins/APIDump/Hooks/OnServerPing.lua index 6dcaf3f17..6d2325fe6 100644 --- a/MCServer/Plugins/APIDump/Hooks/OnServerPing.lua +++ b/MCServer/Plugins/APIDump/Hooks/OnServerPing.lua @@ -20,5 +20,31 @@ return The plugin can return whether to continue processing of the hook with other plugins, the server description to be displayed to the client, the currently online players, the player cap and the base64/png favicon data, in that order. ]], + CodeExamples = { + { + Title = "Change information returned to the player", + Desc = "Tells the client that the server description is 'test', there are one more players online than there actually are, and that the player cap is zero. It also changes the favicon data.", + Code = [[ +function OnServerPing(ClientHandle, ServerDescription, OnlinePlayers, MaxPlayers, Favicon) + -- Change Server Description + ServerDescription = "Test" + + -- Change online / max players + OnlinePlayers = OnlinePlayers + 1 + MaxPlayers = 0 + + -- Change favicon + if (cFile:IsFile("my-favicon.png")) then + local FaviconData = cFile:ReadWholeFile("my-favicon.png") + if (FaviconData != "") then + Favicon = Base64Encode(FaviconData) + end + end + + return false, ServerDescription, OnlinePlayers, MaxPlayers, Favicon +end + ]], + }, + }, }, -- HOOK_SERVER_PING }