summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2006-05-13 18:12:22 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2006-05-13 18:12:22 +0000
commit87be1a8a52a5485d1cf90240cbf628004cbd5350 (patch)
tree5b165cc291021acdca249b040b47656093d7fea7 /src
parentc01baa046b6cfdfe8da438d3e60d6cfa141a674f (diff)
downloadmanaserv-87be1a8a52a5485d1cf90240cbf628004cbd5350.tar.gz
manaserv-87be1a8a52a5485d1cf90240cbf628004cbd5350.tar.bz2
manaserv-87be1a8a52a5485d1cf90240cbf628004cbd5350.tar.xz
manaserv-87be1a8a52a5485d1cf90240cbf628004cbd5350.zip
Applied patch by Guillaume Melquiond which adds ENet check and adds timer.cpp/h
to the Makefile.am. Also fixed some compilation warnings.
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am4
-rw-r--r--src/client.cpp4
-rw-r--r--src/connectionhandler.cpp24
-rw-r--r--src/dalstorage.cpp10
-rw-r--r--src/defines.h2
-rw-r--r--src/netcomputer.h34
6 files changed, 47 insertions, 31 deletions
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 <code>true</code> 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<Packet*> 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