/*
* Empire - A multi-player, client/server Internet based war game.
- * Copyright (C) 1986-2000, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ * Copyright (C) 1986-2006, Dave Pare, Jeff Bailey, Thomas Ruschak,
* Ken Stevens, Steve McClure
*
* This program is free software; you can redistribute it and/or modify
*
* ---
*
- * See the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
- * related information and legal notices. It is expected that any future
- * projects/authors will amend these files as needed.
+ * See files README, COPYING and CREDITS in the root of the source
+ * tree for related information and legal notices. It is expected
+ * that future projects/authors will amend these files as needed.
*
* ---
*
* Steve McClure, 1998
*/
+#include <config.h>
+
#include "misc.h"
#include "proto.h"
#include <ctype.h>
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#if !defined(_WIN32)
#include <unistd.h>
#endif
-int expect();
-int atoi();
-void sendcmd();
-
int
-login(s, uname, cname, cpass, kill_proc)
-int s;
-s_char *uname;
-s_char *cname;
-s_char *cpass;
-int kill_proc;
+login(int s, char *uname, char *cname, char *cpass, int kill_proc, int utf8)
{
- s_char tmp[128];
- s_char buf[1024];
- s_char *ptr;
- s_char *p;
- int len;
+ char tmp[128];
+ char buf[1024];
+ char *ptr;
+ char *p;
+ int len, code;
if (!expect(s, C_INIT, buf))
return 0;
- (void)sendcmd(s, USER, uname);
- if (!expect(s, C_CMDOK, buf))
+ (void)sendcmd(s, "user", uname);
+ if (!expect(s, C_CMDOK, buf)) {
+ fprintf(stderr, "Server rejects your user name\n");
return 0;
- if (cname == 0) {
+ }
+ if (utf8) {
+ sendcmd(s, "options", "utf-8");
+ for (;;) {
+ code = recvline(s, buf);
+ if (code == C_CMDOK)
+ break;
+ if (code != C_DATA) {
+ fprintf(stderr, "Server doesn't support UTF-8\n");
+ return 0;
+ }
+ }
+ }
+ if (cname == NULL) {
(void)printf("Country name? ");
+ fflush(stdout);
cname = fgets(tmp, sizeof(tmp), stdin);
- if (cname == 0 || *cname == 0)
+ if (cname == NULL || *cname == 0)
return 0;
}
len = strlen(cname);
if (cname[len-1] == '\n')
cname[len-1] = 0;
- (void)sendcmd(s, COUN, cname);
+ (void)sendcmd(s, "coun", cname);
if (!expect(s, C_CMDOK, buf)) {
- (void)fprintf(stderr, "empire: no such country\n");
+ (void)fprintf(stderr, "No such country\n");
return 0;
}
- if (cpass == 0) {
+ if (cpass == NULL) {
#ifndef _WIN32
- cpass = (s_char *)getpass("Your name? ");
- if (cpass == 0 || *cpass == 0)
+ cpass = getpass("Your name? ");
+ if (cpass == NULL || *cpass == 0)
return 0;
#else
printf("Note: This is echoed to the screen\n");
printf("Your name? ");
+ fflush(stdout);
cpass = fgets(tmp, sizeof(tmp), stdin);
- if (cpass == 0 || *cpass == 0)
+ if (cpass == NULL || *cpass == 0)
return 0;
len = strlen(cpass);
if (cname[len-1] == '\n')
#endif
}
(void)printf("\n");
- (void)sendcmd(s, PASS, cpass);
+ (void)sendcmd(s, "pass", cpass);
memset(cpass, 0, strlen(cpass)); /* for core dumps */
if (!expect(s, C_CMDOK, buf)) {
(void)fprintf(stderr, "Bad password\n");
return 0;
}
if (kill_proc) {
- (void)sendcmd(s, KILL, (s_char *)0);
+ (void)sendcmd(s, "kill", NULL);
(void)printf("\n\t-=O=-\n");
(void)expect(s, C_EXIT, buf);
fprintf(stderr, "%s\n", buf);
return 0;
}
- (void)sendcmd(s, PLAY, (s_char *)0);
+ (void)sendcmd(s, "play", NULL);
(void)printf("\n\t-=O=-\n");
if (!expect(s, C_INIT, buf)) {
fprintf(stderr, "%s\n", buf);
for (ptr = buf; !isspace(*ptr); ptr++) ;
ptr++;
p = strchr(ptr, '\n');
- if (p != 0)
+ if (p != NULL)
*p = 0;
if (atoi(ptr) != CLIENTPROTO) {
printf("Empire client out of date; get new version!\n");
printf(" this version: %d, current version: %d\n",
CLIENTPROTO, atoi(ptr));
}
+ fflush(stdout);
return 1;
}