View previous topic :: View next topic |
Author |
Message |
Lokey
Joined: 02 Jan 2005 Posts: 158
|
Posted: Tue Jan 25, 2005 11:47 Post subject: Function idea: Shutdown server |
|
|
Would it be possible to write a function that will shutdown the server from within NWNx?
Thinking it would be preferable to do server resets from within NWN: servers been up for 12 hours, shutdown and restart the server for example (especially with the time module so we don't have to depend on the wonky game clock for tracking time or pulling the current time from MySQL or something). Currently we're using a process kill called by task scheduler to shut down the server _________________ Neversummer PW NWNx powered mayhem |
|
Back to top |
|
|
Papillon x-man
Joined: 28 Dec 2004 Posts: 1060 Location: Germany
|
Posted: Tue Jan 25, 2005 13:34 Post subject: |
|
|
I can think of three ways to do this:
1) Write a plugin that makes the server crash, e.g. by accessing a null pointer (ugly, but very easy)
2) Find and call the shutdown function in the server (clean, possibly takes some time)
3) Write a plugin that sends a signal to server (Linux) or one that uses MFC classes to programatically press the shut down button on the GUI (Windows) (somewhat clean, might take some time) _________________ Papillon |
|
Back to top |
|
|
isilweo
Joined: 29 Dec 2004 Posts: 22 Location: poland
|
Posted: Tue Jan 25, 2005 14:04 Post subject: |
|
|
what about simple WM_DESTROY? :) |
|
Back to top |
|
|
redils
Joined: 13 Jan 2005 Posts: 27
|
Posted: Tue Jan 25, 2005 14:41 Post subject: |
|
|
I use postgresql under Linux. The main advantage of that RDBMS is that it allows me to write C functions. So, to reboot my server, I wrote a C function that calls an external executable. This exe. reboots the server cleanly and properly. So, when I need to reboot from my module, I just have to call "SELECT reboot()" and my server reboots. |
|
Back to top |
|
|
JeroenB
Joined: 31 Dec 2004 Posts: 228 Location: Netherlands
|
Posted: Tue Jan 25, 2005 16:35 Post subject: |
|
|
Yes, I would assume that sending a WM_CLOSE to the application would do the job. All you have to do is find the server window and send that message to it.
Only point you should mind is that when there are still players online that it will come up with a message box. You can also close that box the same way. |
|
Back to top |
|
|
Blacksting
Joined: 03 Jan 2005 Posts: 107
|
Posted: Tue Jan 25, 2005 20:22 Post subject: |
|
|
I put in my vote for clean. If it's clean characters should be saved. |
|
Back to top |
|
|
dguntner
Joined: 31 Dec 2004 Posts: 116
|
Posted: Tue Jan 25, 2005 20:59 Post subject: |
|
|
Any reason you can't just use the reload module function?
--Dave |
|
Back to top |
|
|
Asmodae
Joined: 07 Jan 2005 Posts: 55
|
Posted: Tue Jan 25, 2005 21:47 Post subject: |
|
|
Reload module does not clear the memory being used by the server, whether due to bad scripting, NWN memory leaks, etc. The only way to really reset the memory in use is to completely shutdown and restart NWServer.
I'm strongly in favor of this function. I started out using NWN-FF, basically because I didn't know any better, and it does have a shutdown function that you can call from script "NWNX!DMREBOOT", which is very handy. That's one of the things right now holding me back (albeit a weak reason) from going over to NWNX2, that and rewriting a few functions. Once the object storage is stablized, and this is in, I'm converting you betcha.
I've said it before and I'll say it again, you guys are amazing, thanks for providing such a wonderfull tool to the NWN community. _________________ Nepenthe - An NWN2 Persistant World, coming to a planet near you. http://www.nepentheonline.com |
|
Back to top |
|
|
Papillon x-man
Joined: 28 Dec 2004 Posts: 1060 Location: Germany
|
Posted: Tue Jan 25, 2005 22:26 Post subject: |
|
|
Well, if ff-nwn has the function, grab the source, copy it into a plugin and you are set, no ? _________________ Papillon |
|
Back to top |
|
|
DarkstarsDad
Joined: 17 Jan 2005 Posts: 59 Location: Overland Park, Kansas USA
|
Posted: Tue Jan 25, 2005 22:34 Post subject: should be. |
|
|
It should be that easy as his is based on all your source code anyway |
|
Back to top |
|
|
Asmodae
Joined: 07 Jan 2005 Posts: 55
|
Posted: Wed Jan 26, 2005 5:45 Post subject: |
|
|
I know my way around C, C++ pretty well and I've even had a class in assembly language, but I have no clue how to compile or use .dll files.
I'll have to give it a shot, if anyone can point me at a reference for it I'd be gratefull.
(edit) - a quick bit of research shows this should not be too tough, any thing I need to know about NWNX in particular for this to work?
(edit) - And does this mean the same could be done for all the wierd custom functions that are in it, essentially to make a compatability plug in? (that would save me, and I believe a few others a lot of work) _________________ Nepenthe - An NWN2 Persistant World, coming to a planet near you. http://www.nepentheonline.com |
|
Back to top |
|
|
Papillon x-man
Joined: 28 Dec 2004 Posts: 1060 Location: Germany
|
Posted: Wed Jan 26, 2005 9:11 Post subject: |
|
|
I wanted to do this for some time, so here it is: The NWNX plugin cookbook.
So you want to be a NWNX programmer ?
==============================
This post will eventually turn into a HOWTO posted on the website. We will create a new NWNX plugin called "Demoplugin" with these simple steps. It does nothing useful, but is fully standard compliant and can be called from NWScript like any other plugin. You can also download the even more stripped down source code to Demoplugin below (see next post). These instructions are useful if you want to take an existing plugin and create your own version of it.
1) You can use any Visual Studio Environment, I use VS6, while Jeroen uses VS2003. The instructions below pertain to VS6.
2) Take a simple plugin, like the time plugin, and copy it to a new directory inside the nwnx2 source tree.
3) Remove the Release and Debug directories, if they exist.
4) Rename all files accordingly, e.g. NWNXTime.cpp to NWNXDemoplugin.cpp
5) Edit your project.dsp file: Replace all occurences of "time" with "demoplugin". Replace all occurences of "TIME_EXPORTS" with "DEMOPLUGIN_EXPORTS"
6) Open demoplugin.h and replace TIME* with DEMOPLUGIN*
Code: |
#ifdef DEMOPLUGIN_EXPORTS
#define DEMOPLUGIN_API extern "C" __declspec(dllexport)
#else
#define DEMOPLUGIN_API extern "C" __declspec(dllimport)
#endif
DEMOPLUGIN_API CNWNXBase* GetClassObject();
|
7) Open demoplugin.cpp and replace TIME* with DEMOPLUGIN* again
Code: |
#include "stdafx.h"
#include "nwnxdemoplugin.h"
#include "demoplugin.h"
CNWNXDemoplugin Demoplugin;
DEMOPLUGIN_API CNWNXBase* GetClassObject()
{
return &Demoplugin;
}
BOOL APIENTRY DllMain (HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
return TRUE;
}
|
8) Do the same with NWNXDemoplugin.h and remove the unecessary stuff.
Code: |
#if !defined(DEMOPLUGIN_H_)
#define DEMOPLUGIN_H_
#include "..\NWNXDLL\NWNXBase.h"
class CNWNXDemoplugin : public CNWNXBase
{
public:
CNWNXDemoplugin();
virtual ~CNWNXDemoplugin();
char* OnRequest(char *gameObject, char* Request, char* Parameters);
BOOL OnCreate(const char* LogDir);
BOOL OnRelease();
void WriteLogHeader();
};
#endif
|
9) Do the same with NWNXDemoplugin.cpp and remove the unecessary stuff.
Code: |
#include "stdafx.h"
#include "NWNXDemoplugin.h"
CNWNXDemoplugin::CNWNXDemoplugin()
{
}
CNWNXDemoplugin::~CNWNXDemoplugin()
{
OnRelease();
}
char* CNWNXDemoplugin::OnRequest(char *gameObject, char* Request, char* Parameters)
{
if (Request)
Log("* Got request: %s.\n", Request);
if (Parameters)
Log("* Got parameters: %s.\n", Parameters);
return NULL;
}
BOOL CNWNXDemoplugin::OnCreate(const char* LogDir)
{
// call the base class function
char log[MAX_PATH];
sprintf (log, "%s\\nwnx_demoplugin.txt", LogDir);
if (!CNWNXBase::OnCreate(log))
return false;
WriteLogHeader();
return true;
}
BOOL CNWNXDemoplugin::OnRelease()
{
Log("o Shutting down\n");
// call base class function
return CNWNXBase::OnRelease();
}
void CNWNXDemoplugin::WriteLogHeader()
{
fprintf(m_fFile, "NWNX Demo plugin V.1.0.\n");
fprintf(m_fFile, "(c) 2005 by Ingmar Stieger (Papillon)\n");
fprintf(m_fFile, "visit us at http://www.nwnx.org\n\n");
}
|
10) Open the project in Visual Studio an compile it. You should get a DLL in the Debug or Release directory.
11) Copy the plugin to your NWN directory and start the server. You should see a log file (nwnx_demoplugin.txt) in your log directory. _________________ Papillon |
|
Back to top |
|
|
Papillon x-man
Joined: 28 Dec 2004 Posts: 1060 Location: Germany
|
Posted: Wed Jan 26, 2005 9:24 Post subject: |
|
|
The ultimately stripped down Demoplugin
=============================
While writing the short tutorial above, I created the Demoplugin source code. It is the smallest possible NWNX plugin, with a considerably simplified structure. Use this as a base for starting new plugins: Simply code the desired functionality in the function CNWNXDemoplugin::OnRequest !
Download the Demoplugin source code. _________________ Papillon |
|
Back to top |
|
|
Asmodae
Joined: 07 Jan 2005 Posts: 55
|
Posted: Wed Jan 26, 2005 10:08 Post subject: |
|
|
Papillon wrote: |
char* CNWNXDemoplugin::OnRequest(char *gameObject, char* Request, char* Parameters)
{
if (Request)
Log("* Got request: %s.\n", Request);
if (Parameters)
Log("* Got parameters: %s.\n", Parameters);
return NULL;
}
|
I'm guessing "Request" will contain the "NWNX!MY_COMMAND_HERE" string (or is it just "MY_COMMAND_HERE"), and then the variable's contents will be in "Parameters". If that's the case, what is in gameObject, and is there anything usefull we can do with that? These questions are probably easily answered by looking at working code... so that's my next step.
I'm getting really excited, with this and a bit of C++ knowledge there's so much you can do with NWN...
I just hope by the time NWN2 comes out you still have the motivation to port NWNX over, and the NWN2 team doesn't obfuscate the necessary functions. _________________ Nepenthe - An NWN2 Persistant World, coming to a planet near you. http://www.nepentheonline.com |
|
Back to top |
|
|
Themicles
Joined: 23 Jan 2005 Posts: 30 Location: Wolverine Lake, MI
|
Posted: Thu Jan 27, 2005 14:48 Post subject: |
|
|
Teach me to read the forums first. LOL
Missed this and posted similar.
Here's what I had to say.
Quote: | Any chance we could either get NWNX2 functionality, or a module written for, automatic server restarts at a specified time every day?
Some of the bigger modules can get really bogged down if they last a full 24 hours. Personally, it can take a week before my server gets bogged down, but would be nice to have a regular reset to plan around. Could allow for more regular server maintenance. Could allow for easier updates from developers who can upload a module, but don't have access to the desktop to restart the server. EDIT: Of course, would need to send warning messages on the server message channel to give players a chance to stop what they're doing and log off.
*shrugs* Not really sure how useful everyone would find it. Just came to mind when I noticed the MMO I recently started playing was down. And remembered that all the MMOs I've played have had daily restarts for maintenance reasons.
-Themicles |
_________________ World Leader of Tairis'nądur http://www.tairisnadur.com
Member World of CoPaP http://www.copap.org |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|