askuri / dynmaps

XAseco mod to save resources when running with thousands of tracks
GNU General Public License v3.0
4 stars 2 forks source link

making track cache won't work #3

Closed dassschaf closed 5 years ago

dassschaf commented 5 years ago

Under Windows 10 + XAMPP (php 7).

XASECO wouldn't launch because of a uncaught DivisionByZeroException occouring due to glob() returning an empty array for the track cache, although 9930 tracks are avaliable there. I got it working now by replacing glob() by a handwritten function that uses scandir() and then checks the array of files with a loop and if the filename ends on .Challenge.Gbx it's added to an array that'll be returned at the end of the function.

askuri commented 5 years ago

Are you sure you are using the correct folder? I'll quickly set up a server again so I can test it. Maybe you can show me the modifications you made also.

dassschaf commented 5 years ago

it is the correct folder - it worked without renaming folder or anything.

askuri.dynmaps.php - line 75:

// Get available maps for buffering
$this->maps = $this->makeTrackArray($aseco);

askuri.dynmaps.php - at the end of the dyn class:

    public function makeTrackArray($aseco) {
        $list = [];
        $trackdir = $aseco->server->trackdir . '\\dynmaps\\';

        $filelist = scandir($trackdir);

        if ($filelist == false)
            trigger_error('File search in track directory failed!', E_USER_ERROR);

        else {
            // moar random.
            shuffle($filelist);

            foreach ($filelist as $number => $filename) {
                $rev_needle = strrev('.Challenge.Gbx');
                $rev_haystack = strrev($filename);

                if (stripos($rev_haystack, $rev_needle) == 0) {
                    // file *is* a challenge.gbx, add to list
                    array_push($list, $trackdir . $filename);
                }
            }
            return $list;
        }
    }
askuri commented 5 years ago

I'm taking a look at the whole thing again and will do a quick rework. Before we start working on the same thing, wait a bit. I will push my work as soon as it's done.

askuri commented 5 years ago

I have pushed a new version that should fix errors regarding first start when no cache file is present. However, I have not stumbled across your error. Maybe you can try again with my latest commit and let me know if it works? If the same error occurs again, please tell me the exact line number and a stack trace if there is one.

dassschaf commented 5 years ago

The same error occours as before with the initial version I used.

[09/26,14:21:09] [DynMaps] Checking if buffering is needed ...
[09/26,14:21:09] [DynMaps] Adding                                                                                       
PHP Fatal error:  Uncaught DivisionByZeroError: Modulo by zero in E:\TEMP\xaseco dynamap\plugins\askuri.dynmaps.php:116 
Stack trace:                                                                                                            
#0 E:\TEMP\xaseco dynamap\plugins\askuri.dynmaps.php(80): dyn->bufferMaps()                                           
#1 E:\TEMP\xaseco dynamap\plugins\askuri.dynmaps.php(195): dyn->dyn(Object(Aseco))                                      
#2 E:\TEMP\xaseco dynamap\aseco.php(1249): dyn_init(Object(Aseco), NULL)                                                
#3 E:\TEMP\xaseco dynamap\aseco.php(942): Aseco->releaseEvent('onSync', NULL)                                           
#4 E:\TEMP\xaseco dynamap\aseco.php(735): Aseco->serverSync()                                                           
#5 E:\TEMP\xaseco dynamap\aseco.php(2562): Aseco->run('config.xml')                                                     
#6 {main}                                                                                                                 
    thrown in E:\TEMP\xaseco dynamap\plugins\askuri.dynmaps.php on line 116     

