Beispiel #1
0
/**
 * @return The MySQL-escaped name for the given entity.
 */
static const char *G_MySQL_EntityName(const g_entity_t *ent) {
	char name[MAX_NET_NAME];
	static char escaped[MAX_NET_NAME];

	if (!g_mysql_state.mysql) {
		return NULL;
	}

	if (!ent) {
		return "none";
	}

	if (!ent->client) {
		return ent->class_name;
	}

	StripColors(ent->client->locals.persistent.net_name, name);

	if (ent->ai) {
		g_strlcat(name, " [bot]", sizeof(name));
	}

	mysql_real_escape_string(g_mysql_state.mysql, name, escaped, sizeof(escaped));
	return escaped;
}
Beispiel #2
0
DLLFUNC char *restrictcolors_checkmsg(aClient *cptr, aClient *sptr, aChannel *chptr, char *text, int notice)
{
    if (IsULine(sptr) || IsServer(sptr))
       return text;

    if (chptr->mode.extmode && RESTRICT_COLORS && !is_chan_op(sptr, chptr) && !is_halfop(sptr, chptr))
       return StripColors(text);

    return text;
}
 char *nocolor_pre_usermsg(aClient *sptr, aClient *acptr, char *text, int notice)
 {
 	if (IsULine(sptr) || IsServer(sptr))
 		return text;

 	if (acptr->umodes & UMODE_STRIPCOLOR)
 		return StripColors(text);

 	return text;
 }
