blob: 1f4eb3f5848fe9a4c41b698a9b32bbdec21be521 [file] [log] [blame]
MG Mud User88f12472016-06-24 23:31:02 +02001// MorgenGrauen MUDlib
2//
3// login.c -- Object for players just logging in
4//
5// $Id: login.c 9245 2015-06-04 13:04:39Z Arathorn $
6
7 /*
8 * secure/login.c
9 *
10 * This object is cloned for every user trying to log in
11 * We are still running root.
12 *
13 * login.c looks up the username in the secure/PASSWD file. If it is
14 * found, the password is checked. If the user is already logged in,
15 * he will be reconnected to the running object. If the other object
16 * is still interactive, that will be disconnected before the user is
17 * reconnected to that object.
18 *
19 * If the user is not in PASSWD, a new entry with level 0 is created.
20 * All PASSWD writing is done in secure/master.c.
21 *
22 */
23#pragma strict_types
24#pragma no_shadow
25#pragma no_inherit
26#pragma verbose_errors
27#pragma combine_strings
28//#pragma pedantic
29//#pragma range_check
30#pragma warn_deprecated
31
32#include <config.h>
33#include <properties.h>
34#include <moving.h>
35#include "/secure/wizlevels.h"
Zesstrae037c1d2020-02-02 22:02:14 +010036
MG Mud User88f12472016-06-24 23:31:02 +020037#include <telnet.h>
38#include <defines.h>
39#include <input_to.h>
Zesstrae037c1d2020-02-02 22:02:14 +010040#include <configuration.h>
MG Mud User88f12472016-06-24 23:31:02 +020041
42inherit "/secure/mini_props.c";
43inherit "/secure/telnetneg.c";
44
45#define SSL_GRRETING "REMOTE_HOST="
46#define PROXIES ({"127.0.0.1","87.79.24.60"})
47#define GUESTMASTER "/secure/guestmaster"
48
49#ifndef DEBUG
50#define DEBUG(x) if(find_player("tiamak")) tell_object(find_player("tiamak"),x)
51#define DEBUGM(x) if(find_player("muadib")) tell_object(find_player("muadib"),x)
52#endif
53
54/* Variables of the secure save file */
55int level, loginfails, creation_date;
56string password, name, shell, ep, ek, mq;
57string ektips;
58string fptips;
59string *domains, *guilds, *uidstotakecare;
60
61static int invis, neu;
62static string loginname;
63static string cap_name;
64static string *userentry;
65static string banish;
66static mixed *races;
67static int newbie;
68static string realip;
69
70// Prototypes
71static void SendTelopts();
72public nomask string loginname();
73// the following 4 lfuns deal with real logins
74public nomask int logon();
Zesstrab75a89c2020-01-31 18:47:57 +010075static void logon2( string str );
MG Mud User88f12472016-06-24 23:31:02 +020076static int load_player_object( int guestflag );
77static void load_player_ob_2( string obname, int guestflag );
78static int check_illegal( string str );
79static int valid_name( string str );
80static int new_password( string str );
81static int again_password( string str );
82static int check_password( string str );
83static void select_race();
84static void ask_race_question();
85static void get_race_answer( string str );
86
87protected void create();
88public string short();
89public string query_real_name();
90public nomask int query_prevent_shadow();
MG Mud User88f12472016-06-24 23:31:02 +020091public int remove();
92// the following 3 lfuns deal with dummy player creation
93public mixed new_logon( string str);
94static mixed new_load_player_object();
95static mixed new_load_player_ob_2( string obname );
96static void ask_mud_played_question();
97static void get_mud_played_answer(string str);
98
99
100public nomask string loginname()
101{
102 return loginname ? loginname : "";
103}
104
105
106public int remove()
107{
108 destruct( this_object() );
109 return 1;
110}
111
112
113static int check_too_many_logons()
114{
115 object *u;
116 string ip;
117
118 ip = query_ip_number(this_object());
119 // users() nehmen, falls nicht-interaktive Clones von login.c existieren.
120 u = filter( users(), function status (object ob, string addr) {
Zesstra077f3c62016-09-30 21:24:05 +0200121 return load_name(ob) == "/secure/login"
MG Mud User88f12472016-06-24 23:31:02 +0200122 && query_ip_number(ob) == addr;
123 }, ip );
124
Zesstracb45e3d2016-09-30 20:13:31 +0200125 if ( sizeof(u) > 2) {
MG Mud User88f12472016-06-24 23:31:02 +0200126 write( "\nEs laufen schon zu viele Anmeldungen von Deiner Adresse "
127 "aus.\nProbier es bitte in ein bis zwei Minuten noch "
128 "einmal.\n" );
129
Zesstracb45e3d2016-09-30 20:13:31 +0200130 log_file( "LOGIN_DENY", sprintf( "%s: >2 Logons von %-15s (%s)\n",
MG Mud User88f12472016-06-24 23:31:02 +0200131 ctime(time())[4..15],
132 query_ip_number(this_object()),
133 query_ip_name(this_object()) ) );
134 return 1;
135 }
136 else
137 return 0;
138}
139
Zesstrae037c1d2020-02-02 22:02:14 +0100140// Callback when a TLS connection negotiation was finished. This handler is
141// called for negotiations startet by the telnet option START_TLS.
142protected void tls_init_callback(int handshake_result)
143{
144 if (handshake_result < 0)
145 {
146 // Fehler im Vebindungsaufbau
147 write(break_string(sprintf(
148 "Can't establish a TLS/SSL encrypted connection: %s."
149 "Disconnecting now. If this error persists, please "
150 "disable the usage of TLS or STARTTLS in your client.",
151 tls_error(handshake_result)),78));
152 // Disconnect
153 destruct(this_object());
154 return;
155 }
156 // In this case, we will treat the newly negotiated TLS connection as as new
157 // connection and just start over again by calling logon(). And re-enable
158 // the telnet machine of the driver of course.
159 configure_interactive(this_object(), IC_TELNET_ENABLED, 1);
160 logon();
161}
162
163// Called from the telnetneg handler for TELOPT_STARTTLS to initiate the TLS
164// connection negotiation.
165protected void init_tls()
166{
167 ::init_tls();
168 configure_interactive(this_object(), IC_TELNET_ENABLED, 0);
169 tls_init_connection(this_object(), #'tls_init_callback);
170}
171
MG Mud User88f12472016-06-24 23:31:02 +0200172/*
173 * This is the function that gets called by /secure/master for every user
174 */
175public nomask int logon()
176{
Zesstrae037c1d2020-02-02 22:02:14 +0100177 set_next_reset(300); // Timeout fuer Loginverfahren
MG Mud User88f12472016-06-24 23:31:02 +0200178 loginname = "logon";
179 newbie=0;
Zesstraca502032020-02-05 19:56:09 +0100180 realip=0;
MG Mud User88f12472016-06-24 23:31:02 +0200181
Zesstrae037c1d2020-02-02 22:02:14 +0100182 SendTelopts();
183 // In theory, we should not send anything if SendTelops() offers
184 // TELOPT_STARTTLS. However, some clients to not answer unknown telnet
185 // options and it would introduce a delay in any case. Therefore we send
186 // the welcome message anway, unless we received a WILL from the Client.
187
188 // Es wird ein Lookup gemacht, ob die Quelladresse ein Tor-Exitnode ist,
189 // der erlaubt, zu uns zu kommunizieren. Das Lookup ist asynchron und
190 // braucht eine Weile, wenn das Ergebnis noch nicht gecacht ist.
191 // An dieser Stelle wird das Ergebnis nicht ausgewertet. Achja, wie
MG Mud User88f12472016-06-24 23:31:02 +0200192 // machen das natuerlich nicht fuer die IP vom Mudrechner...
193 if (query_ip_number(this_object()) != "87.79.24.60")
194 {
bugfixd94d0932020-04-08 11:27:13 +0200195 ({int})"/p/daemon/dnslookup"->check_tor(query_ip_number(this_object()),
Zesstrae037c1d2020-02-02 22:02:14 +0100196 query_mud_port());
bugfixd94d0932020-04-08 11:27:13 +0200197 ({int})"/p/daemon/dnslookup"->check_dnsbl(query_ip_number(this_object()));
MG Mud User88f12472016-06-24 23:31:02 +0200198 }
Zesstrae037c1d2020-02-02 22:02:14 +0100199
200 // ggf. muss TLS (initiiert durch STARTTLS) noch ausverhandelt werden.
201 if (check_tls_negotiation())
202 return 1; // Verbindung behalten
203
MG Mud User88f12472016-06-24 23:31:02 +0200204 printf("HTTP/1.0 302 Found\n"
205 "Location: http://mg.mud.de/\n\n"
206 "NetCologne, Koeln, Germany. Local time: %s\n\n"
207 MUDNAME" LDmud, NATIVE mode, driver version %s\n\n",
208 strftime("%c"), __VERSION__);
209
MG Mud User88f12472016-06-24 23:31:02 +0200210 if ( check_too_many_logons() ){
211 destruct(this_object());
212 return 0;
213 }
214
215 // ist die Verbindung schon wieder weg?
Zesstrae037c1d2020-02-02 22:02:14 +0100216 if (!objectp(this_object()) || !interactive(this_object()))
217 return 0;
MG Mud User88f12472016-06-24 23:31:02 +0200218
Zesstrae037c1d2020-02-02 22:02:14 +0100219
220 cat( "/etc/WELCOME" );
MG Mud User88f12472016-06-24 23:31:02 +0200221 input_to( "logon2", INPUT_PROMPT,
222 "Wie heisst Du denn (\"neu\" fuer neuen Spieler)? ");
MG Mud User88f12472016-06-24 23:31:02 +0200223 return 1;
224}
225
226
227static int check_too_many_from_same_ip()
228{
229 object *u;
230 string ip;
231
232 ip = query_ip_number(this_object());
233 u = filter(users(), function status (object ob, string addr, int a) {
234 return query_ip_number(ob) == addr
bugfixd94d0932020-04-08 11:27:13 +0200235 && ({int})ob->QueryProp(P_AGE) < a;
MG Mud User88f12472016-06-24 23:31:02 +0200236 }, ip, 12*60*60); // 24h in heart_beats
237
238 if ( sizeof(u) > 25 ){
239 write( "\nDa anscheinend gerade jemand von Deiner Adresse aus "
240 "versucht, das \n"MUDNAME" mit neuen Charakteren zu "
241 "ueberschwemmen, werden momentan \nnur aeltere Charaktere "
242 "von dieser Adresse zugelassen.\nWenn Du meinst, dass es "
243 "sich um einen Fehler handelt, logg Dich bitte als \n"
244 "Gast ein und sprich einen Erzmagier oder Gott an.\n" );
245
246 log_file( "LOGIN_DENY", sprintf( "%s: >10 Spieler von %-15s (%s)\n",
247 ctime(time())[4..15],
248 query_ip_number(this_object()),
249 query_ip_name(this_object()) ) );
250
251 destruct(this_object());
252 return 1;
253 }
254 else
255 return 0;
256}
257
258
259static int check_illegal( string str )
260{
261 string res;
262
Vanion50652322020-03-10 21:13:25 +0100263 res = ({string})master()->QuerySBanished(query_ip_number(this_object()));
MG Mud User88f12472016-06-24 23:31:02 +0200264 if (!res)
265 {
266 // check connection from Tor exit node
Zesstraca502032020-02-05 19:56:09 +0100267 string eff_ip = (sizeof(realip) ? realip
268 : query_ip_number(this_object()));
bugfixd94d0932020-04-08 11:27:13 +0200269 if (({int})"/p/daemon/dnslookup"->check_tor(eff_ip, query_mud_port())
270 || ({int})"/p/daemon/dnslookup"->check_dnsbl(eff_ip))
MG Mud User88f12472016-06-24 23:31:02 +0200271 res =
272 "\nSorry, von Deiner Adresse kamen ein paar Idioten, die "
273 "ausschliesslich\nAerger machen wollten. Deshalb haben wir "
274 "die Moeglichkeit,\neinfach neue Charaktere "
275 "anzulegen, fuer diese Adresse gesperrt.\n\n"
276 "Falls Du bei uns spielen moechtest, schicke bitte eine Email "
277 "an\n\n mud@mg.mud.de\n\n"
278 "mit der Bitte, einen Charakter fuer Dich anzulegen.\n" ;
279 }
280
281 if ( res )
282 {
283 write( res );
284 log_file( "LOGIN_DENY", sprintf( "%s: %-11s %-15s (%s)\n",
285 ctime(time())[4..15], str,
286 query_ip_number(this_object()),
287 query_ip_name(this_object()) ) );
288 remove();
289 return 1;
290 }
291
292 return 0;
293}
294
295
296/*
297 * Check that a player name is valid. Only allow
298 * lowercase letters.
299 */
300static int valid_name( string str )
301{
302 int i;
303
304 if ( str == "logon" ){
305 write( "Der Name wuerde nur Verwirrung stiften.\n" );
306 return 0;
307 }
308
309 i = sizeof(str);
310
311 if ( i > 11 ){
312 write( "Dein Name ist zu lang, nimm bitte einen anderen.\n" );
313 return 0;
314 }
315
316 for ( ; i--; )
317 if ( str[i] < 'a' || str[i] > 'z' ) {
318 write( "Unerlaubtes Zeichen '" + str[i..i] + "' im Namen: " + str
319 + "\n" );
320 write( "Benutze bitte nur Buchstaben ohne Umlaute.\n" );
321 return 0;
322 }
323
324 return 1;
325}
326
Zesstrab75a89c2020-01-31 18:47:57 +0100327static void logon2( string str )
MG Mud User88f12472016-06-24 23:31:02 +0200328{
329 int i, arg;
330 mixed txt;
331
Zesstra4c418f92020-02-03 20:14:35 +0100332 // ggf. muss TLS (initiiert durch STARTTLS) noch ausverhandelt werden.
333 if (check_tls_negotiation())
334 return;
335
MG Mud User88f12472016-06-24 23:31:02 +0200336 if ( !str || str == "" ){
337 write( "Abbruch!\n" );
338 destruct( this_object() );
Zesstrab75a89c2020-01-31 18:47:57 +0100339 return;
MG Mud User88f12472016-06-24 23:31:02 +0200340 }
341
MG Mud User88f12472016-06-24 23:31:02 +0200342 if(strstr(str,SSL_GRRETING)==0)
343 {
344 if( member(PROXIES,query_ip_number(this_object()))>-1 )
345 {
346 realip=str[sizeof(SSL_GRRETING)..];
347 } // andere IPs werden einfach ignoriert. -> log/PROXY.REQ ?
348 // ggf. Lookup fuer Torexits anstossen.
bugfixd94d0932020-04-08 11:27:13 +0200349 ({int})"/p/daemon/dnslookup"->check_tor(realip,query_mud_port());
350 ({int})"/p/daemon/dnslookup"->check_dnsbl(realip);
MG Mud User88f12472016-06-24 23:31:02 +0200351
Zesstrafb642a12020-05-19 14:16:24 +0200352 input_to("logon2");
Zesstrab75a89c2020-01-31 18:47:57 +0100353 return;
MG Mud User88f12472016-06-24 23:31:02 +0200354 }
355
356 if ( loginname != "logon" ) {
357 log_file( "ILLEGAL", sprintf( "%s Illegal patch of login: "
358 "loginname = %O\n",
359 dtime(time()), loginname ) );
360 destruct( this_object() );
Zesstrab75a89c2020-01-31 18:47:57 +0100361 return;
MG Mud User88f12472016-06-24 23:31:02 +0200362 }
363
364 str = lower_case(str);
365 cap_name = capitalize(str);
366
367 if ( str == "neu" && !neu ){
368 cat( "/etc/WELCOME_NEW" );
369 neu = 1;
370 input_to( "logon2", INPUT_PROMPT, "Name: ");
Zesstrab75a89c2020-01-31 18:47:57 +0100371 return;
MG Mud User88f12472016-06-24 23:31:02 +0200372 }
373
374 if ( !valid_name(str) ){
375 string pr;
376 if ( !neu )
377 pr= "Wie heisst Du denn (\"neu\" fuer neuen Spieler)? ";
378 else
379 pr= "Bitte gib Dir einen anderen Namen: ";
380
381 input_to( "logon2", INPUT_PROMPT, pr );
Zesstrab75a89c2020-01-31 18:47:57 +0100382 return;
MG Mud User88f12472016-06-24 23:31:02 +0200383 }
384
385 if ( sscanf( str, "gast%d", arg ) == 1 ){
386 write( "Du meinst wohl 'Gast' ...\n" );
387 str = "gast";
388 }
389
390 loginname = str;
391
392 /* read the secure save file to see if character already exists */
bugfixd94d0932020-04-08 11:27:13 +0200393 string ssavef=({string})master()->secure_savefile(loginname);
Zesstra313eee92017-01-31 14:55:08 +0100394 if ( loginname != "gast"
395 && (!ssavef || !sizeof(ssavef) || !restore_object(ssavef) ))
Zesstrae43dd602017-01-31 10:48:10 +0100396 {
MG Mud User88f12472016-06-24 23:31:02 +0200397 object *user;
398
399 if ( !neu )
400 {
401 write( "Es existiert kein Charakter mit diesem Namen.\n" );
402 write( "Falls Du einen neuen Charakter erschaffen moechtest, "
403 "tippe bitte \"neu\" ein.\n" );
404
405 loginname = "logon";
406 input_to( "logon2", INPUT_PROMPT,
407 "Wie heisst Du denn (\"neu\" fuer neuen Spieler)? ");
Zesstrab75a89c2020-01-31 18:47:57 +0100408 return;
MG Mud User88f12472016-06-24 23:31:02 +0200409 }
410
411 for ( i = sizeof(user = users() - ({ 0, this_object() })); i--; )
412 if ( object_name(user[i])[0..12] == "/secure/login" &&
Vanion50652322020-03-10 21:13:25 +0100413 (({string})user[i]->loginname()) == loginname ){
MG Mud User88f12472016-06-24 23:31:02 +0200414 write( "Eine Anmeldung fuer diesen Namen laeuft bereits.\n" );
415 destruct( this_object() );
Zesstrab75a89c2020-01-31 18:47:57 +0100416 return;
MG Mud User88f12472016-06-24 23:31:02 +0200417 }
418
419 // Site-Banish checken
420 if ( check_illegal(loginname))
Zesstrab75a89c2020-01-31 18:47:57 +0100421 return;
MG Mud User88f12472016-06-24 23:31:02 +0200422
423 if ( check_too_many_from_same_ip() )
Zesstrab75a89c2020-01-31 18:47:57 +0100424 return;
MG Mud User88f12472016-06-24 23:31:02 +0200425
426 /* new character */
427 if ( sizeof(loginname) < 3 ){
428 write( "Der Name ist zu kurz.\n" );
429 loginname = "logon";
430 input_to( "logon2", INPUT_PROMPT,
431 "Versuch einen anderen Namen: ");
Zesstrab75a89c2020-01-31 18:47:57 +0100432 return;
MG Mud User88f12472016-06-24 23:31:02 +0200433 }
434
435
Vanion50652322020-03-10 21:13:25 +0100436 if ( (txt = ({string})master()->QueryBanished(loginname)) ){
MG Mud User88f12472016-06-24 23:31:02 +0200437 if ( txt != "Dieser Name ist gesperrt." )
438 txt = sprintf("Hoppla - dieser Name ist reserviert oder gesperrt "
439 "(\"gebanisht\")!\nGrund: %s\n",txt);
440 else
441 txt = "Hoppla - dieser Name ist reserviert oder gesperrt "
442 "(\"gebanisht\")!\n";
443 write(txt);
444 loginname = "logon";
445 input_to( "logon2", INPUT_PROMPT,
446 "Bitte gib Dir einen anderen Namen: ");
Zesstrab75a89c2020-01-31 18:47:57 +0100447 return;
MG Mud User88f12472016-06-24 23:31:02 +0200448 }
449
450 /* Initialize the new secure savefile */
451 name = loginname;
452 password = "";
453 level = 0;
454 domains = ({ });
455 guilds = ({ });
456 shell = "";
457 ep = "";
458 ek = "";
459 mq = "";
460 ektips="";
461 fptips="";
462 creation_date = time();
463
464 input_to( "new_password", INPUT_NOECHO|INPUT_PROMPT,
465 "Waehle ein Passwort: ");
Zesstrab75a89c2020-01-31 18:47:57 +0100466 return;
MG Mud User88f12472016-06-24 23:31:02 +0200467 }
468 else {
469 if ( loginname == "gast" ){
470 if ( check_illegal(loginname) )
Zesstrab75a89c2020-01-31 18:47:57 +0100471 return;
MG Mud User88f12472016-06-24 23:31:02 +0200472
473 load_player_object(1);
Zesstrab75a89c2020-01-31 18:47:57 +0100474 return;
MG Mud User88f12472016-06-24 23:31:02 +0200475 }
476
477 if ( neu ){
478 write( "Es existiert bereits ein Charakter dieses Namens.\n" );
479 loginname = "logon";
480 input_to( "logon2", INPUT_PROMPT,
481 "Gib Dir einen anderen Namen: ");
Zesstrab75a89c2020-01-31 18:47:57 +0100482 return;
MG Mud User88f12472016-06-24 23:31:02 +0200483 }
484
Vanion50652322020-03-10 21:13:25 +0100485 if ( ({int})master()->check_late_player(loginname) )
MG Mud User88f12472016-06-24 23:31:02 +0200486 {
487 write( "Dieser Spieler hat uns leider fuer immer verlassen.\n" );
488 loginname = "logon";
489 input_to( "logon2", INPUT_PROMPT,
490 "Wie heisst Du denn (\"neu\" fuer neuen Spieler)? ");
Zesstrab75a89c2020-01-31 18:47:57 +0100491 return;
MG Mud User88f12472016-06-24 23:31:02 +0200492 }
493
Vanion50652322020-03-10 21:13:25 +0100494 if ( txt = ({string})master()->QueryTBanished(loginname) ){
MG Mud User88f12472016-06-24 23:31:02 +0200495 write( txt );
496 loginname = "logon";
497 input_to( "logon2", INPUT_PROMPT,
498 "Wie heisst Du denn (\"neu\" fuer neuen Spieler)? ");
Zesstrab75a89c2020-01-31 18:47:57 +0100499 return;
MG Mud User88f12472016-06-24 23:31:02 +0200500 }
501
502 if ( creation_date > (time() - 30*24*60*60)
503 && check_too_many_from_same_ip() )
Zesstrab75a89c2020-01-31 18:47:57 +0100504 return;
MG Mud User88f12472016-06-24 23:31:02 +0200505
506 write( "Schoen, dass Du wieder da bist, "+capitalize(loginname)+"!\n" );
507
508 if ( !stringp(password) || password == "" ) {
509 write( "Du hast KEIN PASSWORD!\n" );
510 write( "Benutze den \"password\"-Befehl, um das zu aendern !\n" );
511 load_player_object(0);
Zesstrab75a89c2020-01-31 18:47:57 +0100512 return;
MG Mud User88f12472016-06-24 23:31:02 +0200513 }
514
515 input_to( "check_password", INPUT_NOECHO|INPUT_PROMPT,
516 "Passwort: ");
Zesstrab75a89c2020-01-31 18:47:57 +0100517 return;
MG Mud User88f12472016-06-24 23:31:02 +0200518 }
519}
520
521
522static int new_password( string str )
523{
524 write( "\n" );
525
526 if ( !str || str == "" )
527 return remove();
528
529 password = str;
530
bugfixd94d0932020-04-08 11:27:13 +0200531 if ( !({int})master()->good_password( str, loginname ) ) {
MG Mud User88f12472016-06-24 23:31:02 +0200532 input_to( "new_password", INPUT_NOECHO|INPUT_PROMPT,
533 "Bitte gib ein Passwort an: ");
534 return 1;
535 }
536
537 write( "\nZur Erinnerung: Es ist v e r b o t e n, andere Spieler "
538 "anzugreifen!\n" );
539 write( "Das gilt auch fuer Froesche, bei denen \"Ein Frosch namens "
540 "XXXXX\" steht.\n\n" );
541 input_to( "again_password", INPUT_NOECHO|INPUT_PROMPT,
542 "Passwort bitte nochmal eingeben: ");
543 return 1;
544}
545
546static int again_password( string str )
547{
548 write( "\n" );
549
550 if ( str != password ){
551 write( "Die Passwoerter stimmten nicht ueberein!\n" );
552 destruct( this_object() );
553 return 1;
554 }
555
Zesstra28d72e52016-10-27 23:56:19 +0200556 set_next_reset(600);
MG Mud User88f12472016-06-24 23:31:02 +0200557 password = md5_crypt( password, 0 );
558 save_object( SECURESAVEPATH + loginname[0..0] + "/" + loginname );
559 master()->RemoveFromCache( loginname );
560
561 load_player_object(0);
562 return 1;
563}
564
565static int check_password( string str )
566{
567 write( "\n" );
568
569 // Invis einloggen?
570 if (sizeof(str) > 1 && str[0] == '-') {
571 invis = 1;
572 str = str[1..];
573 }
574
575 // welcher Hash ists denn?
576 if (sizeof(password) > 13) {
577 // MD5-Hash
578 str = md5_crypt(str, password);
579 }
580 else if (sizeof(password) > 2) {
581 // Crypt-Hash
582 str = crypt(str, password[0..1]);
583 }
584 else {
585 // keiner von beiden Hashes -> ungueltiges PW
586 str = 0;
587 }
588
589 if ( !stringp(str) || str != password ) {
590 // Hashes stimmen nicht ueberein -> und schluss...
591 write( "Falsches Passwort!\n");
592 if ( loginfails > 2 )
593 write(break_string(
594 "Solltest Du weiterhin Probleme mit dem Einloggen haben, kannst "
595 "Du Dein Passwort zuruecksetzen lassen, indem Du Dich als Gast "
596 "anmeldest und einen Erzmagier ansprichst, oder indem Du Dich "
Zesstra0559c662017-02-06 19:14:51 +0100597 "mittels einer E-Mail an mud@mg.mud.de mit uns in Verbindung "
MG Mud User88f12472016-06-24 23:31:02 +0200598 "setzt.",78));
599
600 log_file( (level < 60 ? "LOGINFAIL" : "ARCH/LOGINFAIL"),
601 sprintf( "PASSWORD: %-11s %s, %-15s (%s)\n",
602 loginname, ctime(time())[4..15],
603 query_ip_number(this_object()),
604 query_ip_name(this_object()) ), 200000 );
605
606 loginfails++;
607 save_object( SECURESAVEPATH + loginname[0..0] + "/" + loginname );
608 master()->RemoveFromCache( loginname );
609 destruct( this_object() );
610 return 1;
611 }
612
613 if ( loginfails ) {
614 write( loginfails + " fehlgeschlagene" + (loginfails == 1 ? "r" : "") +
615 " Login-Versuch" + (loginfails == 1 ? "" : "e") +
616 " seit dem letzten erfolgreichen Login.\n" );
617 loginfails = 0;
618 }
619
620 save_object( SECURESAVEPATH + loginname[0..0] + "/" + loginname );
621 master()->RemoveFromCache( loginname );
622
623 load_player_object(0);
624 return 1;
625}
626
627
628static void select_race()
629{
630 int i;
Zesstra7e353662019-11-27 19:52:41 +0100631 string race;
632 int selectable;
MG Mud User88f12472016-06-24 23:31:02 +0200633
634 races = get_dir( "/std/shells/*.c" );
635
636 // Mensch soll immer als erstes in der Auswahlliste stehen.
637 if (member(races,"human.c")!=-1)
638 races=({"human.c"})+(races-({"human.c"}));
639
640 for ( i = sizeof(races); i--; ){
641 races[i] = "/std/shells/" + races[i][0..<3];
Zesstra7e353662019-11-27 19:52:41 +0100642 selectable = 0;
643 race = 0;
644 if ( catch(selectable = ({int})call_other( races[i],
645 "QueryAllowSelect" ); publish)
646 || !selectable)
647 selectable = 0;
648 else if ( catch(race = ({string})call_other(races[i],
649 "QueryProp", P_RACE );publish) )
650 race = 0;
MG Mud User88f12472016-06-24 23:31:02 +0200651
Zesstra7e353662019-11-27 19:52:41 +0100652 if ( !selectable || !sizeof(race) )
MG Mud User88f12472016-06-24 23:31:02 +0200653 races[i..i] = ({});
654 else
Zesstra7e353662019-11-27 19:52:41 +0100655 races[i] = ({ races[i], race });
MG Mud User88f12472016-06-24 23:31:02 +0200656 }
657
658 if ( sizeof(races) == 1 ){
659 write( "Es gibt nur eine Rasse, Du hast also keine Wahl.\n" );
660
661 shell = races[0][0];
662 master()->set_player_object( loginname, shell );
663
664 return load_player_ob_2( shell, 0 );
665 }
666
667 return ask_mud_played_question();
668}
669
670static void ask_mud_played_question()
671{
672 write(break_string(
673 "\nWenn Du ein absoluter Neuling in diesem Spiel bist moechten "
674 "wir Dir mit einigen Tips zu Beginn beiseite stehen.\n\n",78,
675 0,BS_LEAVE_MY_LFS));
676 input_to( "get_mud_played_answer", INPUT_PROMPT,
677 "Hast Du schon einmal in einem MUD gespielt? (ja,nein): ");
678 return;
679}
680
681static void ask_race_question()
682{
683 int i, j;
684
685 write( break_string( "Du musst Dich jetzt entscheiden, welcher Rasse Du "
686 "in dieser Welt angehoeren moechtest. Alle Rassen "
687 "haben verschiedene Vor- und Nachteile, insgesamt "
688 "aber gleich gute Chancen. Auch das Startgebiet "
689 "haengt von der ausgewaehlten Rasse ab. Im "
690 "Normalfall kann die Rasse nicht mehr gewechselt "
691 "werden, nachdem sie einmal ausgewaehlt wurde. "
692 "Ueberlege Dir Deine Entscheidung also gut. Derzeit "
693 "stehen folgende Rassen zur Auswahl:\n\n", 78 ) );
694
695 for ( i = 0, j = sizeof(races); i < j; i++ )
696 printf( "% 2d. %-30s %s", i+1, capitalize(races[i][1]),
697 (i % 2 ? "\n" : "| ") );
698
699 if ( sizeof(races) % 2 )
700 write( "\n" );
701
702 write( break_string( "\nDurch Eingabe einer Ziffer waehlst Du die Rasse "
703 "aus, durch Eingabe eines \"\?\" gefolgt von einer "
704 "Ziffer erhaeltst Du naehere Informationen ueber "
705 "eine Rasse. Ein \"\?\" allein wiederholt diese "
706 "Liste.", 78, 0, 1 ) );
707
708 if (newbie)
709 {
710 write(break_string("\nAls Neuling solltest Du Dich NICHT fuer "
711 "die Dunkelelfen entscheiden. Diese "
712 "Rasse hat einige Probleme im Umgang "
713 "mit den anderen Rassen und mit dem "
714 "Sonnenlicht.",78,0,BS_LEAVE_MY_LFS));
715 }
716
717 input_to( "get_race_answer", INPUT_PROMPT,
718 "\nWas willst Du tun: ");
719 return;
720}
721
722
723static void get_race_answer( string str )
724{
725 int num;
726
727 if ( str == "?" )
728 return ask_race_question();
729
730 if ( sscanf( str, "?%d", num ) ){
731 if ( num < 1 || num > sizeof(races) ){
732 write( "Das geht nicht.\n\n");
733 input_to( "get_race_answer", INPUT_PROMPT,
734 "Was willst Du tun: ");
735 return;
736 }
737
bugfixd94d0932020-04-08 11:27:13 +0200738 write( ({string})call_other( races[num - 1][0], "QueryProp", P_RACE_DESCRIPTION ));
MG Mud User88f12472016-06-24 23:31:02 +0200739 input_to( "get_race_answer", INPUT_PROMPT,
740 "\nWas willst Du tun: ");
741 return;
742 }
743
744 if ( sscanf( str, "%d", num ) && num >= 1 && num <= sizeof(races) ){
745 write( "Ok, Du bist jetzt ein "
746 + capitalize(races[num-1][1]) + ".\n" );
747
748 shell = races[num-1][0];
749 master()->set_player_object( loginname, shell );
750 return load_player_ob_2( shell, 0 );
751 }
752
753 write("Wie bitte?\n\n" );
754 input_to( "get_race_answer", INPUT_PROMPT,
755 "Was willst Du tun: ");
756}
757
758static void get_mud_played_answer (string str)
759{
760 if ( str == "ja" || str=="j")
761 {
762 newbie=0;
763 return ask_race_question();
764 }
765 if ( str != "nein" && str!="n")
766 {
767 write("\n\nAntworte bitte mit ja oder nein.\n\n");
768
769 return ask_mud_played_question();
770 }
771 newbie=1;
772 write("\n\nEine kleine Einfuehrung in das "MUDNAME" bekommst "
773 "Du auch hier:\n\n"
774 "http://mg.mud.de/newweb/hilfe/tutorial/inhalt.shtml\n\n");
775 return ask_race_question();
776
777}
778
779static int load_player_object( int guestflag )
780{
781 object ob;
782 string fname;
783 int was_interactive;
784
785 if ( sizeof(users()) >= 195 && !IS_WIZARD(loginname) ){
786 write( "Die maximale Spielerzahl wurde bereits erreicht!!!\n"
787 "Aus technischen Gruenden duerfen sich nur noch Magier "
788 "einloggen.\nVersuch es spaeter noch einmal ...\n" );
789 destruct( this_object() );
790 return 1;
791 }
792 else if ( sizeof(users()) >= 198 && !IS_ARCH(loginname) ){
793 write( "Die maximale Spieler- und Magierzahl wurde bereits erreicht!!!"
794 "\nAus technischen Gruenden duerfen sich nur noch Erzmagier "
795 "einloggen.\nVersuch es spaeter noch einmal ...\n" );
796 destruct( this_object() );
797 return 1;
798 }
799
800 if ( file_size("/etc/NOLOGIN")>=0 )
801 {
802 if (file_size("/etc/NOLOGIN.info")>0) {
803 //NOLOGIN.info enthaelt evtl. weitergehende Informationen fuer
804 //Spieler, z.B. vorrauss. Wiederverfuegbarkeit.
805 write(break_string(read_file("/etc/NOLOGIN.info"),78,"",
806 BS_LEAVE_MY_LFS|BS_SINGLE_SPACE));
807 }
808 else {
809 //sonst Standardmeldung ausgeben.
810 write ("\nAufgrund von technischen Problemen ist das Einloggen ins "
811 MUDNAME" zur \nZeit nicht moeglich. Bitte versuch es "
812 "spaeter noch einmal.\n\n");
813 }
814 if ( IS_ARCH(loginname) ||
815 member(explode(read_file("/etc/NOLOGIN")||"","\n"),
816 loginname)!=-1 )
817 {
818 write("Im Moment koennen nur Erzmagier einloggen. Um Spieler "
819 "wieder ins Spiel zu lassen, muss die Datei '/etc/NOLOGIN' "
820 "geloescht werden.\n\n ");
821 } else {
822 destruct( this_object() );
823 return 1;
824 }
825 }
826
827 if ( guestflag ){
Vanion50652322020-03-10 21:13:25 +0100828 if ( catch(guestflag = ({int})GUESTMASTER->new_guest();publish)
MG Mud User88f12472016-06-24 23:31:02 +0200829 || !guestflag ){
830 write( "Derzeit ist kein Gastlogin moeglich!\n" );
831 destruct( this_object() );
832 return 1;
833 }
834
835 loginname = "gast" + guestflag;
836 cap_name = capitalize(loginname);
837 name = cap_name;
838
839 if ( !(ob = find_player(loginname) || find_netdead(loginname)) ){
840 object *user;
841 int i;
842
843 // gegen Horden von Gast1 - wenn ein Gast noch am Prompt fuer
844 // das Geschlecht haengt, ist er ueber find_player() noch nicht
845 // zu finden ...
846 for ( i = sizeof(user = users() - ({ 0, this_object() })); i--; )
847 if ( object_name(user[i])[0..11] == "/std/shells/" &&
848 getuid(user[i]) == loginname ){
849 ob = user[i];
850 break;
851 }
852 }
853
854 if ( ob ){
855 tell_object( ob, "Ein anderer Spieler moechte diesen Gastzugang "
856 "jetzt benutzen. Wenn es Dir hier\ngefallen hat, "
857 "ueberleg Dir doch einen Charakternamen und komm "
858 "unter diesem\nNamen wieder!\n" );
859 destruct(ob);
860 }
861
862 load_player_ob_2( "std/shells/human", guestflag );
863
864 return 1;
865 }
866 else {
867 /* Test if we are already playing */
868 was_interactive = 0;
869 ob = find_player(loginname) || find_netdead(loginname);
870
871 if (ob) {
872 write( "Du nimmst schon am Spiel teil!\n" );
873 write( "Verwende Deine alte sterbliche Huelle ...\n" );
874
875 if ( interactive(ob) )
876 {
877 /* The other object is still interactive; reconnect that "soul"
878 to a dummy object and destruct that, thus disconnecting the
879 other probably linkdead user. The real "body" is still
880 there for reconnecting by login.c */
881 remove_interactive(ob);
882 was_interactive = 1;
883 }
884 // Wenn Invislogin, P_INVIS setzen.
885 if ( invis && IS_WIZARD(ob) )
886 {
887 ob->SetProp( P_INVIS, ob->QueryProp(P_AGE) );
888 tell_object( ob, "DU BIST UNSICHTBAR!\n" );
889 }
890 /* Now reconnect to the old body */
891 exec( ob, this_object() );
892 ob->set_realip(realip);
Vanion50652322020-03-10 21:13:25 +0100893 if ( (({int})ob->QueryProp(P_LEVEL)) == -1 )
MG Mud User88f12472016-06-24 23:31:02 +0200894 ob->start_player( cap_name );
895 else
896 ob->Reconnect( was_interactive );
897
898 call_out( "remove", 2 );
899 return 1;
900 }
901 }
902
903 /* read player object from passwd file */
904 if ( stringp(shell) && shell != "" )
905 load_player_ob_2 ( shell, 0 );
906 else
907 select_race();
908
909 return 1;
910}
911
912
913static void load_player_ob_2( string obname, int guestflag )
914{
915 object blueprint;
916 string err, ob_name;
917 object ob, old_ob;
918
919 if (!interactive()) {
920 destruct(this_object());
921 return;
922 }
923 /* start player activity */
Zesstrae88826c2016-09-24 20:37:05 +0200924 log_file( "syslog/shell/ENTER", sprintf( "%-11s %s, %-15s (%s).\n",
MG Mud User88f12472016-06-24 23:31:02 +0200925 capitalize(name), ctime(time())[4..15],
926 query_ip_number(this_object()),
927 query_ip_name(this_object()) ), 200000 );
928
929 seteuid(loginname);
930
931 /* load the "real" player object */
932 /* If some asshole has moved the blueprint */
933 if ( objectp(blueprint = find_object(obname)) && environment(blueprint) )
934 destruct(blueprint);
935
936 if ( err = catch(ob = clone_object(obname);publish) ){
937 log_file( "SHELLS", "Failed to load shell " + obname + ", " +
938 dtime(time()) + ", " + loginname + "\n" + err + "\n\n" );
939
940 write( "Konnte das passende Playerobjekt nicht laden. Lade "
941 "stattdessen\ndas Objekt Mensch. BITTE ERZMAGIER "
942 "BENACHRICHTIGEN !\n" );
943 err = catch(ob = clone_object("/std/shells/human");publish);
944 }
945
946 if ( !ob || err ) {
947 write( "Error on loading " + shell + "\nError = " + err + "\n" );
948 destruct( this_object() );
949 return;
950 }
951
952 if ( guestflag )
953 catch( GUESTMASTER->set_guest( guestflag, ob );publish );
954
955 ob_name = explode( object_name(ob), "#" )[0];
956
957 if ( sizeof(ob_name) > 11 && ob_name[0..11] == "/std/shells/" )
958 ob_name = ob_name[11..];
959
960 ob_name = ob_name + ":" + loginname;
961
962 if( !guestflag )
963 {
964 if ( old_ob = find_object(ob_name) )
965 {
966 catch(old_ob->remove();publish);
967
968 if ( old_ob )
969 destruct( old_ob );
970 }
971 rename_object( ob, ob_name );
972 ob->__reload_explore();
973 }
974 exec( ob, this_object() );
975 ob->set_realip(realip);
976 ob->start_player( cap_name );
Zesstraab834bb2020-01-21 13:11:45 +0100977 // Hinweis: Das Spielerobjekt holt sich in updates_after_restore() von hier
978 // den Status von invis und setzt ggf. P_INVIS, ausserdem den Status der
979 // Telnet Negotiations.
MG Mud User88f12472016-06-24 23:31:02 +0200980
MG Mud User88f12472016-06-24 23:31:02 +0200981 // wenn der Spieler noch nicht im Mud gespielt hat, wird die aktuelle Zeit
982 // in die entsprechende Prop geschrieben. Die Prop ist transient und wird
983 // absichtlich nicht gespeichert.
984 if (newbie)
985 ob->SetProp("_lib_mud_newbie", creation_date);
986
987 destruct( this_object() );
988}
989
990
991/*
992 * With arg = 0 this function should only be entered once!
993 */
994protected void create()
995{
996 loginname = "logon";
997 creation_date = -1;
998 catch( load_object( "/secure/merlin");publish );
999 loginfails = 0;
MG Mud User88f12472016-06-24 23:31:02 +02001000 if (clonep())
1001 set_next_reset(900);
1002 else
1003 set_next_reset(-1);
1004}
1005
1006void reset()
1007{
1008 if (clonep())
Zesstra28d72e52016-10-27 23:56:19 +02001009 {
1010 if (interactive(this_object()))
1011 tell_object(this_object(),"Time out!");
MG Mud User88f12472016-06-24 23:31:02 +02001012 remove();
Zesstra28d72e52016-10-27 23:56:19 +02001013 }
MG Mud User88f12472016-06-24 23:31:02 +02001014}
1015
1016public string short()
1017{
1018 return "<Einloggender Teilnehmer>.\n";
1019}
1020
1021
1022public string query_real_name()
1023{
1024 return "<logon>";
1025}
1026
1027
1028public nomask int query_prevent_shadow()
1029{
1030 return 1;
1031}
1032
1033
MG Mud User88f12472016-06-24 23:31:02 +02001034// Wird von simul_efuns benutzt, um nen dummy-Spielerobjekt zu erzeugen. Nicht
1035// im Loginprozess involviert.
1036public mixed new_logon( string str)
1037{
1038 seteuid(getuid()); // sonst funkt ARCH_SECURITY nicht
1039
1040 if ( !ARCH_SECURITY || process_call() ){
1041 write( "Nur fuer Erzmagier erlaubt!\n" );
1042 destruct( this_object() );
1043 return -1;
1044 }
1045
1046 if ( !str || str == "" ){
1047 write( "Kein Name angegeben!\n" );
1048 destruct( this_object() );
1049 return 0;
1050 }
1051
1052 str = lower_case(str);
1053 cap_name = capitalize(str);
1054
1055 loginname = str;
1056 seteuid(ROOTID);
1057
1058 /* read the secure save file to see if character already exists */
bugfixd94d0932020-04-08 11:27:13 +02001059 if ( !restore_object( ({string})master()->secure_savefile(loginname) ) ){
MG Mud User88f12472016-06-24 23:31:02 +02001060 write( "Kein solcher Spieler!\n" );
1061 destruct( this_object() );
1062 return 0;
1063 }
1064 else {
1065 write( "Ok, der Spieler " + capitalize(str) + " existiert!\n" );
1066 return new_load_player_object();
1067 }
1068}
1069
1070// Wird von simul_efuns benutzt, um nen dummy-Spielerobjekt zu erzeugen. Nicht
1071// im Loginprozess involviert.
1072static mixed new_load_player_object()
1073{
1074 if ( find_player(loginname) || find_netdead(loginname) ){
1075 write( "Der Spieler ist bereits online oder netztot!\n" );
1076 destruct( this_object() );
1077 return 2;
1078 }
1079
1080 /* read player object from passwd file */
1081 if ( stringp(shell) && shell != "" )
1082 return new_load_player_ob_2( shell );
1083 else {
1084 write( "Keine Shell angegeben!\n" );
1085 destruct( this_object() );
1086 return 0;
1087 }
1088}
1089
1090// Wird von simul_efuns benutzt, um nen dummy-Spielerobjekt zu erzeugen. Nicht
1091// im Loginprozess involviert.
1092static mixed new_load_player_ob_2( string obname )
1093{
1094 object blueprint;
1095 string err, ob_name;
1096 object ob, old_ob;
1097
1098 seteuid(loginname);
1099
1100 /* load the "real" player object */
1101 /* If some asshole has moved the blueprint */
1102 if ( objectp(blueprint = find_object(obname)) && environment(blueprint) )
1103 destruct( blueprint );
1104
1105 err = catch(ob = clone_object(obname);publish);
1106
1107 if ( err ){
1108 log_file( "SHELLS", "Failed to load shell " + obname + ", " +
1109 dtime(time()) + ", " + loginname + "\n" + err + "\n\n" );
1110
1111 write( "Konnte das passende Playerobjekt nicht laden. "
1112 "Lade stattdessen\ndas Objekt Mensch!\n" );
1113
1114 err = catch(ob = clone_object( "std/shells/human" );publish );
1115 }
1116
1117 if ( !ob || err ){
1118 write( "Error on loading " + shell + "\nError = " + err + "\n" );
1119 destruct( this_object() );
1120 return 0;
1121 }
1122
1123 ob_name = explode( object_name(ob), "#" )[0];
1124
1125 if ( sizeof(ob_name) > 11 && ob_name[0..11] == "/std/shells/" )
1126 ob_name = ob_name[11..];
1127
1128 ob_name = ob_name + ":" + loginname;
1129
1130 if ( old_ob = find_object(ob_name) ){
1131 catch( old_ob->remove(); publish );
1132
1133 if ( old_ob )
1134 destruct( old_ob );
1135 }
1136
1137 rename_object( ob, ob_name );
1138 ob->__reload_explore();
1139 ob->set_realip(realip);
1140 ob->start_player(cap_name);
1141 ob->SetProp( "creation_date", creation_date );
1142 ob->Set( "creation_date", SAVE|SECURED|PROTECTED, F_MODE_AS );
1143
1144 ob->move( "/room/nowhere", M_NOCHECK );
1145 set_object_heart_beat( ob, 0 );
1146 destruct( this_object() );
1147
1148 return ob;
1149}
1150
Zesstraca502032020-02-05 19:56:09 +01001151public string query_realip()
MG Mud User88f12472016-06-24 23:31:02 +02001152{
Zesstraca502032020-02-05 19:56:09 +01001153 return realip ? realip : 0;
MG Mud User88f12472016-06-24 23:31:02 +02001154}
1155
1156int query_invis()
1157{
1158 return invis;
1159}
1160