Exemple #1
0
/*
// Name: nick
// In: c, the client that sent the command.
// 	   tag, the tag sent from the client.
//	   newname, the name that the client wants to have.
//	   is_quoted, if the name contains quotes.
//	   clients, all connected clients.
// Out: 0
// Purpose: Handles the command NICK
*/
int nick(clientconn_t *c, char *tag, char *newname, 
						int is_quoted, hash *clients) {
	if(newname==NULL || strlen(newname)==0) {
		char msg[MAXTOKENSIZE];
		client_write(c, "* NICK ", 7);
		if(strstr(c->name, " ")) {
			client_write(c, enquote(c->name), strlen(enquote(c->name)));
		} else {
			client_write(c, c->name, strlen(c->name));
		}
		client_write(c, "\r\n", 2);
	} else {
		if(is_quoted) {
			remove_quote(newname, strlen(newname));
		} else if (strstr(newname, " ")!=NULL){
			return badly_formed(c, tag);
		}
		if(nickoccupied(newname, clients)) {
			client_write(c, tag, strlen(tag));
			client_write(c, " NO Name ", 9);
			client_write(c, newname, strlen(newname));
			client_write(c," is already in use.\r\n", 22);
			return 0;
		}
		char prev_name[MAXTOKENSIZE];
		strcpy(prev_name, c->name);
		memset(c->name, '\0', MAXTOKENSIZE);
		remove_quote(newname, strlen(newname));
		strncpy(c->name, newname, strlen(newname));
		if(strlen(prev_name)!=0 && c->joined) {
			char msg[MAXTOKENSIZE];
			strcpy(msg, "* RENAME ");
			if(strstr(prev_name, " ")) {
				strcat(msg, enquote(prev_name));
			} else {
				strcat(msg,prev_name);
			}
			strcat(msg, " ");
			if(is_quoted) {
				strcat(msg, enquote(newname));
			} else {
				strcat(msg, newname);
			}
			broadcast(msg, strlen(msg), c, clients, MSG_RENAME);
		} else {
			char msg[MAXTOKENSIZE];
			strcpy(msg, "* NICK ");
			if(is_quoted) {
				strcat(msg, enquote(newname));
			} else { 
				strcat(msg, newname);
			}
			strcat(msg, "\r\n");
			client_write(c, msg, strlen(msg));
		}
	}
	client_write(c, tag, strlen(tag));
	client_write(c, " OK NICK\r\n", 10);
	return 0;
}
Exemple #2
0
/** Player <I>player_num</I> has rejected trade */
void quote_view_reject(QuoteView * qv, gint player_num)
{
	Player *player = player_get(player_num);
	QuoteInfo *quote;
	GtkTreeIter iter;
	enum TFindResult found;
	GdkPixbuf *pixbuf;

	if (qv->quote_list == NULL)
		return;

	while ((quote =
		quotelist_find_domestic(qv->quote_list, player_num,
					-1)) != NULL) {
		remove_quote(qv, quote);
	}

	quote_found_flag = FALSE;
	gtk_tree_model_foreach(GTK_TREE_MODEL(qv->store),
			       trade_locate_reject, player);
	if (quote_found_flag)	/* Already removed */
		return;

	/* work out where to put the reject row
	 */
	for (quote = quotelist_first(qv->quote_list);
	     quote != NULL; quote = quotelist_next(quote))
		if (!quote->is_domestic)
			continue;
		else if (quote->var.d.player_num >= player_num)
			break;

	found =
	    find_integer_in_tree(GTK_TREE_MODEL(qv->store), &iter,
				 TRADE_COLUMN_PLAYER_NUM, player_num);
	if (found != FIND_NO_MATCH)
		gtk_list_store_insert_before(qv->store, &iter, &iter);
	else
		gtk_list_store_append(qv->store, &iter);
	pixbuf = player_create_icon(GTK_WIDGET(qv), player_num, TRUE);
	gtk_list_store_set(qv->store, &iter, TRADE_COLUMN_PLAYER, pixbuf,
			   TRADE_COLUMN_POSSIBLE, cross_pixbuf,
			   /* Trade: a player has rejected trade */
			   TRADE_COLUMN_DESCRIPTION, _("Rejected trade"),
			   TRADE_COLUMN_QUOTE, NULL,
			   TRADE_COLUMN_REJECT, player,
			   TRADE_COLUMN_PLAYER_NUM, player_num, -1);
	g_object_unref(pixbuf);
}
Exemple #3
0
void quote_view_remove_quote(QuoteView * qv, gint partner_num,
			     gint quote_num)
{
	QuoteInfo *quote;

	if (qv->quote_list == NULL)
		return;

	g_assert(qv->quote_list != NULL);
	quote =
	    quotelist_find_domestic(qv->quote_list, partner_num,
				    quote_num);

	if (quote == NULL)
		return;
	g_assert(quote != NULL);
	remove_quote(qv, quote);
}
Exemple #4
0
void quote_view_theme_changed(QuoteView * qv)
{
	int width, height;
	GdkPixmap *pixmap;
	GdkGC *gc;
	QuoteInfo *quote;

	if (!qv->with_maritime)
		return;

	gtk_icon_size_lookup(GTK_ICON_SIZE_MENU, &width, &height);

	pixmap =
	    gdk_pixmap_new(qv->quotes->window, width, height,
			   gtk_widget_get_visual(qv->quotes)->depth);

	gc = gdk_gc_new(pixmap);
	gdk_gc_set_foreground(gc, &black);
	gdk_draw_rectangle(pixmap, gc, TRUE, 0, 0, width, height);
	gdk_gc_set_fill(gc, GDK_TILED);
	gdk_gc_set_tile(gc, theme_get_terrain_pixmap(SEA_TERRAIN));
	gdk_draw_rectangle(pixmap, gc, TRUE, 0, 0, width, height);
	if (maritime_pixbuf)
		g_object_unref(maritime_pixbuf);
	maritime_pixbuf =
	    gdk_pixbuf_get_from_drawable(NULL, pixmap, NULL, 0, 0, 0, 0,
					 -1, -1);
	g_object_unref(gc);
	g_object_unref(pixmap);

	/* Remove all maritime quotes */
	quote = quotelist_first(qv->quote_list);
	while (quote != NULL) {
		QuoteInfo *curr = quote;
		quote = quotelist_next(quote);
		if (curr->is_domestic)
			break;
		remove_quote(qv, curr);
	}

	/* Add all of the maritime trades that can be performed */
	check_maritime_trades(qv);
}
char* tapp_setup_encoding(char *en)
{
        en = remove_quote(en);

	if (en == NULL || strcmp(en, "locale") == 0) {
		setlocale(LC_ALL, "");
		en = nl_langinfo(CODESET);
		print_message("ENCODING: locale = %s\n", en);
	}

	if (en && (strchr(en, ',') == NULL)) {
		char *encname = en;
		en = tcaps_find_entry(&(gApp.gCaps), "encoding.", encname);
		if (!en) {
			/* not found */
			iconv_t cd = iconv_open("UCS-2BE", encname);
			if (cd != (iconv_t)(-1)) {
				iconv_close(cd);

				en = malloc(sizeof(char) *
                                            (strlen("other,iconv,UTF-8") + 1 + strlen(encname)));
				if (en == NULL)
					die("not enough memory: encode");

				sprintf(en, "other,%s,iconv,UTF-8", encname);
			} else {
				print_error("%s not found, fallback to default\n", encname);
			}
		}
	}

	if (!en)
                en = "G0,G1,ansix3.4-1968,ansix3.4-1968,iso8859.1-1987,ansix3.4-1968";

	return en;
}
Exemple #6
0
/** Check if all existing maritime trades are valid.
 *  Add and remove maritime trades as needed
 */
