Hello all, I have run into a small problem while writing my application. Basically what it does it gets a list of stargate names from my server (http://projectbuilde...ectory&buffer=0) and then what I want it to do next is create a selectable menu out of the list, so that if the user selects one and presses enter, the program would return the name they selected, and then it would ask the server what the address for that name is.
I'm only having problems making the list from the data, I understand all the http stuff fine. From the examples I have seen, it would appear that in order to make a menu as I have described, I would have to parse my list and return a script which indicates a separate condition for each selection, defining which item should be highlighted.
It seems to me that certainly there must be some way to do this dynamically with a loop, without pre-processing the list into a menu script?
Any help would be much appreciated! Thanks, loving this plugin.
Creating a menu with changing content (HTTP)
Started by NullSchritt, May 16 2013 04:21 AM
6 replies to this topic
#1
Posted 16 May 2013 - 04:21 AM
#2
Posted 16 May 2013 - 05:45 AM
You're able to edit the PHP right?
First off: Do you serve HTML tags to everyone? Or is it just if the user agent isn't Java? If the user agent isn't checked, I recommend that you do check first.
Example:
Next, the menu. In this example, the output of the fetch.php page is "Spawn|Nether|North City Skylands"
First off: Do you serve HTML tags to everyone? Or is it just if the user agent isn't Java? If the user agent isn't checked, I recommend that you do check first.
Example:
#In this example, $cont contains the content of the file as a whole, e.g. "North City|Nether|Spawn". It does not contain any HTML tags.
if (!stristr($_SERVER['HTTP_USER_AGENT'], "java")) {
echo("<html><body><pre style='word-wrap: break-word; white-space: pre-wrap;'>".htmlspecialchars($cont)."</pre></body></html>");
} else {
echo($cont);
}
What that does it check to see if the request is coming from java or not. Not foolproof, but I don't see why anyone would set their user agent to something containing "java". Anyways, if the request is coming from java, we can assume that it's ComputerCraft. And we don't spit out any pre or html tags. If it's a browser, we do.Next, the menu. In this example, the output of the fetch.php page is "Spawn|Nether|North City Skylands"
-- //Obviously this would normally be set with http.get()
-- //For demonstration purposes, I hardcoded it
local out = "Spawn|Nether|North City Skylands"
local list = { } -- //This will hold individual strings
local link = { } -- //This will hold the click area for each label
local cursor = 1 -- //Keeping our position during the search
-- //There is probably a much faster and more efficient way to do this search
while string.find(out, "|") do
table.insert(list, string.sub(out, cursor, string.find(out, "|") - 1))
cursor = string.find(out, "|") + 1
end
-- //Since we only grab occurrences BEFORE the "|" character, we need to check if there is anything AFTER it (the last "|" only)
if #list > 0 then
if string.sub(out, cursor) ~= "" then
table.insert(list, string.sub(out, cursor))
end
end
-- And I got too tired to finish my example.
Yeah, sorry. If anyone else comes along before I finish tomorrow, great. It's 1:17 AM here, I better go to sleep.
#3
Posted 16 May 2013 - 07:43 PM
Currently the php script is editable, in fact, I wrote it, and what it does is it connects to a mysql database and prints the "NAME" column of the database, with a | between each name so that the string can be split into an array.
There is no html, in fact no headers at all sent, it's sent as plain text. (:
local request = http.get("http://smp.projectbuilder.info/fetch.php?cmd=page&ID=gatedirectory&buffer=0" )
local out = request.readAll()
There is no html, in fact no headers at all sent, it's sent as plain text. (:
#5
Posted 17 May 2013 - 05:51 PM
NullSchritt, on 16 May 2013 - 07:43 PM, said:
Currently the php script is editable, in fact, I wrote it, and what it does is it connects to a mysql database and prints the "NAME" column of the database, with a | between each name so that the string can be split into an array.
There is no html, in fact no headers at all sent, it's sent as plain text. (:
local request = http.get("http://smp.projectbuilder.info/fetch.php?cmd=page&ID=gatedirectory&buffer=0" )
local out = content.readAll()
There is no html, in fact no headers at all sent, it's sent as plain text. (:
You might want to have another PHP page to get the address for each stargate. Perhaps use GET for that. Then, we can ask the server for the one that is selected. Example: getAddress.php?name=Nether outputs (address for the Nether stargate).
Not tested:
Spoiler
#6
#7
Posted 17 May 2013 - 06:32 PM
Smiley43210, on 17 May 2013 - 05:51 PM, said:
NullSchritt, on 16 May 2013 - 07:43 PM, said:
Currently the php script is editable, in fact, I wrote it, and what it does is it connects to a mysql database and prints the "NAME" column of the database, with a | between each name so that the string can be split into an array.
There is no html, in fact no headers at all sent, it's sent as plain text. (:
local request = http.get("http://smp.projectbuilder.info/fetch.php?cmd=page&ID=gatedirectory&buffer=0" )
local out = content.readAll()
There is no html, in fact no headers at all sent, it's sent as plain text. (:
You might want to have another PHP page to get the address for each stargate. Perhaps use GET for that. Then, we can ask the server for the one that is selected. Example: getAddress.php?name=Nether outputs (address for the Nether stargate).
Not tested:
Spoiler
I already have a separate page which takes a name, and then looks up the address for the gate which most closely matches the text provided(the current dialing program works on queries but I thought it would be neat to also add a directory).
http://smp.projectbu...algate&name=sky
I will add this into my dialing program when I get home, and let you know how it goes. I do have one other question though, how would I add a static option at the top of the menu to "Enter Address Manually" so that users could connect to hidden gates?
2 user(s) are reading this topic
0 members, 2 guests, 0 anonymous users











