-
Posts
138 -
Joined
-
Last visited
-
Days Won
12
Content Type
Profiles
Forums
Events
Everything posted by Alan
-
And the contrary is equally true it seems. - - - Updated - - - And the contrary is equally true it seems.
-
$map[0][0] = CITY; Of course, you would have had to define CITY before hand, and add an element in the $image array for the city itself.
-
Consider http://ideone.com/6YbewY
-
My name ... in vain :D
-
[MENTION=50378]Guest[/MENTION]: 86 characters; not too bad but I'm sure I can shave a few off that - how about 62 - http://codepad.org/jSBqb1ms
-
I'd say yes to both in fact. It's not a criticism aimed at anyone specifically, rather a simple generalization. The key point I was trying to impart is that the accepted solution is far from ideal, it compounds the poor thinking, and subsequent shoddy code seen all too commonly with the engine. If people who regularly post to the forum state something as fact, then whether it is valid, correct or even useful can easily become irrelevant - other members are liable to accept it in good faith without realizing that there are often multiple alternative solutions, some no doubt better - and equally some in all likelihood worse. As for helping, I see no benefit in giving the answer verbatim, I prefer as has no doubt been observed on many occasions, to give hints that force people to think. If only a few people can understand these somewhat obscure hints, I can live with it - programming is not for everybody and people need to realize that they need to really work at it in order to get rewarded be it financially or simply personal satisfaction. Going back to the original problem, I'd suggest that anybody using the same software try out the SQL query I posted above, and endeavor to mold to to their own specific needs; how it's called - by whatever interface - is as you rightly point out, irrelevant Understanding how it works however is highly beneficial.
-
You haz friend now? My word, what is the world coming to?! :D
-
While I'm sure Samurai's solution is provided in good faith, anybody making the mistaken assumption that that is a correct solution really needs to take a step back and consider the problem at hand. The database engine mysql / mysqli can be considered unimportant here; many hosts still run mysql and will continue to do so for some time in order to provide support to legacy applications - and while mysqli is certainly a much better interface, providing for instance the ability to call stored-procedures and the ability to use prepared queries, it's SQL injection prevention is little different especially in how people use it. If people actually looked at the problem and spent a moment to try and understand what is happening underneath and how it could be improved, platforms like the venerable McCodes would perhaps have a lot more following with people willing to provide decent modifications both free and commercial. As it stands, this code is a mess, it falls into the old McCodes way of doing things with no separation of display logic versus data extraction versus program flow. There's also the poor use of SQL - Why 6 queries to do something that is easy in one? Yes, I know the OP posted that mechanism but surely the community (and by that I point an accusing finger towards at least two posters in this topic) should try and improve both their own and other peoples skills by posting clean code, with well written logically thought out SQL. I know plenty of people of have learned a great deal from these forums thankfully, I speak to one or two on a regular basis, and I have also seen their skills improve considerable over the period I've known them. The assistance they were given comes in part from analyzing the poor quality of code presented in posts like this, discussing it in detail, looking at what sort of problems may exist, and dealing with them. Is it so hard for people to do this? Too many times staff or ""community leaders"" have their word accepted as fact, when in reality their ideas and statements can be misread - and I accept that I have to include myself in that. For reference consider the query: SELECT c.cmtTIME, u.username, u.userid, c.cmtTEXT /* other fields to suit */ FROM comments c LEFT JOIN users u ON c.cmtFROM = u.userid WHERE c.cmtTO = $userid ORDER BY c.cmtTIME DESC LIMIT 5
-
@melduk One can only presume that the art of debugging has long since escaped anybody these days Step 1 - Copy the pasted code and save as a file - say reset-password.php Step 2 - Run php -l reset-password.php PHP Parse error: syntax error, unexpected ')' in reset-password.php on line 12 Step 3 - Mark 1 eyeball shows that the filter_function has too many closing brackets, remove one and check the syntax again.
-
@Guest ... or well-written, high-quality, fast, stable PHP code? :D @gamble, My apologies, conceptually doing away with crons is a good thing as they put undue strain on the server often at highly inconvenient times (anybody remember Torn's daily downtime @ new day? - insane). There are a few commercial applications out there; WoltLab's Burning Board IIRC for one; that runs "crons" from PHP doing away with system-level crons, but I'm far more in favor of a solution based on timestamps triggered only when needed. Crons for system level tasks are usually fine, though care must be taken not to run too much at one time (often midnight).
-
Certainly not. The author of said cronless crons really missed the point, and failed to address several issues relating to how periodic events are triggered. Consider writing more sane code, that does not rely on periodics, it's not difficult.
-
@sniko, yes git is extensively used throughout all our projects these days. We maintain a number of branches, with post-hooks to ensure that testing is performed prior to pushing to production (at least that's the plan - unit testing the current code base is far from easy). Master runs on production, with branches created from it for hotfixes as and when the need arises. Development branches and QA branches are active all the time. We use fabric for deployment coupled with phinx for database migration. @guest, I guess it's my round then :D @dominion, experience is one one small aspect of any project. The ability to work with people, to design, develop and maintain a project from a team comprised of almost entirely unknowns is a risk, but can prove enjoyable. Personally, I know I won't make money from this project, so I offer a realistic view of what may happen. In time that ~may~ change, however it would be foolish of me to suggest otherwise at this stage. While my associate chooses to stay out of the limelight for the moment, any information you need about any of my current or prior projects can be found easily enough.
-
We are looking for two, possibly three people to assist with a little game project. I'll ignore the usual partnership template as its mostly irrelevant for this request, however I'll give you some idea of the concepts. Starting with an mccodes base, myself and one other developer are simply experimenting to see what may be possible within a relative short time scale. The aim is to get a stable, working product using basic code and writing everything outside of the initial code-base from scratch. We will be using certain key components in due course to simplify the process, however there's nothing complex or unusual about these parts. The game itself while initially based like all mccodes projects on crime and combat, is anticipated to go more towards a cooperative game; where safe solo play is possible, yet groups of people can play against each other with some friendly rivalry. Hosting is fully covered, the two developers have a number of machines in a variety of places around to globe with sufficient free resources that are fully paid up to host essentially what we want. Any and all costs in the future will be met solely by the two developers. Technologically, initially the core code is PHP based, HTML5 and CSS3 of course with extensive JavaScript. It is developed on Linux servers, but hosted on specially hardened Unix machines. Database back-end is initially MySQL, and we use Redis for caching and providing message queues. Front end is as I've said, bootstrap based, and while we would like to make it responsive enough to be fully mobile aware, this may not be possible at least in the early stages. So, what are we looking for? 1. Game designer(s) - will be tasked with generating ideas and fleshing them out, passing these over to the development team, and play testing. This is probably one of the key posts, as they are in a position to greatly influence the direction of the game and can spend a lot of time with development discussing possible plans. 2. Game administrator - we're developers, we don't really want to get involved in the day to day management of the game once its up and running. Has the ability to bring on staff as and when needed (once approved by the devs) and will probably spend considerable time discussing the game with the designers. 3. Graphics - The game itself is being written using the bootstrap framework for speed, and while we already have certain aspects of the game's look and feel in our mind, we welcome input from designers willing to try their hand at a new project. Of course, these guys and gals will be work closely with both the game designers and developers. Now it may sound a little above the normal for what is essentially a small code-base however with the combined commercial programming experience of over 60 years, coupled with an unrivaled ability to generate fresh ideas, or new twists on old concepts we feel we can have a little fun with your help. And what's in it for you? Well I'm not going to promise money, I'm certainly not going to promise source code, however I will promise a lot of hard work, and a lot of fun. Our aim is it make a fun game that can pay for itself, gain a little experience in the gaming world, and share some of our experiences. What happens to your ideas? Well we're not a couple of script kiddies out to make a fast buck here, we treat our co-workers with respect and honor any wishes they may have. We will not share any ideas or indeed code with any 3rd party without full and complete permission. If your ideas do get written into the project however, it becomes a more complex process to remove them if for some reason we part company, so we'll keep them active until such times as we can faze them out or replace them altogether. We are after all putting a lot of effort into developing the underlying code, so we feel a little give and take is required. What skills do you need? It's up to you whether you feel you have the necessary skills and ideas to come an join us, we won't force anybody to work to silly deadlines, however we do expect that you join where and when you can. In reality, you will need to have a decent eye to see whether something looks right or wrong, you need to have a decent sense of what fair game play is about, programming skills while handy are not required although at some stage down the line we may consider expanding the development team assuming the game warrants it. If you think you can make a fast buck out of us, or maybe think you'll be able to steal the code base, then please, look elsewhere, however if you have the desire and drive to direct and shape a game into something that players will enjoy and keep coming back then drop me a line.
-
Cheapskate! Still, it's a nice starting figure though at least it is unlikely to be needed all at once, or even all up front.
-
@rockwood - consider a faster, and more readable alternative: if (array_key_exists('string', $_POST) && ctype_alnum($_POST['string'])) { // at this stage you have a possibly valid input in $_POST['string'] and while it won't be an empty // string, (ctype_alnum() returns false if passed ""), it may still need to be checked for excessive length. } else { header('HTTP/1.1 400 Bad Request'); // don't forget to exit here, otherwise you will continue execution of the php file. exit; } preg_xxx functions are very useful, but not the fastest around; while the ctype_xxx functions are often direct calls to the underlying standard library (libc) equivalent which are *highly* optimized. Your use of a function to filter out unwanted characters is unnecessary and reduces code legibility considerably.
-
Sadly not infinite, however I'd hazard a guess that 1 million points is the upper limit of what a single server (or rather a single cluster) will run without any degradation in speed. It looks like simplex noise might be the solution, producing what seems to be pleasing gradients, with a little mathematical trickery I suspect this will suffice however I'm going to keep looking for other solutions. Simplex noise with 3 levels in a terminal (75% scale)
-
Remember that nothing is known about the eventual size of the playing field - in fact at any point, there is no way to tell just how big it would get. In tests, the approximate radius of the area (assuming roughly circular) was 1250 and given a point every now and again along the length of the spiral (unlike the attached image), I was looking at around 1 million points. Adding noise together is often like hashing the string representation of a hash - it actually reduces the entropy and becomes far more difficult to write a single generator which given a simple coordinate pair, returns a sane, useful value. This shows a rough concept using a linear (Archimedes) spiral. This is representational only, the current point (or town coordinate if you prefer) uses a much more complex algorithm however the region generation routine is by necessity identical no matter what underling routine is used to generate the location of the points. Note that in the above example, there is 5 separate regions, none of them bisect a point (though that can be ignored as the current algorithm will ensure that no matter what type of noise generator is used to create the regions, no region boundary can every bisect a point. The scale of the regions would by necessity need to be controlled - as obviously having 100 million points with only 5 regions and a layout as seen above, would mean that we could guess that there would be one very small (yellow) region surround by 4 much larger (almost 25% each of the whole area) regions - hardly a viable proposition. What is needed is something whereby regions have a roughly even coverage, perhaps split into multiple separate regions.
-
As part of a new game project, I've been tasked with producing a large scale playing map which is subdivided into multiple regions. Initially I considered 4 separate regions, so dividing the playing area into 4 would seem simple, however given the size of the map, this does not really produce what I need. There are a number of problems which need to be investigated here; as the size of the map cannot be known in advance - players are essentially positioned at a random point along an every increasing spiral. The test data has a radius of 1250 odd places (or towns) if you want to look at it like a normal map. The question is; is there a method of subdividing the entire area given into a small number of regions which themselves span multiple locations - similar to how countries may look? The ideal code (any language within reason is acceptable) should take an x,y coordinate pair and return a number between 1 and (say) 10 inclusive which determines which region those coordinates belong to. Obviously mt_rand(1, 10) is not going to work here. I've looked at perlin noise, and simple addition of scaled sin/cos waves - neither of which provided decent results. Voronoi noise looks as if it may have interesting results, though I'd prefer something a little more random in its edges. Plasma fractals (Diamond square) were considered but they appear to require the size of the playing area to be known before hand
-
@op : Magic quotes itself is deprecated, and there's also a total lack of type checking, not to mention failure to use the function htmlentities correctly - Look at the documentation; essentially it changed how it operated relatively recently in that it now assumes utf-8 whereas previously it assumed iso-8859-1 which can be a nightmare to resolve. Consider the chain of events: user input => assertions for existence => type checking => range checking => database sanitation => output sanitation => browser output. user input can be assumed to be anything from _GET, _POST, _COOKIE, _FILES and to an extent _SERVER and _ENV assertions for existence - don't blindly assume the user has passed data - check it first (see array_key_exists, NOT isset) type checking - both _GET and _POST elements can be arrays, you really need to check they are strings (not integers), but use the shortcut functions ctype_xxx if you can range checking - fairly obvious; pages usually go from 1..numpages, so clamp values or ignore erroneous ones data sanitation : mysql_escape_string() (for the mysql_xxx haters and `but mysql is deprecated` fans, read the C code, the function is mysql_real_escape_string - how you call it from PHP is up to you) output sanitation - you need to prevent things like "<script>alert(1)</script>" getting through - so htmlentities is the final port of call - but use it properly. If your server is correctly setup, stripslashes() should not be needed, addslashes() should never be used unless you want to rot in hell for eternity in real terms: for an int: if (array_key_exists('varname', $_GET) && ctype_digit($_GET['varname'])) { $varname = $_GET['varname']; # range checking if required } else { # do what you will here header('HTTP/1.1 400 Bad Request'); exit; } for a string if (array_key_exists('varname', $_GET) && is_string($_GET['varname'])) { $varname = $_GET['varname']; # range checking if required (possibly in_array() if you are expecting one one of a few values ie "Male", "Female") } else { # do what you will here header('HTTP/1.1 400 Bad Request'); exit; } etc.
-
I'm never keen on any application that sends your username and password in plain text as a confirmation after registering; here far more so. The game, whether it be the original code or the OP's alterations I cannot tell, has sent me my password hashed with md5 and no salt. Does this mean the passwords are actually stored like this in the database? I'd certainly assume so. Given I was able to find multiple online services that were able to resolve my original password (which I admit was not strong, but still, contained mixed case and numerics) I'm afraid I won't give my interest, time or indeed money to this project. Outside of this woeful lack of thinking, the game itself is simply not pleasant to look at, there is no touch of class or elegance that draws my attention, the color scheme is very garish with primaries along with pure black & whites used with nothing to soften the blow and seems to be lacking almost totally in any form of graphic. Storyline looks to be non-existent, though that appears to be the norm these days; however it will no doubt suit a few who discover the obvious "holes" in the system and drag everybody down to their level. Is it me or is a daily task of getting a massage in a Brothel, just not suitable material for a game? While I can't see me playing for longer than it took to write this missive, I've no doubt some will enjoy. Best of luck to the OP.
-
Amazing what people miss <?php # [1] include(__DIR__ . '/db.php'); # [2] $genre = array_key_exists('id', $_GET) && ctype_digit($_GET['id']) # [3] ? $_GET['id'] : 0; # [4] $sql = "SELECT timeslot FROM aclient"; # [5] $rs = mysql_query($sql); if (!is_resource($rs)) { # [6] trigger_error('MySQL query failed -- $sql -- ' . mysql_error()); exit; } $row = mysql_fetch_row($rs); mysql_free_result(); # [7] if (!is_array($row) || !count($row)) { # [8] trigger_error('Unexpected MySQL response to query -- ' . serialize($row)); exit; } $slot_display = $row[0]; if ($slot_display == 4) { $sql = "SELECT `aad` FROM `aprog` WHERE `tag` = $genre"; # [9] $rs = mysql_query($sql); if (!is_resource($rs)) { trigger_error('MySQL query failed -- $sql -- ' . mysql_error()); exit; } $row = mysql_fetch_row($rs); if (!is_array($row) || !count($row)) { trigger_error('Unexpected MySQL response to query -- ' . serialize($row)); exit; } $songid = $row[0]; } else { $songid = 0; # [10] } $sql = "SELECT * FROM mtracks WHERE id = $songid"; $rs = mysql_query($sql); if (!is_resource($rs)) { trigger_error('MySQL query failed -- $sql -- ' . mysql_error()); exit; } $row = mysql_fetch_row($rs); mysql_free_result(); if (!is_array($row)) { trigger_error('Unexpected MySQL response to query -- ' . serialize($row)); exit; } $shmedia = $row; 1. Use full php tags `<?php` not the short-open tags 2. Be explicit where you include files from 3. Check the user has actually passed some data and type check it 4. Provide a default (or throw an error) if missing or bad 5. Define the SQL prior to calling it (makes it easier when debugging) 6. Always check the result of mysql_query 7. Get into the habit of free'ing the result result (good practice) 8. Check the result of the fetch operation - there may be no rows after all 9. Indent your code - code is meant to be read by humans, it makes our lifes easier 10. Ensure variables are declared prior to SQL calls 11. Lose the terminating ?>, there's no need for it 12. Where possible, use PSR1 etc (Google it)
-
Something along the lines of - http://jsfiddle.net/P5aW3/
-
Why don't you try for something unusual, yet easy to code; for example: When two players begin combat, show a simple hexagonal grid overlaying whatever image you need; develop a little AI to control the defender, allow the player to ""move"" their own character; combat then has the ability of being played out strategically, where range becomes an important facet. You can in fact extend this to encompass a lot of elements; movement rates, multiple attackers (think retainers etc), endurance. As a bit of logic, it is remarkably easy, the defender's AI need not be complex, just fair and with a little careful graphic work with your preferred designer it can easily become a highly unique feature of your game. And yes, this has been done; by myself and others; for my own part, not in PHP although it's not overly hard to reproduce in most web-based scripting languages especially with the use of jQuery/Prototype etc.
-
Some interesting suggestions, I hadn't considered trig functions. @denb; yes only integers are produced. For anyone who is curious: <?php $index = 1; $x = 0; $y = 0; $direction = 0; $matrix = array(array(1, 0), array(0, 1), array(-1, 0), array(0, -1)); for ($i = 0; $i < 10; $i++) /* increment 10 to suit */ { for ($j = 0; $j < floor(($i + 2) / 2); $j++) { echo sprintf("%d : ( %d , %d )\n", $index, $x, $y); $index++; $x += $matrix[$direction][0]; $y += $matrix[$direction][1]; } $direction = ++$direction % 4; } If you plot the generated coordinates; you end up with a rather remarkable and handy ""curve"".
-
Given the first few terms of y = f(x), can you determine what the function f() is? x = 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 y = 0, 1, 1, 0, -1, -1, -1, 0, 1, 2, 2, 2, 2, 1, 0, -1, -2, -2, -2, -2 I should point out that I don't know the answer, although I have written a generator which works perfectly, however I'm specifically looking for a single formula.