[C++] Lua-Interface

This Section is all about Coding in C/C++ / Lua / SourcePawn for now...
User avatar
Neico
Lead Coder
Lead Coder
Posts: 1799
Joined: Tue Aug 15, 2006 3:39 pm
Location: Germany
Contact:

[C++] Lua-Interface

Post by Neico »

I'm currently making the Lua Interface I've wanted to do ages ago and to keep you guys updated about it I'll upload new bins from time to time here: http://www.wuala.com/neico/Public/Lua/

If you got any suggestions on what this lua implementation should be capable of, let me know (No, I'm not going to make the Interface itself public, as that one stays completely under my taste)

I'll extent this Post as progress goes on (I'll also update informations about the progress of implementing it into OC)

Things you can help with:
https://docs.google.com/document/d/1r0V ... Ypz3E/edit
Image
Gary
npc_advisor
npc_advisor
Posts: 1125
Joined: Sun Nov 09, 2008 7:21 am
Location: USA, FL
Contact:

Re: [C++] Lua-Interface

Post by Gary »

What exactly do we get from the ability to make lua scripts? What kind of functions can we access? Could we include lua-scripted entities with out maps?

Is this basically going to mirror the way GMOD lua addons work? SNPCs, SENTs, SWEPs, client-side scripts(new HUDs, FP ragdol/death), server scripts?



On the suggestion side:
I suppose, if possible, to rebuild all scripts ingame, so I won't have to restart the engine for every little edit.
Cpp-like options, like GMOD has.
User avatar
Neico
Lead Coder
Lead Coder
Posts: 1799
Joined: Tue Aug 15, 2006 3:39 pm
Location: Germany
Contact:

Re: [C++] Lua-Interface

Post by Neico »

I'm not too sure about GMod like features but expect at least some of the server side ones to appear, but before that I'd like to get some heavy testing going on, which basically requires that you're able to write lua scripts.
But since lua is not hard to write (basically all you need is English knowledge like if then end function etc.) this shouldn't be a problem.

Also, since today the include function is available, it is made with an experimental file path restriction to prevent lua viruses etc.
so crack the heck out of that function and reply in here if you've got a lua script outside of the lua/includes folder working, this is very important...

PS: since there is no real error handling yet use this:
[lua]msg( include( "<filepath>" ) )[/lua]

