Jump to content
MakeWebGames

Damond

Members
  • Posts

    60
  • Joined

  • Last visited

Personal Information

  • Location
    France

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

Damond's Achievements

Newbie

Newbie (1/14)

0

Reputation

  1. After a bit of reading I have found that a better way to redirect a user with a bad answer or a blank answer is to us a META refresh directed at the right page. So replacing: header("Location: macro1.php?refer={$_POST['refer']}");   With: echo '<META http-equiv="refresh" content="5;URL= /macro1.php?refer=' . $_POST['refer'] . '"">';   Solves the problem of "cannot add header information, headers already sent" Giving it a 5 second delay allows the user time to read their mistake before being redirected.
  2. [MENTION=71587]~Rob0t[/MENTION] Thanks for the info. I will have to do a lot more reading to figure out how to correct my mistakes that you have pointed out.
  3. [MENTION=68711]KyleMassacre[/MENTION] Thanks for the response but it looks like once again we have posted at the exact same time. LOL I did finally figure out the proper way of using the system and have it implemented on my site. I updated my OP with the instructions.
  4. Simple question. Has anyone changed to using reCaptcha to limit auto refreshers and if so what is the process? Every thing I am reading is telling me it has to be on a form submit, but I'm looking more for it to pop up after checking if you have done it in the last hour on certain pages. I have a small captcha system now but it is very dated and I have a few users who are blind. Their screen readers are not able to read our current captcha system. Now I have three or four telling me that after entering the code correctly, the very next time the code comes up the display is blank. They are having to clear their cache and reopen the game to get the code to display. All of these problems are pointing me at replacing the captcha system. UPDATE: As I am a novice coder, less then 1yr experience, it is not very often that I get a chance to answer a question posted here. I find myself reading and learning from the other coders more then offering advice. That changes a little today with me answering my own post. I am going to explain in detail how to implement googles new reCaptcha v2.0 in McCodes v2. It has taken me several day to do it but at last it works and I am ready at last to share what I have learned with a community that has taught me so much. So here we go. Step 1: Signing up. First thing you need to do is signup for the FREE service by going to the site http://recaptcha.net Here you will need to assign a name to the captcha you are going to use for your own later use. Basically if you are going to use several different captchas on the same site you can name them to make them easier to find later if you need to make updates. Next enter your domain. And then a contact email for notification of anyone tampering with your system. Register the info and it will take you to a new page where it is going to show you a public key and a privet key. These two things are the most important of the whole system. Under the keys it will show you client side coding well as server side coding. This is where I started having problems. Apparently on the server side coding they already expect you to have a certain level of coding knowledge that as a novice I just didn't have. There are no examples of the coding to work off of nor are there really clear instructions. Don't worry thought after hours of searching and trying different bits of code I finally got all this to work. Step 2: Adding in the coding. This is actually much simpler then it seems. You are going to need to update three PHP pages. header.php, macro1.php, and macro2.php We will start with the header.php A very simple addition: This little bit of code calls for googles recaptcha api javascript. Make sure that you place it BEFORE the closing head tag in the header. </head> <script src="https://www.google.com/recaptcha/api.js" async defer></script>   Next macro1.php When I first started this page was 50 - 60 lines long. It was generating images and number letter combinations... Now reCaptcha take care of all of that for you. You will see the generate widget comment. The line of code right under it is what displays the reCaptcha widget on your site. Replace == YOUR PUBLIC KEY == with the public key generated on the register site. That is now the whole page. <?php include "globals.php"; // make sure user is supposed to be here if(!$set['validate_on'] || $ir['verified']) { showErrMsg("What are you doing on this page?"); } // the page that sent you here $ref=$_GET['refer']; print "<h3>Captcha</h3><hr /> <div class=minion_hunt> This is a necessary evil to prevent cheating. It resets every hour. <br><br> <sub>**Five failures in a row will result in 1 day on the banished isle**</sub></div><br> // form <form action='macro2.php' method='post'> // carry over the starting page <input type='hidden' name='refer' value='{$_GET['refer']}' /> // generate the widget for the captcha <div class='g-recaptcha' data-theme='dark' data-sitekey='== YOUR PUBLIC KEY =='></div> //must have a submit button <input type='submit' value='Verify' /></form>"; $h->endpage(); ?>   Finally the big one macro2.php This page is going to verify the data from the captcha. Here is where the google explanation gets a little fuzzy... They tell you to use a json obj to verify the response from the captcha.. ok... what is a json obj? I still have no idea.. But after hours and hours of searching I found the right way to write the code. // make sure user is supposed to be here if(!$set['validate_on'] || $ir['verified']) { die("What are you doing on this page?"); } if(isset($_POST['g-recaptcha-response'])) $captcha=$_POST['g-recaptcha-response']; // If the captcha is blank send them back if(!$captcha){ echo '<h2>Please check the the captcha form.</h2>'; header("Location: macro1.php?refer={$_POST['refer']}"); exit; } // Check the response from google REPLACE: YOUR PRIVET CODE with the privet code from registration. $response=json_decode(file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=YOUR PRIVET CODE&response=".$captcha."&remoteip=".$_SERVER['REMOTE_ADDR']), true); // If they fail send them back to try again update failed = +1 if($response['success'] == false) { echo '<h2>You failed the captcha!</h2>'; $db->query("UPDATE users SET failed=failed+1 WHERE userid={$userid}"); header("Location: macro1.php?refer={$_POST['refer']}"); exit; } else { $ref=$_POST['refer']; $db->query("UPDATE users SET verified=1 WHERE userid={$userid}"); header("Location: $ref"); } ?>   And thats all there is to it. Google does all the rest of the work. There is no need to upload a captcha DB or js file anymore. I really hope that this helps someone else out there to use this new reCaptcha system.
  5. OK guys I'm still working on my minions system but now I am trying to get them to fight each other. I have the basic coding for it done but I'm having a little trouble with the win/lose system. I'm trying to use a WHILE statement with two conditions.   while (($lose >= 0) || ($lose2 >= 0)){ // Attack $myrand = rand(1,3); if ($myrand ==1){ $type = "Human"; $q = $db->fetch_row($db->query("SELECT base FROM minions WHERE id=1")); $base = $q['base']; $suc = rand(1,10); $tot = $suc + $base; } else if ($myrand==2){ $type = "Elf"; $q = $db->fetch_row($db->query("SELECT base FROM minions WHERE id=2")); $base = $q['base']; $suc = rand(1,10); $tot = $suc + $base; } else { $type = "Dwarf"; $q = $db->fetch_row($db->query("SELECT base FROM minions WHERE id=3")); $base = $q['base']; $suc = rand(1,10); $tot = $suc + $base; } //Defend $myrand2 = rand(1,3); if ($myrand2 ==1){ $type2 = "Human"; $q2 = $db->fetch_row($db->query("SELECT base FROM minions WHERE id=1")); $base2 = $q2['base']; $suc2 = rand(1,10); $tot2 = $suc2 + $base2; } else if ($myrand==2){ $type2 = "Elf"; $q2 = $db->fetch_row($db->query("SELECT base FROM minions WHERE id=2")); $base2 = $q2['base']; $suc2 = rand(1,10); $tot2 = $suc2 + $base2; } else { $type2 = "Dwarf"; $q2 = $db->fetch_row($db->query("SELECT base FROM minions WHERE id=3")); $base2 = $q2['base']; $suc2 = rand(1,10); $tot2 = $suc2 + $base2; } if ($tot > $tot2){ $lose = $lose; $lose2 = $lose2 - 1; $result = "Player two loses 1 of ".number_format($perc).""; } else if ( $tot == $tot2) { $lose = $lose; $lose2 = $lose2; $result = "It was a tie"; } else { $lose = $lose-1; $lose2 = $lose2; $result = "Player one loses 1 of ".number_format($perc).""; } print" $result<br>"; }   I have been searching and reading on trying to do this in this fashion but I can't find anything pointing me in the right direction. Now this code DOES actually work. It just doesn't stop when one or the other hits 0. Player two loses 1 of 10 Player two loses 1 of 10 Player two loses 1 of 10 Player one loses 1 of 10 Player one loses 1 of 10 Player one loses 1 of 10 Player one loses 1 of 10 Player two loses 1 of 10 Player two loses 1 of 10 Player two loses 1 of 10 It was a tie Player two loses 1 of 10 Player one loses 1 of 10 Player two loses 1 of 10 Player two loses 1 of 10 Player two loses 1 of 10 Player two loses 1 of 10 Player one loses 1 of 10 Player one loses 1 of 10 Player two loses 1 of 10 Player one loses 1 of 10 Player two loses 1 of 10 Player two loses 1 of 10 It was a tie Player one loses 1 of 10 Player one loses 1 of 10 Player one loses 1 of 10   Random: 3 Type: Dwarf Base: 6 Multi: 1 Total: 7 Win/lose: -1 <----- Here Random: 2 Type: Dwarf Base: 6 Multi: 5 Total: 11 Win/lose: -4 <----- And here
  6. I have been working on a new mod for my game, the first I have ever coded completely on my own, and it seems I have left a huge opening for abuse. Lucky for me I have only opened up a small part of the system to a few selected beta testers and they have been checking different ways to try and get around my security and pointed out any flaws. This one how ever I'm not exactly sure how to fix, so I turn to the MWG community once again for a solution. Here is a small snippet of the coding in question.   <?php // clicking this link adds +1 to north and sets capture row to 1 // Runs a random to determine if anything is found and how many. Can not exceed 50 if ($minions['north_south']>=50){ echo'<center><img src="images/north.png"></center>'; } else { echo '<center><a href="minion_hunt2.php?step=north"><img src="images/north.png"></a></center>'; } // If something is found this is printed $result = "You moved north and found: $amt2 $type!"; $convert = "<a href='minion_hunt2.php?step=capture&amt=$amt2&type=$type' class='button'>Capture Them?</a>"; // clicking the above link runs another random to determine success or failure in the capturing of minions. // sets capture to 0 so page can not be refreshed. ?>   So the problem is all a user needs to do is click a direction and it sets capture to 1. Even if I changed it to set only if they actually find something my existing problem would still be there. If the users clicks a direction then changes the URL to say: ?step=capture&amt=10000&type=dwarves They can decide how many they found and of what type and nothing in my coding is stopping them. How can I stop this? I can't release this system with that hole there would be too many people spreading this URL cheat around.
  7. Ok so I talked with [MENTION=65518]Kyle[/MENTION] yesterday for a bit and we tried to do a little debugging. The coding has changed a little. In the header: I don't know why there are two different ones I think it has something to do with the AJAX chat we are using as well as something else. <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>   move.php : <?php include_once('globals_nonauth.php'); $userid = $_POST['userid']; $minions=$db->fetch_row($db->query("SELECT * FROM user_minions WHERE userid=$userid")); $_POST['direction'] = array_key_exists('direction', $_GET) && in_array($_GET['direction'], ['north', 'east', 'south', 'west']) ? $_GET['direction'] : null; switch($_POST['direction']) { case 'north': // do north stuff if ($minions['north_south']>=50){ $db->query("UPDATE user_minions SET north_south=50 WHERE userid=$userid"); print"You can't move any farther north!"; echo '<META http-equiv="refresh" content="5;URL= /minion_hunt.php"">'; } if ($minions['north_south']>=0 && $minions['north_south']<=49){ $db->query("UPDATE user_minions SET north_south=north_south+1 WHERE userid=$userid"); echo "You have just moved". $_POST['direction']; } break; case 'east': // do east stuff if ($minions['east_west']>=50){ $db->query("UPDATE user_minions SET east_west=50 WHERE userid=$userid"); print"You can't move any farther east!"; echo '<META http-equiv="refresh" content="5;URL= /minion_hunt.php"">'; } else { $db->query("UPDATE user_minions SET east_west=east_west+1 WHERE userid=$userid"); echo "You have just moved". $_POST['direction']; } break; case 'south': // do east stuff if ($minions['north_south']<=0){ $db->query("UPDATE user_minions SET north_south=0 WHERE userid=$userid"); print"You can't move any farther south!"; echo '<META http-equiv="refresh" content="5;URL= /minion_hunt.php"">'; } else { $db->query("UPDATE user_minions SET north_south=north_south-1 WHERE userid=$userid"); echo "You have just moved". $_POST['direction']; } break; case 'west': // do east stuff if ($minions['east_west']<=0){ $db->query("UPDATE user_minions SET east_west=0 WHERE userid=$userid"); print"You can't move any farther west!"; echo '<META http-equiv="refresh" content="5;URL= /minion_hunt.php"">'; } else { $db->query("UPDATE user_minions SET east_west=east_west-1 WHERE userid=$userid"); echo "You have just moved". $_POST['direction']; } break; } ?>   minion_hunt.php: <?php include "globals.php"; if(($ir['jail'] || $ir['hospital']) && $ir['user_level'] !=2) { showErrMsg("This page cannot be accessed while on Moa Isle or Regeneration."); } $minions=$db->fetch_row($db->query("SELECT * FROM user_minions WHERE userid=$userid")); if ($minions['location']!=$ir['location'] && $minions['north_south']!=0 && $minions['east_west']!=0){ $loc=$db->fetch_row($db->query("SELECT cityname FROM cities WHERE cityid={$minions['location']}")); showErrMsg("You are searching the forest in ".$loc['cityname'].". You must move to 0,0 there first."); } if ($minions['location']==0){ $db->query("UPDATE user_minions SET location={$ir['location']} WHERE userid=$userid"); } else if ($minions['location']!=$ir['location'] && $minions['north_south']==0 && $minions['east_west']==0){ $db->query("UPDATE user_minions SET location={$ir['location']} WHERE userid=$userid"); } print" <div class='box-style5'> <div class='title7c'> <h2>Minion Hunting</h2> </div> </div> <div class='box-style5'> <div class='title7e'> <h2>Location: ".$minions['north_south'].",".$minions['east_west']."<br> Endurance: ".$minions['endurance']."</h2> </div> </div>"; //notification echo '<div id="notificationArea"></div>'; print" <table width=75%> <tr> <td colspan=3>"; if ($minions['north_south']==50){ print"<center><img src='images/north.png'></center>"; } else { echo '<center><a href="#" class="directional" id="north"><img src="images/north.png"></a></center>'; } print" </td> </tr> <tr> <td>"; if ($minions['east_west']<=0){ print"<img src='images/west.png'>"; } else { echo '<a href="#" class="directional" id="west"><img src="images/west.png"></a>'; } print" </td> <td><img src='images/forest.png'></td> <td> "; if ($minions['east_west']==50){ print"<img src='images/east.png'>"; } else { echo '<a href="#" class="directional" id="east"><img src="images/east.png"></a>'; } print" </td> </tr> <tr> <td colspan=3>"; if ($minions['north_south']<=0){ print"<center><img src='images/south.png'></center>"; } else { echo '<center><a href="#" class="directional" id="south"><img src="images/south.png"></a></center>'; } print" </td> </tr> </table> <div id=isla-quest> Here you can search the forest of Aniari looking for minions to recruit. <br><br>You will find a variety of creatures such as Humans, Elves, and Dwarves. You can try and recruit any group of them you come across, but remember that they don't always agree. <br><br> You have a limited endurance for these hunts. When it is gone you will have to wait for it to refill before you can start looking again.<br><br> Also if your wish to search the forest of another city you must first move back to location 0,0 in the forest that you are currently searching. </div> "; ?> <script> (function() { $('.directional').on('click',function(e){ var direction = $(this).attr('id'); $.ajax({ method: "POST", url: "move.php", data: { userid: <?php echo $userid; ?>, direction: direction } }).done(function( msg ) { $( "#notificationArea" ).html( msg ); console.log(msg); }).fail(function(req,msg) { $( "#notificationArea" ).html('Request failed: ' + msg ); }); e.preventDefault(); }); }); </script>   Using the error console there are no errors, and no warnings, yet we can't seem to get any response from the AJAX. There is no text posted. There is no update to the data base.
  8. [MENTION=50378]Guest[/MENTION] I have been trying to get up with you for a couple of days now. Seems our schedules are just not lining up. Anyone else out there care to give me a hand with this? I'm completely stuck on this project until I can get this working.
  9. [MENTION=68711]KyleMassacre[/MENTION] I did mention that AJAX was way over my head didn't I? :p So normally I have a coding partner that can help me figure this stuff out but as he has no net for the next few weeks I am on my own. I get that I needed to create a new page called move.php and put my case stuff in there. Where I am getting stuck is the AJAX script. Here is my full page code.   <?php include "globals.php"; if(($ir['jail'] || $ir['hospital']) && $ir['user_level'] !=2) { showErrMsg("This page cannot be accessed while on Moa Isle or Regeneration."); } $minions=$db->fetch_row($db->query("SELECT * FROM user_minions WHERE userid=$userid")); if ($minions['location']!=$ir['location'] && $minions['north_south']!=0 && $minions['east_west']!=0){ $loc=$db->fetch_row($db->query("SELECT cityname FROM cities WHERE cityid={$minions['location']}")); showErrMsg("You are searching the forest in ".$loc['cityname'].". You must move to 0,0 there first."); } if ($minions['location']==0){ $db->query("UPDATE user_minions SET location={$ir['location']} WHERE userid=$userid"); } else if ($minions['location']!=$ir['location'] && $minions['north_south']==0 && $minions['east_west']==0){ $db->query("UPDATE user_minions SET location={$ir['location']} WHERE userid=$userid"); } print" <div class='box-style5'> <div class='title7c'> <h2>Minion Hunting</h2> </div> </div> <div class='box-style5'> <div class='title7e'> <h2>Location: ".$minions['north_south'].",".$minions['east_west']."<br> Endurance: ".$minions['endurance']."</h2> </div> </div> <div id='notificationArea'></div> <table width=75%> <tr> <td colspan=3>"; if ($minions['north_south']==50){ print"<center><img src='images/north.png'></center>"; } else { print"<center><a href='#' class='directional' id='north'><img src='images/north.png'></a></center></a> <script> $('.directional').on('click',function(e){ var direction = $(this).attr('id'); $.ajax({ method: 'POST', url: 'move.php', data: { userid: $userid, direction: direction } }).done(function( msg ) { $( 'notificationArea' ).html( it works ); }).fail(function(req,msg) { $( 'notificationArea' ).html('Request failed: ' + msg ); }); e.preventDefault(); }); </script>"; } print" </td> </tr> <tr> <td>"; if ($minions['east_west']<=0){ print"<img src='images/west.png'>"; } else { print"<a href='#' class='directional' id='west'><img src='images/west.png'>"; } print" </td> <td><img src='images/forest.png'></td> <td> "; if ($minions['east_west']==50){ print"<img src='images/east.png'>"; } else { print"<a href='#' class='directional' id='east'><img src='images/east.png'></a>"; } print" </td> </tr> <tr> <td colspan=3>"; if ($minions['north_south']<=0){ print"<center><img src='images/south.png'></center>"; } else { print" <center><a href='#' class='directional' id='south'><img src='images/south.png'></a></center></a>"; } print" </td> </tr> </table> <div id=isla-quest> Here you can search the forest of Aniari looking for minions to recruit. <br><br>You will find a variety of creatures such as Humans, Elves, and Dwarves. You can try and recruit any group of them you come across, but remember that they don't always agree. <br><br> You have a limited endurance for these hunts. When it is gone you will have to wait for it to refill before you can start looking again.<br><br> Also if your wish to search the forest of another city you must first move back to location 0,0 in the forest that you are currently searching. </div> "; ?>   The finished page should work something like this: [ATTACH=CONFIG]2185[/ATTACH] The top box: Location: The first number should change +1 for north -1 for south. Second number should change +1 for east -1 for west. Both need to stop at 0 and at 50. My original code was a count behind so it kept going over and under. Endurance: Should drop by 1 each move. (Not as worried about this as I am getting the location to work.) Under that box will be another information box that pops up when you actually find something. "You found a group of 22 Humans." Something like that. The very last thing, something else I'm not as worried about until I can get the location to work, is we want to make it to where you can't refresh the page. I don't want someone sitting in one spot and refreshing to make the random run over and over until they find something. They should be forced to change locations. I know its a lot and I'm not asking for someone to recode my page. I just need some education in using the ajax correctly.
  10. So I used the anchor method and figured out how to work it with a switch:   print"<center><a href='?direction=north'><img src='images/north.png'></center></a>";   My switch: $_GET['direction'] = array_key_exists('direction', $_GET) && in_array($_GET['direction'], ['north', 'east', 'south', 'west']) ? $_GET['direction'] : null; switch($_GET['direction']) { case 'north': $db->query("UPDATE user_minions SET north_south=north_south+1 WHERE userid=$userid"); if ($minions['north_south']>50){ $db->query("UPDATE north_south=50 WHERE userid=$userid"); } break; case 'east': $db->query("UPDATE user_minions SET east_west=east_west+1 WHERE userid=$userid"); if ($minions['east_west']>50){ $db->query("UPDATE east_west=50 WHERE userid=$userid"); } break; case 'south': $db->query("UPDATE user_minions SET north_south=north_south-1 WHERE userid=$userid"); if ($minions['north_south']<0){ $db->query("UPDATE north_south=0 WHERE userid=$userid"); } break; case 'west': $db->query("UPDATE user_minions SET east_west=east_west-1 WHERE userid=$userid"); if ($minions['east_west']<0){ $db->query("UPDATE east_west=0 WHERE userid=$userid"); } break; }   I'm running into the issue that the location is not updating correctly. It is always one behind which forced me to add another if statement. I did like the way [MENTION=68711]KyleMassacre[/MENTION] showed me with the ajax but I would have no idea how to add other actions such as update db or random events like the chance of finding an item.
  11. But won't a switch make it change pages?
  12. [MENTION=68711]KyleMassacre[/MENTION] Thanks for the advice. While I agree ajax would be cool that is even farther away from any coding I know how to do... So lets go with your anchor: <a href="?direction=up" id="upArrow"><img src="yourImagePathHere.ext"/></a>   If I use this method would I just move on to something like:   if (direction=up]{ $db->query("UPDATE DB HERE"); }
  13. Hello again everyone. Here I go jumping into something that is way over my head in the terms of coding skill, but what better way to learn to swim then by jumping into the deep end? So here is the idea. I have a screen that has a little map and four direction arrows. I'm trying to figure out how to code things so that when you click on one of the arrows it updates your location with out changing pages. I know the page will refresh. My limited coding skills are telling me to use a form or a switch but I know both of these are wrong. There must be a simpler way of doing this that I just don't see. Here is a shot of the screen I am working with. Each of the arrows is already a link that goes no where. [ATTACH=CONFIG]2183[/ATTACH]
  14. Normally I am much more carful when writing my CSS, but I am just back from a very long summer season of work and was in a rush to get a new system out. I use Coda which I just found out could have verified my CSS and shown me the error right away. This is what I get for being in a hurry. :p
  15. Did you get any kind of error code? [MENTION=64684]Dayo[/MENTION] [MENTION=71663]IllegalPigeon[/MENTION] Thank you so much! I have been beating my head against that for days now and it was simply a bracket missed in a copy and paste. I feel like an idiot now.
×
×
  • Create New...