27. April 2008 by Mads

Today when I looked at my blog, I saw a blog post telling that the site was hacked!

The entry is now removed and passwords are changed. Let's hope it doesn't happen again! And if anybody out there has a "BlogEngine.NET" blog system, keep an eye on it.

If you use version 1.3.0.0 of BlogEngine get the patch to fix the security issue from here.

6. April 2008 by Mads

NOTE: I'm so sorry I don't have a code parser on my blog at the moment. This means that the code doesn't look very good. I'm working on an codeparser, but just can't find a working one at the moment. So I desided to do the post, and then clean up the source code in it later. 

In a comment to my blog post about PopTheBubble on silverlight.ne, Jason Schluter asked me for the code to the hi-score in the game. So here goes.

The hi-score actually works pretty simple. The game has a Service reference to a WebService, which lives on the web server ofcause (remember the game lives in the users browser). When the Hi-score UserControl is loaded in the Silverlight application (the game), calls a method called "GetScore" to retrieve the top-50 scores/players. When you type in your name and click submit, another method is called on the WebService to save your score. The score is persisted in an xml file on the server.

HiScore.xaml:

    public partial class HiScore : UserControl
    {
        private int score;
        private ServiceReference1.BubbleHiScoreSoapClient scoreClient;

        public HiScore()
        {
            InitializeComponent();
            score = 0;

            //Hook up with WebService
            scoreClient = new PopTheBubble.ServiceReference1.BubbleHiScoreSoapClient();
            scoreClient.GetScoresCompleted += new EventHandler<PopTheBubble.ServiceReference1.GetScoresCompletedEventArgs>(scoreClient_GetScoresCompleted);
            scoreClient.SaveScoreCompleted += new EventHandler<System.ComponentModel.AsyncCompletedEventArgs>(scoreClient_SaveScoreCompleted);
        }

        public void UpdateScore()
        {
            scoreClient.GetScoresAsync();
        }


        public int Score
        {
            get { return this.score; }
            set
            {
                hiScoreTextBlock.Text = "Your score: " + value;
                this.score = value;
            }
        }

        protected void scoreClient_SaveScoreCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
        {
            UpdateScore();
        }

        protected void scoreClient_GetScoresCompleted(object sender, PopTheBubble.ServiceReference1.GetScoresCompletedEventArgs e)
        {
            hiscoreDataGrid.ItemsSource = e.Result;
        }

        private void submitScoreButton_Click(object sender, RoutedEventArgs e)
        {
            if (!playerNameTextbox.Text.ToLower().Equals("type your name...") && playerNameTextbox.Text != "")
                scoreClient.SaveScoreAsync(playerNameTextbox.Text, score);
        }
    }

 

HiScore.asmx 

        [WebMethod]
        public void SaveScore(string name, int score)
        {
           //Saves the score into a xml file. Original code has been removed.
        }

        [WebMethod]
        public List<HiScoreEntry> GetScores()
        {
            //Get the top-50 hiscores from the xml file. Original code has been removed.
        }

As you can see it's pretty simple, but not very secure. You don't need to be a state-of-the-art hacker to figure out how to cheat here, but this was not my focus with this game. The code in the WebService is just normal C# code reading/writing from an xml file. Please post a comment if you have any questions.

2. April 2008 by Mads

UPDATE: Please note that there is a new release of this for Silverlight Beta 2: Check it out here.

When you are doing game development you sometimes wants to spice up the game with some physics. To do this from scratch, you need to be pretty good at math and have a lot of spare time. Lucky for us Silverlight Game Developers, Jeff Weber from Farseer Games, created a little engine to help us out. It's called the Farseer Physics Engine.

Currently the latest release is 1.0.0.5 which supports Silverlight 2 beta 1. This is the release used in this sample.

Getting started 

I am new to the Farseer engine myself, and have been looking on the internet for a, "Getting started with Farseer" tutorial, with out any luck. Therefore I desided to create my own. The release of the engine comes with some pretty nice demos, that shows you how to use the engine. The only problem is, that the code is pretty complex at first sight, which could make some people give up. 

Therefore I have created this tiny project to show you how to make the engine run in the simplest form possible. The code should be pretty self-explaining. If you want to know alittle more about why the diffent things are done, you can read on Andy Beaulieu blog, which has a starting tutorial too. The only problem is thats it's for Silverlight 1.1 Alpha and therefore alittle outdated, but the basic things are the same as far as I can see. 

(As I said, I'm new to the engine also, so this can maybe be done even more simpler. If you  have some changes, please let me know. You can use the "Contact" here on the page and send me and email through that. Thanks in advance.)

You can download the source here.
And you can see the it running in your browser here. 

I hope you have a better idea of how to get the engine to work after looking through the source code.

Happy coding! 

Please note: The Silverlight 2 beta 1 currectly have a "region bug" when you position the elements. If you are running with US region settings, there should be no problem, but if you, like me, run with Danish Region settings, this sample will crash at first sight. So to be able to see/run this, you need to set your region settings to English (United States). This works for me.