示例#1
0
        /// <summary>
        /// Parses LoginSuccess instructions for users
        /// and adds them to the UserList
        /// </summary>
        /// <param name="content">Byte array containing
        /// all recieved buffer</param>
        /// <param name="users">Userlist to add to</param>
        /// returns index of beginning of gamelist
        /// <param name="games">Game list to add
        /// games to</param>
        /// <param name="currindex">index of buffer to
        /// begin parsing</param>
        public static void parseUsersGames(byte[] content, ref UserList users, ref GameList games, int currindex)
        {
            currindex += 2;
            int numUsers = BitConverter.ToInt32(content, currindex);

            currindex += 4;
            int numGames = BitConverter.ToInt32(content, currindex);

            currindex += 4;

            //Parse the users
            for (int i = 0; i < numUsers; i++)
            {
                User          user    = new User();
                StringBuilder usrName = new StringBuilder();
                while (content[currindex] != 0)
                {
                    usrName.Append((char)content[currindex++]);
                }
                user.Name = usrName.ToString();
                currindex++;
                user.ping   = BitConverter.ToInt32(content, currindex);
                currindex  += 4;
                user.status = content[currindex];
                currindex++;
                user.id         = BitConverter.ToInt16(content, currindex);
                currindex      += 2;
                user.connection = content[currindex++];
                user.assignCategory();
                users.AddUser(user);
            }

            //Now for the games
            for (int i = 0; i < numGames; i++)
            {
                Game          game     = new Game();
                StringBuilder gamename = new StringBuilder();
                while (content[currindex] != 0)
                {
                    gamename.Append((char)content[currindex++]);
                }
                game.name = gamename.ToString();
                currindex++;
                game.id    = BitConverter.ToInt32(content, currindex);
                currindex += 4;
                StringBuilder emuName = new StringBuilder();
                while (content[currindex] != 0)
                {
                    emuName.Append((char)content[currindex++]);
                }
                game.emuName = emuName.ToString();
                currindex++;
                StringBuilder hostUser = new StringBuilder();

                while (content[currindex] != 0)
                {
                    hostUser.Append((char)content[currindex++]);
                }


                game.gameHost = hostUser.ToString();
                currindex++;

                StringBuilder usersStr = new StringBuilder();

                while (content[currindex] != 0)
                {
                    usersStr.Append((char)content[currindex++]);
                }

                //Note property setter also sets game users and max users
                game.Users_count = usersStr.ToString();

                game.status = content[++currindex];
                games.AddGame(game);
                currindex++;
            }
        }
