void mcpedit_program(int descr, dbref player, dbref prog, const char *name, McpFrame *mfr) { char namestr[BUFFER_LEN]; char refstr[BUFFER_LEN]; struct line *curr; McpMesg msg; McpVer supp; supp = mcp_frame_package_supported(mfr, "dns-org-mud-moo-simpleedit"); if (supp.verminor == 0 && supp.vermajor == 0) { do_prog(descr, player, name); return; } FLAGS(prog) |= INTERNAL; snprintf(refstr, sizeof(refstr), "%d.prog.", prog); snprintf(namestr, sizeof(namestr), "a program named %s(%d)", NAME(prog), prog); mcp_mesg_init(&msg, "dns-org-mud-moo-simpleedit", "content"); mcp_mesg_arg_append(&msg, "reference", refstr); mcp_mesg_arg_append(&msg, "type", "muf-code"); mcp_mesg_arg_append(&msg, "name", namestr); for (curr = DBFETCH(prog)->sp.program.first; curr; curr = curr->next) mcp_mesg_arg_append(&msg, "content", DoNull(curr->this_line)); mcp_frame_output_mesg(mfr, &msg); mcp_mesg_clear(&msg); free_prog_text(DBFETCH(prog)->sp.program.first); DBFETCH(prog)->sp.program.first = NULL; }
McpVer GuiVersion(int descr) { McpVer supp = { 0, 0 }; McpFrame *mfr; mfr = descr_mcpframe(descr); if (mfr) { supp = mcp_frame_package_supported(mfr, GUI_PACKAGE); } return supp; }
int GuiSupported(int descr) { McpVer supp; McpFrame *mfr; mfr = descr_mcpframe(descr); if (mfr) { supp = mcp_frame_package_supported(mfr, GUI_PACKAGE); if (supp.verminor != 0 || supp.vermajor != 0) { return 1; } } return 0; }
int mcp_frame_output_mesg(McpFrame * mfr, McpMesg * msg) { char outbuf[BUFFER_LEN * 2]; int bufrem = sizeof(outbuf); char mesgname[128]; char datatag[32]; McpArg *anarg = NULL; int mlineflag = 0; char *p; char *out; int flushcount = 8; if (!mfr->enabled && strcmp_nocase(msg->package, MCP_INIT_PKG)) { return EMCP_NOMCP; } /* Create the message name from the package and message subnames */ if (msg->mesgname && *msg->mesgname) { snprintf(mesgname, sizeof(mesgname), "%s-%s", msg->package, msg->mesgname); } else { snprintf(mesgname, sizeof(mesgname), "%s", msg->package); } strcpyn(outbuf, sizeof(outbuf), MCP_MESG_PREFIX); strcatn(outbuf, sizeof(outbuf), mesgname); if (strcmp_nocase(mesgname, MCP_INIT_PKG)) { McpVer nullver = { 0, 0 }; strcatn(outbuf, sizeof(outbuf), " "); strcatn(outbuf, sizeof(outbuf), mfr->authkey); if (strcmp_nocase(msg->package, MCP_NEGOTIATE_PKG)) { McpVer ver = mcp_frame_package_supported(mfr, msg->package); if (!mcp_version_compare(ver, nullver)) { return EMCP_NOPACKAGE; } } } /* If the argument lines contain newlines, split them into separate lines. */ for (anarg = msg->args; anarg; anarg = anarg->next) { if (anarg->value) { McpArgPart *ap = anarg->value; while (ap) { p = ap->value; while (*p) { if (*p == '\n' || *p == '\r') { McpArgPart *nu = (McpArgPart *) malloc(sizeof(McpArgPart)); nu->next = ap->next; ap->next = nu; *p++ = '\0'; nu->value = string_dup(p); ap->value = (char *) realloc(ap->value, strlen(ap->value) + 1); ap = nu; p = nu->value; } else { p++; } } ap = ap->next; } } } /* Build the initial message string */ out = outbuf; bufrem = outbuf + sizeof(outbuf) - out; for (anarg = msg->args; anarg; anarg = anarg->next) { out += strlen(out); bufrem = outbuf + sizeof(outbuf) - out; if (!anarg->value) { anarg->was_shown = 1; snprintf(out, bufrem, " %s: %s", anarg->name, MCP_ARG_EMPTY); out += strlen(out); bufrem = outbuf + sizeof(outbuf) - out; } else { int totlen = strlen(anarg->value->value) + strlen(anarg->name) + 5; if (anarg->value->next || totlen > ((BUFFER_LEN - (out - outbuf)) / 2)) { /* Value is multi-line or too long. Send on separate line(s). */ mlineflag = 1; anarg->was_shown = 0; snprintf(out, bufrem, " %s*: %s", anarg->name, MCP_ARG_EMPTY); } else { anarg->was_shown = 1; snprintf(out, bufrem, " %s: ", anarg->name); out += strlen(out); bufrem = outbuf + sizeof(outbuf) - out; msgarg_escape(out, bufrem, anarg->value->value); out += strlen(out); bufrem = outbuf + sizeof(outbuf) - out; } out += strlen(out); bufrem = outbuf + sizeof(outbuf) - out; } } /* If the message is multi-line, make sure it has a _data-tag field. */ if (mlineflag) { snprintf(datatag, sizeof(datatag), "%.8lX", (unsigned long)(RANDOM() ^ RANDOM())); snprintf(out, bufrem, " %s: %s", MCP_DATATAG, datatag); out += strlen(out); bufrem = outbuf + sizeof(outbuf) - out; } /* Send the initial line. */ SendText(mfr, outbuf); SendText(mfr, "\r\n"); if (mlineflag) { /* Start sending arguments whose values weren't already sent. */ /* This is usually just multi-line argument values. */ for (anarg = msg->args; anarg; anarg = anarg->next) { if (!anarg->was_shown) { McpArgPart *ap = anarg->value; while (ap) { *outbuf = '\0'; snprintf(outbuf, sizeof(outbuf), "%s* %s %s: %s", MCP_MESG_PREFIX, datatag, anarg->name, ap->value); SendText(mfr, outbuf); SendText(mfr, "\r\n"); if (!--flushcount) { FlushText(mfr); flushcount = 8; } ap = ap->next; } } } /* Let the other side know we're done sending multi-line arg vals. */ snprintf(outbuf, sizeof(outbuf), "%s: %s", MCP_MESG_PREFIX, datatag); SendText(mfr, outbuf); SendText(mfr, "\r\n"); } return EMCP_SUCCESS; }
void mcppkg_help_request(McpFrame * mfr, McpMesg * msg, McpVer ver, void *context) { FILE *f; const char* file; char buf[BUFFER_LEN]; char topic[BUFFER_LEN]; char *p; int arglen, found; McpVer supp = mcp_frame_package_supported(mfr, "org-fuzzball-help"); McpMesg omsg; if (supp.verminor == 0 && supp.vermajor == 0) { notify(mcpframe_to_user(mfr), "MCP: org-fuzzball-help not supported."); return; } if (!string_compare(msg->mesgname, "request")) { char *onwhat; char *valtype; onwhat = mcp_mesg_arg_getline(msg, "topic", 0); valtype = mcp_mesg_arg_getline(msg, "type", 0); *topic = '\0'; strcpyn(topic, sizeof(topic), onwhat); if (*onwhat) { strcatn(topic, sizeof(topic), "|"); } if (!string_compare(valtype, "man")) { file = MAN_FILE; } else if (!string_compare(valtype, "mpi")) { file = MPI_FILE; } else if (!string_compare(valtype, "help")) { file = HELP_FILE; } else if (!string_compare(valtype, "news")) { file = NEWS_FILE; } else { snprintf(buf, sizeof(buf), "Sorry, %s is not a valid help type.", valtype); mcp_mesg_init(&omsg, "org-fuzzball-help", "error"); mcp_mesg_arg_append(&omsg, "text", buf); mcp_mesg_arg_append(&omsg, "topic", onwhat); mcp_frame_output_mesg(mfr, &omsg); mcp_mesg_clear(&omsg); return; } if ((f = fopen(file, "rb")) == NULL) { snprintf(buf, sizeof(buf), "Sorry, %s is missing. Management has been notified.", file); fprintf(stderr, "help: No file %s!\n", file); mcp_mesg_init(&omsg, "org-fuzzball-help", "error"); mcp_mesg_arg_append(&omsg, "text", buf); mcp_mesg_arg_append(&omsg, "topic", onwhat); mcp_frame_output_mesg(mfr, &omsg); mcp_mesg_clear(&omsg); } else { if (*topic) { arglen = strlen(topic); do { do { if (!(fgets(buf, sizeof buf, f))) { snprintf(buf, sizeof(buf), "Sorry, no help available on topic \"%s\"", onwhat); fclose(f); mcp_mesg_init(&omsg, "org-fuzzball-help", "error"); mcp_mesg_arg_append(&omsg, "text", buf); mcp_mesg_arg_append(&omsg, "topic", onwhat); mcp_frame_output_mesg(mfr, &omsg); mcp_mesg_clear(&omsg); return; } } while (*buf != '~'); do { if (!(fgets(buf, sizeof buf, f))) { snprintf(buf, sizeof(buf), "Sorry, no help available on topic \"%s\"", onwhat); fclose(f); mcp_mesg_init(&omsg, "org-fuzzball-help", "error"); mcp_mesg_arg_append(&omsg, "text", buf); mcp_mesg_arg_append(&omsg, "topic", onwhat); mcp_frame_output_mesg(mfr, &omsg); mcp_mesg_clear(&omsg); return; } } while (*buf == '~'); p = buf; found = 0; buf[strlen(buf) - 1] = '|'; while (*p && !found) { if (strncasecmp(p, topic, arglen)) { while (*p && (*p != '|')) p++; if (*p) p++; } else { found = 1; } } } while (!found); } mcp_mesg_init(&omsg, "org-fuzzball-help", "entry"); mcp_mesg_arg_append(&omsg, "topic", onwhat); while (fgets(buf, sizeof buf, f)) { if (*buf == '~') break; for (p = buf; *p; p++) { if (*p == '\n' || *p == '\r') { *p = '\0'; break; } } if (!*buf) { strcpyn(buf, sizeof(buf), " "); } mcp_mesg_arg_append(&omsg, "text", buf); } fclose(f); mcp_frame_output_mesg(mfr, &omsg); mcp_mesg_clear(&omsg); } } }