summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2011-07-01 17:15:47 +0200
committerJon Bergli Heier <snakebite@jvnv.net>2011-07-01 17:15:47 +0200
commitfbf91c0782c6b9cbf48209714c650cca45e8a836 (patch)
tree426b40709b7dbc18ed96b9ba1083501f9fb4f40a
parentff7f9de199213ea6d4832c0b91f2a96f5edc6bb2 (diff)
Added MSG_TYPE_OBJECT with a draft class.
-rw-r--r--messages.cpp35
-rw-r--r--messages.h21
2 files changed, 55 insertions, 1 deletions
diff --git a/messages.cpp b/messages.cpp
index ff4a6db..86067d7 100644
--- a/messages.cpp
+++ b/messages.cpp
@@ -220,3 +220,38 @@ Vector3 Player::get_pos() {
std::string Player::get_name() {
return name;
}
+
+/* Object */
+
+Object::Object() {
+ type = MSG_TYPE_OBJECT;
+}
+
+Object::Object(uint32_t obj_type, Vector3 pos) {
+ type = MSG_TYPE_OBJECT;
+
+ this->obj_type = obj_type;
+ this->pos = pos;
+}
+
+void Object::do_send(boost::asio::ip::tcp::socket& socket) {
+ write(socket, obj_type);
+ write(socket, pos.x);
+ write(socket, pos.y);
+ write(socket, pos.z);
+}
+
+void Object::recv(boost::asio::ip::tcp::socket& socket) {
+ read(socket, obj_type);
+ read(socket, pos.x);
+ read(socket, pos.y);
+ read(socket, pos.z);
+}
+
+uint32_t Object::get_type() {
+ return obj_type;
+}
+
+Vector3 Object::get_pos() {
+ return pos;
+}
diff --git a/messages.h b/messages.h
index 743914e..f1625f8 100644
--- a/messages.h
+++ b/messages.h
@@ -13,7 +13,8 @@ enum MessageType {
MSG_TYPE_POS,
MSG_TYPE_CHUNK,
MSG_TYPE_MSG,
- MSG_TYPE_PLAYER
+ MSG_TYPE_PLAYER,
+ MSG_TYPE_OBJECT
};
class MessageBase {
@@ -133,6 +134,24 @@ class Player : public MessageBase {
std::string get_name();
};
+// NOTE: This message type is subject to change!
+class Object : public MessageBase {
+ protected:
+ uint32_t obj_type;
+ Vector3 pos;
+
+ virtual void do_send(boost::asio::ip::tcp::socket& socket);
+
+ public:
+ Object();
+ Object(uint32_t obj_type, Vector3 pos);
+
+ virtual void recv(boost::asio::ip::tcp::socket& socket);
+
+ uint32_t get_type();
+ Vector3 get_pos();
+};
+
}
#endif