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:
parent
976cdfbf9e
commit
baf416652a
7 changed files with 68 additions and 43 deletions
|
@ -172,7 +172,5 @@ extern void agecontact(struct natstr *np);
|
||||||
#define NF_SONAR bit(4) /* Turn auto-sonar on */
|
#define NF_SONAR bit(4) /* Turn auto-sonar on */
|
||||||
#define NF_TECHLISTS bit(5) /* Sort lists by tech not type */
|
#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_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_ */
|
#endif /* _NAT_H_ */
|
||||||
|
|
|
@ -54,6 +54,7 @@ struct player {
|
||||||
int validated;
|
int validated;
|
||||||
natid cnum;
|
natid cnum;
|
||||||
int state;
|
int state;
|
||||||
|
int flags;
|
||||||
struct cmndstr *command;
|
struct cmndstr *command;
|
||||||
struct iop *iop;
|
struct iop *iop;
|
||||||
s_char combuf[1024];
|
s_char combuf[1024];
|
||||||
|
@ -85,6 +86,11 @@ struct player {
|
||||||
#define PS_SHUTDOWN 3
|
#define PS_SHUTDOWN 3
|
||||||
#define PS_KILL 4
|
#define PS_KILL 4
|
||||||
|
|
||||||
|
/* player flags */
|
||||||
|
enum {
|
||||||
|
PF_UTF8 = bit(0) /* client wants UTF-8 */
|
||||||
|
};
|
||||||
|
|
||||||
/* thread priorities */
|
/* thread priorities */
|
||||||
#define PP_UPDATE 6
|
#define PP_UPDATE 6
|
||||||
#define PP_SHUTDOWN 5
|
#define PP_SHUTDOWN 5
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
.TH Command TOGGLE
|
.TH Command TOGGLE
|
||||||
.NA toggle "Toggle client flags"
|
.NA toggle "Toggle client flags"
|
||||||
.LV Expert
|
.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
|
You use the toggle command to set various user-interface flags for
|
||||||
your country. The server will remember which flags you have set
|
your country. The server will remember which flags you have set
|
||||||
between sessions. If you do not specify the second argument ("on" or
|
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
|
techlists is on, when you do a "show" command, the lists shows will be
|
||||||
in order of tech instead of grouping order.
|
in order of tech instead of grouping order.
|
||||||
.s1
|
.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"
|
.EX "toggle"
|
||||||
Will list all your flags and show whether they are on or off.
|
Will list all your flags and show whether they are on or off.
|
||||||
.s1
|
.s1
|
||||||
|
|
|
@ -84,7 +84,7 @@ flash(void)
|
||||||
if ((*sp >= 0x0 && *sp < 0x20 && *sp != '\t') ||
|
if ((*sp >= 0x0 && *sp < 0x20 && *sp != '\t') ||
|
||||||
*sp == 0x7f)
|
*sp == 0x7f)
|
||||||
*sp = '?';
|
*sp = '?';
|
||||||
else if (!(us->nat_flags & NF_UTF8) && (*sp & 0x80))
|
else if (!(player->flags & PF_UTF8) && (*sp & 0x80))
|
||||||
*sp = '?';
|
*sp = '?';
|
||||||
}
|
}
|
||||||
sendmessage(us, to, buf, 1);
|
sendmessage(us, to, buf, 1);
|
||||||
|
@ -115,7 +115,7 @@ wall(void)
|
||||||
if ((*sp >= 0x0 && *sp < 0x20 && *sp != '\t') ||
|
if ((*sp >= 0x0 && *sp < 0x20 && *sp != '\t') ||
|
||||||
*sp == 0x7f)
|
*sp == 0x7f)
|
||||||
*sp = '?';
|
*sp = '?';
|
||||||
else if (!(us->nat_flags & NF_UTF8) && (*sp & 0x80))
|
else if (!(player->flags & PF_UTF8) && (*sp & 0x80))
|
||||||
*sp = '?';
|
*sp = '?';
|
||||||
}
|
}
|
||||||
sendmessage(us, 0, buf, 1);
|
sendmessage(us, 0, buf, 1);
|
||||||
|
|
|
@ -73,10 +73,6 @@ togg(void)
|
||||||
name = "techlists";
|
name = "techlists";
|
||||||
flag = NF_TECHLISTS;
|
flag = NF_TECHLISTS;
|
||||||
break;
|
break;
|
||||||
case 'u':
|
|
||||||
name = "UTF-8";
|
|
||||||
flag = NF_UTF8;
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
return RET_SYN;
|
return RET_SYN;
|
||||||
}
|
}
|
||||||
|
@ -120,10 +116,6 @@ togg(void)
|
||||||
pr("techlists flag on\n");
|
pr("techlists flag on\n");
|
||||||
else
|
else
|
||||||
pr("techlists flag off\n");
|
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;
|
return RET_OK;
|
||||||
|
|
|
@ -40,6 +40,7 @@
|
||||||
#include "com.h"
|
#include "com.h"
|
||||||
#include "empthread.h"
|
#include "empthread.h"
|
||||||
#include "empio.h"
|
#include "empio.h"
|
||||||
|
#include "match.h"
|
||||||
#include "nsc.h"
|
#include "nsc.h"
|
||||||
#include "nat.h"
|
#include "nat.h"
|
||||||
#include "optlist.h"
|
#include "optlist.h"
|
||||||
|
@ -206,6 +207,51 @@ pass_cmd(void)
|
||||||
return RET_OK;
|
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
|
static int
|
||||||
play_cmd(void)
|
play_cmd(void)
|
||||||
{
|
{
|
||||||
|
@ -223,7 +269,7 @@ play_cmd(void)
|
||||||
if (*++ap) {
|
if (*++ap) {
|
||||||
if (natbyname(*ap, &cnum) < 0) {
|
if (natbyname(*ap, &cnum) < 0) {
|
||||||
pr_id(player, C_CMDERR, "country %s does not exist\n", *ap);
|
pr_id(player, C_CMDERR, "country %s does not exist\n", *ap);
|
||||||
return 0;
|
return RET_FAIL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (*++ap) {
|
if (*++ap) {
|
||||||
|
@ -310,14 +356,15 @@ quit_cmd(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
struct cmndstr login_coms[] = {
|
struct cmndstr login_coms[] = {
|
||||||
{"list", 0, list_cmd, 0, 0},
|
|
||||||
{"client clientname [version info]", 0, client_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},
|
{"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},
|
{"pass password", 0, pass_cmd, 0, 0},
|
||||||
{"play [user country pass]", 0, play_cmd, 0, 0},
|
{"play [user country pass]", 0, play_cmd, 0, 0},
|
||||||
{"quit ", 0, quit_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}
|
{0, 0, 0, 0, 0}
|
||||||
};
|
};
|
||||||
|
|
|
@ -61,14 +61,13 @@ static void outid(struct player *pl, int n);
|
||||||
void
|
void
|
||||||
pr(char *format, ...)
|
pr(char *format, ...)
|
||||||
{
|
{
|
||||||
struct natstr *np = getnatp(player->cnum);
|
|
||||||
char buf[4096];
|
char buf[4096];
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
||||||
va_start(ap, format);
|
va_start(ap, format);
|
||||||
(void)vsprintf(buf, format, ap);
|
(void)vsprintf(buf, format, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
if (np->nat_flags & NF_UTF8)
|
if (player->flags & PF_UTF8)
|
||||||
upr_player(player, C_DATA, buf);
|
upr_player(player, C_DATA, buf);
|
||||||
else
|
else
|
||||||
pr_player(player, C_DATA, buf);
|
pr_player(player, C_DATA, buf);
|
||||||
|
@ -77,12 +76,10 @@ pr(char *format, ...)
|
||||||
void
|
void
|
||||||
uprnf(char *buf /* buf is message text */)
|
uprnf(char *buf /* buf is message text */)
|
||||||
{
|
{
|
||||||
struct natstr *np = getnatp(player->cnum);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Translate to ASCII if the client is not in UTF mode
|
* Translate to ASCII if the client is not in UTF mode
|
||||||
*/
|
*/
|
||||||
if (!(np->nat_flags & NF_UTF8))
|
if (!(player->flags & PF_UTF8))
|
||||||
prtoascii(buf);
|
prtoascii(buf);
|
||||||
|
|
||||||
pr_player(player, C_DATA, buf);
|
pr_player(player, C_DATA, buf);
|
||||||
|
@ -109,7 +106,6 @@ void
|
||||||
pr_flash(struct player *pl, char *format
|
pr_flash(struct player *pl, char *format
|
||||||
/* format is message text */, ...)
|
/* format is message text */, ...)
|
||||||
{
|
{
|
||||||
struct natstr *np = getnatp(pl->cnum);
|
|
||||||
char buf[4096]; /* buf is message text */
|
char buf[4096]; /* buf is message text */
|
||||||
va_list ap;
|
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
|
* Translate to ASCII if the client is not in UTF mode
|
||||||
*/
|
*/
|
||||||
if (!(np->nat_flags & NF_UTF8))
|
if (!(pl->flags & PF_UTF8))
|
||||||
prtoascii(buf);
|
prtoascii(buf);
|
||||||
pr_player(pl, C_FLASH, buf);
|
pr_player(pl, C_FLASH, buf);
|
||||||
io_output(pl->iop, IO_NOWAIT);
|
io_output(pl->iop, IO_NOWAIT);
|
||||||
|
@ -332,7 +328,6 @@ uprmptrd(char *prompt, char *str /* str is message text */, int size)
|
||||||
{
|
{
|
||||||
int r;
|
int r;
|
||||||
char *cp; /* cp is message text */
|
char *cp; /* cp is message text */
|
||||||
struct natstr *np = getnatp(player->cnum);
|
|
||||||
|
|
||||||
pr_id(player, C_FLUSH, "%s\n", prompt);
|
pr_id(player, C_FLUSH, "%s\n", prompt);
|
||||||
if ((r = recvclient(str, size)) < 0)
|
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') ||
|
if ((*cp >= 0x0 && *cp < 0x20 && *cp != '\t') ||
|
||||||
*cp == 0x7f)
|
*cp == 0x7f)
|
||||||
*cp = '?';
|
*cp = '?';
|
||||||
else if (!(np->nat_flags & NF_UTF8) && (*cp & 0x80))
|
else if (!(player->flags & PF_UTF8) && (*cp & 0x80))
|
||||||
*cp = '?';
|
*cp = '?';
|
||||||
}
|
}
|
||||||
return strlen(str);
|
return strlen(str);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue