logo logo

 Back to main page

The NWNX Community Forum

 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Real World Time
Goto page Previous  1, 2, 3, 4, 5  Next
 
Post new topic   Reply to topic    nwnx.org Forum Index -> Database related
View previous topic :: View next topic  
Author Message
Gryphyn



Joined: 20 Jan 2005
Posts: 431

PostPosted: Tue Jul 03, 2007 2:27    Post subject: Reply with quote

Zunath wrote:
I've decided it would be better to go with MySQL instead of SQLite since it seems there's a lot more functionality with MySQL.

However, I'm not too sure how to set it up. I've downloaded the SQL server 5.0 and the GUI tools, but as far as actually getting it functional I'm at a loss. And the OBDC documentation didn't help much either. Sad

Thanks guys, can't wait to use real world time. Smile


MySQL & SQLServer are two different beasties.

MySQL plugin is ready (and available)

SQLServer plugin is not too far off. (Miss4 was lacking for attention for a while there) Adding Multiple Active Result Sets at the moment.

I'll have a look at making REALTIME available as a stand-alone plugin (Papillon - has the code, not the time) but it is destined to be merged into the "TIME" plugin.

Cheers
Gryphyn
Back to top
View user's profile Send private message
Zunath



Joined: 06 Jul 2006
Posts: 183

PostPosted: Tue Jul 03, 2007 2:36    Post subject: Reply with quote

Ah, so I got the wrong thing? I don't see a MySQL download though on the mysql.com website.

As of right now I have the following:

MySQL Server 5.0
MySQL Administrator
MySQL Migration Toolkit
MySQL Query Browser
MySQL System Tray Monitor

These are the wrong things then? Do you mind pointing me to a link to what I need? Much appreciated if you can. Smile

Thanks a ton for continuing to help.
Back to top
View user's profile Send private message
Gryphyn



Joined: 20 Jan 2005
Posts: 431

PostPosted: Tue Jul 03, 2007 4:22    Post subject: Reply with quote

Zunath wrote:
Ah, so I got the wrong thing? I don't see a MySQL download though on the mysql.com website.

As of right now I have the following:

MySQL Server 5.0
MySQL Administrator
MySQL Migration Toolkit
MySQL Query Browser
MySQL System Tray Monitor

These are the wrong things then? Do you mind pointing me to a link to what I need? Much appreciated if you can. Smile

Thanks a ton for continuing to help.


No, they are the right things for MySQL
-your post said that you had downloaded SQL server 5.0
<sorry, I work with SQLServer day to day, I wasn't sure if you meant "MySQL" or "SQLServer">

Cheers
Gryphyn
Back to top
View user's profile Send private message
Zunath



Joined: 06 Jul 2006
Posts: 183

PostPosted: Tue Jul 03, 2007 6:41    Post subject: Reply with quote

Ah, ok. Sorry about that.

I'm still not really sure how to set this database up for use though, and eventually get the real world time stuff working.

Do you think you could help me out with getting this to work? I've been using the SQLite database up till now.

Much appreciated for all the help you can give. Smile
Back to top
View user's profile Send private message
Gryphyn



Joined: 20 Jan 2005
Posts: 431

PostPosted: Tue Jul 03, 2007 9:43    Post subject: Reply with quote

Zunath wrote:
Ah, ok. Sorry about that.

I'm still not really sure how to set this database up for use though, and eventually get the real world time stuff working.

Do you think you could help me out with getting this to work? I've been using the SQLite database up till now.

Much appreciated for all the help you can give. Smile


My MySQL is too rusty...

A default install should get you half-way there.
-I'd suggest you use the 'small' configuration options-

The other half gets set-up when you load the Demo module.

Make sure you change your mysql & sqlite ini files to use the appropriate database.

Cheers
Gryphyn
Back to top
View user's profile Send private message
Gryphyn



Joined: 20 Jan 2005
Posts: 431

PostPosted: Thu Sep 20, 2007 0:24    Post subject: Realtime preview Reply with quote

Here's the code for xp_realtime.dll (using nwnx4 1.08 )

This will return the current system (server) time - or parts there of.
No more fetching it via the database.

