Last active
June 14, 2022 21:32
-
-
Save connorjan/317d7583bd2fca77c1c7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import MySQLdb | |
import CSServer | |
import time | |
""" | |
This script will update your cs server's maplist file for you based on tiers that are stored in a database. | |
To get it to work, make sure that you have the 'CSServer.py' file in the same directory as this script, | |
then change the variables in the 'global variables' section as needed. | |
This will overwrite the map list file as needed, and will append changes to the new maps text file if enabled. | |
If you are on Linux, make sure to use the correct version of slash in the path strings! '/' for linux, '\\' for windows | |
Thanks, | |
Cowjan | |
""" | |
__author__ = "Connor G. (Cowjan)" | |
__copyright__ = "Copyright 2015" | |
__credits__ = ["Connor G. (Cowjan)"] | |
__license__ = "MIT" | |
__version__ = "1.0" | |
__maintainer__ = "Connor G. (Cowjan)" | |
__email__ = "cjg3259@rit.edu" | |
__status__ = "Production" | |
### GLOBAL VARIABLES ### | |
# Database Info | |
DATABASE_IP = "" # IP address of the database | |
DATABASE_NAME = "cksurf" # Name of the database to access at this server | |
DATABASE_USER = "root" # Username for the database | |
DATABASE_PASS = "" # Password for the database | |
DATABASE_TABLE = "ck_maptier" # Table where the tiers are located | |
DATABASE_TIER_FIELD_NAME = "tier" # Field name of the tier column in the database | |
DATABASE_MAP_FIELD_NAME = "mapname" # Field name of the map name column in the database | |
# Server Info | |
""" | |
Parameters: | |
MinTier: Minimum tier for the Server | |
MaxTier: Maximum tier for the Server | |
MapType: Prefix of the maps to look at | |
MapsFilePath: Directory to the map list file with respect to the location of this script | |
MapsDirectory: Path to the maps directory file with respect to the location of this script | |
FastDlServer (optional): Address for the fastdl server. If added it will check if the map is on this server before adding it to the map list file | |
""" | |
# Don't forget the commas at the end of each server declaration (not the last one)! | |
SERVERS = \ | |
[ | |
CSServer.CSServer(1, 3, "surf", "..\\surfzipcore\\csgo\\maps.txt", "..\\surfzipcore\\csgo\\maps", "http://vpsla1.site.nfoservers.com/maps/"), | |
CSServer.CSServer(2, 6, "surf", "..\\surfzipcore36\\csgo\\maps.txt", "..\\surfzipcore36\\csgo\\maps", "http://vpsla1.site.nfoservers.com/"), | |
CSServer.CSServer(1, 6, "surf", "..\\surfzipcoredonator\\csgo\\maps.txt", "..\\surfzipcoredonator\\csgo\\maps", "http://vpsla1.site.nfoservers.com/") | |
] | |
WRITE_MAPS_NEW_FILE = True # Whether or not to keep a log of the newly added maps. ( True | False ) | |
MAPS_NEW_FILE_PATH = "..\\maps_new.txt" # The path to the new maps log relative to this script | |
WRITE_MAP_ERRORS_FILE = True # Whether or not to keep a map error file. ( True | False ) | |
MAP_ERRORS_FILE_PATH = "..\\map_errors.txt" # The path to the map error file relative to this script | |
"""" ------------------------------------------------------------ | |
WARNING: YOU SHOULD NOT NEED TO EDIT ANYTHING BELOW THIS SECTION | |
-------------------------------------------------------------- """ | |
# Create a dictionary of map name to tier from the database | |
def GetTiers(): | |
cursor = DB.cursor() | |
cursor.execute("SELECT %s, %s FROM %s" % (DATABASE_MAP_FIELD_NAME, DATABASE_TIER_FIELD_NAME, DATABASE_TABLE)) | |
data = cursor.fetchall() | |
mapDict = dict() | |
for _map in data: | |
mapDict[_map[0]] = int(_map[1]) | |
return mapDict | |
# Write any new maps to a file | |
def WriteNewMaps(newMapsFilePath, linesToWrite): | |
if not linesToWrite: | |
return | |
with open(newMapsFilePath, "a+") as _file: | |
_file.write((time.strftime("%m/%d/%Y %I:%M:%S")) + '\n') | |
_file.write("-------------------" + '\n') | |
_file.write("\n".join(linesToWrite)) | |
_file.write('\n\n') | |
# Write map errors to file | |
def WriteMapErrors(mapErrorsFilePath, errors): | |
if not errors: | |
return | |
errorList = [] | |
for _map, errors in errors.iteritems(): | |
errorList.append("{0:30}: {1}".format(_map, " and ".join(errors))) | |
with open(mapErrorsFilePath, "w+") as _file: | |
_file.seek(0) | |
_file.truncate() | |
_file.write("\n".join(sorted(errorList))) | |
def main(): | |
global DB; | |
DB = MySQLdb.connect(DATABASE_IP, DATABASE_USER, DATABASE_PASS, DATABASE_NAME) | |
GetTierFromMapName = GetTiers() | |
DB.close() | |
for server in SERVERS: | |
server.MapsInDatabase = GetTierFromMapName | |
server.Update() # This is where most things happen | |
# Update new map file if we are configured for it | |
if WRITE_MAPS_NEW_FILE: | |
newMapsSet = set() | |
for server in SERVERS: | |
for _map in server.MapsNew: | |
newMapsSet.add(_map + " : Tier " + str(GetTierFromMapName[_map])) | |
WriteNewMaps(MAPS_NEW_FILE_PATH, sorted(list(newMapsSet))) | |
if WRITE_MAP_ERRORS_FILE: | |
allErrors = dict() | |
for server in SERVERS: | |
for _map,errors in server.MapErrors.iteritems(): | |
if not errors: | |
continue | |
if not _map in allErrors.keys(): | |
allErrors[_map] = set() | |
for error in errors: | |
allErrors[_map].add(error) | |
WriteMapErrors(MAP_ERRORS_FILE_PATH, allErrors) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment