User Name:


Forgot your password?
Vote for Us!
tintin++ ogg sound player script for linux
Author: Robert Smith
Submitted by: Vladaar
6Dragons ogg Soundpack
Author: Vladaar
Submitted by: Vladaar
6Dragons 4.4
Author: Vladaar
Submitted by: Vladaar
LoP 1.46
Author: Remcon
Submitted by: Remcon
LOP 1.45
Author: Remcon
Submitted by: Remcon
Users Online
CommonCrawl, DotBot, Yandex, Bing

Members: 0
Guests: 7
Newest Member
Today's Birthdays
There are no member birthdays today.
Related Links
» SmaugMuds.org » Codebases » SmaugFUSS » Files that don't get closed w...
Forum Rules | Mark all | Recent Posts

Files that don't get closed will eventually lock out players
< Newer Topic :: Older Topic > Hi Priority bug as far as my mud co

Pages:<< prev 1 next >>
Post is unread #1 Aug 20, 2005, 4:13 pm
Go to the top of the page
Go to the bottom of the page

JoinedMay 8, 2005

Rogue wrote this snippet for distribution after resolving the problem on our mud for us this way.

In SmaugFUSS (presumably in Smaug 1.4a as well) there is a known bug in which after awhile too many files will have been left open to continue opeing any more files.

This results in returning players being told that they can not log on because their character does not exist and that the name is now illegal as well, it also results in players already online not being able to save (though they will still see the standard 'ok' when they try to do so.) Sadly, this also results in immortals currently online being spammed to death by bug reports and many other things not saving properly, as well as having the last log reset.

The attached snippet fixes all of these errors by watching for files that get opened and if they are not closed after a few seconds, it closes them. This snippet also outputs to your log file the names of each file being opened and closed and whether it was opened or closed so that you can see the sequence thereof and ensure nothing is being missed. There are a few special case files which appear to need to remain opened, but that is addressed here as well.

Many thanks to Rogue for providing this wonderful fix to the mud community. However, please be warned that this snippet has thus far only been tested on our own mud which is a heavily modified version of SmaugFUSS 1.6 but the nature of this snippet should allow it to work as written on any smaug mud.

/* (c) 2005 By Rogue. Use this software any way you want.. just don't be stingy
(This is a message for anybody who might possibly get their hands on this ..
ever). If you make cool changes, submit them online, somewhere where people
have easy access to it (a website)

Install instructions: Copy/paste the stuff from this file to your base */

/* add to mud.h */
// {{{ File Manipulation structure and support functions
// Support functions are defined in misc.cpp
typedef struct  {
        char *buf[1024];
        FILE *ints[1024];
        int downcount[1024];
        int lastbuf;
        int size;
} filemanipulation;
extern void fmanipsetup();
extern FILE *fmanipopenf(char *fname, char *file_desc);
extern void fmanipclosef(FILE *file_desc, int reallyclose);
extern void fmanipreportOpen();
extern filemanipulation fmanip;
#define fopen2(x, y) (fmanipopenf(x, y))
#define fclose2(x) (fmanipclosef(x, 1))
// }}}
/* pretty much anywhere after the includes, before all the massive 
typedef struct references.......

Supporting functions in misc.cpp

right after the includes is just fine. */
#define EXTRAWMESSAGES // undefine this to remove all the open/close messages
//simply erasing it is enough

//Set up the file wrapper, set default values {{{
//call this from int main() { .... };
void fmanipsetup() {
        printf("Setting up file wrapper\n\r";);
        //this could all be used to potentially build a real DB interface
        //to SQL and such
        int x;
        for(x = 0;x < 1024; x++) fmanip.buf[x] = NULL;
        for(x = 0;x < 1024; x++) fmanip.downcount[x] = 0; //actually counts up
        fmanip.lastbuf = 0;
        fmanip.size = 0;
// }}}
// Open a file, encapsulates fopen() {{{
//this is called by the macro: fopen2(char *filename, char *method);
FILE *fmanipopenf(char *fname, char *opts) {
        FILE *x = fopen(fname, opts);
        fmanip.buf[fmanip.size] = (char *)malloc(strlen(fname));
        strncpy(fmanip.buf[fmanip.size],(const char *) fname, strlen(fname));
        fmanip.ints[fmanip.size] = x;
        printf("%s OPENED \n\r", fmanip.buf[fmanip.size]);
        fmanip.size += 1;
        fmanip.lastbuf += 1;
        //if a file doesn't exist, automatically close it.
        //that's one of the things that wasn't happening before.
        if(!x) fmanipclosef(x, 0);
        return x;

// }}}
//Close a file, remove {{{ it from the arrays, try to close it if it's not a null
//oh, it also, very very simply, pushes eveything down the list when something
//is erased from it. This ensures the oldest ones will be at the bottom
//and the newest ones at the top. It also allows very easy re-use

/* Called by the macro: fclose2(FILE) */
void fmanipclosef(FILE *file_desc) {
        int x = 0;
        bool freed = FALSE;
        for(; x < fmanip.size; x++) {
                if(file_desc == fmanip.ints[x]) {
                        int y = x+1;
                        if(freed == FALSE) {
                                printf("%s CLOSED \n\r", fmanip.buf[x]);
//                              if(fmanip.buf[x] != NULL)
                                memset(fmanip.buf[x], 0, sizeof(fmanip.buf[x]));
                                free(fmanip.buf[x]); // do free this
                                freed = TRUE;
                        for(; y < fmanip.size; y++) {
                                fmanip.ints[y-1] = fmanip.ints[y];
                                fmanip.buf[y-1] = fmanip.buf[y];
        if(!file_desc) ;
        fmanip.size = fmanip.size -1;
//free(file_desc); don't free it
// }}}
// report files that failed to close and close then {{{
//this function is run on a timer called every 1 second (in smaug update.c)
// --pulse_second  ;
void fmanipreportOpen() {
        int x = 0;
        for(; x < fmanip.size; x++) {
                printf("%s \n\r", fmanip.buf[x]);
                fmanip.downcount[x] += 1;
                if(fmanip.downcount[x] > 10) {
                        if(!fmanip.ints[x]) {
                                printf("LOG: NULL file failed to close itself: %s \n\r", fmanip.buf[x])
                                fmanipclosef(fmanip.ints[x], 0);
                        } else {
                                printf("LOG: NON NULL file failed to close itself: %s \n\r", fmanip.buf[x]);
                                fmanipclosef(fmanip.ints[x], 1);
// }}}

btw, Rogue had told me that he'd come up with a revision to this, but I don't know what it entails as he never got back to me with the updated info, so if any of the great and powerful gurus amongst us (Samson, Remcon, etc) want to double check this... well, you're quite welcome. :)
Pages:<< prev 1 next >>