Example #1
0
        private bool CheckForTMXInfoCommand(PlayerChatEventArgs e)
        {
            ServerCommand command = ServerCommand.Parse(e.Text);

            if (command.Is(Command.TMXInfo))
            {
                if (command.PartsWithoutMainCommand.Count > 0)
                {
                    string  trackID = command.PartsWithoutMainCommand[0];
                    TMXInfo tmxInfo = TMXInfo.Retrieve(trackID);

                    if (tmxInfo != null && !tmxInfo.Erroneous)
                    {
                        SendFormattedMessageToLogin(e.Login, "{[#ServerStyle]}> {[#MessageStyle]}[TMX-Info] Name: {[#HighlightStyle]}{[Name]}{[#MessageStyle]}, Author: {[#HighlightStyle]}{[Author]}{[#MessageStyle]}, Environment: {[#HighlightStyle]}{[Env]}", "Name", tmxInfo.Name, "Author", tmxInfo.Author, "Env", tmxInfo.Environment);
                    }
                    else
                    {
                        SendFormattedMessageToLogin(e.Login, "{[#ServerStyle]}> {[#ErrorStyle]}Could not retrieve trackinfo for trackid " + trackID);
                    }
                }

                return(true);
            }

            return(false);
        }
Example #2
0
        public static TMXInfo Parse(string input)
        {
            if (input.IsNullOrTimmedEmpty())
            {
                return(null);
            }

            string[] parts = input.Split(new [] { '\t' }, StringSplitOptions.RemoveEmptyEntries);

            if (parts.Length < 16)
            {
                return new TMXInfo {
                           ErrorMessage = input
                }
            }
            ;

            TMXInfo result = new TMXInfo
            {
                ID             = parts[0],
                Name           = parts[1],
                UserID         = parts[2],
                Author         = parts[3],
                Uploaded       = parts[4],
                Updated        = parts[5],
                Visible        = parts[6].Equals("true", StringComparison.InvariantCultureIgnoreCase),
                Type           = parts[7],
                Environment    = parts[8],
                Mood           = parts[9],
                Style          = parts[10],
                Routes         = parts[11],
                Length         = parts[12],
                DifficultLevel = parts[13],
                LBRating       = parts[14],
                Game           = parts[15]
            };

            if (parts.Length > 16)
            {
                result.Description = parts[16];
            }

            return(result);
        }
Example #3
0
        private bool CheckForTMXAddTrackCommand(PlayerChatEventArgs e)
        {
            ServerCommand command = ServerCommand.Parse(e.Text);

            if (!command.IsAny(Command.AddTrack, Command.InsertTrack))
            {
                return(false);
            }

            if (!LoginHasRight(e.Login, true, Command.AddTrack))
            {
                return(true);
            }

            if (command.PartsWithoutMainCommand.Count == 0)
            {
                return(true);
            }

            string  trackID = command.PartsWithoutMainCommand[0];
            TMXInfo tmxInfo = TMXInfo.Retrieve(trackID);

            if (tmxInfo == null || tmxInfo.Erroneous)
            {
                SendFormattedMessageToLogin(e.Login, "{[#ServerStyle]}> {[#ErrorStyle]}Could not retrieve trackinfo for trackid " + trackID);
                return(true);
            }

            List <ChallengeListSingleInfo> challenges = GetChallengeList();

            if (challenges == null)
            {
                SendFormattedMessageToLogin(e.Login, "{[#ServerStyle]}> {[#ErrorStyle]}Could not retrieve current challenge list.");
                return(true);
            }

            if (challenges.Exists(c => c.FileName.Equals(tmxInfo.GetRelativeFilePath(), StringComparison.InvariantCultureIgnoreCase)))
            {
                SendFormattedMessageToLogin(e.Login, "{[#ServerStyle]}> {[#MessageStyle]}Track is already in tracklist.");
                return(true);
            }

            byte[] trackData = TMXInfo.DownloadTrack(trackID);

            if (trackData == null)
            {
                SendFormattedMessageToLogin(e.Login, "{[#ServerStyle]}> {[#ErrorStyle]}Could not retrieve track {[#HighlightStyle]}{[Trackname]}{[#ErrorStyle]} with trackid {[#HighlightStyle]}{[TrackID]}.", "Trackname", tmxInfo.Name, "TrackID", trackID);
                return(true);
            }

            string targetTrackFilePath = tmxInfo.GetRelativeFilePath();

            GenericResponse <bool> writeFileResponse = Context.RPCClient.Methods.WriteFile(targetTrackFilePath, trackData);

            if (writeFileResponse.Erroneous || !writeFileResponse.Value)
            {
                SendFormattedMessageToLogin(e.Login, "{[#ServerStyle]}>{[#ErrorStyle] Could write track {[#HighlightStyle]}{[Trackname]}{[#ErrorStyle]} with trackid {[#HighlightStyle]}{[TrackID]}.", "Trackname", tmxInfo.Name, "TrackID", trackID);
                return(true);
            }

            GenericResponse <bool> addtrackResponse = command.Is(Command.AddTrack) ? Context.RPCClient.Methods.AddChallenge(targetTrackFilePath)
                                                                                  : Context.RPCClient.Methods.InsertChallenge(targetTrackFilePath);

            if (addtrackResponse.Erroneous || !addtrackResponse.Value)
            {
                SendFormattedMessageToLogin(e.Login, "{[#ServerStyle]}>{[#ErrorStyle] Could add track {[#HighlightStyle]}{[Trackname]}{[#ErrorStyle]} with trackid {[#HighlightStyle]}{[TrackID]}.", "Trackname", tmxInfo.Name, "TrackID", trackID);
                return(true);
            }

            SendFormattedMessageToLogin(e.Login, "{[#ServerStyle]}> {[#MessageStyle]}Track {[#HighlightStyle]}{[Trackname]}{[#MessageStyle]} with trackid {[#HighlightStyle]}{[TrackID]}{[#MessageStyle]} added to tracklist.", "Trackname", tmxInfo.Name, "TrackID", trackID);

            if (command.Is(Command.InsertTrack))
            {
                SendFormattedMessageToLogin(e.Login, "{[#ServerStyle]}> {[#MessageStyle]}Track {[#HighlightStyle]}{[Trackname]}{[#MessageStyle]} with trackid {[#HighlightStyle]}{[TrackID]}{[#MessageStyle]} will be the next track.", "Trackname", tmxInfo.Name, "TrackID", trackID);
            }

            return(true);
        }