0

I'm building a level into a C# string using each char to hold two different elements. I'm using all 16 bits in each char. I'm able to save the level off in a text file and read it back in with no issues. It's ugly to look at because a number of chars match something that equals null. When I tried sending it to PHP (code below) I immediately echoed back the string I received. Upon first glance the data was wrong. Upon checking the bits in each string I could see that there was no real relation between the two strings that were supposed to be the same.

    public static void UploadLevel(int userID, string levelData)
    {
        Debug.Log("LEVEL OUT:");
        Scene_Editor.LevelToBinary(levelData);
        using (var client = new WebClient())
        {
            var values = new NameValueCollection();
            values["uid"] = userID.ToString();
            values["leveldata"] = levelData;

            var response = client.UploadValues("http://example.com/uploadlevel.php", values);

            var responseString = System.Text.Encoding.UTF32.GetString(response);
            Debug.Log("levelData BACK");
            Scene_Editor.LevelToBinary(responseString);
        }
    }

And here is uploadlevel.php

<?php
   echo $_POST['leveldata'];
?>

Here is a very short example of a level converted to a string (3 chars is the smallest, and can go up to 99 chars).

Level Out: ㄐ
Broken down into binary:
0) 0010001011111111 (no char seems to be associated with this value)
1) 0011000100010000 (ㄐ)
2) 0010000001100000 (no char seems to be associated with this value)

Level Back: 询還
Broken down into binary:
0) 1000101111100010 (询) 1) 1001000010000100 (還)

Now, I don't even necessarily need this to be a string as long as I can store it in a database and get it back and convert the bits back into a level. Any ideas? Also, I'm using .net 4.0.

Califer
  • 529
  • 9
  • 28
  • can you show us an example input string and output? – devlin carnate Jan 15 '16 at 00:03
  • i dnt know wheather your data is being sent as get or post. instead of using $_POST use $_REQUEST because request accept both get and post. – jewelhuq Jan 15 '16 at 00:08
  • "number of chars match something that equals null" <- What does that mean? Are you using `===` to compare or just `==`? Also, if you're dealing with binary it is FAR less error prone to base64 encode/decode it when moving it between languages like that. – Mike Jan 15 '16 at 00:09
  • @ devlin: I added an example to the original post. – Califer Jan 15 '16 at 04:44
  • jewelhuq: It is using $_POST. I've got a few other pages and commands working before I tried this tricky one and they've all used post. And since I'm getting data back from post it's clearly set. @Mike: I mean that it doesn't seem to have any char associated with that binary combination. I've added an example in the main post. I'm not using === or ==, I'm breaking the answer down into binary and visually making sure it's the same. How would I get started on base64 encode/decode? – Califer Jan 15 '16 at 04:47
  • @Califer See http://stackoverflow.com/questions/11743160/how-do-i-encode-and-decode-a-base64-string for C# and for PHP you would do `base64_decode($_POST['leveldata'])`. – Mike Jan 15 '16 at 07:36

0 Answers0