Passed
Pull Request — master (#161)
by Vincent
11:02
created

maxPerAccount()   A

Complexity

Conditions 1

Size

Total Lines 2
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
dl 0
loc 2
ccs 1
cts 1
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
/*
2
 * This file is part of Araknemu.
3
 *
4
 * Araknemu is free software: you can redistribute it and/or modify
5
 * it under the terms of the GNU Lesser General Public License as published by
6
 * the Free Software Foundation, either version 3 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * Araknemu is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU Lesser General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU Lesser General Public License
15
 * along with Araknemu.  If not, see <https://www.gnu.org/licenses/>.
16
 *
17
 * Copyright (c) 2017-2020 Vincent Quatrevieux
18
 */
19
20
package fr.quatrevieux.araknemu.game;
21
22
import fr.quatrevieux.araknemu.core.config.ConfigurationModule;
23
import fr.quatrevieux.araknemu.core.config.Pool;
24
import fr.quatrevieux.araknemu.core.config.PoolUtils;
25
import org.apache.commons.lang3.StringUtils;
26
27
import java.time.Duration;
28
import java.util.Arrays;
29
30
/**
31
 * Configuration class for game server
32
 */
33 1
public final class GameConfiguration implements ConfigurationModule {
34
    private PoolUtils pool;
35
36
    @Override
37
    public void setPool(Pool pool) {
38 1
        this.pool = new PoolUtils(pool);
39 1
    }
40
41
    @Override
42
    public String name() {
43 1
        return "game";
44
    }
45
46
    /**
47
     * Get the server ID. By default 1
48
     */
49
    public int id() {
50 1
        return pool.integer("id", 1);
51
    }
52
53
    /**
54
     * Get the server port
55
     */
56
    public int port() {
57 1
        return pool.integer("server.port", 5555);
58
    }
59
60
    /**
61
     * Get the server IP address
62
     */
63
    public String ip() {
64 1
        return pool.string("server.ip", "127.0.0.1");
65
    }
66
67
    /**
68
     * The maximum inactivity time, as duration
69
     * By default, 15min ("PT15M" or "15m")
70
     */
71
    public Duration inactivityTime() {
72 1
        return pool.duration("inactivityTime", Duration.ofMinutes(15));
73
    }
74
75
    /**
76
     * Maximum number of received packets per seconds per clients
77
     * When the limit is reached, the client session is closed
78
     */
79
    public int packetRateLimit() {
80 1
        return pool.integer("packetRateLimit", 100);
81
    }
82
83
    /**
84
     * Get the shutdown reminder delays, in minutes
85
     * The values are integer separated by a comma ","
86
     * Default value : "1,10,30,60,120"
87
     */
88
    public long[] shutdownReminderMinutes() {
89 1
        return Arrays.stream(StringUtils.split(pool.string("shutdownReminderMinutes", "1,10,30,60,120"), ","))
90 1
            .map(String::trim)
91 1
            .mapToLong(Long::parseLong)
92 1
            .sorted()
93 1
            .toArray()
94
        ;
95
    }
96
97
    /**
98
     * Get the refresh interval for the ban ip table
99
     * Default: 10 minutes (10m)
100
     */
101
    public Duration banIpRefresh() {
102 1
        return pool.duration("banip.refresh", Duration.ofMinutes(10));
103
    }
104
105
    /**
106
     * Get player configuration
107
     */
108
    public PlayerConfiguration player() {
109 1
        return new PlayerConfiguration();
110
    }
111
112
    /**
113
     * Get the chat configuration
114
     */
115
    public ChatConfiguration chat() {
116 1
        return new ChatConfiguration();
117
    }
118
119
    /**
120
     * Get the configuration for the game activity
121
     */
122
    public ActivityConfiguration activity() {
123 1
        return new ActivityConfiguration();
124
    }
125
126
    /**
127
     * Get the configuration for the Dofus economy
128
     */
129
    public EconomyConfiguration economy() {
130 1
        return new EconomyConfiguration();
131
    }
132
133 1
    public final class PlayerConfiguration {
134
        /**
135
         * The player name regex
136
         */
137
        public String nameRegex() {
138 1
            return pool.string("player.name.regex", "[A-Z][a-z]+(-[A-Z]?[a-z]+)?");
139
        }
140
141
        /**
142
         * Minimal length of player name
143
         */
144
        public int nameMinLength() {
145 1
            return pool.integer("player.name.minLength", 2);
146
        }
147
148
        /**
149
         * Maximal length of player name
150
         */
151
        public int nameMaxLength() {
152 1
            return pool.integer("player.name.maxLength", 20);
153
        }
154
155
        /**
156
         * Maximal length for generated name
157
         */
158
        public int maxNameGeneratedLength() {
159 1
            return pool.integer("player.name.generated.maxLength", 8);
160
        }
161
162
        /**
163
         * Minimal length for generated name
164
         */
165
        public int minNameGeneratedLength() {
166 1
            return pool.integer("player.name.generated.minLength", 4);
167
        }
168
169
        /**
170
         * Maximum number for characters per account per server
171
         */
172
        public int maxPerAccount() {
173 1
            return pool.integer("player.max", 5);
174
        }
175
176
        /**
177
         * Minimum level which needs secret answer for delete the character
178
         * By default, value is set to 20
179
         *
180
         * To change this value, you should also change in lang.swf, the value `C.SECRET_ANSWER_SINCE_LEVEL`
181
         */
182
        public int deleteAnswerLevel() {
183 1
            return pool.integer("player.deleteAnswerLevel", 20);
184
        }
185
186
        /**
187
         * Get the level up spell points
188
         * By default, value is set to 1
189
         */
190
        public int spellBoostPointsOnLevelUp() {
191 1
            return pool.integer("player.level.spellPoints", 1);
192
        }
193
194
        /**
195
         * Get the level up characteristic points
196
         * By default, value is set to 5
197
         */
198
        public int characteristicPointsOnLevelUp() {
199 1
            return pool.integer("player.level.characteristicPoints", 5);
200
        }
201
202
        /**
203
         * The life regeneration rate.
204
         * This is the number of milliseconds required to regenerate 1 life point. Set to 0 to disable.
205
         * By default 1000 (1 LP / sec)
206
         */
207
        public int baseLifeRegeneration() {
208 1
            return pool.integer("player.lifeRegeneration.base", 1000);
209
        }
210
211
        /**
212
         * Restore life points when player reach a new level
213
         * By default true
214
         */
215
        public boolean restoreLifeOnLevelUp() {
216 1
            return pool.bool("player.restoreLifeOnLevelUp", true);
217
        }
218
    }
219
220 1
    public final class ChatConfiguration {
221
        /**
222
         * Get the waiting time in seconds for global channel flood
223
         *
224
         * Set to -1 for deactivate
225
         */
226
        public int floodTime() {
227 1
            return pool.integer("chat.flood.time", 30);
228
        }
229
230
        /**
231
         * Get list of default channels to add on character creation
232
         */
233
        public String defaultChannels() {
234 1
            return pool.string("chat.channels.default", "*#%!pi$:?");
235
        }
236
237
        /**
238
         * Channels to add on admin characters
239
         */
240
        public String adminChannels() {
241 1
            return pool.string("chat.channels.admin", "@");
242
        }
243
    }
244
245 1
    public final class ActivityConfiguration {
246
        /**
247
         * Number of threads to use for the activity service
248
         */
249
        public int threadsCount() {
250 1
            return pool.integer("activity.threadsCount", 1);
251
        }
252
253
        /**
254
         * Number of seconds for move monster groups
255
         * By default 120s = 2min
256
         */
257
        public int monsterMoveInterval() {
258 1
            return pool.integer("activity.monsters.moveInterval", 120);
259
        }
260
261
        /**
262
         * Percent of chance that a monster group on a map move
263
         * The value must be an integer value between ]0, 100]
264
         * By default 25%
265
         */
266
        public int monsterMovePercent() {
267 1
            return pool.integer("activity.monsters.movePercent", 25);
268
        }
269
    }
270
271 1
    public final class EconomyConfiguration {
272
        /**
273
         * Get the selling item to an NPC price multiplier
274
         * By default 0.1
275
         *
276
         * Should corresponds to "C.SELL_PRICE_MULTIPLICATOR" in lang_xx_xxx.swf
277
         */
278
        public double npcSellPriceMultiplier() {
279 1
            return pool.decimal("economy.npc.sellPriceMultiplier", .1d);
280
        }
281
282
        /**
283
         * The bank cost per item entries
284
         * The value must be a positive double
285
         * Default to 1
286
         * Set to 0 to disable the bank cost
287
         */
288
        public double bankCostPerEntry() {
289 1
            return pool.decimal("economy.bank.costPerEntry", 1);
290
        }
291
    }
292
}
293