summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHuynh Tran <nthuynh75@gmail.com>2005-06-19 10:09:29 +0000
committerHuynh Tran <nthuynh75@gmail.com>2005-06-19 10:09:29 +0000
commitdd0c3c867f1680589baafb317e456f6bae811a19 (patch)
tree29e9bb8365d07b59097e2f9497901e139958e1bf
parente3af53a61d6e22f93f31df3f385288031225c64e (diff)
downloadmanaserv-dd0c3c867f1680589baafb317e456f6bae811a19.tar.gz
manaserv-dd0c3c867f1680589baafb317e456f6bae811a19.tar.bz2
manaserv-dd0c3c867f1680589baafb317e456f6bae811a19.tar.xz
manaserv-dd0c3c867f1680589baafb317e456f6bae811a19.zip
Actually using the new Logger now.
-rw-r--r--configure.ac2
-rw-r--r--src/Makefile.am19
-rw-r--r--src/connectionhandler.cpp71
-rw-r--r--src/main.cpp146
-rw-r--r--src/skill.cpp31
5 files changed, 137 insertions, 132 deletions
diff --git a/configure.ac b/configure.ac
index 4c5e1095..47adf476 100644
--- a/configure.ac
+++ b/configure.ac
@@ -33,6 +33,8 @@ AC_PROG_RANLIB
# Checks for libraries.
AC_CHECK_LIB([physfs], [PHYSFS_init])
AC_CHECK_LIB([SDL_net], [SDLNet_Init])
+AC_CHECK_LIB([crypto], [EVP_Digest])
+AC_CHECK_LIB([crypto], [EVP_md5])
AC_ARG_WITH(scripting,[ --with-scripting Build with scripting])
if test "x$with_scripting" == "xyes"; then
diff --git a/src/Makefile.am b/src/Makefile.am
index 0efc4646..71f67e5e 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -19,8 +19,6 @@ tmwserv_SOURCES = main.cpp \
netsession.cpp \
packet.h \
packet.cpp \
- log.h \
- log.cpp \
skill.h \
skill.cpp \
script.h \
@@ -43,11 +41,20 @@ tmwserv_SOURCES = main.cpp \
dal/dalexcept.h \
dalstorage.h \
dalstoragesql.h \
- dalstorage.cpp
+ dalstorage.cpp \
+ utils/singleton.h \
+ utils/cipher.h \
+ utils/cipher.cpp \
+ utils/logger.h \
+ utils/logger.cpp
# dal/mysqldataprovider.h
# dal/mysqldataprovider.cpp
+# Obsoleted by utils/logger.*
+#
+# log.h
+# log.cpp
# Obsoleted by DAL.
#
@@ -63,7 +70,11 @@ INCLUDES= $(all_includes) $(SQLITE_CFLAGS)
LIBS = $(SQLITE_LIBS)
# the library search path.
-tmwserv_LDFLAGS = $(all_libraries) -lSDL_net `sdl-config --libs` `pkg-config --libs libxml-2.0` -lphysfs
+tmwserv_LDFLAGS = $(all_libraries) \
+ -lSDL_net `sdl-config --libs` \
+ `pkg-config --libs libxml-2.0` \
+ -lphysfs \
+ -lcrypto
tmwserv_CXXFLAGS = -g -Wall `sdl-config --cflags` `pkg-config --cflags libxml-2.0` -fno-inline $(SCRIPT_CFLAGS)
#tmwserv_LDADD = $(LIBSDL_LIBS) -lphysfs
tmwserv_LDADD = $(SCRIPT_LIBS)
diff --git a/src/connectionhandler.cpp b/src/connectionhandler.cpp
index 5f09e9c7..e8c9a592 100644
--- a/src/connectionhandler.cpp
+++ b/src/connectionhandler.cpp
@@ -4,26 +4,26 @@
*
* This file is part of The Mana World.
*
- * The Mana World is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
+ * The Mana World is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or any later version.
*
- * The Mana World is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
+ * The Mana World is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
*
- * You should have received a copy of the GNU General Public License
- * along with The Mana World; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * You should have received a copy of the GNU General Public License along
+ * with The Mana World; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* $Id$
*/
+
#include "connectionhandler.h"
#include "netsession.h"
-#include "log.h"
+#include "utils/logger.h"
#ifdef SCRIPT_SUPPORT
#include "script.h"
@@ -45,76 +45,67 @@ void ConnectionHandler::startListen(ListenThreadData *ltd)
// Allocate a socket set
SDLNet_SocketSet set = SDLNet_AllocSocketSet(MAX_CLIENTS);
if (!set) {
- logger->log("SDLNet_AllocSocketSet: %s", SDLNet_GetError());
+ LOG_FATAL("SDLNet_AllocSocketSet: " << SDLNet_GetError())
exit(1);
}
// Add the server socket to the socket set
if (SDLNet_TCP_AddSocket(set, ltd->socket) < 0) {
- logger->log("SDLNet_AddSocket: %s", SDLNet_GetError());
+ LOG_FATAL("SDLNet_AddSocket: " << SDLNet_GetError())
exit(1);
}
// Keep checking for socket activity while running
- while (ltd->running)
- {
+ while (ltd->running) {
int numready = SDLNet_CheckSockets(set, 100);
- if (numready == -1)
- {
- printf("SDLNet_CheckSockets: %s\n", SDLNet_GetError());
- logger->log("SDLNet_CheckSockets: %s", SDLNet_GetError());
+ if (numready == -1) {
+ LOG_ERROR("SDLNet_CheckSockets: " << SDLNet_GetError())
// When this is a system error, perror may help us
perror("SDLNet_CheckSockets");
}
- else if (numready > 0)
- {
- logger->log("%d sockets with activity!\n", numready);
+ else if (numready > 0) {
+ LOG_INFO(numready << " sockets with activity!")
// Check server socket
- if (SDLNet_SocketReady(ltd->socket))
- {
+ if (SDLNet_SocketReady(ltd->socket)) {
TCPsocket client = SDLNet_TCP_Accept(ltd->socket);
- if (client)
- {
+
+ if (client) {
// Add the client socket to the socket set
if (SDLNet_TCP_AddSocket(set, client) < 0) {
- logger->log("SDLNet_AddSocket: %s", SDLNet_GetError());
+ LOG_ERROR("SDLNet_AddSocket: " << SDLNet_GetError())
}
else {
NetComputer *comp = new NetComputer(this);
clients[comp] = client;
computerConnected(comp);
- logger->log("%d clients connected", clients.size());
+ LOG_INFO(clients.size() << " clients connected")
}
}
}
// Check client sockets
std::map<NetComputer*, TCPsocket>::iterator i;
- for (i = clients.begin(); i != clients.end(); )
- {
+ for (i = clients.begin(); i != clients.end(); ) {
NetComputer *comp = (*i).first;
TCPsocket s = (*i).second;
- if (SDLNet_SocketReady(s))
- {
+ if (SDLNet_SocketReady(s)) {
char buffer[1024];
int result = SDLNet_TCP_Recv(s, buffer, 1024);
- if (result <= 0)
- {
+ if (result <= 0) {
SDLNet_TCP_DelSocket(set, s);
SDLNet_TCP_Close(s);
computerDisconnected(comp);
delete comp;
comp = NULL;
}
- else
- {
+ else {
// Copy the incoming data to the in buffer of this
// client
buffer[result] = 0;
- logger->log("Received %s", buffer);
+ LOG_INFO("Received " << buffer);
#ifdef SCRIPT_SUPPORT
//script->message(buffer);
#endif
@@ -142,12 +133,12 @@ void ConnectionHandler::startListen(ListenThreadData *ltd)
void ConnectionHandler::computerConnected(NetComputer *comp)
{
- logger->log("A client connected!");
+ LOG_INFO("A client connected!")
}
void ConnectionHandler::computerDisconnected(NetComputer *comp)
{
- logger->log("A client disconnected!");
+ LOG_INFO("A client disconnected!")
}
void ConnectionHandler::registerHandler(
diff --git a/src/main.cpp b/src/main.cpp
index dbde8cad..8f702be6 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -4,65 +4,69 @@
*
* This file is part of The Mana World.
*
- * The Mana World is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
+ * The Mana World is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or any later version.
*
- * The Mana World is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
+ * The Mana World is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
*
- * You should have received a copy of the GNU General Public License
- * along with The Mana World; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * You should have received a copy of the GNU General Public License along
+ * with The Mana World; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* $Id$
*/
+
#define TMWSERV_VERSION "0.0.1"
#include <iostream>
+
+#include <SDL.h>
+#include <SDL_net.h>
+
#include "netsession.h"
#include "connectionhandler.h"
#include "accounthandler.h"
#include "storage.h"
-#include <SDL.h>
-#include <SDL_net.h>
#include "skill.h"
-#include "log.h"
-#define LOG_FILE "tmwserv.log"
+
+#include "utils/logger.h"
// Scripting
#ifdef SCRIPT_SUPPORT
#include "script.h"
+
#define SCRIPT_SQUIRREL_SUPPORT
-#ifdef SCRIPT_SQUIRREL_SUPPORT
+#if define (SCRIPT_SQUIRREL_SUPPORT)
#include "script-squirrel.h"
-#endif
-#ifdef SCRIPT_RUBY_SUPPORT
+#elif define (SCRIPT_RUBY_SUPPORT)
#include "script-ruby.h"
-#endif
-#ifdef SCRIPT_LUA_SUPPORT
+#elif define (SCRIPT_LUA_SUPPORT)
#include "script-lua.h"
#endif
std::string scriptLanguage = "squirrel";
-#endif
-//
+
+#endif // SCRIPT_SUPPORT
+
+#define LOG_FILE "tmwserv.log"
#define TMW_WORLD_TICK SDL_USEREVENT
#define SERVER_PORT 9601
-SDL_TimerID worldTimerID; /**< Timer ID of world timer */
-int worldTime = 0; /**< Current world time in 100ms ticks */
-bool running = true; /**< Determines if server keeps running */
-Skill skillTree("base"); /**< Skill tree */
+SDL_TimerID worldTimerID; /**< Timer ID of world timer */
+int worldTime = 0; /**< Current world time in 100ms ticks */
+bool running = true; /**< Determines if server keeps running */
+
+Skill skillTree("base"); /**< Skill tree */
/**
@@ -73,51 +77,55 @@ Uint32 worldTick(Uint32 interval, void *param)
// Push the custom world tick event
SDL_Event event;
event.type = TMW_WORLD_TICK;
+
if (SDL_PushEvent(&event)) {
- logger->log("Warning: couldn't push world tick into event queue!");
+ LOG_WARN("couldn't push world tick into event queue!")
}
+
return interval;
}
+
/**
* Initializes the server.
*/
void initialize()
{
- // Initialize the logger
- logger = new Logger(LOG_FILE);
-
- // Initialize SDL
- if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) == -1)
- {
- logger->log("SDL_Init: %s", SDL_GetError());
+ // initialize the logger.
+ using namespace tmwserv::utils;
+ Logger::instance().setLogFile(LOG_FILE);
+ // write the messages to both the screen and the log file.
+ Logger::instance().setTeeMode(true);
+
+ // initialize SDL.
+ if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) == -1) {
+ LOG_FATAL("SDL_Init: " << SDL_GetError())
exit(1);
}
- // Set SDL to quit on exit
+ // set SDL to quit on exit.
atexit(SDL_Quit);
- // Initialize SDL_net
- if (SDLNet_Init() == -1)
- {
- logger->log("SDLNet_Init: %s", SDLNet_GetError());
+ // initialize SDL_net.
+ if (SDLNet_Init() == -1) {
+ LOG_FATAL("SDLNet_Init: " << SDLNet_GetError())
exit(2);
}
- // Initialize world timer at 10 times per second
+ // initialize world timer at 10 times per second.
worldTimerID = SDL_AddTimer(100, worldTick, NULL);
- // Initialize scripting subsystem
+ // initialize scripting subsystem.
#ifdef SCRIPT_SUPPORT
- logger->log("Script Language %s", scriptLanguage.c_str());
+ LOG_INFO("Script Language " << scriptLanguage)
- if (scriptLanguage == "squirrel")
- {
+ if (scriptLanguage == "squirrel") {
script = new ScriptSquirrel("main.nut");
}
#endif
}
+
/**
* Deinitializes the server.
*/
@@ -136,10 +144,9 @@ void deinitialize()
// Get rid of persistent data storage
tmwserv::Storage::destroy();
-
- delete logger;
}
+
/**
* Update game world
*/
@@ -150,6 +157,7 @@ void updateWorld()
#endif
}
+
/**
* Main function, initializes and runs server.
*/
@@ -168,53 +176,46 @@ int main(int argc, char *argv[])
//AccountHandler *accountHandler = new AccountHandler();
//connectionHandler->registerHandler(C2S_LOGIN, accountHandler);
- logger->log("The Mana World Server v%s", TMWSERV_VERSION);
+ LOG_INFO("The Mana World Server v" << TMWSERV_VERSION)
session->startListen(connectionHandler, SERVER_PORT);
- logger->log("Listening on port %d...", SERVER_PORT);
+ LOG_INFO("Listening on port " << SERVER_PORT << "...")
tmwserv::Storage& store = tmwserv::Storage::instance();
- std::cout << "Number of accounts on server: " << store.getAccountCount() << std::endl;
+ LOG_INFO("Number of accounts on server: " << store.getAccountCount())
// Test the database retrieval code
- std::cout << "Attempting to retrieve account with username 'nym'" << std::endl;
+ LOG_INFO("Attempting to retrieve account with username 'nym'")
Account* acc = store.getAccount("nym");
if (acc)
{
- std::cout << "Account name: " << acc->getName() << std::endl
- << "Account email: " << acc->getEmail() << std::endl;
+ LOG_INFO("Account name: " << acc->getName())
+ LOG_INFO("Account email: " << acc->getEmail())
- std::cout << "Attempting to get character 'Nym the Great'" << std::endl;
+ LOG_INFO("Attempting to get character 'Nym the Great'")
Being* character = acc->getCharacter("Nym the Great");
- if (character)
- {
- std::cout << "Character name: " << character->getName() << std::endl;
+ if (character) {
+ LOG_INFO("Character name: " << character->getName())
}
- else
- {
- std::cout << "No characters found" << std::endl;
+ else {
+ LOG_WARN("No characters found")
}
}
- else
- {
- std::cout << "Account 'nym' not found" << std::endl;
+ else {
+ LOG_WARN("Account 'nym' not found")
}
SDL_Event event;
- while (running)
- {
- while (SDL_PollEvent(&event))
- {
- if (event.type == TMW_WORLD_TICK)
- {
+ while (running) {
+ while (SDL_PollEvent(&event)) {
+ if (event.type == TMW_WORLD_TICK) {
// Move the world forward in time
worldTime++;
// Print world time at 10 second intervals to show we're alive
if (worldTime % 100 == 0) {
- //printf("World time: %d\n", worldTime);
- logger->log("World time: %d", worldTime);
+ LOG_INFO("World time: " << worldTime);
}
// - Handle all messages that are in the message queue
@@ -222,8 +223,7 @@ int main(int argc, char *argv[])
updateWorld();
}
- else if (event.type == SDL_QUIT)
- {
+ else if (event.type == SDL_QUIT) {
running = false;
}
}
@@ -233,7 +233,7 @@ int main(int argc, char *argv[])
SDL_Delay(100);
}
- logger->log("Recieved Quit signal, closing down...");
+ LOG_INFO("Recieved Quit signal, closing down...")
session->stopListen(SERVER_PORT);
deinitialize();
diff --git a/src/skill.cpp b/src/skill.cpp
index 56076411..12ead5c4 100644
--- a/src/skill.cpp
+++ b/src/skill.cpp
@@ -4,25 +4,26 @@
*
* This file is part of The Mana World.
*
- * The Mana World is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
+ * The Mana World is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or any later version.
*
- * The Mana World is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
+ * The Mana World is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
*
- * You should have received a copy of the GNU General Public License
- * along with The Mana World; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * You should have received a copy of the GNU General Public License along
+ * with The Mana World; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* $Id$
*/
+
#include "skill.h"
-#include "log.h"
+#include "utils/logger.h"
+
Skill::Skill(const std::string &ident) :
id(ident),
@@ -58,9 +59,9 @@ bool Skill::addSkill(const std::string &ident, Skill *skill) {
bool Skill::useSkill() {
#ifdef SCRIPT_SUPPORT
//run skill script
- logger->log("Error: Skill: Skills not implemented.");
+ LOG_ERROR("Skill: Skills not implemented.")
#else
- logger->log("Error: Skill: Could not use skill; scripting disabled.");
+ LOG_ERROR("Skill: Could not use skill; scripting disabled.")
#endif
return true;
}
@@ -73,7 +74,7 @@ bool Skill::setScript(const std::string &scriptName)
bool Skill::deleteSkill(const std::string &ident, bool delTree) {
//prevent deletion of self
if (ident == id) {
- logger->log("Error: Skill: Attempt to delete self.");
+ LOG_ERROR("Skill: Attempt to delete self.")
return false;
}