Jump to content
MakeWebGames

GRPG Custom Recode


Zettieee

Recommended Posts

Hello. after speaking with Adam he has allowed me to recode and release a custom version of GRPG.

What would you, the people who use GRPG like in this version?

Somethings I've already started: Converted to mysqli, securing inputs, thinking of removing the weird class system is has in favor of a more array styled system (like the one in mccodes).

So any ideas you guys have post below.

Link to comment
Share on other sites

It's important to add in the missing security checks as the system is old, and I have to admit I have only seen parts of it. I would say Kyle was right on the class system. It probably needs work, but I imagine going OO is better then just dumping everything into arrays.

What I would suggest is making sure the database is optimized. People far to often jump straight into the files, and forget a slow database can be just as big of an issue.

Link to comment
Share on other sites

Would converting an array into a class object be better in the long run?

Not necessarily. I don't really know anything about Grpg so I couldn't comment on the engine, but I've seen people go overboard both ways. If the only thing you do in a class is define a bunch of $vars it's all but pointless. For example I once saw someone set a class up to define the price of travel in mccodes monorail file. If it's something like a character class then it makes sense

So I guess the question is what are the arrays/class files used for in Grpg?

Link to comment
Share on other sites

You could use the mysqli objects as this would keep with current theme to a extent, would make it easier for people to convert mods to it, the classes are used to declare all user information from the database meaning installing a new user mod that requires a new field entered into the user table means you have to update the class which makes it totally useless and harder to install mods.

Link to comment
Share on other sites

Here is the current user class:

http://pastebin.com/pbaT7WKp

Its rather slow and clunky

The way I'm going to d it just array to object.

It'll save me time on development and hopefully make it a little cleaner on the eyes.

//edit here's what I was thinking of using.

<?php
class Z_User {
function Z_User($id) {
$run = mysqli_query("SELECT * FROM `grpgusers` WHERE `id`='$id'");
$users = mysqli_fetch_assoc($run);
foreach ($users as $obj => $value) {
$this->$obj = $value;
}
}
}
?>

 

It's not perfect but it works.

Example use age for people who currently use GRPG: $zuser_class = new Z_User($_SESSION['id']);

<?= $zuser_class->username; ?>

Link to comment
Share on other sites

I was hoping the reiteration would help the issue of making it OO more noticeable.

Fair enough. When I said it I hadn't realised how badly Grpg uses it. If it's redone it should be done with an OO setup in mind(as you said). :-)

Edited by Dominion
Link to comment
Share on other sites

An OO Modular code structure could work very well for this.

I always had plans to do something similar to that.

The idea would be that a developer could zip a mod for the game, and a game owner could install the mods through the admin panel by uploading the zip

Link to comment
Share on other sites

An OO Modular code structure could work very well for this.

I always had plans to do something similar to that.

The idea would be that a developer could zip a mod for the game, and a game owner could install the mods through the admin panel by uploading the zip

This can be done without OO within PHP. For example NWE does it this way.

I'd still say go OO if it's a full recode, but the biggest advantage is logic/design separation, and (in theory) easier maintenance for when new people pick up the code.

Link to comment
Share on other sites

This can be done without OO within PHP. For example NWE does it this way.

I'd still say go OO if it's a full recode, but the biggest advantage is logic/design separation, and (in theory) easier maintenance for when new people pick up the code.

I know it can be done without, but it would be better with.

The zip would contain the logic file(s), the controller (if part of the code structure), and the view file.

In my own ideal scenario, it would also contain a links.txt file.

This would have a structure like:

link : title : location

Where the link is the url to a certain part of the mod, title is the link text and location would be town or main menu

When the zip is uploaded the code would scan for this file, and on finding it would read the location and link and store them into a db. Then the mainmenu and the town links etc would be retrieved from the db.

The admin panel could have a wysiwyg editor to allow the owner to change the order of the links or their titles.

Link to comment
Share on other sites

This would be good in Laravel if you have time for the learning curve. If you don't really want to spend time learning something like Laravel you can use let the bashing begin Code Igniter. Or Laravel 4.2 is much easier than 5.*

I use CodeIgniter, I like it a lot actually /: so I'll prepare myself for the bashing

Link to comment
Share on other sites

To me frameworks never made sense. Relearning basic functions just to start a project is a little rough for me.

You're all welcome to help btw.

Frameworks never made sense... That's a great start.

Um.. They help keep your code maintainable. They provide a range of functions, libraries and helpers to help speed up the process of development.

They generally provide an OO environment out of the box. A lot of them allow you to split the logic and design parts of your code. They provide extensions or plugins to handle things like rendering, bbcode parsers etc. They provide a good code structure. A lot of them have some sort of cache system built in. I'm not sure about Laravel but CodeIgniter has built in CSRF and XSS protection. CodeIgniter also has Query Builder which can help make your database queries more maintainable and readable.

Don't knock them until you try it

Link to comment
Share on other sites

To me frameworks never made sense. Relearning basic functions just to start a project is a little rough for me.

You're all welcome to help btw.

You learn one Framework so you can continue using it for other projects. The larger the application the more sense it makes to use them. It keeps you from having to rewrite the same basic things again, and allows others to pick up a project much easier.

In truth I wouldn't say it's needed here, but I would recommend learning a framework if you work with PHP enough.

Link to comment
Share on other sites

  • 4 weeks later...

First time I looked at that class. It's disgusting.

One of the many things I see wrong is that it doesn't check whether the user it's trying to pull information on even exists.

Next up, all it does is create a bunch of variables in a class, and doesn't do it nicely, or efficiently (foreach( $worked as $k=>$v){ $this->$k = $v; } ??? ). There's no need for this class.

A user class should have both variables and functions.

Even functions as simple as addMoney($amt), removeMoney($amt).

It makes the logic code a lot better. If this approach was taken for a lot of the code you setup for say buying an item could be as simple as:

if(!$this->Items->itemExists($itmid)){
  //handle error
}
$item = $this->Items->getItem($itmid);
if($this->User->get("money") < $item['cost']){
  // handle error
}
$this->User->removeMoney($item['cost']);
$this->User->giveItem($itmid);

 

It cuts down a lot of code and makes life easy and makes the code very readable and easy to understand

  • Like 1
Link to comment
Share on other sites

A user class should have both variables and functions.

His user class had both variables and functions, albeit the class was bad but both those points were there. Not sure what you're getting at?

if(!$this->Items->itemExists($itmid)){
//handle error
}
$item = $this->Items->getItem($itmid);
if($this->User->get("money") < $item['cost']){
// handle error
}
$this->User->removeMoney($item['cost']);
$this->User->giveItem($itmid);

I don't think you understand object referencing.

  • Like 1
Link to comment
Share on other sites

His user class had both variables and functions, albeit the class was bad but both those points were there. Not sure what you're getting at?

 

I don't think you understand object referencing.

More than a constructor function I should say.

And explain my object referencing issue?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...