Exemplo n.º 1
0
def execute():
    for idx, metadata in enumerate(get_all_instances_metadata(), start=1):
        instance_id = metadata["instance_id"]
        backup_game_instance_data(instance_id, comment="nightly_autosave")
        logging.info("Game instance '%s' well autosaved", instance_id)

    logging.info("All %s game instances were well autosaved" % idx)
    return idx
Exemplo n.º 2
0
def execute():

    for idx, metadata in enumerate(get_all_instances_metadata(), start=1):
        
        successes = 0
        errors = 0

        instance_id = metadata["instance_id"]
        
        if metadata["status"] != "active":
            logging.info("Skipping external notifications on obsolete game instance %s", instance_id)
            continue
        
        assert metadata["status"] == "active"
        
        try:
            
            dm = retrieve_game_instance(instance_id)
        
            all_notifications = dm.get_characters_external_notifications()
            master_email = dm.get_global_parameter("master_real_email")
            
            for pack in all_notifications:
                username, real_email = pack["username"], pack["real_email"]
                signal_new_radio_messages, signal_new_text_messages = pack["signal_new_radio_messages"], pack["signal_new_text_messages"]
                
                novelties = ""
                if signal_new_radio_messages:
                    novelties += "- la liste de lecture de la webradio a été mise à jour.\n"
                if signal_new_text_messages:
                    novelties += "- vous avez reçu %s nouveaux messages textuels.\n" % signal_new_text_messages
                
                if not novelties:
                    continue # no news for the player
                   
                assert novelties
                content_dict = dict(username=username,
                                    novelties=novelties)
                message = TEMPLATE % content_dict
                try:
                    send_mail(subject=SUBJECT,
                              message=message,
                              from_email=settings.SERVER_EMAIL,
                              recipient_list=[real_email] + ([master_email] if master_email else []),
                              fail_silently=False)
                except (SMTPException, EnvironmentError), e:
                    logging.error("Couldn't send external notification email to %s", real_email, exc_info=True)
                    errors += 1
                else:
                    logging.info("Properly sent external notification email to %s", real_email)
                    successes += 1
            
        except Exception, e:
            logging.critical("Error during external notifications processing on game instance '%s'", instance_id, exc_info=True)
        else:
            logging.info("Properly notified, by emails, characters from all instances about their novelties.")

        return (idx, successes, errors)
def execute():
    result = True
    for idx, metadata in enumerate(get_all_instances_metadata(), start=1):
        instance_id = metadata["instance_id"]
        dm = retrieve_game_instance(instance_id)
        try:
            dm.check_database_coherence(strict=True)
        except Exception, e:
            result = False
            logging.critical("Error during checking of game instance '%s'", instance_id, exc_info=True)
        else:
            logging.info("Game instance '%s' is OK", instance_id)
