Small tool to create map list

Discuss anything to do with Nexuiz here.

Moderators: Nexuiz Moderators, Moderators

Small tool to create map list

Postby vindimy » Wed Apr 08, 2009 7:20 am

Hey all,

I got sick of manually typing list of maps for my Openarena server, especially tracking all the numbers! So I sat down for half an hour and created a simple tool to generate that list! Incidentally, the tool also works for any other ioquake3-based game, so I'm posting it here as well!

Features:

* Reliably generate a map list
* Start from any number, not just 0
* Increment numbers by 5 if you'd like (useful if you're inserting more maps in between later)

Here it is:

http://oa.thedimi.net/tools/maplist-generator.php

I'll also post the source code below in case my server goes down:
Code: Select all
<?php
if (!empty($_REQUEST['source']))
{
   echo "<pre>";
   echo htmlspecialchars(file_get_contents($_SERVER['SCRIPT_FILENAME']));
   echo "</pre>";
   die();
}
?><html>
<head>
   <title>Openarena Map List Generator</title>
</head>
<body>
<pre>
[<a href="/">home</a>]


<b>Openarena Map List Generator</b>

   Put your list of maps in the textbox below, one map per line. Click submit, and you'll get a list of maps ready to go
into maps.cfg for your Openarena server. Also works for any Quake 3 or ioquake3 based games. Enjoy!

   <b>*Note:</b> <i>No more than 150 entries allowed, and each entry will be cut off at 50 characters!</i>

   <b>*Note:</b> <i>You can also <a target="_blank" href="<?php echo $PHP_SELF . "?source=1"; ?>">view source</a> of this tool!</i>

<form method="post" action="<?php echo $PHP_SELF; ?>">
<textarea name="maps" cols="80" rows="20"><?php echo htmlspecialchars($_REQUEST['maps']); ?></textarea>
(optional) start count at: <input type="text" name="start" value="<?php echo (empty($_REQUEST['start'])) ? 0 : htmlspecialchars($_REQUEST['start']);
?>"></input> (0 - 1000)
(optional) skip 5 numbers each count: <input type="checkbox" name="skip" value="surewhynot"<?php echo (isset($_REQUEST['skip'])) ? ' checked="checked"' : ' '; ?>></input>
<input type="submit" value=" Submit "></input>

<?php

/*

    Purpose: Generate a map configuration file for a server running a
             Quake 3-based or ioquake3-based game, such as Openarena.
    Creator: Dmitriy Vi (me AT thedimi . net)
    Version: 0.1

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.

*/

// These settings prevent potential overloading of the server by malicious users.
define("MAX_ENTRIES", 150);      // total number of entries to accept
define("MAX_ENTRY_LENGTH", 50);  // maximum number of characters per entry
define("MAX_START_AT", 1000);    // do not allow to start count from any number larger than this one

define("INCREMENT_BY", 5);       // some users like gaps in their map numbering sequence to insert more maps later

if (!empty($_REQUEST['maps']))
{
   $start_at = (is_numeric($_REQUEST['start']) && $_REQUEST['start'] > 0 && $_REQUEST['start'] < MAX_START_AT+1) ? $_REQUEST['start'] : 0;
   $j = $start_at;
   $incr_by = (isset($_REQUEST['skip']) && $_REQUEST['skip'] == "surewhynot") ? INCREMENT_BY : 1;

   $maps_arr = split("\n", htmlspecialchars($_REQUEST['maps']), MAX_ENTRIES+1);
   if (!empty($maps_arr[MAX_ENTRIES]))
      die ("ERROR: Can't process your request, too many entries!");

   echo "Here's your maps.cfg:\n\n//------------------------------\n";
   for ($i = 0; $i < count($maps_arr); $i++)
   {
      $last = ($j - count($maps_arr)*$incr_by + $incr_by == $start_at) ? $start_at : $j+$incr_by;
      printf("set m%04d \"map %s ; set nextmap vstr m%04d\"\n", $j, trim(substr($maps_arr[$i], 0, (MAX_ENTRY_LENGTH-1))), $last);
      $j += $incr_by;
   }
   printf("\nwait\n\nvstr m%04d", $start_at);
   echo "\n//------------------------------\n";
}
?>
</pre>
</body>
</html>
vindimy
Newbie
 
Posts: 4
Joined: Wed Apr 08, 2009 7:12 am

Postby GreEn`mArine » Wed Apr 08, 2009 8:09 am

Nexuiz is not based on OpenArena :)

Should maybe be moved to General Discussion
IRC quote:
[kojn] I've been coming a bit more recently
[kojn] she took it the dirty way
GreEn`mArine
Forum addon
 
