Author Topic: finding a server  (Read 1309 times)

I was thinking on how to make a function somewhat like 'findserverbyname("name here")'

Does anyone know how I might be able to do that?

Please explain further.

You have to connect the master server, which is located here: http://master2.blockland.us/

Then get field 4 of every line and check for ones that match the name.

And I imagine you would want it to return the server? or Join the server?
The first is impossible, unfortunately.

And I imagine you would want it to return the server? or Join the server?
The first is impossible, unfortunately.

The first is only impossible if you want the most recent server listing.

The first is only impossible if you want the most recent server listing.

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();
    }
}
« Last Edit: February 26, 2012, 02:29:56 PM by Fluff-is-back »

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();
    }
}


now, fluff, if you could only explain that.

Plus, anyone who wants to know what my true objective is, PM me.

now, fluff, if you could only explain that.

I have now annotated it, if you need any further assistance, I'll do my best to help :)


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.