(chat): New, factored out of flash() and wall().

(flash, wall): Use it.
This commit is contained in:
Markus Armbruster 2007-11-25 14:34:50 +00:00
parent 566223c36b
commit a34a5fd23c

View file

@ -38,6 +38,7 @@
#include "commands.h" #include "commands.h"
static int chat(struct natstr *, struct natstr *, char *);
static int sendmessage(struct natstr *, struct natstr *, char *, int); static int sendmessage(struct natstr *, struct natstr *, char *, int);
int int
@ -45,7 +46,6 @@ flash(void)
{ {
struct natstr *us; struct natstr *us;
struct natstr *to; struct natstr *to;
char buf[1024]; /* UTF-8 */
int tocn; int tocn;
us = getnatp(player->cnum); us = getnatp(player->cnum);
@ -69,10 +69,30 @@ flash(void)
} }
} }
if (player->comtail[2]) { return chat(us, to, player->comtail[2]);
}
int
wall(void)
{
return chat(getnatp(player->cnum), NULL, player->comtail[1]);
}
/*
* Send flash message(s) from US to TO.
* Null TO broadcasts to all.
* MESSAGE is UTF-8. If it is null, prompt for messages interactively.
* Return RET_OK.
*/
static int
chat(struct natstr *us, struct natstr *to, char *message)
{
char buf[1024]; /* UTF-8 */
if (message) {
buf[0] = ':'; buf[0] = ':';
buf[1] = ' '; buf[1] = ' ';
strcpy(buf+2, player->comtail[2]); strcpy(buf+2, message);
sendmessage(us, to, buf, 1); sendmessage(us, to, buf, 1);
} else { } else {
sendmessage(us, to, "...", 1); sendmessage(us, to, "...", 1);
@ -86,30 +106,6 @@ flash(void)
return RET_OK; return RET_OK;
} }
int
wall(void)
{
struct natstr *us;
char buf[1024]; /* UTF-8 */
us = getnatp(player->cnum);
if (player->comtail[1]) {
buf[0] = ':';
buf[1] = ' ';
strcpy(buf+2, player->comtail[1]);
sendmessage(us, 0, buf, 1);
} else {
sendmessage(us, 0, "...", 1);
while (ugetstring("> ", buf)) {
if (*buf == '.')
break;
sendmessage(us, 0, buf, 0);
}
sendmessage(us, 0, "<EOT>", 0);
}
return RET_OK;
}
/* /*
* Send flash message MESSAGE from US to TO. * Send flash message MESSAGE from US to TO.
* MESSAGE is UTF-8. * MESSAGE is UTF-8.