Example #1
0
        public override bool Equals(object obj)
        {
            Hack other = obj as Hack;

            if (other == null)
            {
                return(false);
            }
            return(other.ID == this.ID);
        }
Example #2
0
 public TaskFeedback_Hack Hack(Problem problem, Record record, Hack hack)
 {
     if (!Authenticated) throw new FaultException<AccessDeniedError>(new AccessDeniedError());
     return Env.Run(new Task
     {
         Problem = problem,
         Record = record,
         Hack = hack,
         Type = TaskType.Hack
     }, Callback) as TaskFeedback_Hack;
 }
Example #3
0
        public int HackRecord(int recordID, string dataOrDatamaker, ProgrammingLanguage? datamakerLanguage)
        {
            using (DB db = new DB())
            {
                CheckRole(db, UserRole.Competitor);

                Record record = db.Records.Find(recordID);
                if (record == null) throw new FaultException<NotFoundError>(new NotFoundError { ID = recordID, Type = "Record" });

                if (record.Status != RecordStatus.Accepted)
                    throw new FaultException<InvalidOperationError>(new InvalidOperationError(), "Only accepted records can be hacked");

                Contest contest = record.Problem.Contest;
                Problem problem = record.Problem;

                if (contest.StartTime > DateTime.Now)
                    throw new FaultException<InvalidOperationError>(new InvalidOperationError(), "Contest not started");
                if (contest.EndTime < DateTime.Now)
                    throw new FaultException<InvalidOperationError>(new InvalidOperationError(), "Contest has finished");

                if (contest.Type == ContestType.Codeforces)
                {
                    if (!problem.LockedUsers.Contains(CurrentUser))
                        throw new FaultException<InvalidOperationError>(new InvalidOperationError(), "Please lock the problem first");
                }
                else if (contest.Type == ContestType.TopCoder)
                {
                    if (contest.HackStartTime > DateTime.Now)
                        throw new FaultException<InvalidOperationError>(new InvalidOperationError(), "Hack before hackStartTime");
                }
                else
                    throw new FaultException<InvalidOperationError>(new InvalidOperationError(), "This contest does not support hacking.");

                Hack hack = new Hack
                {
                    DatamakerLanguage = datamakerLanguage,
                    DataOrDatamaker = dataOrDatamaker,
                    HackerID = CurrentUser.ID,
                    RecordID = record.ID,
                    Status = HackStatus.Pending,
                    Time = DateTime.Now
                };

                db.Hacks.Add(hack);
                db.SaveChanges();

                if (NewHack != null)
                    System.Threading.Tasks.Task.Factory.StartNew(() => NewHack(hack.ID));
                return hack.ID;
            }
        }
Example #4
0
        private void DoJudgeHack(int hackID)
        {
            using (DB db = new DB())
            {
                Contest contest;
                Problem problem;
                Record record;
                Hack hack;

                var h = db.Hacks.Find(hackID);
                if (h == null) return;

                if (h.Status != HackStatus.Pending) return;
                h.Status = Entity.HackStatus.Running;
                db.SaveChanges();

                hack = new Hack
                {
                    ID = h.ID,
                    DatamakerLanguage = h.DatamakerLanguage,
                    DataOrDatamaker = h.DataOrDatamaker,
                    HackeeID = h.Record.UserID,
                    HackeeNickName = h.Record.User.NickName,
                    HackerID = h.HackerID,
                    HackerNickName = h.Hacker.NickName,
                    RecordID = h.RecordID,
                    Status = HackStatus.Running
                };

                var r = h.Record;
                record = new Record
                {
                    ID = r.ID,
                    Code = r.Code,
                    Language = r.Language,
                    ProblemID = r.ProblemID,
                    ProblemTitle = r.Problem.Title,
                    Status = RecordStatus.Running,
                    SubmissionTime = r.SubmissionTime,
                    UserID = r.UserID,
                    UserNickName = r.UserNickName
                };

                var p = r.Problem;
                problem = new Problem
                {
                    ID = p.ID,
                    ContestID = p.ContestID,
                    ContestTitle = p.Contest.Title,
                    ForbiddenLanguages = p.ForbiddenLanguages,
                    MemoryLimit = p.MemoryLimit,
                    Score = p.Score,
                    Spj = p.Spj,
                    SpjLanguage = p.SpjLanguage,
                    Std = p.Std,
                    StdLanguage = p.StdLanguage,
                    TestCasesCount = p.TestCases.Count,
                    TimeLimit = p.TimeLimit,
                    Title = p.Title,
                    Validator = p.Validator,
                    ValidatorLanguage = p.ValidatorLanguage
                };

                using (var conn = GetFreestNode())
                {
                    var ret = conn.Hack(problem, record, hack);
                    h.Status = ret.HackStatus;

                    if (ret.HackStatus == HackStatus.Success)
                    {
                        h.Record.Status = RecordStatus.Hacked;
                        var inputHash = MD5.Create().ComputeHash(ret.HackData.Input);
                        var outputHash = MD5.Create().ComputeHash(ret.HackData.Output);

                        bool existed = (from t in db.TestCases
                                        where t.ProblemID == p.ID
                                         && t.InputHash == inputHash
                                        select t).Any();
                        if (!existed)
                        {
                            var hackTestCase = new TestCase
                            {
                                Input = ret.HackData.Input,
                                InputHash = inputHash,
                                Output = ret.HackData.Output,
                                OutputHash = outputHash,
                                ProblemID = p.ID,
                                Type = TestCaseType.Systemtest
                            };
                            db.TestCases.Add(hackTestCase);
                            db.SaveChanges();
                            hack.GeneratedTestCaseID = hackTestCase.ID;
                        }
                    }
                    else
                    {
                        h.Detail = ret.CompilerOutput;
                    }
                    db.SaveChanges();
                }
            }
        }