/** @copydoc popup_button::event_func */ static int popup_button_event_func(popup_button *button) { size_t len; (void) button; len = utarray_len(book_help_history); if (len >= 2) { size_t pos; char **p; pos = len - 2; p = (char **) utarray_eltptr(book_help_history, pos); if (p) { help_show(*p); utarray_erase(book_help_history, pos, 2); } } else { utarray_clear(book_help_history); help_show("main"); } return 1; }
static cb_ret_t help_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data) { WDialog *h = DIALOG (w); switch (msg) { case MSG_RESIZE: { WButtonBar *bb; help_lines = MIN (LINES - 4, MAX (2 * LINES / 3, 18)); dlg_set_size (h, help_lines + 4, HELP_WINDOW_WIDTH + 4); bb = find_buttonbar (h); widget_set_size (WIDGET (bb), LINES - 1, 0, 1, COLS); return MSG_HANDLED; } case MSG_DRAW: dlg_default_repaint (h); help_show (h, currentpoint); return MSG_HANDLED; case MSG_KEY: return help_handle_key (h, parm); case MSG_ACTION: /* Handle shortcuts and buttonbar. */ return help_execute_cmd (parm); default: return dlg_default_callback (w, sender, msg, parm, data); } }
/** @copydoc widgetdata::event_func */ static int widget_event(widgetdata *widget, SDL_Event *event) { uint32_t row, col; size_t i; if (EVENT_IS_MOUSE(event) && event->button.button == SDL_BUTTON_LEFT && list_mouse_get_pos(list_skills, event->motion.x, event->motion.y, &row, &col)) { size_t skill_id; skill_id = row * list_skills->cols + col; if (skill_id < skill_list_num) { if (event->type == SDL_MOUSEBUTTONUP) { if (selected_skill != skill_id) { selected_skill = skill_id; widget->redraw = 1; return 1; } } else if (event->type == SDL_MOUSEBUTTONDOWN) { event_dragging_start(skill_list[skill_id]->skill->tag, event->motion.x, event->motion.y); return 1; } } } /* If the list has handled the mouse event, we need to redraw the * widget. */ if (list_skills && list_handle_mouse(list_skills, event)) { widget->redraw = 1; return 1; } for (i = 0; i < BUTTON_NUM; i++) { if (button_event(&buttons[i], event)) { switch (i) { case BUTTON_CLOSE: widget->show = 0; break; case BUTTON_HELP: help_show("skill list"); break; } widget->redraw = 1; return 1; } if (buttons[i].redraw) { widget->redraw = 1; } } return 0; }
static cb_ret_t help_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data) { WDialog *h = DIALOG (w); switch (msg) { case MSG_RESIZE: { WButtonBar *bb; help_lines = min (LINES - 4, max (2 * LINES / 3, 18)); dlg_set_size (h, help_lines + 4, HELP_WINDOW_WIDTH + 4); bb = find_buttonbar (h); widget_set_size (WIDGET (bb), LINES - 1, 0, 1, COLS); return MSG_HANDLED; } case MSG_DRAW: dlg_default_repaint (h); help_show (h, currentpoint); return MSG_HANDLED; case MSG_KEY: return help_handle_key (h, parm); case MSG_ACTION: /* shortcut */ if (sender == NULL) return help_execute_cmd (parm); /* message from buttonbar */ if (sender == WIDGET (find_buttonbar (h))) { if (data != NULL) return send_message (data, NULL, MSG_ACTION, parm, NULL); return help_execute_cmd (parm); } return MSG_NOT_HANDLED; default: return dlg_default_callback (w, sender, msg, parm, data); } }
/** @copydoc widgetdata::event_func */ static int widget_event(widgetdata *widget, SDL_Event *event) { size_t i; if (list_mplayer) { if (list_handle_mouse(list_mplayer, event)) { widget->redraw = 1; return 1; } else if (scrollbar_event(&scrollbar_progress, event)) { widget->redraw = 1; return 1; } } for (i = 0; i < BUTTON_NUM; i++) { if (button_event(&buttons[i], event)) { switch (i) { case BUTTON_PLAY: if (sound_map_background(-1)) { sound_start_bg_music("no_music", 0, 0); sound_map_background(0); shuffle = 0; } else { list_handle_enter(list_mplayer, event); } break; case BUTTON_SHUFFLE: shuffle = !shuffle; if (shuffle) { mplayer_do_shuffle(list_mplayer); sound_map_background(1); } else { sound_start_bg_music("no_music", 0, 0); sound_map_background(0); } break; case BUTTON_BLACKLIST: /* Toggle the blacklist state of the selected row. */ mplayer_blacklist_toggle(list_mplayer); mplayer_blacklist_save(list_mplayer); break; case BUTTON_CLOSE: widget->show = 0; break; case BUTTON_HELP: help_show("music player"); break; } widget->redraw = 1; return 1; } if (buttons[i].redraw) { widget->redraw = 1; } } return 0; }
/** * Analyze /cmd type commands the player has typed in the console or bound to a * key. * Sort out the "client intern" commands and expand or pre process them for the * server. * @param cmd * Command to check * @return * 0 to send command to server, 1 to not send it */ int client_command_check(const char *cmd) { if (cmd_aliases_handle(cmd)) { return 1; } else if (strncasecmp(cmd, "/ready_spell", 12) == 0) { cmd = strchr(cmd, ' '); if (!cmd || *++cmd == '\0') { draw_info(COLOR_RED, "Usage: /ready_spell <spell name>"); return 1; } else { object *tmp; for (tmp = cpl.ob->inv; tmp; tmp = tmp->next) { if (tmp->itype == TYPE_SPELL && strncasecmp(tmp->s_name, cmd, strlen(cmd)) == 0) { if (!(tmp->flags & CS_FLAG_APPLIED)) { client_send_apply(tmp); } return 1; } } } draw_info(COLOR_RED, "Unknown spell."); return 1; } else if (strncasecmp(cmd, "/ready_skill", 12) == 0) { cmd = strchr(cmd, ' '); if (!cmd || *++cmd == '\0') { draw_info(COLOR_RED, "Usage: /ready_skill <skill name>"); return 1; } else { object *tmp; for (tmp = cpl.ob->inv; tmp; tmp = tmp->next) { if (tmp->itype == TYPE_SKILL && strncasecmp(tmp->s_name, cmd, strlen(cmd)) == 0) { if (!(tmp->flags & CS_FLAG_APPLIED)) { client_send_apply(tmp); } return 1; } } } draw_info(COLOR_RED, "Unknown skill."); return 1; } else if (!strncmp(cmd, "/help", 5)) { cmd += 5; if (*cmd == '\0') { help_show("main"); } else { help_show(cmd + 1); } return 1; } else if (!strncmp(cmd, "/resetwidgets", 13)) { widgets_reset(); return 1; } else if (!strncmp(cmd, "/effect ", 8)) { if (!strcmp(cmd + 8, "none")) { effect_stop(); draw_info(COLOR_GREEN, "Stopped effect."); return 1; } if (effect_start(cmd + 8)) { draw_info_format(COLOR_GREEN, "Started effect %s.", cmd + 8); } else { draw_info_format(COLOR_RED, "No such effect %s.", cmd + 8); } return 1; } else if (!strncmp(cmd, "/d_effect ", 10)) { effect_debug(cmd + 10); return 1; } else if (!strncmp(cmd, "/music_pause", 12)) { sound_pause_music(); return 1; } else if (!strncmp(cmd, "/music_resume", 13)) { sound_resume_music(); return 1; } else if (!strncmp(cmd, "/party joinpassword ", 20)) { cmd += 20; if (cpl.partyjoin[0] != '\0') { char buf[MAX_BUF]; snprintf(VS(buf), "/party join %s\t%s", cpl.partyjoin, cmd); send_command(buf); } return 1; } else if (!strncmp(cmd, "/invfilter ", 11)) { inventory_filter_set_names(cmd + 11); return 1; } else if (!strncasecmp(cmd, "/screenshot", 11)) { SDL_Surface *surface_save; cmd += 11; if (!strncasecmp(cmd, " map", 4)) { surface_save = cur_widget[MAP_ID]->surface; } else { surface_save = ScreenSurface; } if (!surface_save) { draw_info(COLOR_RED, "No surface to save."); return 1; } screenshot_create(surface_save); return 1; } else if (!strncasecmp(cmd, "/console-load ", 14)) { FILE *fp; char path[HUGE_BUF], buf[HUGE_BUF * 4], *cp; StringBuffer *sb; cmd += 14; snprintf(path, sizeof(path), "%s/.atrinik/console/%s", get_config_dir(), cmd); fp = fopen(path, "r"); if (!fp) { draw_info_format(COLOR_RED, "Could not read %s.", path); return 1; } send_command("/console noinf::"); while (fgets(buf, sizeof(buf) - 1, fp)) { cp = strchr(buf, '\n'); if (cp) { *cp = '\0'; } sb = stringbuffer_new(); stringbuffer_append_string(sb, "/console noinf::"); stringbuffer_append_string(sb, buf); cp = stringbuffer_finish(sb); send_command(cp); efree(cp); } send_command("/console noinf::"); fclose(fp); return 1; } else if (strncasecmp(cmd, "/console-obj", 11) == 0) { menu_inventory_loadtoconsole(cpl.inventory_focus, NULL, NULL); return 1; } else if (strncasecmp(cmd, "/patch-obj", 11) == 0) { menu_inventory_patch(cpl.inventory_focus, NULL, NULL); return 1; } else if (string_startswith(cmd, "/cast ") || string_startswith(cmd, "/use_skill ")) { object *tmp; uint8_t type; type = string_startswith(cmd, "/cast ") ? TYPE_SPELL : TYPE_SKILL; cmd = strchr(cmd, ' ') + 1; if (string_isempty(cmd)) { return 1; } for (tmp = cpl.ob->inv; tmp; tmp = tmp->next) { if (tmp->itype == type && strncasecmp(tmp->s_name, cmd, strlen(cmd)) == 0) { client_send_fire(5, tmp->tag); return 1; } } draw_info_format(COLOR_RED, "Unknown %s.", type == TYPE_SPELL ? "spell" : "skill"); return 1; } else if (strncasecmp(cmd, "/clearcache", 11) == 0) { cmd += 12; if (string_isempty(cmd)) { return 1; } if (strcasecmp(cmd, "sound") == 0) { sound_clear_cache(); draw_info(COLOR_GREEN, "Sound cache cleared."); } else if (strcasecmp(cmd, "textures") == 0) { texture_reload(); draw_info(COLOR_GREEN, "Textures reloaded."); } return 1; } else if (string_startswith(cmd, "/droptag ") || string_startswith(cmd, "/gettag ")) { char *cps[3]; unsigned long int loc, tag, num; if (string_split(strchr(cmd, ' ') + 1, cps, arraysize(cps), ' ') != arraysize(cps)) { return 1; } loc = strtoul(cps[0], NULL, 10); tag = strtoul(cps[1], NULL, 10); num = strtoul(cps[2], NULL, 10); client_send_move(loc, tag, num); if (string_startswith(cmd, "/gettag ")) { sound_play_effect("get.ogg", 100); } else { sound_play_effect("drop.ogg", 100); } return 1; } else if (string_startswith(cmd, "/talk")) { char type[MAX_BUF], npc_name[MAX_BUF]; size_t pos; uint8_t type_num; packet_struct *packet; pos = 5; if (!string_get_word(cmd, &pos, ' ', type, sizeof(type), 0) || string_isempty(cmd + pos)) { return 1; } type_num = atoi(type); if (type_num == CMD_TALK_NPC_NAME && (!string_get_word(cmd, &pos, ' ', npc_name, sizeof(npc_name), '"') || string_isempty(cmd + pos))) { return 1; } packet = packet_new(SERVER_CMD_TALK, 64, 64); packet_append_uint8(packet, type_num); if (type_num == CMD_TALK_NPC || type_num == CMD_TALK_NPC_NAME) { if (type_num == CMD_TALK_NPC_NAME) { packet_append_string_terminated(packet, npc_name); } packet_append_string_terminated(packet, cmd + pos); } else { char tag[MAX_BUF]; if (!string_get_word(cmd, &pos, ' ', tag, sizeof(tag), 0) || string_isempty(cmd + pos)) { packet_free(packet); return 1; } packet_append_uint32(packet, atoi(tag)); packet_append_string_terminated(packet, cmd + pos); } socket_send_packet(packet); return 1; } else if (string_startswith(cmd, "/widget_toggle")) { size_t pos; char word[MAX_BUF], *cps[2]; int widget_id; pos = 14; while (string_get_word(cmd, &pos, ' ', word, sizeof(word), 0)) { if (string_split(word, cps, arraysize(cps), ':') < 1) { continue; } widget_id = widget_id_from_name(cps[0]); /* Invalid widget ID */ if (widget_id == -1) { continue; } /* Redraw all or a specific one identified by its UID */ if (cps[1] == NULL) { WIDGET_SHOW_TOGGLE_ALL(widget_id); } else { widgetdata *widget; widget = widget_find(NULL, widget_id, cps[1], NULL); if (widget) { WIDGET_SHOW_TOGGLE(widget); } } } return 1; } else if (string_startswith(cmd, "/widget_focus")) { size_t pos; char word[MAX_BUF], *cps[2]; int widget_id; pos = 14; while (string_get_word(cmd, &pos, ' ', word, sizeof(word), 0)) { if (string_split(word, cps, arraysize(cps), ':') < 1) { continue; } widget_id = widget_id_from_name(cps[0]); if (widget_id == -1) { /* Invalid widget ID */ continue; } widget_switch_focus(widget_id, cps[1]); } return 1; } else if (string_startswith(cmd, "/ping")) { keepalive_ping_stats(); return 1; } else if (string_startswith(cmd, "/region_map")) { region_map_open(); return 1; } return 0; }
int show_ipv6(int argc, char **argv) { int i, j, k; char buf[128]; char buf6[INET6_ADDRSTRLEN + 1]; struct in6_addr ipaddr; struct in_addr in; int off1, off2, off3; int max6 = 0; int id = -1; printf("\n"); if (argc == 3) { if (!strncmp(argv[2], "all", strlen(argv[2]))) { for (i = 0; i < num_pths; i++) { if (vpc[i].ip6.ip.addr32[0] != 0 || vpc[i].ip6.ip.addr32[1] != 0 || vpc[i].ip6.ip.addr32[2] != 0 || vpc[i].ip6.ip.addr32[3] != 0) { memset(buf6, 0, INET6_ADDRSTRLEN + 1); memcpy(ipaddr.s6_addr, vpc[i].ip6.ip.addr8, 16); vinet_ntop6(AF_INET6, &ipaddr, buf6, INET6_ADDRSTRLEN + 1); j = sprintf(buf, "%s/%d", buf6, vpc[i].ip6.cidr); if (j > max6) max6 = j; } } memset(buf, 0, sizeof(buf)); memset(buf, ' ', sizeof(buf) - 1); off1 = 7; off2 = off1 + max6 + 2; off3 = off2 + 17 + 2; j = sprintf(buf, "NAME"); buf[j] = ' '; j = sprintf(buf + off1, "IP/MASK"); buf[j + off1] = ' '; j = sprintf(buf + off2, "ROUTER LINK-LAYER"); buf[j + off2] = ' '; j = sprintf(buf + off3, "MTU"); printf("%s\n", buf); for (i = 0; i < num_pths; i++) { memset(buf, 0, sizeof(buf)); memset(buf, ' ', sizeof(buf) - 1); if (strcmp(vpc[i].xname, "VPCS")== 0) j = sprintf(buf, "%s%d", vpc[i].xname, i + 1); else j = sprintf(buf, "%s", vpc[i].xname); buf[j] = ' '; memset(buf6, 0, INET6_ADDRSTRLEN + 1); memcpy(ipaddr.s6_addr, vpc[i].link6.ip.addr8, 16); vinet_ntop6(AF_INET6, &ipaddr, buf6, INET6_ADDRSTRLEN + 1); sprintf(buf + 7, "%s/%d", buf6, vpc[i].link6.cidr); j = printf("%s", buf); if (vpc[i].ip6.ip.addr32[0] != 0 || vpc[i].ip6.ip.addr32[1] != 0 || vpc[i].ip6.ip.addr32[2] != 0 || vpc[i].ip6.ip.addr32[3] != 0) { memset(buf6, 0, INET6_ADDRSTRLEN + 1); memcpy(ipaddr.s6_addr, vpc[i].ip6.ip.addr8, 16); vinet_ntop6(AF_INET6, &ipaddr, buf6, INET6_ADDRSTRLEN + 1); printf("\n"); for (k = 0; k < off1; k++) printf(" "); j = printf("%s/%d", buf6, vpc[i].ip6.cidr); j += off1; } for (k = j; k < off2; k++) printf(" "); if (etherIsZero(vpc[i].ip6.gmac)) { j = sprintf(buf, " "); } else { j = 0; for (k = 0; k < 6; k++) j += sprintf(buf + k * 3, "%2.2x:", vpc[i].ip6.gmac[k]); } buf[j - 1] = ' '; if (vpc[i].ip6.mtu) j += sprintf(buf + j, " %4.4d", vpc[i].ip6.mtu); else j += sprintf(buf + j, " "); //buf[j] = ' '; printf("%s\n", buf); } return 1; } if (strlen(argv[2]) == 1 && digitstring(argv[2])){ id = argv[2][0] - '1'; } } else if (argc == 2) id = pcid; if (id != -1) { printf("NAME : %s[%d]\n", vpc[id].xname, id + 1); printf("LINK-LOCAL SCOPE : "); memset(buf6, 0, INET6_ADDRSTRLEN + 1); memcpy(ipaddr.s6_addr, vpc[id].link6.ip.addr8, 16); vinet_ntop6(AF_INET6, &ipaddr, buf6, INET6_ADDRSTRLEN + 1); printf("%s/%d\n", buf6, vpc[id].link6.cidr); printf("GLOBAL SCOPE : "); if (vpc[id].ip6.ip.addr32[0] != 0 || vpc[id].ip6.ip.addr32[1] != 0 || vpc[id].ip6.ip.addr32[2] != 0 || vpc[id].ip6.ip.addr32[3] != 0) { memset(buf6, 0, INET6_ADDRSTRLEN + 1); memcpy(ipaddr.s6_addr, vpc[id].ip6.ip.addr8, 16); vinet_ntop6(AF_INET6, &ipaddr, buf6, INET6_ADDRSTRLEN + 1); printf("%s/%d", buf6, vpc[id].ip6.cidr); } printf("\n"); printf("ROUTER LINK-LAYER : "); if (!etherIsZero(vpc[id].ip6.gmac)) PRINT_MAC(vpc[id].ip6.gmac); printf("\n"); printf("MAC : "); PRINT_MAC(vpc[id].ip4.mac); printf("\n"); printf("LPORT : %d\n", vpc[id].lport); in.s_addr = vpc[id].rhost; printf("RHOST:PORT : %s:%d\n", inet_ntoa(in), vpc[id].rport); printf("MTU: : "); if (vpc[id].ip6.mtu) printf("%d", vpc[id].ip6.mtu); printf("\n"); return 1; } argv[argc - 1 ] = "?"; help_show(argc, argv); return 1; }
/** @copydoc widgetdata::event_func */ static int widget_event(widgetdata *widget, SDL_Event *event) { char buf[MAX_BUF]; size_t i; /* If the list has handled the mouse event, we need to redraw the * widget. */ if (list_party && list_handle_mouse(list_party, event)) { widget->redraw = 1; return 1; } for (i = 0; i < BUTTON_NUM; i++) { if ((cpl.partyname[0] == '\0' && (i == BUTTON_PASSWORD || i == BUTTON_LEAVE || i == BUTTON_CHAT || i == BUTTON_MEMBERS)) || (cpl.partyname[0] != '\0' && (i == BUTTON_FORM))) { continue; } if (button_event(&buttons[i], event)) { switch (i) { case BUTTON_PARTIES: send_command("/party list"); break; case BUTTON_MEMBERS: send_command("/party who"); break; case BUTTON_FORM: snprintf(buf, sizeof(buf), "?MCON /party form "); keybind_process_command(buf); break; case BUTTON_PASSWORD: snprintf(buf, sizeof(buf), "?MCON /party password "); keybind_process_command(buf); break; case BUTTON_LEAVE: send_command("/party leave"); break; case BUTTON_CHAT: snprintf(buf, sizeof(buf), "?MCON /gsay "); keybind_process_command(buf); break; case BUTTON_CLOSE: widget->show = 0; break; case BUTTON_HELP: help_show("spell list"); break; } widget->redraw = 1; return 1; } if (buttons[i].redraw) { widget->redraw = 1; } } return 0; }
/** * Handle event in the main screen. * @param event * The event to handle. * @return * 1 if the event was handled, 0 otherwise. */ int intro_event(SDL_Event *event) { if (!list_servers) { return 0; } if (event->type == SDL_MOUSEBUTTONDOWN && event->button.button == SDL_BUTTON_LEFT) { if (LIST_MOUSE_OVER(list_news, event->motion.x, event->motion.y)) { list_news->focus = 1; list_servers->focus = 0; } else if (LIST_MOUSE_OVER(list_servers, event->motion.x, event->motion.y)) { list_servers->focus = 1; list_news->focus = 0; } } if (button_event(&button_play, event)) { list_handle_enter(list_servers, event); return 1; } else if (button_event(&button_refresh, event)) { if (!ms_connecting(-1)) { cpl.state = ST_META; } return 1; } else if (button_event(&button_server, event)) { server_add_open(); return 1; } else if (button_event(&button_settings, event)) { settings_open(); return 1; } else if (button_event(&button_update, event)) { updater_open(); return 1; } else if (button_event(&button_help, event)) { help_show("main screen"); return 1; } else if (button_event(&button_credits, event)) { credits_show(); return 1; } else if (button_event(&button_quit, event)) { exit(0); return 1; } else if (event->type == SDL_KEYDOWN && event->key.keysym.sym == SDLK_TAB && list_news) { int news_focus = 0; if (list_servers->focus) { news_focus = 1; } list_news->focus = news_focus; list_servers->focus = !news_focus; } else if (list_handle_keyboard(list_news && list_news->focus ? list_news : list_servers, event)) { return 1; } else if (list_handle_mouse(list_news, event)) { return 1; } else if (list_handle_mouse(list_servers, event)) { return 1; } return 0; }