Fatal error: Uncaught DivisionByZeroError: Modulo by zero in E:\TEMP\xaseco dynamap\plugins\askuri.dynmaps.php:116      
Stack trace:                                                                                                            
#0 E:\TEMP\xaseco dynamap\plugins\askuri.dynmaps.php(80): dyn->bufferMaps()                                             
#1 E:\TEMP\xaseco dynamap\plugins\askuri.dynmaps.php(195): dyn->dyn(Object(Aseco))                                      
#2 E:\TEMP\xaseco dynamap\aseco.php(1249): dyn_init(Object(Aseco), NULL)                                                
#3 E:\TEMP\xaseco dynamap\aseco.php(942): Aseco->releaseEvent('onSync', NULL)                                           
#4 E:\TEMP\xaseco dynamap\aseco.php(735): Aseco->serverSync()                                                           
#5 E:\TEMP\xaseco dynamap\aseco.php(2562): Aseco->run('config.xml')                                                     
#6 {main}                                                                                                                 
    thrown in E:\TEMP\xaseco dynamap\plugins\askuri.dynmaps.php on line 116
askuri commented 5 years ago

There must be something wrong with the paths. Please put this just after the glob() in line 77:

        if (!$this->maps) {
            trigger_error('[DynMaps] No maps found in '.$this->mapdir.'Challenges/dynmaps! Please place at least one map there or disable this plugin.');
        }

And check if there is really no typo in the path.

Update: maybe you have your tracks in folders inside "Challenges/dynmaps"? That doesn't work currently due to the glob function.

dassschaf commented 5 years ago

the tracks are all in GameData\Tracks\dynmaps, they're definitely not in the wrong place Anmerkung 2019-09-26 150746

adding those three lines comes to the same result as what I posted earlier just with different line numbers obviously - I replaced said with print_r($this->maps); and apparently the maps array is empty:

[09/26,15:11:45] [DBTOOLS] Sync complete. Type "/dbtools" to start.                                                     Array                                                                                                                  
(                                                                                                                       
)                                                                                                                       
[09/26,15:11:45] [DynMaps] Checking if buffering is needed ...                                                          
[09/26,15:11:45] [DynMaps] Adding                                                                                       
PHP Fatal error:  Uncaught DivisionByZeroError: Modulo by zero in E:\TEMP\xaseco dynamap\plugins\askuri.dynmaps.php:119 
Stack trace: ...
askuri commented 5 years ago

Okay. So in your fix above you have used back-slashes while I use forward slashes. Can you kindly change my argument to the glob function so that it also uses back slashes? I've always used forward slashes on windows in php without a problem but maybe glob is special. Or your php version has a bug.

dassschaf commented 5 years ago

Glob with backslashes results in the same, assuming $this->maps = glob($this->mapdir.'Challenges\\dynmaps\\*.Challenge.Gbx'); is the correctly changed line.

askuri commented 5 years ago

So there is only one possibility left: what does $this->mapdir contain? Otherwise it must be a php bug.

dassschaf commented 5 years ago

$this->mapdir contains "E:\TEMP\server\GameData\Tracks\", so what it should contain - I guess it's a php bug at this point or the php version coming with XAMPP being weird.

askuri commented 5 years ago

It's not. $this->mapdir is missing the last slash for some reason. So it's inconsistent behaviour. Strangely $aseco->server->trackdir appends a slash it seems. Otherwise your code above wouldn't work?

dassschaf commented 5 years ago

there is a slash at the end, I typed wrongly - went missing as it was escaping the last quote due to markdown. mea culpa.

askuri commented 5 years ago

Oh man I found it. Glob is case sensitive, even on Windows. Your files have lowercase .gbx, while we are trying to match .Gbx. Uppercase .Gbx is the standard as far as I know. Altough, I think it makes sense to be case-insensitive on any OS. Changing the argument of glob to this "case insensitive" pattern should do the trick: $this->mapdir.'Challenges/dynmaps/*.[Cc]hallenge.[Gg]bx

dassschaf commented 5 years ago

I tried this now, even tried with just *.Challenge.gbx as the files are named like that and I still get an empty array somehow.

askuri commented 5 years ago

I was just as blind as you. You have created the folder in GameData/Tracks/dynmaps while it should be GameData/Tracks/Challenges/dynmaps image And your code worked because you have used a different folder than me.

dassschaf commented 5 years ago

oh... that now worked. I guess that' solved now.