Page Index Toggle Pages: 1 Send TopicPrint
Hot Topic (More than 10 Replies) Essentials on MOD writing (Read 11485 times)
Spikecity
God Member
*****
Offline


Beer anyone ?

Posts: 2630
Location: New York
Joined: Apr 16th, 2002
Gender: Male
Essentials on MOD writing
Dec 5th, 2002 at 1:49pm
Print Post  
Quick Tutorial

This quick tutorial will help any modwriter to code in such a way that all YaBB essential routines and security are used and variables are passed in the correct way.

File Handling

Most functions with YaBB will include some form of file handling, like reading, writing, appending to a file.
As a YaBB was written as a multi user BBS you can imagine that the same file can be touched or opened by several users at the same time.
To prevent file corruption on simultanious writing/opening of files, YaBB uses it's own file locking subroutine to avoid this.
So instead of using open and close you should use fopen and fclose in your mod, ivoking the file handling with the proper locking.
Also be aware that if you create new files which are linked to a user you should also add routines to delete these files if the user is deleted.
Don't forget the admin power options for user deletion !!
So there are more then one place the unlink command is used.

Check this thread for all the places files are deleted !!
(thanks Shoeb for pointing this out to me)

Calling your new subroutines/functions

If your function is just a "blind" routine not fed by any user input in urls or forms, the proper way to call it is just using &yourroutine;.
Any other function/routine where variables are passed for whatever reason should be passed using the action= command and are controlled from the YaBB main script. It's a bad thing calling these kind of routines directly as the readform security check is bypassed making it vulnerable for flooding or hacking.

Passing Variables to a script

Variables are passed to scripts which process them in two manners which both need a different approach in recalling the variables into the handling script.

1. Through url hyperlinks on the screen (GET)
normally written like <a href="$cgi;action=$someaction;variable=$variable....">action text</a>
The script called is based on the value of action= and YaBB.pl/cgi will redirect to the correct pl/subroutine.
The variables passed should be read using the $INFO variable, like my $variable = $INFO{'variable'};

2. Through form input fields on the screen (POST)
normally written like <form action="$cgi;action=$someaction;variable=$variable...." method="POST"> ... your form ...</form>
The script called is based on the value of action= and YaBB.pl/cgi will redirect to the correct pl/subroutine.
The variables passed should be read using the $FORM variable, like my $variable = $FORM{'variable'};

If you mix up these two variables and use the latest security fix the variables will NOT be passed and your code will not work !!

The use of proper html 4.01 in your code

As SP1.1 itsself already has quite a few html 4.01 incompatibilities the use of html 4.01 compliant code is a big plus !!

This means that html tags are never in caps, so it's <br>, <hr> <form... and NOT <BR>, <HR> and <FORM...

Things like <select> options should be closed like this: <option>Your option</option>.

All variables/actions inside a html tag should be inside double quotes, so it's type="input", name="username" or name="$username" if you have dynamic variables inside the html.
If you have trouble with double quotes interfering, try $yymain .=qq~<your html with "vars..">~; instead of $yymain .="<yourhtml with 'vars...'>"; as single quotes are not fully compliant with html 4.01 (allthough they do work in most browsers)
Especially the border, width, size, cellspacing, cellpadding are often abused without double quotes in table definitions.
So it's border="0", cellpadding="4", cellspacing="1", width="100%", size="1".

One last hint !
Try to use percentual widths in tables so your output will adapt to other screen resolutions more easily.
« Last Edit: Dec 5th, 2002 at 3:18pm by Spikecity »  

Nothing to add here Smiley
Back to top
 
IP Logged
 
BHRA Webmaster
God Member
*****
Offline


Mod Author of the Year
2002

Posts: 5238
Location: BHRA Headquarters
Joined: Jan 18th, 2002
Gender: Male
Re: Essentials on MOD writing
Reply #1 - Dec 5th, 2002 at 2:45pm
Print Post  
Can I just add a suggestion to help users who install mods manually (not everyone uses the BoardMod program):

