wiznet_printf.c
snippets · 2.9 KB · 2010-03-30
wiznet_printf: a wiznet that accepts printf-style messages.
Download « Back to the snippets list
// * ***************************************************************** * //
// * Wiznet, printf ? Okay, the run-down, we drop a wiznet, However * //
// * We work alittle differently, this will send a formated wiznet to * //
// * Whatever wiznet-channel you default the data to. * //
// * This is nothing special, have fun with it, i personaly replaced * //
// * tons of calls to sprintf then wiznet, and just simply dropped * //
// * everything to wiznet, :) saves lots of time, and code * //
// * ***************************************************************** * //
// * Enjoy :) -- Dazzle of Sandstorm: The Mages Sanctuary * //
// * Warning, this requires the release of my replacement to strcpy * //
// * and strcat, called replace-str.c* //
// * For more printf functions, just look up Dazzle on mudmagic.c in * //
// * the code search, and all of my released snippets will be there. * //
// * Add this to merc.h or proto.h, whatever one you got, in the proto-section * //
void wiznet_printf(CHAR_DATA *ch, OBJ_DATA *obj,long flag, long flag_skip, int min_level, char* format, ...);
in act_wiz.c, under the void wiznet function.
void wiznet_printf(CHAR_DATA *ch, OBJ_DATA *obj,
long flag, long flag_skip, int min_level,
char* format, ...)
{
va_list ap;
char buf[LBUF],buf2[LBUF], Newtime[30];
char *strtime = (char *) ctime( ¤t_time );
DESCRIPTOR_DATA *d;
int pos = 0, i = 1;
do
{
if (i > 11)
buf[pos++] = *strtime;
}
while (*strtime++ && i++ && pos < 8);
buf[pos] = '\0';
mudstrlcpy(Newtime, buf, 30);
sprintf(buf,"[WiZNET] %s: ", Newtime);
va_start(ap, format);
if(!descriptor_list)
return;
for ( d = descriptor_list; d != NULL; d = d->next )
{
char immnetbuffer[LBUF];
if(!d->character)
continue;
if (d->connected == CON_PLAYING && IsImmortal(d->character) && IsSet(d->character->wiznet,WIZ_ON)
&& (!flag || IsSet(d->character->wiznet,flag)) && (!flag_skip || !IsSet(d->character->wiznet,flag_skip))
&& get_trust(d->character) >= min_level && d->character != ch)
{
vsnprintf(buf2, sizeof(buf2), format, ap);
mudstrlcat(buf, buf2, LBUF );
sprintf(immnetbuffer, "%s", buf);
act_new(immnetbuffer,d->character,obj,ch,TO_CHAR,POS_DEAD);
}
}
va_end(ap);
return;
}
// *Example of this code...* //
// *i threw this in just under where it says 'wrong password' in the nanny before i wrote my new system, does wonders.* //
wiznet_printf(NULL, NULL, WIZ_SECURE, 0, IMMORTAL, "%s has had a failed password attempt from host: %s", ch->name, ch->desc->host);
You can also use this with stuff like $n if you want to grap the PERS data, and use the other variables, if you should be so inclined.
I personaly don't use those that-much, i figure imm's should see things as they are :)