1
|
|
|
# coding: utf-8 |
2
|
|
|
|
3
|
1 |
|
import zope.interface |
4
|
|
|
|
5
|
1 |
|
from schematics.exceptions import ValidationError |
6
|
1 |
|
from schematics.models import Model |
7
|
1 |
|
from schematics.types import IntType, FloatType |
8
|
1 |
|
from schematics.types.compound import ModelType |
9
|
|
|
|
10
|
1 |
|
from ..interfaces import INISerializable |
11
|
|
|
|
12
|
|
|
|
13
|
1 |
|
@zope.interface.implementer(INISerializable) |
14
|
1 |
|
class MaxTime(Model): |
15
|
1 |
|
near = FloatType( |
16
|
|
|
min_value=0.1, |
17
|
|
|
max_value=30.0, |
18
|
|
|
default=2.0, |
19
|
|
|
required=True, |
20
|
|
|
) |
21
|
1 |
|
far = FloatType( |
22
|
|
|
min_value=0.1, |
23
|
|
|
max_value=30.0, |
24
|
|
|
default=10.0, |
25
|
|
|
required=True, |
26
|
|
|
) |
27
|
|
|
|
28
|
1 |
|
def validate_far(self, data, value): |
29
|
|
|
near = data['near'] |
30
|
|
|
|
31
|
|
|
if value < near: |
32
|
|
|
raise ValidationError( |
33
|
|
|
"'far' value ({far}) cannot be less than 'near' value ({near})." |
34
|
|
|
.format(far=value, near=near) |
35
|
|
|
) |
36
|
|
|
|
37
|
|
|
return value |
38
|
|
|
|
39
|
1 |
|
@classmethod |
40
|
|
|
def from_ini(cls, ini): |
41
|
|
|
return cls({ |
42
|
|
|
'near': ini.getfloat( |
43
|
|
|
'MaxLag', 'nearMaxLagTime', |
44
|
|
|
fallback=cls.near.default, |
45
|
|
|
), |
46
|
|
|
'far': ini.getfloat( |
47
|
|
|
'MaxLag', 'farMaxLagTime', |
48
|
|
|
fallback=cls.far.default, |
49
|
|
|
), |
50
|
|
|
}) |
51
|
|
|
|
52
|
|
|
|
53
|
1 |
|
@zope.interface.implementer(INISerializable) |
54
|
1 |
|
class Warnings(Model): |
55
|
1 |
|
delay = FloatType( |
56
|
|
|
min_value=1.0, |
57
|
|
|
max_value=30.0, |
58
|
|
|
default=10.0, |
59
|
|
|
required=True, |
60
|
|
|
) |
61
|
1 |
|
max_number = IntType( |
62
|
|
|
default=3, |
63
|
|
|
required=True, |
64
|
|
|
) |
65
|
|
|
|
66
|
1 |
|
@classmethod |
67
|
|
|
def from_ini(cls, ini): |
68
|
|
|
return cls({ |
69
|
|
|
'delay': ini.getfloat( |
70
|
|
|
'MaxLag', 'cheaterWarningDelay', |
71
|
|
|
fallback=cls.delay.default, |
72
|
|
|
), |
73
|
|
|
'max_number': ini.getint( |
74
|
|
|
'MaxLag', 'cheaterWarningNum', |
75
|
|
|
fallback=cls.max_number.default, |
76
|
|
|
), |
77
|
|
|
}) |
78
|
|
|
|
79
|
|
|
|
80
|
1 |
|
@zope.interface.implementer(INISerializable) |
81
|
1 |
|
class Lags(Model): |
82
|
1 |
|
max_time = ModelType( |
83
|
|
|
model_spec=MaxTime, |
84
|
|
|
required=True, |
85
|
|
|
) |
86
|
1 |
|
warnings = ModelType( |
87
|
|
|
model_spec=Warnings, |
88
|
|
|
required=True, |
89
|
|
|
) |
90
|
|
|
|
91
|
1 |
|
@classmethod |
92
|
|
|
def from_ini(cls, ini): |
93
|
|
|
return cls({ |
94
|
|
|
'max_time': MaxTime.from_ini(ini), |
95
|
|
|
'warnings': Warnings.from_ini(ini), |
96
|
|
|
}) |
97
|
|
|
|