Go Back   EQEmulator Home > EQEmulator Forums > Development > Development::Development

Development::Development Forum for development topics and for those interested in EQEMu development. (Not a support forum)

Reply
 
Thread Tools Display Modes
  #1  
Old 10-21-2007, 10:29 AM
Theeper
Discordant
 
Join Date: May 2004
Posts: 290
Default World UI Rules Script

I wrote a script for the worldUI to tweak rules. It could probably done better, but it works for me. Thought someone might find it useful. When rules-per-zone gets in, I will update this to reflect it.

Just replace the /templates/rules.html with this. It assumes the default ruleset is ID 0.

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" title="Default" href="main.css" type="text/css" />

<script language="JavaScript" type="text/JavaScript">
function get_rules(loc)
 {
   page = loc.options[loc.selectedIndex].value
		
   if (page != "")
   {
      document.location.href = page
   }
 }
</script>

</head>

<body>
<h2 align="center">Rules Management</h2>
<hr/>
<?
my $error=0;
my %rulesets;
my %selected_ruleset;
my %default_rules;
my $get_r = $request->get_all;
$rsid=$get_r->{"rsid"};

# add a new RuleSet
if (defined($get_r->{"add_ruleset"}) && ($get_r->{"add_ruleset"} ne "")) {
	$add_ruleset = $get_r->{"add_ruleset"};
	$q = "INSERT INTO rule_sets (name) VALUES ('$add_ruleset')";
	$EQDB->query($q);
	if ($EQDB->get_errno) {
		$error=1;
	}
	if ($error==0) {
		printf("<CENTER><h3>RuleSet added, will take affect on server restart.</h3><br></CENTER>\n");
	}
}

# get the RuleSets list
$q="SELECT * FROM rule_sets";
my $res4=$EQDB->query($q);
if ($res4) { 
	while(my $row=$res4->fetch_row_hash) {
	$r = $row->{ruleset_id};
	$rulesets{ $r } = $row->{name};
	}
}

# get the default rules, should be ruleset_id = 0
$q="SELECT * FROM rule_values WHERE ruleset_id = '0'";
my $res1=$EQDB->query($q);
if ($res1) { 
	while(my $row=$res1->fetch_row_hash) {
	$r = $row->{rule_name};
        $default_rules{ $r } = $row->{rule_value};
	}
}


# update the Active RuleSet
$set_active_rsid = $request->getInt("set_active_rsid",-1);
if ($set_active_rsid >= 0) {
	my $set_active_name = $rulesets{$set_active_rsid};
	$q = "UPDATE variables SET value = '$set_active_name' WHERE varname = 'RuleSet'";
	$EQDB->query($q);
	if ($EQDB->get_errno) {
		$error=1;
	}
	if ($error==0) {
		printf("<CENTER><h3>Active Ruleset changed, will take affect on server restart.</h3><br></CENTER>\n");
	}
}

# get the Active RuleSet
$q="SELECT ruleset_id, name FROM rule_sets, variables WHERE variables.varname = 'RuleSet' && variables.value = rule_sets.name";
my $res2=$EQDB->query($q);
if ($res2) { 
	if (my $active_ruleset=$res2->fetch_row_hash) {
		$active_rsid = $active_ruleset->{ruleset_id};
		$active_name = $active_ruleset->{name};
	}
}

# Update rule values
if (defined($get_r->{"update_rules"})) {
	while( my ($k, $v) = each %$get_r ) {
		if (($k ne "update_rules") && ($k ne "rsid")) {
			$q="REPLACE INTO rule_values (ruleset_id, rule_name, rule_value) VALUES ('$rsid','$k','$v')";
			$EQDB->query($q);
			if ($EQDB->get_errno) {
				$error=1;
			}
		} 
	}
	if ($error==0) {
		printf("<CENTER><h3>Rules values updated, will take affect on server restart.</h3><br></CENTER>\n");
	}
}

# delete a rule
if (defined($get_r->{"delete_rule"})) {
	my $rule_name = $get_r->{"delete_rule"};
	$q = "DELETE FROM rule_values WHERE ruleset_id = '$rsid' && rule_name = '$rule_name'";
	$EQDB->query($q);
	if ($EQDB->get_errno) {
		$error=1;
	}
	if ($error==0) {
		printf("<CENTER><h3>Rule deleted, will take affect on server restart.</h3><br></CENTER>\n");
	}
}

# add new rule to a set
if (defined($get_r->{"add_rule"})) {
	my $rule_name = $get_r->{"rule"};
	my $rule_value = $default_rules{$rule_name};
	$q = "REPLACE INTO rule_values (ruleset_id, rule_name, rule_value) VALUES ('$rsid','$rule_name','$rule_value')";
	$EQDB->query($q);
	if ($EQDB->get_errno) {
		$error=1;
	}
	if ($error==0) {
		printf("<CENTER><h3>Rule added/reset, will take affect on server restart.</h3><br></CENTER>\n");
	}
}

# check if a ruleset was requested, else use the Active Ruleset
$get_rsid = $request->getInt("rsid",-1);
if ($get_rsid < 0) {
	$rsid=$active_rsid;
	} else {
	$rsid=$get_rsid;
}

# get the selected ruleset
$q="select * from rule_values WHERE ruleset_id = '$rsid' ORDER BY rule_name";

