-
Notifications
You must be signed in to change notification settings - Fork 1
/
configManager.cpp
94 lines (85 loc) · 2.17 KB
/
configManager.cpp
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
#include <deque>
#include <string>
#include <iostream>
#include <fstream>
#include "configManager.h"
using namespace std;
bool stringToBool(string i)
{
if(i == "enabled")
return true;
else
return false;
}
ConfigManager::ConfigManager()
{
this->m_isLoaded = this->loadFile();
}
bool ConfigManager::loadFile()
{
if(!this->m_isLoaded)
{
deque<std::string> lines;
deque<std::string> names;
deque<std::string> values;
string tmp;
std::string filename = "config.cfg";
std::ifstream file(filename.c_str());
if(file.is_open())
{
while(file)
{
tmp.clear();
getline(file, tmp,'\n');
lines.push_back(tmp);
}
file.close();
}
else
return false;
for(unsigned int i = 0; i < lines.size(); i++)
{
if(lines[i].find_first_of("=") != string::npos)
{
string name = lines[i];
if(name.find_first_of(" ") != string::npos)
{
name.erase(name.find_first_of(" "), name.size()-1);
}
names.push_back(name);
string value = lines[i];
value.erase(0,value.find_first_of("'")+1);
value.erase(value.find_first_of("'"), value.size()-1);
values.push_back(value);
}
}
for(unsigned int i = 0; i < names.size(); i++)
{
if(names[i] == "port")
this->port = atoi(values[i].data());
if(names[i] == "pvp")
this->pvp = stringToBool(values[i].data());
if(names[i] == "pzLock")
this->pzLock = atoi(values[i].data());
if(names[i] == "huntingLock")
this->huntingLock = atoi(values[i].data());
if(names[i] == "protectionLevel")
this->protectionLevel = atoi(values[i].data());
if(names[i] == "noDamageToPartyMembers")
this->noDamageToPartyMembers = stringToBool(values[i].data());
if(names[i] == "save")
this->save = stringToBool(values[i].data());
if(names[i] == "saveInterval")
this->saveInterval = atoi(values[i].data());
if(names[i] == "maxPlayers")
this->maxPlayers = atoi(values[i].data());
if(names[i] == "playerActionInterval")
this->playerActionInterval = atoi(values[i].data());
if(names[i] == "checkConnectionInterval")
this->checkConnectionInterval = atoi(values[i].data());
}
this->m_isLoaded = true;
return true;
}
return false;
}