def manage_instances(request):

    session_token_display = None
    game_creation_form = None
    require_email = False # superuser does what he wants

    try:
        if request.method == "POST":

            if request.POST.get("create_game_instance"):
                game_creation_form = GameInstanceCreationForm(require_email=require_email, data=request.POST)
                if game_creation_form.is_valid():
                    cleaned_data = game_creation_form.cleaned_data
                    game_instance_id = cleaned_data["game_instance_id"]
                    creator_login = cleaned_data["creator_login"]
                    creator_email = cleaned_data["creator_email"] or None
                    datamanager_administrator.create_game_instance(game_instance_id=game_instance_id,
                                                                     creator_login=creator_login,
                                                                     creator_email=creator_email,
                                                                     skip_randomizations=False)
                    messages.add_message(request, messages.INFO, _(u"Game instance '%(game_instance_id)s' successfully created for '%(creator_login)s/%(creator_email)s'") %
                                                                    SDICT(game_instance_id=game_instance_id, creator_login=creator_login, creator_email=creator_email))
                    game_creation_form = None
                else:
                    messages.add_message(request, messages.ERROR, _(u"Invalid game creation form submitted."))
            elif request.POST.get("lock_instance"):
                game_instance_id = request.POST["lock_instance"]
                maintenance_until = datetime.utcnow() + timedelta(minutes=GAME_INSTANCE_MAINTENANCE_LOCKING_DELAY_MN)
                datamanager_administrator.change_game_instance_status(game_instance_id=game_instance_id, maintenance_until=maintenance_until)
                messages.add_message(request, messages.INFO, _(u"Game instance '%(game_instance_id)s' successfully locked") % SDICT(game_instance_id=game_instance_id))
            elif request.POST.get("unlock_instance"):
                game_instance_id = request.POST["unlock_instance"]
                datamanager_administrator.change_game_instance_status(game_instance_id=game_instance_id, maintenance_until=None) # removes maintenance
                messages.add_message(request, messages.INFO, _(u"Game instance '%(game_instance_id)s' successfully unlocked") % SDICT(game_instance_id=game_instance_id))
            elif request.POST.get("change_instance_status"):
                game_instance_id = request.POST["change_instance_status"]
                new_status = request.POST["new_status"]
                datamanager_administrator.change_game_instance_status(game_instance_id=game_instance_id, new_status=new_status) # change status
                messages.add_message(request, messages.INFO, _(u"Game instance '%(game_instance_id)s' status changed to '%(new_status)s'") % SDICT(game_instance_id=game_instance_id, new_status=new_status))
            elif request.POST.get("delete_game_instance"):
                game_instance_id = request.POST["delete_game_instance"]
                datamanager_administrator.delete_game_instance(game_instance_id=game_instance_id)
                messages.add_message(request, messages.INFO, _(u"Game instance '%(game_instance_id)s' was deleted") % SDICT(game_instance_id=game_instance_id))
            elif request.POST.get("backup_game_instance"):
                game_instance_id = request.POST["backup_game_instance"]
                backup_comment = slugify(request.POST["backup_comment"].strip()) or None
                datamanager_administrator.backup_game_instance_data(game_instance_id=game_instance_id, comment=backup_comment)
                messages.add_message(request, messages.INFO, _(u"Game instance '%(game_instance_id)s' backup with comment '%(backup_comment)s' done") %
                                                               SDICT(game_instance_id=game_instance_id, backup_comment=(backup_comment or u"<empty>")))
            elif request.POST.get("compute_enforced_session_ticket"):
                game_instance_id = request.POST["game_instance_id"].strip() # manually entered
                login = request.POST["login"].strip()
                is_observer = bool(request.POST.get("is_observer"))
                authentication_token = authentication.compute_enforced_login_token(game_instance_id=game_instance_id, login=login, is_observer=is_observer)
                messages.add_message(request, messages.INFO, _(u"Auto-connection token for instance=%(game_instance_id)s, login=%(login)s and is_observer=%(is_observer)s is displayed below") %
                                                               SDICT(game_instance_id=game_instance_id, login=login, is_observer=is_observer))
                session_token_display = urlencode({authentication.ENFORCED_SESSION_TICKET_NAME: authentication_token})
            else:
                raise ValueError(_("Unknown admin action"))

    except Exception as e:
        messages.add_message(request, messages.ERROR, _(u"Unexpected error: %s") % e)

    instances_metadata = datamanager_administrator.get_all_instances_metadata()

    for _meta in instances_metadata:
        _activation_link = _build_activation_url(game_instance_id=_meta["instance_id"], creator_login=_meta["creator_login"], creator_email=_meta["creator_email"])
        _meta["activation_link"] = _activation_link

    return render(request,
                  "meta_administration/manage_instances.html",
                    {
                     'instances_metadata': instances_metadata, # enriched info
                     'utc_now': datetime.utcnow(),
                     'notifications': get_messages(request),
                     'possible_game_statuses': sorted(GAME_STATUSES),
                     'deletable_statuses': [GAME_STATUSES.terminated, GAME_STATUSES.aborted],
                     'game_creation_form': game_creation_form or GameInstanceCreationForm(require_email=require_email),
                     'session_token_display': session_token_display,
                    })