]> git.pond.sub.org Git - empserver/blobdiff - src/lib/commands/flash.c
(copy_ascii_no_funny, copy_utf8_no_funny)
[empserver] / src / lib / commands / flash.c
index 77cb6dae96694fe6e554ec8b94929b8767e52fb0..f7f37eb4349b0d869c3d108db7ffaaa375f152c7 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2000, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2005, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                           Ken Stevens, Steve McClure
  *
  *  This program is free software; you can redistribute it and/or modify
@@ -44,9 +44,9 @@ flash(void)
 {
     struct natstr *us;
     struct natstr *to;
-    s_char buf[1024];
+    char buf[1024];            /* UTF-8 */
     int tocn;
-    s_char *sp;
+    char *sp;                  /* points into player->combuf[], UTF-8 */
 
     us = getnatp(player->cnum);
     if ((tocn = natarg(player->argp[1], "to which country? ")) < 0)
@@ -76,11 +76,15 @@ flash(void)
     if (player->argp[2]) {
        for (sp = &player->combuf[0]; *sp && *sp != ' '; ++sp) ;
        for (++sp; *sp && *sp != ' '; ++sp) ;
-       sprintf(buf, ":%s", sp);
+       buf[0] = ':';
+       if (player->flags & PF_UTF8)
+           strcpy(buf+1, sp);
+       else
+           copy_utf8_to_ascii_no_funny(buf+1, sp);
        sendmessage(us, to, buf, 1);
     } else {
        sendmessage(us, to, "...", 1);
-       while (getstring("> ", buf)) {
+       while (ugetstring("> ", buf)) {
            if (*buf == '.')
                break;
            sendmessage(us, to, buf, 0);
@@ -94,17 +98,21 @@ int
 wall(void)
 {
     struct natstr *us;
-    s_char buf[1024];
-    s_char *sp;
+    char buf[1024];            /* UTF-8 */
+    char *sp;                  /* points into player->combuf[], UTF-8 */
 
     us = getnatp(player->cnum);
     if (player->argp[1]) {
        for (sp = &player->combuf[0]; *sp && *sp != ' '; ++sp) ;
-       sprintf(buf, ":%s", sp);
+       buf[0] = ':';
+       if (player->flags & PF_UTF8)
+           strcpy(buf+1, sp);
+       else
+           copy_utf8_to_ascii_no_funny(buf+1, sp);
        sendmessage(us, 0, buf, 1);
     } else {
        sendmessage(us, 0, "...", 1);
-       while (getstring("> ", buf)) {
+       while (ugetstring("> ", buf)) {
            if (*buf == '.')
                break;
            sendmessage(us, 0, buf, 0);
@@ -115,32 +123,27 @@ wall(void)
 }
 
 int
-sendmessage(struct natstr *us, struct natstr *to, char *message,
-           int oneshot)
+sendmessage(struct natstr *us, struct natstr *to, char *message
+           /* message is message text */, int oneshot)
 {
     struct player *other;
     struct tm *tm;
-    char *p;
-    char c;
     time_t now;
     int sent = 0;
     struct natstr *wto;
+    char c; /* c is message text */
+    int pos;
 
-    for (p = message; 0 != (c = *p); p++) {
-       if (!isprint(c))
-           *p = '*';
-    }
-    if (strlen(message) > 60) {
-       s_char c = message[60];
-       message[60] = '\0';
-       sendmessage(us, to, message, oneshot);
-       message[60] = c;
-       sendmessage(us, to, &message[60], 0);
-       return 0;
-    }
+    pos = ufindpfx(message, 60);
+    c = message[pos];
+    if (c)
+        message[pos] = '\0';
+    
     time(&now);
     tm = localtime(&now);
     for (other = player_next(0); other != 0; other = player_next(other)) {
+       if (other->state != PS_PLAYING)
+           continue;
        if (to && other->cnum != to->nat_cnum)
            continue;
        if (!(wto = getnatp(other->cnum)))
@@ -188,5 +191,9 @@ sendmessage(struct natstr *us, struct natstr *to, char *message,
                pr("%s is not accepting flashes\n", to->nat_cnam);
        }
     }
+    if (c) {
+       message[pos] = c;
+       sendmessage(us, to, &message[pos], 0);
+    }
     return 0;
 }