It's easier to install a mod if the steps in the mod file appear in the same order as the code changes in the .pl files! It saves all that scrolling back and forth!

The only exception to this should be if there is a step with particular instructions attached to it (ie. if a step has known compatibility problems, or contains a variable that can be changed before installing the mod.) These steps should be moved to the top of the mod file so they are easy to find!
  


World Domination, one smiley at a time!
Back to top
 
IP Logged
 
Christer Alexander
God Member
*****
Offline


Make my day...

Posts: 3443
Location: Lethbridge
Joined: Feb 10th, 2002
Gender: Male
Re: Essentials on MOD writing
Reply #2 - Dec 5th, 2002 at 3:15pm
Print Post  
* Christer Alexander doesn't see the relation to Programming and Coding as much as to mods Undecided
  

Code
Select All
unless(0) { stab("LoonyPandora"); next; } 

Back to top
IP Logged
 
Spikecity
God Member
*****
Offline


Beer anyone ?

Posts: 2630
Location: New York
Joined: Apr 16th, 2002
Gender: Male
Re: Essentials on MOD writing
Reply #3 - Dec 5th, 2002 at 3:19pm
Print Post  
Quote:
* doesn't see the relation to Programming and Coding as much as to mods Undecided

Then move it to the tutorial section, I do not have writing access there  Lips Sealed
As I see a *lot* of mods that do not comply to these "rules" this is usefull.
  

Nothing to add here Smiley
Back to top
 
IP Logged
 
Christer Alexander
God Member
*****
Offline


Make my day...

Posts: 3443
Location: Lethbridge
Joined: Feb 10th, 2002
Gender: Male
Re: Essentials on MOD writing
Reply #4 - Dec 5th, 2002 at 3:48pm
Print Post  
moved to Tutorials.
  

Code
Select All
unless(0) { stab("LoonyPandora"); next; } 

Back to top
IP Logged
 
Spikecity
God Member
*****
Offline


Beer anyone ?

Posts: 2630
Location: New York
Joined: Apr 16th, 2002
Gender: Male
Re: Essentials on MOD writing
Reply #5 - Dec 5th, 2002 at 3:51pm
Print Post  
Quote:
moved to Tutorials.

Thanks Chris Grin
  

Nothing to add here Smiley
Back to top
 
IP Logged
 
Christer Alexander
God Member
*****
Offline


Make my day...

Posts: 3443
Location: Lethbridge
Joined: Feb 10th, 2002
Gender: Male
Re: Essentials on MOD writing
Reply #6 - Dec 5th, 2002 at 3:56pm
Print Post  
np, Spiked city Smiley

* Christer Alexander suggests to add some more mods in this board. EX: Spikecity
« Last Edit: Dec 5th, 2002 at 8:21pm by Christer Alexander »  

Code
Select All
unless(0) { stab("LoonyPandora"); next; } 

Back to top
IP Logged
 
Oldiesmann
New Member
*
Offline


Jesus loves you!

Posts: 5
Location: Cincinnati
Joined: Mar 31st, 2003
Gender: Male
Re: Essentials on MOD writing
Reply #7 - Apr 21st, 2003 at 6:54pm
Print Post  
Quick question... How do you get Boardmod to edit files outside the cgi-bin? ie... I'm trying to write a mod that edits code in ubbc.js, but I can't get Boardmod to pick it up because it's not in cgi-bin and it doesn't seem to understand what "public_html" is...
  
Back to top
 
IP Logged
 
Christer Alexander
God Member
*****
Offline


Make my day...

Posts: 3443
Location: Lethbridge
Joined: Feb 10th, 2002
Gender: Male
Re: Essentials on MOD writing
Reply #8 - Apr 22nd, 2003 at 5:19am
Print Post  
I believe BoardMod understands relative path, so this might be worth a shot:

