diff -Naur Rom24/area/timelock.txt Rom24Timelock/area/timelock.txt --- Rom24/area/timelock.txt 1970-01-01 02:00:00.000000000 +0200 +++ Rom24Timelock/area/timelock.txt 2006-02-20 18:59:35.000000000 +0200 @@ -0,0 +1 @@ +0 0 0 - 7 23 59 diff -Naur Rom24/src/Makefile.linux Rom24Timelock/src/Makefile.linux --- Rom24/src/Makefile.linux 2006-02-20 19:50:07.000000000 +0200 +++ Rom24Timelock/src/Makefile.linux 2006-02-20 18:56:52.000000000 +0200 @@ -9,7 +9,7 @@ alias.o ban.o comm.o const.o db.o db2.o effects.o fight.o flags.o \ handler.o healer.o interp.o note.o lookup.o magic.o magic2.o \ music.o recycle.o save.o scan.o skills.o special.o tables.o \ - update.o + update.o timelock.o rom: $(O_FILES) rm -f rom diff -Naur Rom24/src/comm.c Rom24Timelock/src/comm.c --- Rom24/src/comm.c 2006-02-20 19:50:07.000000000 +0200 +++ Rom24Timelock/src/comm.c 2006-02-20 18:26:53.000000000 +0200 @@ -707,6 +707,27 @@ if ( FD_ISSET( control, &in_set ) ) init_descriptor( control ); + + /* Check if it is time to kick the player*/ + /* The check timelock does take some time */ + if (check_timelock()) + { + for (d = descriptor_list; d; d = d->next) + { + char log_buf[1024]; + if ( d->character && !IS_IMMORTAL(d->character)) + { + sprintf(log_buf, "Extracting %s (timelock reached).", d->character->name); + log_string( log_buf ); + send_to_char("The game has entered locked state. Your character has been saved.\n", d->character); + if (d->character && d->connected == CON_PLAYING) + save_char_obj(d->character); + close_socket(d); + } + } + } + + /* * Kick out the freaky folks. */ @@ -1581,6 +1602,18 @@ fOld = load_char_obj( d, argument ); ch = d->character; + /*The timelock mechanism will allow us to specify when a particular timelock + * should occur. Timelocks mean nobody can log in, and logged in players + * that do not meet the timelock criteria will be logged of. */ + if (check_timelock() && !IS_IMMORTAL (ch)) + { + log_string("New Conneciton terminated on timelock."); + write_to_buffer(d, + "The game is locked at this time. Try again later.\n", 0); + close_socket(d); + return; + } + if (IS_SET(ch->act, PLR_DENY)) { sprintf( log_buf, "Denying access to %s@%s.", argument, d->host ); diff -Naur Rom24/src/db.c Rom24Timelock/src/db.c --- Rom24/src/db.c 2006-02-20 19:50:07.000000000 +0200 +++ Rom24Timelock/src/db.c 2006-02-20 18:29:37.000000000 +0200 @@ -383,6 +383,7 @@ load_notes( ); load_bans(); load_songs(); + load_timelocks(); } return; diff -Naur Rom24/src/merc.h Rom24Timelock/src/merc.h --- Rom24/src/merc.h 2006-02-20 19:50:07.000000000 +0200 +++ Rom24Timelock/src/merc.h 2006-02-20 19:52:45.000000000 +0200 @@ -99,6 +99,7 @@ typedef struct shop_data SHOP_DATA; typedef struct time_info_data TIME_INFO_DATA; typedef struct weather_data WEATHER_DATA; +typedef struct timelock_data TIMELOCK_DATA; @@ -189,7 +190,25 @@ char * string; /* buffer's string */ }; - +/** + * Timelock stuff, added by RuntuGen + * This struct holds timelock information: it holds the + * legal times for the MUD to be open. We use a very simple bit manipulation + * to store the values + * day hour min + * 000 00000 000000 (of an int) + * */ + +#define TIMELOCK_MKTIME(d,h,m) (d << 11 | h << 6 | m) +#define TIMELOCK_GETDAY(t) (t & 0x3800 >> 11) +#define TIMELOCK_GETHOUR(t) (t & 0x7C0 >> 6) +#define TIMELOCK_GETMINUTE(t) (t & 0x3F) +struct timelock_data { + TIMELOCK_DATA* next; + bool valid; + unsigned int from, to; +}; + /* * Time and weather stuff. @@ -2057,6 +2076,7 @@ #define SHUTDOWN_FILE "shutdown.txt"/* For 'shutdown'*/ #define BAN_FILE "ban.txt" #define MUSIC_FILE "music.txt" +#define TIMELOCK_FILE "timelock.txt" diff -Naur Rom24/src/recycle.c Rom24Timelock/src/recycle.c --- Rom24/src/recycle.c 2006-02-20 19:50:07.000000000 +0200 +++ Rom24Timelock/src/recycle.c 2006-02-20 18:29:04.000000000 +0200 @@ -72,7 +72,38 @@ note_free = note; } - +/* stuff for return timelock structures */ +TIMELOCK_DATA* timelock_free; + +TIMELOCK_DATA* new_timelock( void ) +{ + static TIMELOCK_DATA timelock_zero; + TIMELOCK_DATA* timelock; + + if ( timelock_free == NULL ) + timelock = alloc_perm( sizeof( *timelock ) ); + else + { + timelock = timelock_free; + timelock_free = timelock_free->next; + } + + *timelock = timelock_zero; + VALIDATE(timelock); + return timelock; +} + +void free_timelock(TIMELOCK_DATA *timelock) +{ + if (!IS_VALID(timelock)) + return; + + INVALIDATE(timelock); + + timelock->next = timelock_free; + timelock_free = timelock; +} + /* stuff for recycling ban structures */ BAN_DATA *ban_free; diff -Naur Rom24/src/recycle.h Rom24Timelock/src/recycle.h --- Rom24/src/recycle.h 2006-02-20 19:50:07.000000000 +0200 +++ Rom24Timelock/src/recycle.h 2006-02-20 18:54:55.000000000 +0200 @@ -46,6 +46,12 @@ void free_note args( (NOTE_DATA *note) ); #undef ND +/* timelock data recycling */ +#define TD TIMELOCK_DATA +TD *new_timelock args( ( void ) ); +void free_timelock args( ( TIMELOCK_DATA* timelock ) ); +#undef TD + /* ban data recycling */ #define BD BAN_DATA BD *new_ban args( (void) ); diff -Naur Rom24/src/timelock.c Rom24Timelock/src/timelock.c --- Rom24/src/timelock.c 1970-01-01 02:00:00.000000000 +0200 +++ Rom24Timelock/src/timelock.c 2006-02-20 18:17:00.000000000 +0200 @@ -0,0 +1,62 @@ +#include <stdlib.h> +#include <time.h> +#include <stdio.h> +#include <string.h> + +#include "merc.h" +#include "recycle.h" + +TIMELOCK_DATA* timelock_list = NULL; + +void load_timelocks( void ) +{ + //format is simple + //fromday fromhour frommin - today tohour tomin + FILE* fp; + TIMELOCK_DATA* tlock = NULL; + + if ( ( fp = fopen( TIMELOCK_FILE, "r" ) ) == NULL) + { + log_string("Could not load timelock file."); + return; + } + + while (!feof(fp)) + { + tlock = (TIMELOCK_DATA*)new_timelock(); + + tlock->from = TIMELOCK_MKTIME( fread_number(fp) , fread_number(fp) , fread_number(fp) ); + fread_letter(fp); + tlock->to = TIMELOCK_MKTIME( fread_number(fp) , fread_number(fp) , fread_number(fp) ); + fread_to_eol(fp); + + tlock->next = timelock_list; + timelock_list = tlock; + } + + fclose( fp ); +} + +int check_timelock( void ) +{ + time_t ts; + struct tm t; + TIMELOCK_DATA* td; + int res = -1; + unsigned int current = 0; + + time(&ts); + localtime_r(&ts, &t); + current = TIMELOCK_MKTIME( t.tm_wday , t.tm_hour , t.tm_min ); + + for ( td = timelock_list; td; td = td->next ) + { + if ( td->from <= current && current <= td->to ) + { + res = 0; + break; + } + } + + return res; +}