Ejemplo n.º 1
0
def main(cursor):
    team_id = int(common.get_val("team", 0))
    turn = int(common.get_val("turn", -1))

    if team_id < 1:
        return "<div style='padding: 5px;'>%s</div>" % common.select_team_form(cursor, "view_orders")

    if turn < 1:
        turn = common.current_turn()

    the_world = world.World(cursor)
    player_dict = the_world.players()

    the_team = team_q.get_one_team(cursor, team_id)
    the_orders = the_team.get_orders(cursor, the_world, "international", turn)

    # output = ["<div style='padding: 5px; font-size: 14px; line-height: 17px;'>"]
    output = ["<div style='padding: 5px;'>"]
    player_updates = {}

    for o in the_orders:
        player_updates[o.player] = o.team

        if o.content == "Orders placeholder":
            continue

        output.append(
            '<br /><hr />Post: <a href="http://woarl.com/board/viewtopic.php?p=%s#p%s">%s</a><br />'
            % (o.post_id, o.post_id, o.post_id)
        )
        output.append(
            'Poster: <a href="http://woarl.com/board/memberlist.php?mode=viewprofile&u=%d">%s</a> - '
            % (o.player, player_dict[o.player].name)
        )
        output.append('<a href="web.py?mode=edit_player&amp;player=%d">Local edit</a><br />' % (o.player))

        output.append(common.bbcode_to_html(o.content.replace('<span class="stitle">', '<hr /><span class="stitle">')))

    output.append("</div>")

    # Update player activity
    if turn == common.current_turn():
        database.query(cursor, player_f.update_player_activity(player_updates))

        # print "<br />".join(output)
    page_data["Title"] = "%s International orders" % the_team.name
    return "".join(output)
Ejemplo n.º 2
0
Archivo: ti.py Proyecto: Teifion/Rob3
def get_bbcode_core(cursor, team_id):
	the_team = team_q.get_one_team(cursor, team_id)
	md5_name = team_f.team_hash(the_team.name)
	
	# bbcode = "".join([headers, output, footers])
	bbcode = ti_f.bbcode_ti(the_team, md5_name)
	
	ti_output = common.bbcode_to_html(bbcode)
	
	# Clean it
	bbcode = bbcode.replace(' ', '\\ ').replace('\n', 'NEWLINE').replace('\t', '')
	bbcode = bbcode.replace("'", 'APOSTRAPH').replace('&', 'AMPASAND')
	bbcode = bbcode.replace("(", '\\(').replace(')', '\\)')
	
	# Send it
	getter_data = "p=%s&mode=postUpdate&post=%d&string=%s" % (common.data['getterPass'], the_team.team_info_first_post, bbcode)
	result = urllib.request.urlopen(common.data['getter_url'], getter_data).read().strip()
	
	return bbcode
Ejemplo n.º 3
0
def display_team_failures(cursor, the_world, team_id):
    # return '<div class="ti_section" id="failures_div">Implimentation will activate next turn</div>'

    output = []
    output.append(
        """
	<div class="ti_section" id="failures_div">"""
    )

    query = """SELECT content FROM results_log WHERE turn = %d AND team = %d AND failures = True""" % (
        common.current_turn(),
        team_id,
    )
    try:
        cursor.execute(query)
    except Exception as e:
        raise Exception("Database error: %s\nQuery: %s" % (str(e.args[0]).replace("\n", ""), query))
    for row in cursor:
        output.append(common.bbcode_to_html(row["content"]))

    output.append("</div>")
    return "".join(output)
