Forum

> > CS2D > Scripts > Function open_url
Forums overviewCS2D overview Scripts overviewLog in to reply

English Function open_url

13 replies
To the start Previous 1 Next To the start

old Function open_url

Ajmin
User Off Offline

Quote
Hi all,
Is there anyway to open url using lua?

For example:
in serveraction menu i added "visit forum now".
if some one choose it he should redirect to the forum.

(In the same way like clicking on a »url« on server info)

Thanks and Regards,
Ajmin

old Re: Function open_url

Ajmin
User Off Offline

Quote
Oh Ok

This script doesn't works.But reacts.
Lets have a test with this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
local open_cmd -- this needs to stay outside the function, or it'll re-sniff every time...
function open_url(url)
    if not open_cmd then
        if package.config:sub(1,1) == '\\' then -- windows
            open_cmd = function(url)
                -- Should work on anything since (and including) win'95
                os.execute(string.format('start "%s"', url))
            end
        -- the only systems left should understand uname...
        elseif (io.popen("uname -s"):read'*a') == "Darwin" then -- OSX/Darwin ? (I can not test.)
            open_cmd = function(url)
                -- I cannot test, but this should work on modern Macs.
                os.execute(string.format('open "%s"', url))
            end
        else -- that ought to only leave Linux
            open_cmd = function(url)
                -- should work on X-based distros.
                os.execute(string.format('xdg-open "%s"', url))
            end
        end
    end

    open_cmd(url)
end

Anything might be possible with this?

old Re: Function open_url

Raaj Nadar
User Off Offline

Quote
Does cs2D main screen support Html editing.
Like in cs 1.6 we can ass html link of our server & also some images.

And many more cools stuffs.

old Re: Function open_url

Ajmin
User Off Offline

Quote
I dont really understand ur query.
Do you mean adding some images etc to server info?

That stuff is not supported by cs2d in anyway.

old Re: Function open_url

DC
Admin Off Offline

Quote
Yes, CS2D does not support HTML. It does support links though. You can place links in the server briefing which is opened when someone joins the server (and it can also be opened manually using the menu or the briefing key).

To do so simply edit the file sys/serverinfo.txt with a texteditor.

Links must be enclosed in » and «

Example (this will become clickable and will open http://www.UnrealSoftware.de in the browser when a user clicks it):
»www.UnrealSoftware.de«

You can't automatically open any links at client PCs for security reasons. Imagine someone would write a script which just opens thousands of links at your PC when you join his server. That would be really annoying. Therefore it's impossible to do so.

old Re: Function open_url

Ajmin
User Off Offline

Quote
DC has written
and it can also be opened manually using the menu or the briefing key).


how can i manually open the briefing by using a particular menu?

old Re: Function open_url

DC
Admin Off Offline

Quote
Oh... I was sure that there's a button for it in the menu when you hit ESC but it looks like there's only a button for the map briefing. My bad.. sorry.

So you can only open it with the server info key (F1 by default) then. But keep in mind that it also opens automatically when you join the server so it's quite present.

old Re: Function open_url

sheeL
User Off Offline

Quote
In others games, you can execute sound via scripts like

1
2
sv_sound2(id,path or url)
sv_sound2(id,"http://unrealsoftware.de/sound.mp4"); -- EXAMPLE

I think that if CS2D grab this idea will be much cool @user DC:
But open the browser with lua script? I know that some players will abuse of this command.
edited 1×, last 10.10.14 06:18:33 am

old Re: Function open_url

DC
Admin Off Offline

Quote
@user sheeL: This is going a bit OT but there already is cs2d cmd sv_sound and cs2d cmd sv_sound2 in CS2D. It does exactly what you are talking about only that the sound files must be in the file transfer list of the server (either as path or url). This is necessary because otherwise they would have to be downloaded on command execution which would lead to delays (at least the first time the sound is played). With the transfer list they are downloaded directly when you join the server.

Of course there's a huge difference between simply playing a sound and opening a website. Opening a website starts the browser on the client machine which takes a lot of resources and which probably minimizes the game (or in worst case even crashs it when it runs in fullscreen). Servers might even open infected/insecure websites which install malware. So allowing servers to open websites at client systems is really a very bad idea.
It would only be acceptable if it wouldn't open the website directly but show a confirmation dialog with the address first where the client can decide to open the website or to cancel the whole thing.

old Re: Function open_url

DC
Admin Off Offline

Quote
@user sheeL: Please stay on topic. This thread is not about sounds or loading sounds from a website. It's about opening websites in a browser.

Also the current file transfer system for sounds and other files is already pretty okay. A global sound library doesn't make too much sense in my opinion. It might minimize duplicate sounds but those aren't a big problem at all in my opinion and therefore it's not worth putting resources (time for development and management, webspace and traffic) into such a thing.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview