Exemple #1
0
void do_8ball(COMMAND_ARGS)
{
	char	*message;

	if ((message = randstring(RAND8BALLFILE)) == NULL)
	{
		to_user_q(from,ERR_FILEOPEN,RAND8BALLFILE);
		return;
	}

	to_user_q(from,FMT_PLAIN,message);
}
Exemple #2
0
/*
help:HOSTINFO:(no arguments)

Equivalent to ``uname -orm''

See also: meminfo, cpuinfo
*/
void do_hostinfo(COMMAND_ARGS)
{
	struct utsname un;

	if (uname(&un) == 0)
		to_user_q(from,"%s %s %s",un.sysname,un.release,un.machine);
}
Exemple #3
0
/*
 *
 *  commands for variables
 *
 */
void do_esay(COMMAND_ARGS)
{
	/*
	 *  on_msg checks CAXS + CARGS
	 */
	char	output[MSGLEN];
	char	c,*chp;
	int	i,n;

	ec_end = output + MSGLEN - 20;
	ec_src = rest;
	rest = STREND(rest);
	ec_dest = output;
	c = 0;
	chp = NULL;

	while(*ec_src)
	{
		if (*ec_src != '$')
		{
			*(ec_dest++) = *(ec_src++);
			continue;
		}
		for(i=0;ecmd[i].len;i++)
		{
			if ((rest - ec_src) >= ecmd[i].len)
			{
				chp = ec_src + ecmd[i].len;
				c = *chp;
				*chp = 0;
			}
			n = Strcasecmp(ecmd[i].name,ec_src);
			if (c)
			{
				*chp = c;
				c = 0;
			}
			if (!n)
			{
				ec_src += ecmd[i].len;
				ecmd[i].func(from,to);
				break;
			}
		}
		if (!ecmd[i].len)
		{
			*(ec_dest++) = *(ec_src++);
		}
	}
	*ec_dest = 0;
	to_user_q(from,FMT_PLAIN,output);
}
Exemple #4
0
void usage_command(char *to, const char *arg)
{
	char	*pt;
	int	i;

	for(i=0;ulist[i].command;i++)
	{
		if (!Strcasecmp(arg,ulist[i].command))
		{
			pt = ulist[i].usage;
			to_user_q(to,(pt) ? "Usage: %s %s" : "Usage: %s",ulist[i].command,pt);
			return;
		}
	}
	to_user(to,"Usage: (missing)");
}
Exemple #5
0
/*
help:MEMINFO:(no arguments)

Will display memory usage of the energymech process.

VM   Virtual size, size if everything was loaded into memory)
RSS   Resident set size, physical memory actually in use right now.
  Code    Memory allocated for code
  Data    Memory allocated for data
  Libs    Memory used by shared libraries
  Stack   Memory allocated for stack

See also: hostinfo, cpuinfo
*/
void do_meminfo(COMMAND_ARGS)
{
	char	fn[64];
	pid_t	p;
	int	i,fd;

	p = getpid();
	snprintf(fn,sizeof(fn),"/proc/%i/status",p);

	for(i=0;sv[i].key;i++)
		*(sv[i].valbuf) = 0;
	if ((fd = open(fn,O_RDONLY)) < 0)
		return;
	readline(fd,&parse_proc_status);	// readline closes fd

	to_user_q(from,"VM %s (Max %s), RSS %s [ Code %s, Data %s, Libs %s, Stack %s ]",
		vmsize,vmpeak,vmrss,vmexe,vmdata,vmlib,vmstk);
}
Exemple #6
0
void do_usage(COMMAND_ARGS)
{
	/*
	 *  on_msg checks: CARGS
	 */
	char	*cmd;
	int	i;

	cmd = chop(&rest);
	for(i=0;mcmd[i].name;i++)
	{
		if (!Strcasecmp(cmd,mcmd[i].name))
		{
			usage_command(from,mcmd[i].name);
			return;
		}
	}
	to_user_q(from,"Unknown command: %s",cmd);
}
Exemple #7
0
void do_seen(COMMAND_ARGS)
{
	Seen	*seen;
	char	ago[35];		/* enought for "36500 days, 23 hours and 59 minutes" (100 years) */
	char	*chan,*fmt,*n,*u,*c1,*c2,*c3;
	time_t	when;
	int	d,h,m,mul;

	chan = get_channel(to,&rest);
	mul = get_maxaccess(from);

	if (!*rest)
	{
		if (mul) to_user_q(from,"Who do you want me look for?");
		return;
	}

	n = chop(&rest);
	if (!is_nick(n))
	{
		if (mul) to_user_q(from,ERR_NICK,n);
		return;
	}

	if (!nickcmp(n,current->nick))
	{
		fmt = "%s is me you dweeb!";
	}
	else
	if (!nickcmp(n,from))
	{
		fmt = "Trying to find yourself %s?";
	}
	else
	{
		for(seen=seenlist;seen;seen=seen->next)
		{
			if (!Strcasecmp(n,seen->nick))
				break;
		}

		if (!seen)
		{
			fmt = "I have no memory of %s";
		}
		else
		{
			when = now - seen->when;
			d = when / 86400;
			h = (when -= d * 86400) / 3600;
			m = (when -= h * 3600) / 60;

			*ago = 0;
			c2 = ago;

			if (d)
			{
				sprintf(c2,"%i day%s, ",d,EXTRA_CHAR(d));
			}
			if (h || d)
			{
				sprintf(ago,"%s%i hour%s and ",ago,h,EXTRA_CHAR(h));
			}
			sprintf(ago,"%s%i minute%s",ago,m,EXTRA_CHAR(m));

			n = seen->nick;
			u = seen->userhost;
			c1 = seen->pa;
			c2 = ago;

			switch(seen->t)
			{
			case SEEN_PARTED:
				fmt = "%s (%s) parted from %s, %s ago";
				break;
			case SEEN_QUIT:
				fmt = "%s (%s) signed off with message \"%s\", %s ago";
				break;
			case SEEN_NEWNICK:
				fmt = "%s (%s) changed nicks to %s, %s ago";
				break;
			case SEEN_KICKED:
				c2 = seen->pb;
				c3 = ago;
				fmt = "%s (%s) was kicked by %s with message \"%s\", %s ago";
			}
		}
	}

	to_user_q(from,fmt,n,u,c1,c2,c3);
}
Exemple #8
0
void do_bigsay(COMMAND_ARGS)
{
	/*
	 *  on_msg checks CARGS + CAXS
	 */
	BigC	*bigc;
	Strp	*sp;
	char	output[MSGLEN];
	char	*pt,*tail,*temp;
	int	i,x,sz;

#ifdef DEBUG
	debug("(do_bigsay) rest = \"%s\"\n",rest);
#endif /* DEBUG */

	Strcpy(output,BIGSAY_DEFAULTFONT);

	if (read_bigcharset(output) < 0)
	{
		to_user(from,ERR_FILEOPEN,output);
		return;
	}

	for(i=0;i<charheight;i++)
	{
		sz = 0;
		*output = 0;
		tail = output;
		for(pt=rest;*pt;pt++)
		{
			/* find a matching character */
			if (*pt == ' ')
			{
				x = spacewidth;
				while(x--)
					*(tail++) = ' ';
				*tail = 0;
				continue;
			}
			for(bigc=fontlist;bigc;bigc=bigc->next)
			{
				if (STRCHR(bigc->chars,*pt))
				{
					sp = bigc->data;
					for(x=0;x<i;x++)
						if (sp) sp = sp->next;
					temp = Strcat(tail,sp->p);
					while(temp < (tail + bigc->width))
						*(temp++) = ' ';
					if (pt[1])
					{
						x = kerning;
						while(x--)
							*(temp++) = ' ';
					}
					*temp = 0;
					tail = temp;
					break;
				}
			}
		}
		temp = NULL;
		for(tail=output;*tail;tail++)
		{
			if (!temp && *tail == ' ')
				temp = tail;
			if (*tail != ' ')
				temp = NULL;
		}
		if (temp)
		{
			if (temp == output)
				temp++;
			*temp = 0;
		}
		to_user_q(from,FMT_PLAIN,output);
	}
}
Exemple #9
0
/*
help:CPUINFO:(no arguments)

See also: hostinfo, meminfo
*/
void do_cpuinfo(COMMAND_ARGS)
{
	char	bogostr[64],cpustr[64];
	char	*a1,*a2,*a3,*dst;
	int	fd,n;

#ifdef DEVELOPING
	a1 = chop(&rest);
	if (a1)
		sprintf(bogostr,"/home/git/cpuinfo/%s",a1);
	else
		stringcpy(bogostr,"/proc/cpuinfo");
	if ((fd = open(bogostr,O_RDONLY)) < 0)
//	if ((fd = open("/home/git/cpuinfo/mips3",O_RDONLY)) < 0)
//	if ((fd = open("/home/git/cpuinfo/mips2",O_RDONLY)) < 0)
//	if ((fd = open("/home/git/cpuinfo/mips1",O_RDONLY)) < 0)
//	if ((fd = open("/home/git/cpuinfo/intel1",O_RDONLY)) < 0)
//	if ((fd = open("/home/git/cpuinfo/cosmiccow",O_RDONLY)) < 0)
#endif
	if ((fd = open("/proc/cpuinfo",O_RDONLY)) < 0)
#ifdef DEBUG
	{
		debug("(do_cpuinfo) /proc/cpuinfo: %s\n",strerror(errno));
		return;
	}
#else
		return;
#endif

	global_from = from;
	havemodel = bogo = siblings = procct = cpus = cores = physid = 0;
	omni[1] = 0;
	readline(fd,&parse_proc_cpuinfo); // readline closes fd

	if ((fd = open("/proc/loadavg",O_RDONLY)) < 0)
#ifdef DEBUG
	{
		debug("(do_cpuinfo) /proc/loadavg: %s\n",strerror(errno));
		return;
	}
#else
		return;
#endif
	n = read(fd,globaldata,MSGLEN-2);
	globaldata[n] = 0;
	close(fd);

	rest = globaldata;
	a1 = chop(&rest);
	a2 = chop(&rest);
	a3 = chop(&rest);

	if (!a3 || !*a3)
		return;

#ifdef DEBUG
	debug("(do_cpuinfo) procct %i, physid %i, cores %i, bogo %i\n",procct,physid,cores,bogo);
#endif

	if (cores == 0)
		cores = bogo;
	if (cores && physid && (physid % cores) == 0)
		cpus = (physid / cores)-1;
	if (cores && (cpus == 0 || physid == cores))
		cpus = 1;

	*bogostr = 0;
	*cpustr = 0;
	if (bogo)
		sprintf(bogostr,", %s BogoMips",vmlib);
	if (cpus > 1 || (cores > cpus))
	{
		sprintf(cpustr,", %i physical cpu%s",cpus,(cpus == 1) ? "" : "s");
		if (cores)
			sprintf(STREND(cpustr),", %i core%s",cores,(cores == 1) ? "" : "s");
	}
	to_user_q(from,"%s%s%s, loadavg: %s(1m) %s(5m) %s(15m)",
		omni+1,bogostr,cpustr,a1,a2,a3);
}