
Zeggy
Members-
Posts
401 -
Joined
-
Last visited
-
Days Won
1
Content Type
Profiles
Forums
Events
Everything posted by Zeggy
-
An irc module for ezRPG using wsIRC. Features: Automatic join Choose your own channel/server Integrated into your game design Players join with their username
-
Here's a free bank module for ezRPG. Built from the bank module tutorial. Includes automatic installer and uninstaller, you just need to upload and you're ready to go! Basic features: Withdraw money Deposit money :P Enjoy! If you're interested in writing modules for the ezRPG engine and want to distribute them, you can check this code out for an example of how to include an automatic installer/uninstaller for running sql queries etc.
-
Can someone just check over this quick please
Zeggy replied to CherryDarling's topic in General Discussion
By that logic, we should never reply to a topic, always waiting in case somebody else posts something better. If you've tried the solution somebody posted, you should let them know so they can suggest a different fix or ask for more info. -
Can someone just check over this quick please
Zeggy replied to CherryDarling's topic in General Discussion
I don't know about other people, but I find it extremely annoying and insulting if you ask for help, then tell us what the problem is after we give a solution. If you knew the problem already, why are you asking for help? You could at least give the solution a try... -
IRC is able to handle many users without adding any load to your own server. Also, it's easy to manage, you can get bots on the channel and improve the user experience, and you can let users create their own channels (for example, each gang can get their own private channel). A shoutbox is not live and is only really useful is everybody using the shoutbox knows each other (since a shoutbox is basically just leaving messages for each other, not really real-time chat). As for a live chat system hosted on your server. Assuming it's web-based (ajax or similar) and in PHP. 30 players online (not too much) in the chat, with chat updates happening once per second (still pretty slow for a live chat). That's 30 connections per second to the database (unless you use persistent connections). 30 connections at once to the database is the limit for many servers. Of course, the example I just gave is 30 connections over a period of 1 second so the database should be able to handle it (30 connections over 1 second is very different from 30 connections instantly, since database connections can last for milliseconds), but a chat system is very read/write intensive, much more so than a game (which is already more read/write intensive than a regular site). Your database will slow down, and so will the rest of your game if the chat isn't coded extremely well. Add to that your regular game and the people not in the chat who are also creating database connections while they play the game. Shared hosting will probably not be able to handle that.
-
ezRPG MySQL Tutorial Note: This is not a general MySQL tutorial. It is a tutorial for using mySQL in ezRPG using the database class includeded with it. Introduction Even though you may be familiar with MySQL, you might not be able to see immediately how the database is communicated with in ezRPG. That's because ezRPG uses its own database class that wraps many native mysql functions so it is easier for you to use! Within modules, you will use the object $this->db to communicate with the database. The Database Each ezRPG game installation may choose their own table name prefix. So instead of having a table named `players`, a game might have a table named `ezrpg_players` or `game_players`. You can deal with this problem by prefixing the table name in your queries with <ezrpg>, for example `<ezrpg>players`. The database class will automatically replace <ezrpg> with the prefix stored in the configuration file. Executing Queries Here's an example of executing a simple query on the database: $this->db->execute('UPDATE `<ezrpg>players` SET `money`=100 WHERE `id`=1'); This is a pretty straightforward query for when you don't care about the result set, such as updating a row. Here is an introduction to parameter binding, an easy way to use variables in your query and protecting your query from SQL injections: $this->db->execute('UPDATE `<ezrpg>players` SET `money`=? WHERE `id`=?', array($money, $this->player->id)); The question marks in the query represent where you want to insert a variable. This is called binding a variable to a query. The question marks will be replaced by the variables you passed in the array as the next parameter. The order of the question marks will match the order of the variables in the array. Retrieving Rows Getting a single row $result = $this->db->fetchRow('SELECT `id`, `username` FROM `<ezrpg>players` WHERE `id`=0'); echo $result->id; //prints 0 echo $result->username; //print the player's username $this->db->fetchRow() will fetch a single row and return an object. With this object you can access all the column data you selected in the query. Selecting many rows This is an example of how to select more than one row at a time, then looping over them individually. //Select the first 5 members $query = $this->db->execute('SELECT `id`, `username` FROM `<ezrpg>players` WHERE `id`<=5'); //Loop through each result while ($row = $this->db->fetch($query) { echo $row->id; //prints 0 echo $row->username; //print the player's username } Inserting Data You can insert data by simply executing a query, but there is also a more intuitive method of inserting data with arrays! $insert = Array(); //Create a new array //Add the data you want to insert to the array $insert['username'] = 'Andy'; $insert['password'] = 'a9629b9e1cd5792effb62'; $insert['email'] = '[email protected]'; $insert['registered'] = time(); $new_player = $this->db->insert('<ezrpg>players', $insert); As you can see, the insert array should be a direct map to the table you are inserting to. Make sure you add all the data that you need, and do not add data that does not have a corresponding column in the table! $new_player will contain the row ID of the inserted row (if it has one). More info For more information on the database class, check out the documentation for the mysql driver: http://ezrpg.googlecode.com/hg/Docs/files/lib/db-mysql-php.html There are examples for most of the methods in the class, and you can always take a look at the existing modules if you want to see a real application of the database class.
-
Don't mind me, I'm an idiot!
-
In this tutorial I will go through the process of coding a Bank module. The bank will allow players to deposit and withdraw money from their bank account. First, we need to go into the database and add a new column to the player database. Add a new column called 'bank', with integer type: ALTER TABLE `players` ADD `bank` INT NOT NULL DEFAULT '0' AFTER `money`; Don't forget to change the table name in the query if you added a table prefix when you installed ezRPG! We will begin with the code from skeleton.php. skeleton.php is the most basic module possible, without actually doing or displaying anything. It is a perfect place to start when writing any module: <?php defined('IN_EZRPG') or exit; class Module_Skeleton extends Base_Module { public function start() { requireLogin(); } } ?> The start() function is the function that will be called when somebody visits the bank page on index.php?mod=Bank. We need to rename the module so that the URL will work and bring up the correct module. If we want the player to access the module through index.php?mod=Bank, then we need to rename the class Module_Bank. If we wanted index.php?mod=Bla, then the class would be called Module_Bla. Get it now? Every module must have a different name, so be very careful if you are creating a module and you name it something that's already been taken! Feel free to give your module its own unique name like ZeggyBank or ZBank! Just as the name of the PHP class needs to match the name of the module, so does the folder the file goes in. This module will go in /modules/Bank/index.php. The file name must always be index.php, and the folder it is in is the module name. We keep the requireLogin() line because our module is not a public module, it should only be seen by players who are logged in. Next, we will define two class functions - withdraw() and deposit() for the two possible actions the player can make. We will fill those in later. We'll work on displaying a bank page first before adding any functionality. In ezRPG, to display any output, we use template files. Templates separate design from code so you can easily change the design of any page or of your entire game without having to go through any code. All templates files are stored in /smarty/templates. We will call our bank template file bank.tpl, and use the template object to display the template: defined('IN_EZRPG') or exit; class Module_Bank extends Base_Module { public function start() { requireLogin(); //Display the bank template file $this->tpl->display('bank.tpl'); } private function withdraw() { } private function deposit() { } } We haven't created a template file yet so this doesn't do anything yet. Let's create a template file for the bank. Create a file called bank.tpl in the /smarty/templates folder: {include file="header.tpl" TITLE="Bank"} <h1>Bank</h1> Welcome, [b]{$player->username}[/b]! You have [b]{$player->bank}[/b] money in your bank! </p> <div class="left"> <h2>Deposit</h2> <form method="post" action="index.php?mod=Bank&act=deposit"> <label>Amount to Deposit</label> <input type="text" name="amount" value="{$player->money}" /> <input type="submit" value="Deposit" /> </form> </div> <div class="right"> <h2>Withdraw</h2> <form method="post" action="index.php?mod=Bank&act=withdraw"> <label>Amount to Withdraw</label> <input type="text" name="amount" value="{$player->bank}" /> <input type="submit" value="Withdraw" /> </form> </div> {include file="footer.tpl"} The first and last lines in the template file include the header and footer templates, so that you only ever need to put the code for the layout once. This helps separate the design from the content of the game. Most of your templates should have an include header, the content, then an include footer to integrate with the game. You can see I added an introduction paragraph showing the player the amount of money he has in the bank and demonstrating the use of template variables. I used {$player->username} to display the player's username in the template. You cannot use normal PHP or variables! To have your template use a variable, you need to call $this->tpl->assign('variablename', $variable); before you display the template. We don't need to do this for bank.tpl because the $player variable is already assigned by default to every template file. Beneath the introduction I added two standard forms for withdrawal/deposit that submit to index.php?mod=Bank. If you visit index.php?mod=Bank right now, you can see your bank mod! If everything went correctly so far, you will be able to see the introduction paragraph and the deposit/withdraw forms. They don't do anything yet, but at least the design is done! Finally, edit city.tpl so there is a link to the bank that players can click on! Continue on with Bank Module, Part 2
-
Introduction Modules are located in the sub-folder /modules. Almost everything you see on ezRPG is a module - login, register, logout, members list, account settings, etc. You can see the most basic code for a module in /modules/skeleton.php: defined('IN_EZRPG') or exit; class Module_Skeleton extends Base_Module { public function start() { requireLogin(); } } This is probably the best place to start whenever you write a new module - just copy the code in skeleton.php and work from there. Rules There are some rules that you need to follow when writing modules for them to integrate properly with ezRPG: Modules go in their own /modules/ModuleName sub-folder. Always. Admin modules go in the /admin/ModuleName sub-folder. Module class names must begin with the Module_ prefix, followed by the module name. Modules are accessed by their class name, minus the Module_prefix. For example, Module_Blabla will be accessed throughindex.php?mod=Blabla. Modules must extend the Base_Module class in order to access database, template and player objects. Modules must have a public start() method. This is the method that will be called when your module is viewd by a player. Class Variables In every module, there are three class variables available to you, as well as global functions and constants: $this->db - This is the database object. Check out the documentation for the database class to see what kind of stuff you can do! Example of writing a database query: //Count the number of players $result = $this->db->fetchRow('SELECT COUNT(`id`) AS `count` FROM `players`'); echo $result->count; //Display the result $this->tpl - This is the smarty template object. Check out the included modules to see how you can display templates or assign variables! For example, to display a template you can use $this->tpl->display('example.tpl');. $this->player - This is the player object. It contains all player data as class variables. For example, to access the player's username, you can use $this->player->username;. Other Files If you add template files, they belong in /smarty/templates. If you are adding many template files for your mod, you can place them in their own sub-folder. If you add files like images or CSS stylesheets, they belong in /static. If you want to add your own global functions, place the files in /lib. After they have been put in the lib folder, you can add an include to that file in /init.php and it will be included globally in the game. Examples For examples of how real modules are used, check out the source code! All the modules included in ezRPG are completely usable, and demonstrate different ways of writing different types of modules.
-
Release candidate 1 of ezRPG has been released! Download it, try it out on a local host or upload it, play around, and let me know what you think! Please report any bugs! If you are mod writer and want to start writing mods for ezRPG, it is fine to being writing using the release candidate. The module system will NOT be changed in the final release. http://code.google.com/p/ezrpg/downloads/list Instructions are included (see readme.txt), and an automatic installer so you don't need to edit any files or run any queries yourself!
-
A small security tutorial, hope its somewhat helpful.
Zeggy replied to a topic in Tips and tutorials
I never said that it is necessary to use it on numbers. I was just refuting this from the original topic: -
Ah, well, there's no confirmation email, it should be pretty easy to create your own account :P Here's a demo account I just created in 2 seconds :P : username: demo password: demo Please don't change the password of the demo account ;)
-
Just a reference to the folder structure for anybody who's confused while browsing the source online: / The root folder. You probably won't touch most of the files in here, except maybe config.php. /Docs The documentation folder. If you're not a developer, you can delete this folder. (I might exclude it from the download.) Otherwise you might need this as a reference to classes/functions in the engine. /admin Contains the admin modules. You might be installing admin modules in here if you're getting admin panel enhancements. /lib Contains files that ezRPG requires to run. Also contains the database drivers (just mysql at the moment). You probably won't do very much in here, but you might want to take a look at some of the classes to see how you can use them in coding modules. /modules The most important folder for a game owner. Every feature of your game has a sub-folder in here. If you are editing code, this is probably where you'll want to be. /smarty/templates Contains the template folders for modules. The admin subfolder in here is for admin template files. /smarty/templates_c Cached template files - they make your site go faster! :P /static This is where you can place your static files - files such as images, CSS files, font files, etc. Only the root files, static files and admin/index.php files are ever actually viewed in the browser. If you want to move everything outside of your web root (which is more secure), this should be fairly easy. All you need to do is change the folder paths in init.php!
-
Woo, got my own board!* :P ezRPG is a free modular game engine. Website is http://www.ezrpgproject.com but it's still under construction. It's open source and free, and you can view the source code and a bit more info on the project page: http://code.google.com/p/ezrpg At the moment there's no demo, but I will update this topic as the engine gets closer to release status. I've uploaded a demo. There's really not much to see as it's just a game engine, not a game, but here it is: http://www.ezrpgproject.com/demo Demo username: demo Password: demo If you're interested in learning more, there are two tutorials at the moment on the website. Eventually I will move those and post more to MWG. The idea behind ezRPG was pretty simple. Instead of letting you download a game, you are downloading something of a framework. All the code is implemented to load modules from a module folder. Hopefully I can get a nice community of mod writers for ezrpg, as it should be much easier to write for and install than mccodes. I'm sorry I can't show you much more at this moment, but let me know what you think if you decide to take a look at the source/tutorials :) Oh yeah, and lemme know if you find bugs or security leaks ^^ * Reply to this topic for a free party hat!
-
Notepad doesn't treat unix/mac new lines correctly. Use a real text editor or IDE! Notepad++, crimson editor, textpad, textmate are all decent gui text editors. Eclipse, zend studio, komodo, phped are all good PHP IDEs. vim or emacs for a more advanced code editor. nano for a simple notepad-like editor.
-
grpg-v1 [Mod] GRPG profile signatures [My First]
Zeggy replied to SlanderDesign's topic in Free Plugins
It may work and do exactly what it is supposed to do, but if you're given a chance to improve it, would you take it? You need to forget this. Any code you write in a class can be written as functions, and same vice versa. Since you haven't been able to get it to work without a class, you should try to learn how to use functions instead of classes then. If not for rewriting this mod, then simply for improving your understanding of PHP. Your code is not wrong. There is nothing wrong with using classes for everything, if that's what you want. We're just pointing out that it would probably be less code and easier to use if you were to put it into a function instead of a class, since in this situation using a class provides no benefits. -
grpg-v1 [Mod] GRPG profile signatures [My First]
Zeggy replied to SlanderDesign's topic in Free Plugins
If you're just learning, then you should learn to take criticism. You can either learn from criticism, or be offended. LazyT's criticism was helpful, not intended to offend you at all. Since you've been coding for 3 weeks, how do you know what you are doing is correct? LazyT is correct, there is no need to put it in a class. You can easily put that code in a function. There is also a sql injection vulnerability, assuming there is no security other than what has been posted: mysql_query("UPDATE `grpgusers` SET `profileSIG`='".$profileSIG."',`avatar`='".$avatar."', `quote`='".$quote."' WHERE `id`='".$user_class->id."'"); -
As well as preventing hijacked sessions from being used, something else to consider is to prevent sessions from being hijacked in the first place: Prevent xss, don't allow your site to be iframed, no hotlinking, no off-site images on your game, etc. CrimGame: I don't understand your idea very well, could you explain it more? (or example code)
-
Yep, using IPs always gives some kind of trouble with silly ISPs :P I don't really have any ideas on how to solve that.
-
As well as doing this for user agent, you can also do the same with the player's IP address. The hashing isn't really necessary since this is all server-side data, the player will never be able to see any of it. Some more tips: Look into regenrating session tokens - http://php.net/manual/en/function.session-regenerate-id.php Set a time-out on old sessions. Destroy the session if there is no referer. This way a player can only visit your site through your login box, they can't just type a url and enter the player area of your game (or admin area).
-
Well, it might not work depending on where you are using it. I assumed you'd be using it when you output the text on a web page. nl2br() converts all your new lines into tags so if you output text with newlines on an html page, it will display correctly. If you're displaying it in a text field, of course it will show , html is not rendered in form fields. Also, if you are using code like htmlentities after you use nl2br, it will convert all the < and > to html entities.
-
Use the nl2br() function to add newlines.
-
If you think you've got too many fields, you're probably not designing your database correctly. The number of rows in a table can go into tens of millions - that's what mysql is made for. BUT if you don't have correct indexes on your tables, it can become really slow. EDIT: Sorry, the emphasis of my post is - use indexes correctly and your database will do just fine. If your queries are using indexes, even if your table has a billion rows, it won't have to look through them all to select the rows you want. Here's a quick guide: Any time you have a select where [...], add indexes on the columns that you are selecting by. Same for sorting/ordering. And if you are selecting/sorting by more than one column, you can add indexes on the columns individually, or you could a composite index of the two columns together, so an index on (col1, col2). If you have a query "select `id` from `players` where `level`>1 and `level`<10", then add an index to the level column. If you have a query "select `id` from `players` where `level`>1 and `money`>1000", then you can add an index to level and money, or you could add an index to (level, money). The order of the columns in the index is also important - it should follow the order that you used them in the query. The problem with this is that if you have loads of columns in your table, your table may end up with loads of indexes on almost every column. Every time you write to the database, the database needs to update the indexes (and indexes also take space). So indexes will speed up your reads from the database, but slow down your writes. Since web games are pretty write-intensive, you need to figure out how many indexes you need/want - OR write your queries better.
-
SELECT count(`id`) FROM userstats us LEFT JOIN users u ON us.userid=u.userid WHERE us.$mykey > $stat AND u.user_level != 0 Just select the count of one column, I set it to `id` but I don't know if you have that column. Just change it if your id column is named differently. I removed 'us.userid != $userid' because 'us.$mykey > $stat' already implies that you are excluding the current user. Last thing to consider is whether or not you really need the u.user_level != 0. If you don't need it then you can remove the entire left join.
-
watching the super bowl right now :D