Exemplo n.º 1
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);
        }