MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame^] | 1 | // MorgenGrauen MUDlib |
| 2 | // |
| 3 | // guestmaster.c -- Verwalter von Gast-Logins |
| 4 | // |
| 5 | // $Id: guestmaster.c 8909 2014-08-20 21:33:55Z Zesstra $ |
| 6 | #pragma no_clone,no_inherit,no_shadow |
| 7 | #pragma strict_types,save_types,rtt_checks |
| 8 | |
| 9 | #include <wizlevels.h> |
| 10 | |
| 11 | nosave int max_guests = 10; /* Max no. of guests. -1 is 'unlimited' */ |
| 12 | nosave object *guests = ({}); |
| 13 | nosave int *ltime = ({}); |
| 14 | |
| 15 | protected void create() |
| 16 | { |
| 17 | seteuid(getuid()); |
| 18 | } |
| 19 | |
| 20 | nomask int new_guest () { |
| 21 | int ix; |
| 22 | |
| 23 | if (!max_guests) return 0; |
| 24 | if (load_name(previous_object()) != "/secure/login") |
| 25 | return 0; |
| 26 | |
| 27 | if ((ix = member(guests,0)) == -1) { |
| 28 | ix = sizeof(guests); |
| 29 | if (max_guests < 0 || ix < max_guests) |
| 30 | { |
| 31 | guests += ({ 0 }), ltime += ({ 0 }); |
| 32 | } |
| 33 | else { |
| 34 | int mintime, minix; |
| 35 | mintime = time(); |
| 36 | for (ix = 0; ix < sizeof(guests); ix++) { |
| 37 | if (guests[ix] && ltime[ix] < mintime) { |
| 38 | mintime=ltime[ix]; |
| 39 | minix=ix; |
| 40 | } |
| 41 | } |
| 42 | ix = minix; |
| 43 | } |
| 44 | } |
| 45 | return ix+1; |
| 46 | } |
| 47 | |
| 48 | nomask void set_guest (int ix, object pl) { |
| 49 | if (load_name(previous_object()) != "/secure/login") return; |
| 50 | guests[ix-1] = pl; |
| 51 | ltime[ix-1] = time(); |
| 52 | } |
| 53 | |
| 54 | nomask int query_max_guests() { return max_guests; } |
| 55 | nomask int set_max_guests(int v) { |
| 56 | if (!process_call() && LORD_SECURITY) |
| 57 | max_guests = v; |
| 58 | return max_guests; |
| 59 | } |
| 60 | |