DMCH
1
Hi,
Trying to add server side hi-scores to my game, but struggling with this error. I’m using the script located here: link text Thanks
Error is: The name MD5Test does not exist in the current context. It originates from line 6 of the code posted below.
// Post Score
IEnumerator PostScores()
{
//This connects to a server side php script that will add the name and score to a MySQL DB.
// Supply it with a string representing the players name and the players score.
string hash = MD5Test.Md5Sum(userName + score + secretKey);
string post_url = addScoreURL + "name=" + WWW.EscapeURL(name) + "&score=" + score + "&hash=" + hash;
// Post the URL to the site and create a download object to get the result.
WWW hs_post = new WWW(post_url);
yield return hs_post; // Wait until the download is done
if (hs_post.error != null)
{
print("There was an error posting the high score: " + hs_post.error);
}
}
Looks like the script is missing an MD5 hash function. There’s one here: http://wiki.unity3d.com/index.php?title=MD5
Don’t know how cross platform it is if that’s an issue.
majaus
3
In the article you have a link to this page:
http://wiki.unity3d.com/index.php/MD5
Here you have the function:
public string Md5Sum(string strToEncrypt)
{
System.Text.UTF8Encoding ue = new System.Text.UTF8Encoding();
byte[] bytes = ue.GetBytes(strToEncrypt);
// encrypt bytes
System.Security.Cryptography.MD5CryptoServiceProvider md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
byte[] hashBytes = md5.ComputeHash(bytes);
// Convert the encrypted bytes back to a string (base 16)
string hashString = "";
for (int i = 0; i < hashBytes.Length; i++)
{
hashString += System.Convert.ToString(hashBytes*, 16).PadLeft(2, '0');*