home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / games / tinymud2.zip / PLAYER.C < prev    next >
C/C++ Source or Header  |  1990-09-02  |  2KB  |  74 lines

  1. #include "copyright.h"
  2.  
  3. #include "db.h"
  4. #include "config.h"
  5. #include "interface.h"
  6. #include "externs.h"
  7.  
  8. #ifndef PLAYER_LIST    
  9. /* don't use this, it's expensive */
  10. /* maybe soon we'll put in a hash table */
  11. dbref lookup_player(const char *name)
  12. {
  13.     dbref i;
  14.  
  15.     for(i = 0; i < db_top; i++) {
  16.     if(Typeof(i) == TYPE_PLAYER
  17.        && db[i].name && !string_compare(db[i].name, name)) return i;
  18.     }
  19.     return NOTHING;
  20. }
  21. #endif PLAYER_LIST
  22.  
  23. dbref connect_player(const char *name, const char *password)
  24. {
  25.     dbref player;
  26.  
  27.     if((player = lookup_player(name)) == NOTHING) return NOTHING;
  28.     if(db[player].password
  29.        && *db[player].password
  30.        &&strcmp(db[player].password, password)) return NOTHING;
  31.  
  32.     return player;
  33. }
  34.  
  35. dbref create_player(const char *name, const char *password)
  36. {
  37.     dbref player;
  38.  
  39.     if(!ok_player_name(name) || !ok_password(password)) return NOTHING;
  40.  
  41.     /* else he doesn't already exist, create him */
  42.     player = new_object();
  43.  
  44.     /* initialize everything */
  45.     db[player].name = alloc_string(name);
  46.     db[player].location = PLAYER_START;
  47.     db[player].exits = PLAYER_START;    /* home */
  48.     db[player].owner = player;
  49.     db[player].flags = TYPE_PLAYER;
  50.     db[player].password = alloc_string(password);
  51.     
  52.     /* link him to PLAYER_START */
  53.     PUSH(player, db[PLAYER_START].contents);
  54.  
  55. #ifdef PLAYER_LIST
  56.     add_player(player);
  57. #endif PLAYER_LIST    
  58.  
  59.     return player;
  60. }
  61.  
  62. void do_password(dbref player, const char *old, const char *newobj)
  63. {
  64.     if(!db[player].password || strcmp(old, db[player].password)) {
  65.     notify(player, "Sorry");
  66.     } else if(!ok_password(newobj)) {
  67.     notify(player, "Bad new password.");
  68.     } else {
  69.     free((void *) db[player].password);
  70.     db[player].password = alloc_string(newobj);
  71.     notify(player, "Password changed.");
  72.     }
  73. }
  74.