Blockland Forums > Modification Help
how to make a gui only useable by the host?
Ipquarx:
Allright, here is what I'm trying to do, EXACTLY:
I'm tying to make a host-only GUI that goes along with my mod (if you really care that much, it's called WhiteList) so that people can use the mod easier. I've made the GUI itself, named all the right parts, and entered the commands for the buttons, here are the rest of the details:
there is a scrollable text list that lists all the blids on the whitelist. I'm trying to use a server-sided console function that returns 1 blid associated with a specific number, and a onWake function (client-sided) that is supposed to get all the blids from that function and put them in the list. That's problem 1.
I'm using a clientcmd to open and close the GUI (client-sided). That works.
I'm using a clientcmd to refresh the GUI. I don't know if it works.
There is a text box to enter in blids which is stored in a variable, and a button to add that blid to the whitelist using a server-sided console function. That's problem 2.
That specific enough?
I'm typing this on a iPod, so I can't get any code ATM.
Space Guy:
--- Quote ---I'm tying to make a host-only GUI
--- End quote ---
As previously explained, anybody can open that GUI client-side. You can just have it so it doesn't give them any information, though.
--- Quote ---I'm trying to use a server-sided console function that returns 1 blid associated with a specific number
--- End quote ---
You could send a tabbed list of 10-15 at a time. Wouldn't run over the character limit, saves on number of commandtoclient functions called.
--- Quote ---and a onWake function (client-sided) that is supposed to get all the blids from that function and put them in the list. That's problem 1.
--- End quote ---
Bad. This means you're sending however many server commands whether you're an admin or not if someone gets the GUI open, which'd be annoying for the server. Make it send one "requestWhitelist", then if they're the host the above can update the list. This also solves trying to get the number of IDs clientside when that isn't necessary - just clear the list then add every received one to the end of the list, either sorted on the server or after all of them have been recieved on the client.
--- Quote ---I'm using a clientcmd to open and close the GUI (client-sided). That works.
--- End quote ---
Alternately you could have this accessible from something like the Admin menu, provided it doesn't get in the way of RTB or other mods. Just don't make it another useless keybind I have to set.
--- Quote ---I'm using a clientcmd to refresh the GUI. I don't know if it works.
--- End quote ---
Clearing the GUI then requesting the whitelist again. Does this need a separate client-command? I don't see a use for it (all they'd have to do is close/reopen it) unless you want it to send only on first join and when the list is updated.
--- Quote ---There is a text box to enter in blids which is stored in a variable, and a button to add that blid to the whitelist using a server-sided console function. That's problem 2.
--- End quote ---
Well, what have you tried? You seem to know what you want so show an attempt before asking it to be spoon-fed to you.
Red_Guy:
--- Quote from: Ipquarx on May 30, 2011, 02:49:23 PM ---that sounds good, allright.
but i have a few questions:
1. do they have to be servercmds?
2. how do i make it dedicated compatible? in other words, how do i make it function properly without using canvas.
3. would makeing it dedicated compatible require client files?
--- End quote ---
Having had this thing crash my own dedicated server...heres a few tips:
1) TEST it on a dedicated server (start a dedicated LAN server on your own pc, join it and go from there).
2) use a client.cs file to exec() the .gui files
3) use a /command to open the gui. The setup looks something like this:
in server.cs
function serverCmdOpenMyGui(%client)
{
if (%client== getNumKeyID() )
commandToClient(%client, 'openMyGui' );
}
in client.cs
exec("mygui.gui");
function clientCmdOpenMyGui()
{
Canvas.pushDialog(MyGui);
}
You can also try making completely seperate addons, and only distribute the client-sided one to those people you want.
Thats step 1
Once the gui is opened, you also have to check every single servercmd to make sure the client is the host. Like Iban said -- there is nothing to stop people from hacking the gui to open on their own client.
my own comments on what your trying to do:
--- Quote from: Ipquarx on May 31, 2011, 03:09:38 PM ---I'm trying to use a server-sided console function that returns 1 blid associated with a specific number, and a onWake function (client-sided) that is supposed to get all the blids from that function and put them in the list. That's problem 1.
I'm using a clientcmd to open and close the GUI (client-sided). That works.
I'm using a clientcmd to refresh the GUI. I don't know if it works.
There is a text box to enter in blids which is stored in a variable, and a button to add that blid to the whitelist using a server-sided console function. That's problem 2.
--- End quote ---
I suspect a bad design of problem 1 is leading to problem #2
what I would do is this:
inside the onWake function you do 'commandToServer' and request the list of bl_ids from the server.
create a clientcmd to accept the bl_id and add it to your scrolling list in the gui
create a servercmd to loop through all your values and send them back to the client using the client cmd you just created. Send them to the client one at a time. This wont be a problem unless your whitelist includes more than 1,000 entries.
next create a servercmd that adds/creates a new entry in your global variable, and then sends that back to the client -- reuse your client cmd here as well.
Lastly -- in your gui, you just call the servercmd that creates a new entry. the servercmd then sends the result back to your client using the clientcmd you already created to add it to your scrolling list.
And in the 2 new server cmds you created, make sure to put in a check to make sure the client is the host.
Ipquarx:
Sounds like i've got my work cut out for me.
sounds like i basically did the entire thing wrong, if i need any further help i'll post another reply.
PNetwork2011:
ifSuperAdmin?