bool FontRendererImpl::GetStringMetrics(const std::string& characterString, float fontSize, float fontScale, const std::string& fontRef, Rect* outRect)
{
	ComPtr<IDWriteTextFormat> textFormat;
	m_dwFactory->CreateTextFormat(ToWide(fontRef).c_str(), nullptr, DWRITE_FONT_WEIGHT_NORMAL, DWRITE_FONT_STYLE_NORMAL, DWRITE_FONT_STRETCH_NORMAL, fontSize, L"en-us", textFormat.GetAddressOf());

	std::string stripped = StripColors(characterString);
	std::wstring wide = ToWide(stripped);

	ComPtr<IDWriteTextLayout> textLayout;
	m_dwFactory->CreateTextLayout(wide.c_str(), static_cast<UINT32>(wide.length()), textFormat.Get(), 8192.0, 8192.0, textLayout.GetAddressOf());

	DWRITE_TEXT_METRICS textMetrics;
	textLayout->GetMetrics(&textMetrics);

	*outRect = Rect();
	outRect->SetRect(textMetrics.left, textMetrics.top, textMetrics.left + textMetrics.width, textMetrics.top + textMetrics.height);

	return true;
}
Beispiel #5
0
/*
** m_part
**	parv[0] = sender prefix
**	parv[1] = channel
**	parv[2] = comment (added by Lefler)
*/
DLLFUNC CMD_FUNC(m_part)
{
	aChannel *chptr;
	Membership *lp;
	char *p = NULL, *name;
	char *commentx = (parc > 2 && parv[2]) ? parv[2] : NULL;
	char *comment;
	int n;
	
	if (parc < 2 || parv[1][0] == '\0')
	{
		sendto_one(sptr, err_str(ERR_NEEDMOREPARAMS),
		    me.name, parv[0], "PART");
		return 0;
	}

	if (MyClient(sptr))
	{
		if (IsShunned(sptr))
			commentx = NULL;
		if (STATIC_PART)
		{
			if (!strcasecmp(STATIC_PART, "yes") || !strcmp(STATIC_PART, "1"))
				commentx = NULL;
			else if (!strcasecmp(STATIC_PART, "no") || !strcmp(STATIC_PART, "0"))
				; /* keep original reason */
			else
				commentx = STATIC_PART;
		}
		if (commentx)
		{
			n = dospamfilter(sptr, commentx, SPAMF_PART, parv[1], 0, NULL);
			if (n == FLUSH_BUFFER)
				return n;
			if (n < 0)
				commentx = NULL;
		}
	}

	for (; (name = strtoken(&p, parv[1], ",")); parv[1] = NULL)
	{
		chptr = get_channel(sptr, name, 0);
		if (!chptr)
		{
			sendto_one(sptr, err_str(ERR_NOSUCHCHANNEL),
			    me.name, parv[0], name);
			continue;
		}
		if (check_channelmask(sptr, cptr, name))
			continue;

		/* 'commentx' is the general part msg, but it can be changed
		 * per-channel (eg some chans block badwords, strip colors, etc)
		 * so we copy it to 'comment' and use that in this for loop :)
		 */
		comment = commentx;

		if (!(lp = find_membership_link(sptr->user->channel, chptr)))
		{
			/* Normal to get get when our client did a kick
			   ** for a remote client (who sends back a PART),
			   ** so check for remote client or not --Run
			 */
			if (MyClient(sptr))
				sendto_one(sptr,
				    err_str(ERR_NOTONCHANNEL), me.name,
				    parv[0], name);
			continue;
		}

		if (!IsAnOper(sptr) && !is_chanownprotop(sptr, chptr)) {
#ifdef STRIPBADWORDS
			int blocked = 0;
#endif
			/* Banned? No comment allowed ;) */
			if (comment && is_banned(sptr, chptr, BANCHK_MSG))
				comment = NULL;
			/* And other things... */
			if ((chptr->mode.mode & MODE_NOCOLOR) && comment) {
				if (strchr((char *)comment, 3) || strchr((char *)comment, 27)) {
					comment = NULL;
				}
			}
			if ((chptr->mode.mode & MODE_MODERATED) && comment &&
				 !has_voice(sptr, chptr) && !is_halfop(sptr, chptr))
			{
				comment = NULL;
			}
			if ((chptr->mode.mode & MODE_STRIP) && comment) {
				comment = (char *)StripColors(comment);
			}
#ifdef STRIPBADWORDS
 #ifdef STRIPBADWORDS_CHAN_ALWAYS
			if (comment)
			{
				comment = (char *)stripbadwords_channel(comment, &blocked);
			}
 #else
			if ((chptr->mode.extmode & EXTMODE_STRIPBADWORDS) && comment) {
				comment = (char *)stripbadwords_channel(comment, &blocked);
			}
 #endif
#endif
			
		}
		/* +M and not logged in to services? */
		if ((chptr->mode.mode & MODE_MODREG) && !IsLoggedIn(sptr) && !IsAnOper(sptr))
			comment = NULL;

		if (MyConnect(sptr))
		{
			Hook *tmphook;
			for (tmphook = Hooks[HOOKTYPE_PRE_LOCAL_PART]; tmphook; tmphook = tmphook->next) {
				comment = (*(tmphook->func.pcharfunc))(sptr, chptr, comment);
				if (!comment)
					break;
			}
		}

		/* Send to other servers... */
		if (!comment)
			sendto_serv_butone_token(cptr, parv[0],
			    MSG_PART, TOK_PART, "%s", chptr->chname);
		else
			sendto_serv_butone_token(cptr, parv[0],
			    MSG_PART, TOK_PART, "%s :%s", chptr->chname,
			    comment);

		if (1)
		{
			if ((chptr->mode.mode & MODE_AUDITORIUM) && !is_chanownprotop(sptr, chptr))
			{
				if (!comment)
				{
					sendto_chanops_butone(NULL,
					    chptr, ":%s!%s@%s PART %s",
					    sptr->name, sptr->user->username, GetHost(sptr),
					    chptr->chname);
					if (!is_chan_op(sptr, chptr) && MyClient(sptr))
						sendto_one(sptr, ":%s!%s@%s PART %s",
						    sptr->name, sptr->user->username, GetHost(sptr), chptr->chname);
				}
				else
				{
					sendto_chanops_butone(NULL,
					    chptr,
					    ":%s!%s@%s PART %s %s",
					    sptr->name,
					    sptr->user->username,
					    GetHost(sptr),
					    chptr->chname, comment);
					if (!is_chan_op(cptr, chptr) && MyClient(sptr))
						sendto_one(sptr,
						    ":%s!%s@%s PART %s %s",
						    sptr->name, sptr->user->username, GetHost(sptr),
						    chptr->chname, comment);
				}
			}
			else
			{


				if (!comment)

					sendto_channel_butserv(chptr,
					    sptr, PARTFMT, parv[0],
					    chptr->chname);
				else
					sendto_channel_butserv(chptr,
					    sptr, PARTFMT2, parv[0],
					    chptr->chname, comment);
			}
			if (MyClient(sptr))
				RunHook4(HOOKTYPE_LOCAL_PART, cptr, sptr, chptr, comment);
			else
				RunHook4(HOOKTYPE_REMOTE_PART, cptr, sptr, chptr, comment);

			remove_user_from_channel(sptr, chptr);
		}
	}
	return 0;
}
Beispiel #6
0
/*
 * @brief
 */