my $res5=$EQDB->query($q);
if ($res5) { 
	while(my $row=$res5->fetch_row_hash) {
		$r = $row->{rule_name};
		$selected_ruleset{ $r } = $row->{rule_value};
	}
}

print "<TABLE ALIGN='center'>\n";
print "<TR>\n";
print "<TD>Active Ruleset: <B>$active_name</B></TD>\n";
print "</TR>\n";
print "</TABLE>\n\n";

print "<TABLE ALIGN='center'>\n";
print "<FORM ACTION='rules.html' METHOD='get'>\n";
print "<TR>\n";
print "<TD><INPUT TYPE='text' NAME='add_ruleset'></TD>\n";
print "<TD><INPUT TYPE='submit' VALUE='Add New RuleSet >>'></TD>";
print "</TR>\n";
print "</FORM></TABLE>\n\n";


# create the table of the selected ruleset's values
print "<TABLE ALIGN='center'>\n";
if (%selected_ruleset) { 
	print "<FORM ACTION='rules.html' METHOD='get'>\n";
        print "<TR>\n";
        print "<TD ALIGN='center'>\n";
	print "<SELECT NAME='rsid' onChange=\"get_rules(this.form.rsid)\">\n";
	for my $ruleset (sort keys %rulesets ) {
		print "<OPTION VALUE='rules.html?rsid=$ruleset'";
		if ($ruleset == $rsid) {
			print " SELECTED";
		}
		print ">Ruleset - $rulesets{$ruleset}</OPTION>\n";
	}
	print "</SELECT>\n";
	print "</TD></FORM>";
	print "<FORM ACTION='rules.html' METHOD='get'>\n";
	print "<INPUT TYPE='hidden' NAME='update_rules' VALUE='1'>\n";
	print "<INPUT TYPE='hidden' NAME='rsid' VALUE='$rsid'>\n";
	print "<TD ALIGN='right'><INPUT TYPE='submit' VALUE='Update >>'></TD></TR>\n";
	for my $rule_name (sort keys %selected_ruleset ) {
		print "<TR>\n";
		print "<TD><B>$rule_name</B></TD>\n";
		print "<TD><INPUT TYPE='text' NAME='$rule_name' VALUE='$selected_ruleset{$rule_name}' SIZE='12'></TD>\n";
		if ($rsid > 0) {
			print "<TD><A HREF='rules.html?rsid=$rsid&delete_rule=$rule_name'><IMG SRC='delete.gif' BORDER='0'></A></TD>\n";
		}
		print "</TR>\n";
	}
}

# make the row for the 'Add Rule' select menu
print "<TR>\n";
print "</FORM>\n";
if ($rsid > 0) {
	print "<TD COLSPAN='2'>&nbsp;</TD></TR>\n";
	print "<TR>\n";
	print "<FORM ACTION='rules.html' METHOD='get'>\n";
	print "<INPUT TYPE='hidden' NAME='add_rule'>\n";
	print "<INPUT TYPE='hidden' NAME='rsid' VALUE='$rsid'>\n";
	print "<TD ALIGN='center'>\n";
	print "<SELECT NAME='rule'>\n";
	for my $rule (sort keys %default_rules ) {
		print "<OPTION VALUE='$rule'>$rule</OPTION>\n";
	}
	print "</SELECT>\n";
	print "</TD>\n";
	print "<TD ALIGN='center'><INPUT TYPE='submit' VALUE='Add >>'></TD>\n";
	print "</FORM></TR>\n";
}

print "<TR><TD COLSPAN='2'>&nbsp;</TD></TR>\n";
print "<TR>\n";
print "<FORM ACTION='rules.html' METHOD='get'>\n";
print "<INPUT TYPE='hidden' NAME='set_active_rsid' VALUE='$rsid'>\n";
print "<TD COLSPAN='2' ALIGN='center'><INPUT TYPE='submit' VALUE='Make this the Active RuleSet'></TD>\n";
print "</FORM></TR></TABLE>\n\n";


?>
<BR>&nbsp;<BR>
</body>
</html>
Reply With Quote
  #2  
Old 10-23-2007, 01:49 AM
John Adams
Demi-God
 
Join Date: Jul 2006
Posts: 1,552
Default

Nice, thank you! It's good to see the worldUI getting some much needed attention. So many opportunities to improve and add to that UI. If I ever finish my petitions.html, I will share it. Right now it just views and allows deleting, since I don't think the emu supports updating anyway (returning a response to the player)?
Reply With Quote
  #3  
Old 10-23-2007, 02:25 AM
Theeper
Discordant
 
Join Date: May 2004
Posts: 290
Default

Thanks JA. I have a couple other mods to the world UI, but nothing complete yet. I will be working on some other areas just because PERL is so fun.
Reply With Quote
  #4  
Old 10-23-2007, 10:53 PM
Myrakkel
Fire Beetle
 
Join Date: Jul 2003
Location: Paoli, IN
Posts: 13
Default

I am sure once the mail system in game is developed and fluid that an updating petition list would be possible.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

   

All times are GMT -4. The time now is 02:32 PM.


 

Everquest is a registered trademark of Daybreak Game Company LLC.
EQEmulator is not associated or affiliated in any way with Daybreak Game Company LLC.
Except where otherwise noted, this site is licensed under a Creative Commons License.
       
Powered by vBulletin®, Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Template by Bluepearl Design and vBulletin Templates - Ver3.3