当前位置: 首页>>代码示例>>Python>>正文


Python Server.console方法代码示例

本文整理汇总了Python中server.Server.console方法的典型用法代码示例。如果您正苦于以下问题:Python Server.console方法的具体用法?Python Server.console怎么用?Python Server.console使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在server.Server的用法示例。


在下文中一共展示了Server.console方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: BaskitCLI

# 需要导入模块: from server import Server [as 别名]
# 或者: from server.Server import console [as 别名]
class BaskitCLI(cmd.Cmd):
    prompt = 'baskit> '
    server = None
    
    def __init__(self):
        cmd.Cmd.__init__(self)
        self.server = Server()
        
        # This is some initialization stuff to make sure that the directory
        # structure that baskit expects is in place.
        for item in [self.server.env,
                     os.path.join(self.server.env, 'archive', 'backups'),
                     os.path.join(self.server.env, 'archive', 'snaps'),
                     os.path.join(self.server.env, 'persistent'),
                     os.path.join(self.server.env, 'env')]:
            if not os.path.exists(item):
                os.makedirs(item)


    def do_help(self, s):
        if s == '': self.onecmd('help help')
        else:
            cmd.Cmd.do_help(self, s) 

    

    def help_help(self):
        print '''Welcome to the Baskit Minecraft Server Manager!
        
        Baskit is designed to be a minimalistic, yet powerful server management
        system.  Baskit uses GNU-Screen at the heart of the application and
        simply wrap around that.  This means that you can perform in-place
        upgrades of Baskit, or even remove it completely without worry of it
        impacting the running server. There are a lot of functions available to 
        help assist you in managing the server as well, below is a high-level
        list of what is available.  For further detail (including avalable
        options) for any command, type help [COMMAND].

        start                       Starts the server.
        
        stop                        Stops the server.

        restart                     Restarts the server.

        server                      Returns the running state & server binary
                                    information that we have on-hand about
                                    the running server.

        cmd [COMMAND]               Sends the command specified to the server.
                                    There is no limit as to what can be sent
                                    here, and it is quite easy to script
                                    commands into the server with this.

        players                     Returns the list of players currently logged
                                    into the server.

        console                     Will drop you directly into the server
                                    console.  From here you are directly
                                    interacting with the server.  To detach from
                                    the server console, hit CNTRL+A,D to exit.

        update                      Allows you to update the server binary based
                                    on the conditions you had specified.  It's 
                                    highly recommended you run help update to
                                    get some more detail.

        backup                      All backup related functions are housed
                                    within the backup command.  Running "backup"
                                    will present it's help.

        snapshot                    All snapshot related functions are housed
                                    within the snapshot command.  Running
                                    "snapshot" will present it's help.

        sync                        Handles syncing to/from ramdisk and
                                    persistent storage if ramdisk support is
                                    enabled (disabled by default)
        '''
    

    def do_exit(self, s):
        '''exit
        Exits the interactive CLI
        '''
        return True
    

    def do_cmd(self, s):
        '''cmd [COMMAND]
        Sends the specified command to the Minecraft server console
        '''
        self.server.command(s)
        print 'Sent to console: %s' % s
    

    def do_players(self, s):
        '''players
        Retuns a list of the currently connected players
        '''
        if not self.server.running():
#.........这里部分代码省略.........
开发者ID:SteveMcGrath,项目名称:baskit,代码行数:103,代码来源:cli.py

示例2: __init__

# 需要导入模块: from server import Server [as 别名]
# 或者: from server.Server import console [as 别名]

