diff options
Diffstat (limited to 'src/modules/my')
-rw-r--r-- | src/modules/my/Makefile.am | 20 | ||||
-rw-r--r-- | src/modules/my/idle.cpp | 133 | ||||
-rw-r--r-- | src/modules/my/idle.h | 84 | ||||
-rw-r--r-- | src/modules/my/idle_mac.cpp | 162 | ||||
-rw-r--r-- | src/modules/my/idle_x11.cpp | 113 | ||||
-rw-r--r-- | src/modules/my/libkvimy.cpp | 430 |
6 files changed, 942 insertions, 0 deletions
diff --git a/src/modules/my/Makefile.am b/src/modules/my/Makefile.am new file mode 100644 index 00000000..4c179e48 --- /dev/null +++ b/src/modules/my/Makefile.am @@ -0,0 +1,20 @@ +############################################################################### +# KVirc IRC client Makefile - 10.03.2000 Szymon Stefanek <[email protected]> +############################################################################### + +AM_CPPFLAGS = -I$(SS_TOPSRCDIR)/src/kvilib/include/ -I$(SS_TOPSRCDIR)/src/kvirc/include/ \ +$(SS_INCDIRS) $(SS_CPPFLAGS) -DGLOBAL_KVIRC_DIR=\"$(globalkvircdir)\" + +pluglib_LTLIBRARIES = libkvimy.la + +libkvimy_la_LDFLAGS = -module -avoid-version $(SS_LDFLAGS) $(SS_LIBDIRS) + +libkvimy_la_SOURCES = libkvimy.cpp idle_x11.cpp idle_mac.cpp idle.cpp +libkvimy_la_LIBADD = $(SS_LIBLINK) ../../kvilib/build/libkvilib.la + +noinst_HEADERS= idle.h + +%.moc: %.h + $(SS_QT_MOC) $< -o $@ + +idle.cpp: idle.moc diff --git a/src/modules/my/idle.cpp b/src/modules/my/idle.cpp new file mode 100644 index 00000000..56720c77 --- /dev/null +++ b/src/modules/my/idle.cpp @@ -0,0 +1,133 @@ +/* + * idle.cpp - detect desktop idle time + * Copyright (C) 2003 Justin Karneges + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include"idle.h" + +#include<qcursor.h> +#include<qdatetime.h> +#include<qtimer.h> + +static IdlePlatform *platform = 0; +static int platform_ref = 0; + + +Idle::Idle() +{ + d = new Private; + d->active = false; + d->idleTime = 0; + + // try to use platform idle + if(!platform) { + IdlePlatform *p = new IdlePlatform; + if(p->init()) + platform = p; + else + delete p; + } + if(platform) + ++platform_ref; + + connect(&d->checkTimer, SIGNAL(timeout()), SLOT(doCheck())); +} + +Idle::~Idle() +{ + if(platform) { + --platform_ref; + if(platform_ref == 0) { + delete platform; + platform = 0; + } + } + delete d; +} + +bool Idle::isActive() const +{ + return d->active; +} + +bool Idle::usingPlatform() const +{ + return (platform ? true: false); +} + +void Idle::start() +{ + d->startTime = QDateTime::currentDateTime(); + + if(!platform) { + // generic idle + d->lastMousePos = QCursor::pos(); + d->idleSince = QDateTime::currentDateTime(); + } + + // poll every second (use a lower value if you need more accuracy) + d->checkTimer.start(1000); +} + +void Idle::stop() +{ + d->checkTimer.stop(); +} + +int Idle::secondsIdle() +{ + int i; + if(platform) + i = platform->secondsIdle(); + else { + QPoint curMousePos = QCursor::pos(); + QDateTime curDateTime = QDateTime::currentDateTime(); + if(d->lastMousePos != curMousePos) { + d->lastMousePos = curMousePos; + d->idleSince = curDateTime; + } + i = d->idleSince.secsTo(curDateTime); + } + + // set 'beginIdle' to the beginning of the idle time (by backtracking 'i' seconds from now) + QDateTime beginIdle = QDateTime::currentDateTime().addSecs(-i); + + // set 't' to hold the number of seconds between 'beginIdle' and 'startTime' + int t = beginIdle.secsTo(d->startTime); + + // beginIdle later than (or equal to) startTime? + if(t <= 0) { + // scoot ourselves up to the new idle start + d->startTime = beginIdle; + } + // beginIdle earlier than startTime? + else if(t > 0) { + // do nothing + } + + // how long have we been idle? + int idleTime = d->startTime.secsTo(QDateTime::currentDateTime()); + return idleTime; +} + +void Idle::doCheck() +{ + secondsIdle(secondsIdle()); +} + +#include "idle.moc" diff --git a/src/modules/my/idle.h b/src/modules/my/idle.h new file mode 100644 index 00000000..647b2691 --- /dev/null +++ b/src/modules/my/idle.h @@ -0,0 +1,84 @@ +/* + * idle.h - detect desktop idle time + * Copyright (C) 2003 Justin Karneges + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifndef IDLE_H +#define IDLE_H + +#include "kvi_settings.h" +#include<qobject.h> +#include<qcursor.h> +#include<qdatetime.h> +#include<qtimer.h> + +class IdlePlatform; + +class Idle : public QObject +{ + Q_OBJECT +public: + Idle(); + ~Idle(); + + bool isActive() const; + bool usingPlatform() const; + void start(); + void stop(); + int secondsIdle(); + +signals: + void secondsIdle(int); + +private slots: + void doCheck(); + +private: + class Private; + Private *d; +}; + +class IdlePlatform +{ +public: + IdlePlatform(); + ~IdlePlatform(); + + bool init(); + int secondsIdle(); + +private: + class Private; + Private *d; +}; + +class Idle::Private +{ +public: + Private() {} + + QPoint lastMousePos; + QDateTime idleSince; + + bool active; + int idleTime; + QDateTime startTime; + QTimer checkTimer; +}; + +#endif diff --git a/src/modules/my/idle_mac.cpp b/src/modules/my/idle_mac.cpp new file mode 100644 index 00000000..92de564d --- /dev/null +++ b/src/modules/my/idle_mac.cpp @@ -0,0 +1,162 @@ +/* + * idle_mac.cpp - detect desktop idle time + * Copyright (C) 2003 Tarkvara Design Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifdef Q_OS_MACX + +#include"idle.h" +#include <Carbon/Carbon.h> + +// Why does Apple have to make this so complicated? +static OSStatus LoadFrameworkBundle(CFStringRef framework, CFBundleRef *bundlePtr) { + OSStatus err; + FSRef frameworksFolderRef; + CFURLRef baseURL; + CFURLRef bundleURL; + + if ( bundlePtr == nil ) return( -1 ); + + *bundlePtr = nil; + + baseURL = nil; + bundleURL = nil; + + err = FSFindFolder(kOnAppropriateDisk, kFrameworksFolderType, true, &frameworksFolderRef); + if (err == noErr) { + baseURL = CFURLCreateFromFSRef(kCFAllocatorSystemDefault, &frameworksFolderRef); + if (baseURL == nil) { + err = coreFoundationUnknownErr; + } + } + if (err == noErr) { + bundleURL = CFURLCreateCopyAppendingPathComponent(kCFAllocatorSystemDefault, baseURL, framework, false); + if (bundleURL == nil) { + err = coreFoundationUnknownErr; + } + } + if (err == noErr) { + *bundlePtr = CFBundleCreate(kCFAllocatorSystemDefault, bundleURL); + if (*bundlePtr == nil) { + err = coreFoundationUnknownErr; + } + } + if (err == noErr) { + if ( ! CFBundleLoadExecutable( *bundlePtr ) ) { + err = coreFoundationUnknownErr; + } + } + + // Clean up. + if (err != noErr && *bundlePtr != nil) { + CFRelease(*bundlePtr); + *bundlePtr = nil; + } + if (bundleURL != nil) { + CFRelease(bundleURL); + } + if (baseURL != nil) { + CFRelease(baseURL); + } + + return err; +} + + +class IdlePlatform::Private { +public: + EventLoopTimerRef mTimerRef; + int mSecondsIdle; + + Private() : mTimerRef(0), mSecondsIdle(0) {} + + static pascal void IdleTimerAction(EventLoopTimerRef, EventLoopIdleTimerMessage inState, void* inUserData); + +}; + + +pascal void IdlePlatform::Private::IdleTimerAction(EventLoopTimerRef, EventLoopIdleTimerMessage inState, void* inUserData) { + switch (inState) { + case kEventLoopIdleTimerStarted: + case kEventLoopIdleTimerStopped: + // Get invoked with this constant at the start of the idle period, + // or whenever user activity cancels the idle. + ((IdlePlatform::Private*)inUserData)->mSecondsIdle = 0; + break; + case kEventLoopIdleTimerIdling: + // Called every time the timer fires (i.e. every second). + ((IdlePlatform::Private*)inUserData)->mSecondsIdle++; + break; + } +} + + +IdlePlatform::IdlePlatform() { + d = new Private(); +} + +IdlePlatform::~IdlePlatform() { + RemoveEventLoopTimer(d->mTimerRef); + delete d; +} + + +// Typedef for the function we're getting back from CFBundleGetFunctionPointerForName. +typedef OSStatus (*InstallEventLoopIdleTimerPtr)(EventLoopRef inEventLoop, + EventTimerInterval inFireDelay, + EventTimerInterval inInterval, + EventLoopIdleTimerUPP inTimerProc, + void * inTimerData, + EventLoopTimerRef * outTimer); + + +bool IdlePlatform::init() { + // May already be init'ed. + if (d->mTimerRef) { + return true; + } + + // According to the docs, InstallEventLoopIdleTimer is new in 10.2. + // According to the headers, it has been around since 10.0. + // One of them is lying. We'll play it safe and weak-link the function. + + // Load the "Carbon.framework" bundle. + CFBundleRef carbonBundle; + if (LoadFrameworkBundle( CFSTR("Carbon.framework"), &carbonBundle ) != noErr) { + return false; + } + + // Load the Mach-O function pointers for the routine we will be using. + InstallEventLoopIdleTimerPtr myInstallEventLoopIdleTimer = (InstallEventLoopIdleTimerPtr)CFBundleGetFunctionPointerForName(carbonBundle, CFSTR("InstallEventLoopIdleTimer")); + if (myInstallEventLoopIdleTimer == 0) { + return false; + } + + EventLoopIdleTimerUPP timerUPP = NewEventLoopIdleTimerUPP(Private::IdleTimerAction); + if ((*myInstallEventLoopIdleTimer)(GetMainEventLoop(), kEventDurationSecond, kEventDurationSecond, timerUPP, 0, &d->mTimerRef)) { + return true; + } + + return false; +} + + +int IdlePlatform::secondsIdle() { + return d->mSecondsIdle; +} +#endif
\ No newline at end of file diff --git a/src/modules/my/idle_x11.cpp b/src/modules/my/idle_x11.cpp new file mode 100644 index 00000000..fa2f1f15 --- /dev/null +++ b/src/modules/my/idle_x11.cpp @@ -0,0 +1,113 @@ +/* + * idle_x11.cpp - detect desktop idle time + * Copyright (C) 2003 Justin Karneges + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ +#ifndef Q_OS_MACX +#ifndef COMPILE_ON_WINDOWS + +#include"idle.h" + +#ifndef COMPILE_XSS_SUPPORT + +IdlePlatform::IdlePlatform() {} +IdlePlatform::~IdlePlatform() {} +bool IdlePlatform::init() { return false; } +int IdlePlatform::secondsIdle() { return 0; } + +#else + +#include<qapplication.h> + +#include<X11/Xlib.h> +#include<X11/Xutil.h> +#include<X11/extensions/scrnsaver.h> + +#ifdef COMPILE_USE_QT4 + #include <qdesktopwidget.h> +#endif + +static XErrorHandler old_handler = 0; +extern "C" int xerrhandler(Display* dpy, XErrorEvent* err) +{ + if(err->error_code == BadDrawable) + return 0; + + return (*old_handler)(dpy, err); +} + +class IdlePlatform::Private +{ +public: + Private() {} + + XScreenSaverInfo *ss_info; +}; + +IdlePlatform::IdlePlatform() +{ + d = new Private; + d->ss_info = 0; +} + +IdlePlatform::~IdlePlatform() +{ + if(d->ss_info) + XFree(d->ss_info); + if(old_handler) { + XSetErrorHandler(old_handler); + old_handler = 0; + } + delete d; +} + +bool IdlePlatform::init() +{ + if(d->ss_info) + return true; + + old_handler = XSetErrorHandler(xerrhandler); + + int event_base, error_base; + if(XScreenSaverQueryExtension(QApplication::desktop()->screen()->x11Display(), &event_base, &error_base)) { + d->ss_info = XScreenSaverAllocInfo(); + return true; + } + return false; +} + +#ifdef COMPILE_USE_QT4 + #include <qx11info_x11.h> +#endif + +int IdlePlatform::secondsIdle() +{ + if(!d->ss_info) + return 0; +#ifdef COMPILE_USE_QT4 + if(!XScreenSaverQueryInfo(QApplication::desktop()->screen()->x11Display(), QX11Info::appRootWindow(), d->ss_info)) +#else + if(!XScreenSaverQueryInfo(QApplication::desktop()->screen()->x11Display(), qt_xrootwin(), d->ss_info)) +#endif + return 0; + return d->ss_info->idle / 1000; +} + +#endif + +#endif +#endif diff --git a/src/modules/my/libkvimy.cpp b/src/modules/my/libkvimy.cpp new file mode 100644 index 00000000..d98d44af --- /dev/null +++ b/src/modules/my/libkvimy.cpp @@ -0,0 +1,430 @@ +// +// File : libkvimy.cpp +// Creation date : Mon Jul 1 02:46:49 2002 GMT by Szymon Stefanek +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 2001 Szymon Stefanek (pragma at kvirc dot net) +// +// 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 opinion) 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. ,51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// + +#include "kvi_module.h" + +#include "kvi_console.h" + +#include "kvi_app.h" +#include "kvi_locale.h" +#include "kvi_ircconnection.h" +#include "kvi_ircconnectionuserinfo.h" +#include "kvi_ircconnectionserverinfo.h" +#include "kvi_ircserver.h" +#include "idle.h" +Idle* g_pIdle; +#ifdef COMPILE_NEW_KVS +#define GET_KVS_CONSOLE \ + kvs_uint_t uiWnd; \ + KviConsole *wnd =0; \ + KVSM_PARAMETERS_BEGIN(c) \ + KVSM_PARAMETER("context_id",KVS_PT_UINT,KVS_PF_OPTIONAL,uiWnd) \ + KVSM_PARAMETERS_END(c) \ + if(!c->parameterList()->count()) \ + { \ + if(c->window()->console()) wnd = c->window()->console(); \ + else c->warning(__tr2qs("This window has no associated irc context")); \ + } \ + else \ + { \ + wnd = g_pApp->findConsole(uiWnd); \ + if(!wnd)c->warning(__tr2qs("No such irc context (%d)"),uiWnd); \ + } +#endif +/* + @doc: my.nick + @type: + function + @title: + $my.nick + @short: + Returns the current nickname + @syntax: + <string> $my.nick([irc_context_id:uint]) + @description: + Returns the nickname of the current irc context.[br] + If the irc context is not connected then an empty string is returned.[br] + If <irc_context_id> is specified this function returns acts as it was called + in that irc_context.[br] + Note that this function is different from [fnc]$me[/fnc] that will work also in a DCC CHAT.[br] +*/ + + +static bool my_kvs_fnc_nick(KviKvsModuleFunctionCall * c) +{ + GET_KVS_CONSOLE + if(wnd) + { + if(wnd->connection()) + c->returnValue()->setString(wnd->connection()->userInfo()->nickName()); + } + return true; +} + +/* + @doc: my.startIdleTimer + @type: + command + @title: + my.startIdleTimer + @short: + Starts a global idle hook + @syntax: + my.startIdleTimer() + @description: + Starts a global idle hook. Allows to detect a global user idle time +*/ + +static bool my_kvs_cmd_startIdleTimer(KviKvsModuleCommandCall * c) +{ + if(!g_pIdle) + g_pIdle = new Idle(); + g_pIdle->start(); + return true; +} + +/* + @doc: my.stopIdleTimer + @type: + command + @title: + my.stopIdleTimer + @short: + Stops a global idle hook + @syntax: + my.stopIdleTimer() + @description: + Stops a global idle hook. Allows to detect a global user idle time +*/ + +static bool my_kvs_cmd_stopIdleTimer(KviKvsModuleCommandCall * c) +{ + if(!g_pIdle) return true; + g_pIdle->stop(); + //delete g_pIdle; + return true; +} + +/* + @doc: my.globalIdle + @type: + function + @title: + $my.globalIdle + @short: + Returns the current user global idle time + @syntax: + <int> $my.globalIdle() + @description: + Returns the current user global idle time +*/ + +static bool my_kvs_fnc_globalIdle(KviKvsModuleFunctionCall * c) +{ + if(g_pIdle) + { + c->returnValue()->setInteger(g_pIdle->secondsIdle()); + } else { + c->error(__tr2qs("Global idle timer must be started before using $my.globalIdle function")); + } + return true; +} + +/* + @doc: my.umode + @type: + function + @title: + $my.umode + @short: + Returns the current user mode flags + @syntax: + <string> $my.umode([irc_context_id:uint]) + @description: + Returns the user mode flags of the current irc context.[br] + If the irc context is not connected then an empty string is returned.[br] + If <irc_context_id> is specified this function returns acts as it was called + in that irc_context.[br] +*/ + +static bool my_kvs_fnc_umode(KviKvsModuleFunctionCall * c) +{ + GET_KVS_CONSOLE + if(wnd) + { + if(wnd->connection()) + c->returnValue()->setString(wnd->connection()->userInfo()->userMode()); + } + return true; +} + +/* + @doc: my.user + @type: + function + @title: + $my.user + @short: + Returns the current username + @syntax: + <string> $my.user([irc_context_id:uint]) + @description: + Returns the username of the current irc context.[br] + If the irc context is not connected then an empty string is returned.[br] + If <irc_context_id> is specified this function returns acts as it was called + in that irc_context.[br] +*/ + +static bool my_kvs_fnc_user(KviKvsModuleFunctionCall * c) +{ + GET_KVS_CONSOLE + if(wnd) + { + if(wnd->connection()) + c->returnValue()->setString(wnd->connection()->userInfo()->userName()); + } + return true; +} + +/* + @doc: my.host + @type: + function + @title: + $my.host + @short: + Returns the current hostname + @syntax: + <string> $my.host([irc_context_id:uint]) + @description: + Returns the hostname of the current irc context as known by the IRC server.[br] + If the irc context is not connected then an empty string is returned.[br] + If <irc_context_id> is specified this function returns acts as it was called + in that irc_context.[br] +*/ + + +static bool my_kvs_fnc_host(KviKvsModuleFunctionCall * c) +{ + GET_KVS_CONSOLE + if(wnd) + { + if(wnd->connection()) + c->returnValue()->setString(wnd->connection()->userInfo()->hostName()); + } + return true; +} + +/* + @doc: my.ip + @type: + function + @title: + $my.ip + @short: + Returns the current ip address + @syntax: + <string> $my.ip([irc_context_id:uint]) + @description: + Returns the ip address of the current irc context as known by the IRC server.[br] + The ip address is resolved as soon as the hostname is received from the server. + If the hostname is masked or there is an error in the DNS lookup then + you may get the real local host ip address as determined at connection startup.[br] + If the irc context is not connected then an empty string is returned.[br] + If <irc_context_id> is specified this function returns acts as it was called + in that irc_context.[br] +*/ + + +static bool my_kvs_fnc_ip(KviKvsModuleFunctionCall * c) +{ + GET_KVS_CONSOLE + if(wnd) + { + if(wnd->connection()) + c->returnValue()->setString(wnd->connection()->userInfo()->hostIp()); + } + return true; +} + +/* + @doc: my.serverIsIPV6 + @type: + function + @title: + $my.serverIsSSL + @short: + Returns 1 if the current server connection use IPV6. + @syntax: + <boolean> $my.serverIsIPV6([irc_context_id:uint]) + @description: + Returns 1 if the server connection use IPV6.[br] + If the irc context is not connected then an empty string is returned.[br] + If <irc_context_id> is specified this function returns acts as it was called + in that irc_context.[br] +*/ + +static bool my_kvs_fnc_serverIsIPV6(KviKvsModuleFunctionCall * c) +{ + + GET_KVS_CONSOLE + if(wnd) + { + if(wnd->connection()) + c->returnValue()->setBoolean(wnd->connection()->server()->isIpV6()); + } + return true; +} + + +/* + @doc: my.serverIsSSL + @type: + function + @title: + $my.serverIsSSL + @short: + Returns 1 if the current server connection use SSL. + @syntax: + <boolean> $my.serverIsSSL([irc_context_id:uint]) + @description: + Returns 1 if the server connection use SSL.[br] + If the irc context is not connected then an empty string is returned.[br] + If <irc_context_id> is specified this function returns acts as it was called + in that irc_context.[br] +*/ + +static bool my_kvs_fnc_serverIsSSL(KviKvsModuleFunctionCall * c) +{ + + GET_KVS_CONSOLE + if(wnd) + { + if(wnd->connection()) + c->returnValue()->setBoolean(wnd->connection()->socket()->usingSSL()); + } + return true; +} + +/* + @doc: my.server + @type: + function + @title: + $my.server + @short: + Returns the current server name + @syntax: + <string> $my.server([irc_context_id:uint]) + @description: + Returns the server name of the current irc context.[br] + If the irc context is not connected then an empty string is returned.[br] + If <irc_context_id> is specified this function returns acts as it was called + in that irc_context.[br] + Please note that this function returns the name of the server as reported + by the server itself. Some servers report a bogus value for this field. + You should take a look at $context.serverIpAddress or $context.serverHostName + if you want a value that can be used to really reconnect to this server. +*/ + +static bool my_kvs_fnc_server(KviKvsModuleFunctionCall * c) +{ + GET_KVS_CONSOLE + if(wnd) + { + if(wnd->connection()) + c->returnValue()->setString(wnd->connection()->serverInfo()->name()); + } + return true; +} + +/* + @doc: my.network + @type: + function + @title: + $my.network + @short: + Returns the current network name + @syntax: + <string> $my.network([irc_context_id:uint]) + @description: + Returns the network name of the current irc context.[br] + If the irc context is not connected then an empty string is returned.[br] + If <irc_context_id> is specified this function returns acts as it was called + in that irc_context.[br] +*/ + +static bool my_kvs_fnc_network(KviKvsModuleFunctionCall * c) +{ + GET_KVS_CONSOLE + if(wnd) + { + if(wnd->connection()) + c->returnValue()->setString(wnd->currentNetworkName().utf8().data()); + } + return true; +} + +static bool my_module_init(KviModule * m) +{ + g_pIdle = 0; + KVSM_REGISTER_FUNCTION(m,"nick",my_kvs_fnc_nick); + KVSM_REGISTER_FUNCTION(m,"user",my_kvs_fnc_user); + KVSM_REGISTER_FUNCTION(m,"host",my_kvs_fnc_host); + KVSM_REGISTER_FUNCTION(m,"ip",my_kvs_fnc_ip); + KVSM_REGISTER_FUNCTION(m,"server",my_kvs_fnc_server); + KVSM_REGISTER_FUNCTION(m,"network",my_kvs_fnc_network); + KVSM_REGISTER_FUNCTION(m,"umode",my_kvs_fnc_umode); + KVSM_REGISTER_FUNCTION(m,"serverIsSSL",my_kvs_fnc_serverIsSSL); + KVSM_REGISTER_FUNCTION(m,"serverIsIPV6",my_kvs_fnc_serverIsIPV6); + + KVSM_REGISTER_SIMPLE_COMMAND(m,"stopIdleTimer",my_kvs_cmd_stopIdleTimer); + KVSM_REGISTER_SIMPLE_COMMAND(m,"startIdleTimer",my_kvs_cmd_startIdleTimer); + return true; +} + +static bool my_module_cleanup(KviModule *m) +{ + if(g_pIdle) + delete g_pIdle; + g_pIdle = 0; + return true; +} + +static bool my_module_can_unload(KviModule *) +{ + return !g_pIdle; +} + +KVIRC_MODULE( + "My", // module name + "1.0.0", // module version + "Copyright (C) 2002 Szymon Stefanek (pragma at kvirc dot net)" \ + " (C) 2005 Tonino Imbesi (grifisx at barmes dot net)" \ + " (C) 2005 Alessandro Carbone (noldor at barmes dot net)", // author & (C) + "Scripting irc-context related functions", + my_module_init, + my_module_can_unload, + 0, + my_module_cleanup +) |