]> git.pond.sub.org Git - empserver/blobdiff - src/client/login.c
COPYING duplicates information from README. Remove. Move GPL from
[empserver] / src / client / login.c
index 2c0257c8341e4663fa2b145a3c4e33b707a22597..e88f6d57a86d057bfdc5242c95fc45a99f6505da 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2004, 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
@@ -19,9 +19,9 @@
  *
  *  ---
  *
- *  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.
  *
  *  ---
  *
@@ -32,6 +32,8 @@
  *     Steve McClure, 1998
  */
 
+#include <config.h>
+
 #include "misc.h"
 #include "proto.h"
 
 #endif
 
 int
-login(int s, char *uname, char *cname, char *cpass, int kill_proc)
+login(int s, char *uname, char *cname, char *cpass, int kill_proc, int utf8)
 {
     char tmp[128];
     char buf[1024];
     char *ptr;
     char *p;
-    int len;
+    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 (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 == NULL || *cname == 0)
            return 0;
@@ -66,9 +83,9 @@ login(int s, char *uname, char *cname, char *cpass, int kill_proc)
     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 == NULL) {
@@ -79,6 +96,7 @@ login(int s, char *uname, char *cname, char *cpass, int kill_proc)
 #else
        printf("Note: This is echoed to the screen\n");
        printf("Your name? ");
+       fflush(stdout);
        cpass = fgets(tmp, sizeof(tmp), stdin);
        if (cpass == NULL || *cpass == 0)
            return 0;
@@ -88,20 +106,20 @@ login(int s, char *uname, char *cname, char *cpass, int kill_proc)
 #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, NULL);
+       (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, NULL);
+    (void)sendcmd(s, "play", NULL);
     (void)printf("\n\t-=O=-\n");
     if (!expect(s, C_INIT, buf)) {
        fprintf(stderr, "%s\n", buf);
@@ -117,5 +135,6 @@ login(int s, char *uname, char *cname, char *cpass, int kill_proc)
        printf("   this version: %d, current version: %d\n",
               CLIENTPROTO, atoi(ptr));
     }
+    fflush(stdout);
     return 1;
 }