Date: Saturday August 23, 2003 @ 1:14 Author: cameron Update of /home/netrek/cvsroot/Vanilla/ntserv In directory swashbuckler.real-time.com:/var/tmp/cvs-serv28837/ntserv Modified Files: Makefile.in getname.c main.c ntscmds.c util.c Log Message: Makefile.in mods for GNU standards **************************************** Index: Vanilla/ntserv/Makefile.in diff -u Vanilla/ntserv/Makefile.in:1.3 Vanilla/ntserv/Makefile.in:1.4 --- Vanilla/ntserv/Makefile.in:1.3 Tue May 1 21:00:19 2001 +++ Vanilla/ntserv/Makefile.in Sat Aug 23 01:14:19 2003 @@ -101,12 +101,12 @@ install: ntserv daemonII - at if [ ! -d $(LIBDIR) ]; then \ - $(INSTALL) -d $(LIBDIR); \ + $(INSTALL) -d $(DESTDIR)$(LIBDIR); \ fi - $(INSTALLPROG) $(INSTALLOPTS) ntserv $(LIBDIR)/ntserv - $(INSTALLPROG) $(INSTALLOPTS) daemonII $(LIBDIR)/daemonII - touch $(LIBDIR)/.planets - chmod 600 $(LIBDIR)/.planets + $(INSTALLPROG) $(INSTALLOPTS) ntserv $(DESTDIR)$(LIBDIR)/ntserv + $(INSTALLPROG) $(INSTALLOPTS) daemonII $(DESTDIR)$(LIBDIR)/daemonII + touch $(DESTDIR)$(LIBDIR)/.planets + chmod 600 $(DESTDIR)$(LIBDIR)/.planets installbin: install echo "target installbin deprecated, assumed install" Index: Vanilla/ntserv/getname.c diff -u Vanilla/ntserv/getname.c:1.12 Vanilla/ntserv/getname.c:1.13 --- Vanilla/ntserv/getname.c:1.12 Mon Nov 25 00:05:03 2002 +++ Vanilla/ntserv/getname.c Sat Aug 23 01:14:19 2003 @@ -32,8 +32,11 @@ /* file scope prototypes */ static void handleLogin(void); static int lockout(void); -static void savepass(const struct statentry *); +#ifdef REGISTERED_USERS +char *registered_users_name; +char *registered_users_pass; +#endif void getname(void) /* Let person identify themselves from w */ @@ -65,16 +68,22 @@ readFromClient(); } + /* + ERROR(8,("handleLogin: %s %s %s\n", + passPick[15] == 0 ? "attempt" : "query", namePick, passPick)); + */ + if ((strcmp(namePick, "Guest")==0 || strcmp(namePick, "guest")==0) && !lockout()) { + handlelogin_guest: /* all INL games prohibit guest login */ if (status->gameup & GU_INROBOT) { sendClientLogin(NULL); flushSockBuf(); return; } - /* but we don't check for existing players on INL robot entry */ + /* todo: we don't check for existing players on INL robot entry */ hourratio=5; MZERO(&player.stats, sizeof(struct stats)); @@ -124,31 +133,7 @@ /* We look for the guy in the stat file */ if (strcmp(player.name, namePick) != 0) { - for (;;) { /* so I can use break; */ - plfd = open(PlayerFile, O_RDONLY, 0644); - if (plfd < 0) { - ERROR(1,("I cannot open the player file!\n")); - strcpy(player.name, namePick); - position= -1; - ERROR(1,("Error number: %d\n", errno)); - break; - } - /* sequential search of player file */ - position=0; - while (read(plfd, (char *) &player, sizeof(struct statentry)) == - sizeof(struct statentry)) { - if (strcmp(namePick, player.name)==0) { - close(plfd); - break; - } - position++; - } - if (strcmp(namePick, player.name)==0) break; - close(plfd); - position= -1; - strcpy(player.name, namePick); - break; - } + position = findplayer(namePick, &player); } /* Was this just a query? */ @@ -160,7 +145,23 @@ } flushSockBuf(); return; - } + } + +#ifdef REGISTERED_USERS + /* record the username they wanted, but if we don't have it in the + score file, force them to be a guest */ + registered_users_name = strdup(namePick); + registered_users_pass = strdup(passPick); + if (position == -1) { + /* ERROR(8,("handleLogin: unregistered %s\n", namePick)); */ + strcpy(namePick, "guest"); + goto handlelogin_guest; + } + /* ERROR(8,("handleLogin: registered %s\n", namePick)); */ + /* todo: tell this user when they log in to try registering */ + /* todo: turn off certain privs if guest, e.g. eject voting */ + /* todo: replicate code below in the registration response program */ +#endif /* A new guy? */ if ((position== -1) && !lockout()) { @@ -182,24 +183,18 @@ /* race condition: Two new players joining at once * can screw up the database. */ - plfd = open(PlayerFile, O_RDWR|O_CREAT, 0644); - if (plfd < 0) { - sendClientLogin(NULL); + if (entries = newplayer(&player) < 0) { + sendClientLogin(NULL); } else { - if ((file_pos = lseek(plfd, 0, SEEK_END)) < 0) { - sendClientLogin(NULL); - } - write(plfd, (char *) &player, sizeof(struct statentry)); - close(plfd); - entries = file_pos / sizeof(struct statentry); - me->p_pos = entries; - MCOPY(&player.stats, &(me->p_stats), sizeof(struct stats)); - strcpy(me->p_name, namePick); - sendClientLogin(&player.stats); + me->p_pos = entries; + MCOPY(&player.stats, &(me->p_stats), sizeof(struct stats)); + strcpy(me->p_name, namePick); + sendClientLogin(&player.stats); } flushSockBuf(); return; } + /* An actual login attempt */ strcpy(newpass, (char *) crypt(passPick, salt(player.name, sb))); if (lockout() || @@ -207,8 +202,10 @@ !streq(player.password, (char *) crypt(passPick, player.password)))) { sendClientLogin(NULL); flushSockBuf(); + /* ERROR(8,("handleLogin: password-failure namePick=%s passPick=%s file=%s newstyle=%s oldstyle=%s\n", namePick, passPick, player.password, newpass, (char *) crypt(passPick, player.password))); */ return; } + /* ERROR(8,("handleLogin: password-success namePick=%s passPick=%s file=%s newstyle=%s oldstyle=%s\n", namePick, passPick, player.password, newpass, (char *) crypt(passPick, player.password))); */ sendClientLogin(&player.stats); strcpy(me->p_name, namePick); me->p_pos=position; @@ -220,49 +217,6 @@ } flushSockBuf(); return; -} - -void changepassword (char *passPick) -{ - saltbuf sb; - struct statentry se; - strcpy(se.password, (char *) crypt(passPick, salt(me->p_name, sb))); - savepass(&se); -} - -static void savepass(const struct statentry* se) -{ - int fd; - if (me->p_pos < 0) return; - printf("getname.c: updating password for %s\n", se->name); - fd = open(PlayerFile, O_WRONLY, 0644); - if (fd >= 0) { - lseek(fd, me->p_pos * sizeof(struct statentry) + - offsetof(struct statentry, password), SEEK_SET); - write(fd, &se->password, sizeof(se->password)); - close(fd); - } -} - -void savestats(void) -{ - int fd; - - if (me->p_pos < 0) return; - -#ifdef OBSERVERS - /* Do not save stats for observers. This is corrupting the DB. -da */ - if (Observer) return; -#endif - - fd = open(PlayerFile, O_WRONLY, 0644); - if (fd >= 0) { - me->p_stats.st_lastlogin = time(NULL); - lseek(fd, me->p_pos * sizeof(struct statentry) + - offsetof(struct statentry, stats), SEEK_SET); - write(fd, (char *) &me->p_stats, sizeof(struct stats)); - close(fd); - } } /* return true if we want a lockout */ Index: Vanilla/ntserv/main.c diff -u Vanilla/ntserv/main.c:1.26 Vanilla/ntserv/main.c:1.27 --- Vanilla/ntserv/main.c:1.26 Fri Feb 21 02:41:17 2003 +++ Vanilla/ntserv/main.c Sat Aug 23 01:14:19 2003 @@ -285,8 +285,9 @@ logEntry(); /* moved down to get login/monitor 2/12/92 TMC */ #ifdef NO_HOSTNAMES - me->p_full_hostname[0] = '\0'; - me->p_monitor[0] = '\0'; + strcpy(me->p_full_hostname, "hidden"); + strcpy(me->p_monitor, "hidden"); + strcpy(me->p_login, "anonymous"); #endif #ifdef PING /* 0 might just be legit for a local player */ Index: Vanilla/ntserv/ntscmds.c diff -u Vanilla/ntserv/ntscmds.c:1.26 Vanilla/ntserv/ntscmds.c:1.27 --- Vanilla/ntserv/ntscmds.c:1.26 Mon Nov 25 00:05:03 2002 +++ Vanilla/ntserv/ntscmds.c Sat Aug 23 01:14:19 2003 @@ -1,4 +1,4 @@ -/* $Id: ntscmds.c,v 1.26 2002/11/25 06:05:03 cameron Exp $ +/* $Id: ntscmds.c,v 1.27 2003/08/23 06:14:19 cameron Exp $ */ /* @@ -56,6 +56,9 @@ void do_nodock(char *comm, struct message *mess); void do_transwarp(char *comm, struct message *mess); void do_admin(char *comm, struct message *mess); +#ifdef REGISTERED_USERS +void do_register(char *comm, struct message *mess); +#endif const char myname[] = {"GOD"}; @@ -117,6 +120,12 @@ C_PR_INPICKUP, "Administration commands for privileged users", do_admin }, /* ADMIN */ +#ifdef REGISTERED_USERS + { "REGISTER", + C_PR_INPICKUP, + "Register your character, e.g. 'register you at example.com'", + do_register }, /* ADMIN */ +#endif #ifdef NODOCK { "DOCK", C_PR_INPICKUP, @@ -653,14 +662,19 @@ int j; for (j=0; j < count; j++) { +#ifdef NO_HOSTNAMES + char *them = "hidden"; +#else + char *them = waiting[k].host; +#endif int m = find_slot_by_host(waiting[k].host, 0); if (m != -1) { struct player *p = &players[m]; pmessage(who, MINDIV, addr, "Q%d: (aka %s %s) %s", - j, p->p_mapchars, p->p_name, waiting[k].host); + j, p->p_mapchars, p->p_name, them); } else { pmessage(who, MINDIV, addr, "Q%d: %s", - j, waiting[k].host); + j, them); } k = waiting[k].next; } @@ -1364,3 +1378,76 @@ pmessage(who, MINDIV, addr, "admin: what? kill/quit/ban/reset, lowercase"); } } + +#ifdef REGISTERED_USERS +void do_register(char *comm, struct message *mess) +{ + int who = mess->m_from; + struct player *p = &players[who]; + char *addr = addr_mess(who,MINDIV); + extern char *registered_users_name, *registered_users_pass; + char *one, *two, filename[64], command[128]; + FILE *file; + int status; + + if (strchr(registered_users_name, '\t') != NULL) { + pmessage(who, MINDIV, addr, "Registration refused for character names containing tabs."); + return; + } + + if (strchr(registered_users_pass, '\t') != NULL) { + pmessage(who, MINDIV, addr, "Registration refused for passwords containing tabs."); + return; + } + + if (strchr(host, '\t') != NULL) { + pmessage(who, MINDIV, addr, "Registration refused for hosts containing tabs."); + return; + } + + /* register */ + one = strtok(comm, " "); + if (one == NULL) return; + + /* address */ + two = strtok(NULL, " "); + if (two == NULL) { + pmessage(who, MINDIV, addr, "Try again, type your e-mail address after the word REGISTER"); + return; + } + + if (strchr(two, '@') == NULL) { + pmessage(who, MINDIV, addr, "That doesn't look like an e-mail address!"); + return; + } + + if (strchr(two, '\t') != NULL) { + pmessage(who, MINDIV, addr, "Registration refused for e-mail addresses containing a tab."); + return; + } + + sprintf(filename, "user-requests/%d", p->p_no); + file = fopen(filename, "a"); + if (file == NULL) { + pmessage(who, MINDIV, addr, "Registration refused."); + return; + } + + fprintf(file, "%s\t%s\t%s\t%s\t%s\n", + (!strcmp(p->p_name, "guest")) ? "add" : "change", + host, registered_users_name, registered_users_pass, two); + if (fclose(file) != 0) { + pmessage(who, MINDIV, addr, "Registration could not be recorded."); + return; + } + + sprintf(command, "tools/register %s", filename); + status = system(command); + if (status != 0) { + pmessage(who, MINDIV, addr, "Registration could not be processed."); + return; + } + + pmessage(who, MINDIV, addr, "Registration recorded, expect an e-mail."); +} +#endif Index: Vanilla/ntserv/util.c diff -u Vanilla/ntserv/util.c:1.5 Vanilla/ntserv/util.c:1.6 --- Vanilla/ntserv/util.c:1.5 Tue May 21 01:17:28 2002 +++ Vanilla/ntserv/util.c Sat Aug 23 01:14:19 2003 @@ -137,4 +137,3 @@ #endif return -1; } - _______________________________________________ vanilla-devel mailing list vanilla-devel at us.netrek.org https://mailman.real-time.com/mailman/listinfo/vanilla-devel