this either returns true or false + the error message (the error message will be moved to the error handler once that one's done~)
Image
User avatar
Dominic
Donator
Donator
Posts: 54
Joined: Thu May 13, 2010 7:02 am
Contact:

Re: [C++] Lua-Interface

Post by Dominic »

I can see the usefulness of this, please do not drop support for this. I'm very interested in this since I know from gmod server side lua scripts really can make a server unique. I can see people making some unique scripts, I mean I can't think of any off the top of my head but this sounds really cool if it got implemented into OC. I want to help but I have no real knowledge of lua, I'll ask one of my friends if he can try to get a lua script out of the includes folder.
User avatar
Dominic
Donator
Donator
Posts: 54
Joined: Thu May 13, 2010 7:02 am
Contact:

Re: [C++] Lua-Interface

Post by Dominic »

With the help of my friend, turtle, he asked me to do various types of things in the console and we found that we can access lua files outside of the includes folder, windows folder, C: folder, and in system 32, which is very bad.

Outside of includes folder msg( include( "../test.lua" ) )
C:/ drive msg( include( "../../../../../../../../../../../../../../../test.lua" ) )
Windows folder msg( include( "../../../../../../../../../../../../../../../WINDOWS/test.lua" ) )
System 32 folder while true do include("../../../../../../../../../../windows/system32/*.*" ) end

For the above to work turtle told me you only need a minimum of six ../'s for those to work

the system 32 one lagged my whole computer out, the last one apparently attempts to read windows files every cpu cycle so console.exe was at 75ish cpu usage and steam was at 15.

Hope that helps!
User avatar
Neico
Lead Coder
Lead Coder
Posts: 1799
Joined: Tue Aug 15, 2006 3:39 pm
Location: Germany
Contact:

Re: [C++] Lua-Interface

Post by Neico »

That's the kind of feedback I need, thanks I'll look into it
Image
User avatar
Neico
Lead Coder
Lead Coder
Posts: 1799
Joined: Tue Aug 15, 2006 3:39 pm
Location: Germany
Contact:

Re: [C++] Lua-Interface

Post by Neico »

Don't know how, but I've fixed it somehow, not too sure what I did tough, but I got an assumption, anyways I think I need to modify that algorithm further~

Edit: This call looks now a bit expensive but this now is unbreakable to anyone O.o

[cpp]
bool MakeValidPath( std::string &FileName )
{
boost::replace_all( FileName, "\\", "/" );
if( boost::istarts_with( FileName, "./" ) ) boost::replace_first( FileName, "./", "" );
boost::replace_all( FileName, "..\\", "" );
boost::replace_all( FileName, "../", "" );

boost::filesystem::path FilePath( boost::filesystem::absolute( boost::filesystem::path( FileName ) ).generic_string() );

if( !FilePath.has_extension() ) FilePath = boost::filesystem::path( std::string( FilePath.generic_string() ).append( ".lua" ) );
if( !boost::iends_with( FilePath.parent_path().generic_string(), "/lua/includes/" ) )
{
std::string tmp( std::string( FilePath.parent_path().generic_string() ) );
tmp += "/lua/includes/";
tmp += FilePath.filename().generic_string();
FilePath = boost::filesystem::path( tmp );
}

std::string RequiredPath( boost::filesystem::current_path().generic_string() );
RequiredPath += "/lua/includes/";

FileName = FilePath.generic_string();
return ( boost::istarts_with( FilePath.generic_string(), RequiredPath ) && boost::filesystem::exists( FilePath ) );
}
[/cpp]

Image
Image
User avatar
Dominic
Donator
Donator
Posts: 54
Joined: Thu May 13, 2010 7:02 am
Contact:

Re: [C++] Lua-Interface

Post by Dominic »

Awesome work, glad I could help somewhat.
MaestraFénix
Team Member
Team Member
Posts: 2470
Joined: Mon May 10, 2010 11:50 am
Location: Spain
Contact:

Re: [C++] Lua-Interface

Post by MaestraFénix »

What about the security of this? i heard before a general update in Gmod that some LUA files can make VAC ban you (or put inside of your computer vyrus, troyans and such) when you downloaded it joining a server. There will be way to control what is modified and what not?
Click on my photo to add me into your friends in Steam
Image
Steam photos | Steam videos

Image
User avatar
Neico
Lead Coder
Lead Coder
Posts: 1799
Joined: Tue Aug 15, 2006 3:39 pm
Location: Germany
Contact:

Re: [C++] Lua-Interface

Post by Neico »

Currently, everything that could harm the computer has been removed from it, the only thing currently is the include function which basically provides the base security that I'll apply to the rest of the filesystem related functions later on

and since this is not added to any sourcemod yet is it impossible to get vac banned (and when I do I'll keep in touch with garry to ensure that everything stay's safe)
Image
MaestraFénix
Team Member
Team Member
Posts: 2470
Joined: Mon May 10, 2010 11:50 am
Location: Spain
Contact:

Re: [C++] Lua-Interface

Post by MaestraFénix »

Ok, is good know that.
Click on my photo to add me into your friends in Steam
Image
Steam photos | Steam videos

Image
User avatar
Neico
Lead Coder
Lead Coder
Posts: 1799
Joined: Tue Aug 15, 2006 3:39 pm
Location: Germany
Contact:

Re: [C++] Lua-Interface

Post by Neico »

Added a Link to the Main Post, feel free to help me by commenting, it would really help me (even tough you probably won't be able to see the results)
Image
User avatar
Dominic
Donator
Donator
Posts: 54
Joined: Thu May 13, 2010 7:02 am
Contact:

Re: [C++] Lua-Interface

Post by Dominic »

Ok I asked my friend turtle to help, I posted a few on there.
User avatar
Neico
Lead Coder
Lead Coder
Posts: 1799
Joined: Tue Aug 15, 2006 3:39 pm
Location: Germany
Contact:

Re: [C++] Lua-Interface

Post by Neico »

It's sad that so few people seem to have any ideas on how a Function could be called...
Image
MaestraFénix
Team Member
Team Member
Posts: 2470
Joined: Mon May 10, 2010 11:50 am
Location: Spain
Contact:

Re: [C++] Lua-Interface

Post by MaestraFénix »

Neico wrote:It's sad that so few people seem to have any ideas on how a Function could be called...
I swear to you that tommorrow i´ll do a bit. I´m always forget this.
Click on my photo to add me into your friends in Steam
Image
Steam photos | Steam videos

Image
Post Reply