Jump to content

[SOLVED] eval() Problems


entity

Recommended Posts

Hi, I've began using the language construct eval() and have hit a snag. I'm trying to use it to insert some code if a certain requirement is met. It didn't work, I have properly escaped all the characters that needed escaping.

 

But the thing is, I'm getting really bizzare errors now.

I made a totally empty file and tried making it work as well so it didn't rely on anything like ifs just in case that was affecting my results somehow.

Here is my totally bizzare error:

 

Parse error: syntax error, unexpected T_STRING in /home/.flirt/entity_azirius/realmsofeternity.com/RPG/equipment/armour/asdasdasda.php(135) : eval()'d code on line 1

 

Interesting as the VERY FIRST line is the opening <?php thing... Weird eh? I've also received several escaped character errors which were actually correctly escaped.

 

If you'd like you can view the source of what code I'm trying to eval()

 

<?php

$CweaponMi = 3;
$CweaponMa = 44;
$user_accMa = 20;
$user_magic = 20;
$CweaponType = "Magic";
$CweaponElem = "Freeze";
$monster_m_def = 0;

$monster_stored_attack[0] = 100;
$monster_stored_attack[1] = 2;
$range_type = "Ranged";
$magic_type = "Magic";
$melee_type = "Melee";
$default_elem = "Flame";

