[PLUGIN] rex_Function2

Post your completed addons to share with the community

Post » Wed Dec 14, 2011 10:09 am

Update:

Add "action: Inject JS function objects" for advance user. You can pass a code string. Plugin will use eval to parse it then execute it.

Example

The code string is
[code]function(fn)
{
    var my_add = function(fn)
    {
        fn.result = fn.param[0] + fn.param[1];
        fn.CallFn('message', 'I\'m at js function');
    };
    fn.InjectJS('my_add', my_add);
}[/code]

1. This code string is a function with one input parameter named 'fn' which is a part of function plugin.
2. Use command 'fn.InjectJS' to assign a js function into function plugin.
In this example:
[code]fn.InjectJS('my_add', my_add);[/code]
- User can use 'action:call "my_add"' in event sheet to execute this js function
3. The 'my_add' function has a input parameter named "fn". It is the same as 'fn' at previous.
- 'fn.param' is to get the value set by 'action: set parameter'
- 'fn.result' is to set the value got by Function.Result.
- 'fn.CallFn(name, param0, param1)' can call any function defined in this function plugin, even in event sheet. In this example, it will call 'message' which is defined at event sheet to append some text at text object. Oh, it can return the value set by 'action: set Result'.


This feature can not let you control every objects in javascript. User can use javascript as game logic, and call 'fn.CallFn' to interact with other objects, or get some values from event sheet.



The API of internal function object (using in JS) are listed below.
A. set parameters, returns
- fn.param
:: input parameters, a hash
- fn.ret
:: return values ,a hash
- fn.result
:: return value, single value

B. call function
- fn.CallFn(name, param0, param1...)

C. inject javascript function
- fn.InjectJS(name, fn)



Additional:

When the name of javascript function is the same as the function defined in event sheet, the function plugin will execute javascript function first, then the event sheet one.
If the javascript function return true, function plugin will not continue to execute the event sheet one. You can use this trick to do some checking/preprocessing before running the function defined in event sheet. rexrainbow2011-12-14 10:20:56
B
97
S
22
G
178
Posts: 4,122
Reputation: 104,051

Post » Tue Dec 20, 2011 10:04 am

How safe is this? Would someone be able to hack the system using a method similar to an SQL injection in the game? For that matter, would this be able to hijack an AJAX call and send the player to a phishing/malware site? Just wondering, I'm not yet up on C2 security.
B
27
S
5
G
5
Posts: 24
Reputation: 4,553

Post » Tue Dec 20, 2011 12:24 pm

Would it let me call a piece of javascript with jquery, like this:

$.post("https://www.scoreoid.com/api/getNotification", { api_key: "Your API Key", game_id: "Your Game ID", response: "JSON"},
   function(data) {
     alert("Data Loaded: " + data);
   },
"json"
);
B
29
S
12
G
7
Posts: 740
Reputation: 7,849

Post » Wed Dec 21, 2011 12:57 am

@dagda825
I'm not yet up on C2 security, too.
But I thought, if designer did not create a entry to allow player input string for code injecting, it might be safe.
Designer just use this feature to create game logic.
B
97
S
22
G
178
Posts: 4,122
Reputation: 104,051

Post » Wed Dec 21, 2011 1:00 am

@smitchell

Yes, you can call javascript with jquery in this feature, even you can call function defined in event sheet(Condition:On function) for a callback.
B
97
S
22
G
178
Posts: 4,122
Reputation: 104,051

Post » Wed Dec 21, 2011 9:09 am

That's alright. I'm going to give the plugin a go; it looks fantastic! Thanks for coding it.
B
27
S
5
G
5
Posts: 24
Reputation: 4,553

Post » Wed Dec 21, 2011 11:59 am

Im calling the javascript, But it doesn't like the syntax, More specifically the $, I think this is because i removed the "" but even when its there it doesn't like the script because there is various "" already in the code.

$.post("https://www.scoreoid.com/api/getNotification", { api_key: "Your API Key", game_id: "Your Game ID", response: "JSON"},
   function(data) {
     alert("Data Loaded: " + data);
   },
"json"
);
B
29
S
12
G
7
Posts: 740
Reputation: 7,849

Post » Thu Dec 22, 2011 4:38 am

If the problem is "" , try loading code string from AJAX plugin.rexrainbow2011-12-22 05:43:50
B
97
S
22
G
178
Posts: 4,122
Reputation: 104,051

Post » Thu Dec 22, 2011 12:23 pm

@rexrainbow,
?? You think i should load the strings from ajax and the call the javascript? Will that work? could you show me a example..?
B
6
S
1
G
1
Posts: 42
Reputation: 810

Post » Fri Dec 23, 2011 3:53 am

@DiggyDog

I put an example in original zip file. See test_fn_js_inject_AJAX.capx,
and an exported folder, the code string is put in file "fn.js".

You can type the code string in C2 editor, or use AJAX to load from external file.rexrainbow2011-12-23 03:56:19
B
97
S
22
G
178
Posts: 4,122
Reputation: 104,051

PreviousNext

Return to Completed Addons

Who is online

Users browsing this forum: No registered users and 5 guests