Note: This code is intended to be included in the official xp_time plugin so it may become redundant in the near future - although I've been sitting on it for quite some time, waiting for that near future Embarassed

realtime.h
Code:

/***************************************************************************
    NWNX RealTime - RealTime functions plugin
    Copyright (C) 2007 Rob Lobbe (Gryphyn, private message at nwnx.org)

    This program 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
    (at your option) any later version.

    This program 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 this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 ***************************************************************************/

#pragma once

#define DLLEXPORT extern "C" __declspec(dllexport)

#include <windows.h>
#include "../plugin.h"
#include "../../misc/log.h"
#include "wx/datetime.h"

class RealTime : public Plugin
{
public:
   RealTime();
   ~RealTime();

   bool Init(TCHAR* nwnxhome); 

   //Active Functions
   int GetInt(char* sFunction, char* sParam1, int nParam2);
   char* GetString(char* sFunction, char* sParam1, int nParam2);

   //Ignored Functions
   void SetInt(char* sFunction, char* sParam1, int nParam2, int nValue) {};
   float GetFloat(char* sFunction, char* sParam1, int nParam2) { return 0.0; }
   void SetFloat(char* sFunction, char* sParam1, int nParam2, float fValue) {};
   void SetString(char* sFunction, char* sParam1, int nParam2, char* sValue) {};

   void GetFunctionClass(TCHAR* fClass);

private:
   wxLogNWNX* logger;
   wxDateTime LoadTime;

};


realtime.cpp
Code:

/***************************************************************************
    NWNX RealTime - RealTime functions plugin
    Copyright (C) 2007 Rob Lobbe (Gryphyn, private message at nwnx.org)

    This program 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
    (at your option) any later version.

    This program 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 this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 ***************************************************************************/

#include "RealTime.h"

/***************************************************************************
    NWNX and DLL specific functions
***************************************************************************/

RealTime* plugin;

DLLEXPORT Plugin* GetPluginPointerV2()
{
   return plugin;
}

BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
   if (ul_reason_for_call == DLL_PROCESS_ATTACH)
   {
      plugin = new RealTime();

      TCHAR szPath[MAX_PATH];
      GetModuleFileName(hModule, szPath, MAX_PATH);
      plugin->SetPluginFullPath(szPath);
   }
   else if (ul_reason_for_call == DLL_PROCESS_DETACH)
   {
      delete plugin;
   }
    return true;
}

/***************************************************************************
    Implementation of RealTime Plugin
***************************************************************************/

RealTime::RealTime()
{
   header = _T(
      "NWNX RealTime Plugin V.106.108.1.1\n" \
      "(c) 2007 by Rob Lobbe (Gryphyn)\n" \
      "visit us at http://www.nwnx.org\n");

   description = _T(
      "This plugin provides basic RealTime functionality");

   subClass = _T("RealTime");
   version = _T("106.108.1.1");

}

RealTime::~RealTime()
{
   wxLogMessage(wxT("* Plugin unloaded."));
}

bool RealTime::Init(TCHAR* nwnxhome)
{
   assert(GetPluginFileName());

   /* Log file */
   wxString logfile(nwnxhome);
   logfile.append(wxT("\\"));
   logfile.append(GetPluginFileName());
   logfile.append(wxT(".txt"));
   logger = new wxLogNWNX(logfile, wxString(header.c_str()));

   wxLogMessage(wxT("* Plugin initialized."));

   LoadTime = wxDateTime::Now();
   wxLogMessage(wxT("* Uptime Base: %s"), LoadTime.Format());

   return true;
}

void RealTime::GetFunctionClass(TCHAR* fClass)
{
   _tcsncpy_s(fClass, 128, wxT("RLTM"), 4);
}

