Jump to content

Monkuar

Members
  • Content Count

    987
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by Monkuar

  1. It's because $query = "select username from member";Isn't checking against a username, you need to specify WHERE username = ? I'm sure that's why you havn't had $unameErr = "* Username already in use. Please choose another."; firing and you're receiving duplicates? New code: (I updated the new query = WHERE username and added mysql_real_escape_string to it. I also tabbed the code a bit to make it look nice. Let me know how this goes: <?php if (empty($_POST["uname"])) { $unameErr = "* Username is required"; } else { $uname = test_input($_POST["uname"]); if (!preg_match("/^[a-zA-Z0-9]*$/",$uname)) { $unameErr = "* Only letters and numerals are allowed"; } else { // Now sure the username is legit, we check to see if it's a // unique username by comparing it to all usernames already in member table. require_once 'login.php'; // This file contains database access credentials $db_conn = new mysqli($db_hostname, $db_username, $db_password, 'login'); if($db_conn->connect_error) die ('Connect Error: ('.$db_conn->connect_errno.')'.$db_conn->connect_error); $query = 'select username from member WHERE username = \''.mysql_real_escape_string($uname).'\' LIMIT 1'; // Only selecting the field to compare to $result = $db_conn->query($query); if(!$result) die ('Database access failed: ('.$db_conn->connect_errno.')'.$db_conn->connect_error); $rows = $result->num_rows; for($i = 0; $i <= $rows; $i++) { if(mysqli_fetch_assoc($result) == $uname) { $unameErr = "* Username already in use. Please choose another."; mysql_close($db_conn); exit; } } if (empty($unameErr)){ // Make sure unameErr is empty (no errors) before submitting the data. $query = "insert into member values(NULL, '$uname', '$pwd1', '$fname', '$lname')"; $result = $db_conn->query($query); if(!$result) die ("Database insertion failed: ".mysql_error()); } } } ?>.. and Shitty IPB forum software doesn't save tabbed code, what a joke. Oh well. Sorry >_> Edit: Oh it does save it when you turn off the editing feature.. lol
  2. I'm sure you'll do just fine with Javescript. Heard it works perfectly, being you know, case insensitive and whatnot.
  3. Wrote some beautiful code (well that can be subjective). But to me anyways, this code checks if the item is placed on a box and that if the dimensions of the item will overlap the outside container = Out of bounds: csz= tempitemdata.getAttribute('slot-size'); sgo = parseInt( this.getAttribute('data-slot') ); if (csz[2]> 1){ // Bottoms Rows Disabled X Positions for (e=0; e < slots; e++){ limitX=(csz[2])? (csz[2]*9-9):0; if(sgo > ( slots - limitX ) ){ notify('Item out of bounds ~ '); return; } } }if (csz[0] == 2){ // 0,2++ Bottoms Rows Disabled Y Positions multi = new Array,c=0; while(c<slots){ multi.push( 9 * c); c++; } if(multi.indexOf(sgo)!=-1){ notify('Item out of bounds ~ '); return; } } I love the indexOf short hand function. It's literally insane. It's not EXACTLY like the in_array function in php, but it's pretty damn close. As you can see on this code. I'm pushing my multi array of multiples of 9. So if the slot_Size of an item is 1x2 or greater, it checks down the Y row every 9th slot. And if a user trys to put an item at that slot they cannot because the width would be out of bounds. I just need a good way to do this serverside now. I guess I'll convert the code above into php and check it against the database too. The issue is... the padding or SCOPE of items dimensions need to be checked dynamically so they don't overlap.... This can be done clientside with javascript, but serverside, I'm not too sure. mac_quer posted some code to help, but his code didn't check the dimensions of an item (padding). In any event. I'm only going to have 1x3, 1x2 and 1x1 dimensions and 2x2 (For armor) right now. I'll have a reset button in the inventory to clear the slots if we got script kiddies playing with live HTTP headers trying to fool around with item positioning though, so I'll be fine. The user experience will still be 99% working just like Path of Exile and Diablo 2! I am extremely happy! I scratched interactJS too! I'm just using basic Diablo 2 inventory movement with basic javascript: hasitem=0; tempitemdata = 0; tempitemdata2 = 0; slots = 99; function checkinventory(){ ibox = qsa('.InventoryTest'); for(i=0; i < ibox.length; i++){ ibox[i].onclick=function(){ //console.log( tempitemdata ); if(hasitem == 1){ /* if (this.childNodes[1]){ //swap? console.log(tempitemdata); this.childNodes[1].style.display='none'; tempitemdata.style.display='inline-block'; this.appendChild(tempitemdata); tempitemdata=this.childNodes[1]; setTimeout(function(){ hasitem = 1; }, 100); qs('#InventoryWindow').style.cursor="url("+this.childNodes[1].getAttribute('item-image')+"),auto"; return; } */ if (this.childNodes[1] || this.childNodes[0]){ hasitem = 0; tempitemdata.style.display='inline-block'; notify('An item already exists here.'); qs('#InventoryWindow').style.cursor="default"; return; } csz= tempitemdata.getAttribute('slot-size'); sgo = parseInt( this.getAttribute('data-slot') ); if (csz[2]> 1){ // Bottoms Rows Disabled X Positions for (e=0; e < slots; e++){ limitX=(csz[2])? (csz[2]*9-9):0; if(sgo > ( slots - limitX ) ){ notify('Item out of bounds ~ '); return; } } }if (csz[0] == 2){ // 0,2++ Bottoms Rows Disabled Y Positions multi = new Array,c=0; while(c<slots){ multi.push( 9 * c); c++; } if(multi.indexOf(sgo)!=-1){ notify('Item out of bounds ~ '); return; } } tempitemdata2.innerHTML=''; tempitemdata.style.display='inline-block'; if(hasitem == 1){ qs('#InventoryWindow').style.cursor="default"; setTimeout(function(){ hasitem = 0 }, 50); this.appendChild(tempitemdata); } } } } } iitems = qsa('.itemdrag'); for(i=0; i < iitems.length; i++){ iitems[i].onclick=function(){ if (hasitem == 0){ itemimage = this.childNodes[1].childNodes[1].src; this.style.display='none'; tempitemdata=this; tempitemdata2=this.parentNode; qs('#InventoryWindow').style.cursor="url("+itemimage+"),auto"; setTimeout(function(){ checkinventory(); hasitem = 1 }, 100); } } }It's awesome and intuitive in my opinion and works just like D3's. I can add more styling later to make it sexier, but for now it's fine. Gyzo makes the images upon clicking really weird, ignore that. But your cursor changes to the item itself upon clicking, it's just like D2's, so awesome! I am so happy too!! So lightweight no interactJS, or plugins. Love it.
  4. You'll have to use some type of session handler. Some options: build your own (session_set_save_handler) or use extensions that provide their own session handler, like memcached.
  5. Good. I made it so every slot is droppable when the user starts to drag the item (green background) [ Although, will not show it when we go live because like you said, the user can already see where to place it because of the borders and boxes]. Then, when the user drops the elements, just check to see if it overlaps, and if it does, revert the image back to the original position, right? That's what I'm doing now, it's just going to be hard because if an item is 2x2, and a user is moving a item that is 1x1, it will only revert if the user tries to drag it on the 1x1 of the 2x2 slot. If that makes sense. For example, let me show u: I need to DETECT the padding around an image based on their dimensions and fill in the appropiate boxes below: For example.. That belt has the dimensions 2x1 2width and 1 height. I need to edit the <div class="InventoryTest"> classes with a "PADDING" that is one to the right of the item, so it will revert back on my image instead. It's reverting back if it checks if their is a parent node on that InventoryTest (And there is it's the belt), but the BELT is only in 1 SLOT, but has 2boxes of an dimension. There is essentially a false position slot. How do I creating a PADDING around the box slots (InventoryTest divs) via the DOM? TLDR.. All items are essentially in 1 SLOT position. 1,100 (I have 99 slots). But if an image is in 1 SLOT that is 2x WITH, it's actually taking up 2 HORIZONTAL slots, but the slot next to it, isn't actually holding any data.. that's the problem. I need to HAVE A PADDING around them based on their dimensions. So if that belt is in slot position 60, it should be taking up 60 and 61. Because it's a width of 2. But it's only taking up position 60. I need some type of padding function / formula. But it's not, because it's 1 item in 1 slot and the image is just showing it like because it's 55px horizontal.
  6. Well yeah. Because your local web dev browser doesn't have a built in php mail function! Unless, ofcourse, you have a mail server setup on localhost. What error are you getting? Try to take out that echo, and put whatever you want to echo out in the welcome.html page instead
  7. Your issue is not having error checking. Here is your new code: <!DOCTYPE html> <html> <head> <title>DFW Information Technologies</title> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta name="generator" content="Bluefish 2.2.5" > <meta name="author" content="Landslyde" > <meta name="date" content="2015-01-25T17:49:28-0600" > <meta name="copyright" content=""> <meta name="keywords" content=""> <meta name="description" content=""> <meta name="ROBOTS" content="NOINDEX, NOFOLLOW"> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <meta http-equiv="content-type" content="application/xhtml+xml; charset=UTF-8"> <meta http-equiv="content-style-type" content="text/css"> <meta http-equiv="expires" content="0"> <link href="style/index.css" rel="stylesheet"> <!--[if lt IE 9]> <script scr="html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> </head> <body> <h1>DFW Information Technologies</h1> <img class="img1" src="images/blue_world.jpeg" width="225" height="225"> <div class="gradientbuttons"> <ul> <li><a href="index.html">Home</a></li> <li><a href="about.html">About Us</a></li> <li><a href="services.html">Services</a></li> <li><a href="register.php">Register</a></li> <li><a href="client.php">Client Area</a></li> <li><a href="contact.html">Contact Us</a></li> </ul> </div> <?php error_reporting(E_ALL | E_NOTICE); ini_set('display_errors', '1'); $fnameErr = $lnameErr = $emailErr = $unameErr = $pwd1Err = $pwd2Err = ""; $fname = $lname = $email = $uname = $pwd1 = $pwd2 = ""; if ($_SERVER["REQUEST_METHOD"] == "POST") { if (empty($_POST["fname"])) { $fnameErr = "* First name is required"; } else { $fname = test_input($_POST["fname"]); if (!preg_match("/^[a-zA-Z]*$/",$fname)) { $fnameErr = "* Only letters are allowed"; } } if (empty($_POST["lname"])) { $lnameErr = "* Last name is required"; } else { $lname = test_input($_POST["lname"]); if (!preg_match("/^[a-zA-Z]*$/",$lname)) { $lnameErr = "* Only letters are allowed"; } } if (empty($_POST["email"])) { $emailErr = "* Email is required"; } else { $email = test_input($_POST["email"]); if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { $emailErr = "* Invalid email format"; } } if (empty($_POST["uname"])) { $unameErr = "* Username is required"; } else { $uname = test_input($_POST["uname"]); if (!preg_match("/^[a-zA-Z0-9]*$/",$uname)) { $unameErr = "* Only letters and numerals are allowed"; } } if (empty($_POST["pwd1"])) { $pwd1Err = "* Password is required"; } else { $pwd1 = test_input($_POST["pwd1"]); } if (empty($_POST["pwd2"])) { $pwd2Err = "* Password confirmation is required"; } else { $pwd2 = test_input($_POST["pwd2"]); if($pwd1 != $pwd2) { $pwd2Err = "* Passwords do not match"; } } if ( empty($pwd2Err) && empty($pwd1Err) && empty($unameErr) && empty($emailErr) && empty($lnameErr) && empty($fnameErr) ){ // Good to go $to = $email; // this is your Email address $from = "verify@dfwit.co"; // this is the sender's Email address $subject = "Form submission"; $message = $fname . ":\n\n" . "Thank you for subscribing to DFW Information Technologies database services.\n\nYour login credentials are:\n\nUsername: ".$uname."\nPassword: ".$pwd1."\n\nPlease click the link below to proceed to Login screen:\n\nhttp:www.dfwit.co/index.html\n\n\n\nTech Support: techsupport@dfwit.co\nSales: sales@dfwit.co"; $headers = "From:" . $from; mail($to,$subject,$message,$headers); echo "Mail Sent. Thank you " . $fname . ", we will contact you shortly."; header("Location: www.dfwit.co/index.html"); // I put this in but it won't redirect until the mail // This is a personal problem. If your email server is slow, that's too bad lol. } } function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } ?> <form method="post" action="<?php echo htmlentities($_SERVER['PHP_SELF']);?>"> <input type="text" name="fname" placeholder="First Name" value="<?php if (isset($_POST['fname'])) { echo $fname; } ?>"> <span class="error"> <?php echo $fnameErr;?></span><br><br> <input type="text" name="lname" placeholder="Last Name" value="<?php if (isset($_POST['lname'])) { echo $lname; } ?>"> <span class="error"> <?php echo $lnameErr;?></span><br><br> <input type="text" name="email" placeholder="E-mail Address" value="<?php if (isset($_POST['email'])) { echo $email; } ?>"> <span class="error"> <?php echo $emailErr;?></span><br><br> <input type="text" name="uname" placeholder="Username" value="<?php if (isset($_POST['uname'])) { echo $uname; } ?>"> <span class="error"> <?php echo $unameErr;?></span><br><br> <input type="password" name="pwd1" placeholder="Password" value="<?php if (isset($_POST['pwd1'])) { echo $pwd1; } ?>"> <span class="error"> <?php echo $pwd1Err;?></span><br><br> <input type="password" name="pwd2" placeholder="Confirm Password" value="<?php if (isset($_POST['pwd2'])) { echo $pwd2; } ?>"> <span class="error"> <?php echo $pwd2Err;?></span><br><br> <input type="submit" value="Submit"></button> </form> </body> </html>The email 'lag' you receive is a personal issue. If your email server is slow, that's too bad lol. Hope this helps. Also, put this: echo "Mail Sent. Thank you " . $fname . ", we will contact you shortly.";At the welcome.html page. They won't see that echo.
  8. I've think I actually pushed javascript to the limits where what I'm trying to do isn't even actually feasible. I'm using interactJS for drag and drop. Upon the drag event, I simply call a function to make 1x2 div's inside the inventory. (For places for the sword to be placed). The limitation is: Watch the last 2 seconds of this gif. It's impossible to have it be placed at position X1, Y1. Edit: This is the code to loop through all the boxes and show the green placeholder. itest = qsa('.iBoxes2'); itemtype = event.target.getAttribute('slot-size'); console.log(' Width: '+itemtype[0]+' | Height: '+itemtype[2]+' '); iwidth=(itemtype[0]*25.5); iheight=(itemtype[2]*24.5); console.log(iwidth); counter=0; for(i=0; i < itest.length; i++){ cslot = itest[i].getAttribute('data-slot'); if ( counter % 2 ==0 && cslot != 9 && cslot != 18 && cslot != 27 && cslot != 36 && cslot != 45 && cslot != 54 && cslot != 63) { itest[i].style.position='relative'; itest[i].style.display="inline-block"; itest[i].style.width=""+iwidth+"px"; itest[i].style.background='#D8FFDA'; itest[i].style.height=""+iheight+"px" } counter++; }qsa is function qsa(e){return document.querySelectorAll(e)}
  9. Ya forgot a semi colon lol. Welcome !
  10. Isn't the item identified in the array though? $item = array('id'=>5,'w'=>5,'h'=>5); // define a 'test' item $grid[1][2] = 5; // put an item in the grid (value is the item's id, 0 = empty, not used as an id value) var_dump(test_pos(1,3,$item,$grid)); Yeah, the existing item in the grid is x=1, y=2, but it's defined in the $item=array with width=5, h=5. not w=1, h=1. Where did u get w=1, h=1 from?
  11. Okay. I found an issue in the code: // example usage - $item = array('id'=>5,'w'=>5,'h'=>5); // define a 'test' item $grid[1][2] = 5; // put an item in the grid (value is the item's id, 0 = empty, not used as an id value) var_dump(test_pos(1,3,$item,$grid));This returns 1 (String OK) which it shouldn't.Because if you have an item at location 1,2 and the item id is 5. The WIDTH of that item is 5 ('w'=>5). So 1,3 should be overlapping. 1,4 too, 1,5, 1,6, and 1,7. 1,8 is a free spot (But then it would be outof bounds). Also: I added this to display the grid: foreach ($grid as $widthbox => $heightbox){ // Grid layout: foreach($heightbox as $heightgrid => $item){ $counter++; if ($item['id'] == $i){ // Trying to display the item based on it's width and height values ( How many boxes to take up! ?? ) // We have a match. $i = $item['id']; $w = $item['w']; $h = $item['h']; echo '<div class="InventoryTest" title="'.$counter.'"> '.$item.'</div>'; }else{ echo '<div class="InventoryTest" title="'.$counter.'"> '.$item.'</div>'; } } }The problem is, if a item's width is 5 boxes, I cannot seem to make it a 'block' and take up those corresponding 5 blocks horizontally. css for everything is: <style> .fadeIn{animation-name:fadeIn;-webkit-animation-name:fadeIn;animation-duration:.7s;-webkit-animation-duration:.7s;animation-timing-function:ease-in-out;-webkit-animation-timing-function:ease-in-out;visibility:visible!important}@keyframes fadeIn{0%{transform:scale(0);opacity:0}60%{transform:scale(1.1)}100%{transform:scale(1);opacity:1}}@-webkit-keyframes fadeIn{0%{-webkit-transform:scale(0);opacity:0}60%{-webkit-transform:scale(1.1)}100%{-webkit-transform:scale(1);opacity:1}} .InventoryTest{ border:1px solid #D3D3D3;border-bottom:0;width:24px;height:24px;float:left;padding:3px;border-right:0; } .itemdrag{position:relative;z-index:1} .InventoryTest:nth-child(9n+9){ border-right:1px solid #D3D3D3 } .InventoryTest:nth-last-child(-n+9){ border-bottom:1px solid #D3D3D3; } .itemdrag{position:relative;z-index:1} </style> <?php error_reporting(E_WARNING); // origin is top, left - 1,1 (x,y) // define grid size $max_x = 9; // across $max_y = 9; // down // create empty grid - $x = range(1,$max_x); $y = range(1,$max_y); $grid = array(); foreach($x as $xx){ foreach($y as $yy){ $grid[$xx][$yy] = 0; } } // for any requested x,y position, determine if the $item can be placed starting at that position in the grid // inputs - $x,$y - requested position // $item - item definition array(id, width, height) // $grid - the grid holding existing items // processing - test starting at the requested position if the item fits within the grid boundary and that all the corresponding cells are empty // return - 1 if the item can be placed at the requested position, 2 if out of bounds, 3 if overlap another item define('POS_OK', 'OK'); define('POS_OUTOFBOUNDS', 'OUT OF BOUNDS'); define('POS_OVERLAP', 'OVERLAP'); function test_pos($x,$y,$item,$grid){ $w = $x + $item['w'] - 1; // highest width $h = $y + $item['h'] - 1; // highest height // check if out of bounds if(!isset($grid[$x]) || !isset($grid[1][$y]) || !isset($grid[$w]) || !isset($grid[1][$h])){ return POS_OUTOFBOUNDS; } // check if overlap for($xx = $x; $xx <= $w; $xx++){ for($yy = $y; $yy <= $h; $yy++){ if($grid[$xx][$yy] != 0){ return POS_OVERLAP; } } } return POS_OK; } // example usage - $item = array('id'=>5,'w'=>5,'h'=>5); // define a 'test' item $grid[1][1] = 5; // put an item in the grid (value is the item's id, 0 = empty, not used as an id value) var_dump(test_pos(1,3,$item,$grid)); ?> <div style="width:310px" id="InventoryContainer" onmouseleave="qs('#InventoryContainer').style.cursor='default'"> <?php foreach ($grid as $widthbox => $heightbox){ // Grid layout: foreach($heightbox as $heightgrid => $item){ $counter++; if ($item['id'] == $i){ // Trying to display the item based on it's width and height values ( How many boxes to take up! ?? ) // We have a match. $i = $item['id']; $w = $item['w']; $h = $item['h']; echo '<div class="InventoryTest" title="'.$counter.'"> '.$item.'</div>'; }else{ echo '<div class="InventoryTest" title="'.$counter.'"> '.$item.'</div>'; } } } ?> </div>
  12. PHPBB3 does it. I crafted it on my own forum too. Why not have it here? Code is being posted daily. https://www.phpbb.com/community/viewtopic.php?p=5655675#p5655675 See it in action? That would be usefull here instead of dragging and highlighting our mouse over the code and pressing CTRL+C. If IPB has a custom BBCODE manager, you could just use the code in their topic @Phillip.
  13. This might be a Godsend, but requinex pm'd me with some guidelines and an overhow on how to do it. I'm going to try to spend all today figuring this out on my own instead of just copying your code. I feel like I would be cheating myself, and that's not right. I will spend all day today, and if nothing prevails I'll use this as a startup. Marked as best answer, thank you mac. Requinex told me it should be 0,0 as top left. Now you're saying it should be 1,1. Life is confusing lol, haha. I need to get away from the house and just do this I know I can
  14. I'm going to MAKE this task very simple for you. I am just not that experienced with php yet to conquer this specific task. Let me get you started with some examples of how easy the client side of this is. Copy and paste this and run it as index.php on your dev server: <script src="http://code.interactjs.io/interact-1.2.2.min.js"></script> <script> function qs(expr){return document.querySelector(expr)} </script> <style> .fadeIn{animation-name:fadeIn;-webkit-animation-name:fadeIn;animation-duration:.7s;-webkit-animation-duration:.7s;animation-timing-function:ease-in-out;-webkit-animation-timing-function:ease-in-out;visibility:visible!important}@keyframes fadeIn{0%{transform:scale(0);opacity:0}60%{transform:scale(1.1)}100%{transform:scale(1);opacity:1}}@-webkit-keyframes fadeIn{0%{-webkit-transform:scale(0);opacity:0}60%{-webkit-transform:scale(1.1)}100%{-webkit-transform:scale(1);opacity:1}} .InventoryTest{ border:1px solid #D3D3D3;border-bottom:0;width:24px;height:24px;float:left;padding:3px;border-right:0; } .itemdrag{position:relative;z-index:1} .InventoryTest:nth-child(9n+9){ border-right:1px solid #D3D3D3 } .InventoryTest:nth-last-child(-n+9){ border-bottom:1px solid #D3D3D3; } .itemdrag{position:relative;z-index:1} </style> <?php error_reporting(E_ERROR); //Display 63 boxes (Fits with the css nth-child tags to look pretty! lol) for($i = 1; $i < 64; $i++){ if ($i == 1){ // Slot positions 1 Dimensions: 3x3 (lengthXwidth) $item1 = '<div class="itemdrag" item_id='.$i.' data-cslot='.$i.'><img src=http://i.imgur.com/3azYLNf.png></div>'; }elseif($i==4){ // Slot position 2 Dimensions 2x1 lengthXwidth) $item1 = '<div class="itemdrag" item_id='.$i.' data-cslot='.$i.'><img src=http://i.imgur.com/l3y0W7d.png></div>'; }else{$item1 = '';} $inventoryboxes .= '<div class="InventoryTest" data-slot='.$i.'>'.$item1.'</div>'; } ?> <div style="width:300px"> <?php echo $inventoryboxes ?> </div> <script> // target elements with the "draggable" class interact('.itemdrag') .draggable({ // enable inertial throwing inertia: true, onstart: function (event) { }, // call this function on every dragmove event onmove: function (event) { var target = event.target, // keep the dragged position in the data-x/data-y attributes x = (parseFloat(target.getAttribute('data-x')) || 0) + event.dx, y = (parseFloat(target.getAttribute('data-y')) || 0) + event.dy; // translate the element target.style.position = "relative"; target.style.zIndex="2500"; target.style.webkitTransform = target.style.transform ='translate(' + x + 'px, ' + y + 'px)'; // update the posiion attributes target.setAttribute('data-x', x); target.setAttribute('data-y', y); }, // call this function on every dragend event onend: function (event) { var target = event.target; target.removeAttribute("style"); target.removeAttribute("data-x"); target.removeAttribute("data-y"); } }); interact('.InventoryTest').dropzone({ // only accept elements matching this CSS selector accept: '.itemdrag', // Require a 75% element overlap for a drop to be possible overlap: 0.40, // listen for drop related events: ondropactivate: function (event) { var draggableid = event.relatedTarget; // add active dropzone feedback // Is this and item that can be equipped? if (event.relatedTarget.getAttribute('item-type') != "Misc"){ //qs('#shadow'+draggableid.getAttribute('item-type')+'').style.display='none'; } event.target.classList.add('drop-ACCEPT'); }, ondragenter: function (event) { var draggableElement = event.relatedTarget, dropzoneElement = event.target; // feedback the possibility of a drop dropzoneElement.classList.add('drop-target'); draggableElement.classList.add('can-drop'); //draggableElement.textContent = 'Dragged in'; }, ondragleave: function (event) { // remove the drop feedback style event.target.classList.remove('drop-target'); event.relatedTarget.classList.remove('can-drop'); //event.relatedTarget.textContent = 'Dragged out'; }, ondrop: function (event) { var dragid = event.relatedTarget; if (event.target.hasChildNodes()) { //console.log(event.target.childNodes[1]); return; } var slotp = event.target.getAttribute("data-slot"); var slotp2 = event.relatedTarget.getAttribute("data-cslot"); var shadowid = qs('#shadow'+dragid.getAttribute('item-type')+''); var item_id = event.relatedTarget.getAttribute("item_id"); // <-- The one being dragged //We need to show the shadow gear again. (shadowid) ? shadowid.style.display='inline-block': ''; qs('[data-slot="'+slotp2+'"]').innerHTML=''; qs('[data-slot="'+slotp+'"]').appendChild(event.relatedTarget); event.target.childNodes[0].setAttribute("data-cslot", slotp); //We do our ajax functions here, just log the information for now: console.log(" item_id="+item_id+"&slot_go="+slotp+" "); event.relatedTarget.className += ' fadeIn'; //console.log(event.relatedTarget); //console.log(event.target); //event.relatedTarget.textContent = 'Dropped'; }, ondropdeactivate: function (event) { // remove active dropzone feedback event.target.classList.remove('drop-ACCEPT'); event.target.classList.remove('drop-target'); } }); </script> Now, go there and drag and move the belt around in the inventory. They should update accordingly. Example: Press F12 and check your console. You should see upon each item being moved, it's logging their slot it was moved. What I need? I need this where items CANNOT overlap each other in the inventory. The items need to be piped from mysql and positioned to the appropriate position in the inventory. You need to be experienced in Javascript and PHP for this. InteractJS because if you check the example above, the armor is being dragged, but you cannot drop it on anything because interactjs doesn't know it's that big. If you look at Diablo 2's inventory system, and Path of Exile's or Diablo 3's, you can get an idea of what I'm looking for. Let me know if you're interested in this and what price. There is a field in my rpg_user_items table called slot_position and slot_size. slot_size represents the widthxheight of the item. (in this example and code above, it's 3x3 (armor) and 2x1 (belt).
  15. Yeah, that's the problem I faced. I had to scratch this project and just go back to my original inventory system: I really want to do the inventory system like Path of Exile or Diablo 2's/3's. But the problem is. I cannot get the positions of the other items when moving the main item. (Well, I could, but I cannot do it dynamically) I added a field in my rpg_items table called slot_size and for the belt it was 2x1 (2 WIDTH, 1 HEIGHT), and slot position = 1. Then, I used explode to check the width and height of all the users inventory items But... the image is spanning across 2 blocks. So I just don't know how to read the image, so a user cannot put a item in slot position 2. But then, what if the item they are moving is 3x2? or 1x5? Too much algorithm / math involved that I could never really understand. What if the belt was 2x5? 2width and 5 blocks high? How do I check serverside if a user was putting an item on the XX slot? 5 blocks down would be in row 5, and slot number whatever. Just too much shit going on and I cannot do it. I'm sorry guys, failed you but this was too much. I am either wrong on the design process, or my knowledge is the bottleneck. I'm using interactJS to drag and drop though. So if anyone crafts this up, I'll pay around 50$. But other then that, I'm happy with my regular 1 slot moving inventory system.. well not really. I would really love a D2/Path of Exile feel... but too complicated atm. Time is Gold.
  16. Nice one Req, I thought you were going to do something with the number bytes format code you crafted earlier though. Still impressive though, love this.
  17. Rules: 1) It has to be legit and actually work and have a useful function in society/web world. 2) The code cannot be minimized into one line. It has to have line breaks. (Not necessarily for each new function or short hand property, but so it's partly readable) 3) It has to be written in PHP or Javascript. For example, (Not my original code) but I'll start: A time_ago function: function timeago($tm,$rcs = 0) { $cur_tm = time(); $dif = $cur_tm-$tm; $pds = array('second','minute','hour','day','week','month','year','decade'); $lngh = array(1,60,3600,86400,604800,2630880,31570560,315705600); for($v = sizeof($lngh)-1; ($v >= 0)&&(($no = $dif/$lngh[$v])<=1); $v--); if($v < 0) $v = 0; $_tm = $cur_tm-($dif%$lngh[$v]); $no = floor($no); if($no <> 1) $pds[$v] .='s'; $x = sprintf("%d %s ",$no,$pds[$v]); if(($rcs == 1)&&($v >= 1)&&(($cur_tm-$_tm) > 0)) $x .= time_ago($_tm); return $x; }Your turn!
  18. In PHP? Let's say I'm going off of: width x height So this is 2x1 2x1 2 blocks across, 1 block height. How do I check this against other blocks in php to see if the 2x1 will overlap another set of dimensions dynamically? Am I over thinking this?
  19. His site is broke. Wait, I guess he doesn't allow html characters in a contact form. I don't blame him. I just sent him a text message then. Thanks!
  20. ? Is there an option somewhere in this cesspool infested IPB settings panel?
  21. Well, that was a thought out and nice reply. Currently, I'm not using stream_select, or I cannot find it inside my server file. What the server is actually running (literally) is: And this is what is being buffered or as u said (memory usage for each concurrent user): $wsClients[ integer ClientID ] = array( 0 => resource Socket, // client socket 1 => string MessageBuffer, // a blank string when there's no incoming frames 2 => integer ReadyState, // between 0 and 3 3 => integer LastRecvTime, // set to time() when the client is added 4 => int/false PingSentTime, // false when the server is not waiting for a pong 5 => int/false CloseStatus, // close status that wsOnClose() will be called with 6 => integer IPv4, // client's IP stored as a signed long, retrieved from ip2long() 7 => int/false FramePayloadDataLength, // length of a frame's payload data, reset to false when all frame data has been read (cannot reset to 0, to allow reading of mask key) 8 => integer FrameBytesRead, // amount of bytes read for a frame, reset to 0 when all frame data has been read 9 => string FrameBuffer, // joined onto end as a frame's data comes in, reset to blank string when all frame data has been read 10 => integer MessageOpcode, // stored by the first frame for fragmented messages, default value is 0 11 => integer MessageBufferLength // the payload data length of MessageBuffer ) And the maximum amount in bytes per payload are: // the maximum length, in bytes, of a frame's payload data (a message consists of 1 or more frames), this is also internally limited to 2,147,479,538 define('WS_MAX_FRAME_PAYLOAD_RECV', 500); // the maximum length, in bytes, of a message's payload data, this is also internally limited to 2,147,483,647 define('WS_MAX_MESSAGE_PAYLOAD_RECV', 500);Not that much, 500 bytes? That's nothing. But then again, I am using this gameserver for only inventory item slot updates and a chat server. For example: Check this out, no HTTP requests, items are updated via websockets. And this takes care of that ^: cb.socket.send('SLOTUPDATE 412 2');2 being the slot position. This then runs this inside my websocket gameserver: elseif ($command == 'SLOTUPDATE') { $item_id = intval($message[0]); if ($item_id < 1){return;} $slot_id = intval($message[1]); if ($slot_id < 1){echo "No.."; return;} if ($slot_id > 20) { wsSend($clientID, 'GERROR You have exceeded the maximum <b>slot</b> limit. '); return; } //Check if the user even owns this item: $checkquery = $db->query('SELECT rpg_items_id,slot_position from rpg_user_items where user_id = '.$users[$clientID]['user_id'].' LIMIT 20 '); if (!$db->num_rows($checkquery)){ echo "Invalid Item ID, or item does not exist."; return; } //If they're moving it into the same slot? Cannot do it that.. while ($checkdata = $db->fetch_assoc($checkquery)){ $slotarray[] = $checkdata['slot_position']; } //var_dump($slotarray); if (in_array($slot_id, $slotarray)) { wsSend($clientID, 'GERROR You already have an item in that specific slot, please move it.');return; } //If the system got passed all the checks and exits'... move the damn item! $db->query('UPDATE rpg_user_items SET slot_position = '.$slot_id.' where itemid = '.$item_id.' AND user_id = '.$users[$clientID]['user_id'].' LIMIT 1 '); wsSend($clientID, 'GSUCCESS Item successfully moved.'); echo var_dump($message); }Also, this thing is a MYSQL saver if you think about it. The websocket stores ALL user's data (essentially sessions), in a variable, and you can update a user without even authenticating them per each update. Yes, I authenticate them upon connection to the websocket server then once authenticated, I store their server values to the array in the websocket. And you can use them like a wild billy goat freely and securely. It's actually pretty awesome. It's pretty much like php $_SESSION's, but inside a websocket connection, and there is no fwrite, or fopen crap too. It's actually a performance INCREASE in my opinion when dealing with mysql updates; especially when updating the user, or in this case, item slots. For example in that gif I posted above. That's around 5 HTTP requests and 5kb of transfer data saved because of websockets. That mind sound very small now, but if there is let's say 2,000 users updating their item slots, that's over 10000 kilobytes saved just in that short period of time ALONE. (Whether it be a day, 2 days, a month, whatever). But I do need to figure out the length of the data being store inside the websocket connection (the session essentially). Pretty much this: Cannot be that much. Wait, let me get the size of the session array information per user: function addUser($clientID, $username, $userID, $rowdata) { global $users; // let all clients know about this user joining (not including the user joining) foreach ($users as $clientID2 => $username2) { wsSend($clientID2, 'ONJOIN '.$username.' '.$rowdata[0]['selected_characterid'].''); } // send list of usernames to the user joining $usernames = getUsernames(); echo ' Add User Function Dump:'; echo " \n "; var_dump($usernames); wsSend($clientID, 'USERS '.implode(' ', $usernames)); //Flood Control Data $users[$clientID]['last_session_request'] = microtime_float(); // store the user's client ID and username $users[$clientID]['username'] = $username; $users[$clientID]['user_id'] = $userID; $users[$clientID]['timezone'] = $rowdata[0]['timezone']; $users[$clientID]['selected_characterid'] = $rowdata[0]['selected_characterid']; //RPG Values $users[$clientID]['min_dmg'] = $rowdata[0]['min_dmg']; $users[$clientID]['max_dmg'] = $rowdata[0]['max_dmg']; $serialized = serialize($users); if (function_exists('mb_strlen')) { $size = mb_strlen($serialized, '8bit'); } else { $size = strlen($serialized); } echo $size; var_dump($users); }So the $size is outputting roughly, 231 bytes for the user's session in socket. That's pretty much the "Character stats (hp, str, armor, etc)", part you were talking about. After adding these up, you're actually pretty damn close with your numbers...
  22. Yeah, but that's why I already store the users items in a table and have them for each row. So I don't have to do that. But I'm trying to store the users inventory into a field like this so I don't have to query the rpg_user_items database everytime just to check if a users inventory is full, you know? Hope this helps
  23. Lol, I'm running Is there one for nginx?
  24. Before reading: I already have a system in place for inventory management. I use it with a rpg_items database with a field called 'item_slot', etc and it works wonderfully. My issue is. I think it would be intuitive if I were to store a basic 20 slot 0 iteration in a field under the users table for each character. So I can just check against that, instead of querying the whole rpg_user_items table, (which will have thousands, hundreds of thousands of users items) to just check if a user's inventory is full, that is not intuitive. I'd rather just check if a field name has no open 0's instead with php. (This ofcourse will be updated dynamically upon a user moving their items to different slots). Let's say I have this array, and it's stored in a field called userinventory in the users table: 0,0,0,0,0 0,0,0,0,0 0,0,0,0,0 0,0,0,0,0 This is pretty easy to read. there is 20 slots, 5 on reach row. That's 20 inventory slots a user has access to. This is supposed to represent something like this: I can store this in the MYSQL field as 'userinventory'. Now, how do I go about dynamically each specific 0 (ZERO) in this Block? I'm going to call this a block. I will need to label it accordingly. Paint time. Here u go How do I use PHP to dynamically update a block like this based upon user input? (A 1, A 2, A3, B2, B1, etc) To check if a user's inventory is full would be easy. I can just explode them by ',' and use count to see if it's greater than 20. My problem is about updating each individual block to represent a users inventory. So, if there is a 1 there, an item would be there. That's all I'm trying to do. I could ofcourse, create what 20 (5x4) if functions to place them at each individual block, but that wouldn't be intuitive and be extremely confusing.
×
×
  • 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.