Spheres Simple WebPage Generation Can be a handy tool and its not hard to use.
For this example a stone will be created in game and then read from a webpage.
1. Make a stone
PHP Code:
[ITEMDEF i_webpageExample_stone]
DEFNAME=i_webpageExample_stone
NAME=Web Stone
ID=i_gravestone_2
TYPE=t_script
ON=@CREATE
ATTR=ATTR_NEWBIE|ATTR_MOVE_NEVER
TIMER=1
ON=@TIMER
// Set some tags on it to read
IF <REGION.GUARDED>
TAG.RegionGuarded=UP
ELSE
TAG.RegionGuarded=DOWN
ENDIF
// And the timer it should be less than the webupdate time, that ill mention in a moment.
TIMER=10
RETURN 1
2. in game .add i_webpageExample_stone in a town on your map.
3. in game write .xshow UID and target the stone, record the UID mines is (040005f1d)
4. above the stone script write this DEFNAME and put your stones UID in
PHP Code:
[DEFNAME WebExample]
WebStoneUid 040005f1d
5. resync the server
6. open note pad and copy and paste the following
PHP Code:
<html>
<head>
<title>WebPageExample</title>
</head>
<body>
Webpage Example
</body>
</html>
7. save and close the text file and then rename it (Including its extension ".txt") to "webpage.html"
8. if you have a website put the page into it (
http://www.mywebsite.com/webpage.html)
if you dont have a website put the file inside your sphere folder (/scripts/web/webpage.html)
9. Open Sphere.ini and scroll down until you find
Code:
///////////////////////////////////////////////////////////////
//////// Webpage Settings
///////////////////////////////////////////////////////////////
// Note, that you can catch error codes by creating sphere404.htm and so on
// for all HTTP error codes sphere support.
[WEBPAGE 1]
// Determines what html file is used as base for the status page
WebPageSrc=scripts/web/spherestatusbase.html
// Determines where the status page is saved
WebPageFile=scripts/web/status.html
// In seconds, how often the status file is updated
WebPageUpdate=60
// Required PLevel to view this page (0 = anyone, 6 = admins only)
PLevel=0
10. Create a new one as below [WEBPAGE 2]
Code:
[WEBPAGE 2]
WebPageSrc=scripts/web/webpage.html // Your new webpage
WebPageFile=scripts/web/webpage.php // You can even change the file extension (Remeber not to use same name if same extension)
WebPageUpdate=20 // 15 Seconds is too fast and has been set just for the purpose of the example.
//sphere reads WebPageSrc and then makes the WebPageFile every WebPageUpdate seconds
while sphere.ini is still open check these settings
Code:
// Use the built in http server
// 0 - disable http server and webpage generation
// 1 - disable http server and enable webpage generation
// 2 - enable http server and webpage generation (default)
UseHttp=2
11. Edit your webpage.html again and change it as shown below.
PHP Code:
<html>
<head>
<title>WebPageExample</title>
</head>
<body>
<p>Webpage Example</p>
<p>%uid.WebStoneUid.NAME% is in %uid.WebStoneUid.REGION.NAME%</p>
<p>and Guard Zone is %uid.WebStoneUid.TAG.RegionGuarded%</p>
</body>
</html>
12. Open up your stone script and add the following function
PHP Code:
[PLEVEL 1]
WebPage
[FUNCTION WebPage]
WEBLINK C:\sphere\scripts\web\webpage.php
13. Save and close all open scripts and webpages
14. resync the server and wait for <WebPageUpdate> seconds for the page to be generated.
15. if you own a website goto
http://www.mywebsite.com/webpage.php.
if you dont own a website in game use the command .webpage