Ejemplo n.º 4
0
def main(cursor):
	team_id		= int(common.get_val("team", 0))
	turn		= int(common.get_val("turn", -1))
	
	the_world = world.World(cursor)
	the_world.prep_for_orders()
	
	if team_id < 1:
		return "<div style='padding: 5px;'>%s</div>" %  common.select_team_form(cursor, 'view_orders')
	
	if turn < 1:
		turn = common.current_turn()
	
	# the_team = team_q.get_one_team(cursor, team_id)
	# the_team.get_resources(cursor)
	# the_team.get_spells(cursor)
	# the_team.get_techs(cursor)
	the_team = the_world.teams()[team_id]
	the_orders = the_team.get_orders(cursor, the_world, "normal", turn)
	
	output = ["<div style='padding:1px;'>"]
	player_updates = {}
	
	blocks = []
	for o in the_orders:
		o.split()
		blocks.extend(o.blocks)
	
	# Setup
	for b in blocks:
		b.setup()
	
	# Execution
	for b in blocks:
		b.execute()
	
	for b in blocks:
		# Player activity needs to get updated
		if turn == common.current_turn():
			player_updates[b.post.player] = b.post.team
		
		output.append("""
		<div class="orders" style="border-color:{border};background-color:{background};">
			<strong>{title}</strong>: {cost}<br />
			{response}
			<br />
			
			<div style="float: left; width: 50%;">
				<textarea rows="6" style="float:left;width:99%;">{results}</textarea>
			</div>
			<div style="float: left; width: 50%;">
				<textarea rows="6" style="float:right;width:99%;">{queries}</textarea>
			</div>
			<div style="clear: left;">
				&nbsp;
			</div>
		</div>
		""".format(
			title		= b.title_name,
			cost		= str(b.cost),
			response	= common.bbcode_to_html("<br />".join(b.input_response)),
			results		= "\n".join(b.results),
			queries		= "\n".join(b.queries),
			
			border		= b.border_colour,
			background	= b.background_colour,
		))
	
	# output.append("""
	# Time taken: %(total)s<br /><br />
	# %(joined)s
	# """ % {
	# 	"total":	total_time,
	# 	"joined":	"<br />".join(time_list),
	# })
	# 
	# output.append("""
	# <a href="#" id="all_q_link" style="float: right; padding-right: 10px;" onclick="$('#all_q_div').load('web.py', {'ajax':'True','mode':'run_queries','subject':'Normal orders','queries':$('#all_q_text').val()}); $('#all_q_link').hide(); return false;">Run queries</a>
	# <br />
	# <textarea name="Name" id="Name" rows="8" style="width: 49%%;">%s</textarea>
	# <div style="float: right; width: 49%%; padding-right: 5px;" id="all_q_div">
	# 	<textarea id="all_q_text" name="Name" id="Name" rows="8" style="width: 100%%;">%s</textarea>
	# </div>
	# """ % ("\n".join(total_results), "\n".join(total_queries)))
	
	output.append("</div>")
	
	# Update player activity
	if turn == common.current_turn():
		database.query(cursor, player_f.update_player_activity(player_updates))
	
	page_data['Title'] = "%s normal orders" % the_team.name
	
	return "".join(output)
