Friday, April 08, 2005 11:30 AM
RichardM
Dice BBCode Addin
Obviously most of the forum issues are fixed, and I feel I understand the structure fairly well. I am also happy to be learning about the asp.net 2.0 member system, it really rocks!
At any rate, I decided I wanted to finish my Dice BBCode Addin, as I had talked about it before, but previously didn't understand the code well enough to actually write it. So here is the first incarnation.
Here were my goals going in.
- The dice roller should be able to be used multiple times in a single post
- The dice should support multiple types, so I could customize outputs to match various popular games
- The dice roller should only impact the performance on initial posts, not on thread views
I have made the dieroller only work on new posts, to discourage cheating. For PBF (Play by Forum) games I run, I'm always subscribed anyways (it means I get copies of all new posts), so it would be impossible to cheat, but I didn't want to encourage it. Now that its done, I'm thinking of adding it to edit posts too, because what if someone forgets to add one? I don't really want to encourage double posting either (though I do it enough myself... ;)).
Anyway, so I opened the sourcecode in Visual Basic after setting up IIS to point to the web folder as a /cs subfolder. I opened /web/forums/addpost.aspx, and saw that it is using a control called CreateEditPost whose namespace is in the CommunityServer.Discussions.Controls, so I went to Class View, found the appropriate namespace, and double clicked to open the source code.
A little wandering through the code, I found posts.AddPost, Right clicked chose -> Go to Definition (Man I LOVE Visual Studio, the source is a nightmare, if I had to try and find everthing myself, I'd go nuts). A little more wandering, and I found where the bbcode was added.
Now they store the bbcode results in post.FormattedBody, but I couldn't do it that way, because otherwise random numbers would get generated constantly, or they would get wiped out, depending on whether I ultimately decide to generate the dice results on post updates or not. So I looked how they did the transforms:
post.FormattedBody = Transforms.FormatPost(post.Body, post.PostType);
I put in my code like so:
post.Body = rmcsmod.diceroller.parsetext(post.Body);
Then I started on my separate project. Right clicking on the solution, choosing add project, I added a classlibrary called rmcsmod.
I added a class called diceroller, then began creating my shared functions. There are lots of areas for improvement here, and this won't be my final version, but it works for now.
Here is the code I used.
Compiling the code, I simply copied the 2 assemblies (my rmcsmod assembly, and the modified communityserver.forums.discussions assembly) into the live server, and I was done!
Caveats:
- cheating is fairly easy if the DM doesn't have subscriptions turned on. Who wants to play with someone who cheats anyways? But regardless, I want to modify this to store each die result in a database table, then allow results to be looked up by user and date
- complex die results, like 5(1d4+1) which is a standard magic missile spell for D&D, can't be done with the current function. This looks like a major rewrite, and I just got too tired to do it last night. I'll probably work on this in the next few days, maybe if I decide to try and do it in a regular expression way.
- I'll be honest, the whole thing would probably easier if I had a better grasp of regular expressions, but its just not something I have had time to thoroughly learn.