char* RealTime::GetString(char* sFunction, char* sParam1, int nParam2)
{
   wxLogTrace(TRACE_VERBOSE, wxT("* Plugin GetString(%s, %s, %d)"), sFunction, sParam1, nParam2);

#ifdef UNICODE
   wxString wxRequest(sFunction, wxConvUTF8);
   wxString function(sFunction, wxConvUTF8);
#else
   wxString wxRequest(sFunction);
   wxString function(sFunction);
#endif

   if (function == wxT(""))
   {
      wxLogMessage(wxT("* Function not specified."));
      return NULL;
   }

   if      (function == wxT("DATE"))   sprintf_s(returnBuffer, MAX_BUFFER, "%s", wxDateTime::Now().FormatISODate());
   else if (function == wxT("TIME"))     sprintf_s(returnBuffer, MAX_BUFFER, "%s", wxDateTime::Now().FormatISOTime());
   else if (function == wxT("UPTIME")) sprintf_s(returnBuffer, MAX_BUFFER, "%s", wxDateTime::Now().Subtract(LoadTime).Format());
   else
   {
      // Process generic functions
      wxString query = ProcessQueryFunction(function.c_str());
      if (query != wxT("")) sprintf_s(returnBuffer, MAX_BUFFER, "%s", query);
      else
      {
         wxLogMessage(wxT("* Unknown function '%s' called."), function);
         return NULL;
      }
   }

   return returnBuffer;
}

int RealTime::GetInt(char* sFunction, char* sParam1, int nParam2)
{
   wxLogTrace(TRACE_VERBOSE, wxT("* Plugin GetInt(%s, %s, %d)"), sFunction, sParam1, nParam2);

#ifdef UNICODE
   wxString wxRequest(sFunction, wxConvUTF8);
   wxString function(sFunction, wxConvUTF8);
#else
   wxString wxRequest(sFunction);
   wxString function(sFunction);
#endif

   if (function == wxT(""))
   {
      wxLogMessage(wxT("* Function not specified."));
      return 0;
   }

   if      (function == wxT("YEAR"))        return wxDateTime::Now().GetYear();
   else if (function == wxT("YR"))          return wxDateTime::Now().GetYear();
   else if (function == wxT("MONTH"))       return wxDateTime::Now().GetMonth();
   else if (function == wxT("MON"))         return wxDateTime::Now().GetMonth();
   else if (function == wxT("DAY"))         return wxDateTime::Now().GetDay();
   else if (function == wxT("HOUR"))        return wxDateTime::Now().GetHour();
   else if (function == wxT("HR"))          return wxDateTime::Now().GetHour();
   else if (function == wxT("MINUTE"))      return wxDateTime::Now().GetMinute();
   else if (function == wxT("MIN"))         return wxDateTime::Now().GetMinute();
   else if (function == wxT("MILLI"))       return wxDateTime::Now().GetMillisecond();
   else if (function == wxT("MILLISECOND")) return wxDateTime::Now().GetMillisecond();
   else if (function == wxT("UPDAYS"))      return wxDateTime::Now().Subtract(LoadTime).GetDays();
   else if (function == wxT("UPHOURS"))     return wxDateTime::Now().Subtract(LoadTime).GetHours();
   else if (function == wxT("UPMINUTES"))   return wxDateTime::Now().Subtract(LoadTime).GetMinutes();
   else wxLogMessage(wxT("* Unknown function '%s' called"));
   return 0;
}
Back to top
View user's profile Send private message
b1o



Joined: 03 Apr 2007
Posts: 16

PostPosted: Thu Oct 25, 2007 19:07    Post subject: Reply with quote

What kind of program do i need to compile those? Microsoft visual studio 2003?
Back to top
View user's profile Send private message
Gryphyn



Joined: 20 Jan 2005
Posts: 431

PostPosted: Fri Oct 26, 2007 0:13    Post subject: Reply with quote

b1o wrote:
What kind of program do i need to compile those? Microsoft visual studio 2003?

Just the standard development environment for any plugin. (Doco here)
VC++ Express, which is free or any of the VS suite of products.