#.........这里部分代码省略.........
						if result == False:
							return False
					except:
						self.log.error("Plugin '%s' errored out when executing callback event '%s':" % (pluginID, event))
						for line in traceback.format_exc().split("\n"):
							self.log.error(line)
		except:
			self.log.error("A serious runtime error occurred - if you notice any strange behaviour, please restart immediately")
		return True
	def playerCommand(self, payload):
		self.log.info("%s executed: /%s %s" % (str(payload["player"]), payload["command"], " ".join(payload["args"])))
		def args(i):
			try: return payload["args"][i]
			except: return ""
		def argsAfter(i):
			try: return " ".join(payload["args"][i:])
			except: return ""
		if payload["command"] == "wrapper":
			player = payload["player"]
			buildString = self.getBuildString()
			if len(args(0)) > 0:
				subcommand = args(0)
				if subcommand == "update":
					player.message({"text": "Checking for new Wrapper.py updates...","color":"yellow"})
					update = self.checkForNewUpdate()
					if update:
						version, build, type = update
						player.message("&bNew Wrapper.py Version %s (Build #%d) available!)" % (".".join([str(_) for _ in version]), build))
						player.message("&bYou are currently on %s." % self.getBuildString())
						player.message("&aPerforming update...")
						if self.performUpdate(version, build, type):
							player.message("&aUpdate completed! Version %s #%d (%s) is now installed. Please reboot Wrapper.py to apply changes." % (version, build, type))
						else:
							player.message("&cAn error occured while performing update. Please check the Wrapper.py console as soon as possible for an explanation and traceback. If you are unsure of the cause, please file a bug report on http://github.com/benbaptist/minecraft-wrapper with the traceback.")
					else:
						player.message("&cNo new Wrapper.py versions available.")
				else:
					player.message("&cUnknown sub-command /wrapper '%s'." % subcommand)
			else:
				player.message({"text": "Wrapper.py Version %s" % (buildString), "color": "gray", "italic": True})
			return False
		if payload["command"] in ("plugins", "pl"):
			player = payload["player"]
			if player.isOp():
				player.message({"text": "List of plugins installed:", "color": "red", "italic": True})
				for id in self.plugins:
					plugin = self.plugins[id]
					if plugin["good"]:
						name = plugin["name"]
						version = plugin["version"]
						summary = plugin["summary"]
						description = plugin["description"]
					else:
						name = id
						version = None
						summary = None
						description = ""
					if summary == None:
						summary = {"text": "No description is available for this plugin", "color": "gray", "italic": True, 
							"hoverEvent": {"action": "show_text", "value": description}}
					else:
						summary = {"text": summary, "color": "white", "hoverEvent": {"action": "show_text", "value": description}}
					
					if version == None: version = "v?.?"
					else: version = ".".join([str(_) for _ in version])
					if plugin["good"]:
开发者ID:eristoddle,项目名称:minecraft-wrapper,代码行数:70,代码来源:__main__.py

示例3: __init__

# 需要导入模块: from server import Server [as 别名]
# 或者: from server.Server import console [as 别名]

#.........这里部分代码省略.........
			commandName = payload["command"]
			if commandName in self.commands[pluginID]:
				try:
					command = self.commands[pluginID][commandName]
					if player.hasPermission(command["permission"]):
						command["callback"](payload["player"], payload["args"])
					else:
						player.message({"translate": "commands.generic.permission", "color": "red"})
					return False
				except:
					self.log.error("Plugin '%s' errored out when executing command: '<%s> /%s':" % (pluginID, payload["player"], command))
					for line in traceback.format_exc().split("\n"):
						self.log.error(line)
					payload["player"].message({"text": "An internal error occurred on the server side while trying to execute this command. Apologies.", "color": "red"})
					return False
		if payload["command"] == "wrapper":
			if not player.isOp():
				player.message({"text": "Unknown command. Try /help for a list of commands", "color": "red"})
				return False
			buildString = self.getBuildString()
			if len(args(0)) > 0:
				subcommand = args(0)
				if subcommand == "update":
					player.message({"text": "Checking for new Wrapper.py updates...","color":"yellow"})
					update = self.checkForNewUpdate()
					if update:
						version, build, type = update
						player.message("&bNew Wrapper.py Version %s (Build #%d) available!)" % (".".join([str(_) for _ in version]), build))
						player.message("&bYou are currently on %s." % self.getBuildString())
						player.message("&aPerforming update...")
						if self.performUpdate(version, build, type):
							player.message("&aUpdate completed! Version %s #%d (%s) is now installed. Please reboot Wrapper.py to apply changes." % (version, build, type))
						else:
							player.message("&cAn error occured while performing update. Please check the Wrapper.py console as soon as possible for an explanation and traceback. If you are unsure of the cause, please file a bug report on http://github.com/benbaptist/minecraft-wrapper with the traceback.")
					else:
						player.message("&cNo new Wrapper.py versions available.")
				elif subcommand == "halt":
					player.message("&cHalting Wrapper.py... goodbye!")
					self.shutdown()
				elif subcommand in ("mem", "memory"):
					if self.server.getMemoryUsage():
						player.message("&cServer Memory: %d bytes" % self.server.getMemoryUsage())
					else:
						player.message("&cError: Couldn't retrieve memory usage for an unknown reason")
				elif subcommand == "random":
					player.message("&cRandom number: &a%d" % random.randrange(0, 99999999))
				else:
					player.message("&cUnknown sub-command /wrapper '%s'." % subcommand)
		if payload["command"] in ("plugins", "pl"):
			if player.isOp():
				player.message({"text": "List of plugins installed:", "color": "red", "italic": True})
				for id in self.plugins:
					plugin = self.plugins[id]
					if plugin["good"]:
						name = plugin["name"]
						version = plugin["version"]
						summary = plugin["summary"]
						description = plugin["description"]
					else:
						name = id
						version = None
						summary = None
						description = ""
					if summary == None:
						summary = {"text": "No description is available for this plugin", "color": "gray", "italic": True, 
							"hoverEvent": {"action": "show_text", "value": description}}
开发者ID:gitter-badger,项目名称:minecraft-wrapper,代码行数:70,代码来源:__main__.py


注:本文中的server.Server.console方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。