Example #1
0
def init(serverPK):
    """ Init the given server.  """
    mcServer = MinecraftServer.objects.get(pk = serverPK)
    # Get the class type that is the right type
    stype = getServerFromModel(mcServer = mcServer)
    # Server interaction object
    server = stype(mcServer = mcServer)
    # Run the init 
    server.localInit()
Example #2
0
def status(serverPK):
    """ Start a server """
    # Get model objects
    mcServer = MinecraftServer.objects.get(pk = serverPK)
    # Get the class type that is the right type
    stype = getServerFromModel(mcServer = mcServer)
    # Server interaction object
    server = stype(mcServer = mcServer)
    
    return server.localStatus()
Example #3
0
def stop(serverPK, warn = True, warnDelaySeconds = 0):
    """ Start a server """
    # Get model objects
    mcServer = MinecraftServer.objects.get(pk = serverPK)
    # Get the class type that is the right type
    stype = getServerFromModel(mcServer = mcServer)
    # Server interaction object
    server = stype(mcServer = mcServer)
    
    return server.localStopServer(warn = warn, warnDelaySeconds = warnDelaySeconds)
Example #4
0
def save_map(serverPK, name, desc = '', version = '', owner = None):
    """ Save a map. Returns MapSave PK. """    
    # Get model objects
    mcServer = MinecraftServer.objects.get(pk = serverPK)
    # Get the class type that is the right type
    stype = getServerFromModel(mcServer = mcServer)
    # Server interaction object
    server = stype(mcServer = mcServer)
    
    mapPK = server.localSaveMap(name = name, desc = desc, version = version, owner = owner)
    
    return mapPK 
Example #5
0
def updateDB_MCConfig(configPK):
    """ Update the given server.properties config file  """
    mcp = MinecraftServerProperties.get(docid=configPK)

    mcServer = MinecraftServer.objects.get(pk=mcp.nc_minecraftServerPK)
    # Get the class type that is the right type
    stype = getServerFromModel(mcServer=mcServer)
    # Server interaction object
    server = stype(mcServer=mcServer)
    #     # Run the init
    #     server.localInit()
    cfg = ServerProperitiesConfigFileType(serverDir=server.getServerRoot(), minecraftServerObj=server)
    server.localUpdateDBConfigFile(cfg)
Example #6
0
def loadMap(serverPK, mapPK):
    """ Init the given server.  
    TODO: Add support for saving the existing map if one exists. 
    """
    # Get model objects
    mcServer = MinecraftServer.objects.get(pk = serverPK)
    mapSave = MapSave.objects.get(pk = mapPK)
    # Get the class type that is the right type
    stype = getServerFromModel(mcServer = mcServer)
    # Server interaction object
    server = stype(mcServer = mcServer)
    # Load the map
    server.localLoadMap(mapSave)
Example #7
0
def createFile_MCConfig(configPK):
    """ Update the given server.properties config file  """
    # FIXME: Add in file locking to prevent race conditions around this
    mcp = MinecraftServerProperties.get(docid=configPK)

    mcServer = MinecraftServer.objects.get(pk=mcp.nc_minecraftServerPK)
    # Get the class type that is the right type
    stype = getServerFromModel(mcServer=mcServer)
    # Server interaction object
    server = stype(mcServer=mcServer)
    #     # Run the init
    #     server.localInit()
    cfg = ServerProperitiesConfigFileType(serverDir=server.getServerRoot(), minecraftServerObj=server)
    server.localUpdateConfigFile(cfg, preChangeSHA512=None)
Example #8
0
def restart(serverPK, warn = True, warnDelaySeconds = 0):
    """ Restart a server """
    # Get model objects
    mcServer = MinecraftServer.objects.get(pk = serverPK)
    # Get the class type that is the right type
    stype = getServerFromModel(mcServer = mcServer)
    # Server interaction object
    server = stype(mcServer = mcServer)
    
    results=dict(start=None,stop=None)
    results['stop'] = stop(
                           serverPK = mcServer.pk,
                           warn = warn,
                           warnDelaySeconds = warnDelaySeconds,
                           )

    # Make sure the stop worked
    if results['stop']:
        results['start'] = start(serverPK = mcServer.pk)
    return results