summaryrefslogtreecommitdiff
path: root/src/mmo
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
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')
-rw-r--r--src/mmo/extract.cpp25
-rw-r--r--src/mmo/extract.hpp45
-rw-r--r--src/mmo/extract_test.cpp2
-rw-r--r--src/mmo/fwd.hpp37
-rw-r--r--src/mmo/ids.cpp21
-rw-r--r--src/mmo/ids.hpp109
-rw-r--r--src/mmo/mmo.hpp32
-rw-r--r--src/mmo/socket.cpp3
-rw-r--r--src/mmo/socket.hpp3
-rw-r--r--src/mmo/utils.hpp2
-rw-r--r--src/mmo/version.hpp2
11 files changed, 241 insertions, 40 deletions
diff --git a/src/mmo/extract.cpp b/src/mmo/extract.cpp
index 378986d..f25126f 100644
--- a/src/mmo/extract.cpp
+++ b/src/mmo/extract.cpp
@@ -22,6 +22,8 @@
#include "../strings/xstring.hpp"
#include "../strings/vstring.hpp"
+#include "mmo.hpp"
+
#include "../poison.hpp"
bool extract(XString str, XString *rv)
@@ -47,7 +49,7 @@ bool extract(XString str, struct item *it)
XString ignored;
return extract(str,
record<',', 11>(
- &it->id,
+ &ignored,
&it->nameid,
&it->amount,
&it->equip,
@@ -60,3 +62,24 @@ bool extract(XString str, struct item *it)
&ignored,
&ignored));
}
+
+bool extract(XString str, MapName *m)
+{
+ XString::iterator it = std::find(str.begin(), str.end(), '.');
+ str = str.xislice_h(it);
+ VString<15> tmp;
+ bool rv = extract(str, &tmp);
+ *m = tmp;
+ return rv;
+}
+
+bool extract(XString str, CharName *out)
+{
+ VString<23> tmp;
+ if (extract(str, &tmp))
+ {
+ *out = CharName(tmp);
+ return true;
+ }
+ return false;
+}
diff --git a/src/mmo/extract.hpp b/src/mmo/extract.hpp
index f3df0f3..ab65661 100644
--- a/src/mmo/extract.hpp
+++ b/src/mmo/extract.hpp
@@ -19,7 +19,7 @@
// 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 "../sanity.hpp"
+# include "fwd.hpp"
# include <cerrno>
# include <cstdlib>
@@ -27,11 +27,17 @@
# include <algorithm>
# include <vector>
+# include "../ints/wrap.hpp"
+
# include "../strings/xstring.hpp"
-# include "mmo.hpp"
+# include "../generic/enum.hpp"
+
# include "utils.hpp"
+template<class T>
+bool do_extract(XString str, T t);
+
template<class T, typename=typename std::enable_if<std::is_integral<T>::value && !std::is_same<T, char>::value && !std::is_same<T, bool>::value>::type>
bool extract(XString str, T *iv)
{
@@ -98,6 +104,12 @@ bool extract(XString str, VString<N> *out)
return true;
}
+inline
+bool extract(XString str, LString exact)
+{
+ return str == exact;
+}
+
template<class T>
class LStripper
{
@@ -200,27 +212,20 @@ bool extract(XString str, struct global_reg *var);
bool extract(XString str, struct item *it);
-inline
-bool extract(XString str, MapName *m)
-{
- XString::iterator it = std::find(str.begin(), str.end(), '.');
- str = str.xislice_h(it);
- VString<15> tmp;
- bool rv = extract(str, &tmp);
- *m = tmp;
- return rv;
+bool extract(XString str, MapName *m);
+
+bool extract(XString str, CharName *out);
+
+template<class T>
+bool do_extract(XString str, T t)
+{
+ return extract(str, t);
}
-inline
-bool extract(XString str, CharName *out)
+template<class R>
+bool extract(XString str, Wrapped<R> *w)
{
- VString<23> tmp;
- if (extract(str, &tmp))
- {
- *out = CharName(tmp);
- return true;
- }
- return false;
+ return extract(str, &w->_value);
}
#endif // TMWA_MMO_EXTRACT_HPP
diff --git a/src/mmo/extract_test.cpp b/src/mmo/extract_test.cpp
index c405de1..126cb14 100644
--- a/src/mmo/extract_test.cpp
+++ b/src/mmo/extract_test.cpp
@@ -22,6 +22,8 @@
#include "../strings/xstring.hpp"
+#include "mmo.hpp"
+
#include "../poison.hpp"
TEST(extract, record_int)
diff --git a/src/mmo/fwd.hpp b/src/mmo/fwd.hpp
new file mode 100644
index 0000000..f9c176c
--- /dev/null
+++ b/src/mmo/fwd.hpp
@@ -0,0 +1,37 @@
+#ifndef TMWA_MMO_FWD_HPP
+#define TMWA_MMO_FWD_HPP
+// mmo/fwd.hpp - list of type names for mmo lib
+//
+// 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 "../sanity.hpp"
+
+// meh, add more when I feel like it
+class MapName;
+class CharName;
+
+class Session;
+
+class AccountId;
+class CharId;
+class PartyId;
+class ItemUnkId;
+class ItemNameId;
+class GmLevel;
+
+#endif // TMWA_MMO_FWD_HPP
diff --git a/src/mmo/ids.cpp b/src/mmo/ids.cpp
new file mode 100644
index 0000000..971013b
--- /dev/null
+++ b/src/mmo/ids.cpp
@@ -0,0 +1,21 @@
+#include "ids.hpp"
+// ids.cpp - 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 "../poison.hpp"
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
diff --git a/src/mmo/mmo.hpp b/src/mmo/mmo.hpp
index 3fba7e6..fdfc478 100644
--- a/src/mmo/mmo.hpp
+++ b/src/mmo/mmo.hpp
@@ -21,7 +21,7 @@
// 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 "../sanity.hpp"
+# include "fwd.hpp"
# include "../compat/memory.hpp"
@@ -29,6 +29,7 @@
# include "../generic/enum.hpp"
+# include "ids.hpp"
# include "timer.t.hpp"
// affects CharName
@@ -199,8 +200,7 @@ using e::EPOS;
struct item
{
- int id;
- short nameid;
+ ItemNameId nameid;
short amount;
EPOS equip;
};
@@ -322,28 +322,28 @@ SEX sex_from_char(char c)
struct CharKey
{
CharName name;
- int account_id;
- int char_id;
+ AccountId account_id;
+ CharId char_id;
unsigned char char_num;
};
struct CharData
{
- int partner_id;
+ CharId partner_id;
int base_exp, job_exp, zeny;
- short species;
+ Species species;
short status_point, skill_point;
int hp, max_hp, sp, max_sp;
Option option;
short karma, manner;
short hair, hair_color, clothes_color;
- int party_id;
+ PartyId party_id;
ItemLook weapon;
- short shield;
- short head_top, head_mid, head_bottom;
+ ItemNameId shield;
+ ItemNameId head_top, head_mid, head_bottom;
unsigned char base_level, job_level;
earray<short, ATTR, ATTR::COUNT> attrs;
@@ -375,8 +375,8 @@ struct CharPair
struct storage
{
- int dirty;
- int account_id;
+ bool dirty;
+ AccountId account_id;
short storage_status;
short storage_amount;
Array<struct item, MAX_STORAGE> storage_;
@@ -384,13 +384,13 @@ struct storage
struct GM_Account
{
- int account_id;
- uint8_t level;
+ AccountId account_id;
+ GmLevel level;
};
struct party_member
{
- int account_id;
+ AccountId account_id;
CharName name;
MapName map;
int leader, online, lv;
@@ -399,7 +399,7 @@ struct party_member
struct party
{
- int party_id;
+ PartyId party_id;
PartyName name;
int exp;
int item;
diff --git a/src/mmo/socket.cpp b/src/mmo/socket.cpp
index 2fec6c1..79857b1 100644
--- a/src/mmo/socket.cpp
+++ b/src/mmo/socket.cpp
@@ -33,7 +33,10 @@
#include <cstring>
#include <ctime>
+#include "../compat/memory.hpp"
+
#include "../io/cxxstdio.hpp"
+
#include "core.hpp"
#include "timer.hpp"
#include "utils.hpp"
diff --git a/src/mmo/socket.hpp b/src/mmo/socket.hpp
index c166794..f62ca7a 100644
--- a/src/mmo/socket.hpp
+++ b/src/mmo/socket.hpp
@@ -21,13 +21,14 @@
// 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 "../sanity.hpp"
+# include "fwd.hpp"
# include <netinet/in.h>
# include <cstdio>
# include <array>
+# include <memory>
# include "../compat/rawmem.hpp"
diff --git a/src/mmo/utils.hpp b/src/mmo/utils.hpp
index 3002866..ed48ad0 100644
--- a/src/mmo/utils.hpp
+++ b/src/mmo/utils.hpp
@@ -21,7 +21,7 @@
// 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 "../sanity.hpp"
+# include "fwd.hpp"
# include <sys/types.h>
diff --git a/src/mmo/version.hpp b/src/mmo/version.hpp
index 1cec0ba..9e20bf1 100644
--- a/src/mmo/version.hpp
+++ b/src/mmo/version.hpp
@@ -21,7 +21,7 @@
// 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 "../sanity.hpp"
+# include "fwd.hpp"
# include <cstdint>