diff --git a/include/nat.h b/include/nat.h index 72663f89..2d638777 100644 --- a/include/nat.h +++ b/include/nat.h @@ -172,7 +172,5 @@ extern void agecontact(struct natstr *np); #define NF_SONAR bit(4) /* Turn auto-sonar on */ #define NF_TECHLISTS bit(5) /* Sort lists by tech not type */ #define NF_SACKED bit(6) /* Capital was sacked, and hasn't been reset yet */ -#define NF_UTF8 bit(7) /* Whether the client accepts UTF-8 (true) or - ASCII only (false) */ #endif /* _NAT_H_ */ diff --git a/include/player.h b/include/player.h index 8f378aec..21c06d49 100644 --- a/include/player.h +++ b/include/player.h @@ -54,6 +54,7 @@ struct player { int validated; natid cnum; int state; + int flags; struct cmndstr *command; struct iop *iop; s_char combuf[1024]; @@ -85,6 +86,11 @@ struct player { #define PS_SHUTDOWN 3 #define PS_KILL 4 +/* player flags */ +enum { + PF_UTF8 = bit(0) /* client wants UTF-8 */ +}; + /* thread priorities */ #define PP_UPDATE 6 #define PP_SHUTDOWN 5 diff --git a/info/Commands/toggle.t b/info/Commands/toggle.t index 594afcec..616bc649 100644 --- a/info/Commands/toggle.t +++ b/info/Commands/toggle.t @@ -1,7 +1,7 @@ .TH Command TOGGLE .NA toggle "Toggle client flags" .LV Expert -.SY "toggle [inform|flash|beep|coastwatch|sonar|techlists|utf8] [on|off]" +.SY "toggle [inform|flash|beep|coastwatch|sonar|techlists] [on|off]" You use the toggle command to set various user-interface flags for your country. The server will remember which flags you have set between sessions. If you do not specify the second argument ("on" or @@ -39,19 +39,6 @@ Will toggle the "techlists" flag (default off) for your country. When techlists is on, when you do a "show" command, the lists shows will be in order of tech instead of grouping order. .s1 -.EX "toggle utf8" -Will toggle the "utf8" flag (default off) for your country. -When utf8 is on, you can use multiple langauges in your user communication. -To use this feature, the client must support the unicode character set -and must encode unicode characters using the UTF8 format -when sending the characters to the server and must decode -the UTF8 characters into -unicode characters when receiving characters from the server. -Also both the sending and receiving clients must support -unicode in order to communicate using unicode characters. -This feature applies to the follow commands: -wire, read, announcement, flash, telegram and turn. -.s1 .EX "toggle" Will list all your flags and show whether they are on or off. .s1 diff --git a/src/lib/commands/flash.c b/src/lib/commands/flash.c index 46bd6f8a..5043e674 100644 --- a/src/lib/commands/flash.c +++ b/src/lib/commands/flash.c @@ -84,7 +84,7 @@ flash(void) if ((*sp >= 0x0 && *sp < 0x20 && *sp != '\t') || *sp == 0x7f) *sp = '?'; - else if (!(us->nat_flags & NF_UTF8) && (*sp & 0x80)) + else if (!(player->flags & PF_UTF8) && (*sp & 0x80)) *sp = '?'; } sendmessage(us, to, buf, 1); @@ -115,7 +115,7 @@ wall(void) if ((*sp >= 0x0 && *sp < 0x20 && *sp != '\t') || *sp == 0x7f) *sp = '?'; - else if (!(us->nat_flags & NF_UTF8) && (*sp & 0x80)) + else if (!(player->flags & PF_UTF8) && (*sp & 0x80)) *sp = '?'; } sendmessage(us, 0, buf, 1); diff --git a/src/lib/commands/togg.c b/src/lib/commands/togg.c index 7230db92..ab5a0ec5 100644 --- a/src/lib/commands/togg.c +++ b/src/lib/commands/togg.c @@ -73,10 +73,6 @@ togg(void) name = "techlists"; flag = NF_TECHLISTS; break; - case 'u': - name = "UTF-8"; - flag = NF_UTF8; - break; default: return RET_SYN; } @@ -120,10 +116,6 @@ togg(void) pr("techlists flag on\n"); else pr("techlists flag off\n"); - if (np->nat_flags & NF_UTF8) - pr("UTF-8 flag on\n"); - else - pr("UTF-8 flag off\n"); } return RET_OK; diff --git a/src/lib/player/login.c b/src/lib/player/login.c index 2ecb0777..8e07ffa3 100644 --- a/src/lib/player/login.c +++ b/src/lib/player/login.c @@ -40,6 +40,7 @@ #include "com.h" #include "empthread.h" #include "empio.h" +#include "match.h" #include "nsc.h" #include "nat.h" #include "optlist.h" @@ -206,6 +207,51 @@ pass_cmd(void) return RET_OK; } +static int +options_cmd(void) +{ + /* + * The login option mechanism allows arbitrary string values, but + * so far all options are flags in struct player. Should be easy + * to generalize if needed. + */ + struct logoptstr { + char *name; + int val; + }; + static struct logoptstr login_opts[] = { + { "utf-8", PF_UTF8 } + }; + char **ap; + char *p; + int opt; + + for (ap = player->argp+1; *ap; ++ap) { + p = strchr(*ap, '='); + if (p) + *p++ = 0; + opt = stmtch(*ap, login_opts, + offsetof(struct logoptstr, name), + sizeof(struct logoptstr)); + if (opt < 0) { + pr_id(player, C_BADCMD, "Option %s not found\n", *ap); + return RET_FAIL; + } + if (!p || atoi(p)) + player->flags |= login_opts[opt].val; + else + player->flags &= ~login_opts[opt].val; + } + + for (opt = 0; opt < sizeof(login_opts) / sizeof(*login_opts); ++opt) + pr_id(player, C_DATA, "%s=%d", + login_opts[opt].name, + (player->flags & login_opts[opt].val) != 0); + pr_id(player, C_CMDOK, "Options okay\n"); + + return RET_OK; +} + static int play_cmd(void) { @@ -223,7 +269,7 @@ play_cmd(void) if (*++ap) { if (natbyname(*ap, &cnum) < 0) { pr_id(player, C_CMDERR, "country %s does not exist\n", *ap); - return 0; + return RET_FAIL; } } if (*++ap) { @@ -310,14 +356,15 @@ quit_cmd(void) } struct cmndstr login_coms[] = { - {"list", 0, list_cmd, 0, 0}, {"client clientname [version info]", 0, client_cmd, 0, 0}, - {"user username", 0, user_cmd, 0, 0}, - {"sanc", 0, sanc_cmd, 0, 0}, {"coun countryname", 0, coun_cmd, 0, 0}, + {"kill", 0, kill_cmd, 0, 0}, + {"list", 0, list_cmd, 0, 0}, + {"options", 0, options_cmd, 0, 0}, {"pass password", 0, pass_cmd, 0, 0}, {"play [user country pass]", 0, play_cmd, 0, 0}, - {"quit ", 0, quit_cmd, 0, 0}, - {"kill {self}", 0, kill_cmd, 0, 0}, + {"quit", 0, quit_cmd, 0, 0}, + {"sanc", 0, sanc_cmd, 0, 0}, + {"user username", 0, user_cmd, 0, 0}, {0, 0, 0, 0, 0} }; diff --git a/src/lib/subs/pr.c b/src/lib/subs/pr.c index c7a2a689..8ea260c6 100644 --- a/src/lib/subs/pr.c +++ b/src/lib/subs/pr.c @@ -61,14 +61,13 @@ static void outid(struct player *pl, int n); void pr(char *format, ...) { - struct natstr *np = getnatp(player->cnum); char buf[4096]; va_list ap; va_start(ap, format); (void)vsprintf(buf, format, ap); va_end(ap); - if (np->nat_flags & NF_UTF8) + if (player->flags & PF_UTF8) upr_player(player, C_DATA, buf); else pr_player(player, C_DATA, buf); @@ -77,12 +76,10 @@ pr(char *format, ...) void uprnf(char *buf /* buf is message text */) { - struct natstr *np = getnatp(player->cnum); - /* * Translate to ASCII if the client is not in UTF mode */ - if (!(np->nat_flags & NF_UTF8)) + if (!(player->flags & PF_UTF8)) prtoascii(buf); pr_player(player, C_DATA, buf); @@ -109,7 +106,6 @@ void pr_flash(struct player *pl, char *format /* format is message text */, ...) { - struct natstr *np = getnatp(pl->cnum); char buf[4096]; /* buf is message text */ va_list ap; @@ -121,7 +117,7 @@ pr_flash(struct player *pl, char *format /* * Translate to ASCII if the client is not in UTF mode */ - if (!(np->nat_flags & NF_UTF8)) + if (!(pl->flags & PF_UTF8)) prtoascii(buf); pr_player(pl, C_FLASH, buf); io_output(pl->iop, IO_NOWAIT); @@ -320,7 +316,7 @@ prmptrd(char *prompt, char *str, int size) if (*str == 0) return 1; for(cp = str; 0 != *cp; ++cp) { - if ((*cp >= 0x0 && *cp < 0x20 && *cp != '\t') || + if ((*cp >= 0x0 && *cp < 0x20 && *cp != '\t') || *cp == 0x7f || *cp & 0x80) *cp = '?'; } @@ -332,7 +328,6 @@ uprmptrd(char *prompt, char *str /* str is message text */, int size) { int r; char *cp; /* cp is message text */ - struct natstr *np = getnatp(player->cnum); pr_id(player, C_FLUSH, "%s\n", prompt); if ((r = recvclient(str, size)) < 0) @@ -342,10 +337,10 @@ uprmptrd(char *prompt, char *str /* str is message text */, int size) return 1; for(cp = str; 0 != *cp; ++cp) { - if ((*cp >= 0x0 && *cp < 0x20 && *cp != '\t') || + if ((*cp >= 0x0 && *cp < 0x20 && *cp != '\t') || *cp == 0x7f) *cp = '?'; - else if (!(np->nat_flags & NF_UTF8) && (*cp & 0x80)) + else if (!(player->flags & PF_UTF8) && (*cp & 0x80)) *cp = '?'; } return strlen(str);