c# MySql API

hi guys I’m currently working on an c# to mysql library, via php.

I’m making it open source so that you guys don’t have to spend forever learning how to do it yourself.

The plan is to have it able to send high scores to a mysql database then retrieve the high scores for that leaderboard.

I.also want it to support as many leaderboards as you want and be able to sort it ascending or descending.

I still need to upload the php files as well as write a demo program a d a guide on how to use it.

If your interested in this let me know as I will probably be able to incorporate some suggestions as well

Edit: Here is the link to the repositry link

Why a library? If you have remote Access to the Database you can send queries directly.
If you don’t have a static ip to activate remote access in your database, you can simply rent a shared webhosting which are cheap and make a simple page where you can send data via url parameters and the page adds your data to the db.

Would be like 5 lines of code.

Yes however u can use any direct mysql or sql commands if u want it to be a windows store app. This way it will be cross platform

Are you saying you want to make an API with php in order to send highscores from C# with CRUD operations from ?

If you want it crossplatform, that would be the way to go, instead of using the mysql connector.net.

that’s exactly what I’m after. I already have a load of the api working. It will be fully cross platform and really simple to use.

With C#, you can use
WebClient.DownloadString -> GET
WebClient.UploadValues -> POST/PUT (Prefer the overload using NameValueCollection, it is easier than concatenating the string yourself and converting to a bytes array, and avoids problems: https://msdn.microsoft.com/fr-fr/library/9w7b4fz7(v=vs.110).aspx)

That’s what I do in my game. I also use a token per client and other data to authentify and avoid (hopefully) cheating

When you say a token to avoid cheating what do you mean. Iv have come up with a anti cheat system myself. they would need to disassemble the code to find out how it was generated.

disassemble the code to find out how it was generated

Which is fairly easy to do with the free decompilers out there.

yea I realize that just need to come up with a better methord

Even when using an obuscator ?

@Mattlekim: I use a token generated with a timestamp, user’s infos etc generated at each connection and valid for a period of time + some other things encrypted in it.
And for highscores, I compare the playtime vs the score, the timestamps between 2 deaths, etc.

Anyone can use a deobfuscator and decompiler such as a de4dot to look at your source code of your game, though it might not be as readable as the original source code. Security through obscurity is a bad policy.

A game should be considered just like a web browser; it communicates with a server which communicates with the database. Game <-> Server <-> Database

For the game / server, you can then either use simple HTTP post/get commands, or write your own application layer protocol using TCP / UDP transport protocols. Should probably use Lidgren if you decide to not use HTTP.

For the server / database, you should then use an existing object-relational mapping (ORM) framework instead of writing your own. One such library that is popular is Dapper. Another is Entity Framework by Microsoft.

1 Like

Hi guys.

Iv have made some progress with this.
My code can now login to the server and pull down scores from a leaderboard.

There is also an example program that will pull down scores from one of my leaderboards

There is currently no documentation and no security checks what so ever.

Ill keep posting as I add more functions.

Fell free to use the code, fork or whatever you wish.
Here is the repositry

Hope it will help some of you out.
Also never set up a proto build before so currently you need visual studio’s 2017 to use the example.

At first it’s going to be just a leaderboard system. Later I will add actual mysql commands.

Just went to your repository and clicked on the first file (LeaderboardServer.cs) to be confronted by “bad words”… not that many, but the last one doesn’t have a “c” in it.

Sorry about that, I’ll remove them and allow the user to input there own if they wish to use it

Fixed this in development branch as well as rewrote how it decodes the data from html tables. It now has the ability to download any MySQL database to a c# dictionary. Will finish the code and add the documentation soon and then merge with master brance

Now you can add scores.
Also wrote a getting started guide for you use.

As of now the leaderboard system is fully working. There is still things to do but you can add and get scores from a server.

Hope It helps some of you out