Author Topic: Finding the host  (Read 2016 times)

How would I find the host of the server? I have seen %host = getSubStr($ServerInfo::Name, 0, strStr($ServerInfo::Name, "\'"));. Would that work if the server was dedicated and the host was not on? Is there another way?

It would work unless the host's username had a ' in it, because the name of the server always starts with (Host's Name)'s.

$pref::Player::NetName is loaded in both dedicated and normal blockland modes.

$pref::Player::NetName is loaded in both dedicated and normal blockland modes.
I'm pretty sure he means client-sidedly considering he's using a variable that's loaded on the client side when you join a server.

Ah, well he should have said so.

for(%offset = 0; strStr(getSubStr($ServerInfo::Name, (%pos = strPos($ServerInfo::Name, "\'", %offset))-1, 3), "s") >= 0, %offset = %pos) {} %name = getSubStr($ServerInfo::Name, 0, %pos);

I haven't tested it, but that should work for 99% of scenarios. The only situation in which it won't work is if someone has named themselves "Mom's Boyfriend" in which case it's literally impossible to decypher at what point the player name stops and the server name begins without lexical parsing. This will, however, cover names like Kel'Block.
« Last Edit: March 26, 2014, 11:37:21 AM by $trinick »

Or you could just do %host = getsubstr($ServerInfo::Name, 0, strPos($ServerInfo::Name, "'s ")); (Which as far as I can tell does the same thing.)

Or you could just do %host = getsubstr($ServerInfo::Name, 0, strPos($ServerInfo::Name, "'s ")); (Which as far as I can tell does the same thing.)
No it doesn't. Ducks' Blockland Server

No it doesn't. Ducks' Blockland Server
%p = $ServerInfo::Name;
%host = getSubStr(%p,0,getMin((%p1=strPos(%p,"'s "))<0?999:%p1,(%p2=strPos(%p,"s' "))<0?999:%p2));


Picks 's or s' , whichever is first
« Last Edit: March 26, 2014, 03:52:46 PM by Ipquarx »

Why are you purposely making it unreadable D:

%p = $serverInfo::name;
%host = getsubstr(%p, 0, (%p1=(%p1=strpos(%p,"'s "))<0?999:%p1)<(%p2=(%p2=strpos(%p,"s' "))<0?999:%p2)?%p1:strpos(%p,"s' "));


Picks 's or s' , whichever is first

...

Code: [Select]
%full = $ServerInfo::Name;
%host = getSubStr(%full, 0, getMin(strPos(%full, "'s "), strPos(%full, "s' ")));


Even if you didn't know there was a getMin function, that's no excuse for using that monstrosity over defining function mMin(%a, %b) { return %a < %b ? %a : %b; }.

...

Code: [Select]
%full = $ServerInfo::Name;
%host = getSubStr(%full, 0, getMin(strPos(%full, "'s "), strPos(%full, "s' ")));


Even if you didn't know there was a getMin function, that's no excuse for using that monstrosity over defining function mMin(%a, %b) { return %a < %b ? %a : %b; }.
If either 's or s' don't exist in the name then the getMin call will be -1.

Here's an expanded version of that that isn't impossible to read:
%full = $ServerInfo::Name;
%p1 = strPos(%full, "'s ");
%p2 = strPos(%full, "s' ");
%p1 = %p1 < 0 ? 999 : %p1;
%p2 = %p2 < 0 ? 999 : %p2;
%host = getSubStr(%full, 0, getMin(%p1, %p2));
« Last Edit: March 26, 2014, 03:47:10 PM by Ipquarx »

-snip-

Code: [Select]
%full = $ServerInfo::Name;
%pos = getMin(strPos(%full, "'s "), strPos(%full, "s' "));
%host = getSubStr(%full, 0, %pos == -1 ? strLen(%full) : %pos);

What if the server name was aaaaa(snip 1990 a's)aaaaa? Your script would only show aaaaa(snip 989 a's)aaaaa.

Code: [Select]
%full = $ServerInfo::Name;
%pos = getMin(strPos(%full, "'s "), strPos(%full, "s' "));
%host = getSubStr(%full, 0, %pos == -1 ? strLen(%full) : %pos);

What if the server name was aaaaa(snip 1990 a's)aaaaa? Your script would only show aaaaa(snip 989 a's)aaaaa.
Usernames are restricted to some number < 30 characters of length, so I could shorten that number to less than 3 digits if I wanted to. This works because the person's name always comes first.

And you'll still be having that same issue, with the server name "Blockhead's Thingy" %host will end up being "Blockhead's Thingy".
« Last Edit: March 26, 2014, 04:01:29 PM by Ipquarx »

you could also send a request to the auth server with the name and ip to see if it returns a valid bl_id, and if not try checking the second 's/s' etc. etc.

**hosts name won't appear in ServerInfo until you spawn**
Code: [Select]
%host = getWord($ServerInfo::Name, 0);
%host = getSubStr(%host, 0, strLen(%host) - 3); //the three \'s characters