Ejemplo n.º 1
0
	def event_loop(self):
		#Set up signal handlers
		signal.signal(signal.SIGINT, self.signal_handler)
		signal.signal(signal.SIGTERM, self.signal_handler)

		while not (self.flags&cflags['KILL_EVENT'] and self.kill):
			self.getflags()
			if self.flags:
				for name, flag in cflags.iteritems():
					if self.flags&flag:
						#Default handlers
						if flag in fhandles: fhandles[flag](self)
						#Plugin handlers
						for callback in self.plugin_handlers[flag]: callback(flag)
			if self.daemon:
				sys.stdout.flush()
				sys.stderr.flush()
Ejemplo n.º 2
0
	def event_loop(self):
		#Set up signal handlers
		signal.signal(signal.SIGINT, self.signal_handler)
		signal.signal(signal.SIGTERM, self.signal_handler)
		#Fire off plugins that need to run after init
		for callback in self.plugin_handlers[cflags['START_EVENT']]: callback(flag)

		while not (self.flags&cflags['KILL_EVENT'] and self.kill):
			self.getflags()
			if self.flags:
				for name, flag in cflags.iteritems():
					if self.flags&flag:
						#Default handlers
						if flag in fhandles: fhandles[flag](self)
						#Plugin handlers
						for callback in self.plugin_handlers[flag]: callback(flag)
			for index, timer in enumerate(self.timers):
				if timer.update():
					timer.fire()
				if not timer.check():
					del self.timers[index]
			if self.daemon:
				sys.stdout.flush()
				sys.stderr.flush()
Ejemplo n.º 3
0
	def __init__(self, **kwargs):
		#Grab some settings
		self.daemon = kwargs.get('daemon', False)
		self.logfile = kwargs.get('argfile', '')
		self.pidfile = kwargs.get('pidfile', '')
		plugins = kwargs.get('plugins', [])
		self.authenticated = kwargs.get('authenticated', True)
		self.bufsize = kwargs.get('bufsize', 4096)
		self.timeout = kwargs.get('timeout', 1)
		self.proxy = kwargs.get('proxy', {
			'enabled': False,
			'host': '',
			'port': 0,
			}
		)

		#Initialize plugin list
		#Plugins should never touch this
		self.plugin_handlers = {flag: [] for name, flag in cflags.iteritems()}
		self.plugin_dispatch = {ident: [] for ident in mcdata.structs}
		self.plugins = [plugin(self) for plugin in plugins]

		#Initialize socket and poll
		#Plugins should never touch these unless they know what they're doing
		self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
		self.sock.setblocking(0)
		self.poll = select.poll()
		self.poll.register(self.sock, smask)

		#Initialize Event Loop/Network variables
		#Plugins should generally not touch these
		self.encrypted = False
		self.kill = False
		self.auth_err = False
		self.login_err = False
		self.rbuff = bound_buffer.BoundBuffer()
		self.sbuff = ''
		self.flags = 0 #OK to read flags, not write

		#State variables
		#Plugins should read these (but generally not write)
		self.world = smpmap.World()
		self.world_time = {
			'world_age': 0,
			'time_of_day': 0,
		}
		self.position = {
			'x': 0,
			'y': 0,
			'z': 0,
			'stance': 0,
			'yaw': 0,
			'pitch': 0,
			'on_ground': False,
		}
		self.health = {
			'health': 20,
			'food': 20,
			'food_saturation': 5,
		}
		self.playerlist = {}
		self.entitylist = {}
		self.spawn_position = {
			'x': 0,
			'y': 0,
			'z': 0,
		}
		self.login_info = {}