Login options.

(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.
This commit is contained in:
Markus Armbruster 2005-05-27 16:31:19 +00:00
parent 976cdfbf9e
commit baf416652a
7 changed files with 68 additions and 43 deletions

View file

@ -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_ */

View file

@ -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

View file

@ -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

View file

@ -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);

View file

@ -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;

View file

@ -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},
{"sanc", 0, sanc_cmd, 0, 0},
{"user username", 0, user_cmd, 0, 0},
{0, 0, 0, 0, 0}
};

View file

@ -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);
@ -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)
@ -345,7 +340,7 @@ uprmptrd(char *prompt, char *str /* str is message text */, int size)
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);