Example #1
0
def main(cursor):
	battle_id	= int(common.get_val("battle", -1))
	unit_id		= int(common.get_val("unit", -1))
	army_id		= int(common.get_val("army", -1))
	amount		= int(common.get_val("amount", 0))
	
	if battle_id < 1:
		raise Exception("No battle supplied")
	
	if army_id < 1:
		raise Exception("No army supplied")
	
	if unit_id < 1:
		raise Exception("No unit supplied")
	
	if amount == 0:
		return ""
		raise Exception("No amount supplied")
	
	if amount < 0:
		return refund_losses(cursor, battle_id, unit_id, army_id, amount)
	
	# Get all handles and instances
	the_battle		= battle_q.get_one_battle(cursor, battle_id)
	battle_squads	= the_battle.get_squads(cursor)
	squad_dict		= squad_q.get_squads_from_army_and_unit(cursor, army_id, unit_id)
	
	squad_list = [s for s in battle_squads if s in squad_dict]
	
	# return str(squad_list)
	squad_f.apply_losses_to_squads(cursor, amount, squad_list, battle_id)
	return ""
Example #2
0
def main(cursor):
	team			= int(common.get_val("team", 0))
	name			= common.get_val("name", 0)
	city_location	= common.get_val("city_location", 0)
	text_location	= common.get_val("text_location", "")
	army_type		= int(common.get_val("type", 0))
	
	actual_x = 0
	actual_y = 0
	
	if text_location != "":
		actual_x = re.search(r"(-?[0-9]+)[,:] ?(-?[0-9]+)", text_location).groups()[0]
		actual_y = re.search(r"(-?[0-9]+)[,:] ?(-?[0-9]+)", text_location).groups()[1]
	else:
		the_city = city_q.get_one_city(city_location)
		
		actual_x = the_city['x']
		actual_y = the_city['y']
	
	database.query(cursor,
		army_f.new_army(name, team, actual_x, actual_y, army_type=army_type))
	
	# Redirect
	page_data['Redirect'] = 'list_armies&team={0:d}'.format(team)
	return ""
Example #3
0
def main(cursor):
	start = time.time()
	
	tech_id		= int(common.get_val("tech", 0))
	level		= int(common.get_val("level", 0))
	
	return str(tech_rules.cost_for_next_level(cursor, tech_id, level).get("Tech points"))
Example #4
0
def main(cursor):
	output = ['<div style="padding:5px;">']
	
	# Get input
	team	= int(common.get_val("team", 0))
	city	= int(common.get_val("city", 0))
	target_team	= int(common.get_val("target_team", 0))
	area	= common.get_val("area", "")
	radius	= int(common.get_val("radius", 10))
	
	if city < 1 and target_team > 0:
		return team_main(cursor)
	
	the_world = spy_world.Spy_world(cursor)
	
	reports = spy_report_f.generate_report(the_world, team, city, area, radius)
	
	for r in reports:
		output.append('<div style="float: left; margin-right: 15px;">')
		output.append('<span class="stitle">%s</span><br />' % r.report_type)
		output.append('<textarea rows="8" cols="40">')
		output.append(r.content)
		output.append("</textarea></div>")
	
	output.append('</div>')
	return "".join(output)
Example #5
0
def main(cursor):
    queries = common.get_val("queries", "")
    subject = common.get_val("subject", "No subject")

    if queries == "":
        e = Exception("POST:'queries' was empty")
        raise e

    queries_list = queries.split("\n")

    database.cursor.execute("BEGIN")

    for q in queries_list:
        if q == "":
            continue
        if q[0:2] == "--":
            continue

        try:
            database.cursor.execute(q)
        except Exception as e:
            database.cursor.execute("ROLLBACK")
            print ("Query: %s\n" % q)
            raise e

    database.cursor.execute("COMMIT")

    queries_f.log_query(queries, subject)

    return "All queries run successfully"
    print ""
Example #6
0
def main(cursor):
	campaign	= int(common.get_val("campaign", 0))
	location	= common.get_val("location", "")
	team		= int(common.get_val("team", 0))
	
	# Get location
	result = battle.battle_coords.search(location)
	if result != None:
		x = int(result.groups()[0])
		y = int(result.groups()[1])
	else:
		# Get it from the last battle
		last_battle = battle_q.get_last_battle_from_campaign(cursor, campaign)
		if last_battle == None: return ""
		
		x = last_battle.x
		y = last_battle.y
	
	# Get armies
	armies = campaign_q.get_armies_from_campaign_from_team(cursor, campaign, team)	
	
	# Move them
	database.query(cursor,
		army_f.move_armies(armies, (x, y)))
	
	page_data['Redirect'] = "list_battles&campaign={0}".format(campaign)
	return ""
