Example #1
0
def process(ediparts, p):
	if len(ediparts) == 2: # Player wants waypoint set: WPT x,y
		wpid = config.min_player_wpid + p.id
		wppos = [int(x) for x in ediparts[1]]
		wptitle = config.player_wp_fmtstring.format(p=p)

		wp = waypoint.by_id(wpid)
		if not wp:
			wp = waypoint.Waypoint(wpid, wppos, wptitle)
			waypoint.all.append(wp)

		wp.owner = p.id

		network.to_ready(edicomm.encode('WPT', wpid, wppos, wptitle, p.id))
	elif len(ediparts) == 1: # Player wants waypoint deleted
		wpid = config.min_player_wpid + p.id

		wp = waypoint.by_id(wpid)
		if wp:
			waypoint.all.remove(wp)

		network.to_ready(edicomm.encode('WPT', wpid))
	else:
		print 'Malformed WPT: {0}'.format( edicomm.encode(ediparts) )
		raise EDIException(99, 'Wrong argument count!')
Example #2
0
    def new_nick(self, nick):
        if not self.nick:  # First-time setting?
            self.metanick = nick
            tok = auth.player_token(nick)
            tokens.append(tok)
            self.enqueue(edicomm.encode("TOK", tok))

        self.nick = nick
        self.enqueue(edicomm.encode("USN", nick))
Example #3
0
def process(ediparts, p):
	if len(ediparts) != 2:
		raise edicomm.EDIException(99, 'Wrong argument count!')

	# TODO: Validation!
	newname = ediparts[1]

	print 'Player', p.id, 'sets name to', newname, 'from', p.name

	p.name = newname

	network.to_ready(edicomm.encode('USN', p.id, p.name))

	p.ready = True

	nickmap = [edicomm.encode('USN', pl.id, pl.name) for pl in player.all if pl.ready]
	wpt_map = [edicomm.encode('WPT', wp.id, wp.position, wp.title, wp.owner) for wp in waypoint.all]

	p.enqueue('\n'.join(nickmap + wpt_map))
Example #4
0
def process(ediparts, p):
    if len(ediparts) != 2:
        raise edicomm.EDIException(99, "Wrong argument count!")

    desired_shot = [int(x) for x in ediparts[1]]

    network.to_observing_at(desired_shot, edicomm.encode("USF", p.id, desired_shot))

    # HACK: Quick and dirty "death" of player that gets shot
    for pl in player.all:
        if not pl.id == p.id and pl.contains(desired_shot):
            pl.position = locals.spawn
            pl.velocity = [0, 0]
Example #5
0
	def found_terminator(self):
		data = ''.join(self.recv_buffer)
		data = data.strip()

		if self.long_data:
			self.long_data = False
			self.set_terminator('\n')

			self.push(edicomm.encode('WAR', 2, 'Exited long data mode.'))

		messages.enqueue(self.addr, data)

		self.recv_buffer = []
Example #6
0
def wp_handler(str, cl):
	parts = str.split(' ', 4)

	if len(parts) == 1: # Just wp by itself lists waypoints
		print 'ID\ttitle\tposition'
		for wp in waypoint.all:
			print wp.id, '\t', wp.title, '\t', wp.position
	elif len(parts) == 2: # wp <wpid> deletes waypoints
		wpid = int(parts[1])
		wp = waypoint.by_id(wpid)

		if not wp:
			print 'No waypoint with id {0}'.format(wpid)
			return

		print 'Deleting waypoint {wp.id} at {wp.position} titled {wp.title}'.format(wp=wp)

		waypoint.all.remove(wp)
		network.to_ready(edicomm.encode('WPT', wpid))
	elif len(parts) == 4: # wp <id> <x,y> <title> makes/moves waypoints
		wpid = int(parts[1])
		wppos = [int(x) for x in parts[2].split(',')]
		wptitle = parts[3]

		wp = waypoint.by_id(wpid)

		if not wp:
			wp = waypoint.Waypoint(wpid, wppos, wptitle)
			waypoint.all.append(wp)

		wp.position = wppos
		wp.title = wptitle

		print 'Created/moved/named waypoint {wp.id} at {wp.position} titled {wp.title}'.format(wp=wp)

		network.to_ready(edicomm.encode('WPT', wpid, wppos, wptitle))
Example #7
0
def forget_handler(str, cl):
	parts = str.split(' ', 2)

	if len(parts) == 1:
		print 'Missing argument, try "help forget" for usage info.'
		return

	try:
		p = player.by_partial_name(parts[1])
	except PlayerAmbiguityError as e:
		print 'Found two players with same partial name: {e.p_one.name} and {e.p_two.name}'.format(e=e)
		return

	if not p:
		print 'Couldn\'t find player with prefix', parts[1]
		return

	# TODO: Should notify player of being kicked

	print 'Forgetting player', p.name
	network.to_ready( edicomm.encode( 'USD', p.id, 'Player kicked.' ) )
	player.all.remove(p)
Example #8
0
def check_input():
	global sock

	while True: # breakout by return a few lines below
		socks = select.select([sock], [], [], 0)

		if len(socks[0]) == 0:
			return

		try:
			data, addr = sock.recvfrom(1500)
		except socket.error:
			# Swallowing socket.error 10054 because UDP shouldn't f*****g care!
			continue

		data = data.strip()
		if data != '':
			print 'got data: ', data, 'from', addr

			try:
				actions.dispatch(edicomm.decode(data), addr)
			except edicomm.EDIException as e:
				sock.sendto(edicomm.encode('ERR', str(e.id), e.msg), addr)
Example #9
0
def process(ediparts, addr):
	if len(ediparts) != 2:
		raise edicomm.EDIException(99, 'Wrong argument count!')

	# TODO: Validation!
	token = ediparts[1]

	print 'Got new player with token', token

	if token not in player.tokens:
		player.tokens.append(token)

	newid = player.tokens.index(token)

	p = player.by_token(token)

	if not p:
		p = player.new_player(newid + 1, token)

	p.addr = addr
	p.enqueue(edicomm.encode('UID', p.id))

	print 'Player (token:', token, ') got id', p.id
Example #10
0
	def move(self):
		if not self.ready:
			return

		newpos = [int(vel / 10) + pos for(vel, pos) in zip(self.velocity, self.position)]

		if newpos[0] < 0 or newpos[0] > locals.width:
			self.velocity[0] = 0
			newpos[0] = self.position[0]
		if newpos[1] < 0 or newpos[1] > locals.height:
			self.velocity[1] = 0
			newpos[1] = self.position[1]

		newrot = self.rotation

		if self.velocity != [0,0]:
			newrot = degrees(atan2(self.velocity[0], self.velocity[1]))

		self.position = newpos
		self.rotation = newrot

		self.tank_rect.topleft = newpos

		network.to_observing(self, edicomm.encode('USP', self.id, self.position, self.rotation))
Example #11
0
	def set_long_data(self):
		self.long_data = True
		self.set_terminator('\n.\n')

		self.push(edicomm.encode('WAR', 1, 'Entering long data mode, end with "." by itself on a line.'))