diff options
author | Aaron Marks <nymacro@gmail.com> | 2005-07-24 05:41:44 +0000 |
---|---|---|
committer | Aaron Marks <nymacro@gmail.com> | 2005-07-24 05:41:44 +0000 |
commit | b54666222ca5020438aa9151a51a295269b1b319 (patch) | |
tree | 76effbcef01e027f6de1b5f77b7c360884c88ac3 | |
parent | 7c69090507eb2d314ca53d99265f538a10a0f1fb (diff) | |
download | manaserv-b54666222ca5020438aa9151a51a295269b1b319.tar.gz manaserv-b54666222ca5020438aa9151a51a295269b1b319.tar.bz2 manaserv-b54666222ca5020438aa9151a51a295269b1b319.tar.xz manaserv-b54666222ca5020438aa9151a51a295269b1b319.zip |
Added character selection.
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/accounthandler.cpp | 20 | ||||
-rw-r--r-- | src/accounthandler.h | 1 | ||||
-rw-r--r-- | src/chathandler.cpp | 4 | ||||
-rw-r--r-- | src/chathandler.h | 3 | ||||
-rw-r--r-- | src/client.cpp | 12 | ||||
-rw-r--r-- | src/connectionhandler.cpp | 4 | ||||
-rw-r--r-- | src/defines.h | 7 | ||||
-rw-r--r-- | src/main.cpp | 1 | ||||
-rw-r--r-- | src/netcomputer.cpp | 8 | ||||
-rw-r--r-- | src/netcomputer.h | 12 |
11 files changed, 65 insertions, 9 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 37528879..affba32c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -12,6 +12,8 @@ tmwserv_SOURCES = main.cpp \ chathandler.cpp \ connectionhandler.h \ connectionhandler.cpp \ + gamehandler.h \ + gamehandler.cpp \ debug.h \ debug.cpp \ defines.h \ diff --git a/src/accounthandler.cpp b/src/accounthandler.cpp index bdfa0ba4..59956242 100644 --- a/src/accounthandler.cpp +++ b/src/accounthandler.cpp @@ -135,6 +135,26 @@ void AccountHandler::receiveMessage(NetComputer &computer, MessageIn &message) } break; + case CMSG_CHAR_SELECT: + { + if (computer.getAccount() == NULL) + break; // not logged in + + char charNum = message.readByte(); + + tmwserv::Beings &chars = computer.getAccount()->getCharacters(); + + result.writeShort(SMSG_CHAR_SELECT_RESPONSE); + if (charNum >= chars.size()) { + // invalid char selection + result.writeByte(SELECT_INVALID); + break; + } + + result.writeByte(SELECT_OK); + } + break; + default: std::cout << "Invalid message type" << std::endl; result.writeShort(SMSG_LOGIN_ERROR); diff --git a/src/accounthandler.h b/src/accounthandler.h index b9460cc2..f0df51b8 100644 --- a/src/accounthandler.h +++ b/src/accounthandler.h @@ -1,4 +1,3 @@ - /* * The Mana World Server * Copyright 2004 The Mana World Development Team diff --git a/src/chathandler.cpp b/src/chathandler.cpp index b6cd4f54..bd48a3d5 100644 --- a/src/chathandler.cpp +++ b/src/chathandler.cpp @@ -27,8 +27,8 @@ void ChatHandler::receiveMessage(NetComputer &computer, MessageIn &message) { - if (computer.getAccount() == NULL) - return; + if (computer.getCharacter() == NULL) + return; // character not selected switch (message.getId()) { diff --git a/src/chathandler.h b/src/chathandler.h index 597d61b0..5087cb0c 100644 --- a/src/chathandler.h +++ b/src/chathandler.h @@ -30,13 +30,12 @@ /** * Manages all chat related - * */ class ChatHandler : public MessageHandler { public: /** - * Recieves chat related messages. + * Receives chat related messages. */ void receiveMessage(NetComputer &computer, MessageIn &message); }; diff --git a/src/client.cpp b/src/client.cpp index 06b67daf..2b8b3204 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -54,8 +54,9 @@ int main(int argc, char *argv[]) printf ("0) Quit\n"); printf ("1) Register\n"); printf ("2) Login\n"); + printf ("3) Chat\n"); printf ("4) Create character\n"); - printf ("3) Chat\n\n"); + printf ("5) Character selecion\n"); printf ("Insert your option: "); std::cin >> answer; @@ -101,6 +102,15 @@ int main(int argc, char *argv[]) msg.writeByte(0); } break; + case 5: + { + // Select character + msg.writeShort(CMSG_CHAR_SELECT); + printf("\nCharacrer ID: "); + std::cin >> line; + msg.writeByte(atoi(line)); + } break; + default: continue; } diff --git a/src/connectionhandler.cpp b/src/connectionhandler.cpp index ad42adcf..6a46b94e 100644 --- a/src/connectionhandler.cpp +++ b/src/connectionhandler.cpp @@ -188,8 +188,8 @@ ConnectionHandler::startListen(ListenThreadData *ltd) std::string ipaddr = ip4ToString( SDLNet_TCP_GetPeerAddress(s)->host); - // Make sure that the packet is big enough - if (result >= 4) + // Make sure that the packet is big enough (> short) + if (result >= 2) { Packet *packet = new Packet(buffer, result); MessageIn msg(packet); // (MessageIn frees packet) diff --git a/src/defines.h b/src/defines.h index d4c0e880..35c05363 100644 --- a/src/defines.h +++ b/src/defines.h @@ -70,6 +70,7 @@ enum { SMSG_CHAR_CREATE_RESPONSE = 0x0021, CMSG_CHAR_LIST = 0x0022, // this is required after char creation CMSG_CHAR_SELECT = 0x0023, + SMSG_CHAR_SELECT_RESPONSE = 0x0034, // Objects SMSG_NEW_OBJECT = 0x0100, @@ -135,5 +136,11 @@ enum { CREATE_NOLOGIN }; +// Character selection return values +enum { + SELECT_OK = 0, + SELECT_INVALID +}; + #endif // _TMWSERV_DEFINES_H_ diff --git a/src/main.cpp b/src/main.cpp index 2eda5863..6178940f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -206,6 +206,7 @@ int main(int argc, char *argv[]) connectionHandler->registerHandler(CMSG_LOGIN, accountHandler); connectionHandler->registerHandler(CMSG_REGISTER, accountHandler); connectionHandler->registerHandler(CMSG_CHAR_CREATE, accountHandler); + connectionHandler->registerHandler(CMSG_CHAR_SELECT, accountHandler); connectionHandler->registerHandler(CMSG_SAY, chatHandler); connectionHandler->registerHandler(CMSG_ANNOUNCE, chatHandler); diff --git a/src/netcomputer.cpp b/src/netcomputer.cpp index a9245910..663d74a8 100644 --- a/src/netcomputer.cpp +++ b/src/netcomputer.cpp @@ -28,7 +28,8 @@ NetComputer::NetComputer(ConnectionHandler *handler, TCPsocket sock): handler(handler), socket(sock), - account(NULL) + account(NULL), + character(NULL) { } @@ -51,3 +52,8 @@ void NetComputer::setAccount(tmwserv::Account *acc) { account = acc; } + +void NetComputer::setCharacter(tmwserv::Being *ch) +{ + character = ch; +} diff --git a/src/netcomputer.h b/src/netcomputer.h index 29bf1412..1cecd719 100644 --- a/src/netcomputer.h +++ b/src/netcomputer.h @@ -31,6 +31,7 @@ #include <list> #include "account.h" +#include "being.h" // Forward declaration class ConnectionHandler; @@ -87,6 +88,16 @@ class NetComputer */ tmwserv::Account *getAccount() { return account; } + /** + * Set the selected character associated with connection + */ + void setCharacter(tmwserv::Being *ch); + + /** + * Get character associated with the connection + */ + tmwserv::Being *getCharacter() { return character; } + private: ConnectionHandler *handler; @@ -94,6 +105,7 @@ class NetComputer TCPsocket socket; /**< Client socket */ tmwserv::Account *account; /**< Account associated with connection */ + tmwserv::Being *character; /**< Selected character */ }; #endif |