static void Cl_Print(const console_string_t *str) {
	char stripped[strlen(str->chars) + 1];

	StripColors(str->chars, stripped);
	fputs(stripped, stdout);
}
Beispiel #7
0
/*
** m_quit
**	parv[0] = sender prefix
**	parv[1] = comment
*/
DLLFUNC int  m_quit(aClient *cptr, aClient *sptr, int parc, char *parv[])
{
	char *ocomment = (parc > 1 && parv[1]) ? parv[1] : parv[0];
	static char comment[TOPICLEN + 1];
	Membership *lp;

	if (!IsServer(cptr) && IsPerson(sptr))
	{
#ifdef STRIPBADWORDS
		int blocked = 0;
#endif
		int n;
		char *s = comment;
		Hook *tmphook;
		if (STATIC_QUIT)
			return exit_client(cptr, sptr, sptr, STATIC_QUIT);
		if (IsVirus(sptr))
			return exit_client(cptr, sptr, sptr, "Client exited");

		if (!prefix_quit || strcmp(prefix_quit, "no"))
			s = ircsprintf(comment, "%s ",
		    		BadPtr(prefix_quit) ? "Quit:" : prefix_quit);
#ifdef STRIPBADWORDS
		ocomment = (char *)stripbadwords_quit(ocomment, &blocked);
		if (blocked)
			ocomment = parv[0];
#endif
		n = dospamfilter(sptr, ocomment, SPAMF_QUIT, NULL, 0, NULL);
		if (n == FLUSH_BUFFER)
			return n;
		if (n < 0)
			ocomment = parv[0];
		
		if (!IsAnOper(sptr) && ANTI_SPAM_QUIT_MSG_TIME)
			if (sptr->firsttime+ANTI_SPAM_QUIT_MSG_TIME > TStime())
				ocomment = parv[0];

		/* Strip color codes if any channel is +S, use nick as reason if +c. */
		if (IsPerson(sptr) && (strchr(ocomment, '\003')))
		{
			unsigned char filtertype = 0; /* 1=filter, 2=block, highest wins. */
			for (lp = sptr->user->channel; lp; lp = lp->next)
			{
				if (lp->chptr->mode.mode & MODE_NOCOLOR)
				{
					filtertype = 2;
					break;
				}
				if (lp->chptr->mode.mode & MODE_STRIP)
				{
					if (!filtertype)
						filtertype = 1;
				}
			}
			if (filtertype == 1)
			{
				ocomment = StripColors(ocomment);
				if (*ocomment == '\0')
					ocomment = parv[0];
			} else
			if (filtertype == 2)
				ocomment = parv[0];
		} /* (strip color codes) */

                for (tmphook = Hooks[HOOKTYPE_PRE_LOCAL_QUIT]; tmphook; tmphook = tmphook->next)
		{
                	ocomment = (*(tmphook->func.pcharfunc))(sptr, ocomment);
                        if (!ocomment)
			{			
				ocomment = parv[0];
                                break;
                        }
                }

		strncpy(s, ocomment, TOPICLEN - (s - comment));
		comment[TOPICLEN] = '\0';
		return exit_client(cptr, sptr, sptr, comment);
	}
	else
	{
		return exit_client(cptr, sptr, sptr, ocomment);
	}
}
Beispiel #8
0
/**
 * @brief Fs_EnumerateFunc for map discovery.
 */
