From efb7d4fd3e9d20facf6a5b3d41bee8ca3d894bbc Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 13 Oct 2013 20:29:57 +0200 Subject: Fixed WebAdmin's request parameters. Also added doxycomments on what they really contain. --- source/HTTPServer/HTTPFormParser.cpp | 12 ++++++++++++ source/HTTPServer/HTTPFormParser.h | 17 +++++++++++------ source/WebAdmin.cpp | 13 ++++++++++++- source/WebAdmin.h | 6 ++++++ 4 files changed, 41 insertions(+), 7 deletions(-) (limited to 'source') diff --git a/source/HTTPServer/HTTPFormParser.cpp b/source/HTTPServer/HTTPFormParser.cpp index 7db7b4e6d..596db424e 100644 --- a/source/HTTPServer/HTTPFormParser.cpp +++ b/source/HTTPServer/HTTPFormParser.cpp @@ -52,6 +52,18 @@ cHTTPFormParser::cHTTPFormParser(cHTTPRequest & a_Request, cCallbacks & a_Callba +cHTTPFormParser::cHTTPFormParser(eKind a_Kind, const char * a_Data, int a_Size, cCallbacks & a_Callbacks) : + m_Callbacks(a_Callbacks), + m_Kind(a_Kind), + m_IsValid(true) +{ + Parse(a_Data, a_Size); +} + + + + + void cHTTPFormParser::Parse(const char * a_Data, int a_Size) { if (!m_IsValid) diff --git a/source/HTTPServer/HTTPFormParser.h b/source/HTTPServer/HTTPFormParser.h index b92ef9d3c..a554ca5a4 100644 --- a/source/HTTPServer/HTTPFormParser.h +++ b/source/HTTPServer/HTTPFormParser.h @@ -26,6 +26,13 @@ class cHTTPFormParser : public cMultipartParser::cCallbacks { public: + enum eKind + { + fpkURL, ///< The form has been transmitted as parameters to a GET request + fpkFormUrlEncoded, ///< The form has been POSTed or PUT, with Content-Type of "application/x-www-form-urlencoded" + fpkMultipart, ///< The form has been POSTed or PUT, with Content-Type of "multipart/form-data" + } ; + class cCallbacks { public: @@ -40,8 +47,12 @@ public: } ; + /// Creates a parser that is tied to a request and notifies of various events using a callback mechanism cHTTPFormParser(cHTTPRequest & a_Request, cCallbacks & a_Callbacks); + /// Creates a parser with the specified content type that reads data from a string + cHTTPFormParser(eKind a_Kind, const char * a_Data, int a_Size, cCallbacks & a_Callbacks); + /// Adds more data into the parser, as the request body is received void Parse(const char * a_Data, int a_Size); @@ -54,12 +65,6 @@ public: static bool HasFormData(const cHTTPRequest & a_Request); protected: - enum eKind - { - fpkURL, ///< The form has been transmitted as parameters to a GET request - fpkFormUrlEncoded, ///< The form has been POSTed or PUT, with Content-Type of "application/x-www-form-urlencoded" - fpkMultipart, ///< The form has been POSTed or PUT, with Content-Type of "multipart/form-data" - }; /// The callbacks to call for incoming file data cCallbacks & m_Callbacks; diff --git a/source/WebAdmin.cpp b/source/WebAdmin.cpp index 08817139a..daec2f925 100644 --- a/source/WebAdmin.cpp +++ b/source/WebAdmin.cpp @@ -185,8 +185,19 @@ void cWebAdmin::HandleWebadminRequest(cHTTPConnection & a_Connection, cHTTPReque HTTPfd.Name = itr->first; TemplateRequest.Request.FormData[itr->first] = HTTPfd; TemplateRequest.Request.PostParams[itr->first] = itr->second; - TemplateRequest.Request.Params[itr->first] = itr->second; } // for itr - Data->m_Form[] + + // Parse the URL into individual params: + size_t idxQM = a_Request.GetURL().find('?'); + if (idxQM != AString::npos) + { + cHTTPFormParser URLParams(cHTTPFormParser::fpkURL, a_Request.GetURL().c_str() + idxQM + 1, a_Request.GetURL().length() - idxQM - 1, *Data); + URLParams.Finish(); + for (cHTTPFormParser::const_iterator itr = URLParams.begin(), end = URLParams.end(); itr != end; ++itr) + { + TemplateRequest.Request.Params[itr->first] = itr->second; + } // for itr - URLParams[] + } } // Try to get the template from the Lua template script diff --git a/source/WebAdmin.h b/source/WebAdmin.h index 16b5dd4dc..72c77ddfb 100644 --- a/source/WebAdmin.h +++ b/source/WebAdmin.h @@ -56,8 +56,14 @@ struct HTTPRequest AString Path; AString Username; // tolua_end + + /// Parameters given in the URL, after the questionmark StringStringMap Params; // >> EXPORTED IN MANUALBINDINGS << + + /// Parameters posted as a part of a form - either in the URL (GET method) or in the body (POST method) StringStringMap PostParams; // >> EXPORTED IN MANUALBINDINGS << + + /// Same as PostParams FormDataMap FormData; // >> EXPORTED IN MANUALBINDINGS << } ; // tolua_export -- cgit v1.2.3 From 18bbe82f30af5f0ebb0b4789f386f5179ec56f2b Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 13 Oct 2013 22:19:13 +0200 Subject: WebAdmin honors the [WebAdmin].Enable setting. This fixes #234. --- source/WebAdmin.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'source') diff --git a/source/WebAdmin.cpp b/source/WebAdmin.cpp index daec2f925..316513f11 100644 --- a/source/WebAdmin.cpp +++ b/source/WebAdmin.cpp @@ -79,8 +79,14 @@ bool cWebAdmin::Init(void) return false; } - AString PortsIPv4 = m_IniFile.GetValue("WebAdmin", "Port", "8080"); - AString PortsIPv6 = m_IniFile.GetValue("WebAdmin", "PortsIPv6", ""); + if (!m_IniFile.GetValueSetB("WebAdmin", "Enabled", true)) + { + // WebAdmin is disabled, bail out faking a success + return true; + } + + AString PortsIPv4 = m_IniFile.GetValueSet("WebAdmin", "Port", "8080"); + AString PortsIPv6 = m_IniFile.GetValueSet("WebAdmin", "PortsIPv6", ""); if (!m_HTTPServer.Initialize(PortsIPv4, PortsIPv6)) { -- cgit v1.2.3 From 173e8684a5bcca63f462cc86cc3fa6541beaf367 Mon Sep 17 00:00:00 2001 From: Sofapriester Date: Tue, 15 Oct 2013 00:46:32 +0200 Subject: Update BlockID.cpp Added g_BlockIsTorchPlaceable[E_BLOCK_STONE_BRICKS] = true; -> this should fix Issue #254 -> Please check if ok Thx --- source/BlockID.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source') diff --git a/source/BlockID.cpp b/source/BlockID.cpp index 7c3fa0b8e..177652a46 100644 --- a/source/BlockID.cpp +++ b/source/BlockID.cpp @@ -1,4 +1,3 @@ - // BlockID.cpp // Implements the helper functions for converting Block ID string to int etc. @@ -930,6 +929,7 @@ public: g_BlockIsTorchPlaceable[E_BLOCK_STAINED_CLAY] = true; g_BlockIsTorchPlaceable[E_BLOCK_WOOL] = true; g_BlockIsTorchPlaceable[E_BLOCK_STONE] = true; + g_BlockIsTorchPlaceable[E_BLOCK_STONE_BRICKS] = true; } } BlockPropertiesInitializer; -- cgit v1.2.3 From 8147ccd13be96e8d4bec2aae33b8cc8ee84c5866 Mon Sep 17 00:00:00 2001 From: tonibm19 Date: Tue, 15 Oct 2013 17:09:43 +0200 Subject: Added horse saddling It uses pig code, sorry if it don't works, i'm a noob, but it should work. --- source/Mobs/Horse.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'source') diff --git a/source/Mobs/Horse.cpp b/source/Mobs/Horse.cpp index 46e7969cc..1f2c28adf 100644 --- a/source/Mobs/Horse.cpp +++ b/source/Mobs/Horse.cpp @@ -1,4 +1,3 @@ - #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules #include "Horse.h" @@ -107,6 +106,18 @@ void cHorse::OnRightClicked(cPlayer & a_Player) m_TameAttemptTimes++; a_Player.AttachTo(this); + + if (a_Player.GetEquippedItem().m_ItemType == E_ITEM_SADDLE) + { + if (!a_Player.IsGameModeCreative()) + { + a_Player.GetInventory().RemoveOneEquippedItem(); + } + + // Set saddle state & broadcast metadata + m_bIsSaddled = true; + m_World->BroadcastEntityMetadata(*this); + } } -- cgit v1.2.3 From 7d4c0582a8b5768c7ebe9259ac9fe77dc38870d1 Mon Sep 17 00:00:00 2001 From: tonibm19 Date: Tue, 15 Oct 2013 17:11:42 +0200 Subject: Added extra line --- source/Mobs/Horse.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'source') diff --git a/source/Mobs/Horse.cpp b/source/Mobs/Horse.cpp index 1f2c28adf..c2a8f6ed0 100644 --- a/source/Mobs/Horse.cpp +++ b/source/Mobs/Horse.cpp @@ -1,3 +1,4 @@ + #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules #include "Horse.h" -- cgit v1.2.3 From fbba2e79eb0ab60e5515a00944313486131c1a35 Mon Sep 17 00:00:00 2001 From: tonibm19 Date: Tue, 15 Oct 2013 17:31:26 +0200 Subject: Added basic milk code. --- source/Mobs/Cow.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'source') diff --git a/source/Mobs/Cow.cpp b/source/Mobs/Cow.cpp index 8e9b87d27..38cb30963 100644 --- a/source/Mobs/Cow.cpp +++ b/source/Mobs/Cow.cpp @@ -1,4 +1,3 @@ - #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules #include "Cow.h" @@ -7,10 +6,6 @@ -// TODO: Milk Cow - - - cCow::cCow(void) : @@ -28,6 +23,18 @@ void cCow::GetDrops(cItems & a_Drops, cEntity * a_Killer) AddRandomDropItem(a_Drops, 1, 3, IsOnFire() ? E_ITEM_STEAK : E_ITEM_RAW_BEEF); } +void cCow::OnRightClicked(cPlayer & a_Player) +{ + if ((a_Player.GetEquippedItem().m_ItemType == E_ITEM_BUCKET)) + { + if (!a_Player.IsGameModeCreative()) + { + a_Player.GetInventory().RemoveOneEquippedItem(); + a_Player.GetInventory().AddItem(E_ITEM_MILK) + } + + } +} -- cgit v1.2.3 From 06b7e09e7099256598ada53a4cc6e17a5474fb1e Mon Sep 17 00:00:00 2001 From: tonibm19 Date: Tue, 15 Oct 2013 17:32:15 +0200 Subject: Added extra line (yes, again) --- source/Mobs/Cow.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'source') diff --git a/source/Mobs/Cow.cpp b/source/Mobs/Cow.cpp index 38cb30963..431a6916d 100644 --- a/source/Mobs/Cow.cpp +++ b/source/Mobs/Cow.cpp @@ -1,3 +1,4 @@ + #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules #include "Cow.h" -- cgit v1.2.3 From 400cab0b86476546b4c6a01fa4974c253e58ec8c Mon Sep 17 00:00:00 2001 From: tonibm19 Date: Tue, 15 Oct 2013 18:17:17 +0200 Subject: Fixed a big fail.I did --- source/Mobs/Cow.h | 1 + 1 file changed, 1 insertion(+) (limited to 'source') diff --git a/source/Mobs/Cow.h b/source/Mobs/Cow.h index b90cb170e..0391d4a31 100644 --- a/source/Mobs/Cow.h +++ b/source/Mobs/Cow.h @@ -18,6 +18,7 @@ public: CLASS_PROTODEF(cCow); virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = NULL) override; + virtual void OnRightClicked(cPlayer & a_Player) override; } ; -- cgit v1.2.3