-1

I don't know how to process, and when i search in the internet, there is so many solutions, I'm a bit lost.

My task is to create a leaderboard, the game is developed in C# with unity and my internship supervisor just told me "You have to put some PHP into the database server of our client and then make a "bridge" between our game and this PHP"

I never used C# before (Java is sooo cooler) any advice, source with commented code "easy" to understand?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • why do you need the **bridge**, what is it going to do ? – Sudipta Mondal Jul 10 '17 at 08:40
  • The bridge will "send" informations to fill the database from the game – Laurent Outtan Jul 10 '17 at 08:42
  • No wonder you're lost - I'd be lost if someone asked me to *... to put some PHP into the database serveur of our client and then make a "bridge" bitween our game and this PHP*; what is meant by putting PHP into the database server? Is it going into the database (pointless) or are the database and application server the same thing? What is meant by client in this case - a customer or a client machine? What did they mean by "bridge" - an API? This is way too vague to be answerable... – CD001 Jul 10 '17 at 08:50
  • How i see the solution : The php in our customer Database server is something wich be call when the server recieve informations from the game to treat them and fill the database – Laurent Outtan Jul 10 '17 at 09:02
  • PHP, Java, C# all mentioned. Which one are you actually using? I think your supervisor means that you need a server-side web API to accept HTTP requests from your game in order to send and retrieve information to/from the database (exposing the database directly over the internet is usually a bad idea for security and performance) and maybe perform some business logic calculations and manage security etc. It's a pretty standard application architecture these days. – ADyson Jul 10 '17 at 09:02

1 Answers1

0

You may want to write your API. You will then call it with C# using web requests.

A very simple way to get data from your database is to switch through given endpoints in your the URL. For instance, the following URL: http://yourserver.com/api/v1/?leaderboard/top

You may explode the URL to get the endpoints with $endpoints = explode('/', rtrim($_SERVER['QUERY_STRING'], '/'));. In this case, $endpoints[0] would give leaderboard.

You could then use a switch statement to handle your request.

// ...
$endpoints = explode('/', rtrim($_SERVER['QUERY_STRING'], '/'));
switch ($endpoints[0])
{
    case 'leaderboard':
    {
        switch ($endpoints[1])
        {
            case 'top':
                // Ask your database
                $result = get_top_leaderboard();
                echo json_encode($result);
                break;
            // case ...
         }
         break;
     // case...
     }
}
// ...

Use the same method with $_POST to get user entries, and write them in your database. Do not forget to protect yourself from SQL injections.

In C#, perform a GET request on your API:

var responseString = await client.GetStringAsync("http://yourserver.com/api/v1/?leaderboard/top");

Keep in mind this exemple is not secured. If you want to get sensible data from your database, do not let your API unsecured with public access.

Enzo Innocenzi
  • 549
  • 4
  • 12