How do I link C programming compiler to C2

Get help using Construct 2

Post » Wed Jun 01, 2016 6:41 am

I want to make a educational game which teaches C programming language I want the players can edit C code on my game and send code file to run on compiler then send back the result from complied Please help me how I can do
Thank you
B
7
S
3
Posts: 14
Reputation: 607

Post » Wed Jun 01, 2016 2:49 pm

if you're running with nwjs you can call an external application to do this for you. If you're running on the web you'd have to send the data to a server and then run the compiler on the server.
Nothing goes unanswered!
B
24
S
5
G
1
Posts: 434
Reputation: 3,446

Post » Wed Jun 01, 2016 3:12 pm

briggybros wrote:if you're running with nwjs you can call an external application to do this for you. If you're running on the web you'd have to send the data to a server and then run the compiler on the server.

Thank you so much for reply, briggybros

I am running my game on web but I don't know how to send the data from C2 to a server and then run the compiler . What I should to know before do it such as a how to or the name of compiler. I spanned time all week for solve this issue but I can't, please help me or tell me more about the process or step Thank you again.
B
7
S
3
Posts: 14
Reputation: 607

Post » Wed Jun 01, 2016 11:08 pm

so the solution from the top of my head would be to rent a server with a linux distribution, making sure you have gcc installed, and configure a webserver with a large post length. Then in your app, you can use construct's urlencode() on the entire source code and use AJAX post to url to post the encoded source code to a webpage with a php script something like the following:

Code: Select all
<?php

function checkSource($source) {
   //TODO: Definitely check here if the C program will not try to kill your server.
   $safe = true;
   return $safe ? $source : '#include<stdio.h> \n main(){printf("Illegal C Program!");}';
}

$name = "tempfile" . rand(0, 100000);
file_put_contents($name . ".c", checkSource(urldecode($_POST['source'])));
$res = shell_exec("gcc" . $name . ".c -o " . $name);
if ($res == NULL) {
   print("Compilation error");
} else {
   print (exec("./" . $name));
}
?>


I cannot stress the importance of checking whether the C file will not break your system, and personally I would never allow a script like this to be on my server, as it's prone to so much abuse.
Nothing goes unanswered!
B
24
S
5
G
1
Posts: 434
Reputation: 3,446


Return to How do I....?

Who is online

Users browsing this forum: banquetburger and 45 guests