static void NETWORK_on_received(DictionaryIterator *iter, void *context) { int rval = 0; struct NetworkState *state = context; abort_if(!state, "state is null"); Tuple *tuple = dict_find(iter, 0); abort_if(!tuple, "tuple is null"); char *action = tuple->value->cstring; log_debug("<-- %s", action); if(strcmp(action, "COUNT") == 0) { rval = process_count(iter, state); abort_if(rval, "process_count failed"); } else if(strcmp(action, "HABIT") == 0) { rval = process_habit(iter, state); abort_if(rval, "process_habit failed"); } else if(strcmp(action, "OK") == 0) { rval = process_ok(state); abort_if(rval, "process_ok failed"); } CLEANUP: return; }
/* ======================================= */ static gint key_press(guint keyval, gchar *commit_str, gchar *preedit_str) { if(!gcomprisBoard) return FALSE; /* Add some filter for control and shift key */ switch (keyval) { /* Avoid all this keys to be interpreted by this game */ case GDK_Shift_L: case GDK_Shift_R: case GDK_Control_L: case GDK_Control_R: case GDK_Caps_Lock: case GDK_Shift_Lock: case GDK_Meta_L: case GDK_Meta_R: case GDK_Alt_L: case GDK_Alt_R: case GDK_Super_L: case GDK_Super_R: case GDK_Hyper_L: case GDK_Hyper_R: case GDK_Num_Lock: return FALSE; case GDK_KP_Enter: case GDK_Return: process_ok(); return TRUE; case GDK_Right: case GDK_Left: break; case GDK_BackSpace: if(answer_string) g_string_truncate(answer_string, answer_string->len -1); break; } if(answer_string) { gchar *tmpstr; gchar c = commit_str ? commit_str[0] : 0; /* Limit the user entry to 5 digits */ if(c>='0' && c<='9' && answer_string->len < 5) answer_string = g_string_append_c(answer_string, c); if (board_mode == MODE_WEIGHT) tmpstr = g_strdup_printf(_("Weight in g = %s"), answer_string->str); else tmpstr = g_strdup_printf(_("Weight = %s"), answer_string->str); g_object_set(answer_item, "text", tmpstr, NULL); g_free(tmpstr); } return TRUE; }
/* ==================================== */ static gint item_event(GooCanvasItem *item, GooCanvasItem *target, GdkEvent *event, gpointer data) { if(board_paused) return FALSE; gchar *answer = g_utf8_strdown ( (gchar*)data , -1 ); switch (event->type) { case GDK_BUTTON_PRESS: /* We really don't want the user to change his/her mind */ board_paused = TRUE; if ( strcmp(answer, right_letter) == 0 ) { gamewon = TRUE; } else { gamewon = FALSE; } highlight_selected(item); process_ok(); break; default: break; } g_free(answer); return FALSE; }
/* ==================================== */ static gboolean item_event (GooCanvasItem *item, GooCanvasItem *target, GdkEventButton *event, gpointer data) { gint button_id = GPOINTER_TO_INT(data); GooCanvasItem *button; if(board_paused) return FALSE; switch (event->type) { case GDK_BUTTON_PRESS: board_paused = TRUE; if ( button_id == right_word ) gamewon = TRUE; else gamewon = FALSE; button = (GooCanvasItem*)g_object_get_data(G_OBJECT(goo_canvas_item_get_parent(item)), "button"); highlight_selected(button); process_ok(); break; default: break; } return FALSE; }
void ftp_rsauser(t_client *client, char *str) { char *arg; char filename[4096]; char trame[4096]; unsigned char encrypted[4096]; unsigned char *randstr; int len; arg = get_cmd(str, 7); if (atoi(client->server->conf->ssl_enabled) == 0 || atoi(client->server->conf->ssl_fconnect) == 0) return (ssl_not_actived(client)); sprintf(filename, "/etc/bertomzilla/.rsa/%s.pub", arg); if (!fill_publicKeyFromScratch(client, filename)) return (show_error("Error while filling RSA File")); randstr = randstring(16); len = public_encrypt(randstr, 16, client->publicKeyRSA, encrypted); post(trame, len, client, encrypted); if (!strncmp(trame, (const char*) randstr, 16)) process_ok(client, arg); else write(client->fd, "KO\r\n", 4); }
static gint key_press(guint keyval, gchar *commit_str, gchar *preedit_str) { gint length_passed, i; if(!gcomprisBoard) return FALSE; /* i suppose even numbers are passed through IM_context */ if ((commit_str == NULL) && (preedit_str == NULL)) return FALSE; gchar *string_passed; if (commit_str) string_passed = commit_str; else string_passed = preedit_str; length_passed = g_utf8_strlen(string_passed, -1); for (i=0; i < length_passed; i++){ gunichar ckey = \ g_unichar_tolower( g_utf8_get_char (string_passed) ); gunichar cright = \ g_unichar_tolower( g_utf8_get_char (right_letter) ); if (ckey == cright){ gamewon = TRUE; process_ok(); gc_im_reset(); return TRUE; } string_passed = g_utf8_next_char (string_passed); } return TRUE; }
void scale_anim_plate(void) { double delta_y; double angle; double scale; int diff; // in MODE_WEIGHT the granularity is gramm, so we use a different factor scale = (board_mode == MODE_WEIGHT) ? 2000.0 : 10.0; diff = get_weight_plate(0); delta_y = CLAMP(PLATE_Y_DELTA / scale * diff, -PLATE_Y_DELTA, PLATE_Y_DELTA); if(get_weight_plate(1) == 0) delta_y = -PLATE_Y_DELTA; /* Update the sign */ if (diff == 0) g_object_set(sign, "text", "=", NULL); else if (diff < 0) g_object_set(sign, "text", "<", NULL); else g_object_set(sign, "text", ">", NULL); if(last_delta != delta_y) { goo_canvas_item_translate(group_g, 0, -last_delta); goo_canvas_item_translate(group_d, 0, last_delta); last_delta = delta_y; angle = tan(delta_y / 138) * 180 / M_PI; goo_canvas_item_translate(group_g, 0, delta_y); goo_canvas_item_translate(group_d, 0, -delta_y); gc_item_rotate_with_center(bras, -angle, 138, 84); } if(diff == 0 && ask_for_answer) { double x_offset = BOARDWIDTH/2; double y_offset = BOARDHEIGHT*0.7; GooCanvasItem *item = goo_canvas_svg_new (boardRootItem, gc_skin_rsvg_get(), "svg-id", "#BUTTON_TEXT", NULL); SET_ITEM_LOCATION_CENTER(item, x_offset / 2, y_offset); goo_canvas_item_scale(item, 2, 1); answer_item = goo_canvas_text_new(boardRootItem, "", x_offset, y_offset, -1, GTK_ANCHOR_CENTER, "font", gc_skin_font_board_title_bold, "fill-color", "white", NULL); answer_string = g_string_new(NULL); key_press(0, NULL, NULL); } else if(diff == 0) process_ok(); }
/* ======================================= */ static gint key_press(guint keyval, gchar *commit_str, gchar *preedit_str) { guint c; if(!gcomprisBoard || gamewon == TRUE) return FALSE; /* Add some filter for control and shift key */ switch (keyval) { /* Avoid all this keys to be interpreted by this game */ case GDK_Shift_L: case GDK_Shift_R: case GDK_Control_L: case GDK_Control_R: case GDK_Caps_Lock: case GDK_Shift_Lock: case GDK_Meta_L: case GDK_Meta_R: case GDK_Alt_L: case GDK_Alt_R: case GDK_Super_L: case GDK_Super_R: case GDK_Hyper_L: case GDK_Hyper_R: case GDK_Num_Lock: return FALSE; case GDK_KP_Enter: case GDK_Return: process_ok(); return TRUE; case GDK_Right: case GDK_Left: break; case GDK_BackSpace: if(answer_string_index>0) { answer_string_index--; answer_string[answer_string_index] = 0; } break; } c = tolower(keyval); /* Limit the user entry to 5 digits */ if(c>='0' && c<='9' && answer_string_index<5) { answer_string[answer_string_index++] = c; answer_string[answer_string_index] = 0; } if(answer_item) { gchar *tmpstr = g_strdup_printf(_("Points = %s"), answer_string); g_object_set(answer_item, "text", tmpstr, NULL); g_free(tmpstr); process_ok(); } return TRUE; }