summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAaron Marks <nymacro@gmail.com>2005-07-19 12:10:18 +0000
committerAaron Marks <nymacro@gmail.com>2005-07-19 12:10:18 +0000
commit7c69090507eb2d314ca53d99265f538a10a0f1fb (patch)
tree5fe7d81018914ac6689d401f365f986cd6b15333 /src
parente57ecd19592ac46465d340d56c59a9faef26f18c (diff)
downloadmanaserv-7c69090507eb2d314ca53d99265f538a10a0f1fb.tar.gz
manaserv-7c69090507eb2d314ca53d99265f538a10a0f1fb.tar.bz2
manaserv-7c69090507eb2d314ca53d99265f538a10a0f1fb.tar.xz
manaserv-7c69090507eb2d314ca53d99265f538a10a0f1fb.zip
Added character creation.
Diffstat (limited to 'src')
-rw-r--r--src/accounthandler.cpp37
-rw-r--r--src/chathandler.cpp3
-rw-r--r--src/client.cpp13
-rw-r--r--src/connectionhandler.h5
-rw-r--r--src/defines.h5
-rw-r--r--src/main.cpp1
-rw-r--r--src/netcomputer.cpp8
-rw-r--r--src/netcomputer.h14
-rw-r--r--src/storage.h6
9 files changed, 75 insertions, 17 deletions
diff --git a/src/accounthandler.cpp b/src/accounthandler.cpp
index 0f5adddd..bdfa0ba4 100644
--- a/src/accounthandler.cpp
+++ b/src/accounthandler.cpp
@@ -50,6 +50,12 @@ void AccountHandler::receiveMessage(NetComputer &computer, MessageIn &message)
std::string username = message.readString();
std::string password = message.readString();
+ if (computer.getAccount() != NULL) {
+ result.writeShort(SMSG_LOGIN_ERROR);
+ result.writeShort(LOGIN_UNKNOWN);
+ break;
+ }
+
// see if the account exists
Account *acc = store.getAccount(username);
if (!acc) {
@@ -65,11 +71,24 @@ void AccountHandler::receiveMessage(NetComputer &computer, MessageIn &message)
result.writeShort(SMSG_LOGIN_ERROR);
result.writeByte(LOGIN_INVALID_PASSWORD);
} else {
- // Login OK! (send an OK message or something)
std::cout << "Login OK by " << username << std::endl;
+ // Associate account with connection
+ computer.setAccount(acc);
+
result.writeShort(SMSG_LOGIN_CONFIRM);
- // TODO: Return information about available characters
+
+ // Return information about available characters
+ tmwserv::Beings &chars = computer.getAccount()->getCharacters();
+ result.writeByte(chars.size());
+
+ for (unsigned int i = 0; i < chars.size(); i++) {
+ result.writeString(chars[i]->getName());
+ result.writeByte(chars[i]->getLevel());
+ result.writeByte(chars[i]->getMoney());
+ //result.writeString(chars[i]->getRawStatistics(),
+ // sizeof(tmwserv::RawStatistics));
+ }
}
}
break;
@@ -93,16 +112,26 @@ void AccountHandler::receiveMessage(NetComputer &computer, MessageIn &message)
case CMSG_CHAR_CREATE:
{
+ if (computer.getAccount() == NULL) {
+ result.writeShort(SMSG_CHAR_CREATE_RESPONSE);
+ result.writeByte(CREATE_NOLOGIN);
+ break;
+ }
+
std::string name = message.readString();
//char hairStyle = message.readByte();
//char hairColor = message.readByte();
- //char sex = message.readByte();
+ Genders sex = (Genders)message.readByte();
// TODO: Finish this message type (should a player customize stats
// slightly?)
+ tmwserv::RawStatistics stats = {10, 10, 10, 10, 10, 10};
+ tmwserv::BeingPtr newCharacter(new tmwserv::Being(name, sex, 1, 0, stats));
+ computer.getAccount()->addCharacter(newCharacter);
+
result.writeShort(SMSG_CHAR_CREATE_RESPONSE);
- result.writeShort(CREATE_OK);
+ result.writeByte(CREATE_OK);
}
break;
diff --git a/src/chathandler.cpp b/src/chathandler.cpp
index f3bf38b1..b6cd4f54 100644
--- a/src/chathandler.cpp
+++ b/src/chathandler.cpp
@@ -27,6 +27,9 @@
void ChatHandler::receiveMessage(NetComputer &computer, MessageIn &message)
{
+ if (computer.getAccount() == NULL)
+ return;
+
switch (message.getId())
{
case CMSG_SAY:
diff --git a/src/client.cpp b/src/client.cpp
index 40c9cdf2..06b67daf 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -54,6 +54,7 @@ int main(int argc, char *argv[])
printf ("0) Quit\n");
printf ("1) Register\n");
printf ("2) Login\n");
+ printf ("4) Create character\n");
printf ("3) Chat\n\n");
printf ("Insert your option: ");
std::cin >> answer;
@@ -90,6 +91,18 @@ int main(int argc, char *argv[])
msg.writeString(line);
msg.writeShort(0);
break;
+ case 4:
+ {
+ // Create character
+ msg.writeShort(CMSG_CHAR_CREATE);
+ printf("\nName: ");
+ std::cin >> line;
+ msg.writeString(line);
+ msg.writeByte(0);
+ } break;
+
+ default:
+ continue;
}
printf("\n");
diff --git a/src/connectionhandler.h b/src/connectionhandler.h
index a66c075b..92f7658d 100644
--- a/src/connectionhandler.h
+++ b/src/connectionhandler.h
@@ -99,11 +99,6 @@ class ConnectionHandler
*/
void registerHandler(unsigned int msgId, MessageHandler *handler);
- /**
- * Send queued packets to client
- */
- void sendPackets();
-
private:
std::map<unsigned int, MessageHandler*> handlers;
diff --git a/src/defines.h b/src/defines.h
index fe94d79c..d4c0e880 100644
--- a/src/defines.h
+++ b/src/defines.h
@@ -68,6 +68,8 @@ enum {
SMSG_LOGIN_CONFIRM = 0x0013,
CMSG_CHAR_CREATE = 0x0020,
SMSG_CHAR_CREATE_RESPONSE = 0x0021,
+ CMSG_CHAR_LIST = 0x0022, // this is required after char creation
+ CMSG_CHAR_SELECT = 0x0023,
// Objects
SMSG_NEW_OBJECT = 0x0100,
@@ -129,7 +131,8 @@ enum {
CREATE_INVALID_HAIR,
CREATE_INVALID_SEX,
CREATE_EXISTS_USERNAME,
- CREATE_EXISTS_EMAIL
+ CREATE_EXISTS_EMAIL,
+ CREATE_NOLOGIN
};
diff --git a/src/main.cpp b/src/main.cpp
index 315e4d5d..2eda5863 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -205,6 +205,7 @@ int main(int argc, char *argv[])
// Register message handlers
connectionHandler->registerHandler(CMSG_LOGIN, accountHandler);
connectionHandler->registerHandler(CMSG_REGISTER, accountHandler);
+ connectionHandler->registerHandler(CMSG_CHAR_CREATE, accountHandler);
connectionHandler->registerHandler(CMSG_SAY, chatHandler);
connectionHandler->registerHandler(CMSG_ANNOUNCE, chatHandler);
diff --git a/src/netcomputer.cpp b/src/netcomputer.cpp
index d56b4db7..a9245910 100644
--- a/src/netcomputer.cpp
+++ b/src/netcomputer.cpp
@@ -27,7 +27,8 @@
NetComputer::NetComputer(ConnectionHandler *handler, TCPsocket sock):
handler(handler),
- socket(sock)
+ socket(sock),
+ account(NULL)
{
}
@@ -45,3 +46,8 @@ void NetComputer::send(const Packet *p)
{
SDLNet_TCP_Send(socket, p->data, p->length);
}
+
+void NetComputer::setAccount(tmwserv::Account *acc)
+{
+ account = acc;
+}
diff --git a/src/netcomputer.h b/src/netcomputer.h
index d3eb0a05..29bf1412 100644
--- a/src/netcomputer.h
+++ b/src/netcomputer.h
@@ -30,6 +30,8 @@
#include <queue>
#include <list>
+#include "account.h"
+
// Forward declaration
class ConnectionHandler;
@@ -75,11 +77,23 @@ class NetComputer
*/
TCPsocket getSocket() { return socket; }
+ /**
+ * Set the account associated with the connection
+ */
+ void setAccount(tmwserv::Account *acc);
+
+ /**
+ * Get account associated with the connection
+ */
+ tmwserv::Account *getAccount() { return account; }
+
private:
ConnectionHandler *handler;
std::queue<Packet*> queue; /**< Message Queue (FIFO) */
TCPsocket socket; /**< Client socket */
+
+ tmwserv::Account *account; /**< Account associated with connection */
};
#endif
diff --git a/src/storage.h b/src/storage.h
index 0022aac4..13b9842f 100644
--- a/src/storage.h
+++ b/src/storage.h
@@ -280,12 +280,6 @@ class Storage
delAccount(const std::string& userName) = 0;
/**
- * Add character to account.
- */
- //virtual void
- //addCharacter(const Being *);
-
- /**
* Saves the changes permanently.
*/
virtual void