struct nh_cmd_desc *nhnet_get_object_commands(int *count, char invlet) { int i, defkey, altkey; json_t *jmsg, *jarr, *jobj; struct nh_cmd_desc *cmdlist = NULL; const char *name, *desc; if (!nhnet_active()) return nh_get_object_commands(count, invlet); if (!api_entry()) return 0; jmsg = json_pack("{si}", "invlet", invlet); jmsg = send_receive_msg("get_obj_commands", jmsg); if (json_unpack(jmsg, "{so!}", "cmdlist", &jarr) == -1 || !json_is_array(jarr)) { print_error("Incorrect return object in nhnet_get_object_commands"); } else { *count = json_array_size(jarr); cmdlist = xmalloc(*count * sizeof(struct nh_cmd_desc)); for (i = 0; i < *count; i++) { jobj = json_array_get(jarr, i); json_unpack(jobj, "{ss,ss,si,si,si!}", "name", &name, "desc", &desc, "def", &defkey, "alt", &altkey, "flags", &cmdlist[i].flags); strcpy(cmdlist[i].name, name); strcpy(cmdlist[i].desc, desc); cmdlist[i].defkey = defkey; cmdlist[i].altkey = altkey; } } json_decref(jmsg); api_exit(); return cmdlist; }
static void ccmd_get_obj_commands(json_t * params) { int invlet, cmdcount, i; json_t *jarr, *jobj; struct nh_cmd_desc *cmdlist; if (json_unpack(params, "{si*}", "invlet", &invlet) == -1) exit_client("Bad parameters for get_obj_commands"); cmdlist = nh_get_object_commands(&cmdcount, invlet); jarr = json_array(); for (i = 0; i < cmdcount; i++) { jobj = json_pack("{ss,ss,si,si,si}", "name", cmdlist[i].name, "desc", cmdlist[i].desc, "def", cmdlist[i].defkey, "alt", cmdlist[i].altkey, "flags", cmdlist[i].flags); json_array_append_new(jarr, jobj); } client_msg("get_obj_commands", json_pack("{so}", "cmdlist", jarr)); }