
Zeggy
Members-
Posts
401 -
Joined
-
Last visited
-
Days Won
1
Content Type
Profiles
Forums
Events
Everything posted by Zeggy
-
Hmmm, that's strange. And the game works fine when you remove this hook? Change intval($args->id) to intval($player->id). $args does not contain player data for the header hook. Edit: And dominion pointed this out to me, you're missing a $ sign: $power = ((($player->attack+$player->defence)*0.31)-0.15);
-
Did you turn on error reporting/debug mode in config.php? You need to add opening and closing braces to this line of code: if ($args === 0 || LOGGED_IN == false) return $args;
-
RulerOfZu: How is 2co working out? Do you sell in-game currency? Or how do you describe your 'product' to 2co? What size transactions do you get in your game? I want to try them out but their transaction fees look pretty steep for small payments :/
-
Why on earth would you want to make visitors wait an extra 3 seconds just to see an image while they wait? You can use setTimeout to have functions run after a certain time.
-
Yep, if your database doesn't use negative or zero IDs then that will work perfectly.
-
Not so much of an advantage, but abs is a different function from intval. Converting to int will still allow negative numbers. But for example, ID numbers in the database probably don't go into the negatives, so using abs is just an extra check that would be very useful.
-
$_GET['ID'] = isset($_GET['ID']) && ctype_digit($_GET['ID']) ? abs((int) $_GET['ID']) : false; This code is redundant. Simply using ctype_digit to check the number will make sure that the value is an absolute integer, since ctype_digit only allows number characters. In other words, what part of that code is doing is 'if $_GET['id'] is an absolute integer, set it to an absolute integer'. Something less redundant: if (!ctype_digit($_GET['id'])) { $_GET['id'] = false; } So use either ctype_digit OR abs(intval()), no need for both. (technicallyyyyy what I said above isn't true, see if you can spot the error. But practically, it's fine in php thanks to its type system) LordDan: Your regex checks a character set. Negative numbers have a strict standard for where the negative sign is: in front. So your regex will match -123 but will also allow 12-3---. As for advantages of abs over your method, regex is much slower than a simple number function, and far too overqualified for its task. There are functions like abs to be used for a reason. Regex is for more advanced pattern matching.
-
Nope, that's something your browser controls. You can use javascript to create your own tooltips. There's a really nice one called wz_tooltip but apparently the website for it is gone.
-
Hmm... let's see... 100 users online at the same time, 60 seconds per minute = 6,000 requests per second just for a simple timer. It's a silly waste of bandwidth and processing power that could be used better elsewhere. And it won't be more accurate than a javascript timer. There's always a latency delay and loading speed delay that you cannot avoid, while a javascript timer relies on the client's own cpu clock. The javascript solutions posted above aren't ideal - they still require php to give the initial time. It would be more accurate to simply use javascript and grab the time straight from the browser. As it is right now, it's starting from the time that php parses that line, and there could be seconds between that event and when the javascript begins running on the client's browser. Also the solutions use setTimeout. The time between each update then becomes 1000ms + whatever time it takes to execute timer update, and eventually the timer would be way out of sync with real time. It would be more accurate to use setInterval.
-
Theirs requires an initial php timestamp to be passed. If you look at the source, your page doesn't seem to do that, it's actually displaying the php code inside their javascripts :P
-
There are many places where improvements can be made: PHP code Database queries Database schema Server specs (cpu, ram, etc) Server network speed To get the best improvement in speed, you'll need to do some testing to see which area is slowest.
-
Exactly, if all that's being done is display time, then the best solution is pure javascript. Apart from bandwidth issues, there's also problems with loading speed, disconnects, latency/inaccuracy, etc. Every browser should be capable of counting its own time :)
-
Well, javascript is run in the browser and php is run on the server. When the page loads, the php adds the current time to your var timda, and then you can consider it 'hardcoded' to the javascript. All the function calls you do after that with javascript will load that exact same timestamp, meaning your div won't change at all. You're just reloading the same string into it over and over again. If you really want to use php for the time, you can either use php to give the starting timestamp, and use javascript to increment the time, otherwise you'll need to use ajax to reload the time from php. But there's not really any need for that, javascript has its own time functions. If you want to display time you can do it purely with javascript.
-
Change the field type for money in the database from int to bigint.
-
An image is an image, html belongs in a browser. If you want the image to link to something, you need to link it with . If you want parts of the image to link to different pages, you can use image maps.
-
PBBG-Engine - Free PHP RPG engine with a plugin system!
Zeggy replied to JakeB's topic in Game Projects
In my opinion, this is a problem that shouldn't be encouraged. Lazy people make lazy games, and while a few of these games may succeed to some degree, it still shouldn't be the accepted standard. The user should be required to do at least a bit of work in making real decisions about their game. Otherwise all that's happening is people running a copy of somebody else's game. And back on topic: your game engine looks pretty awesome :) Especially the automated plugin system, reminds me of smf's package system but simpler to use. -
If this just happens to certain people, and not all at the same time, there might be some xss on your website that is messing with the sessions/cookies.
-
Here is my linux :D http://i.imgur.com/d1cw6.png
-
Well, string concats are more computationally expensive than just outputting text on a screen. Yes, 1 echo is faster than 3 echoes, but 1 echo + x-1 string concats is slower than x echoes. PHP needs to 'reconstruct' the string with each concatenation. So to go deeper into my previous example with 'hi' . 'bla' . 'bla', PHP does this: create new string 'hibla' create new string 'hiblabla' return 'hiblabla' Edit: this is also why it's 'faster' to use heredoc syntax rather than a whole series of $text .= 'bla'; $text .= 'bleh', etc. Or 'faster' to use echo "{$variable} blabla" rather than echo $variable . "blabla". (actually I'm not sure about this one) But the speed difference is really not noticeable, everybody should just use the format that they prefer to code in.
-
The dot and comma do different things in echo. The comma is for separating parameters. Think of echo as like a function: echo ('hi', 'bla', 'bla'); All this does is echo hi, then echo bla, then echo bla. The dot is for concatenating strings together. If you use echo 'hi' . 'bla' . 'bla', what PHP does is: Create a new string 'hiblabla', and THEN echo it. As you can probably guess, using comma is faster (not by much) because php doesn't need to concatenate the parts into a new string, it just echoes each part directly.
-
Here's the first update for ezRPG! Download it now on the project page: http://code.google.com/p/ezrpg/downloads/list The following changes were made: - Added html purifier config setting to disallow external links. - Rearranged init.php, fixed PHP notice in Stat Points module. - Added fetchAll method to mysql database class. - Updated the event log and members list modules to use the new fetchAll method. - Updated documentation. These changes fix a slight security issue and add functionality to the database class. I recommend that everybody upgrades if possible. There's also a simple upgrade package available on the download page which contains only the files that have been updated, which you can easily upload and overwrite on your game. For more info on ezRPG, check out the website: http://www.ezrpgproject.com/ The official demo has also been updated: http://www.ezrpgproject.com/demo/
-
You use __FILE__ to help in this kind of situation: You call file1.php, which has a line to include 'subfolder/file2.php'. file2.php also has a line to include 'file3.php'. Now, where will PHP look for file3.php? In the root folder, since that is where file1.php is, or inside subfolder/, since that is where file2.php is? When you have lots of includes in many different folders, this can get very confusing and you could make many mistakes, or even make your entire file system unusable in your script. You can be consistent with includes if you use DIRNAME(__FILE__): it will always include the file from the same folder as the included file. So in this situation, it will include 'subfolder/file3.php'.
-
This is an article on how to code your game so it can scale to very large audiences. The techniques described in this article can be applied in any other programming language, I just chose PHP as an example since most people here will know it. The article describes two techniques to scale large amounts of data writes, and large amounts of data reads. Sharding - heavy writing Sharding is a technique used to handle frequent writes. While a database can contain large amounts of data, writing to a particular piece of data in the database is limited to x number of writes per second. While one row is being written, nobody else can write to that row at the same time. (Most storage engines on mysql lock the entire table, so sharding across rows won't help in any way. If you want to shard on myisam, you'll need to do it across different tables. An example of row level locking in mysql is InnoDB, which is what is discussed below.) What type of data should sharding be used for? Data that is updated very frequently (> x writes per second). For example, a specific player's level and stats should NOT need to be sharded since a player's actions are limited. What could be sharded is a counter for total page views, or total number of battles performed, etc. - data that might be updated by many players at the same moment. What is sharding? An example of how you would normally count the total number of page views would be something like this: mysql_query("UPDATE `game` SET `count`=count+1 WHERE `key`='pageviews' "); With sharding, instead of having the page view count stored in a single row, you split it among many rows. This way you can spread the write load among several rows: $shards = 50; function update_pageview() { //Pick a random shard to write to $shard = 'pageview_' . rand(0, $shards - 1); $shard_exists = mysql_num_rows(mysql_query("SELECT `count` FROM `pageviews` WHERE `key`='$shard' ")); if ($shard_exists == 1) mysql_query("UPDATE `pageviews` SET `count`=count+1 WHERE `key`='$shard' "); else mysql_query("INSERT INTO `pageviews` (`key`, `count`) VALUES('$shard', 1) "); } function get_pageviews() { //Get the total count of every shard in the table $result = mysql_fetch_array(mysql_query("SELECT SUM(`count`) AS `count` FROM `pageviews` ")); return $result['count']; } The code defines two functions you use for updating the pageview counter, and for getting the total number of page views. Whenever you update the pageview counter, it randomly chooses a shard to update, and writes it to the database. When you get the total number of pageviews, it will calculate the sum of counts in every shard in the table. This way you spread the write load among your different shards, letting you handle far more writes to a particular piece of data. Like I said above, you will need to spread the load between different tables instead of rows if you are using table level locking, but I'm not sure how effective it is as you can't select the sum of data in different tables. Again, I only chose mysql because most people here are familiar with it, but it doesn't work so well as an example (table level locking is pretty fast). If you are using a different database that will benefit hugely from sharding, then you can apply the idea in whatever language and database. Memcached - heavy reading Memcached is an api to store data directly on your server's memory, available in many programming languages (http://code.google.com/p/memcached/wiki/Clients). Getting data from memory is much, much faster than fetching data from a database. Ideally you could store lots of game data in memory, however the data you store in memory is a) temporary, not persistent - if your server restarts, all data is lost b) not always available - if memory is needed for other applications on your server, data can be overwritten and lost, so your game must never depend on that data to be available. Having a backup source for the data is important (most often it's your database). which is why it should be used a cache instead of permanent storage. The ideal type of data to store with memcached is data that is read very often, but written less frequently (< 1 write per minute for example). Before you read on, not every server has memcached installed. You will need to install it on your server first, and then install the PHP memcache package (there are two available, see the above link). Here's an example of using memcache: http://uk.php.net/manual/en/memcache.examples-overview.php However, for it to be useful for your game, you'll want to define your own functions for fetching certain data through memcache. Let's take the player's profile data for an example: function get_player_profile($player, $memcache) { $key = 'profile_' . $player; $profile = $memcache>get($key); //Get from memcache if ($profile === false) //Memcache data doesn't exist? $profile = set_player_profile($player, $memcache); return $profile; } function set_player_profile($player, $memcache) { $key = 'profile_' . $player; $timeout = 600; //Number of seconds to cache the data $profile = mysql_fetch_array(mysql_query("SELECT * FROM `profiles` WHERE `player_id`=$player")); $memcache->set($key, $profile, false, $timeout); //Save data to memcache so it can be used in future calls to get_player_profile() return $profile; } We defined a function to get the player profile data from memcache. The function checks if the memcache data exists (because remember, you cannot depend on the data to be there). If it doesn't, then it makes a call to set_player_profile. Set_player_profile grabs the profile data from the database, then adds it to memcache. I gave that particular piece of data a 10 minute time-out since it's unlikely that the player's profile data will have changed in the next 10 minutes. You can change the timeout to whatever you feel is appropriate. A shorter timeout means players will see profile changes much quicker, but in worst case you'll be making more database queries. A longer timeout means you'll make less database queries, profiles load faster in general, but profile updates will take a while to appear until the old data expires and memcache is updated. Personally, I've used memcache to store data for as little as 60 seconds for fast changing data, and as long as a week, for data that will rarely change. I also use a slightly different updating mechanism that ensures my memcache data is usually up to date with the database, so I don't suffer any delays in seeing updates, but I'm not writing about that here. Examples of memcache uses Long term: template files, translation strings, item data, mail, map tiles/info Short term: profile data, inventory, user logs, statistics These examples might not apply to every game, it really just depends on your game mechanics. What data you store and for how long depends on the situation, and you should decide for yourself. Finally You can combine the two techniques I described above - sharding with memcache (good), and memcache with sharding (not so useful). If I think of other techniques used for scaling, I'll update my post here or make a new post. Feel free to ask any questions! :) If you want to see some sample code that I actually use in my game, I can post some here but it's in python and uses a non relational database.
-
Well, what kind of proxy did you use? If you used a website proxy (ala proxy.org), well those are not very effective proxies.