#553 Allow scripts + logs to be in custom paths, check for configs in /etc/eq2emu

Open
opened 5 months ago by Techwizz · 1 comments

Allowing scripts to be in a custom path would help with packaging for Linux distributions.

My proposal is to add something like this to LoginServer.ini (or another more appropriate ini by suggestion).

[WorldServer]
scriptpath=/var/lib/eq2emu/scripts
structpath=/var/lib/eq2emu/structs

NOTE: DEFAULT WOULD BE . FOR CURRENT DIRECTORY, TO NOT BREAK CURRENT INSTALLATIONS.

The worldserver/loginserver should also be able to find the configs in /etc/eq2emu/CONFIG.ini (but if there's a config in the current directory, use that instead).

This would also probably require being able to specify a custom log path, probably also in LoginServer.ini.

logpath=/var/log/eq2emu

Both logpath and script/structpath should definitely default to their current paths, ., but this would allow for package maintainers to package it appropriately for their distribution.

I plan on adding something like this in my fork and would like to see it upstreamed as well, along with getting feedback on approaching this issue. After this is added, I'll add a Debian packaging script and make a Debian repo to make it easy for people to maintain their own servers.

Allowing scripts to be in a custom path would help with packaging for Linux distributions. My proposal is to add something like this to LoginServer.ini (or another more appropriate ini by suggestion). ``` [WorldServer] scriptpath=/var/lib/eq2emu/scripts structpath=/var/lib/eq2emu/structs ``` NOTE: DEFAULT WOULD BE `.` FOR CURRENT DIRECTORY, TO NOT BREAK CURRENT INSTALLATIONS. The worldserver/loginserver should also be able to find the configs in `/etc/eq2emu/CONFIG.ini` (but if there's a config in the current directory, use that instead). This would also probably require being able to specify a custom log path, probably also in LoginServer.ini. ``` logpath=/var/log/eq2emu ``` Both logpath and script/structpath should definitely default to their current paths, `.`, but this would allow for package maintainers to package it appropriately for their distribution. I plan on adding something like this in my fork and would like to see it upstreamed as well, along with getting feedback on approaching this issue. After this is added, I'll add a Debian packaging script and make a Debian repo to make it easy for people to maintain their own servers.
Techwizz commented 5 months ago
Poster

Not a working patch, but this is essentially along the lines of what I'm thinking of for the log + data path.

diff --git a/EQ2/source/WorldServer/LuaInterface.cpp b/EQ2/source/WorldServer/LuaInterface.cpp
index c74167b93..047413d6c 100755
--- a/EQ2/source/WorldServer/LuaInterface.cpp
+++ b/EQ2/source/WorldServer/LuaInterface.cpp
@@ -23,6 +23,7 @@
 #include "SpellProcess.h"
 #include "../common/Log.h"
 #include "World.h"
+#include "net.h"
 
 #ifndef WIN32
     #include <stdio.h>
@@ -795,7 +796,8 @@ lua_State* LuaInterface::LoadLuaFile(const char* name) {
        return 0;
    lua_State* state = luaL_newstate();
    luaL_openlibs(state);
-   if(luaL_dofile(state, name) == 0){
+   const char*dataPath = net.GetDataPath();
+   if(luaL_dofile(state, dataPath + name) == 0){
        RegisterFunctions(state);
        return state;
    }
@@ -2702,4 +2704,4 @@ LUASpellWrapper::LUASpellWrapper() {
 
 bool LUASpellWrapper::IsSpell() {
    return true;
-}
\ No newline at end of file
+}
diff --git a/EQ2/source/WorldServer/net.cpp b/EQ2/source/WorldServer/net.cpp
index e04f1b782..0c0ce84df 100644
--- a/EQ2/source/WorldServer/net.cpp
+++ b/EQ2/source/WorldServer/net.cpp
@@ -210,8 +210,9 @@ int main(int argc, char** argv) {
    }
 
    LogWrite(WORLD__DEBUG, 1, "World", "-Loading structs...");
-   if(!configReader.LoadFile("CommonStructs.xml") || !configReader.LoadFile("WorldStructs.xml") || !configReader.LoadFile("SpawnStructs.xml") || !configReader.LoadFile("ItemStructs.xml")) {
-       LogWrite(INIT__ERROR, 0, "Init", "Loading structs failed. Make sure you have CommonStructs.xml, WorldStructs.xml, SpawnStructs.xml, and ItemStructs.xml in the working directory!");
+   const char* dataPath = net.GetDataPath();
+   if(!configReader.LoadFile(dataPath + "CommonStructs.xml") || !configReader.LoadFile(dataPath + "WorldStructs.xml") || !configReader.LoadFile(dataPath + "SpawnStructs.xml") || !configReader.LoadFile(dataPath + "ItemStructs.xml")) {
+       LogWrite(INIT__ERROR, 0, "Init", "Loading structs failed. Make sure you have CommonStructs.xml, WorldStructs.xml, SpawnStructs.xml, and ItemStructs.xml in your data directory!");
        return false;
    }
 
@@ -775,6 +776,12 @@ bool NetConnection::ReadLoginINI() {
                    DEFAULTSTATUS = atoi(buf);
                }
            }
+           if (!strcasecmp(type, "datapath")) {
+               char* DATAPATH = buf;
+           }
+           if (!strcasecmp(type, "logpath")) {
+               char* LOGPATH = buf;
+           }
        }
    }
    fclose (f);
diff --git a/EQ2/source/WorldServer/net.h b/EQ2/source/WorldServer/net.h
index 65540752c..a482e16c8 100644
--- a/EQ2/source/WorldServer/net.h
+++ b/EQ2/source/WorldServer/net.h
@@ -43,6 +43,8 @@ void UpdateWindowTitle(char* iNewTitle);
 
 #define PORT       9000
 #define LOGIN_PORT 9100
+#define DEFAULT_DPATH  "./"
+#define DEFAULT_LPATH  "logs"
 
 class NetConnection
 {
@@ -61,6 +63,8 @@ public:
        memset(internalworldaddress, 0, sizeof(internalworldaddress));
        worldport = PORT;
        DEFAULTSTATUS=0;
+       DATAPATH = DEFAULT_DPATH;
+       LOGPATH = DEFAULT_LPATH;
        LoginServerInfo = 0;//ReadLoginINI();
        UpdateStats = false;
    }
@@ -81,6 +85,8 @@ public:
    inline char* GetInternalWorldAddress()  { return internalworldaddress; }
    inline int16 GetWorldPort()             { return worldport; }
    inline int8 GetDefaultStatus()          { return DEFAULTSTATUS; }
+   inline char* GetDataPath()          { return DATAPATH; }
+   inline char* GetLogPath()           { return LOGPATH; }
    bool world_locked;
 private:
    int     listening_socket;
@@ -93,6 +99,8 @@ private:
    char    internalworldaddress[21];
    int16   worldport;
    int8    DEFAULTSTATUS;
+   char*   DATAPATH;
+   char*   LOGPATH;
 
 };
 
diff --git a/EQ2/source/common/Log.cpp b/EQ2/source/common/Log.cpp
index 0c59aa98b..ade0a856a 100644
--- a/EQ2/source/common/Log.cpp
+++ b/EQ2/source/common/Log.cpp
@@ -30,6 +30,7 @@
 #include "../WorldServer/World.h"
 #include "../WorldServer/client.h"
 #include "../WorldServer/zoneserver.h"
+#include "../WorldServer/net.h"
 
 extern ZoneList zone_list;
 
@@ -61,7 +62,7 @@ LogTypeStatus *log_type_info = real_log_type_info;
 #define LOG_CYCLE      100     //milliseconds between each batch of log writes
 #define LOGS_PER_CYCLE 50      //amount of logs to write per cycle
 
-#define LOG_DIR    "logs"
+#define LOG_DIR net.GetLogPath()
 
 #if defined LOGIN
 #define EXE_NAME   "login"
Not a working patch, but this is essentially along the lines of what I'm thinking of for the log + data path. ``` diff --git a/EQ2/source/WorldServer/LuaInterface.cpp b/EQ2/source/WorldServer/LuaInterface.cpp index c74167b93..047413d6c 100755 --- a/EQ2/source/WorldServer/LuaInterface.cpp +++ b/EQ2/source/WorldServer/LuaInterface.cpp @@ -23,6 +23,7 @@ #include "SpellProcess.h" #include "../common/Log.h" #include "World.h" +#include "net.h" #ifndef WIN32 #include <stdio.h> @@ -795,7 +796,8 @@ lua_State* LuaInterface::LoadLuaFile(const char* name) { return 0; lua_State* state = luaL_newstate(); luaL_openlibs(state); - if(luaL_dofile(state, name) == 0){ + const char*dataPath = net.GetDataPath(); + if(luaL_dofile(state, dataPath + name) == 0){ RegisterFunctions(state); return state; } @@ -2702,4 +2704,4 @@ LUASpellWrapper::LUASpellWrapper() { bool LUASpellWrapper::IsSpell() { return true; -} \ No newline at end of file +} diff --git a/EQ2/source/WorldServer/net.cpp b/EQ2/source/WorldServer/net.cpp index e04f1b782..0c0ce84df 100644 --- a/EQ2/source/WorldServer/net.cpp +++ b/EQ2/source/WorldServer/net.cpp @@ -210,8 +210,9 @@ int main(int argc, char** argv) { } LogWrite(WORLD__DEBUG, 1, "World", "-Loading structs..."); - if(!configReader.LoadFile("CommonStructs.xml") || !configReader.LoadFile("WorldStructs.xml") || !configReader.LoadFile("SpawnStructs.xml") || !configReader.LoadFile("ItemStructs.xml")) { - LogWrite(INIT__ERROR, 0, "Init", "Loading structs failed. Make sure you have CommonStructs.xml, WorldStructs.xml, SpawnStructs.xml, and ItemStructs.xml in the working directory!"); + const char* dataPath = net.GetDataPath(); + if(!configReader.LoadFile(dataPath + "CommonStructs.xml") || !configReader.LoadFile(dataPath + "WorldStructs.xml") || !configReader.LoadFile(dataPath + "SpawnStructs.xml") || !configReader.LoadFile(dataPath + "ItemStructs.xml")) { + LogWrite(INIT__ERROR, 0, "Init", "Loading structs failed. Make sure you have CommonStructs.xml, WorldStructs.xml, SpawnStructs.xml, and ItemStructs.xml in your data directory!"); return false; } @@ -775,6 +776,12 @@ bool NetConnection::ReadLoginINI() { DEFAULTSTATUS = atoi(buf); } } + if (!strcasecmp(type, "datapath")) { + char* DATAPATH = buf; + } + if (!strcasecmp(type, "logpath")) { + char* LOGPATH = buf; + } } } fclose (f); diff --git a/EQ2/source/WorldServer/net.h b/EQ2/source/WorldServer/net.h index 65540752c..a482e16c8 100644 --- a/EQ2/source/WorldServer/net.h +++ b/EQ2/source/WorldServer/net.h @@ -43,6 +43,8 @@ void UpdateWindowTitle(char* iNewTitle); #define PORT 9000 #define LOGIN_PORT 9100 +#define DEFAULT_DPATH "./" +#define DEFAULT_LPATH "logs" class NetConnection { @@ -61,6 +63,8 @@ public: memset(internalworldaddress, 0, sizeof(internalworldaddress)); worldport = PORT; DEFAULTSTATUS=0; + DATAPATH = DEFAULT_DPATH; + LOGPATH = DEFAULT_LPATH; LoginServerInfo = 0;//ReadLoginINI(); UpdateStats = false; } @@ -81,6 +85,8 @@ public: inline char* GetInternalWorldAddress() { return internalworldaddress; } inline int16 GetWorldPort() { return worldport; } inline int8 GetDefaultStatus() { return DEFAULTSTATUS; } + inline char* GetDataPath() { return DATAPATH; } + inline char* GetLogPath() { return LOGPATH; } bool world_locked; private: int listening_socket; @@ -93,6 +99,8 @@ private: char internalworldaddress[21]; int16 worldport; int8 DEFAULTSTATUS; + char* DATAPATH; + char* LOGPATH; }; diff --git a/EQ2/source/common/Log.cpp b/EQ2/source/common/Log.cpp index 0c59aa98b..ade0a856a 100644 --- a/EQ2/source/common/Log.cpp +++ b/EQ2/source/common/Log.cpp @@ -30,6 +30,7 @@ #include "../WorldServer/World.h" #include "../WorldServer/client.h" #include "../WorldServer/zoneserver.h" +#include "../WorldServer/net.h" extern ZoneList zone_list; @@ -61,7 +62,7 @@ LogTypeStatus *log_type_info = real_log_type_info; #define LOG_CYCLE 100 //milliseconds between each batch of log writes #define LOGS_PER_CYCLE 50 //amount of logs to write per cycle -#define LOG_DIR "logs" +#define LOG_DIR net.GetLogPath() #if defined LOGIN #define EXE_NAME "login" ```
Sign in to join this conversation.
Loading...
Cancel
Save
There is no content yet.