| Blockland Forums > Modification Help |
| finding a server |
| << < (2/2) |
| Fluff-is-back:
--- Quote from: Port on February 26, 2012, 04:03:43 AM ---The first is only impossible if you want the most recent server listing. --- End quote --- Ah yes, you could use a regularly cached one and loop though that. Also, I did make this function getServerByName(%name) // Call this function with the argument %name being the server's name { if(%name $= "") // if the name is blank, let's not waste our time. return; new HTTPObject(GSBN_HTTP).get("http://master2.blockland.us:80", "/index.php"); // Send a request for the master server list GSBN_HTTP.nameToSearchFor = %name; // Store the name we want for later use } function GSBN_HTTP::onLine(%this, %line) // When we get a line from the master server { if(getField(%line, 0) $= "FIELDS" || getField(%line, 0) $= "START") // If the lines start with this, we don't need them return; %names = %names TAB getField(%line, 4); // Saves all of the server names to a variable, separated by tabs - these are now fields %servers = %servers TAB getField(%line, 0) @ ":" @ getField(%line, 1); // Save the servers' connection details if(getField(%line, 0) $= "END") // Once we have them all, we are ready to cycle through each one { for(%i = 0; %i < getFieldCount(%names); %i++) { if(getField(%names, %i) $= %this.nameToSearchFor) // if the server name is the same as the name you specified earlier, we have found it! { doStuffWithServer(getField(%servers, %i)); // Call any function you like with getField(%servers, %i) will return ip:port break; } } %this.delete(); } } |
| I-have-not:
--- Quote from: Fluff-is-back on February 26, 2012, 04:11:35 AM ---Ah yes, you could use a regularly cached one and loop though that. Also, I did make this function getServerByName(%name) { if(%name $= "") return; new HTTPObject(GSBN_HTTP).get("http://master2.blockland.us:80", "/index.php"); GSBN_HTTP.nameToSearchFor = %name; } function GSBN_HTTP::onLine(%this, %line) { if(getField(%line, 0) $= "FIELDS" || getField(%line, 0) $= "START") return; %names = %names TAB getField(%line, 4); %servers = %servers TAB getField(%line, 0) @ ":" @ getField(%line, 1); if(getField(%line, 0) $= "END") { for(%i = 0; %i < getFieldCount(%names); %i++) { if(getField(%names, %i) $= %this.nameToSearchFor) { doStuffWithServer(getField(%servers, %i)); // Call any function you like with getField(%servers, %i) will return ip:port break; } } %this.delete(); } } --- End quote --- now, fluff, if you could only explain that. |
| I-have-not:
Plus, anyone who wants to know what my true objective is, PM me. |
| Fluff-is-back:
--- Quote from: I-have-not on February 26, 2012, 02:04:20 PM ---now, fluff, if you could only explain that. --- End quote --- I have now annotated it, if you need any further assistance, I'll do my best to help :) |
| Port:
--- Quote from: Fluff-is-back on February 26, 2012, 04:11:35 AM --- --- End quote --- Where are you storing %servers and %names? It doesn't magically exist all the time. You should probably store it on the HTTPObject itself (changing %servers to %this.servers and doing the same for %names) and also empty those variables upon starting a new query. Secondly, this will create an empty server in the start of the list. You might want to start the field loop at 1 instead of 0 to skip it. It isn't that much of a problem because "" won't be checked (start of getServerByName), but it's still a detail. |
| Navigation |
| Message Index |
| Previous page |