-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathSampConfigReader.cpp
73 lines (61 loc) · 1.35 KB
/
SampConfigReader.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
#include "SampConfigReader.hpp"
#include <fstream>
#include <algorithm>
SampConfigReader::SampConfigReader()
{
std::ifstream config_file("server.cfg");
while (config_file.good())
{
string line_buffer;
std::getline(config_file, line_buffer);
size_t cr_pos = line_buffer.find_first_of("\r\n");
if (cr_pos != string::npos)
line_buffer.erase(cr_pos);
m_FileContent.push_back(std::move(line_buffer));
}
}
bool SampConfigReader::GetVar(string varname, string &dest)
{
varname += ' ';
for (auto &i : m_FileContent)
{
if (i.find(varname) == 0)
{
dest = i.substr(varname.length());
return true;
}
}
return false;
}
bool SampConfigReader::GetVarList(string varname, vector<string> &dest)
{
dest.clear();
string data;
if (GetVar(std::move(varname), data) == false)
return false;
size_t
last_pos = 0,
current_pos = 0;
while (last_pos != string::npos)
{
if (last_pos != 0)
++last_pos;
current_pos = data.find(' ', last_pos);
dest.push_back(data.substr(last_pos, current_pos - last_pos));
last_pos = current_pos;
}
return dest.size() > 1;
}
bool SampConfigReader::GetGamemodeList(vector<string> &dest)
{
string
varname("gamemode"),
value;
unsigned int counter = 0;
while (GetVar(varname + std::to_string(counter), value))
{
dest.push_back(value.substr(0, value.find(' ')));
++counter;
}
return counter != 0;
}