summaryrefslogtreecommitdiff
path: root/Client/Source
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-12-13 15:00:32 +0800
committerchai <chaifix@163.com>2021-12-13 15:00:32 +0800
commita5dd54fbf8b6768423c48786b6a2afaf9a8ece0e (patch)
treef85c85c991c36d105f6bcba7fd628dc9749e1462 /Client/Source
parentbca78a2319400ef7e11a35f682fe45ac3fce0fbd (diff)
*misc
Diffstat (limited to 'Client/Source')
-rw-r--r--Client/Source/Filesystem/Filesystem.cpp0
-rw-r--r--Client/Source/Filesystem/Filesystem.h4
-rw-r--r--Client/Source/Local/LocalPlayer.cpp0
-rw-r--r--Client/Source/Local/LocalPlayer.h0
-rw-r--r--Client/Source/Network/Socket.h2
-rw-r--r--Client/Source/Network/http.cpp0
-rw-r--r--Client/Source/Network/http.h1
-rw-r--r--Client/Source/Physics/raycast.cpp0
-rw-r--r--Client/Source/Physics/raycast.h0
-rw-r--r--Client/Source/Remote/RemotePlayer.cpp0
-rw-r--r--Client/Source/Remote/RemotePlayer.h0
-rw-r--r--Client/Source/Serialization/serialization.cpp0
-rw-r--r--Client/Source/Serialization/serialization.h0
-rw-r--r--Client/Source/Threading/Event.cpp0
-rw-r--r--Client/Source/Threading/Event.h0
-rw-r--r--Client/Source/Utilities/Optional.h105
-rw-r--r--Client/Source/Utilities/base64.cpp154
-rw-r--r--Client/Source/Utilities/base64.h26
-rw-r--r--Client/Source/Utilities/hex.h60
-rw-r--r--Client/Source/metadata.cpp115
-rw-r--r--Client/Source/metadata.h63
21 files changed, 530 insertions, 0 deletions
diff --git a/Client/Source/Filesystem/Filesystem.cpp b/Client/Source/Filesystem/Filesystem.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Client/Source/Filesystem/Filesystem.cpp
diff --git a/Client/Source/Filesystem/Filesystem.h b/Client/Source/Filesystem/Filesystem.h
new file mode 100644
index 0000000..5919022
--- /dev/null
+++ b/Client/Source/Filesystem/Filesystem.h
@@ -0,0 +1,4 @@
+#pragma once
+
+
+
diff --git a/Client/Source/Local/LocalPlayer.cpp b/Client/Source/Local/LocalPlayer.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Client/Source/Local/LocalPlayer.cpp
diff --git a/Client/Source/Local/LocalPlayer.h b/Client/Source/Local/LocalPlayer.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Client/Source/Local/LocalPlayer.h
diff --git a/Client/Source/Network/Socket.h b/Client/Source/Network/Socket.h
index e69de29..3749a34 100644
--- a/Client/Source/Network/Socket.h
+++ b/Client/Source/Network/Socket.h
@@ -0,0 +1,2 @@
+
+// UDP socket \ No newline at end of file
diff --git a/Client/Source/Network/http.cpp b/Client/Source/Network/http.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Client/Source/Network/http.cpp
diff --git a/Client/Source/Network/http.h b/Client/Source/Network/http.h
new file mode 100644
index 0000000..50e9667
--- /dev/null
+++ b/Client/Source/Network/http.h
@@ -0,0 +1 @@
+#pragma once
diff --git a/Client/Source/Physics/raycast.cpp b/Client/Source/Physics/raycast.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Client/Source/Physics/raycast.cpp
diff --git a/Client/Source/Physics/raycast.h b/Client/Source/Physics/raycast.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Client/Source/Physics/raycast.h
diff --git a/Client/Source/Remote/RemotePlayer.cpp b/Client/Source/Remote/RemotePlayer.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Client/Source/Remote/RemotePlayer.cpp
diff --git a/Client/Source/Remote/RemotePlayer.h b/Client/Source/Remote/RemotePlayer.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Client/Source/Remote/RemotePlayer.h
diff --git a/Client/Source/Serialization/serialization.cpp b/Client/Source/Serialization/serialization.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Client/Source/Serialization/serialization.cpp
diff --git a/Client/Source/Serialization/serialization.h b/Client/Source/Serialization/serialization.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Client/Source/Serialization/serialization.h
diff --git a/Client/Source/Threading/Event.cpp b/Client/Source/Threading/Event.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Client/Source/Threading/Event.cpp
diff --git a/Client/Source/Threading/Event.h b/Client/Source/Threading/Event.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Client/Source/Threading/Event.h
diff --git a/Client/Source/Utilities/Optional.h b/Client/Source/Utilities/Optional.h
new file mode 100644
index 0000000..eda7fff
--- /dev/null
+++ b/Client/Source/Utilities/Optional.h
@@ -0,0 +1,105 @@
+/*
+Minetest
+Copyright (C) 2021 rubenwardy
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 2.1 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License along
+with this program; if not, write to the Free Software Foundation, Inc.,
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+#pragma once
+
+#include <utility>
+#include "debug.h"
+
+struct nullopt_t
+{
+};
+constexpr nullopt_t nullopt{};
+
+/**
+ * An implementation of optional for C++11, which aims to be
+ * compatible with a subset of std::optional features.
+ *
+ * Unfortunately, Minetest doesn't use C++17 yet.
+ *
+ * @tparam T The type to be stored
+ */
+template <typename T>
+class Optional
+{
+ bool m_has_value = false;
+ T m_value;
+
+public:
+ Optional() noexcept {}
+ Optional(nullopt_t) noexcept {}
+
+ Optional(const T &value) noexcept : m_has_value(true), m_value(value) {}
+ Optional(T &&value) noexcept : m_has_value(true), m_value(std::move(value)) {}
+
+ Optional(const Optional<T> &other) noexcept :
+ m_has_value(other.m_has_value), m_value(other.m_value)
+ {}
+ Optional(Optional<T> &&other) noexcept :
+ m_has_value(other.m_has_value), m_value(std::move(other.m_value))
+ {
+ other.m_has_value = false;
+ }
+
+ Optional<T> &operator=(nullopt_t) noexcept { m_has_value = false; return *this; }
+
+ Optional<T> &operator=(const Optional<T> &other) noexcept
+ {
+ if (&other == this)
+ return *this;
+ m_has_value = other.m_has_value;
+ m_value = other.m_value;
+ return *this;
+ }
+
+ Optional<T> &operator=(Optional<T> &&other) noexcept
+ {
+ if (&other == this)
+ return *this;
+ m_has_value = other.m_has_value;
+ m_value = std::move(other.m_value);
+ other.m_has_value = false;
+ return *this;
+ }
+
+ T &value()
+ {
+ FATAL_ERROR_IF(!m_has_value, "optional doesn't have value");
+ return m_value;
+ }
+
+ const T &value() const
+ {
+ FATAL_ERROR_IF(!m_has_value, "optional doesn't have value");
+ return m_value;
+ }
+
+ const T &value_or(const T &def) const { return m_has_value ? m_value : def; }
+
+ // Unchecked access consistent with std::optional
+ T* operator->() { return &m_value; }
+ const T* operator->() const { return &m_value; }
+
+ T& operator*() { return m_value; }
+ const T& operator*() const { return m_value; }
+
+ bool has_value() const noexcept { return m_has_value; }
+
+ explicit operator bool() const { return m_has_value; }
+};
diff --git a/Client/Source/Utilities/base64.cpp b/Client/Source/Utilities/base64.cpp
new file mode 100644
index 0000000..0c24552
--- /dev/null
+++ b/Client/Source/Utilities/base64.cpp
@@ -0,0 +1,154 @@
+/*
+base64.cpp and base64.h
+
+Copyright (C) 2004-2008 René Nyffenegger
+
+This source code is provided 'as-is', without any express or implied
+warranty. In no event will the author be held liable for any damages
+arising from the use of this software.
+
+Permission is granted to anyone to use this software for any purpose,
+including commercial applications, and to alter it and redistribute it
+freely, subject to the following restrictions:
+
+1. The origin of this source code must not be misrepresented; you must not
+ claim that you wrote the original source code. If you use this source code
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+
+2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original source code.
+
+3. This notice may not be removed or altered from any source distribution.
+
+René Nyffenegger rene.nyffenegger@adp-gmbh.ch
+
+*/
+
+#include "base64.h"
+#include <iostream>
+
+static const std::string base64_chars =
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ "abcdefghijklmnopqrstuvwxyz"
+ "0123456789+/";
+
+static const std::string base64_chars_padding_1 = "AEIMQUYcgkosw048";
+static const std::string base64_chars_padding_2 = "AQgw";
+
+static inline bool is_base64(unsigned char c)
+{
+ return (c >= '0' && c <= '9')
+ || (c >= 'A' && c <= 'Z')
+ || (c >= 'a' && c <= 'z')
+ || c == '+' || c == '/';
+}
+
+bool base64_is_valid(std::string const& s)
+{
+ size_t i = 0;
+ for (; i < s.size(); ++i)
+ if (!is_base64(s[i]))
+ break;
+ unsigned char padding = 3 - ((i + 3) % 4);
+ if ((padding == 1 && base64_chars_padding_1.find(s[i - 1]) == std::string::npos)
+ || (padding == 2 && base64_chars_padding_2.find(s[i - 1]) == std::string::npos)
+ || padding == 3)
+ return false;
+ int actual_padding = s.size() - i;
+ // omission of padding characters is allowed
+ if (actual_padding == 0)
+ return true;
+
+ // remaining characters (max. 2) may only be padding
+ for (; i < s.size(); ++i)
+ if (s[i] != '=')
+ return false;
+ // number of padding characters needs to match
+ return padding == actual_padding;
+}
+
+std::string base64_encode(unsigned char const* bytes_to_encode, unsigned int in_len) {
+ std::string ret;
+ int i = 0;
+ int j = 0;
+ unsigned char char_array_3[3];
+ unsigned char char_array_4[4];
+
+ while (in_len--) {
+ char_array_3[i++] = *(bytes_to_encode++);
+ if (i == 3) {
+ char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
+ char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
+ char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
+ char_array_4[3] = char_array_3[2] & 0x3f;
+
+ for(i = 0; (i <4) ; i++)
+ ret += base64_chars[char_array_4[i]];
+ i = 0;
+ }
+ }
+
+ if (i)
+ {
+ for(j = i; j < 3; j++)
+ char_array_3[j] = '\0';
+
+ char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
+ char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
+ char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
+ char_array_4[3] = char_array_3[2] & 0x3f;
+
+ for (j = 0; (j < i + 1); j++)
+ ret += base64_chars[char_array_4[j]];
+
+ // Don't pad it with =
+ /*while((i++ < 3))
+ ret += '=';*/
+
+ }
+
+ return ret;
+
+}
+
+std::string base64_decode(std::string const& encoded_string) {
+ int in_len = encoded_string.size();
+ int i = 0;
+ int j = 0;
+ int in_ = 0;
+ unsigned char char_array_4[4], char_array_3[3];
+ std::string ret;
+
+ while (in_len-- && ( encoded_string[in_] != '=') && is_base64(encoded_string[in_])) {
+ char_array_4[i++] = encoded_string[in_]; in_++;
+ if (i ==4) {
+ for (i = 0; i <4; i++)
+ char_array_4[i] = base64_chars.find(char_array_4[i]);
+
+ char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
+ char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
+ char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];
+
+ for (i = 0; (i < 3); i++)
+ ret += char_array_3[i];
+ i = 0;
+ }
+ }
+
+ if (i) {
+ for (j = i; j <4; j++)
+ char_array_4[j] = 0;
+
+ for (j = 0; j <4; j++)
+ char_array_4[j] = base64_chars.find(char_array_4[j]);
+
+ char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
+ char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
+ char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];
+
+ for (j = 0; (j < i - 1); j++) ret += char_array_3[j];
+ }
+
+ return ret;
+}
diff --git a/Client/Source/Utilities/base64.h b/Client/Source/Utilities/base64.h
new file mode 100644
index 0000000..7f2bf13
--- /dev/null
+++ b/Client/Source/Utilities/base64.h
@@ -0,0 +1,26 @@
+/*
+Minetest
+Copyright (C) 2013-2017 celeron55, Perttu Ahola <celeron55@gmail.com>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 2.1 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License along
+with this program; if not, write to the Free Software Foundation, Inc.,
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+#pragma once
+
+#include <string>
+
+bool base64_is_valid(std::string const& s);
+std::string base64_encode(unsigned char const* , unsigned int len);
+std::string base64_decode(std::string const& s);
diff --git a/Client/Source/Utilities/hex.h b/Client/Source/Utilities/hex.h
new file mode 100644
index 0000000..708f330
--- /dev/null
+++ b/Client/Source/Utilities/hex.h
@@ -0,0 +1,60 @@
+/*
+Minetest
+Copyright (C) 2013 Jonathan Neuschäfer <j.neuschaefer@gmx.net>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 2.1 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License along
+with this program; if not, write to the Free Software Foundation, Inc.,
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+#pragma once
+
+#include <string>
+
+static const char hex_chars[] = "0123456789abcdef";
+
+static inline std::string hex_encode(const char *data, unsigned int data_size)
+{
+ std::string ret;
+ ret.reserve(data_size * 2);
+
+ char buf2[3];
+ buf2[2] = '\0';
+
+ for (unsigned int i = 0; i < data_size; i++) {
+ unsigned char c = (unsigned char)data[i];
+ buf2[0] = hex_chars[(c & 0xf0) >> 4];
+ buf2[1] = hex_chars[c & 0x0f];
+ ret.append(buf2);
+ }
+
+ return ret;
+}
+
+static inline std::string hex_encode(const std::string &data)
+{
+ return hex_encode(data.c_str(), data.size());
+}
+
+static inline bool hex_digit_decode(char hexdigit, unsigned char &value)
+{
+ if (hexdigit >= '0' && hexdigit <= '9')
+ value = hexdigit - '0';
+ else if (hexdigit >= 'A' && hexdigit <= 'F')
+ value = hexdigit - 'A' + 10;
+ else if (hexdigit >= 'a' && hexdigit <= 'f')
+ value = hexdigit - 'a' + 10;
+ else
+ return false;
+ return true;
+}
diff --git a/Client/Source/metadata.cpp b/Client/Source/metadata.cpp
new file mode 100644
index 0000000..453ac1c
--- /dev/null
+++ b/Client/Source/metadata.cpp
@@ -0,0 +1,115 @@
+/*
+Minetest
+Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 2.1 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License along
+with this program; if not, write to the Free Software Foundation, Inc.,
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+#include "metadata.h"
+#include "log.h"
+
+/*
+ Metadata
+*/
+
+void Metadata::clear()
+{
+ m_stringvars.clear();
+ m_modified = true;
+}
+
+bool Metadata::empty() const
+{
+ return m_stringvars.empty();
+}
+
+size_t Metadata::size() const
+{
+ return m_stringvars.size();
+}
+
+bool Metadata::contains(const std::string &name) const
+{
+ return m_stringvars.find(name) != m_stringvars.end();
+}
+
+bool Metadata::operator==(const Metadata &other) const
+{
+ if (size() != other.size())
+ return false;
+
+ for (const auto &sv : m_stringvars) {
+ if (!other.contains(sv.first) || other.getString(sv.first) != sv.second)
+ return false;
+ }
+
+ return true;
+}
+
+const std::string &Metadata::getString(const std::string &name, u16 recursion) const
+{
+ StringMap::const_iterator it = m_stringvars.find(name);
+ if (it == m_stringvars.end()) {
+ static const std::string empty_string = std::string("");
+ return empty_string;
+ }
+
+ return resolveString(it->second, recursion);
+}
+
+bool Metadata::getStringToRef(
+ const std::string &name, std::string &str, u16 recursion) const
+{
+ StringMap::const_iterator it = m_stringvars.find(name);
+ if (it == m_stringvars.end()) {
+ return false;
+ }
+
+ str = resolveString(it->second, recursion);
+ return true;
+}
+
+/**
+ * Sets var to name key in the metadata storage
+ *
+ * @param name
+ * @param var
+ * @return true if key-value pair is created or changed
+ */
+bool Metadata::setString(const std::string &name, const std::string &var)
+{
+ if (var.empty()) {
+ m_stringvars.erase(name);
+ return true;
+ }
+
+ StringMap::iterator it = m_stringvars.find(name);
+ if (it != m_stringvars.end() && it->second == var) {
+ return false;
+ }
+
+ m_stringvars[name] = var;
+ m_modified = true;
+ return true;
+}
+
+const std::string &Metadata::resolveString(const std::string &str, u16 recursion) const
+{
+ if (recursion <= 1 && str.substr(0, 2) == "${" && str[str.length() - 1] == '}') {
+ return getString(str.substr(2, str.length() - 3), recursion + 1);
+ }
+
+ return str;
+}
diff --git a/Client/Source/metadata.h b/Client/Source/metadata.h
new file mode 100644
index 0000000..5333f8a
--- /dev/null
+++ b/Client/Source/metadata.h
@@ -0,0 +1,63 @@
+/*
+Minetest
+Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 2.1 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License along
+with this program; if not, write to the Free Software Foundation, Inc.,
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+#pragma once
+
+#include "irr_v3d.h"
+#include <iostream>
+#include <vector>
+#include "util/string.h"
+
+class Metadata
+{
+ bool m_modified = false;
+public:
+ virtual ~Metadata() = default;
+
+ virtual void clear();
+ virtual bool empty() const;
+
+ bool operator==(const Metadata &other) const;
+ inline bool operator!=(const Metadata &other) const
+ {
+ return !(*this == other);
+ }
+
+ //
+ // Key-value related
+ //
+
+ size_t size() const;
+ bool contains(const std::string &name) const;
+ const std::string &getString(const std::string &name, u16 recursion = 0) const;
+ bool getStringToRef(const std::string &name, std::string &str, u16 recursion = 0) const;
+ virtual bool setString(const std::string &name, const std::string &var);
+ inline bool removeString(const std::string &name) { return setString(name, ""); }
+ const StringMap &getStrings() const
+ {
+ return m_stringvars;
+ }
+ // Add support for variable names in values
+ const std::string &resolveString(const std::string &str, u16 recursion = 0) const;
+
+ inline bool isModified() const { return m_modified; }
+ inline void setModified(bool v) { m_modified = v; }
+protected:
+ StringMap m_stringvars;
+};