Exemplo n.º 1
0
/////////////////////
// Get the command based on name
ChatCommand *GetCommand(const std::string& name)
{
	for (uint i=0; tKnownCommands[i].tProcFunc != NULL; ++i)
		if (stringcasecmp(name, tKnownCommands[i].sName) == 0 ||
			stringcasecmp(name, tKnownCommands[i].sAlias) == 0)
			return &tKnownCommands[i];

	// Not found
	return NULL;
}
Exemplo n.º 2
0
Shit *find_shit(const char *userhost, const char *channel)
{
	Shit	*shit,*save;
	int	num,best;

	if (!userhost)
		return(NULL);
	save = NULL;
	best = 0;
	for(shit=current->shitlist;shit;shit=shit->next)
	{
		if (!channel || !stringcasecmp(channel,shit->chan) ||
		    (*shit->chan == '*') || (*channel == '*'))
		{
			num = num_matches(shit->mask,userhost);
			if (num > best)
			{
				best = num;
				save = shit;
			}
		}
	}
	if (save && save->expire < now)
	{
		remove_shit(save);
		save = NULL;
	}
	return(save);
}
Exemplo n.º 3
0
int catch_note(char *from, char *to, char *rest)
{
	User	*u;
	Note	*n,**pp;
	Strp	*sp,**np;

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

	pp = &notelist;
	while(*pp)
	{
		n = *pp;
#ifdef DEBUG
		debug("(catch_note) n->from = %s, n->to = %s\n",n->from,n->to);
#endif /* DEBUG */
		if (!stringcasecmp(from,n->from) && !stringcasecmp(to,n->to))
		{
#ifdef DEBUG
			debug("(catch_note) note to user = %s\n",n->user);
#endif /* DEBUG */
			if (rest[0] == '.' && rest[1] == 0)
			{
				to_user(from,"Note for %s has been saved",n->user);
				*pp = n->next;
				Free((char**)&n);
				return(TRUE);
			}
			if (!(u = find_handle(n->user)))
				return(TRUE);
			append_strp(&u->note,rest);
			return(TRUE);
		}
		if ((now - n->start) > 120)
		{
			*pp = n->next;
			Free((char**)&n);
			return(TRUE);
		}
		pp = &(*pp)->next;
	}
	return(FALSE);
}
Exemplo n.º 4
0
std::string ProcessSetName(const std::vector<std::string>& params, int sender_id)
{
	// Check params
	int p_id;
	std::string ch = CheckIDParams(params, &ProcessSetName, &p_id);
	if (ch.size() != 0)
		return ch;

	// Get the sender
	CServerConnection *sender = cServer->getClient(sender_id);
	if (!sender)
		return "Name could not be changed";

	// Check if we can change the name
	if (!sender->getRights()->NameChange && !sender->getRights()->Override)
		return "You don't have sufficient privileges to change user nick";

	// Get the name
	std::string name;
	for (std::vector<std::string>::const_iterator it = params.begin() + 2; it != params.end(); it++)  {
		name += *it;
		name += ' ';
	}
	name.erase(name.size() - 1);  // erase the last space

	name = RemoveSpecialChars(name); // Strip unicode characters
	if (name.size() > 32)  // Check if not too long
		name.erase(32, std::string::npos);

	// Get the target worm
	CWorm *tw = cServer->getWorms() + p_id;
	if (!tw->isUsed())
		return "The worm with specified ID does not exist";

	// Check no other user has this name
	CWorm *w = cServer->getWorms();
	for(int i=0; i < MAX_WORMS; i++, w++) {
		if(!w->isUsed())
			continue;
		if(!stringcasecmp(name, w->getName()) && w->getID() != p_id)
			return "Another player is already using this nick";
	}

	// Set the name
	std::string oldname = tw->getName();
	tw->setName(name);

	// Send the update
	cServer->UpdateWorm(tw);

	// Send the notification
	cServer->SendGlobalText(oldname + " is now known as " + name, TXT_NORMAL);

	return "";
}
Exemplo n.º 5
0
std::string ProcessSetMyName(const std::vector<std::string>& params, int sender_id)
{
	// Check params
	if (params.size() < GetCommand(&ProcessSetMyName)->iMinParamCount)
		return "Not enough parameters";

	// Get the sender
	CServerConnection *sender = cServer->getClient(sender_id);
	if (!sender)
		return "Name could not be changed";

	// Check if we can change the name
	if (!sender->getRights()->NameChange && !tLXOptions->bAllowNickChange && !sender->getRights()->Override)
		return "You don't have sufficient privileges to change your nick";

	if(sender->getNumWorms() == 0)
		return "Your client doesn't have any worms";
	
	// Get the name
	std::string name;
	for (std::vector<std::string>::const_iterator it = params.begin(); it != params.end(); it++)  {
		if(it != params.begin()) name += ' ';
		name += *it;
	}

	name = RemoveSpecialChars(name); // Strip unicode characters
	if (name.size() > 32)  // Check if not too long
		name.erase(32, std::string::npos);

	// Check no other user has this name
	CWorm *w = cServer->getWorms();
	for(int i=0; i < MAX_WORMS; i++, w++) {
		if(!w->isUsed())
			continue;
		if(!stringcasecmp(name, w->getName()) && w->getID() != sender_id)
			return "Another player is already using this nick";
	}

	// Set the name
	std::string oldname = sender->getWorm(0)->getName();
	sender->getWorm(0)->setName(name);

	// Send the update
	cServer->UpdateWorm(sender->getWorm(0));

	// Send the notification
	cServer->SendGlobalText(oldname + " is now known as " + name, TXT_NORMAL);
	notes << "worm rename: " << sender->getWorm(0)->getID() << ":" << oldname << " renamed to " << sender->getWorm(0)->getName() << endl;
	
	return "";
}
Exemplo n.º 6
0
///////////////////
// Common param check used in many cases
std::string CheckIDParams(const std::vector<std::string>& params, ChatCommand::tProcFunc_t func, /*out*/ int *id)
{
	*id = 0;

	// Param count
	ChatCommand *me = GetCommand(func);
	if (params.size() < me->iMinParamCount || params.size() > me->iMaxParamCount)
		return "Invalid parameter count";

	// ID presence check
	if (stringcasecmp(params[0], "id") != 0)
		return "Please specify a worm ID";

	// ID check
	if (!ConvertID(params[1], id))
		return "Invalid worm ID";

	return "";
}
Exemplo n.º 7
0
int spy_source(char *from, int *t_src, const char **src)
{
	int	i;

#ifdef DEBUG
	debug("(spy_source) t_src %i, src %s\n",*t_src,*src);
#endif /* ifdef DEBUG */

	for(i=0;spy_source_list[i].idstring;i++)
	{
		if (!stringcasecmp(*src,spy_source_list[i].idstring))
		{
			*src = spy_source_list[i].idstring;
			*t_src = spy_source_list[i].typenum;
			return(200);
		}
	}
	*t_src = SPY_CHANNEL;
	if (!ischannel(*src))
		return(-1);
	return(get_useraccess(from,*src));
}
Exemplo n.º 8
0
		int operator ()(CListviewItem *item1, CListviewItem *item2)  {
			// Get the correct subitems
			CListviewSubitem *s1; 
			CListviewSubitem *s2;
			if (bAscending)  {
				s1 = item1->getSubitem(iSubitemIndex);
				s2 = item2->getSubitem(iSubitemIndex);
			} else { // Swapped
				s1 = item2->getSubitem(iSubitemIndex);
				s2 = item1->getSubitem(iSubitemIndex);
			}

			// Special case - one or both of the subitems are NULL
			if (s1 == NULL)  {
				if (s2 == NULL)
					return 0;
				else
					return -1;
			}
			if (s2 == NULL && s1 != NULL)
				return 1;

			// Swap the two items?
			bool failed1,failed2;
			int nat_cmp1 = from_string<int>(s1->getName(), failed1);
			int nat_cmp2 = from_string<int>(s2->getName(), failed2);

			// First try, if we compare numbers
			if (!failed1 && !failed2)  {
				if(nat_cmp1 == nat_cmp2)
					return s1->getName().size() - s2->getName().size(); // because from_string("123456") == from_string("123456abcd")
				else
					return nat_cmp1 - nat_cmp2;
			// String comparison
			} else {
				return stringcasecmp(s1->getName(), s2->getName());
			}
		}
