forked from borzh/botrix
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.cpp
More file actions
635 lines (553 loc) · 21.8 KB
/
config.cpp
File metadata and controls
635 lines (553 loc) · 21.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
#include <stdlib.h> // atoi
#include "types.h"
#include "chat.h"
#include "config.h"
#include "mod.h"
#include "source_engine.h"
#include "type2string.h"
#include "weapon.h"
#include "good/string_buffer.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
#if defined(DEBUG) || defined(_DEBUG)
# define ConfigMessage(...) CUtil::Message(NULL, __VA_ARGS__)
#else
# define ConfigMessage(...)
#endif
# define ConfigError(...) CUtil::Message(NULL, __VA_ARGS__)
extern char* szMainBuffer;
extern int iMainBufferSize;
//------------------------------------------------------------------------------------------------------------
good::ini_file CConfiguration::m_iniFile; // Ini file.
bool CConfiguration::m_bModified; // True if something was modified (to save later).
//------------------------------------------------------------------------------------------------------------
TModId CConfiguration::Load( const good::string& sFileName, const good::string& sGameDir, const good::string& sModDir )
{
TModId iModId = EModId_Invalid;
StringVector aBotNames(0), aModels(0), aTeams(4);
good::string_buffer sbBuffer(szMainBuffer, iMainBufferSize, false);
m_iniFile.name = sFileName;
if ( m_iniFile.load() >= good::IniFileNotFound )
ConfigError("Error reading configuration file %s", m_iniFile.name.c_str());
m_bModified = false;
// Process general section.
good::ini_file::iterator it = m_iniFile.find("Bots");
if ( it != m_iniFile.end() )
{
// Get bot names.
good::ini_section::iterator kv = it->find("names");
if ( kv != it->end() )
{
sbBuffer = kv->value;
sbBuffer.escape();
aBotNames = sbBuffer.split<good::vector>(',', true);
}
else
ConfigError("File %s, section [%s]: missing bot_names.", m_iniFile.name.c_str(), it->name.c_str());
aBotNames.push_back("Botrix");
#if defined(DEBUG) || defined(_DEBUG)
ConfigMessage("Bot names:");
for ( int i = 0; i < (int)aBotNames.size(); ++i )
ConfigMessage( " %s", aBotNames[i].c_str() );
#endif
// Check if need to show intelligence in it's name.
kv = it->find("name_with_intelligence");
if ( kv != it->end() )
{
int iValue = CTypeToString::BoolFromString(kv->value);
if ( iValue == -1 )
CUtil::Message( NULL, "File %s, section [%s]: invalid parameter %s for %s.", m_iniFile.name.c_str(),
it->name.c_str(), kv->value.c_str(), kv->key.c_str() );
else
{
CMod::bIntelligenceInBotName = (iValue != 0);
ConfigMessage("Intelligence in bot name: %s.", kv->value.c_str());
}
}
}
else
ConfigError("File %s, missing [%s] section.", m_iniFile.name.c_str(), it->name.c_str());
CMod::SetBotNames(aBotNames);
// Set current mod from mods sections.
for ( it = m_iniFile.begin(); it != m_iniFile.end(); ++it )
{
if ( it->name.ends_with(".mod") )
{
good::ini_section::iterator games = it->find("games");
good::ini_section::iterator mods = it->find("mods");
if ( (games != it->end()) && (mods != it->end()) )
{
sbBuffer = games->value;
sbBuffer.lower_case();
StringVector aGameDirs = sbBuffer.split<good::vector>(',', true);
for ( StringVector::const_iterator gameDirsIt = aGameDirs.begin(); gameDirsIt != aGameDirs.end(); ++gameDirsIt )
{
if ( *gameDirsIt == sGameDir )
{
sbBuffer = mods->value;
sbBuffer.escape();
good::list<good::string> aModsDirs = sbBuffer.split<good::list>(',', true);
for ( good::list<good::string>::const_iterator modDirsIt = aModsDirs.begin(); modDirsIt != aModsDirs.end(); ++modDirsIt )
{
if ( *modDirsIt == sModDir )
{
// Get bot used in this mod.
good::ini_section::iterator bot = it->find("bot");
if ( bot != it->end() )
{
iModId = CTypeToString::ModFromString(bot->value);
if ( iModId == EModId_Invalid )
{
ConfigError("File %s, section [%s], invalid bot -> %s.", m_iniFile.name.c_str(), it->name.c_str(), bot->value.c_str());
ConfigError("Using default bot: hl2dm.");
iModId = EModId_HL2DM;
}
}
else
{
ConfigError("Not 'bot' key in section [%s]. Using default bot: hl2dm.", it->name.c_str());
iModId = EModId_HL2DM;
}
// Get player teams.
good::ini_section::iterator teams = it->find("teams");
if ( teams != it->end() )
{
sbBuffer = teams->value;
sbBuffer.escape();
aTeams = sbBuffer.split<good::vector>(',', true);
ConfigMessage("Team names:");
for ( int i = 0; i < (int)aTeams.size(); ++i )
{
if ( aTeams[i] == "unassigned" )
CMod::iUnassignedTeam = i;
else if ( aTeams[i] == "spectators" )
CMod::iSpectatorTeam = i;
ConfigMessage( " %s", aTeams[i].c_str() );
}
}
// Get player models.
for ( int i = 0; i < aTeams.size(); ++i )
{
if ( aTeams[i] == "spectators" )
continue;
sbBuffer = "models ";
sbBuffer.append(aTeams[i]);
good::ini_section::iterator models = it->find(sbBuffer);
if ( models != it->end() )
{
sbBuffer = models->value;
sbBuffer.escape();
aModels = sbBuffer.split<good::vector>(',', true);
#if defined(DEBUG) || defined(_DEBUG)
ConfigMessage("Model names for team %s:", aTeams[i].c_str());
for ( int j = 0; j < (int)aModels.size(); ++j )
ConfigMessage( " %s", aModels[j].c_str() );
#endif
CMod::SetBotModels( aModels, i );
}
}
CMod::aTeamsNames = aTeams;
// Get mod name in sbBuffer.
sbBuffer = it->name;
sbBuffer.erase( sbBuffer.length() - 4, 4 ); // Erase ".mod" from section name.
goto mod_found;
}
}
}
}
}
else
ConfigError("File %s, section [%s], invalid mod section (missing games/mods keys).", m_iniFile.name.c_str(), it->name.c_str());
}
}
mod_found:
if ( iModId == EModId_Invalid )
{
ConfigError("File %s: there is no mod available that matches current game & mod folders.", m_iniFile.name.c_str());
ConfigError("Using default mod 'HalfLife2Deathmatch' with bot 'hl2dm', no items available.");
CMod::sModName = "HalfLife2Deathmatch";
sbBuffer = CMod::sModName;
}
else
{
ConfigMessage("Current mod: '%s'.", sbBuffer.c_str());
CMod::sModName.assign(sbBuffer, true);
}
// Load health /armor / object entity classes.
for ( TEntityType iType = 0; iType < EEntityTypeTotal; ++iType )
{
// Get mod item section, i.e. [HalfLife2Deathmatch.item.health].
sbBuffer.erase( CMod::sModName.size() );
sbBuffer.append(".items.");
sbBuffer.append( CTypeToString::EntityTypeToString(iType) );
good::ini_file::iterator it = m_iniFile.find( sbBuffer );
if ( it != m_iniFile.end() )
{
CItems::SetEntityClassesSizeForType( iType, it->size() ); // Reserve needed space, as we will use pointers to that space.
// Iterate throught key values.
for ( good::ini_section::const_iterator itemIt = it->begin(); itemIt != it->end(); ++itemIt )
{
CEntityClass cEntityClass;
cEntityClass.sClassName.assign( itemIt->key.c_str(), itemIt->key.size() ); // String instance will live until plugin is unloaded.
// Get item flags.
StringVector aArguments = itemIt->value.split<good::vector>(',', true);
for ( int i=0; i < aArguments.size(); ++i )
{
StringVector aCurrent = aArguments[i].split<good::vector>();
int iFlag = CTypeToString::EntityClassFlagsFromString(aCurrent[0]);
if ( iFlag == -1 )
ConfigError("File %s, section [%s], invalid entity flag %s for %s.", m_iniFile.name.c_str(), it->name.c_str(), aArguments[i].c_str(), itemIt->key.c_str());
else
{
FLAG_SET(iFlag, cEntityClass.iFlags);
/*if ( iFlag == FEntityRespawnable ) // Check respawn time.
{
if ( aCurrent.size() == 2 )
{
int iValue = -1;
sscanf(aCurrent[1].c_str(), "%d", &iValue);
if ( iValue > 0 )
SET_2ND_WORD(iValue, cEntityClass.iFlags);
else
ConfigError("File %s, section [%s], invalid respawn time for: %s.", m_iniFile.name.c_str(), it->name.c_str(), itemIt->key.c_str());
}
else if ( aCurrent.size() > 2 )
ConfigError("File %s, section [%s], invalid arguments count for: %s.", m_iniFile.name.c_str(), it->name.c_str(), itemIt->key.c_str());
}*/
}
}
CItems::AddItemClassFor( iType, cEntityClass );
}
}
}
// Load object models.
sbBuffer = CMod::sModName;
sbBuffer.erase( CMod::sModName.size() );
sbBuffer.append(".items.object.models");
it = m_iniFile.find( sbBuffer );
if ( it != m_iniFile.end() )
{
// Iterate throught key values.
for ( good::ini_section::const_iterator itemIt = it->begin(); itemIt != it->end(); ++itemIt )
{
int iValue = CTypeToString::EntityClassFlagsFromString(itemIt->value);
if ( iValue > 0 )
CItems::SetObjectFlagForModel(iValue, itemIt->key);
else
{
ConfigError("File %s, section [%s], invalid object model flag: %s.", m_iniFile.name.c_str(), it->name.c_str(), itemIt->value.c_str());
ConfigError("Can be one of: %s", CTypeToString::EntityClassFlagsToString(FEntityAll).c_str());
}
}
}
// Load weapons.
ConfigMessage("Weapons:");
sbBuffer.erase( CMod::sModName.size() );
sbBuffer.append(".weapons");
it = m_iniFile.find( sbBuffer );
if ( it != m_iniFile.end() )
{
// Iterate throught key values.
for ( good::ini_section::const_iterator itemIt = it->begin(); itemIt != it->end(); ++itemIt )
{
sbBuffer = itemIt->value;
sbBuffer.escape();
StringVector aParams = sbBuffer.split<good::vector>(',', true);
good::vector<CEntityClass> aAmmos[2];
if ( itemIt->key == "default" ) // Default weapons.
{
for ( StringVector::iterator paramsIt = aParams.begin(); paramsIt != aParams.end(); ++paramsIt )
{
StringVector aCurrent = paramsIt->split<good::vector>();
DebugAssert( aCurrent.size() > 0 );
// Get weapon from name.
TWeaponId iWeaponId = CWeapons::GetIdFromWeaponName( aCurrent[0] );
if ( iWeaponId == -1 )
{
ConfigError("File %s, section [%s], 'default' weapons: unknown weapon '%s', skipping.",
m_iniFile.name.c_str(), it->name.c_str(), aCurrent[0].c_str());
continue;
}
const CWeapon* pWeapon = CWeapons::Get(iWeaponId);
int iNeedArgument = 1;
if ( pWeapon->iClipSize[0] > 0 )
iNeedArgument++;
if ( pWeapon->bHasSecondary && !pWeapon->bSecondaryUseSameBullets )
iNeedArgument++;
if ( aCurrent.size() != iNeedArgument )
ConfigError("File %s, section [%s], 'default' weapons, weapon '%s': invalid parameters count.",
m_iniFile.name.c_str(), it->name.c_str(), aCurrent[0].c_str());
// Get primary extra ammo for this weapon.
int iExtra[2] = { -1, -1 };
if ( (pWeapon->iClipSize[0] > 0) && (aCurrent.size() >= 2 )) // Weapon name, primary extra ammo.
{
sscanf( aCurrent[1].c_str(), "%u", &iExtra[0]);
if ( iExtra[0] < 0 )
ConfigError("File %s, section [%s], 'default' weapons, weapon '%s': invalid parameter %s.",
m_iniFile.name.c_str(), it->name.c_str(), aCurrent[0].c_str(), aCurrent[1].c_str());
}
// Get secondary extra ammo.
if ( pWeapon->bHasSecondary && !pWeapon->bSecondaryUseSameBullets && (aCurrent.size() >= 3) )
{
sscanf( aCurrent[2].c_str(), "%u", &iExtra[1]);
if ( iExtra[1] < 0 )
ConfigError("File %s, section [%s], 'default' weapons, weapon '%s': invalid parameter %s.",
m_iniFile.name.c_str(), it->name.c_str(), aCurrent[0].c_str(), aCurrent[3].c_str());
}
if ( pWeapon->iClipSize[0] && (iExtra[0] < 0) )
{
iExtra[0] = pWeapon->iDefaultAmmo[0];
ConfigError("File %s, section [%s], 'default' weapons, weapon '%s': using default primary %u.",
m_iniFile.name.c_str(), it->name.c_str(), aCurrent[0].c_str(), iExtra[0]);
}
if ( pWeapon->iClipSize[1] && (iExtra[1] < 0) )
{
iExtra[1] = pWeapon->iDefaultAmmo[1];
ConfigError("File %s, section [%s], 'default' weapons, weapon '%s': using default secondary %u.",
m_iniFile.name.c_str(), it->name.c_str(), aCurrent[0].c_str(), iExtra[1]);
}
CWeapons::SetDefault( iWeaponId, iExtra[0] >= 0 ? iExtra[0] : 0, iExtra[1] >= 0 ? iExtra[1] : 0);
}
}
else // Weapon definition.
{
CWeapon* pWeapon = new CWeapon();
bool bSecondary = false, bError = false;
for ( StringVector::iterator paramsIt = aParams.begin(); paramsIt != aParams.end(); ++paramsIt )
{
int iValue = -1;
StringVector aCurrent = paramsIt->split<good::vector>();
DebugAssert( aCurrent.size() > 0 );
if ( aCurrent.size() == 1 )
{
if ( aCurrent[0] == "secondary" )
pWeapon->bHasSecondary = bSecondary = true;
else if ( aCurrent[0] == "same_ammo" )
pWeapon->bSecondaryUseSameBullets = true;
else if ( aCurrent[0] == "force_aim" )
pWeapon->bForceAim = true;
else if ( aCurrent[0] == "background_reload" )
pWeapon->bBackgroundReload = true;
else if ( aCurrent[0] == "add_clip" )
pWeapon->bAddClip = true;
else
{
ConfigError("File %s, section [%s], weapon %s, unknown keyword: %s or invalid parameters count.",
m_iniFile.name.c_str(), it->name.c_str(), itemIt->key.c_str(), aCurrent[0].c_str());
bError = true;
break;
}
}
else if ( aCurrent.size() == 2 )
{
if ( aCurrent[0] == "type" )
{
int iType = CTypeToString::WeaponTypeFromString(aCurrent[1]);
if ( iType == -1 )
{
ConfigError("File %s, section [%s], weapon %s, invalid weapon type: %s.",
m_iniFile.name.c_str(), it->name.c_str(), itemIt->key.c_str(), aCurrent[1].c_str());
bError = true;
break;
}
pWeapon->iType = iType;
// Set weapon default parameters.
switch (iType)
{
case EWeaponManual:
case EWeaponPhysics:
pWeapon->iAttackBullets[0] = pWeapon->iAttackBullets[1] = 0;
break;
case EWeaponRpg:
case EWeaponGrenade:
case EWeaponFlash:
case EWeaponSmoke:
case EWeaponRemoteDetonation:
pWeapon->iClipSize[0] = 1;
break;
}
}
else if ( aCurrent[0] == "preference" )
{
iValue = CTypeToString::PreferenceFromString(aCurrent[1]);
if ( iValue == -1 )
ConfigError("File %s, section [%s], weapon %s, invalid preference: %s, using 'lowest'.",
m_iniFile.name.c_str(), it->name.c_str(), itemIt->key.c_str(), aCurrent[1].c_str());
else
pWeapon->iBotPreference = iValue;
}
else if ( aCurrent[0] == "team" )
{
iValue = CMod::GetTeamIndex(aCurrent[1]);
if ( iValue == -1 )
{
ConfigError("File %s, section [%s], weapon %s, invalid team: %s.",
m_iniFile.name.c_str(), it->name.c_str(), itemIt->key.c_str(), aCurrent[1].c_str());
bError = true;
break;
}
pWeapon->iTeamOnly = iValue;
}
else if ( aCurrent[0] == "range" )
{
// TODO:
}
else
{
sscanf(aCurrent[1].c_str(), "%u", &iValue);
if ( iValue < 0 )
{
ConfigError("File %s, section [%s], weapon %s, invalid number: %s for parameter %s.",
m_iniFile.name.c_str(), it->name.c_str(), itemIt->key.c_str(),
aCurrent[1].c_str(), aCurrent[0].c_str());
bError = true;
break;
}
if ( aCurrent[0] == "clip" )
pWeapon->iClipSize[bSecondary] = iValue;
else if ( aCurrent[0] == "damage" )
pWeapon->iDamage[bSecondary] = iValue;
else if ( aCurrent[0] == "delay" )
pWeapon->fShotTime[bSecondary] = iValue / 1000.0f;
else if ( aCurrent[0] == "reload" )
pWeapon->fReloadTime[bSecondary] = iValue / 1000.0f;
else if ( aCurrent[0] == "holster" )
pWeapon->fHolsterTime = iValue / 1000.0f;
else if ( aCurrent[0] == "default_ammo" )
pWeapon->iDefaultAmmo[bSecondary] = iValue;
else if ( aCurrent[0] == "max_ammo" )
pWeapon->iMaxAmmo[bSecondary] = iValue;
else if ( aCurrent[0] == "bullets" )
pWeapon->iAttackBullets[bSecondary] = iValue;
else if ( aCurrent[0] == "default_ammo" )
pWeapon->iDefaultAmmo[bSecondary] = iValue;
else if ( aCurrent[0] == "parabolic" )
pWeapon->iParabolic[bSecondary] = iValue;
else if ( aCurrent[0] == "zoom_distance" )
pWeapon->fMinDistanceSqr[1] = SQR(iValue);
else if ( aCurrent[0] == "zoom_time" )
pWeapon->fShotTime[1] = iValue / 1000.0f;
else
{
ConfigError("File %s, section [%s], weapon %s, unknown keyword: %s or invalid parameters count.",
m_iniFile.name.c_str(), it->name.c_str(), itemIt->key.c_str(), aCurrent[0].c_str());
bError = true;
break;
}
}
}
else if ( aCurrent[0] == "ammo" ) // 3+ arguments.
{
if ( (aCurrent.size() & 1) == 0 ) // Number must be odd.
{
ConfigError("File %s, section [%s], weapon %s: invalid parameters count for %s.",
m_iniFile.name.c_str(), it->name.c_str(), itemIt->key.c_str(), aCurrent[0].c_str());
bError = true;
break;
}
aAmmos[bSecondary].reserve( (aCurrent.size() - 1) >> 1 ); // Reserve some space for ammos.
for ( int i=1; i < aCurrent.size(); i+=2 )
{
int iValue = -1;
sscanf(aCurrent[i+1].c_str(), "%u", &iValue);
if ( iValue <= 0 ) // Ammo count can't be 0.
{
ConfigError("File %s, section [%s], weapon %s, invalid parameter for '%s' ammo's count: %s.",
m_iniFile.name.c_str(), it->name.c_str(), itemIt->key.c_str(), aCurrent[i].c_str(), aCurrent[i+1].c_str());
bError = true;
break;
}
CEntityClass cAmmoClass;
cAmmoClass.sClassName.assign(aCurrent[i], true);
cAmmoClass.SetArgument(iValue);
aAmmos[bSecondary].push_back(cAmmoClass);
}
if ( bError )
break;
}
else
{
ConfigError("File %s, section [%s], weapon %s: unknown parameter %s.",
m_iniFile.name.c_str(), it->name.c_str(), itemIt->key.c_str(), aCurrent[0].c_str());
bError = true;
break;
}
}
if ( !bError )
{
ConfigMessage( " %s", itemIt->key.c_str() );
pWeapon->iId = CWeapons::Size();
// Add weapon class.
CEntityClass cEntityClass;
cEntityClass.sClassName.assign(itemIt->key, true);
pWeapon->pWeaponClass = CItems::AddItemClassFor( EEntityTypeWeapon, cEntityClass );
// Add ammo classes.
pWeapon->aAmmos[0].reserve(aAmmos[0].size());
pWeapon->aAmmos[1].reserve(aAmmos[1].size());
for ( int bSec=0; bSec < 2; ++bSec )
for ( int i=0; i < aAmmos[bSec].size(); ++i )
{
const CEntityClass* pAmmoClass = CItems::AddItemClassFor( EEntityTypeAmmo, aAmmos[bSec][i] );
pWeapon->aAmmos[bSec].push_back( pAmmoClass );
ConfigMessage( " ammo %s (%u bullets)", pWeapon->aAmmos[bSec][i]->sClassName.c_str(),
pWeapon->aAmmos[bSec][i]->GetArgument(), itemIt->key.c_str() );
}
CWeaponWithAmmo cWeapon(pWeapon);
CWeapons::Add(cWeapon);
}
else
delete pWeapon;
}
}
}
// Load chat: synonims.
ConfigMessage("Loading chat synonims:");
it = m_iniFile.find( "Chat.replace" );
if ( it != m_iniFile.end() )
{
// Iterate throught key values.
for ( good::ini_section::const_iterator wordIt = it->begin(); wordIt != it->end(); ++wordIt )
CChat::AddSynonims( wordIt->key, wordIt->value );
}
// Load chat: commands.
ConfigMessage("Loading chat sentences:");
it = m_iniFile.find( "Chat.sentences" );
if ( it != m_iniFile.end() )
{
// Iterate throught key values.
for ( good::ini_section::const_iterator wordIt = it->begin(); wordIt != it->end(); ++wordIt )
CChat::AddChat( wordIt->key, wordIt->value );
}
return iModId;
}
//------------------------------------------------------------------------------------------------------------
const good::string* CConfiguration::GetGeneralSectionValue( const good::string& sKey )
{
good::ini_section& sect = m_iniFile["General"];
good::ini_section::iterator kv = sect.find(sKey);
return (kv == sect.end()) ? NULL : &kv->value;
}
void CConfiguration::SetGeneralSectionValue( const good::string& sKey, const good::string& sValue )
{
good::ini_section& sect = m_iniFile["General"];
sect[sKey] = sValue;
m_bModified = true;
}
//------------------------------------------------------------------------------------------------------------
TCommandAccessFlags CConfiguration::ClientAccessLevel( const good::string& sSteamId )
{
good::ini_section& sect = m_iniFile["User access"];
good::ini_section::iterator kv = sect.find(sSteamId);
if ( kv == sect.end() )
return 0;
int flags = CTypeToString::AccessFlagsFromString(kv->value);
return ( flags == -1 ) ? 0 : flags;
}
void CConfiguration::SetClientAccessLevel( const good::string& sSteamId, TCommandAccessFlags iAccess )
{
good::ini_section& sect = m_iniFile["User access"];
char buffer[10];
sprintf( buffer, "%d", iAccess );
sect[sSteamId] = good::string(buffer, true, true);
m_bModified = true;
}