/* 
************************************************** ************************* 
************************************************** *************** 
** Global Noticer **
** Written by: NeTDeLiSi ** 
** - **
**  ** 
** ** 
************************************************** **************** 
************************************************** *************************
*/


#include "config.h"
#include "struct.h"
#include "common.h"
#include "sys.h"
#include "numeric.h"
#include "msg.h"
#include "channel.h"
#include <time.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef _WIN32
#include <io.h>
#endif
#include <fcntl.h>
#include "h.h"
#include "proto.h"
#ifdef STRIPBADWORDS
#include "badwords.h"
#endif
#ifdef _WIN32
#include "version.h"
#endif

// Configuration
#define MSG_GLOBAL "GLOBAL"
#define TOK_GLOBAL "zt"
#define DESCRIPTION "Sunucu.com System secure bots team"
#define SENDER "Sunucu.Com"
#define STYPE "PRIVMSG" /* NOTICE OR PRIVMSG */
// End of configuration

DLLFUNC int m_global(aClient *cptr, aClient *sptr, int parc, char *parv[]);
void do_global(aClient *, aClient *, char *);

ModuleHeader MOD_HEADER(global)
= {
"Global Noticer",
"v1.0 by ADS",
DESCRIPTION,
"3.2-b8-1",
NULL 
};

DLLFUNC int MOD_INIT(m_global)(ModuleInfo *modinfo)
{
add_Command(MSG_GLOBAL, TOK_GLOBAL, m_global, 1);
MARK_AS_OFFICIAL_MODULE(modinfo);
return MOD_SUCCESS;
}

DLLFUNC int MOD_LOAD(m_global)(int module_load)
{
return MOD_SUCCESS;
}

DLLFUNC int MOD_UNLOAD(m_global)(int module_unload)
{
if (del_Command(MSG_GLOBAL, TOK_GLOBAL, m_global) < 0)
{
sendto_realops("Failed to delete commands when unloading %s",
MOD_HEADER(m_global).name);
}
return MOD_SUCCESS;
}

void do_global(aClient *sptr, aClient *cptr, char *gmessage) {
aClient *acptr;

for (acptr = client; acptr; acptr = acptr->next)
{
if (IsRegistered(acptr) && !IsULine(acptr)) {
sendto_one(acptr, ":%s!GNoticer@%s %s %s :%s", SENDER, me.name, STYPE, acptr->name, gmessage);
}
}
}

DLLFUNC int m_global(aClient *cptr, aClient *sptr, int parc, char *parv[]) {
aClient acptr;
char *gmessage; 

if (!IsOper(sptr)) {
sendto_one(sptr, err_str(ERR_NOPRIVILEGES), me.name, parv[0]);
return 0;
}
if (parc < 2)
{
sendto_one(sptr, err_str(ERR_NEEDMOREPARAMS), me.name, parv[0], "GLOBAL");
return 0;
}
if (*parv[1]) {
gmessage = parv[1];
do_global(sptr, cptr, gmessage);
}

}