def add_user(user, password):
	user = util.trim(user)
	login_id = util.alphanums(user)
	
	if len(login_id) == 0:
		return 0
	
	start = get_next_start_point()
	
	sector = str(start[0]) + '^' + str(start[1])
	location = str(start[2]) + '^' + str(start[3])
	
	user_id = sql.insert('INSERT INTO `user` (`name`, `login_id`, `password`, `hq_sector`, `hq_loc`, `research`) values (%s,%s,%s,%s,%s, 20)',
		(user, login_id, password, sector, location))
	
	sql.insert("INSERT INTO `resource_status` (`user_id`) VALUES (" + str(user_id) + ")")
	# place HQ
	build.do_build(
		user_id,
		util.md5(str(time.time()) + "automated")[:16],
		0,
		sector,
		location,
		'hq',
		False)
	
	return user_id
def add_user(user, password):
    user = util.trim(user)
    login_id = util.alphanums(user)

    if len(login_id) == 0:
        return 0

    start = get_next_start_point()

    sector = str(start[0]) + '^' + str(start[1])
    location = str(start[2]) + '^' + str(start[3])

    user_id = sql.insert(
        'INSERT INTO `user` (`name`, `login_id`, `password`, `hq_sector`, `hq_loc`, `research`) values (%s,%s,%s,%s,%s, 20)',
        (user, login_id, password, sector, location))

    sql.insert("INSERT INTO `resource_status` (`user_id`) VALUES (" +
               str(user_id) + ")")
    # place HQ
    build.do_build(user_id,
                   util.md5(str(time.time()) + "automated")[:16], 0, sector,
                   location, 'hq', False)

    return user_id
Beispiel #3
0
def do_things(action, args):
	
	if action == 'echo':
		return { 'success': True, 'data': args.get('data', None) }
	elif action == 'api_users':
		from serverlib import api
		return api.get_user_info()
	elif action == 'authenticate':
		return authenticate.heavy_authenticate(args.get('user', ''), args.get('password', ''), True)
	elif action == 'getuser':
		from serverlib import getuser
		return getuser.get_user(args.get('user_id_list', None))
		
	else:
		user_id = util.parseInt(args.get('user_id', 0))
		
		if authenticate.light_authenticate(user_id, args.get('password', '')):
			if action == 'poll':
				
				return poll.do_poll(user_id, args.get('sectors'))
			elif action == 'build':
				from serverlib import build
				return build.do_build(
					user_id,
					args.get('client_token'),
					args.get('last_id'),
					args.get('sector'),
					args.get('loc'),
					args.get('type'))
				
			elif action == 'demolish':
				from serverlib import demolish
				return demolish.do_demolish(
					user_id,
					args.get('last_id'),
					args.get('sector'),
					args.get('loc'),
					args.get('client_token'))
			elif action == 'radar':
				from serverlib import neighbors
				return neighbors.find_neighbors(
					user_id,
					args.get('rx', None),
					args.get('ry', None))
			elif action == 'research':
				from serverlib import research
				return research.apply_research(
					user_id,
					args.get('type', None))
			elif action == 'quarrydata':
				from serverlib import quarrydata
				return quarrydata.get_quarry_data(
					user_id,
					args.get('sector', None),
					args.get('xy', None))
			elif action == 'buildbot':
				from serverlib import producebot
				return producebot.produce_bot(
					user_id,
					args.get('type', 0))
			elif action == 'getbots':
				from serverlib import producebot
				return producebot.get_count(user_id)
			elif action == 'dispatchbots':
				from serverlib import producebot
				return producebot.dispatch(user_id)
			elif action == 'debug_resources':
				from serverlib import producebot
				return producebot.DEBUG_resources(user_id)
			elif action == 'start_research':
				from serverlib import research
				return research.apply_research(user_id, args.get('subject', None))
			elif action == 'alienkill':
				from serverlib import serverbattle
				return serverbattle.award_resources(
					user_id, args.get('alientype', 'x'))
			elif action == 'attacksuccess':
				from serverlib import serverbattle
				return serverbattle.award_bytes(
					user_id, args.get('attacked', 0), args.get('numbytes', 0))
			else:
				return { 'success': False, 'message': "Unrecognized command" }
		
		else:
			return { 'success': False, 'message': "Invalid username/password." }