Exemplo n.º 1
0
 def getTrustFinal(self):
     clearance = Clearance(self.getClearance())
     if self.status == self.STATUS_REPORTED:
         if self.correct:
             return clearance.getTrustReportedCorrect()
         else:
             return clearance.getTrustReportedIncorrect()
     elif self.status == self.STATUS_REVOKED:
         return clearance.getTrustRevoked()
     else:
         return 0
Exemplo n.º 2
0
def check_mail(mail):
        if mail.requisitionInstance is not None and mail.requisitionInstance.blank.requisition.category == Requisition.CATEGORY_HELP:
            subject = "[MoP] %s: Help Request (Cron: %s)" % (mail.mop.user.username, mail.mop.cron.user.username)
            create_player_email(mail, subject)
            return
        elif mail.requisitionInstance is not None and mail.requisitionInstance.blank.requisition.category == Requisition.CATEGORY_SPECIAL_REPORT:
            subject = "[MoP] %s: MOPAIN Report (Cron: %s)" % (mail.mop.user.username, mail.mop.cron.user.username)
            create_player_email(mail, subject)
            return    
        else:    
            newMail = prepareMail(mail)    
            if mail.requisitionInstance is not None and mail.requisitionInstance.blank.requisition.category == Requisition.CATEGORY_SPECIAL_APPLY:
                if not delayedEnough(mail, DELAY_SUPERLONG):
                    return
                #deny because already
                if mail.mop.mopTracker.specialStatusAllowed:
                    newMail.subject = Mail.SUBJECT_SPECIAL_DENIED
                    newMail.bodyType = Mail.BODY_SPECIAL_ALREADY
                    newMail.trust = -100
                else:
                    #deny because shit
                    if not check_special_hack(mail.requisitionInstance.data) or not mail.mop.mopTracker.clearance >= Clearance.CLEARANCE_RED:
                        newMail.subject = Mail.SUBJECT_SPECIAL_DENIED
                        newMail.bodyType = Mail.BODY_SPECIAL_DENIED
                        newMail.trust = -250
                    #grant
                    else:
                        newMail.subject = Mail.SUBJECT_SPECIAL_GRANTED
                        newMail.bodyType = Mail.BODY_SPECIAL_GRANTED
                        newMail.trust = 500
                        mail.mop.mopTracker.specialStatusAllowed = True
                        mail.mop.mopTracker.save()
            
            elif mail.unit == None:
                if not delayedEnough(mail, DELAY_SHORT):
                    return
                newMail.subject = Mail.SUBJECT_ERROR
                newMail.bodyType = Mail.BODY_ERROR_MISSING_UNIT
                #if there is no unit an error is generated automatically - no need to set it manually
            elif mail.subject == Mail.SUBJECT_EMPTY:
                if not delayedEnough(mail, DELAY_SHORT):
                    return
                newMail.subject = Mail.SUBJECT_ERROR
                newMail.bodyType = Mail.BODY_ERROR_NO_SUBJECT
            elif mail.requisitionInstance == None:
                if not delayedEnough(mail, DELAY_SHORT):
                    return
                newMail.subject = Mail.SUBJECT_ERROR
                newMail.bodyType = Mail.BODY_ERROR_MISSING_FORM
            elif not mail.unit == mail.requisitionInstance.blank.requisition.unit:
                if not delayedEnough(mail, DELAY_SHORT):
                    return
                newMail.subject = Mail.SUBJECT_ERROR
                newMail.bodyType = Mail.BODY_ERROR_WRONG_UNIT
            elif not (subjectMatchesRequisition(mail)):
                newMail.subject = Mail.SUBJECT_ERROR
                newMail.bodyType = Mail.BODY_ERROR_WRONG_FORM
            elif redundantDocument(mail):
                if not delayedEnough(mail, DELAY_SHORT):
                    return
                newMail.subject = Mail.SUBJECT_ERROR
                newMail.bodyType = Mail.BODY_ERROR_REDUNDANT_DOCUMENT
            elif missingDocument(mail):
                if not delayedEnough(mail, DELAY_SHORT):
                    return
                newMail.subject = Mail.SUBJECT_ERROR
                newMail.bodyType = Mail.BODY_ERROR_MISSING_DOCUMENT
            elif wrongDocument(mail):
                if not delayedEnough(mail, DELAY_SHORT):
                    return
                newMail.subject = Mail.SUBJECT_ERROR
                newMail.bodyType = Mail.BODY_ERROR_WRONG_DOCUMENT
            #Now the mail should be formally correct
            #Let's see about the content!
            elif mail.subject == Mail.SUBJECT_REQUEST_FORM:
                requisition = getRequisition(mail)
                if requisition == None:
                    if not delayedEnough(mail, DELAY_SHORT):
                        return
                    newMail.subject = Mail.SUBJECT_ERROR
                    newMail.bodyType = Mail.BODY_ERROR_UNFOUND_FORM
                elif requisitionBlankExists(mail.mop, requisition):
                    if not delayedEnough(mail, DELAY_SHORT):
                        return
                    newMail.subject = Mail.SUBJECT_ERROR
                    newMail.bodyType = Mail.BODY_ERROR_EXISTING_FORM
                else:
                    if not delayedEnough(mail, DELAY_MEDIUM):
                        return
                    requisitionBlank = assignRequisition(mail.mop, requisition)
                    newMail.requisitionBlank = requisitionBlank
                    newMail.subject = Mail.SUBJECT_RECEIVE_FORM
                    newMail.bodyType = Mail.BODY_ASSIGNING_FORM
            elif mail.subject == Mail.SUBJECT_REQUEST_DOCUMENT:
                #The serial inside the form could be either for a mop or for a cron 'document'
                cronDocument = getCronDocument(mail)
                randomizedDocument = getRandomizedDocument(mail)
                if cronDocument == None and randomizedDocument == None:
                    if not delayedEnough(mail, DELAY_SHORT):
                        return
                    newMail.subject = Mail.SUBJECT_ERROR
                    newMail.bodyType = Mail.BODY_ERROR_UNFOUND_DOCUMENT
                elif mopDocumentInstanceExists(mail.mop, cronDocument, randomizedDocument):
                    if not delayedEnough(mail, DELAY_SHORT):
                        return
                    #TODO what if document is used?
                    newMail.subject = Mail.SUBJECT_ERROR
                    newMail.bodyType = Mail.BODY_ERROR_EXISTING_DOCUMENT
                elif not hasEnoughTrust(mail.mop, cronDocument, randomizedDocument):
                    if not delayedEnough(mail, DELAY_SHORT):
                        return
                    newMail.subject = Mail.SUBJECT_ERROR
                    newMail.bodyType = Mail.BODY_ERROR_LACKING_TRUST
                else:
                    if not delayedEnough(mail, DELAY_MEDIUM):
                        return
                    mopDocumentInstance = assignDocument(mail.mop, cronDocument, randomizedDocument)
                    newMail.mopDocumentInstance = mopDocumentInstance
                    clearance = Clearance(mopDocumentInstance.getClearance())
                    newMail.trust = clearance.getTrustRequested()
                    newMail.subject = Mail.SUBJECT_RECEIVE_DOCUMENT
                    newMail.bodyType = Mail.BODY_ASSIGNING_DOCUMENT
            elif mail.subject == Mail.SUBJECT_SUBMIT_DOCUMENT:
                clearance = Clearance(mail.mopDocumentInstance.getClearance())
                newMail.subject = Mail.SUBJECT_REPORT_EVALUATION
                newMail.mopDocumentInstance = mail.mopDocumentInstance
                if mail.mopDocumentInstance.correct:
                    if not delayedEnough(mail, DELAY_LONG):
                        return
                    newMail.bodyType = Mail.BODY_REPORT_SUCCESS
                    newMail.trust = clearance.getTrustReportedCorrect()
                    tutorial.submitDocument(mail.mop.mopTracker)
                else:
                    if not delayedEnough(mail, DELAY_LONG):
                        return
                    newMail.bodyType = Mail.BODY_REPORT_FAIL
                    newMail.trust = clearance.getTrustReportedIncorrect()
                mail.mopDocumentInstance.status = MopDocumentInstance.STATUS_REPORTED
                mail.mopDocumentInstance.save()
            else:
                if not delayedEnough(mail, DELAY_SHORT):
                    return
                newMail.subject = Mail.SUBJECT_UNCAUGHT_CASE
                newMail.body = Mail.BODY_UNCAUGHT_CASE
                
    
            if newMail.subject == Mail.SUBJECT_ERROR:
                newMail.trust = -1
                
                if not mail.mopDocumentInstance == None:
                    mail.mopDocumentInstance.status = MopDocumentInstance.STATUS_ACTIVE
                    mail.mopDocumentInstance.save()
                    newMail.mopDocumentInstance = mail.mopDocumentInstance
               
    
            mail.processed = True
            mail.save()
            newMail.save()
            
            if newMail.trust is not None:
                forTotal = True
                if newMail.subject == Mail.SUBJECT_RECEIVE_DOCUMENT:
                    forTotal = False
                mail.mop.mopTracker.addTrust(newMail.trust, forTotal)
                
            if newMail.subject == Mail.SUBJECT_ERROR:
                logging.log_action(ActionLog.ACTION_MOP_RECEIVE_MAIL_ERROR, mop=mail.mop, mail=newMail)
            elif newMail.subject == Mail.SUBJECT_RECEIVE_DOCUMENT:
                logging.log_action(ActionLog.ACTION_MOP_RECEIVE_MAIL_DOCUMENT, mop=mail.mop, mail=newMail)
            elif newMail.subject == Mail.SUBJECT_RECEIVE_FORM:
                logging.log_action(ActionLog.ACTION_MOP_RECEIVE_MAIL_FORM, mop=mail.mop, mail=newMail)
            elif newMail.subject == Mail.SUBJECT_REPORT_EVALUATION:
                logging.log_action(ActionLog.ACTION_MOP_RECEIVE_MAIL_REPORT, mop=mail.mop, mail=newMail)
            elif newMail.subject == Mail.SUBJECT_SPECIAL_DENIED:
                logging.log_action(ActionLog.ACTION_MOP_RECEIVE_MAIL_SPECIAL_DENIED, mop=mail.mop, mail=newMail)
            elif newMail.subject == Mail.SUBJECT_SPECIAL_GRANTED:
                logging.log_action(ActionLog.ACTION_MOP_RECEIVE_MAIL_SPECIAL_GRANTED, mop=mail.mop, mail=newMail)
Exemplo n.º 3
0
 def getTrustRequested(self):
     clearance = Clearance(self.getClearance())
     return clearance.getTrustRequested()