Example #7
0
def team_main(cursor):
	output = ['<div style="padding:5px;">TEAM']
	
	# Get input
	team		= int(common.get_val("team", 0))
	target_team	= int(common.get_val("target_team", 0))
	area		= common.get_val("area", "")
	radius		= int(common.get_val("radius", 10))
	
	the_world = spy_world.Spy_world(cursor)
	
	city_dict = the_world.cities_from_team(target_team)
	
	report_total = {}
	for city in city_dict.keys():
		reports = spy_report_f.generate_report(the_world, team, city, area, radius)
		
		for r in reports:
			if r.report_type not in report_total:
				report_total[r.report_type] = []
			
			report_total[r.report_type].append(r.content)
	
	for title, content in report_total.items():
		output.append('<div style="float: left; margin-right: 15px;">')
		output.append('<span class="stitle">%s</span><br />' % title)
		output.append('<textarea rows="8" cols="40">')
		output.append("\n".join(content))
		output.append("</textarea></div>")
	
	output.append('</div>')
	return "".join(output)
Example #8
0
def main(cursor):
	team_id = int(common.get_val("team", 0))
	default_border = int(common.get_val("default_border_state", 0))
	
	team_dict = team_q.get_real_active_teams(cursor, skip_irs=False)
	the_team = team_dict[team_id]
	
	queries = [
		"DELETE FROM team_borders WHERE host = %d" % team_id,
		"UPDATE teams SET default_borders = %d WHERE id = %d;" % (default_border, team_id),
	]
	insertions = []
	
	# Get a list of states
	for t, other_team in team_dict.items():
		if t == the_team.id: continue
		
		state = int(common.get_val("border_state_%d" % t, -1))
		if state >= 0:
			insertions.append("(%d, %d, %d)" % (team_id, t, state))
	
	# Add insertions to list
	if len(insertions) > 0:
		queries.append("INSERT INTO team_borders (host, visitor, state) values %s;" % ",".join(insertions))
		
	# print("")
	# print(common.print_post_data())
	# print("<br /><br />")
	# print("<br />".join(queries))
	# exit()
	
	database.query(cursor, queries)
	
	page_data['Redirect'] = 'view_borders&team={0:d}'.format(team_id)
	return ""
Example #9
0
File: to.py Project: Teifion/Rob3
def main(cursor):
	# Get team Id
	post_output = int(common.get_val('post_output', 0))
	dev_mode	= common.get_val('dev_mode', 0)
	ajax		= common.get_val('ajax', 0)
	
	the_world = world.World(cursor)
	the_world.prep_for_to()
	
	headers = to_f.headers(the_world)
	footers = to_f.footers(the_world)
	js = to_f.javascript(the_world)
	output = to_f.make_to(the_world)
	
	content = []
	
	if dev_mode == "1":
		headers = headers.replace('../styles.css', 'http://localhost/woa/styles.css').replace('../includes/jquery.js', '%sjquery.js' % common.data['media_path'])
	
	if ajax:	content.append(headers)
	else:		content.append(js)
	
	content.append(output)
	
	if ajax:	content.append(footers)
	
	return "".join(content)
Example #10
0
def main(cursor):
	# Get team Id
	team_id		= int(common.get_val('team', 0))
	recache		= common.get_val('recache', False)
	
	output = []
	
	output.append("""<div style="padding: 5px;">
	<form style="padding: 5px;" action="web.py" method="get" accept-charset="utf-8">
		<input type="hidden" name="mode" id="mode" value="team_stats" />
		<table border="0" cellspacing="5" cellpadding="5">
			<tr>
				<td><label for="team">Team:</label></td>
				<td>%(team_option_box)s</td>
				<td width="10">&nbsp;</td>
				<td><input type="submit" value="Get stats" /></td>
			</tr>
		</table>
	</form>
	<a href="web.py?mode=team_stats&amp;team=%(team_id)s&amp;recache=1" class="block_link">Recache</a>
	<br />""" % {
		"team_option_box":		team_f.structured_list(cursor, default=team_id),
		"last_id":				team_q.get_latest_active_team_id(cursor, skip_irs = True),
		"team_id":				team_id,
	})
	
	if team_id < 1:
		return "".join(output)
	
	ajax = False
	output.append(get_stat_core(cursor, team_id, recache, ajax))
	# output.append("</div>")
	
	return "".join(output)
Example #11
0
def main(cursor):
	team_id	= int(common.get_val('team', 0))
	build	= int(common.get_val('build', 0))
	
	if team_id < 1:
		return "<div style='padding: 5px;'>%s</div>" % common.select_team_form(cursor, 'team_map', ajax=1)
	
	return _draw_map(cursor, team_id, build)