static void enumerateMaps(const char *path, void *data) {

	MapListCollectionView *this = (MapListCollectionView *) data;

	const Array *maps = (Array *) this->maps;
	for (size_t i = 0; i < maps->count; i++) {

		const Value *value = $(maps, objectAtIndex, i);
		const MapListItemInfo *info = value->value;

		if (g_strcmp0(info->mapname, path) == 0) {
			return;
		}
	}

	file_t *file = cgi.OpenFile(path);
	if (file) {

		bsp_header_t header;
		if (cgi.ReadFile(file, (void *) &header, sizeof(header), 1) == 1) {

			for (size_t i = 0; i < sizeof(header) / sizeof(int32_t); i++) {
				((int32_t *) &header)[i] = LittleLong(((int32_t *) &header)[i]);
			}

			if (header.version != BSP_VERSION && header.version != BSP_VERSION_QUETOO) {
				cgi.Warn("Invalid BSP header found in %s: %d\n", path, header.version);
				cgi.CloseFile(file);
				return;
			}

			MapListItemInfo *info = g_new0(MapListItemInfo, 1);

			g_strlcpy(info->mapname, path, sizeof(info->mapname));
			g_strlcpy(info->message, path, sizeof(info->message));

			char *entities = g_malloc(header.lumps[BSP_LUMP_ENTITIES].file_len);

			cgi.SeekFile(file, header.lumps[BSP_LUMP_ENTITIES].file_ofs);
			cgi.ReadFile(file, entities, 1, header.lumps[BSP_LUMP_ENTITIES].file_len);

			const char *ents = entities;

			while (true) {
				char *c = ParseToken(&ents);

				if (*c == '\0') {
					break;
				}

				if (g_strcmp0(c, "message") == 0) {

					c = ParseToken(&ents);
					StripColors(c, info->message);

					c = strstr(info->message, "\\n");
					if (c) {
						*c = '\0';
					}

					c = strstr(info->message, " - ");
					if (c) {
						*c = '\0';
					}

					c = strstr(info->message, " by ");
					if (c) {
						*c = '\0';
					}

					break;
				}
			}

			g_free(entities);

			GList *mapshots = cgi.Mapshots(path);

			const size_t len = g_list_length(mapshots);
			if (len) {
				const char *mapshot = g_list_nth_data(mapshots, rand() % len);

				SDL_Surface *surf;
				if (cgi.LoadSurface(mapshot, &surf)) {
					SDL_SetSurfaceBlendMode(surf, SDL_BLENDMODE_NONE);
					info->mapshot = SDL_CreateRGBSurface(0,
					                                     this->collectionView.itemSize.w * 2,
					                                     this->collectionView.itemSize.h * 2,
					                                     surf->format->BitsPerPixel,
					                                     surf->format->Rmask,
					                                     surf->format->Gmask,
					                                     surf->format->Bmask,
					                                     surf->format->Amask
					                                    );
					SDL_SetSurfaceBlendMode(info->mapshot, SDL_BLENDMODE_NONE);
					SDL_BlitScaled(surf, NULL, info->mapshot, NULL);
				} else {
					info->mapshot = NULL;
				}
			}

			g_list_free_full(mapshots, g_free);

			Value *value = $(alloc(Value), initWithValue, info);

			WithLock(this->lock, {
				$(this->maps, addObject, value);
				$(this->maps, sort, sortMaps);
			});
		}