summaryrefslogtreecommitdiff
path: root/src/netcomputer.cpp
diff options
context:
space:
mode:
authorAaron Marks <nymacro@gmail.com>2005-07-17 03:18:31 +0000
committerAaron Marks <nymacro@gmail.com>2005-07-17 03:18:31 +0000
commit98f41d64a9a1628dd132b356487415762b1409a8 (patch)
treec2e784d778c0285f589d555f6acb4395485bb406 /src/netcomputer.cpp
parent49bc551cc81f23c6e5243e1ddb0ddf6d0159c544 (diff)
downloadmanaserv-98f41d64a9a1628dd132b356487415762b1409a8.tar.gz
manaserv-98f41d64a9a1628dd132b356487415762b1409a8.tar.bz2
manaserv-98f41d64a9a1628dd132b356487415762b1409a8.tar.xz
manaserv-98f41d64a9a1628dd132b356487415762b1409a8.zip
Added server->client communications.
Updated MessageHandler's to use short for message type.
Diffstat (limited to 'src/netcomputer.cpp')
-rw-r--r--src/netcomputer.cpp30
1 files changed, 29 insertions, 1 deletions
diff --git a/src/netcomputer.cpp b/src/netcomputer.cpp
index 79110fd4..bffe7b86 100644
--- a/src/netcomputer.cpp
+++ b/src/netcomputer.cpp
@@ -22,15 +22,43 @@
*/
#include "netcomputer.h"
-
+#include <cstdlib>
+#include <iostream>
NetComputer::NetComputer(ConnectionHandler *handler):
handler(handler)
{
}
+NetComputer::~NetComputer()
+{
+ // delete unsent messages
+ while (queue.size() > 0) {
+ delete queue.front();
+ queue.pop();
+ }
+}
+
void NetComputer::disconnect(const std::string &reason)
{
// Somehow notify the netsession listener about the disconnect after
// sending this computer a disconnect message containing the reason.
}
+
+void NetComputer::send(const Packet *p)
+{
+ // Copy the packet
+ Packet *newPacket = new Packet(NULL, 0);
+ newPacket->data = new char[p->length];
+ memcpy(newPacket->data, (void*) p->data, p->length);
+ newPacket->length = p->length;
+
+ queue.push(newPacket);
+}
+
+Packet *NetComputer::front()
+{
+ Packet *ret = queue.front();
+ queue.pop();
+ return ret;
+}