annotate src/getname.c @ 8:0836fb919dfa

First entry of Paradise Server 2.9 patch 10 Beta
author darius
date Sat, 06 Dec 1997 04:37:05 +0000
parents aa38447a4b21
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
1 /*--------------------------------------------------------------------------
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
2 NETREK II -- Paradise
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
3
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
4 Permission to use, copy, modify, and distribute this software and its
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
5 documentation, or any derivative works thereof, for any NON-COMMERCIAL
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
6 purpose and without fee is hereby granted, provided that this copyright
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
7 notice appear in all copies. No representations are made about the
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
8 suitability of this software for any purpose. This software is provided
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
9 "as is" without express or implied warranty.
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
10
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
11 Xtrek Copyright 1986 Chris Guthrie
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
12 Netrek (Xtrek II) Copyright 1989 Kevin P. Smith
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
13 Scott Silvey
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
14 Paradise II (Netrek II) Copyright 1993 Larry Denys
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
15 Kurt Olsen
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
16 Brandon Gillespie
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
17 --------------------------------------------------------------------------*/
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
18
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
19 #include "config.h"
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
20 #include <stdio.h>
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
21 #include <sys/types.h>
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
22 #include <sys/stat.h>
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
23 #include <sys/file.h>
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
24 #include <sys/ipc.h>
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
25 #include <sys/shm.h>
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
26 #include <sys/time.h>
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
27 #ifndef ULTRIX
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
28 #include <sys/fcntl.h>
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
29 #endif
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
30 #include <errno.h>
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
31 #include <pwd.h>
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
32 #include <string.h>
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
33 #include <ctype.h>
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
34 #include <time.h>
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
35 #include "defs.h"
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
36 #include "struct.h"
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
37 #include "data.h"
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
38 #include "packets.h"
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
39 #include "path.h"
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
40 #include "shmem.h"
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
41
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
42 #define crypt(a, b) (a)
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
43
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
44 void handleLogin();
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
45 extern int exitGame();
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
46 extern int isClientDead();
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
47 extern int socketPause();
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
48 extern int readFromClient();
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
49 int lockout();
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
50 extern int sendClientLogin();
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
51 extern int flushSockBuf();
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
52 #ifdef BAD_SVR4_HACKS
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
53 int updateMOTD();
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
54 #else
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
55 extern int updateMOTD();
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
56 #endif
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
57 #ifndef IRIX
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
58 extern int printf();
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
59 #endif
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
60 extern int read();
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
61 extern int close();
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
62 extern off_t lseek();
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
63 extern int write();
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
64 extern time_t time();
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
65
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
66 /* replace non-printable characters in string with spaces */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
67 static void
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
68 remove_ctl(str)
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
69 char *str;
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
70 {
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
71 while (*str)
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
72 {
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
73 if (!isgraph(*str)) /* not a printable character */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
74 *str = ' '; /* replace it with space */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
75 str++;
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
76 }
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
77 }
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
78
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
79 void
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
80 getname()
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
81 /* Let person identify themselves from w */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
82 {
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
83 *(me->p_name) = 0;
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
84 while (*(me->p_name) == 0)
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
85 {
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
86 handleLogin();
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
87 }
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
88 }
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
89
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
90 void
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
91 handleLogin()
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
92 {
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
93 static struct statentry player;
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
94 static int position = -1;
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
95 int plfd;
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
96 int entries;
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
97 struct stat buf;
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
98 char *paths;
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
99
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
100 paths = build_path(PLAYERFILE);
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
101 *namePick = '\0';
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
102 inputMask = CP_LOGIN;
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
103 while (*namePick == '\0')
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
104 {
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
105 /* Been ghostbusted? */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
106 if (me->p_status == PFREE)
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
107 exitGame();
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
108 if (isClientDead())
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
109 exitGame();
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
110 socketPause();
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
111 readFromClient();
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
112 }
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
113 #ifdef REMOVE_CTL /* untested */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
114 /* Change those annoying control characters to spaces */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
115 remove_ctl(namePick);
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
116 #endif
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
117 if ((strcmp(namePick, "Guest") == 0 || strcmp(namePick, "guest") == 0) &&
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
118 !lockout())
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
119 {
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
120 hourratio = 5;
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
121 memset(&player.stats, 0, sizeof(struct stats));
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
122 player.stats.st_tticks = 1;
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
123 player.stats.st_flags = ST_INITIAL;
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
124 /*
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
125 * If this is a query on Guest, the client is screwed, but I'll send him
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
126 * some crud anyway.
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
127 */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
128 if (passPick[15] != 0)
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
129 {
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
130 sendClientLogin(&player.stats);
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
131 flushSockBuf();
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
132 return;
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
133 }
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
134 sendClientLogin(&player.stats);
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
135
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
136 updateMOTD(); /* added here 1/19/93 KAO */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
137
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
138 flushSockBuf();
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
139 strcpy(me->p_name, namePick);
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
140 me->p_pos = -1;
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
141 memcpy(&(me->p_stats), &player.stats, sizeof(struct stats));
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
142 return;
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
143 }
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
144 hourratio = 1;
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
145 /* We look for the guy in the stat file */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
146 if (strcmp(player.name, namePick) != 0)
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
147 {
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
148 for (;;)
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
149 { /* so I can use break; */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
150 plfd = open(paths, O_RDONLY, 0644);
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
151 if (plfd < 0)
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
152 {
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
153 printf("I cannot open the player file!\n");
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
154 strcpy(player.name, namePick);
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
155 position = -1;
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
156 printf("Error number: %d\n", errno);
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
157 break;
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
158 }
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
159 position = 0;
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
160 while (read(plfd, (char *) &player, sizeof(struct statentry)) ==
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
161 sizeof(struct statentry))
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
162 {
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
163 #ifdef REMOVE_CTL /* untested */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
164 /*
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
165 * this is a temporary thing to remove control chars from existing
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
166 * entries in the player db
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
167 */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
168 remove_ctl(player.name);
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
169 #endif
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
170 if (strcmp(namePick, player.name) == 0)
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
171 {
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
172 close(plfd);
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
173 break;
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
174 }
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
175 position++;
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
176 }
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
177 if (strcmp(namePick, player.name) == 0)
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
178 break;
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
179 close(plfd);
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
180 position = -1;
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
181 strcpy(player.name, namePick);
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
182 break;
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
183 }
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
184 }
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
185 /* Was this just a query? */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
186 if (passPick[15] != 0)
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
187 {
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
188 if (position == -1)
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
189 {
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
190 sendClientLogin(NULL);
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
191 }
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
192 else
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
193 {
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
194 sendClientLogin(&player.stats);
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
195 }
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
196 flushSockBuf();
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
197 return;
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
198 }
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
199 /* A new guy? */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
200 if ((position == -1) && !lockout())
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
201 {
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
202 strcpy(player.name, namePick);
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
203 strcpy(player.password, crypt(passPick, namePick));
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
204 memset(&player.stats, 0, sizeof(struct stats));
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
205 player.stats.st_tticks = 1;
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
206 player.stats.st_flags = ST_INITIAL;
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
207 player.stats.st_royal = 0;
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
208 plfd = open(paths, O_RDWR | O_CREAT, 0644);
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
209 if (plfd < 0)
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
210 {
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
211 sendClientLogin(NULL);
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
212 }
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
213 else
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
214 {
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
215 fstat(plfd, &buf);
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
216 entries = buf.st_size / sizeof(struct statentry);
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
217 lseek(plfd, entries * sizeof(struct statentry), 0);
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
218 write(plfd, (char *) &player, sizeof(struct statentry));
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
219 close(plfd);
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
220 me->p_pos = entries;
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
221 memcpy(&(me->p_stats), &player.stats, sizeof(struct stats));
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
222 strcpy(me->p_name, namePick);
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
223 sendClientLogin(&player.stats);
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
224 updateMOTD(); /* added here 1/19/93 KAO */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
225 }
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
226 flushSockBuf();
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
227 return;
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
228 }
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
229 /* An actual login attempt */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
230 if ((strcmp(player.password, crypt(passPick, player.password)) != 0) ||
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
231 lockout())
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
232 {
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
233 sendClientLogin(NULL);
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
234 }
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
235 else
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
236 {
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
237 strcpy(me->p_name, namePick);
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
238 me->p_pos = position;
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
239 memcpy(&(me->p_stats), &player.stats, sizeof(struct stats));
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
240
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
241 sendClientLogin(&player.stats);
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
242
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
243 updateMOTD(); /* st_flags&ST_NOBITMAPS */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
244 }
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
245 flushSockBuf();
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
246
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
247 #if 1
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
248 /* Try to make the first person in the player database an Emperor */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
249 if (position == 0)
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
250 me->p_stats.st_royal = NUMROYALRANKS - 1;
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
251 #endif
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
252
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
253 return;
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
254 }
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
255
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
256 void
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
257 savestats()
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
258 {
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
259 int fd;
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
260 char *paths;
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
261
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
262 if (me->p_pos < 0)
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
263 return;
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
264
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
265 paths = build_path(PLAYERFILE);
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
266
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
267 fd = open(paths, O_WRONLY, 0644);
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
268 if (fd >= 0)
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
269 {
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
270 me->p_stats.st_lastlogin = time(NULL);
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
271 lseek(fd, 32 + me->p_pos * sizeof(struct statentry), 0);
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
272 write(fd, (char *) &me->p_stats, sizeof(struct stats));
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
273 close(fd);
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
274 }
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
275 }
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
276
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
277 /* return true if we want a lockout */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
278 int
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
279 lockout()
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
280 {
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
281 return (
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
282 /*
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
283 * (strncmp (login, "bozo", 4) == 0) ||
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
284 */
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
285 0
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
286 );
aa38447a4b21 First entry of Paradise Server 2.9 patch 10 Beta
darius
parents:
diff changeset
287 }