Exemplo n.º 9
0
int (*parser_get_correct_func(const char *filename))
    (struct parser *, FILE *)
{
    const char *e = NULL;
    const char *ext = filename;
    const struct ext_parser *p;

    while (*ext) {
        if (*ext == '.')
            e = ext;
        ext++;
    }

    if (!e)
        return NULL;

    e++;

    for (p = parsers; p->extension != NULL; p++)
        if (stringcasecmp(p->extension, e) == 0)
            return p->parser;

    return NULL;
}
Exemplo n.º 10
0
void send_spy(const char *src, const char *format, ...)
{
	Chan	*chan;
	Mech	*backup;
	Spy	*spy;
	va_list	msg;
	const char *tempsrc;
	char	tempdata[MAXLEN];
	int	fd;
	int	printed = FALSE;

	tempsrc = (src == SPYSTR_STATUS) ? time2medium(now) : src;

#ifdef DEBUG
	debug("(send_spy) src %s format = '%s'\n",src,format);
#endif /* DEBUG */

	for(spy=current->spylist;spy;spy=spy->next)
	{
		if ((*src == '#' || *src == '*') && spy->t_src == SPY_CHANNEL)
		{
			if ((*src != '*') && stringcasecmp(spy->src,src))
				continue;
			if ((chan = find_channel_ac(spy->src)) == NULL)
				continue;
			if (find_chanuser(chan,CurrentNick) == NULL)
				continue;
			tempsrc = spy->src;
		}
		else
		/*
		 *  by using string constants we can compare addresses
		 */
		if (spy->src != src)
			continue;

		if (!printed)
		{
			printed = TRUE;
			va_start(msg,format);
			vsprintf(tempdata,format,msg);
			va_end(msg);
		}

		switch(spy->t_dest)
		{
		case SPY_DCC:
			to_file(spy->dcc->sock,"[%s] %s\n",tempsrc,tempdata);
			break;
		case SPY_CHANNEL:
			if (spy->destbot >= 0)
			{
				backup = current;
				for(current=botlist;current;current=current->next)
				{
					if (current->guid == spy->destbot)
					{
						to_server("PRIVMSG %s :[%s] %s\n",spy->dest,tempsrc,tempdata);
						break;
					}
				}
				current = backup;
			}
			else
			{
				to_user(spy->dest,"[%s] %s",tempsrc,tempdata);
			}
			break;
		case SPY_FILE:
			if ((fd = open(spy->dest,O_WRONLY|O_CREAT|O_APPEND,NEWFILEMODE)) >= 0)
			{
				to_file(fd,"[%s] %s\n",logtime(now),tempdata);
				close(fd);
			}
		}
	}
}
Exemplo n.º 11
0
bool LevelInfo::operator<(const CustomVar& o) const {
	const LevelInfo* oi = dynamic_cast<const LevelInfo*> (&o);
	if(oi) return stringcasecmp(path, oi->path) < 0;
	return this < &o;		
}
Exemplo n.º 12
0
///////////////////
// Read a string
static bool GetString(const std::string& filename, const std::string& section, const std::string& key, std::string& string, bool abs_fn)
{
	FILE	*config = NULL;
	std::string	Line;
	std::string	tmpLine;
	std::string	curSection;
	std::string	temp;
	std::string	curKey;
	size_t	chardest = 0;
	int		Position;
	bool	found = false;
	
	if(filename == "")
		return false;
	
	if(abs_fn) {
		config = OpenGameFile(filename.c_str(), "rt");
	} else
		config = OpenGameFile(filename,"rt");
	if(!config)
		return false;
	
	//string="";
	curSection="";
	temp="";
	curKey="";
	
	// Check for UTF-8 encoded file and skip the UTF-8 mark if it is
	unsigned char utf8mark[3] = {0,0,0};
	if(fread(utf8mark, sizeof(utf8mark), 1, config) == 0) {
		fclose(config);
		return false;
	}
	if (utf8mark[0] != 0xEF || utf8mark[1] != 0xBB || utf8mark[2] != 0xBF)
		fseek(config, 0, SEEK_SET); // Not a UTF-8 file, jump back to the beginning
	
	
	while(!feof(config) && !ferror(config))
	{
		// Parse the lines
		Line = ReadUntil(config, '\n');
		TrimSpaces(Line);
		
		///////////////////
		// Comment, Ignore
		if(Line.size() == 0 || Line[0] == '#')
			continue;
		
		////////////
		// Sections
		if(Line[0] == '[' && Line[Line.size()-1] == ']')
		{
			curSection = Line.substr(1);
			curSection.erase(curSection.size()-1);
			continue;
		}
		
		////////
		// Keys
		chardest = Line.find('=');
		if(chardest != std::string::npos)
		{
			// Key
			Position = (int)chardest;
			tmpLine = Line;
			tmpLine.erase(Position);
			TrimSpaces(tmpLine);
			curKey = tmpLine;
			
			// Check if this is the key were looking for under the section were looking for
			if(stringcasecmp(curKey,key) == 0 && stringcasecmp(curSection,section) == 0)
			{
				// Get the value
				tmpLine = Line.substr(Position+1);
				TrimSpaces(tmpLine);
				string = tmpLine;
				found = true;
				break;
			}
			continue;
		}
	}
	
	fclose(config);
	
	return found;
}