static void check_maritime_trades(QuoteView * qv)
{
	QuoteInfo *quote;
	gint idx;
	gboolean check_supply = FALSE;
	gint maritime_supply[NO_RESOURCE];

	if (!qv->with_maritime)
		return;

	/* Check supply whenever any supply box is selected.  */
	for (idx = 0; idx < NO_RESOURCE; ++idx) {
		if (qv->maritime_filter_supply[idx])
			check_supply = TRUE;
	}

	/* Check how many of which resources can be used for maritime supply.
	 */
	for (idx = 0; idx < NO_RESOURCE; ++idx) {
		if (check_supply && !qv->maritime_filter_supply[idx])
			maritime_supply[idx] = 0;
		else
			maritime_supply[idx] = maritime_amount(qv, idx);
	}

	/* Remove invalid quotes.  */
	quote = quotelist_first(qv->quote_list);
	while (quote != NULL) {
		QuoteInfo *curr = quote;

		quote = quotelist_next(quote);
		if (curr->is_domestic)
			break;

		/* Is the current quote valid?  */
		if (qv->maritime_filter_receive[curr->var.m.receive] == 0
		    || maritime_supply[curr->var.m.supply] == 0)
			remove_quote(qv, curr);
	}

	/* Add all of the maritime trades that can be performed
	 */
	for (idx = 0; idx < NO_RESOURCE; idx++) {
		gint supply_idx;

		if (!qv->maritime_filter_receive[idx])
			continue;

		for (supply_idx = 0; supply_idx < NO_RESOURCE;
		     supply_idx++) {
			if (supply_idx == idx)
				continue;

			if (!maritime_supply[supply_idx])
				continue;

			if (resource_asset(supply_idx)
			    >= maritime_supply[supply_idx])
				add_maritime_trade(qv,
						   maritime_supply
						   [supply_idx], idx,
						   supply_idx);
		}
	}
}