From 87be1a8a52a5485d1cf90240cbf628004cbd5350 Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Sat, 13 May 2006 18:12:22 +0000 Subject: Applied patch by Guillaume Melquiond which adds ENet check and adds timer.cpp/h to the Makefile.am. Also fixed some compilation warnings. --- src/Makefile.am | 4 +++- src/client.cpp | 4 ++-- src/connectionhandler.cpp | 24 +++++++++++++----------- src/dalstorage.cpp | 10 +++++----- src/defines.h | 2 +- src/netcomputer.h | 34 +++++++++++++++++++++++----------- 6 files changed, 47 insertions(+), 31 deletions(-) (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index 90baf8b9..070d6f00 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -82,7 +82,9 @@ tmwserv_SOURCES = main.cpp \ utils/logger.h \ utils/logger.cpp \ utils/stringfilter.h \ - utils/stringfilter.cpp + utils/stringfilter.cpp \ + utils/timer.h \ + utils/timer.cpp if BUILD_MYSQL tmwserv_SOURCES += dal/mysqldataprovider.h \ diff --git a/src/client.cpp b/src/client.cpp index 81f023c7..d99690ca 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -437,7 +437,7 @@ void parsePacket(char *data, int recvLength) { // Register switch (msg.readByte()) { case LOGIN_OK: - char charNumber; + unsigned char charNumber; charNumber = msg.readByte(); std::cout << "Account has " << int(charNumber) << " characters." << std::endl; for (unsigned int i = 0; i < charNumber; i++) { @@ -654,7 +654,7 @@ void parsePacket(char *data, int recvLength) { { switch (msg.readByte()) { case CHAR_LIST_OK: - char charNumber; + unsigned char charNumber; charNumber = msg.readByte(); std::cout << "Character List:" << std::endl << "---------------" << std::endl; diff --git a/src/connectionhandler.cpp b/src/connectionhandler.cpp index b0a85f71..b7d1b1ba 100644 --- a/src/connectionhandler.cpp +++ b/src/connectionhandler.cpp @@ -103,7 +103,7 @@ ConnectionHandler::startListen(ListenThreadData *ltd) while (ltd->running) { ENetEvent event; - + // Wait up to 1000 milliseconds for an event. while (enet_host_service(ltd->host, &event, 1000) > 0) { @@ -119,19 +119,19 @@ ConnectionHandler::startListen(ListenThreadData *ltd) computerConnected(comp); /*LOG_INFO(ltd->host->peerCount << " client(s) connected", 0);*/ - + // Store any relevant client information here. event.peer->data = (void *)comp; } break; - + case ENET_EVENT_TYPE_RECEIVE: { LOG_INFO("A packet of length " << event.packet->dataLength << " was received from " << event.peer->address.host, 2); - + NetComputer *comp = (NetComputer *)event.peer->data; - + #ifdef SCRIPT_SUPPORT // This could be good if you wanted to extend the // server protocol using a scripting language. This @@ -171,11 +171,11 @@ ConnectionHandler::startListen(ListenThreadData *ltd) else { LOG_ERROR("Message too short from " << ipaddr, 0); } - + /* Clean up the packet now that we're done using it. */ enet_packet_destroy(event.packet); } break; - + case ENET_EVENT_TYPE_DISCONNECT: { NetComputer *comp = (NetComputer *)event.peer->data; @@ -186,12 +186,14 @@ ConnectionHandler::startListen(ListenThreadData *ltd) delete comp; event.peer->data = NULL; } break; + + default: break; } } } - + // - Disconnect all clients (close sockets) - + // TODO: probably there's a better way. ENetPeer *currentPeer; @@ -265,9 +267,9 @@ void ConnectionHandler::sendAround(tmwserv::BeingPtr beingPtr, MessageOut &msg) i != clients.end(); i++) { // See if the other being is near enough, then send the message - if (abs((*i)->getCharacter().get()->getX() - beingPtr.get()->getX()) <= AROUND_AREA_IN_TILES ) + if (abs((*i)->getCharacter().get()->getX() - beingPtr.get()->getX()) <= (int)AROUND_AREA_IN_TILES ) { - if (abs((*i)->getCharacter().get()->getY() - beingPtr.get()->getY()) <= AROUND_AREA_IN_TILES ) + if (abs((*i)->getCharacter().get()->getY() - beingPtr.get()->getY()) <= (int)AROUND_AREA_IN_TILES ) { (*i)->send(msg.getPacket()); break; diff --git a/src/dalstorage.cpp b/src/dalstorage.cpp index 5d4f96a6..cb0f87dc 100644 --- a/src/dalstorage.cpp +++ b/src/dalstorage.cpp @@ -231,10 +231,10 @@ DALStorage::getAccount(const std::string& userName) LOG_INFO(userName << "'s account has " << charInfo.rows() << " character(s) in database.", 1) - // As the recordset functions are set to be able to get one recordset - // at a time, we store charInfo in a temp array of strings - // To avoid the problem where values of charInfo were erased by the - // values of mapInfo. + // As the recordset functions are set to be able to get one + // recordset at a time, we store charInfo in a temp array of + // strings. To avoid the problem where values of charInfo were + // erased by the values of mapInfo. std::string strCharInfo[charInfo.rows()][charInfo.cols()]; for (unsigned int i = 0; i < charInfo.rows(); ++i) { @@ -247,7 +247,7 @@ DALStorage::getAccount(const std::string& userName) for (unsigned int k = 0; k < charRows; ++k) { RawStatistics stats = { - toUshort(strCharInfo[k][11]), // strength + toUshort(strCharInfo[k][11]), // strength toUshort(strCharInfo[k][12]), // agility toUshort(strCharInfo[k][13]), // vitality toUshort(strCharInfo[k][14]), // intelligence diff --git a/src/defines.h b/src/defines.h index c4d00bb5..faab7073 100644 --- a/src/defines.h +++ b/src/defines.h @@ -182,7 +182,7 @@ enum { SMSG_QUIT_CHANNEL_RESPONSE = 0x0422, // Other - SMSG_LOAD_MAP = 0x0500, + SMSG_LOAD_MAP = 0x0500 // NOTE: We will need more messages for in-game control (eg. moving a client to a new map/position etc.). Currently the protocol only caters for the bare basics. }; diff --git a/src/netcomputer.h b/src/netcomputer.h index 2e74c960..de3e822d 100644 --- a/src/netcomputer.h +++ b/src/netcomputer.h @@ -56,12 +56,14 @@ class NetComputer /** * Returns true if this computer is disconnected. */ - //bool isDisconnected(); + //bool + //isDisconnected(); /** * Disconnects the computer from the server. */ - void disconnect(const std::string &reason); + void + disconnect(const std::string &reason); /** * Queues (FIFO) a packet for sending to a client. @@ -70,7 +72,8 @@ class NetComputer * introduce the reliable argument, which would cause a UDP message * to be sent when set to false. */ - void send(const Packet *p); + void + send(const Packet *p); //void send(Packet *p, bool reliable = true); /** @@ -81,33 +84,39 @@ class NetComputer /** * Set the account associated with the connection */ - void setAccount(tmwserv::AccountPtr acc); + void + setAccount(tmwserv::AccountPtr acc); /** * Unset the account associated with the connection */ - void unsetAccount(); + void + unsetAccount(); /** * Get account associated with the connection */ - tmwserv::AccountPtr getAccount() { return mAccountPtr; } + tmwserv::AccountPtr + getAccount() { return mAccountPtr; } /** * Set the selected character associated with connection */ - void setCharacter(tmwserv::BeingPtr ch); + void + setCharacter(tmwserv::BeingPtr ch); /** * Deselect the character associated with connection * and remove it from the world */ - void unsetCharacter(); + void + unsetCharacter(); /** * Get character associated with the connection */ - tmwserv::BeingPtr getCharacter() { return mCharacterPtr; } + tmwserv::BeingPtr + getCharacter() { return mCharacterPtr; } private: ConnectionHandler *handler; @@ -115,8 +124,11 @@ class NetComputer std::queue queue; /**< Message Queue (FIFO) */ ENetPeer *peer; /**< Client peer */ - tmwserv::AccountPtr mAccountPtr; /**< Account associated with connection */ - tmwserv::BeingPtr mCharacterPtr; /**< Selected character */ + /** Account associated with connection */ + tmwserv::AccountPtr mAccountPtr; + + /** Selected character */ + tmwserv::BeingPtr mCharacterPtr; }; #endif -- cgit v1.2.3-70-g09d2