summaryrefslogtreecommitdiff
path: root/src/mmo/ids.hpp
diff options
context:
space:
mode:
authorBen Longbons <b.r.longbons@gmail.com>2014-04-22 11:46:23 -0700
committerBen Longbons <b.r.longbons@gmail.com>2014-04-22 13:20:52 -0700
commitad049a15b43b7ddba3fe7d0a898652fc8022629d (patch)
tree142624e70ead3e89a8da6d56de41651f171524d0 /src/mmo/ids.hpp
parentceeda2e337077b2edaf1af09cc4df2c30e8205a1 (diff)
downloadtmwa-ad049a15b43b7ddba3fe7d0a898652fc8022629d.tar.gz
tmwa-ad049a15b43b7ddba3fe7d0a898652fc8022629d.tar.bz2
tmwa-ad049a15b43b7ddba3fe7d0a898652fc8022629d.tar.xz
tmwa-ad049a15b43b7ddba3fe7d0a898652fc8022629d.zip
Use strict ID types
Possibly some missing for the far side of the network. AccountId and BlockId are still terribly entangled.
Diffstat (limited to 'src/mmo/ids.hpp')
-rw-r--r--src/mmo/ids.hpp109
1 files changed, 109 insertions, 0 deletions
diff --git a/src/mmo/ids.hpp b/src/mmo/ids.hpp
new file mode 100644
index 0000000..71164ff
--- /dev/null
+++ b/src/mmo/ids.hpp
@@ -0,0 +1,109 @@
+#ifndef TMWA_MMO_IDS_HPP
+#define TMWA_MMO_IDS_HPP
+// ids.hpp - special integer classes for various object IDs
+//
+// Copyright © 2014 Ben Longbons <b.r.longbons@gmail.com>
+//
+// This file is part of The Mana World (Athena server)
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 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 General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# include "fwd.hpp"
+
+# include "../ints/wrap.hpp"
+
+# include "extract.hpp"
+
+class Species : public Wrapped<uint16_t> { public: explicit operator bool() const = delete; bool operator !() const = delete; Species() : Wrapped<uint16_t>() {} protected: template<class... A> constexpr explicit Species(A... a) : Wrapped<uint16_t>(a...) {} };
+
+class AccountId : public Wrapped<uint32_t> { public: AccountId() : Wrapped<uint32_t>() {} protected: template<class... A> constexpr explicit AccountId(A... a) : Wrapped<uint32_t>(a...) {} };
+class CharId : public Wrapped<uint32_t> { public: CharId() : Wrapped<uint32_t>() {} protected: template<class... A> constexpr explicit CharId(A... a) : Wrapped<uint32_t>(a...) {} };
+// important note: slave mobs synthesize PartyId as -BlockId of master
+class PartyId : public Wrapped<uint32_t> { public: PartyId() : Wrapped<uint32_t>() {} protected: template<class... A> constexpr explicit PartyId(A... a) : Wrapped<uint32_t>(a...) {} };
+class ItemNameId : public Wrapped<uint16_t> { public: ItemNameId() : Wrapped<uint16_t>() {} protected: template<class... A> constexpr explicit ItemNameId(A... a) : Wrapped<uint16_t>(a...) {} };
+
+class GmLevel
+{
+ uint32_t bits;
+
+ friend bool extract(XString str, GmLevel *lvl) { return extract(str, &lvl->bits); }
+ constexpr explicit
+ GmLevel(uint32_t b) : bits(b) {}
+ constexpr explicit
+ operator uint32_t() { return bits; }
+
+ template<class T>
+ explicit
+ GmLevel(T) = delete;
+ template<class T, typename=typename std::enable_if<!std::is_same<T, uint32_t>::value && !std::is_same<T, bool>::value>::type>
+ explicit
+ operator T() = delete;
+public:
+ constexpr
+ GmLevel() : bits() {}
+ constexpr static
+ GmLevel from(uint32_t bits) { return GmLevel(bits); }
+ template<class T>
+ constexpr static
+ GmLevel from(T) = delete;
+
+ constexpr explicit
+ operator bool() const { return bits; }
+ constexpr
+ bool operator !() const { return !bits; }
+
+ // the argument is the level of a command
+ constexpr
+ bool satisfies(GmLevel perm) { return bits >= perm.bits; }
+ // the argument is another player's gm level, for info commands
+ constexpr
+ bool detects(GmLevel other) { return bits >= other.bits; }
+ // the argument is another player's gm level, for aggressive commands
+ constexpr
+ bool overwhelms(GmLevel other) { return bits >= other.bits; }
+ // the argument is another potential permission level
+ constexpr
+ bool obsoletes(GmLevel plvl) { return bits >= plvl.bits; }
+
+ constexpr
+ uint16_t get_public_word() const
+ {
+ return (bits == 60 || bits == 99) ? 0x0080 : 0;
+ }
+
+ constexpr
+ uint32_t get_all_bits() const
+ {
+ return bits;
+ }
+
+ friend constexpr
+ bool operator == (GmLevel l, GmLevel r)
+ {
+ return l.bits == r.bits;
+ }
+ friend constexpr
+ bool operator != (GmLevel l, GmLevel r)
+ {
+ return l.bits != r.bits;
+ }
+};
+
+inline
+uint32_t convert_for_printf(GmLevel g)
+{
+ return g.get_all_bits();
+}
+
+#endif // TMWA_MMO_IDS_HPP