Example #12
0
def main(cursor):
	monster_id	= int(common.get_val('monster', 0))
	army_id 	= int(common.get_val('army', 0))
	amount  	= int(common.get_val('amount', 0))
	
	database.query(cursor, monster_f.alter_army_monster_size(army_id, monster_id, amount))
	
	page_data['Redirect'] = "list_squads&army={0}".format(army_id)
	return ""
Example #13
0
def main(cursor):
	name			= common.get_val("name", "")
	city			= int(common.get_val("city", 0))
	point_cost		= int(common.get_val("point_cost", 0))
	material_cost	= int(common.get_val("material_cost", 0))
	description		= common.get_val("description", "")
	
	database.query(cursor,
		wonder_f.new_wonder(name, city, point_cost, material_cost, description))
Example #14
0
def main(cursor):
	campaign	= int(common.get_val("campaign"))
	team		= int(common.get_val("team"))
	side		= int(common.get_val("side"))
	
	database.query(cursor,
		campaign_f.remove_team_from_campaign(campaign, side, team))
	
	return ""
Example #15
0
def main(cursor):
	unit	= int(common.get_val("unit", 0))
	item	= int(common.get_val("item", 0))
	
	database.query(cursor,
		unit_f.add_equipment(unit=unit, item=item))
	
	# Redirect
	page_data['Redirect'] = 'edit_unit&unit={0:d}'.format(unit)
	return ""
Example #16
0
def main(cursor):
	page_data['Redirect'] = ''
	
	trait_id	= int(common.get_val("trait", 0))
	team_id		= int(common.get_val("team", 0))
	
	database.query(cursor, team_f.add_trait(team_id, trait_id))
	
	page_data['Redirect'] = 'edit_team&team={0:d}'.format(team_id)
	return ""
Example #17
0
def main(cursor):
	page_data['Redirect'] = ''
	
	deity_id	= int(common.get_val("deity", 0))
	team_id		= int(common.get_val("team", 0))
	
	database.query(cursor, team_f.remove_deity(team_id, deity_id))
	
	page_data['Redirect'] = 'edit_team&team={0:d}'.format(team_id)
	return ""
Example #18
0
def main(cursor):
	building_id		= int(common.get_val("building", 0))
	completion		= int(common.get_val("completion", 0))
	amount			= int(common.get_val("amount", 0))
	city_id			= int(common.get_val("city", 0))
	
	city_f.set_building(cursor, city_id, building_id, completion, amount)
	
	page_data['Redirect'] = 'edit_city&city={0:d}'.format(city_id)
	return ""
Example #19
0
def main(cursor):
	spell_id	= int(common.get_val("spell", 0))
	team		= int(common.get_val("team", 0))
	level		= int(common.get_val("level", 0))
	points		= int(common.get_val("points", 0))
	
	database.query(cursor, spell_f.set_spell(spell_id=spell_id, team_id=team, level=level, points=points))
	
	page_data['Redirect'] = "list_spells&team=%s" % team
	return ""
Example #20
0
def main(cursor):
	tech_id		= int(common.get_val("tech", 0))
	team		= int(common.get_val("team", 0))
	level		= int(common.get_val("level", 0))
	points		= int(common.get_val("points", 0))
	
	database.query(cursor, tech_f.set_tech(tech_id=tech_id, team_id=team, level=level, points=points))
	
	page_data['Redirect'] = "list_techs&team=%s" % team
	return ""
Example #21
0
def main(cursor):
    page_data["Redirect"] = ""

    deity_id = int(common.get_val("deity", 0))
    team_id = int(common.get_val("team", 0))

    database.query(cursor, team_f.add_deity(team_id, deity_id))

    page_data["Redirect"] = "edit_team&team={0:d}".format(team_id)
    return ""
Example #22
0
File: lore.py Project: Teifion/Rob3
def main(cursor):
	cat		= common.get_val('cat', "")
	page	= common.get_val('page', "")
	
	page_data['title'] = "Lore: %s.%s" % (cat, page)
	
	try:
		output = pages.get_html(cursor, cat, page, "gm")
	except Exception as e:
		return str(e)
	
	return output
Example #23
0
def main(cursor):
	name		= common.get_val("name", "")
	player		= int(common.get_val("player", 0))
	power_type	= int(common.get_val("type", 0))
	description	= common.get_val("power_description", "")
	
	database.query(cursor,
		power_f.new_power(name, player, power_type, description))
	
	# Redirect
	page_data['Redirect'] = 'list_powers'
	return ""