Ejemplo n.º 5
0
def main(cursor):
	team_id		= int(common.get_val("team", 0))
	orders_str	= common.get_val("orders", "")#.replace("’", "'")
	msn_mode	= int(common.get_val("msn_mode", 0))
	
	if team_id < 1 or orders_str == "":
		return """
		<div style='padding: 5px;'>
			<form action="web.py" id="select_team_form" method="post" accept-charset="utf-8">
				<input type="hidden" name="mode" id="mode" value="test_orders" />
				<label for="msn_mode">MSN mode:</label> <input type="checkbox" id="msn_mode" name="msn_mode" value="1" />
				Team: %s
				<!--
				<a class="block_link" href="#" onclick="$('#select_team_form').submit(); return false;">Run orders</a>
				-->
				<input type="submit" value="Run orders" />
				<br />
				<textarea name="orders" rows="8" style="width: 100%%;">[o]Rob command[/o]
Enable: Overbudget

</textarea>
			</form>
		</div>%s""" % (
			team_f.structured_list(cursor, field_id="team"),
			common.onload("$('#team').focus();"),
		)
	
	the_world = world.World(cursor)
	the_world.prep_for_orders()
	
	the_team = the_world.teams()[team_id]
	produced_resources, new_resources = team_rules.produce_resources(cursor, the_team, the_world, force_requery=True)
	the_team.resources = new_resources
	blocks = request_f.convert_orders(the_world, the_team, orders_str)
	
	output = ["<div style='padding:1px;'>"]
	
	output.append("Running with resources: %s" % str(the_team.resources))
	
	# Setup
	for b in blocks:
		b.setup(msn_order=msn_mode)
	
	# Execution
	for b in blocks:
		b.execute()
	
	debug = []
	for i, b in enumerate(blocks):
		# if b.cost.as_string() != "":
		# 	b.results = b.results.replace("{COST}", " - [neg]Cost: %s[/neg]" % b.cost.as_string())
		# else:
		# 	b.results = b.results.replace("{COST}", "")
		# 
		# # Trade queries are done differently
		# if b.order_type != "trades":
		# 	total_queries.append(b.queries)
		# 	total_results.append(b.results.strip())
		# 	total_results.append("")# To create a gap
		
		if len(b.debug) > 1:
			debug.append(b.debug[0])
			debug.append("\n---\n".join(b.debug[1:len(b.debug)]))
		
		output.append("""
		<div class="orders" style="border-color:{border};background-color:{background};">
			<strong>{title}</strong>: {cost}<br />
			{response}
			<br />
			
			<div style="float: left; width: 50%;">
				<textarea rows="6" style="float:left;width:99%;">{results}</textarea>
			</div>
			
			<div style="float: left; width: 50%;">
				<textarea rows="6" style="float:right;width:99%;">{queries}</textarea>
				<br />
				<a href="web.py?mode=direct_query">Direct query</a>
			</div>
			<div style="clear: left;">
				&nbsp;
			</div>
		</div>
		""".format(
			title		= b.title_name,
			cost		= str(b.cost),
			response	= common.bbcode_to_html("<br />".join(b.input_response)),
			results		= "\n".join(b.results),
			queries		= "\n".join(b.queries),
			
			border		= b.border_colour,
			background	= b.background_colour,
		))
	
	if debug != []:
		output.insert(2, '<br /><strong>Debug:</strong><br /><textarea name="debug" id="debug" rows="6" cols="80">%s</textarea><br />' % "".join(debug))
	
	output.append("Finishing with resources: %s" % str(the_team.resources))
	output.append("</div>")
	
	return "".join(output)