It is intended that this become part of the official 'Time' plugin, (but it's taking a while)

Cheers
Gryphyn
Back to top
View user's profile Send private message
Disco



Joined: 06 Dec 2006
Posts: 152

PostPosted: Tue Oct 30, 2007 11:45    Post subject: Reply with quote

Could someone make this kind of plugin for NWNX2 as well?

I tried to make a plugin myself, but C# or C++ (I forgot what it was) is not my forte.

I guess something that can interface with a set of NWN functions like this would be very handy for a lot of people:

//get unix timestamp
Timer_UnixTime();

//get runtime of the module in seconds since reset
Timer_RunTime();

//get MYSQL type of timestamp: YYYY-MM-DD HH:MM:SS
Timer_Timestamp();

//gets relevant bit of a timestamp (optional)
Timer_Year();
Timer_Month();
Timer_Day();
Timer_Hour();
Timer_Minute();
Timer_Second();


Actually, Timer_RunTime(); would make me ecstatic all by itself.

If you can make this a very fast plugin you can eliminate a lot of blocking delays on triggers and PLCs.

The unix stamp would be very handy for things like banning somebody from a city for two RL days, or events that you want to do once a week.
Back to top
View user's profile Send private message
Gryphyn



Joined: 20 Jan 2005
Posts: 431

PostPosted: Tue Oct 30, 2007 23:01    Post subject: Reply with quote

Disco wrote:
Could someone make this kind of plugin for NWNX2 as well?

I tried to make a plugin myself, but C# or C++ (I forgot what it was) is not my forte.

I guess something that can interface with a set of NWN functions like this would be very handy for a lot of people:

//get unix timestamp
Timer_UnixTime();

//get runtime of the module in seconds since reset
Timer_RunTime();

//get MYSQL type of timestamp: YYYY-MM-DD HH:MM:SS
Timer_Timestamp();

//gets relevant bit of a timestamp (optional)
Timer_Year();
Timer_Month();
Timer_Day();
Timer_Hour();
Timer_Minute();
Timer_Second();


Actually, Timer_RunTime(); would make me ecstatic all by itself.

If you can make this a very fast plugin you can eliminate a lot of blocking delays on triggers and PLCs.

The unix stamp would be very handy for things like banning somebody from a city for two RL days, or events that you want to do once a week.


This is what you get already, for the most part.

1. For NWNX2 - take the int result and convert it to a string.
2. UnixTime? - see DATE + TIME (could be combined)
3. RunTime - see UPMINUTES (simple to add an extra function for UPSECONDS - why?)
4. Timestamp - see DATE + TIME
5. Year/Month/Day etc already covered.

6. Date Maths - excluded, this was simply to get at the system clock, without having to go via an expensive database call. Not doing any more than exposing a few of the wxDateTime class methods.

Cheers
Gryphyn
Back to top
View user's profile Send private message
Disco



Joined: 06 Dec 2006
Posts: 152

PostPosted: Wed Oct 31, 2007 13:00    Post subject: Reply with quote

I am afraid I am a genuine noob when it comes to C++/C#/whateverthatlanguageis, and the last time I tried to compile something I stared at the error messages I got for a few minutes and uninstalled the compiler.

So... my next question is: how do I get that code into a plugin, and how do I get the dates into NWNscript?
Back to top
View user's profile Send private message
Gryphyn



Joined: 20 Jan 2005
Posts: 431

PostPosted: Wed Oct 31, 2007 23:37    Post subject: Reply with quote

I've got to do some retro work for a TheFold (NWN1).
I should be able to get something before Christmas.
I'll even try for this weekend...

Cheers
Gryphyn
Back to top
View user's profile Send private message
Disco



Joined: 06 Dec 2006
Posts: 152

PostPosted: Thu Nov 01, 2007 13:42    Post subject: Reply with quote

Whooties! Thanks, man!
Back to top
View user's profile Send private message
Gryphyn



Joined: 20 Jan 2005
Posts: 431

PostPosted: Mon Nov 05, 2007 0:41    Post subject: Reply with quote

Not his weekend...
in the middle of rebuilding my PC.
Just when you want it it all goes south Crying or Very sad

a couple of non-work days before Christmas...

Cheers
Gryphyn
Back to top
View user's profile Send private message
Disco



Joined: 06 Dec 2006
Posts: 152

PostPosted: Mon Nov 05, 2007 11:39    Post subject: Reply with quote

I appreciate the fact that you want to look into it. Good luck with the PC.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    nwnx.org Forum Index -> Database related All times are GMT + 2 Hours
Goto page Previous  1, 2, 3, 4, 5  Next
Page 2 of 5

 
Jump to:  
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