2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2009, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * See files README, COPYING and CREDITS in the root of the source
23 * tree for related information and legal notices. It is expected
24 * that future projects/authors will amend these files as needed.
28 * login.c: Log into an empire server
30 * Known contributors to this file:
48 #define getpass ersatz_getpass
50 ersatz_getpass(char *prompt)
57 HANDLE input_handle = GetStdHandle(STD_INPUT_HANDLE);
59 if (GetConsoleMode(input_handle, &mode))
60 SetConsoleMode(input_handle, mode & ~ENABLE_ECHO_INPUT);
63 printf("Note: your input is echoed to the screen\n");
64 printf("Your name? ");
66 p = fgets(buf, sizeof(buf), stdin);
68 if (GetConsoleMode(input_handle, &mode))
69 SetConsoleMode(input_handle, mode | ENABLE_ECHO_INPUT);
74 if (p[len - 1] == '\n')
81 login(int s, char *uname, char *cname, char *cpass,
82 int kill_proc, int utf8)
90 if (!expect(s, C_INIT, buf))
92 sendcmd(s, "user", uname);
93 if (!expect(s, C_CMDOK, buf)) {
94 fprintf(stderr, "Server rejects your user name\n");
98 sendcmd(s, "options", "utf-8");
100 code = recvline(s, buf);
103 if (code != C_DATA) {
104 fprintf(stderr, "Server doesn't support UTF-8\n");
110 (void)printf("Country name? ");
112 cname = fgets(tmp, sizeof(tmp), stdin);
113 if (cname == NULL || *cname == 0)
117 if (cname[len-1] == '\n')
119 sendcmd(s, "coun", cname);
120 if (!expect(s, C_CMDOK, buf)) {
121 (void)fprintf(stderr, "No such country\n");
125 cpass = getpass("Your name? ");
126 if (cpass == NULL || *cpass == 0)
130 sendcmd(s, "pass", cpass);
131 memset(cpass, 0, strlen(cpass)); /* for core dumps */
132 if (!expect(s, C_CMDOK, buf)) {
133 (void)fprintf(stderr, "Bad password\n");
137 sendcmd(s, "kill", NULL);
138 (void)printf("\n\t-=O=-\n");
139 (void)expect(s, C_EXIT, buf);
140 fprintf(stderr, "%s\n", buf);
143 sendcmd(s, "play", NULL);
144 (void)printf("\n\t-=O=-\n");
145 if (!expect(s, C_INIT, buf)) {
146 fprintf(stderr, "%s\n", buf);
149 for (ptr = buf; !isspace(*ptr); ptr++) ;
151 p = strchr(ptr, '\n');
154 if (atoi(ptr) != CLIENTPROTO) {
155 printf("Empire client out of date; get new version!\n");
156 printf(" this version: %d, current version: %d\n",
157 CLIENTPROTO, atoi(ptr));