summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAaron Marks <nymacro@gmail.com>2005-07-18 11:47:00 +0000
committerAaron Marks <nymacro@gmail.com>2005-07-18 11:47:00 +0000
commit62395df8a674475cd7b277e964cc5512fa6e7576 (patch)
tree8e20148fc8990d2f012473e4a266440b24a8c2c9 /src
parent98f41d64a9a1628dd132b356487415762b1409a8 (diff)
downloadmanaserv-62395df8a674475cd7b277e964cc5512fa6e7576.tar.gz
manaserv-62395df8a674475cd7b277e964cc5512fa6e7576.tar.xz
manaserv-62395df8a674475cd7b277e964cc5512fa6e7576.zip
Updated server->client communications.
Diffstat (limited to 'src')
-rw-r--r--src/accounthandler.cpp10
-rw-r--r--src/connectionhandler.cpp27
-rw-r--r--src/connectionhandler.h2
-rw-r--r--src/defines.h3
-rw-r--r--src/main.cpp3
-rw-r--r--src/netcomputer.cpp25
-rw-r--r--src/netcomputer.h14
-rw-r--r--src/storage.h5
8 files changed, 31 insertions, 58 deletions
diff --git a/src/accounthandler.cpp b/src/accounthandler.cpp
index a23ac66..6bc1b68 100644
--- a/src/accounthandler.cpp
+++ b/src/accounthandler.cpp
@@ -94,11 +94,17 @@ void AccountHandler::receiveMessage(NetComputer &computer, MessageIn &message)
case CMSG_CHAR_CREATE:
{
std::string name = message.readString();
+ char hairStyle = message.readByte();
+ char hairColor = message.readByte();
+ char sex = message.readByte();
+
// TODO: Finish this message type (should a player customize stats
// slightly?)
- result.writeShort(LOGIN_UNKNOWN);
+
+ result.writeShort(SMSG_CHAR_CREATE_RESPONSE);
+ result.writeShort(CREATE_OK);
} break;
-
+
default:
std::cout << "Invalid message type" << std::endl;
result.writeShort(SMSG_LOGIN_ERROR);
diff --git a/src/connectionhandler.cpp b/src/connectionhandler.cpp
index d0a0d23..338913f 100644
--- a/src/connectionhandler.cpp
+++ b/src/connectionhandler.cpp
@@ -135,8 +135,8 @@ ConnectionHandler::startListen(ListenThreadData *ltd)
LOG_ERROR("SDLNet_AddSocket: " << SDLNet_GetError())
}
else {
- NetComputer *comp = new NetComputer(this);
- clients[comp] = client;
+ NetComputer *comp = new NetComputer(this, client);
+ clients.push_back(comp);
computerConnected(comp);
LOG_INFO(clients.size() << " clients connected")
}
@@ -144,10 +144,10 @@ ConnectionHandler::startListen(ListenThreadData *ltd)
}
// Check client sockets
- std::map<NetComputer*, TCPsocket>::iterator i;
+ std::list<NetComputer*>::iterator i;
for (i = clients.begin(); i != clients.end(); ) {
- NetComputer *comp = (*i).first;
- TCPsocket s = (*i).second;
+ NetComputer *comp = *i;
+ TCPsocket s = (*i)->getSocket();
if (SDLNet_SocketReady(s)) {
char buffer[1024];
@@ -213,7 +213,7 @@ ConnectionHandler::startListen(ListenThreadData *ltd)
// Traverse to next client, possibly deleting current
if (comp == NULL) {
- std::map<NetComputer*, TCPsocket>::iterator ii = i;
+ std::list<NetComputer*>::iterator ii = i;
ii++;
clients.erase(i);
i = ii;
@@ -245,18 +245,3 @@ void ConnectionHandler::registerHandler(
{
handlers[msgId] = handler;
}
-
-void ConnectionHandler::sendPackets()
-{
- for (std::map<NetComputer*, TCPsocket>::iterator i = clients.begin();
- i != clients.end(); i++) {
- NetComputer *computer = i->first;
-
- while (computer->size() > 0) {
- // Send queued packet
- Packet *packet = computer->front();
- SDLNet_TCP_Send(i->second, packet->data, packet->length);
- delete packet;
- }
- }
-}
diff --git a/src/connectionhandler.h b/src/connectionhandler.h
index 0f11476..589838b 100644
--- a/src/connectionhandler.h
+++ b/src/connectionhandler.h
@@ -106,7 +106,7 @@ class ConnectionHandler
private:
std::map<unsigned int, MessageHandler*> handlers;
- std::map<NetComputer*, TCPsocket> clients;
+ std::list<NetComputer*> clients;
};
#endif
diff --git a/src/defines.h b/src/defines.h
index 7fb3310..fe94d79 100644
--- a/src/defines.h
+++ b/src/defines.h
@@ -124,7 +124,8 @@ enum {
// Character creation return values
enum {
- CREATE_INVALID_NAME = 0,
+ CREATE_OK = 0,
+ CREATE_INVALID_NAME,
CREATE_INVALID_HAIR,
CREATE_INVALID_SEX,
CREATE_EXISTS_USERNAME,
diff --git a/src/main.cpp b/src/main.cpp
index a4c2067..315e4d5 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -238,9 +238,6 @@ int main(int argc, char *argv[])
// - Handle all messages that are in the message queue
// - Update all active objects/beings
updateWorld();
-
- // Send data to client
- connectionHandler->sendPackets();
}
else if (event.type == SDL_QUIT) {
running = false;
diff --git a/src/netcomputer.cpp b/src/netcomputer.cpp
index bffe7b8..d56b4db 100644
--- a/src/netcomputer.cpp
+++ b/src/netcomputer.cpp
@@ -25,18 +25,14 @@
#include <cstdlib>
#include <iostream>
-NetComputer::NetComputer(ConnectionHandler *handler):
- handler(handler)
+NetComputer::NetComputer(ConnectionHandler *handler, TCPsocket sock):
+ handler(handler),
+ socket(sock)
{
}
NetComputer::~NetComputer()
{
- // delete unsent messages
- while (queue.size() > 0) {
- delete queue.front();
- queue.pop();
- }
}
void NetComputer::disconnect(const std::string &reason)
@@ -47,18 +43,5 @@ void NetComputer::disconnect(const std::string &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;
+ SDLNet_TCP_Send(socket, p->data, p->length);
}
diff --git a/src/netcomputer.h b/src/netcomputer.h
index 046c2a6..83382a7 100644
--- a/src/netcomputer.h
+++ b/src/netcomputer.h
@@ -43,7 +43,7 @@ class NetComputer
/**
* Constructor.
*/
- NetComputer(ConnectionHandler *handler);
+ NetComputer(ConnectionHandler *handler, TCPsocket sock);
/**
* Destructor
@@ -69,21 +69,17 @@ class NetComputer
*/
void send(const Packet *p);
//void send(Packet *p, bool reliable = true);
-
- /**
- * Get next message
- */
- Packet *front();
-
+
/**
- * Number of messages in queue
+ * Return the socket
*/
- unsigned int size() { return queue.size(); }
+ TCPsocket getSocket() { return socket; }
private:
ConnectionHandler *handler;
std::queue<Packet*> queue; /**< Message Queue (FIFO) */
+ TCPsocket socket; /**< Client socket */
};
#endif
diff --git a/src/storage.h b/src/storage.h
index 3adf1b2..0022aac 100644
--- a/src/storage.h
+++ b/src/storage.h
@@ -279,6 +279,11 @@ class Storage
virtual void
delAccount(const std::string& userName) = 0;
+ /**
+ * Add character to account.
+ */
+ //virtual void
+ //addCharacter(const Being *);
/**
* Saves the changes permanently.