(player): New member flags.
(PF_UTF8, NF_UTF8): New PF_UTF8 replaces NF_UTF8. Users changed.
(options_cmd): New.
(login_coms): New command `options'.
(toggle): Revert to the previous rev.
#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_ */
int validated;
natid cnum;
int state;
+ int flags;
struct cmndstr *command;
struct iop *iop;
s_char combuf[1024];
#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
.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
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
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);
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);
name = "techlists";
flag = NF_TECHLISTS;
break;
- case 'u':
- name = "UTF-8";
- flag = NF_UTF8;
- break;
default:
return RET_SYN;
}
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;
#include "com.h"
#include "empthread.h"
#include "empio.h"
+#include "match.h"
#include "nsc.h"
#include "nat.h"
#include "optlist.h"
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)
{
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) {
}
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}
};
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);
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);
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;
/*
* 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);
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 = '?';
}
{
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)
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);