示例#2
0
        /// <summary>
        /// Parses LoginSuccess instructions for users
        /// and adds them to the UserList
        /// </summary>
        /// <param name="content">Byte array containing
        /// all recieved buffer</param>
        /// <param name="users">Userlist to add to</param>
        /// returns index of beginning of gamelist
        /// <param name="games">Game list to add 
        /// games to</param>
        /// <param name="currindex">index of buffer to
        /// begin parsing</param>
        public static void parseUsersGames(byte[] content, ref UserList users, ref GameList games, int currindex)
        {

            currindex += 2;      
            int numUsers = BitConverter.ToInt32(content, currindex);
            currindex += 4;
            int numGames = BitConverter.ToInt32(content, currindex);
            currindex += 4;

            //Parse the users
            for (int i = 0; i < numUsers; i++)
            {
                User user = new User();
                StringBuilder usrName = new StringBuilder();
                while (content[currindex] != 0)
                {
                    usrName.Append((char)content[currindex++]);
                }
                user.Name = usrName.ToString();
                currindex++;
                user.ping = BitConverter.ToInt32(content, currindex);
                currindex += 4;
                user.status = content[currindex];
                currindex++;
                user.id = BitConverter.ToInt16(content, currindex);
                currindex += 2;
                user.connection = content[currindex++];
                user.assignCategory();
                users.AddUser(user);
            }

            //Now for the games
            for (int i = 0; i < numGames; i++)
            {
                Game game = new Game();
                StringBuilder gamename = new StringBuilder();
                while (content[currindex] != 0)
                {
                    gamename.Append((char)content[currindex++]);
                }
                game.name = gamename.ToString();
                currindex++;
                game.id = BitConverter.ToInt32(content, currindex);
                currindex += 4;
                StringBuilder emuName = new StringBuilder();
                while (content[currindex] != 0)
                {
                    emuName.Append((char)content[currindex++]);
                }
                game.emuName = emuName.ToString();
                currindex++;
                StringBuilder hostUser = new StringBuilder();
                
                while (content[currindex] != 0)
                {
                    hostUser.Append((char)content[currindex++]);
                }


                game.gameHost = hostUser.ToString();
                currindex++;

                StringBuilder usersStr = new StringBuilder();

                while (content[currindex] != 0)
                {
                    usersStr.Append((char)content[currindex++]);
                }

                //Note property setter also sets game users and max users
                game.Users_count = usersStr.ToString();

                game.status = content[++currindex];
                games.AddGame(game);
                currindex++;

            }
        }
        /// <summary>
        /// Attempts to add the game, returns errors if there are any.
        /// </summary>
        /// <returns>Returns Constants.AddGameErrors enum, depicting what error occured, if any.</returns>
        public Constants.AddGameErrors AddGame()
        {
            // Checks if any of the variables are either null or empty, and returns with an error if they are.
            if (Name.IsNullOrEmpty())
            {
                return(Constants.AddGameErrors.NameInvalid);
            }
            else if (Categories.IsNullOrEmpty())
            {
                return(Constants.AddGameErrors.CategoriesInvalid);
            }
            else if (Price.IsNullOrEmpty())
            {
                return(Constants.AddGameErrors.PriceInvalid);
            }
            else if (Description.IsNullOrEmpty())
            {
                return(Constants.AddGameErrors.DescriptionInvalid);
            }

            // Parses the price string to a float.
            float _price = float.Parse(Price, System.Globalization.CultureInfo.InvariantCulture);

            // Creates a list of categories, and splits the Categories string into it.
            List <String> _categories = new List <string>();

            _categories = Categories.Split(",").ToList();
            List <CarrouselItem> _carrouselItems = new List <CarrouselItem>();

            // Creates and adds CarrouselItems to the list above, depending on what type of CarrouselItem it is.
            foreach (StorageFile file in CarrouselImages)
            {
                _carrouselItems.Add(new CarrouselItem(Constants.CarrouselItemType.Image, file.Path));
            }
            foreach (StorageFile file in CarrouselVideos)
            {
                _carrouselItems.Add(new CarrouselItem(Constants.CarrouselItemType.Video, file.Path));
            }
            foreach (ListviewString item in CarrouselYoutubeVids)
            {
                _carrouselItems.Add(new CarrouselItem(Constants.CarrouselItemType.YoutubeVideo, item.Value));
            }

            // Checks the price, and returns an error depending on whether or not it is valid.
            if (_price.ToString().Length == 0 || _price < 1 || _price > 1000)
            {
                return(Constants.AddGameErrors.PriceInvalid);
            }

            // Creates a new game with all the information.
            Game newGame = new Game(AccountHandler.Account, ThumbnailImagePath, Name, _price, 0, Description, "", _categories, _carrouselItems, _releaseDate);

            // Checks if the identifier for the game is identical to any game already in the list. Return with error if it does.
            foreach (Game game in _gameList.StoreGameCollection)
            {
                if (game.Identifier == newGame.Identifier)
                {
                    return(Constants.AddGameErrors.GameExists);
                }
            }

            // Adds the newly created game to the gamelist.
            _gameList.AddGame(newGame);

            // Returns with no errors.
            return(Constants.AddGameErrors.NoError);
        }