Difference between revisions of "MGS"

From MSX Game Library

Line 15: Line 15:
 
* and any other useful information for your game.
 
* and any other useful information for your game.
  
For example, in a racing game, besides the time to complete the race (the score) and the track (the leaderboard), you might also want to record the car type used, whether the player used a manual or automatic gearbox, etc.
+
For example, in a racing game, besides the time to complete the race (the score) and the track (the leaderboard), you might also want to record the used car model, whether the player used a manual or automatic gearbox, etc.
  
 
You are free to use any technique you want to encrypt your data.
 
You are free to use any technique you want to encrypt your data.
 
Just make sure the encoding is strong enough to prevent someone from inputting random codes and getting a valid score.
 
Just make sure the encoding is strong enough to prevent someone from inputting random codes and getting a valid score.
MSXgl provides a [[Modules/crypt|C module for encoding data]].
+
MSXgl provides a [[Modules/crypt|C module for encoding data]] than can be easily adapt to other development environment.
 
 
As the score code will be decrypted on the server side, so the function that decrypts your code will have to be written in PHP (a language that looks a lot like C).<>
 
  
 
=== Add your game to MGS ===
 
=== Add your game to MGS ===
Line 27: Line 25:
 
For now, this is a manual process that is handled directly by the site owner (MRC user Aoineko).
 
For now, this is a manual process that is handled directly by the site owner (MRC user Aoineko).
  
 +
Finally, the interface for converting score code to leaderboard entry needs to be created.
 +
It consist of several PHP functions (the site owner can help you write them).
  
 +
==== Decode ====
 +
If you are not using MSXgl encryption feature in your MSX game, you will have to provide your own decrypt function in PHP (a language that looks a lot like C).
 +
This function have to check the validity of the submitted code and, if valid, generates the entry to be added to the leaderboard.
  
Finally, the interface needs to be created: this is PHP code that checks the validity of the submitted code and, if valid, generates the entry to be added to the leaderboard.
+
Function prototype:
 
 
I have some example PHP functions available, but I can also write them for you if needed.
 
To decode the score code, you’ll need to write in PHP the inverse function of the one used on MSX.
 
If you use the MSXgl score encoding function, the corresponding PHP decoding function is already available.
 
 
 
 
<syntaxhighlight lang="php">
 
<syntaxhighlight lang="php">
// Decode a string and if valide, output a data stream and return true
+
// Decode a string and if valid, output a data stream and return true
 
// Parameters:
 
// Parameters:
 
//  code : Input crypted code
 
//  code : Input crypted code
Line 45: Line 43:
 
function Decode(string $code, string $key, array &$data): bool {}
 
function Decode(string $code, string $key, array &$data): bool {}
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 +
 +
 +
 +
 +
I have some example PHP functions available, but I can also write them for you if needed.
 +
To decode the score code, you’ll need to write in PHP the inverse function of the one used on MSX.
 +
If you use the MSXgl score encoding function, the corresponding PHP decoding function is already available.

Revision as of 18:36, 26 May 2025

MSX Game Scores (MGS) is an online leaderboard platform for MSX games: https://aoineko.org/mgs.

It allows players to submit their high scores using codes generated by the games themselves. Developers can integrate score encoding into their games, and once submitted, the scores are verified server-side and displayed on public leaderboards. The goal is to bring a modern, competitive scoring system to new MSX games.

Note: The MGS site has the same author but is not directly linked to MSXgl, even though this library includes tools to help generate score code.

How do I add my game to MGS?

Generate a score code

The basic idea is that your MSX game must generate a code that encodes the relevant data:

  • the score,
  • the corresponding leaderboard (if there are several),
  • and any other useful information for your game.

For example, in a racing game, besides the time to complete the race (the score) and the track (the leaderboard), you might also want to record the used car model, whether the player used a manual or automatic gearbox, etc.

You are free to use any technique you want to encrypt your data. Just make sure the encoding is strong enough to prevent someone from inputting random codes and getting a valid score. MSXgl provides a C module for encoding data than can be easily adapt to other development environment.

Add your game to MGS

After that, the game and its leaderboards have to be added to the MGS site. For now, this is a manual process that is handled directly by the site owner (MRC user Aoineko).

Finally, the interface for converting score code to leaderboard entry needs to be created. It consist of several PHP functions (the site owner can help you write them).

Decode

If you are not using MSXgl encryption feature in your MSX game, you will have to provide your own decrypt function in PHP (a language that looks a lot like C). This function have to check the validity of the submitted code and, if valid, generates the entry to be added to the leaderboard.

Function prototype:

// Decode a string and if valid, output a data stream and return true
// Parameters:
//  code : Input crypted code
//  key  : Input decoder key
//  data : Output data stream (bytes array)
// Return:
//  true if decode succeed
function Decode(string $code, string $key, array &$data): bool {}



I have some example PHP functions available, but I can also write them for you if needed. To decode the score code, you’ll need to write in PHP the inverse function of the one used on MSX. If you use the MSXgl score encoding function, the corresponding PHP decoding function is already available.