|
grunthork Novice
Joined: 22 Jun 2009 Posts: 38
|
Posted: Thu Mar 17, 2011 4:51 am
How can I post stats to an external webpage? [PROv3.33a] (SOLVED) |
Reading through 90 pages of forum posts really is hard to do. I made it through 30 and then decided i need to get some help. Basically I want to keep updated stats for my character on a webpage, so that other people can see my progress. For example, I would have the following variables (let's keep it simple for now):
@maxhp
@maxmp
@currentlevel
How can I get those into a simple webpage, and update each one as they change? I have a separate computer on my lan that's using apache 2.2 (windows) and php. I can capture the variables without any issue, and I can also configure the webpage as needed. What I can't seem to figure out is how do i get these variables out of CMUD and onto my webserver? I've tried connecting to a database, which didn't work for me. What other methods are there? I'd like to post up-to-date information on my little webpage so that if I level up, my website reflects that change. I'm using CMUD Pro v3.33a. Thanks in advance to anyone that can help me with this. I don't need a lot of details, but a general method would help me focus and get started. |
|
Last edited by grunthork on Sat Mar 19, 2011 12:34 am; edited 1 time in total |
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4690 Location: Pensacola, FL, USA
|
Posted: Thu Mar 17, 2011 6:29 am |
Well... You could #FTP a .txt #FILE, which you can #WRITE via script.
The have your webpage update whenever the file gets updated. |
|
_________________ Discord: Shalimarwildcat |
|
|
|
charneus Wizard
Joined: 19 Jun 2005 Posts: 1876 Location: California
|
Posted: Thu Mar 17, 2011 1:07 pm |
Using the %url function, you can effectively POST data. Take a look at http://forums.zuggsoft.com/forums/viewtopic.php?t=35723 for an example of manipulating web pages. Hopefully that will get you started in the right direction. (Note: Scroll down about midway through the page to see the CMUDPro version)
|
|
|
|
grunthork Novice
Joined: 22 Jun 2009 Posts: 38
|
Posted: Fri Mar 18, 2011 1:03 am Thanks! |
Thanks for the quick replies. Unfortunately the FTP method doesn't work, since that stupid FTP window keeps opening up. Zugg stated the lag introduced by the FTP window popping up was caused by the directory listing using FTP, so i can't use it.
The %url function looks like what i need, but I'm unclear on how it works. I know a little about httpget and httppost, but not a ton. I need a little direction here. The %url function is what's escaping me. I think I would also need to write some CGI script to accomplish this. Can someone tell me if that's the right path to getting %url to work with this? If that's not right, can someone give me the high-level process so i can start doing a little research?
Thanks so much for your help. This has really got me stumped. |
|
|
|
orphean Apprentice
Joined: 21 Oct 2008 Posts: 147 Location: Olympia, WA
|
Posted: Fri Mar 18, 2011 8:29 pm |
This isn't too hard to do. From a highlevel viewpoint what you're going to do is create a CGI program on your webserver and you will use the %url() CMUD Pro function to interface with it (as you've already surmised in this thread.) The CGI program will serve a dual purpose. The first purpose will be to display your stats, the second purpose is to update them.
Moving on, from the webserver's viewpoint processing data from a GET or POST request are virtually identical. There are other considerations but we don't have to worry about them right now for this example. I think you'll find the GET request to be marginally easier to work with so that's the approach I'll take. So a GET request is simply data that's tacked onto the end of a URL. If you look in your browser bar while you're reading this post you should see a '?t=36677' in there. That's the data for a GET request, in this case it's telling the viewtopic.php program which thread to show. What we want to do is create our own program that can take a GET request like that and do something with it. In our case we want to store some variables.
So our interface can be very simple:
Code: |
http://yourserver.com/mudstats.pl?maxhp=<HP HERE>&maxmp=<MP HERE>¤tlevel=<LEVEL HERE> |
And here's what a possible (albeit terrible) CGI program might look like that processes that request:
Code: |
#!/usr/bin/perl
use CGI qw(:standard);
use DB_File;
use Fcntl;
print header;
if( param() ) { # Were any parameters passed?
# Yes, we have parameters. Let's update
# our mud stats.
my %h;
tie %h, "DB_File", "mudstats.dat", O_RDWR|O_CREAT,0644, $DB_HASH;
$h{"maxhp"} = param('maxhp');
$h{"maxmp"} = param('maxmp');
$h{"currentlevel"} = param('currentlevel');
untie %h;
} else {
# Nope no parameters, display our stats.
my %h;
tie %h, "DB_File", "mudstats.dat", O_RDWR|O_CREAT,0644,$DB_HASH;
print <<EOM;
<html>
<head>
<title>MudStats</title>
</head>
<body>
<table>
<tr><td>MaxHP:</td><td>$h{"maxhp"}</td></tr>
<tr><td>MaxMP:</td><td>$h{"maxmp"}</td></tr>
<tr><td>CurrentLevel:</td><td>$h{"currentlevel"}</td></tr>
</table>
</body>
</html>
EOM
untie %h;
} |
That should be readable enough to get a gist of what it's doing. The weird crap with the 'tie %h' is a way in perl to store and read a database file from a disk. It's where it dumps and retrieves the stored variables. One thing to point out is the lone if/else block in the script. It checks to see if there are any parameters and, if so, it stores the data. Otherwise we display it. This does no error checking and is in general a really stupid script but it's functional and simple and should help to give an idea of what this piece of it might look like.
So now that we have the CGI we can call it from CMUD Pro. Here's a simple test alias that calls the CGI script to update the values:
Code: |
$maxhp = 550
$maxmp = 750
$currentlevel = 5
$u = %url("yourserver.com/mudstats.pl?maxhp="$maxhp"&maxmp="$maxmp"¤tlevel="$currentlevel)
#call $u.Get |
In 'real life' you would use your existing variables for these values of course. Now, going to:
Code: |
http://yourserver.com/mudstats.pl |
(note no parameters!) we get the following result in our browser:
Code: |
MaxHP: 550
MaxMP: 750
CurrentLevel: 5 |
Whee.
And that's basically it. When you want to update your website variables you just build the URL and call Get on it and it's done from CMUD. This should be enough to get you started, if not, well that's what the thread is for |
|
|
|
grunthork Novice
Joined: 22 Jun 2009 Posts: 38
|
Posted: Sat Mar 19, 2011 12:34 am |
Perfect. You went into more detail than necessary, so thanks for that. That confirms what I need to do. I'll write a C++ program to handle my CGI, and I think i'll use a POST instead of GET. Thanks again for all of the help!
|
|
|
|
orphean Apprentice
Joined: 21 Oct 2008 Posts: 147 Location: Olympia, WA
|
Posted: Sat Mar 19, 2011 3:31 am |
I'd recommend getting a CGI library (such as cgicc) if that's the route you're going to take to help save you reinventing the wheel. And yeah POST/GET whatever you want, it's all the same to the webserver. If it's going to be publically viewable link the results if you don't mind so we can see what you came up with!
|
|
|
|
grunthork Novice
Joined: 22 Jun 2009 Posts: 38
|
Posted: Sun Mar 20, 2011 4:40 pm New Issue - Same Thread |
Well Now i'm having an issue with %url. I've tried to copy and past Zugg's examples, and I just don't understand how to use it. Zugg's listed all of the methods and params, but I don't understand how to use them. This is new to me so i'm wondering if someone could give me an example of post or get (or both) using the %url function. I don't want to retrieve any information from the webserver, i really only need to send it information. I haven't quite finished my program on the cgi end of it, but when I do i'll really need to understand %url to test it. Thanks again everyone.
|
|
|
|
Ithilion Wanderer
Joined: 02 Sep 2005 Posts: 85
|
Posted: Thu Mar 24, 2011 9:08 pm |
I can't answer, but I can comment that it's better to start a new thread, even if it's the same issue, it's easier and cleaner that way, btw
|
|
|
|
|
|