$after_monster .= "\$random = rand(0, 100);
if(\$random > 0) {
	\$count_the_attacks = 0;
	foreach(\$monster_stored_attack as \$darnacus) {
		if(\$darnacus > 0) {
			\$count_the_attacks++;
		}
	}
	if(\$count_the_attacks == count(\$monster_stored_attacks)) {
	\$log_message .= \"You are dealing a counter attack!<br />\";
	if(\$CweaponType == \"Magic\") {
		\$use_stat = \$user_magic;
		\$use_stat2 = \$user_accMa;
		\$mon_defence = \$monster_m_def;
		\$CweaponType = \$magic_type;
	}
	elseif(\$CweaponType == \"Melee\") {
		\$use_stat = \$user_melee;
		\$use_stat2 = \$user_accMe;
		\$mon_defence = \$monster_me_def;
		\$CweaponType = \$melee_type;
	}
	elseif(\$CweaponType == \"Ranged\") {
		\$use_stat = \$user_ranged;
		\$use_stat2 = \$user_accRa;
		\$mon_defence = \$monster_r_def;							
		\$CweaponType = \$range_type;
	}
	else {
	    \$use_stat = \$user_melee;
		\$use_stat2 = \$user_accMe;
		\$mon_defence = \$monster_me_def;
		\$CweaponType = \$melee_type;
	}
	\$stat = \$use_stat;
	\$stat2 = \$use_stat2;
	\$random_dmg = (\$CweaponMa + \$stat) - \$CweaponMi;
	\$attack = rand(\$CweaponMi, (\$CweaponMa + rand(0, \$random_dmg)));
	\$CweaponCri = (\$CweaponCri > 100) ? 100 : \$CweaponCri;
    \$work_crit = 100 - \$CweaponCri;
	\$do_crit = rand(0, 100);
	if(\$work_crit <= \$do_crit) {
	 	\$log_message .= \"<span class=\"critical\">CRITICAL HIT!</span><br />\";
	 	\$str_crit_bonus = (\$str > 200) ? 200 : \$str;
	 	\$str_crit_bonus = (\$str_crit_bonus == 0) ? 10 : \$str_crit_bonus;
		\$times = 1 + round(\$str_crit_bonus * 0.005);
	}
	else {
		\$times = 1;
	}
	\$attack *= \$times;  			
	\$CweaponElem = (\$CweaponElem == \"\") ? \$default_elem : \$CweaponElem;
	\$defended_damage = \$attack;
	if(\$MonsterElements['MonsterFlame'] <= 0 && \$CweaponElem == \"Flame\") {
		if(\$mf == 0) {
		 	\$heal_opponent = 1;
		}
	}
	elseif(\$MonsterElements['MonsterFreeze'] <= 0 && \$CweaponElem == \"Freeze\") {
		\$heal_opponent = 1;
	}
	elseif(\$MonsterElements['MonsterLiquid'] <= 0 && \$CweaponElem == \"Liquid\") {
		\$heal_opponent = 1;
	}
	elseif(\$MonsterElements['MonsterEarth'] <= 0 && \$CweaponElem == \"Earth\") {
		\$heal_opponent = 1;
	}
	elseif(\$MonsterElements['MonsterWind'] <= 0 && \$CweaponElem == \"Wind\") {
		\$heal_opponent = 1;
	}
	elseif(\$MonsterElements['MonsterEnergy'] <= 0 && \$CweaponElem == \"Energy\") {
		\$heal_opponent = 1;
	}
	elseif(\$MonsterElements['MonsterHoly'] <= 0 && \$CweaponElem == \"Holy\") {
		\$heal_opponent = 1;
	}
	elseif(\$MonsterElements['MonsterUnholy'] <= 0 && \$CweaponElem == \"Unholy\") {
		\$heal_opponent = 1;
	}
	if(\$heal_opponent == 0) {
		\$defended_damage = str_replace('-', '', \$defended_damage);
	}
	if(\$mf > 0) {
	  	\$character_acc = 10000;
	  	\$monster_dodge = 0;
	}
	else {
	 	\$total_accuracy = \$use_stat2 + \$CweaponAq;
	 	\$total_defence = \$mon_defence + round((\$mon_luk / 20) + (\$mon_dex / 10));
	 	\$character_acc = rand(round(\$total_accuracy / , \$total_accuracy) + rand(1, 30);
		\$monster_dodge = rand(round(\$total_defence / , \$total_defence) + rand(1, 30);
	}
	if(\$heal_opponent == 1) {
		if(\$character_acc >= \$monster_dodge) {
		 	\$monster_lf -= \$defended_damage;
		 	if(\$monster_lf > \$monster_mlf) {
				 	\$monster_lf = \$monster_mlf;
			}
		 	\$log_message .= \"Hit \".(\$aimer + 1).\" healed <span class=\"\".strtolower(\$CweaponElem).\"\">\$defended_damage \$CweaponElem \$CweaponType</span> <strong>Life Force</strong> to <font class=\"\$monster_elem2\">\$monster_elem</font>. It now has <strong>\$monster_lf Life Force</strong>.<br />\";
		}
		else {
			\$log_message .= \"Hit 1 missed <font class=\"\$monster_elem2\">\$monster_name</font>.<br />\";
		}
	}
	else {
		if(\$character_acc >= \$monster_dodge) {
		 	\$monster_lf -= \$defended_damage;
		 	\$log_message .= \"Hit 1 dealt <span class=\"\".strtolower(\$CweaponElem).\"\">\$defended_damage \".\$CweaponElem.\" \$CweaponType</span> damage to <font class=\"\$monster_elem2\">\$monster_name</font>. It now has <strong>\$monster_lf Life Force</strong> left over.<br />\";
		 	\$connect_status = TRUE;
		}
		else {
			\$log_message .= \"Hit 1 missed <font class=\"$monster_elem2\">\$monster_name</font>.<br />\";
		}
	}
}
}
";
eval($after_monster);

echo ("$log_message");
?>

 

If any one can help me with this, I'd be forever great full! As I am well and truly stumped on this.

Link to comment
Share on other sites

I'd never let it have input from a user, if that's what you mean by dangerous?

 

Well, because then then the main battle file would become so huge if I added a new set of code for each and every piece of equipment.

 

I've used it before with fopen() and it worked okay, but now it gives me errors and no matter how hard I check I can't see a single error. I've escaped everything properly. The latest one where the file is considering the <?php at the start of the file to be an error.

Link to comment
Share on other sites

When it works I'll be putting it into an equipment file where this and some more code is included.

 

So you think I should have another include when I want this to happen instead of using the eval() function? As that's fine as well, I just thought it would save having more than one file, but I'd be okay with an include I suppose.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.