aboutsummaryrefslogtreecommitdiff
path: root/src/script/lua_api
Commit message (Collapse)AuthorAge
* Respect object property hp_max field for players (#6287)SmallJoker2017-08-23
| | | | | | | | | | | * Respect object property hp_max field for players This allows modders to configure the maximal HP per player * Statbars: Downscale bar to full 20 HP when exceeding this value Add default max HP for players and breath constants to builtin Document the constants * Rename PLAYER_MAX_HP -> PLAYER_MAX_HP_DEFAULT
* Minimap: Add new HUD flag for minimap radar modeparamat2017-08-20
| | | | | Flag default is true to not change default behaviour. The existing minimap HUD flag remains the master control for minimap.
* Modernize code: very last fixes (#6290)Loïc Blot2017-08-20
| | | Last modernization fixes
* Modernize source code: last part (#6285)Loïc Blot2017-08-20
| | | | | | | | | | | * Modernize source code: last par * Use empty when needed * Use emplace_back instead of push_back when needed * For range-based loops * Initializers fixes * constructors, destructors default * c++ C stl includes
* Code modernization: subfolders (#6283)Loïc Blot2017-08-19
| | | | | | | | | | | | | * Code modernization: subfolders Modernize various code on subfolders client, network, script, threading, unittests, util * empty function * default constructor/destructor * for range-based loops * use emplace_back instead of push_back * C++ STL header style * Make connection.cpp readable in a pointed place + typo
* Optimize headers (part 2) (#6272)Loïc Blot2017-08-18
| | | | | | | | | | | | | | * Optimize headers (part 2) * less debug.h in headers * less remoteplayer.h for everybody * Cleanup (part 2) * camera.h: mesh.h * mapgen.h: mapnode.h * serverenvironment.h: mapblock.h * nodedef.h: shader.h
* C++ modernize: Pragma once (#6264)Loïc Blot2017-08-17
| | | | * Migrate cpp headers to pragma once
* l_server, clientenvironment, clientiface: code modernizationLoic Blot2017-08-17
| | | | | * use range-based for loops * use refs on some exceptions & one setter
* Cleanup various headers to reduce compilation times (#6255)Loïc Blot2017-08-16
| | | | * Cleanup various headers to reduce compilation times
* Clouds API: change speed from 'y' to 'z', ColorSpecs in Lua docs (#6164)Ben Deutsch2017-07-24
|
* [CSM] Add flavour limits controlled by server (#5930)Loïc Blot2017-07-18
| | | | | | | | | | | | | | | | | | | | * [CSM] Add flavour limits controlled by server Server send flavour limits to client permitting to disable or limit some Lua calls * Add limits for reading nodedefs and itemdefs * flavour: Add lookup node limits * Merge get_node_or_nil into get_node. Sending fake node doesn't make sense in CSM, just return nil if node is not available for any reason * Add node range customization when noderange flavour is enabled (default 8 nodes) * Limit nodes range & disable chat message sending by default * Bump protocol version
* Chat protocol rewrite (#5117)Loïc Blot2017-07-16
| | | | | | | | | | | | | * New TOCLIENT_CHAT_MESSAGE packet * Rename old packet to TOCLIENT_CHAT_MESSAGE_OLD for compat * Handle TOCLIENT_CHAT_MESSAGE new structure client side * Client chat queue should use a specific object * SendChatMessage: use the right packet depending on protocol version (not complete yet) * Add chatmessage(type) objects and handle them client side (partially) * Use ChatMessage instead of std::wstring server side * Update with timestamp support
* Revert "CSM: Revert "[CSM] Add send_chat_message and run_server_chatcommand""Loic Blot2017-07-15
| | | | This reverts commit bdac12761cd92960c3df83c932aa610f2322215f.
* CSM: Revert "[CSM] Add send_chat_message and run_server_chatcommand"rubenwardy2017-07-15
| | | | | Original PR: #5747. This reverts commit 39f4a2f607d44738d60db84eba4b30e3d7450204.
* Remove remaining modstore code (#6120)Elijah Duffy2017-07-14
|
* Expose getPointedThing to LuaDániel Juhász2017-07-07
| | | | | | This commit introduces Raycast, a Lua user object, which can be used to perform a raycast on the map. The ray is continuable, so one can also get hidden nodes (for example to see trough glass).
* Main Menu: Allow copying directories from non-Minetest locations (#6095)Elijah Duffy2017-07-04
| | | | | Allow `core.copy_dir` (main menu API) to copy directories from a non-Minetest location. The check to disallow copying to non-Minetest locations is retained.
* Create a filesystem abstraction layer for CSM and only allow accessing files ↵red-0012017-06-30
| | | | | | | | | | | | | | | | | | that are scanned into it. (#5965) * Load client-side mods into memory before executing them. This removes the remaining filesystem access that client-sided mods had and it will hopefully make then more secure. * Lua Virtual filesystem: don't load the files into memory just scan the filenames into memory. * Fix the issues with backtrace * fix most of the issues * fix code style. * add a comment
* Isolate irrlicht references and use a singleton (#6041)Loïc Blot2017-06-26
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Add Device3D class which will contain IrrlichtDevice interface move getSupportedVideoDrivers to Device3D Add Device3D singleton & use it in various places Rename Device3D to Rendering engine & add helper functions to various device pointers More singleton work RenderingEngine owns draw_load_screen move draw functions to RenderingEngine Reduce IrrlichtDevice exposure and guienvironment RenderingEngine: Expose get_timer_time() to remove device from guiEngine Make irrlichtdevice & scene manager less exposed * Code style fixes * Move porting::getVideoDriverName, getVideoDriverFriendlyName, getDisplayDensity, getDisplaySize to RenderingEngine Fix XORG_USED macro -> RenderingEngine + create_engine_device from RenderingEngine constructor directly * enum paralax => enum parallax
* Fix CSM crash caused by move to C++11. (#6027)red-0012017-06-22
|
* Automatic item and node colorization (#5640)Dániel Juhász2017-06-20
| | | | | | | | | | | | | | | | | * Automatic item and node colorization Now nodes with a palette yield colored item stacks, and colored items place colored nodes by default. The client predicts the colorization. * Backwards compatibility * Use nil * Style fixes * Fix code style * Document changes
* Fix 2 warnings reported by GCCLoic Blot2017-06-20
| | | | | * ClientEnvironment::m_irr is not used anymore since a recent cleanup * l_vmanip constructor ordering
* C++11 cleanup on constructors (#6000)Vincent Glize2017-06-19
| | | | * C++11 cleanup on constructors dir script
* find_nodes_in_area: Extend maximal count to U32_MAX (#5277)SmallJoker2017-06-19
| | | | | | | Extend documentation, limit area volume Remove u16 count limitation * Prevent integer overflow, replace minp/maxp with pos1/pos2
* Client::makeScreenshot: remove device paramLoic Blot2017-06-19
| | | | We already have the device param as class member
* Sound: Add pitch option (#5960)Rui2017-06-11
| | | | * Sound: Add pitch option
* Improve the path select GUI (#5852)red-0012017-06-11
| | | | | | | | | | | - Allow lua to chose whatever directories or files can be selected - Fix selecting directories - Rename dialog to `guiPathSelectMenu` from `guiFileSelectMenu` - Rename lua function for opening the menu from `show_file_open_dialog` to `show_path_select_dialog` - Remove duplicate code and fix code style. Related changes - fix `clang-format` whitelist. - Regenerate minetest.conf.example
* [CSM] Add function to get player privileges (#5933)red-0012017-06-07
| | | | | | * [CSM] Add function to get player privileges + move related help functions to common * Added @Zeno- const
* Main Menu: Add get_clientmodpath API (#5912)Elijah Duffy2017-06-06
| | | Add `core.get_clientmodpath` to main menu API (also possible in async calls).
* C++11 patchset 2: remove util/cpp11.h and util/cpp11_container.h (#5821)Loïc Blot2017-06-04
|
* Minetest for C++11 (CMakeLists + Travis)Loic Blot2017-06-04
| | | | | | | | | | | * Move GCC to GCC 6 & GCC 7 * Move Clang to Clang 3.6 & Clang 4.0 * LINT moves from Clang 3.9 to Clang 4.0 * Move XCode 7.3 to 8.0 * Use more travis tricks to install compilers instead of adding complexity to our build script * Clang format fixes on checked files (compat Cpp11 instead of Cpp03) * Mingw GCC update from 4.8.4 to 5.3 (Ubuntu Xenial) * Drop mingw cmake generated files and add them to gitignore
* Enhance ABM performance a little bit by removing two std::set copy (#5815)Loïc Blot2017-05-25
| | | | | | | | | | * Enhance ABM performance a little bit by removing two std::set copy * ActiveBlockModifier::getTriggerContents now returns a const ref * ActiveBlockModifier::getRequiredNeighbors now returns a const ref * ActiveBlockModifier::getRequiredNeighbors is now purely virtual * Little code style fix
* Fix wrong return value in get_sky Lua call since ↵Loic Blot2017-05-23
| | | | | | ad9fcf859ec2347325830e09504ae96968b51ea8 Fix #5803
* LINT fix & check all files with clang-formatLoic Blot2017-05-22
| | | | Seems the diff mode doesn't work well, PR are detected as working whereas in master it's shown it's problematic (and really problematic). Use same check everywhere
* [CSM] Add send_chat_message and run_server_chatcommand API functions (#5747)Pierre-Adrien Langrognet2017-05-21
| | | | | | | | | | | | * [CSM] Add send_chat_message and run_server_chatcommand API functions * Add client-side chat message rate limiting * Limit out chat queue size * [CSM] Add minetest.clear_out_chat_queue API function and .clear_chat_queue chatcommand * Last fixes/cleanups before merge
* Fix LINT broken by dfa0c15ce045705f05487d623dc7beca6c945b4bLoic Blot2017-05-21
|
* [CSM] Add function to get the definition of items (#5732)bigfoot5472017-05-21
| | | | | Add node def and item def documentation. Please be ready for merge!
* [CSM] Correct the log destination of print() (#5784)SmallJoker2017-05-20
|
* Private nodemeta (#5702)sfan52017-05-10
| | | | * Private node metadata that isn't sent to the client
* read_schematic_replacements: ensure fields are strings (#5726)Loïc Blot2017-05-08
| | | | | | | | * read_schematic_replacements: ensure fields are strings add a type check before reading strings on read_schematic_replacements deserializer * throw LuaError instead of asserting the whole client
* Player attrs: permits to remove an attribute by setting value to nil (#5716)Loïc Blot2017-05-07
| | | | | | | | | | * Player attrs: permits to remove an attribute by setting value to nil When doing player:set_attribute("attr", nil) remove attribute Also remove a useless check on C++ API part (already done by checkplayer) Fix #5709
* LINT fix since d0678948165768472fc940c03e78cba787f49ea5Loic Blot2017-05-07
|
* Replace occurrence of luaL_reg in l_camera.cppT0ny22017-05-07
| | | | | Related to commit 41c5483. Replace an occurrence of luaL_reg in src/script/lua_api/l_camera.cpp (added by commit de028fc).
* Clean up numeric.h and split FacePositionCache from itShadowNinja2017-05-06
| | | | | I also optiized FacePositionCache a bit: I removed a map lookup and vector copy from both branches of getFacePosition.
* Use a settings object for the main settingsShadowNinja2017-05-06
| | | | | | | This unifies the settings APIs. This also unifies the sync and async registration APIs, since the async registration API did not support adding non-functions to the API table.
* Fix codestyle since CSM Camera APILoic Blot2017-05-06
|
* [CSM] Add camera API (#5609)bigfoot5472017-05-05
| | | | | | | * [CSM] Add camera API roper rebase & squash * Address nerzhul's review
* Add option to also check the center to `find_node_near` (#5255)red-0012017-05-04
| | | | | * Add option to also check the center to `find_node_near`
* Add function to get server info.red-0012017-05-04
|
* Set sky API: Add bool for clouds in front of custom skyboxparamat2017-05-02
| | | | | | | Default true. Add 'm_clouds_enabled' bool to sky.h, set from new bool in 'set sky' API. Make 'getCloudsVisible()' depend on 'm_clouds_enabled' instead of 'm_visible' (whether normal sky is visible).
opt">::basic_string<T> &prefix, bool case_insensitive = false) { if (str.size() < prefix.size()) return false; if (!case_insensitive) return str.compare(0, prefix.size(), prefix) == 0; for (size_t i = 0; i < prefix.size(); ++i) if (tolower(str[i]) != tolower(prefix[i])) return false; return true; } /** * Check whether \p str begins with the string prefix. If \p case_insensitive * is true then the check is case insensitve (default is false; i.e. case is * significant). * * @param str * @param prefix * @param case_insensitive * @return true if the str begins with prefix */ template <typename T> inline bool str_starts_with(const std::basic_string<T> &str, const T *prefix, bool case_insensitive = false) { return str_starts_with(str, std::basic_string<T>(prefix), case_insensitive); } /** * Check whether \p str ends with the string suffix. If \p case_insensitive * is true then the check is case insensitve (default is false; i.e. case is * significant). * * @param str * @param suffix * @param case_insensitive * @return true if the str begins with suffix */ template <typename T> inline bool str_ends_with(const std::basic_string<T> &str, const std::basic_string<T> &suffix, bool case_insensitive = false) { if (str.size() < suffix.size()) return false; size_t start = str.size() - suffix.size(); if (!case_insensitive) return str.compare(start, suffix.size(), suffix) == 0; for (size_t i = 0; i < suffix.size(); ++i) if (tolower(str[start + i]) != tolower(suffix[i])) return false; return true; } /** * Check whether \p str ends with the string suffix. If \p case_insensitive * is true then the check is case insensitve (default is false; i.e. case is * significant). * * @param str * @param suffix * @param case_insensitive * @return true if the str begins with suffix */ template <typename T> inline bool str_ends_with(const std::basic_string<T> &str, const T *suffix, bool case_insensitive = false) { return str_ends_with(str, std::basic_string<T>(suffix), case_insensitive); } /** * Splits a string into its component parts separated by the character * \p delimiter. * * @return An std::vector<std::basic_string<T> > of the component parts */ template <typename T> inline std::vector<std::basic_string<T> > str_split( const std::basic_string<T> &str, T delimiter) { std::vector<std::basic_string<T> > parts; std::basic_stringstream<T> sstr(str); std::basic_string<T> part; while (std::getline(sstr, part, delimiter)) parts.push_back(part); return parts; } /** * @param str * @return A copy of \p str converted to all lowercase characters. */ inline std::string lowercase(const std::string &str) { std::string s2; s2.reserve(str.size()); for (char i : str) s2 += tolower(i); return s2; } /** * @param str * @return A copy of \p str with leading and trailing whitespace removed. */ inline std::string trim(const std::string &str) { size_t front = 0; while (std::isspace(str[front])) ++front; size_t back = str.size(); while (back > front && std::isspace(str[back - 1])) --back; return str.substr(front, back - front); } /** * Returns whether \p str should be regarded as (bool) true. Case and leading * and trailing whitespace are ignored. Values that will return * true are "y", "yes", "true" and any number that is not 0. * @param str */ inline bool is_yes(const std::string &str) { std::string s2 = lowercase(trim(str)); return s2 == "y" || s2 == "yes" || s2 == "true" || atoi(s2.c_str()) != 0; } /** * Converts the string \p str to a signed 32-bit integer. The converted value * is constrained so that min <= value <= max. * * @see atoi(3) for limitations * * @param str * @param min Range minimum * @param max Range maximum * @return The value converted to a signed 32-bit integer and constrained * within the range defined by min and max (inclusive) */ inline s32 mystoi(const std::string &str, s32 min, s32 max) { s32 i = atoi(str.c_str()); if (i < min) i = min; if (i > max) i = max; return i; } /** * Returns a 32-bit value reprensented by the string \p str (decimal). * @see atoi(3) for further limitations */ inline s32 mystoi(const std::string &str) { return atoi(str.c_str()); } /** * Returns a float reprensented by the string \p str (decimal). * @see atof(3) */ inline float mystof(const std::string &str) { return atof(str.c_str()); } #define stoi mystoi #define stof mystof /// Returns a value represented by the string \p val. template <typename T> inline T from_string(const std::string &str) { std::stringstream tmp(str); T t; tmp >> t; return t; } /// Returns a 64-bit signed value represented by the string \p str (decimal). inline s64 stoi64(const std::string &str) { return from_string<s64>(str); } #if __cplusplus < 201103L namespace std { /// Returns a string representing the value \p val. template <typename T> inline string to_string(T val) { ostringstream oss; oss << val; return oss.str(); } #define DEFINE_STD_TOSTRING_FLOATINGPOINT(T) \ template <> \ inline string to_string<T>(T val) \ { \ ostringstream oss; \ oss << std::fixed \ << std::setprecision(6) \ << val; \ return oss.str(); \ } DEFINE_STD_TOSTRING_FLOATINGPOINT(float) DEFINE_STD_TOSTRING_FLOATINGPOINT(double) DEFINE_STD_TOSTRING_FLOATINGPOINT(long double) #undef DEFINE_STD_TOSTRING_FLOATINGPOINT /// Returns a wide string representing the value \p val template <typename T> inline wstring to_wstring(T val) { return utf8_to_wide(to_string(val)); } } #endif /// Returns a string representing the decimal value of the 32-bit value \p i. inline std::string itos(s32 i) { return std::to_string(i); } /// Returns a string representing the decimal value of the 64-bit value \p i. inline std::string i64tos(s64 i) { return std::to_string(i); } // std::to_string uses the '%.6f' conversion, which is inconsistent with // std::ostream::operator<<() and impractical too. ftos() uses the // more generic and std::ostream::operator<<()-compatible '%G' format. /// Returns a string representing the decimal value of the float value \p f. inline std::string ftos(float f) { std::ostringstream oss; oss << f; return oss.str(); } /** * Replace all occurrences of \p pattern in \p str with \p replacement. * * @param str String to replace pattern with replacement within. * @param pattern The pattern to replace. * @param replacement What to replace the pattern with. */ inline void str_replace(std::string &str, const std::string &pattern, const std::string &replacement) { std::string::size_type start = str.find(pattern, 0); while (start != str.npos) { str.replace(start, pattern.size(), replacement); start = str.find(pattern, start + replacement.size()); } } /** * Escapes characters [ ] \ , ; that can not be used in formspecs */ inline void str_formspec_escape(std::string &str) { str_replace(str, "\\", "\\\\"); str_replace(str, "]", "\\]"); str_replace(str, "[", "\\["); str_replace(str, ";", "\\;"); str_replace(str, ",", "\\,"); } /** * Replace all occurrences of the character \p from in \p str with \p to. * * @param str The string to (potentially) modify. * @param from The character in str to replace. * @param to The replacement character. */ void str_replace(std::string &str, char from, char to); /** * Check that a string only contains whitelisted characters. This is the * opposite of string_allowed_blacklist(). * * @param str The string to be checked. * @param allowed_chars A string containing permitted characters. * @return true if the string is allowed, otherwise false. * * @see string_allowed_blacklist() */ inline bool string_allowed(const std::string &str, const std::string &allowed_chars) { return str.find_first_not_of(allowed_chars) == str.npos; } /** * Check that a string contains no blacklisted characters. This is the * opposite of string_allowed(). * * @param str The string to be checked. * @param blacklisted_chars A string containing prohibited characters. * @return true if the string is allowed, otherwise false. * @see string_allowed() */ inline bool string_allowed_blacklist(const std::string &str, const std::string &blacklisted_chars) { return str.find_first_of(blacklisted_chars) == str.npos; } /** * Create a string based on \p from where a newline is forcefully inserted * every \p row_len characters. * * @note This function does not honour word wraps and blindy inserts a newline * every \p row_len characters whether it breaks a word or not. It is * intended to be used for, for example, showing paths in the GUI. * * @note This function doesn't wrap inside utf-8 multibyte sequences and also * counts multibyte sequences correcly as single characters. * * @param from The (utf-8) string to be wrapped into rows. * @param row_len The row length (in characters). * @return A new string with the wrapping applied. */ inline std::string wrap_rows(const std::string &from, unsigned row_len) { std::string to; size_t character_idx = 0; for (size_t i = 0; i < from.size(); i++) { if (!IS_UTF8_MULTB_INNER(from[i])) { // Wrap string after last inner byte of char if (character_idx > 0 && character_idx % row_len == 0) to += '\n'; character_idx++; } to += from[i]; } return to; } /** * Removes backslashes from an escaped string (FormSpec strings) */ template <typename T> inline std::basic_string<T> unescape_string(const std::basic_string<T> &s) { std::basic_string<T> res; for (size_t i = 0; i < s.length(); i++) { if (s[i] == '\\') { i++; if (i >= s.length()) break; } res += s[i]; } return res; } /** * Remove all escape sequences in \p s. * * @param s The string in which to remove escape sequences. * @return \p s, with escape sequences removed. */ template <typename T> std::basic_string<T> unescape_enriched(const std::basic_string<T> &s) { std::basic_string<T> output; size_t i = 0; while (i < s.length()) { if (s[i] == '\x1b') { ++i; if (i == s.length()) continue; if (s[i] == '(') { ++i; while (i < s.length() && s[i] != ')') { if (s[i] == '\\') { ++i; } ++i; } ++i; } else { ++i; } continue; } output += s[i]; ++i; } return output; } template <typename T> std::vector<std::basic_string<T> > split(const std::basic_string<T> &s, T delim) { std::vector<std::basic_string<T> > tokens; std::basic_string<T> current; bool last_was_escape = false; for (size_t i = 0; i < s.length(); i++) { T si = s[i]; if (last_was_escape) { current += '\\'; current += si; last_was_escape = false; } else { if (si == delim) { tokens.push_back(current); current = std::basic_string<T>(); last_was_escape = false; } else if (si == '\\') { last_was_escape = true; } else { current += si; last_was_escape = false; } } } //push last element tokens.push_back(current); return tokens; } std::wstring translate_string(const std::wstring &s, Translations *translations); std::wstring translate_string(const std::wstring &s); inline std::wstring unescape_translate(const std::wstring &s) { return unescape_enriched(translate_string(s)); } /** * Checks that all characters in \p to_check are a decimal digits. * * @param to_check * @return true if to_check is not empty and all characters in to_check are * decimal digits, otherwise false */ inline bool is_number(const std::string &to_check) { for (char i : to_check) if (!std::isdigit(i)) return false; return !to_check.empty(); } /** * Returns a C-string, either "true" or "false", corresponding to \p val. * * @return If \p val is true, then "true" is returned, otherwise "false". */ inline const char *bool_to_cstr(bool val) { return val ? "true" : "false"; } inline const std::string duration_to_string(int sec) { int min = sec / 60; sec %= 60; int hour = min / 60; min %= 60; std::stringstream ss; if (hour > 0) { ss << hour << "h"; if (min > 0 || sec > 0) ss << " "; } if (min > 0) { ss << min << "min"; if (sec > 0) ss << " "; } if (sec > 0) { ss << sec << "s"; } return ss.str(); } /** * Joins a vector of strings by the string \p delimiter. * * @return A std::string */ inline std::string str_join(const std::vector<std::string> &list, const std::string &delimiter) { std::ostringstream oss; bool first = true; for (const auto &part : list) { if (!first) oss << delimiter; oss << part; first = false; } return oss.str(); } /** * Create a UTF8 std::string from a irr::core::stringw. */ inline std::string stringw_to_utf8(const irr::core::stringw &input) { std::wstring str(input.c_str()); return wide_to_utf8(str); } /** * Create a irr::core:stringw from a UTF8 std::string. */ inline irr::core::stringw utf8_to_stringw(const std::string &input) { std::wstring str = utf8_to_wide(input); return irr::core::stringw(str.c_str()); } /** * Sanitize the name of a new directory. This consists of two stages: * 1. Check for 'reserved filenames' that can't be used on some filesystems * and prefix them * 2. Remove 'unsafe' characters from the name by replacing them with '_' */ std::string sanitizeDirName(const std::string &str, const std::string &optional_prefix);