Posts: 1509
Joined: Tue Feb 28, 2006 9:33 pm
Location: Germany

Postby esteel » Wed Apr 08, 2009 8:30 am

Nexuiz just uses pk3 files but none of the q3 variables controling the maplist.. Its also not based in q3/ioq3 but DarkPlaces which itself is a HEAVILY modifies quake (1 / ONE) engine
Thus that php file will not help unless someone would modify it.
esteel
Site admin and forum addon
 
Posts: 3924
Joined: Wed Mar 01, 2006 8:27 am

Postby vindimy » Wed Apr 08, 2009 5:44 pm

GreEn`mArine wrote:Nexuiz is not based on OpenArena :)


I never said that it is! :D However I did think that they are both based on ioquake3 (and haven't really confirmed that). What led me to think that is the fact that they all share the master server list provider (dpmaster.deathmask.net).

Well, it's a bummer that Nexuiz uses a different ways to rotate maps than Openarena & Quake 3 and ioquake3-based games... Can someone point me to the syntax? I might go ahead and modify my script to include Nexuiz syntax.
vindimy
Newbie
 
Posts: 4
Joined: Wed Apr 08, 2009 7:12 am

Postby esteel » Wed Apr 08, 2009 6:19 pm

You must have missed my post.. i clearly stated which engine its based upon :)

Nexuiz uses a variable g_maplist which simply contains all the bsp filenames (without the maps/ path and without the .bsp...
(e.g. g_maplist "runningman darkzone aggressor")
It will play from start to end of the list and warp around, however there are buildin ways so play it in random order or shuffle it. and ALSO the game uses a 'next map voting screen' by default that lets people choose from the map (from 6 randomly choosen maps of the maplist)
I'm not sure were a tool could really help here, but maybe i'm missing something..
esteel
Site admin and forum addon
 
Posts: 3924
Joined: Wed Mar 01, 2006 8:27 am

Postby vindimy » Wed Apr 08, 2009 6:28 pm

esteel wrote:You must have missed my post.. i clearly stated which engine its based upon :)


You must have missed my post.. I clearly stated that

I did think that they are both based on ioquake3 (and haven't really confirmed that).


Notice the "did" = past tense :D


In summary, since you indicate that Nexuiz doesn't require such tool, no further discussion is necessary :D Mods can go ahead and delete this topic :)
vindimy
Newbie
 
Posts: 4
Joined: Wed Apr 08, 2009 7:12 am

Postby [-z-] » Wed Apr 08, 2009 7:53 pm

I have actually written a bash script that will generate a list based on game type. I don't really use it anymore because I've separated my servers into a framework that will auto load files based on which folder they are in.

It's one of my first bash scripts, so it's probably not written as efficient as it could be but hey, it works.


Code: Select all
#!/bin/bash
#
# Title: Maplist Generator - Part of NST - Automaps
# Created By: Tyler "-z-" Mulligan of the Nexuiz Ninjaz (www.nexuizninjaz.com)
#
# usage: ./maplist [gametype] [directory]
#
# [gametype]:   (dm|tdm|ctf|lms|dom ... etc); default gametype is dm
#                              
# [directory] Create a maplist for a specific gametype based on the maps found
# in your data directory (default folder: ~/.nexuiz/data/) other than ~/.nexuiz/data
#

# Used to dynamically build a maplist based on the pk3's in your directory rather
# than rely on the g_maplist="" emergency override
function create_maplist {
  # Start the maplist string
  i="g_maplist=\""
 
  # Get Gametype
  if [[ "$1" != "" ]]; then
    t=$1
  else
    echo; echo "[WARNING] No gametype has been set, setting to dm"
    t="dm"
  fi
 
  # Handle Optional Directory Parameter
  if [[ "$2" != "" ]]; then
    if [[ -d "$2" ]]; then
      d=$2
    fi
  else
    d=~/.nexuiz/data
  fi

  # Get the a list of all properly packaged bsps
  for map in $(ls $d/*.pk3); do
   
    # Used to tell if the package mapinfo and generate map info exist
    m=false
    m2=false
   
    # List contents, grab the name of the bsp, remove the folder name, drop any bsp not in the maps folder
    mapname=$(unzip -l $map | grep .bsp | awk '{ print $4 }' | sed 's/maps\/\([A-Za-z_0-9.-]*\)\.bsp/\1/' | grep -vi .bsp)
    # If a map bsp is present
    if [[ "$mapname" != "" ]]; then
   
      # Check mapinfo's gametype against $t
      echo
      game_type=$(unzip -p $map maps/$mapname.mapinfo | grep "^type")
     
      if [[ "$game_type" != "" ]]; then
        echo "Checking package ($map) for mapinfo: [OK]"
        m=true
       
        game_type=$(unzip -p $map maps/$mapname.mapinfo | grep "^type $t")
        if [[ "$game_type" == "" ]]; then
          echo "Checking mapinfo for gametype compatiability ($mapname): [NO]"
        else
          # The mapinfo from the package has this gametype
          echo "Checking mapinfo for gametype compatiability ($mapname): [OK]"
        fi
      else
        echo "Checking package ($mapname) for mapinfo: [FAILED]"
      fi
     
      # If it doesn't exist, check the generated mapinfo folder
      if [[ "$game_type" == "" ]]; then
     
        echo "Checking ~/.nexuiz/data/data/maps/ for generated mapinfo: $mapname.mapinfo"
        cd ~/.nexuiz/data/data/maps/

        if [[ ! -r "$mapname.mapinfo" ]]; then
          echo "[WARNING] No generated mapinfo found for $mapname - not adding to list"
          status="warning"
        else
          # the generated mapinfo file exists
          echo "Check for generated $mapname.mapinfo file: [OK]"
          m2=true
                   
          game_type=$(grep "^type $t" $mapname.mapinfo)
         
          if [[ "$game_type" != "" ]]; then
            # The check for the generated mapinfo compatiability passed
            echo "Checking generated mapinfo for gametype compatiability ($t): [OK]"
          fi
        fi
      fi
     
      # Everything looks good, add it to the list.
      if [[ "$game_type" != "" ]]; then
        # Print with quotes and a comma then append to string 'i'
        echo "[ADDING] $mapname to the list"
        mapname="$t"\_"$mapname "
        i=$i$mapname
      else
        if [[ $m2 == true ]]; then
          echo "Checking generated mapinfo for gametype compatiability ($t): [NO]"
        fi
      fi

    fi
  done

  # Trim the last space and echo maplist
  i=$(echo $i | sed 's/ $//')
  i=$i"\""
 
  if [[ "$status" == "warning" ]]; then
    echo; echo "[WARNING] Some maps weren't added because no mapinfo files were found. Some maps may not be included! Restart Nexuiz to generate them automatically, then run this script again."
  fi
 
  echo; echo "-- Printing $t Maplist -----------"; echo; echo $i; echo
} # End create_maplist

create_maplist $1 $2
[-z-]
Site Admin and Nexuiz Ninja
 
Posts: 1794
Joined: Mon Nov 13, 2006 12:20 am
Location: Florida

Postby esteel » Wed Apr 08, 2009 8:24 pm

vindimy wrote:In summary, since you indicate that Nexuiz doesn't require such tool, no further discussion is necessary :D Mods can go ahead and delete this topic :)

Well i'm not the ultimo on map handling, maybe i overlook something.. Maybe someone else can need your work. I see no reason for anyone to delete that thread. Don't be so negative. Its good to see people trying to contribute and just because i do not see it being useful to me at the moment, does not mean noone has use for it :)
esteel
Site admin and forum addon
 
Posts: 3924
Joined: Wed Mar 01, 2006 8:27 am

Postby vindimy » Thu Apr 09, 2009 3:51 am

esteel wrote:Don't be so negative.

hey, i'm not negative :D it's common for forums to delete/archive threads that do not apply!

well, hopefully someone who decides to try Openarena could use my tool :D yeah, Openarena is awesome :D
vindimy
Newbie
 
Posts: 4
Joined: Wed Apr 08, 2009 7:12 am

Postby divVerent » Thu Apr 09, 2009 4:59 am

Also, someone who has a Nexuiz server could read this thread to the end, and see -z-'s script.

Also, a suggestion from me:

g_maplist ""

(clearing the maplist)

will cause the maplist to be automatically filled with ALL maps.
1. Open Notepad
2. Paste: ÿþMSMSMS
3. Save
4. Open the file in Notepad again

You can vary the number of "MS", so you can clearly see it's MS which is causing it.
divVerent
Site admin and keyboard killer
 
Posts: 3809
Joined: Thu Mar 02, 2006 4:46 pm
Location: BRLOGENSHFEGLE


Return to Nexuiz - General Discussion

Who is online

Users browsing this forum: No registered users and 1 guest

cron