Example #1
0
        public string UpdateMap(string MapName, Map NewMapData, ChatroomEntity User)
        {
            MapValidityCheck       MapCheck    = CheckIfValid(NewMapData);
            UpdateMapValidityCheck Updatecheck = GetMapPositionInList(MapName);
            string ReturnMessage;

            if (MapCheck.IsValid && Updatecheck.MapExistsInList)
            {
                int entry = Updatecheck.MapEntry;

                if (mapList[entry].Submitter.ToString().Equals(User.identifier.ToString()) | User.Rank == ChatroomEntity.AdminStatus.True)
                {
                    mapList[entry].Filename    = NewMapData.Filename ?? mapList[entry].Filename;
                    mapList[entry].DownloadURL = NewMapData.DownloadURL;
                    mapList[entry].Notes       = NewMapData.Notes ?? mapList[entry].Notes;
                    mapList[entry].Uploaded    = NewMapData.Uploaded;

                    ReturnMessage = "Successfully updated the map!";
                }
                else
                {
                    ReturnMessage = "You are either not an admin or this isn't your map!";
                }
            }
            else
            {
                ReturnMessage = MapCheck.ReturnMessage;
            }

            return(ReturnMessage);
        }
Example #2
0
        private MapValidityCheck CheckIfValid(Map map)
        {
            MapValidityCheck ValidityCheck = new MapValidityCheck();

            try
            {
                if (map.Uploaded == true)
                {
                }
                else
                {
                    if (AllowOnlyUploadedMaps)
                    {
                        throw new ArgumentException(ForceMapsToBeUploadedErrorResponse);
                    }

                    if (map.DownloadURL != null & map.DownloadURL.StartsWith("http", StringComparison.OrdinalIgnoreCase))
                    {
                    }
                    else
                    {
                        throw new ArgumentException("Your map isn't uploaded, and doesn't include a URL!");
                    }
                }

                if (string.IsNullOrWhiteSpace(map.Filename))
                {
                    throw new ArgumentException("You must include a filename!");
                }

                if (CheckIfStringIsNumbers(map.Filename))
                {
                    throw new ArgumentException("You must include more than numbers!");
                }
                if (map.Filename.Any(c => char.IsUpper(c)))
                {
                    throw new ArgumentException("It includes an uppercase letter");
                }

                if (map.Filename.Length > 27)
                {
                    throw new ArgumentException("It includes too many characters: " + "27");
                }

                if (mapList.Any(m => m.Filename.Equals(map.Filename)))
                {
                    throw new ArgumentException("Your map has been rejected as it already exists in the map list!");
                }
            }
            catch (ArgumentException ex) { ValidityCheck.SetInvalid(ex.Message); }
            catch (NullReferenceException ex) { throw new ArgumentException("Map isn't uploaded"); }

            return(ValidityCheck);
        }
Example #3
0
        public string AddMap(Map map)
        {
            MapValidityCheck MapCheck = CheckIfValid(map);

            if (MapCheck.IsValid)
            {
                mapList.Add(map);
                return(string.Format("{0} Has been added to the list!", map.Filename));
            }
            else
            {
                return(MapCheck.ReturnMessage);
            }
        }