Can I Call Function with PHP

Started by vcmptr, Mar 11, 2015, 05:44 PM

Previous topic - Next topic

vcmptr

I wonder can I call squirrel function with PHP?
My English is not good.

.

#1
Quote from: vcmptr on Mar 11, 2015, 05:44 PMI wonder can i call squirrel function with PHP?

No, you can't. Not unless you write a specialized PHP extension that allows you to do that. Like this extension does for Lua. But the problem isn't just executing a Squirrel function. I'm assuming that you want to execute a Squirrel function from your script loaded by the Squirrel module which is currently executed by the server.

Another idea, which might not be the best and/or fastest solution would be to use the sockets module of squirrel to create a simple server/daemon like, listener in Squirrel and then, either from PHP or somewhere else, connect to that listener and either send specific commands that the script knows how to react (preferred, for safety) or strings that can then be evaluated in Squirrel as code at runtime.

compilestring(string,[buffername])

compiles a string containing a squirrel script into a function and returns it

local compiledscript=compilestring("::print(\"ciao\")");
//run the script
compiledscript();

Either way, it's not very pretty to do and you haven't told us what you're trying to achieve. Maybe there's a better way.
.

Thijn

Making it accept a string that will be evaluated seems like a major security flaw.

Another way I can think of is using MySQL, and then writing to a table with PHP and reading from it within Squirrel.

vcmptr

Thanks S.L.C and Thijn. I will try this ways.
My English is not good.

.

Quote from: Thijn on Mar 11, 2015, 06:48 PMMaking it accept a string that will be evaluated seems like a major security flaw.

Obviously! Actually, I'm not even sure why these things are implemented. But I assume it's for those rare cases when you need it and it's mostly for testing and/or personal use. I've seen major software doing that and evaluating run-time generated PHP code.
.

Stormeus

The above posts answer your question. Personally I'm of the opinion that if you think you need to do this, you don't, and going forward with it would be a terrible idea.

More refined help would be available if you explained what you're actually trying to accomplish using this feature.

vcmptr

#6
Quote from: stormeus on Mar 11, 2015, 07:53 PMThe above posts answer your question. Personally I'm of the opinion that if you think you need to do this, you don't, and going forward with it would be a terrible idea.

More refined help would be available if you explained what you're actually trying to accomplish using this feature.
Now I need check is player in game.  :)
My English is not good.

.

Quote from: vcmptr on Mar 12, 2015, 08:48 AMNow I need check is player in game.  :)

Something that simple? A database would be the easiest and most simple way. An even simple and easier way if you don't know how to use databases would be .ini files. Anything other than calling Squirrel from PHP would be better.
.

Fuzzie


Sk

#9
create a table
When player join insert his data.
When he leaves delete that data now in php all you need to know that if the player exist in that table,then do your stuff.

vcmptr

Quote from: S.L.C on Mar 12, 2015, 11:51 AM
Quote from: vcmptr on Mar 12, 2015, 08:48 AMNow I need check is player in game.  :)

Something that simple? A database would be the easiest and most simple way. An even simple and easier way if you don't know how to use databases would be .ini files. Anything other than calling Squirrel from PHP would be better.
I just wondered It's possible. I thought call this functions:
function gplayer(name)
{
local player = FindPlayer(name);
if(player)
{
return [player.ID, player.Name, player.IP, player.UniqueID, player.Skin, player.Score, status[ player.ID ].KillingSpree]
}
else return 0;
}
or this:
function rld()
{
ReloadScripts();
print("Script reloaded from website!");
}

But I give up use reload function for now. I decided to use Query Mechanism and MySQL.

Thanks all for helping. :)
My English is not good.