summaryrefslogtreecommitdiff
path: root/src/net
diff options
context:
space:
mode:
authorFreeyorp <Freeyorp101@hotmail.com>2010-05-17 20:55:06 +1200
committerFreeyorp <Freeyorp101@hotmail.com>2010-07-10 21:51:07 +1200
commit98cdcb1de4f422255aa5ef924042ae7d00a5b968 (patch)
tree1746776580502fb007581f171fa89638ab6bc64f /src/net
parent26d8eba0ad906cd9b4a95bbd94fc1556719fd5d2 (diff)
downloadmanaserv-98cdcb1de4f422255aa5ef924042ae7d00a5b968.tar.gz
manaserv-98cdcb1de4f422255aa5ef924042ae7d00a5b968.tar.bz2
manaserv-98cdcb1de4f422255aa5ef924042ae7d00a5b968.tar.xz
manaserv-98cdcb1de4f422255aa5ef924042ae7d00a5b968.zip
New attribute system and major changes to many low-level areas.
Attribute system: Structure is no longer completely hardcoded. Attributes and structure is defined by new xml file (defaulting to stats.xml) Structure defines non-base modifications to an attribute, to be used by modifiers from items, effects, etc. Calculating the base value for core attributes is still done in C++ (and for such fundamental elements the only reason I can think of to do it any other way is perhaps being able to quickly change scripts without a compile could be useful for testing, but such things are a low priority anyway) Item structure: Modifiers are now through triggers rather than single events. This also removes hardcoded types - an item could be both able to be equipped and be able to be activated. Item activation no longer consumes by default, this must be specified by the property <consumes /> inside the trigger. Currently only attribute modifications, autoattacks, and consumes are defined as effects, but stubs for others do exist. Autoattacks are currently non-functional, and this should be rectified with some urgency. Auto Attacks: AutoAttacks are now separate entities, though not fully complete, nor fully integrated with all beings yet. Integration with the Character class is urgent, integration with other Being children less so. When fully integrated this will allow for multiple autoattacks, through equipping multiple items with this as an equip effect or even through other means if needed. Equipment structure: As ItemClass types are no longer hardcoded, so too are equip types. An item have multiple ways to be equipped across multiple equipment slots with any number in each slot. Character maximums are global but configurable. Miscellaneous: Speed, money, and weight are now attributes. Some managers have been changed into classes such that their associated classes can have them as friends, to avoid (ab)use of public accessors. The serialise procedure should also be set as a friend of Character (both in the account- and game- server) as well; having public accessors returning iterators is simply ridiculous. Some start for such cleanups have been made, but this is not the primary focus here. Significant work will need to be done before this is resolved completely, but the start is there. BuySell::registerPlayerItems() has been completely disabled temporarily. The previous function iterated through equipment, yet in the context I think it is intended to fill items? I have been unable to update this function to fit the modifications made to the Inventory/Equipment/Possessions, as I am unsure what exactly what it should be doing. ItemClass::mSpriteId was previously unused, so had been removed, but I notice that it was used when transmitting equipment to nearby clients. Experimentation showed that this value was never set to anything other than 0, and so has been left out of the ItemManager rewrite. I am not entirely sure what is happening here, but it should be worth looking into at a later time, as I am not sure how equipment appearences would be sent otherwise.
Diffstat (limited to 'src/net')
-rw-r--r--src/net/messagein.cpp22
-rw-r--r--src/net/messagein.hpp5
-rw-r--r--src/net/messageout.cpp23
-rw-r--r--src/net/messageout.hpp6
4 files changed, 56 insertions, 0 deletions
diff --git a/src/net/messagein.cpp b/src/net/messagein.cpp
index 45d1b21c..63fd8778 100644
--- a/src/net/messagein.cpp
+++ b/src/net/messagein.cpp
@@ -23,8 +23,12 @@
#include <iostream>
#include <string>
#include <enet/enet.h>
+#ifndef USE_NATIVE_DOUBLE
+#include <sstream>
+#endif
#include "net/messagein.hpp"
+#include "utils/logger.h"
MessageIn::MessageIn(const char *data, int length):
mData(data),
@@ -42,6 +46,7 @@ int MessageIn::readByte()
{
value = (unsigned char) mData[mPos];
}
+ else LOG_DEBUG("Unable to read 1 byte in " << this->getId() << "!");
mPos += 1;
return value;
}
@@ -55,6 +60,7 @@ int MessageIn::readShort()
memcpy(&t, mData + mPos, 2);
value = (unsigned short) ENET_NET_TO_HOST_16(t);
}
+ else LOG_DEBUG("Unable to read 2 bytes in " << this->getId() << "!");
mPos += 2;
return value;
}
@@ -68,10 +74,26 @@ int MessageIn::readLong()
memcpy(&t, mData + mPos, 4);
value = ENET_NET_TO_HOST_32(t);
}
+ else LOG_DEBUG("Unable to read 4 bytes in " << this->getId() << "!");
mPos += 4;
return value;
}
+double MessageIn::readDouble()
+{
+ double value;
+#ifdef USE_NATIVE_DOUBLE
+ if (mPos + sizeof(double) <= mLength)
+ memcpy(&value, mData + mPos, sizeof(double));
+ mPos += sizeof(double);
+#else
+ int length = readByte();
+ std::istringstream i (readString(length));
+ i >> value;
+#endif
+ return value;
+}
+
std::string MessageIn::readString(int length)
{
// Get string length
diff --git a/src/net/messagein.hpp b/src/net/messagein.hpp
index 71884190..c6e49ab5 100644
--- a/src/net/messagein.hpp
+++ b/src/net/messagein.hpp
@@ -47,6 +47,11 @@ class MessageIn
int readByte(); /**< Reads a byte. */
int readShort(); /**< Reads a short. */
int readLong(); /**< Reads a long. */
+ /**
+ * Reads a double. HACKY and should *not* be used for client
+ * communication!
+ */
+ double readDouble();
/**
* Reads a string. If a length is not given (-1), it is assumed
diff --git a/src/net/messageout.cpp b/src/net/messageout.cpp
index 8e6a4a7a..950da5f3 100644
--- a/src/net/messageout.cpp
+++ b/src/net/messageout.cpp
@@ -21,6 +21,10 @@
#include <cstring>
#include <iomanip>
#include <iostream>
+#ifndef USE_NATIVE_DOUBLE
+#include <limits>
+#include <sstream>
+#endif
#include <string>
#include <enet/enet.h>
@@ -98,6 +102,25 @@ void MessageOut::writeLong(int value)
mPos += 4;
}
+void MessageOut::writeDouble(double value)
+{
+#ifdef USE_NATIVE_DOUBLE
+ expand(mPos + sizeof(double));
+ memcpy(mData + mPos, &value, sizeof(double));
+ mPos += sizeof(double);
+#else
+// Rather inefficient, but I don't have a lot of time.
+// If anyone wants to implement a custom double you are more than welcome to.
+ std::ostringstream o;
+ // Highest precision for double
+ o.precision(std::numeric_limits< double >::digits10);
+ o << value;
+ std::string str = o.str();
+ writeByte(str.size());
+ writeString(str, str.size());
+#endif
+}
+
void MessageOut::writeCoordinates(int x, int y)
{
expand(mPos + 3);
diff --git a/src/net/messageout.hpp b/src/net/messageout.hpp
index cd7befa7..270b7963 100644
--- a/src/net/messageout.hpp
+++ b/src/net/messageout.hpp
@@ -56,6 +56,12 @@ class MessageOut
void writeLong(int value); /**< Writes an integer on four bytes. */
/**
+ * Writes a double. HACKY and should *not* be used for client
+ * communication!
+ */
+ void writeDouble(double value);
+
+ /**
* Writes a 3-byte block containing tile-based coordinates.
*/
void writeCoordinates(int x, int y);