Example #24
0
def main(cursor):
	campaign	= int(common.get_val("campaign"))
	side		= int(common.get_val("side"))
	team		= int(common.get_val("team"))
	
	try:
		database.query(cursor,
			campaign_f.add_team_to_campaign(campaign, team, side))
	except Exception as e:
		# It's expected to fail if the team is already on that side
		pass
	
	return ""
Example #25
0
def main(cursor):
	campaign_id = int(common.get_val('campaign', -1))
	team_id = int(common.get_val('team', -1))
	army_names_normal = common.get_val('army_names', "").replace("\n", ",").split(",")
	
	# Get last battle
	last_battle = battle_q.get_last_battle_from_campaign(cursor, campaign_id)
	if not last_battle:
		page_data['Redirect'] = 'setup_campaign&campaign=%d' % campaign_id
		return ""
	
	start_time = last_battle.start
	
	army_names = []
	for a in army_names_normal:
		army_names.append(a.lower().strip())
	
	army_dict = army_q.get_armies_from_team(cursor, team_id, True)
	army_list = []
	
	queries = []
	for army_id, the_army in army_dict.items():
		if the_army.name.lower() in army_names:
			queries.append("INSERT INTO campaign_armies (campaign, army, started) values (%d, %d, %d);" % (campaign_id, army_id, start_time))
	
	# print("")
	# print([a.name.lower() for i, a in army_dict.items()], "<br />")
	# print(army_names)
	# print("<br />".join(queries))
	# exit()
	
	# print("")
	# print(queries)
	# exit()
	
	for q in queries:
		try:
			cursor.execute(q)
		except Exception as e:
			pass
			# raise Exception("Database error: %s\nQuery: %s" % (str(e.args[0]).replace("\n",""), q))
	
	# if queries == []:
	# 	print("")
	# 	print(army_names)
	# 	
	# 	exit()
	
	# Redirect
	page_data['Redirect'] = 'setup_campaign&campaign={0:d}'.format(campaign_id)
Example #26
0
def main(cursor):
    army_id = int(common.get_val("army", -1))
    the_army = army_q.get_one_army(cursor, army_id)
    database.query(cursor, army_f.make_delete_query(army_id))

    # Redirect
    page_data["Redirect"] = "list_armies&team={0:d}".format(the_army.team)
Example #27
0
def main(cursor):
	unit_id = int(common.get_val('unit', -1))
	the_unit = unit_q.get_one_unit(cursor, unit_id)
	database.query(cursor, unit_f.delete_unit(unit_id))
	
	# Redirect
	page_data['Redirect'] = 'list_units&team={0:d}'.format(the_unit.team)
Example #28
0
def main(cursor):
	team			= int(common.get_val("team", 0))
	name			= common.get_val("name", "")
	location		= int(common.get_val("location", 0))
	description		= common.get_val("artefact_description", "")
	
	database.query(cursor,
		artefact_f.new_artefact(name, team, location, description))
	
	# Redirect
	if team < 1:
		page_data['Redirect'] = 'list_artefacts'
	else:
		page_data['Redirect'] = 'list_artefacts&team={0:d}'.format(team)
	
	return ""
Example #29
0
def main(cursor):
	op_id = int(common.get_val('operative', -1))
	the_op = operative_q.get_one_operative(cursor, op_id)
	database.query(cursor, operative_f.kill_operative(op_id))
	
	# Redirect
	page_data['Redirect'] = 'list_operatives&team={0:d}'.format(the_op.team)
Example #30
0
def main(cursor):
	raise Exception("Thought to no longer be used")
	
	team_id = int(common.get_val("team", -1))
	
	if team_id < 1:
		return "<div style='padding: 5px;'>%s</div>" %  common.select_team_form(cursor, 'results')
	
	the_team = team_q.get_one_team(cursor, team_id)
	the_world = world.World(cursor)
	
	output = ['<div style="padding: 5px;">']
	output.append('<span class="stitle">%s results</span>' % the_team.name)
	output.append('<textarea name="results" id="results" rows="13" style="width: 100%;">')
	output.append(team_f.create_results_tail(the_world, the_team))
	output.append('</textarea>Previous results:')
	
	# Now to get the results for the last few turns
	# results_dict = results.get_results_by_team()
	# our_results_dict = results_dict.get(team_id, {})
	# 
	# for t in range(common.current_turn(),common.current_turn()-5,-1):
	# 	if t in our_results_dict:
	# 		output.append("""
	# 		<hr />
	# 		Turn: %d<br />
	# 		%s
	# 		""" % (t, common.bbcode_to_html(our_results_dict[t].strip())))
	
	output.append('<hr /></div>')
	return "".join(output)