diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/chathandler.cpp | 10 | ||||
-rw-r--r-- | src/connectionhandler.cpp | 4 | ||||
-rw-r--r-- | src/defines.h | 5 | ||||
-rw-r--r-- | src/main.cpp | 43 |
4 files changed, 41 insertions, 21 deletions
diff --git a/src/chathandler.cpp b/src/chathandler.cpp index 73906275..3e5f6010 100644 --- a/src/chathandler.cpp +++ b/src/chathandler.cpp @@ -140,8 +140,7 @@ void ChatHandler::handleCommand(NetComputer &computer, std::string command) LOG_INFO("Chat: Recieved unhandled command: " << command, 2) MessageOut result; result.writeShort(SMSG_CHAT); - result.writeShort(0); // The Channel - result.writeString("SERVER: Unknown or unhandled command."); + result.writeByte(CHATCMD_UNHANDLED_COMMAND); computer.send(result.getPacket()); } @@ -150,8 +149,7 @@ void ChatHandler::warnPlayerAboutBadWords(NetComputer &computer) // We could later count if the player is really often unpolite. MessageOut result; result.writeShort(SMSG_CHAT); - result.writeShort(0); // The Channel - result.writeString("SERVER: Take care not to use bad words when you speak..."); + result.writeByte(CHAT_USING_BAD_WORDS); // The Channel computer.send(result.getPacket()); LOG_INFO(computer.getCharacter()->getName() << " says bad words.", 2) @@ -171,8 +169,8 @@ void ChatHandler::announce(NetComputer &computer, std::string text) } else { - result.writeShort(SMSG_SYSTEM); - result.writeString("Cannot make announcements. You have not enough rights."); + result.writeShort(SMSG_CHAT); + result.writeByte(CHATCMD_UNSUFFICIENT_RIGHTS); computer.send(result.getPacket()); LOG_INFO(computer.getCharacter()->getName() << " couldn't make an announcement due to insufficient rights.", 2) diff --git a/src/connectionhandler.cpp b/src/connectionhandler.cpp index b8172fe0..3009ae56 100644 --- a/src/connectionhandler.cpp +++ b/src/connectionhandler.cpp @@ -122,7 +122,7 @@ ConnectionHandler::startListen(ListenThreadData *ltd) perror("SDLNet_CheckSockets"); } else if (numready > 0) { - LOG_INFO(numready << " sockets with activity!", 0) + LOG_INFO(numready << " socket(s) with activity!", 0) // Check server socket if (SDLNet_SocketReady(ltd->socket)) { @@ -295,5 +295,3 @@ void ConnectionHandler::sendAround(tmwserv::BeingPtr beingPtr, MessageOut &msg) } } } - - diff --git a/src/defines.h b/src/defines.h index f1b27a27..8bc7218c 100644 --- a/src/defines.h +++ b/src/defines.h @@ -230,7 +230,10 @@ enum { enum { // CHAT_OK = 0, CHAT_NOLOGIN = 1, - CHAT_NO_CHARACTER_SELECTED + CHAT_NO_CHARACTER_SELECTED, + CHAT_USING_BAD_WORDS, + CHATCMD_UNHANDLED_COMMAND, + CHATCMD_UNSUFFICIENT_RIGHTS }; // Object type enumeration diff --git a/src/main.cpp b/src/main.cpp index d1e26e04..766ca33c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -68,11 +68,18 @@ std::string scriptLanguage = "lua"; std::string scriptLanugage = "none"; #endif // SCRIPT_SUPPORT +// Default options that automake should be able to override. +#ifndef LOG_FILE #define LOG_FILE "tmwserv.log" +#endif +#ifndef CONFIG_FILE +#define CONFIG_FILE "tmwserv.xml" +#endif +#ifndef DEFAULT_SERVER_PORT +#define DEFAULT_SERVER_PORT 9601 +#endif #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 */ @@ -187,15 +194,20 @@ void initialize() config.setValue("dbpass", ""); config.setValue("dbhost", ""); -#ifdef WIN32 - std::string configPath = "."; -#else +#ifdef __USE_UNIX98 std::string configPath = getenv("HOME"); + configPath += "/."; + configPath += CONFIG_FILE; + std::string logPath = getenv("HOME"); + logPath += "/."; + logPath += LOG_FILE; +#else + std::string configPath = CONFIG_FILE; + std::string logPath = LOG_FILE; #endif - configPath += "/.tmwserv.xml"; config.init(configPath); LOG_INFO("Using Config File: " << configPath, 0) - LOG_INFO("Using Log File: " << LOG_FILE, 0) + LOG_INFO("Using Log File: " << logPath, 0) // Initialize PhysicsFS PHYSFS_init(""); @@ -262,6 +274,7 @@ void parseOptions(int argc, char *argv[]) const struct option long_options[] = { { "help", no_argument, 0, 'h' }, { "verbosity", required_argument, 0, 'v' }, + { "port", required_argument, 0, 'p' }, 0 }; @@ -280,10 +293,18 @@ void parseOptions(int argc, char *argv[]) break; case 'v': // Set Verbosity to level - unsigned short verbosityLevel = atoi(optarg); + unsigned short verbosityLevel; + verbosityLevel = atoi(optarg); tmwserv::utils::Logger::instance().setVerbosity(verbosityLevel); LOG_INFO("Setting Log Verbosity Level to " << verbosityLevel, 0) break; + case 'p': + // Change the port to listen on. + unsigned short portToListenOn; + portToListenOn = atoi(optarg); + config.setValue("ListenOnPort", portToListenOn); + LOG_INFO("Setting Default Port to " << portToListenOn, 0) + break; } } } @@ -335,8 +356,8 @@ int main(int argc, char *argv[]) connectionHandler->registerHandler(CMSG_REQ_TRADE, gameHandler); connectionHandler->registerHandler(CMSG_EQUIP, gameHandler); - session->startListen(connectionHandler, SERVER_PORT); - LOG_INFO("Listening on port " << SERVER_PORT << "...", 0) + session->startListen(connectionHandler, int(config.getValue("ListenOnPort", DEFAULT_SERVER_PORT))); + LOG_INFO("Listening on port " << config.getValue("ListenOnPort", DEFAULT_SERVER_PORT) << "...", 0) using namespace tmwserv; @@ -380,7 +401,7 @@ int main(int argc, char *argv[]) } LOG_INFO("Received: Quit signal, closing down...", 0) - session->stopListen(SERVER_PORT); + session->stopListen(int(config.getValue("ListenOnPort", DEFAULT_SERVER_PORT))); deinitialize(); } |