Ejemplo n.º 6
0
def main(cursor):
	team_id		= int(common.get_val("team", 0))
	turn		= int(common.get_val("turn", -1))
	
	turn = 81
	team_id = 83# Clan
	team_id = 71# Shrikes
	# team_id = 72# Daninia
	
	# Defaults
	if team_id < 1:
		return "<div style='padding: 5px;'>%s</div>" % common.select_team_form(cursor, 'view_orders')
	
	if turn < 1:
		turn = common.current_turn()
	
	# Build some handles
	the_world = world.World(cursor)
	player_dict = the_world.players()
	
	the_team = team_q.get_one_team(cursor, team_id)
	the_orders = the_team.get_orders(cursor, the_world, "international", turn)
	
	output = ["<div style='padding: 5px;'>"]
	player_updates = {}
	
	# Make sure we have the orders in place
	for o in the_orders:
		intorder_f.create_default(cursor, o)
	
	# Bulk get
	intorders = intorder_q.get_orders_from_posts(cursor, [o.post_id for o in the_orders])
	intorder_q.mass_get_parents(cursor, intorders)
	
	for i, o in intorders.items():
		# if o.parent.content == "Orders placeholder": continue
		
		sections = o.split()
		
		for s in sections:
			output.append("""
			<div class="intorder">
				<a href="http://woarl.com/board/memberlist.php?mode=viewprofile&amp;u={player.id}">{player.name}</a>:
				<a href="http://woarl.com/board/viewtopic.php?p={the_order.post_id}#p{the_order.post_id}">{the_order.post_id}</a>
				<br />
				
				{content}
			</div>""".format(
				intorder = o,
				player = player_dict[o.parent.player],
				the_order = o.parent,
				s = s,
				
				content = common.bbcode_to_html(s.content),
			))
		
		
		# output.append('<br /><hr />Post: <a href="http://woarl.com/board/viewtopic.php?p=%s#p%s">%s</a><br />' % (o.parent.post_id, o.parent.post_id, o.parent.post_id))
		# output.append('Poster: <a href="http://woarl.com/board/memberlist.php?mode=viewprofile&u=%s">%s</a><br />' % (o.parent.player, player_dict[o.parent.player].name))
		# 
		# output.append(common.bbcode_to_html(o.parent.content.replace('{SMILIES_PATH}', 'http://woarl.com/board/images/smilies')))
		# 
		# output.append(str(the_order.parent.topic))
		# output.append("<br />")
	
	output.append("</div>")
	
	# TODO update player activity
	
	# print "<br />".join(output)
	page_data['Title'] = "%s International orders" % the_team.name
	return "".join(output)
Ejemplo n.º 7
0
def make_report(the_world, the_team):
	output = []
	
	city_dict = the_world.cities()
	team_dict = the_world.teams()
	
	# Tabs
	# output.append(tabs(cursor, the_team))
	
	# Date
	output.append("<h2>Spy report for turn %d</h2><br />\n" % common.current_turn())
	
	# Actual output
	city_dict = the_world.cities()
	locations = location_list(the_world, the_team)
	
	team_output = {}
	
	# Foreign
	# output.append('<span class="stitle">Foreign reports</span><br />')
	for city_id, the_city in city_dict.items():
		if city_id in locations:
			if the_city.team != the_team.id:
				reports = produce_location_report(the_world, the_team, city_id)
				
				for r in reports:
					if r.enemy not in team_output:
						team_output[r.enemy] = []
					
					team_output[r.enemy].append(r)
				
				# output.append(fout)
	
	options = []
	
	for k, v in team_output.items():
		output.append('<span class="stitle" id="%s">%s</span><br />' % (common.js_name(team_dict[k].name), team_dict[k].name))
		# headers.append('<a href="#%s">%s</a>' % (team_dict[k].name, common.js_name(team_dict[k].name)))
		options.append(team_dict[k].name)
		
		last_city = -1
		for r in v:
			if last_city != r.city:
				output.append("<strong id='%s'>%s</strong>" % (common.js_name(city_dict[r.city].name), city_dict[r.city].name))
				options.append(city_dict[r.city].name)
				last_city = r.city
			
			output.append('<div class="spy_report_new">')
			# output.append(common.bbcode_to_html(r))
			output.append(common.bbcode_to_html(r.content))
			output.append("</div>")
	
	form = """
	<div style="cursor: pointer; padding:5px; color: #00A;" onclick=" $(this).hide(500); $('#option_list').show(500);">
		Display jump list
	</div>
	<div id="option_list" style="display:none;">
		%s
		<br /><br />
	</div>
	""" % "<br />".join(['<a href="#%s">%s</a>' % (common.js_name(o), o) for o in options])
	
	output.insert(1, form)
	
	# print("".join(output))
	# print("<br />".join(headers))
	# exit()
	
	# Our cities
	'''
	output.append('<br /><span class="stitle">Internal reports</span><br />')
	for city_id, the_city in the_world.cities_from_team(the_team.id).items():
		output.append(produce_location_report_own_city(the_world, the_team, city_id))
	'''
	# output.append(operative_list(the_world, the_team))
	
	# output.append()
	
	return "".join(output)