P
P
Perzh2014-05-17 18:54:41
Django
Perzh, 2014-05-17 18:54:41

How to organize achievements for site users?

Hello.
I'm trying to make a site where the administrator would add various achievements for the DOTA2 game, and users would try to complete them, and the verification is carried out automatically. The question is how to organize the storage of achievements?
The only thing that came to my mind was to store a human-readable description of the achievement and some string in which to encode the achievement feasibility predicate somehow, for example:

Описание: выиграть игру раньше 20 минут с показателем GPM > 250.
Строка-предикат: "duration>20&GPM>250&winer"

When the user presses the 'Run' button, the server parses the string and, using the user's game information, calculates a predicate.
Questions:
1. What is the best way to encode a string? If I encode it as in the example, then I will have to write a parser (or, as it were, an interpreter) to calculate the predicate. Or, for example, you can immediately write python code in a line so that the python interpreter executes it itself, what do you think?
2. Maybe there is some other way to organize it?
3. Just criticize the idea if nothing else comes to mind =)
Thanks in advance!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
kazhuravlev, 2014-05-19
@kazhuravlev

Python code is not OK (the user can write anything there and cause harm),
but you can come up with some format for storing such data based on existing structures. for example, you can collect a hash into some JSON, and then parse it on the server

{
    'duration': {
        'greater_than': 20
    },
    'GPM': {
        'greater_than': 250    
} 
}

F
FeNUMe, 2014-06-13
@FeNUMe

You need to store it in a format that will be easiest to check later if there are no additional requirements. In the simplest case, an ordinary dictionary with conditions and a check function is enough. You pass the results of the battle and the necessary dictionaries with achievements to the function, go through the dictionary in a loop and compare. Do not forget to skip the iterations where it is immediately clear that the achievement has not been completed (if there are several conditions and the first one fails, then there is no point in checking the rest - we move on to the next achievement).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question