diff options
author | Aaron Marks <nymacro@gmail.com> | 2005-11-14 08:50:25 +0000 |
---|---|---|
committer | Aaron Marks <nymacro@gmail.com> | 2005-11-14 08:50:25 +0000 |
commit | 9c4f838ef2e9b801a08c3550647aff4efcbb1ebd (patch) | |
tree | b8bc83cc47357173ef439f263b81b5c3775f3350 | |
parent | f14d517cd6bb949e935f5c5401dfdf81bbf7ab4f (diff) | |
download | manaserv-9c4f838ef2e9b801a08c3550647aff4efcbb1ebd.tar.gz manaserv-9c4f838ef2e9b801a08c3550647aff4efcbb1ebd.tar.bz2 manaserv-9c4f838ef2e9b801a08c3550647aff4efcbb1ebd.tar.xz manaserv-9c4f838ef2e9b801a08c3550647aff4efcbb1ebd.zip |
Added intial SWIG bindings.
-rw-r--r-- | configure.ac | 13 | ||||
-rw-r--r-- | src/Makefile.am | 6 | ||||
-rw-r--r-- | src/connectionhandler.h | 4 | ||||
-rw-r--r-- | src/main.cpp | 97 | ||||
-rw-r--r-- | src/messagehandler.cpp | 18 | ||||
-rw-r--r-- | src/messagehandler.h | 2 | ||||
-rw-r--r-- | src/netcomputer.h | 2 |
7 files changed, 79 insertions, 63 deletions
diff --git a/configure.ac b/configure.ac index 0a03bbf8..758e76ce 100644 --- a/configure.ac +++ b/configure.ac @@ -119,7 +119,18 @@ AC_ARG_WITH( ) if test "$with_scripting_engine" = "ruby"; then - AC_MSG_ERROR([sorry, $with_scripting_engine is not supported yet]) + # AC_MSG_ERROR([sorry, $with_scripting_engine is not supported yet]) + AC_CHECK_LIB([ruby], [ruby_init]) + AC_PATH_PROG(swig_path, swig, no) + if test "$swig_path" = "no"; then + AC_MSG_ERROR(Could not find swig in PATH) + fi + SWIG="$swig_path" + SWIGFLAGS="-c++ -ruby -minherit" + AC_SUBST(SWIG) + AC_SUBST(SWIGFLAGS) + CXXFLAGS="$CXXFLAGS -DSCRIPT_SUPPORT -DRUBY_SUPPORT -I/usr/lib/ruby/1.8/linux/" + LIBS="$LIBS -lruby" elif test "$with_scripting_engine" = "squirrel"; then AC_CHECK_LIB([squirrel], [sq_open]) diff --git a/src/Makefile.am b/src/Makefile.am index e7c893cb..2d9ef9be 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -90,6 +90,12 @@ tmwserv_SOURCES += script.h \ script-squirrel.cpp endif +if BUILD_RUBY +tmwserv_SOURCES += bindings_wrap.cpp +bindings_wrap.cpp: bindings.i + $(SWIG) $(SWIGFLAGS) -o bindings_wrap.cpp bindings.i +endif + tmwserv_CXXFLAGS = -Wall -fno-inline diff --git a/src/connectionhandler.h b/src/connectionhandler.h index 944b1c6a..943c2d12 100644 --- a/src/connectionhandler.h +++ b/src/connectionhandler.h @@ -83,7 +83,7 @@ class ConnectionHandler /** * Called when a computer reconnects to a network session. */ - void computerReconnected(NetComputer *computer); + //void computerReconnected(NetComputer *computer); /** * Called when a computer disconnects from a network session. @@ -96,7 +96,7 @@ class ConnectionHandler /** * Called when a computer sends a packet to the network session. */ - void receivePacket(NetComputer *computer, Packet *packet); + //void receivePacket(NetComputer *computer, Packet *packet); /** * Registers a message handler to handle a certain message type. diff --git a/src/main.cpp b/src/main.cpp index bb6a0e96..1909d057 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -49,20 +49,22 @@ // Scripting #ifdef SCRIPT_SUPPORT -#include "script.h" - -#define SCRIPT_SQUIRREL_SUPPORT - -#if define (SCRIPT_SQUIRREL_SUPPORT) -#include "script-squirrel.h" -#elif define (SCRIPT_RUBY_SUPPORT) -#include "script-ruby.h" -#elif define (SCRIPT_LUA_SUPPORT) -#include "script-lua.h" -#endif +extern "C" void Init_Tmw(); +#if defined (SQUIRREL_SUPPORT) std::string scriptLanguage = "squirrel"; +#elif defined (RUBY_SUPPORT) +#include <ruby.h> +int rubyStatus; +std::string scriptLanguage = "ruby"; +#elif defined (LUA_SUPPORT) +std::string scriptLanguage = "lua"; +#else +#error "Scripting enabled, but no language selected" +#endif +#else +std::string scriptLanugage = "none"; #endif // SCRIPT_SUPPORT #define LOG_FILE "tmwserv.log" @@ -82,6 +84,8 @@ AccountHandler *accountHandler = new AccountHandler(); /**< Account message hand ChatHandler *chatHandler = new ChatHandler(); /**< Communications (chat) messaqge handler */ GameHandler *gameHandler = new GameHandler(); /**< Core game message handler */ +ConnectionHandler connectionHandler; /**< Primary connection handler */ + /** * SDL timer callback, sends a <code>TMW_WORLD_TICK</code> event. */ @@ -129,12 +133,20 @@ void initialize() worldTimerID = SDL_AddTimer(100, worldTick, NULL); // initialize scripting subsystem. -#ifdef SCRIPT_SUPPORT - LOG_INFO("Script Language " << scriptLanguage) +#ifdef RUBY_SUPPORT + LOG_INFO("Script Language: " << scriptLanguage) - if (scriptLanguage == "squirrel") { - script = new ScriptSquirrel("main.nut"); - } + // initialize ruby + ruby_init(); + ruby_init_loadpath(); + ruby_script("tmw"); + + // initialize bindings + Init_Tmw(); + + // run test script + rb_load_file("scripts/init.rb"); + rubyStatus = ruby_exec(); #else LOG_WARN("No Scripting Language Support.") #endif @@ -181,9 +193,10 @@ void deinitialize() // Quit SDL_net SDLNet_Quit(); -#ifdef SCRIPT_SUPPORT - // Destroy scripting subsystem - delete script; +#ifdef RUBY_SUPPORT + // Finish up ruby + ruby_finalize(); + ruby_cleanup(rubyStatus); #endif // destroy message handlers @@ -204,11 +217,7 @@ int main(int argc, char *argv[]) #ifdef __USE_UNIX98 LOG_INFO("The Mana World Server v" << PACKAGE_VERSION) #endif - initialize(); - // Ready for server work... - std::auto_ptr<ConnectionHandler> - connectionHandler(new ConnectionHandler()); std::auto_ptr<NetSession> session(new NetSession()); // Note: This is just an idea, we could also pass the connection handler @@ -217,25 +226,27 @@ 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_CHAR_SELECT, accountHandler); - - connectionHandler->registerHandler(CMSG_SAY, chatHandler); - connectionHandler->registerHandler(CMSG_ANNOUNCE, chatHandler); - - connectionHandler->registerHandler(CMSG_PICKUP, gameHandler); - connectionHandler->registerHandler(CMSG_USE_OBJECT, gameHandler); - connectionHandler->registerHandler(CMSG_USE_ITEM, gameHandler); // NOTE: this is probably redundant (CMSG_USE_OBJECT) - connectionHandler->registerHandler(CMSG_TARGET, gameHandler); - connectionHandler->registerHandler(CMSG_WALK, gameHandler); - connectionHandler->registerHandler(CMSG_START_TRADE, gameHandler); - connectionHandler->registerHandler(CMSG_START_TALK, gameHandler); - connectionHandler->registerHandler(CMSG_REQ_TRADE, gameHandler); - connectionHandler->registerHandler(CMSG_EQUIP, gameHandler); - - session->startListen(connectionHandler.get(), SERVER_PORT); + 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); + + connectionHandler.registerHandler(CMSG_PICKUP, gameHandler); + connectionHandler.registerHandler(CMSG_USE_OBJECT, gameHandler); + connectionHandler.registerHandler(CMSG_USE_ITEM, gameHandler); // NOTE: this is probably redundant (CMSG_USE_OBJECT) + connectionHandler.registerHandler(CMSG_TARGET, gameHandler); + connectionHandler.registerHandler(CMSG_WALK, gameHandler); + connectionHandler.registerHandler(CMSG_START_TRADE, gameHandler); + connectionHandler.registerHandler(CMSG_START_TALK, gameHandler); + connectionHandler.registerHandler(CMSG_REQ_TRADE, gameHandler); + connectionHandler.registerHandler(CMSG_EQUIP, gameHandler); + + initialize(); + + session->startListen(&connectionHandler, SERVER_PORT); LOG_INFO("Listening on port " << SERVER_PORT << "...") using namespace tmwserv; @@ -267,7 +278,7 @@ int main(int argc, char *argv[]) // - Handle all messages that are in the message queue // - Update all active objects/beings - state.update(*connectionHandler.get()); + state.update(connectionHandler); } else if (event.type == SDL_QUIT) { running = false; diff --git a/src/messagehandler.cpp b/src/messagehandler.cpp index 0b496a7e..9ec14971 100644 --- a/src/messagehandler.cpp +++ b/src/messagehandler.cpp @@ -23,20 +23,8 @@ #include "messagehandler.h" #include "debug.h" +#include "utils/logger.h" -/* -void MessageHandler::receiveMessage(NetComputer &computer, MessageIn &message) -{ - int result = 0; - - // determine message type - switch(message.type) - { - case TYPE_LOGIN: - result = loginMessage(computer, message); - break; - } - - debugCatch(result); +void MessageHandler::receiveMessage(NetComputer &computer, MessageIn &message) { + LOG_WARN("MessageHandler class created without receiveMessage override") } -*/ diff --git a/src/messagehandler.h b/src/messagehandler.h index 1b7c4681..6949066f 100644 --- a/src/messagehandler.h +++ b/src/messagehandler.h @@ -46,7 +46,7 @@ class MessageHandler * to an ID this message handler registered to handle. */ virtual void - receiveMessage(NetComputer &computer, MessageIn &message) = 0; + receiveMessage(NetComputer &computer, MessageIn &message); //= 0; no pure virtual }; diff --git a/src/netcomputer.h b/src/netcomputer.h index c1a4bac5..766cf94a 100644 --- a/src/netcomputer.h +++ b/src/netcomputer.h @@ -56,7 +56,7 @@ class NetComputer /** * Returns <code>true</code> if this computer is disconnected. */ - bool isDisconnected(); + //bool isDisconnected(); /** * Disconnects the computer from the server. |