../../public_html/ubbc.js

That's the path for a standard out-of-the-box unzipped YaBB.
  

Code
Select All
unless(0) { stab("LoonyPandora"); next; } 

Back to top
IP Logged
 
disco
Junior Member
**
Offline



Posts: 68
Location: Janesville
Joined: Jan 21st, 2003
Gender: Male
Re: Essentials on MOD writing
Reply #9 - Jun 4th, 2003 at 2:18am
Print Post  
Quote:
2. Through form input fields on the screen (POST)
normally written like <form action="$cgi;action=$someaction;variable=$variable...." method="POST"> ... your form ...</form>
The script called is based on the value of action= and YaBB.pl/cgi will redirect to the correct pl/subroutine.
The variables passed should be read using the $FORM variable, like my $variable = $FORM{'variable'};


Could you expand on this a bit; ie. parsing whats handed back to yabb- is there a sub already written that can simply be called, or do I need to split, and do character replacements before I can do anything with it...
  
Back to top
 
IP Logged
 
Administrator
Forum Administrator
*****
Offline


Yummm

Posts: 7
Location: Modders Rile
Joined: Oct 7th, 2014
Gender: Male
Re: Essentials on MOD writing
Reply #10 - Jun 4th, 2003 at 10:49am
Print Post  
YaBB has a sub called readform (Subs.pl) which does the job of splitting and character checking. It's called very early, everytime YaBB.pl is called. So you don't have todo anything, simply use $FORM{'variable'} and $INFO{'variable'} as you like.
  

The Administrator.
Back to top
WWW  
IP Logged
 
disco
Junior Member
**
Offline



Posts: 68
Location: Janesville
Joined: Jan 21st, 2003
Gender: Male
Re: Essentials on MOD writing
Reply #11 - Jun 6th, 2003 at 2:54am
Print Post  
is it possible to use variables inside the $FORM{'variable'}?

ie, if I'm using a loop to build a form
Code
Select All
(set count to 0)

<form action="$cgi;action=spellvault2" method="post">

(foreach statment here)

<input type="text" name="spell$count" value="0" SIZE="1"
 MAXLENGTH="2"
/>

count++ 



I sucessfuly get spell1=0+spell2=4+spell3=0....yada yada, but when I try to, again looping though and calling $FORM{spell$count}, I get nothing in return...

excuse sloppy syntax, just trying to illustrate point, not code...


Edited:
you know...I think just typing out the question usualy helps me answer it myself Wink figured it our 30 seconds later; use FORM{"spell$count"} ; the double qoutes force interpolation....duh
  
Back to top
 
IP Logged
 
Imp_In_Training
God Member
*****
Offline


Don't follow me, I'm lost
too!

Posts: 608
Location: Aberdeen
Joined: Jun 17th, 2004
Gender: Male
Re: Essentials on MOD writing
Reply #12 - Oct 18th, 2005 at 12:14am
Print Post  
Any chance we can get an idea if anything has changed regarding this material and YaBB2?  For instance, it might help to let people know about the obvious differences in the english.lng change to the English folder / <mod>.lng files.  Plus the addition of the menu0.def - menu1.def - menu2.def files.

Display.pl has changed drastically also, and I'm trying to understand what all has changed so I can better revise a mod from 1.3 to YaBB2.  Any help I can get in this direction is very appreciated.
  
Back to top
WWW  
IP Logged
 
BeachBoy
New Member
*
Offline


I love YaBB 1G - SP1.2!

Posts: 17
Joined: Sep 13th, 2006
Re: Essentials on MOD writing
Reply #13 - Sep 21st, 2006 at 9:02pm
Print Post  
is there a tutorial on creating a mod?

meaning, the steps to do, like add the sub menu in the admin panel, etc.

I can figure it out form opening othe rmods, but if there is a standard procedure I'd like to know.

Regards,
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint