public void SendMessage(string serializedMessage)
        {
            try
            {
                BesiegedMessage message = serializedMessage.FromXml<BesiegedMessage>();
                if (message is GenericServerMessage && (message as GenericServerMessage).MessageEnum == ServerMessage.ServerMessageEnum.StartServer)
                {
                    m_ServerCallback = OperationContext.Current.GetCallbackChannel<IClient>();
                    GenericServerMessage started = new GenericServerMessage() { MessageEnum = ServerMessage.ServerMessageEnum.ServerStarted };
                    m_ServerCallback.SendMessage(started.ToXml());
                    m_IsServerInitialized.Value = true;
                    //StartProcessingMessages();
                    ProcessMessages();
                }
                else if (message is ConnectMessage)
                {
                    IClient callback = OperationContext.Current.GetCallbackChannel<IClient>();
                    string clientId = Guid.NewGuid().ToString();
                    ConnectedClient connectedClient = new ConnectedClient((message as ConnectMessage).Name, clientId, callback);
                    AggregateMessage aggregate = new AggregateMessage();
                    GenericClientMessage success = new GenericClientMessage() { ClientId = clientId, MessageEnum = ClientMessage.ClientMessageEnum.ConnectSuccessful };
                    aggregate.MessageList.Add(success);

                    if (m_Games.Count > 0)  // notify the client of any pre-existing game instances that they might be able to join
                    {
                        foreach (KeyValuePair<string, BesiegedGameInstance> game in m_Games)
                        {
                            if (!game.Value.IsGameInstanceFull)
                            {
                                string capacity = string.Format("{0}/{1} players", game.Value.Players.Count, game.Value.MaxPlayers);
                                GameInfoMessage gameInfo = new GameInfoMessage(game.Value.GameId, game.Value.Name, capacity, false, game.Value.Password != string.Empty ? true : false);
                                aggregate.MessageList.Add(gameInfo);
                            }
                        }
                    }

                    callback.SendMessage(aggregate.ToXml());
                    ConsoleLogger.Push(string.Format("{0} has joined the server", connectedClient.Name));
                    m_ConnectedClients.GetOrAdd(clientId, connectedClient);     // Add an entry to the global client hook
                }
                else
                {
                    m_MessageQueue.Add(message);
                }
            }
            catch (Exception ex)
            {
                ErrorLogger.Push(ex);
            }
        }
        public void Initialize()
        {
            try
            {
                m_CurrentGameListView = new ListView();
                m_CurrentGameListView.Opacity = 0.75;

                m_GameGridView = new GridView();
                m_GameGridView.AllowsColumnReorder = false;

                m_NameColumn = new GridViewColumn();
                m_NameColumn.DisplayMemberBinding = new Binding("Name");
                m_NameColumn.Header = "Game Name";
                m_GameGridView.Columns.Add(m_NameColumn);

                m_CapacityColumn = new GridViewColumn();
                m_CapacityColumn.DisplayMemberBinding = new Binding("Capacity");
                m_CapacityColumn.Header = "Capacity";
                m_GameGridView.Columns.Add(m_CapacityColumn);

                m_CurrentGameListView.View = m_GameGridView;
                m_CurrentGameListView.ItemsSource = ClientGameEngine.Get().GamesCollection;

                m_CurrentGameListView.SelectionChanged += (s, e) =>
                {
                    m_SelectedGame = ((ListView)s).SelectedItem as GameInfoMessage;
                };

                double aspectRatio = Math.Round((double)ClientGameEngine.Get().ClientDimensions.Width / (double)ClientGameEngine.Get().ClientDimensions.Height, 2, MidpointRounding.AwayFromZero);
                string UIComponentPath = "resources\\UI\\Menu\\MultiplayerMenu\\";
                string ratioPath = string.Empty;

                if (aspectRatio == 1.33)
                {
                    //4:3
                    ratioPath = "4x3\\";
                }
                else
                {
                    //16:9
                    ratioPath = "16x9\\";
                }

                BitmapImage bitmapImage = new BitmapImage();
                bitmapImage = new BitmapImage(new Uri(UIComponentPath + ratioPath + "Background.png", UriKind.RelativeOrAbsolute));
                m_BackgroundBrush = new ImageBrush(bitmapImage);

                bitmapImage = new BitmapImage(new Uri(UIComponentPath + "JoinGame.png", UriKind.RelativeOrAbsolute));
                m_JoinGameImage = new Image();
                m_JoinGameImage.Source = bitmapImage;
                m_JoinGameImage.Width = bitmapImage.PixelWidth;
                m_JoinGameImage.Height = bitmapImage.PixelHeight;
                m_JoinGameImage.Name = "JoinGame";
                m_JoinGameImage.MouseEnter += MenuOptionHover;
                m_JoinGameImage.MouseLeave += MenuOptionHoverLost;
                m_JoinGameImage.MouseDown += MenuOptionMouseDown;
                m_JoinGameImage.MouseUp += MenuOptionMouseUp;

                bitmapImage = new BitmapImage(new Uri(UIComponentPath + "CreateGame.png", UriKind.RelativeOrAbsolute));
                m_CreateGameImage = new Image();
                m_CreateGameImage.Source = bitmapImage;
                m_CreateGameImage.Width = bitmapImage.PixelWidth;
                m_CreateGameImage.Height = bitmapImage.PixelHeight;
                m_CreateGameImage.Name = "CreateGame";
                m_CreateGameImage.MouseEnter += MenuOptionHover;
                m_CreateGameImage.MouseLeave += MenuOptionHoverLost;
                m_CreateGameImage.MouseDown += MenuOptionMouseDown;
                m_CreateGameImage.MouseUp += MenuOptionMouseUp;

                bitmapImage = new BitmapImage(new Uri(UIComponentPath + "MainMenu.png", UriKind.RelativeOrAbsolute));
                m_MainMenuImage = new Image();
                m_MainMenuImage.Source = bitmapImage;
                m_MainMenuImage.Width = bitmapImage.PixelWidth;
                m_MainMenuImage.Height = bitmapImage.PixelHeight;
                m_MainMenuImage.Name = "MainMenu";
                m_MainMenuImage.MouseEnter += MenuOptionHover;
                m_MainMenuImage.MouseLeave += MenuOptionHoverLost;
                m_MainMenuImage.MouseDown += MenuOptionMouseDown;
                m_MainMenuImage.MouseUp += MenuOptionMouseUp;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
 public void SendUpdatedGameInfo()
 {
     string capacity = string.Format("{0}/{1} players", Players.Count, MaxPlayers);
     GameInfoMessage gameInfo = new GameInfoMessage(GameId, Name, capacity, false, Password != string.Empty ? true : false);
     BesiegedServer.NotifyAllConnectedClients(gameInfo.ToXml());
 }