-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsaveData.h
121 lines (120 loc) · 3.18 KB
/
saveData.h
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
#include "global.h"
#ifndef SAVEDATA_H_
#define SAVEDATA_H_
void saveData()
{
ofstream outss;
outss.open("clientData.txt", ios::out);
for (int i = 1; i <= DataSaveArry.size(); i++)
{
outss << DataSaveArry[i - 1].ClientWanIp
<< " " << DataSaveArry[i - 1].ClientLanIp
<< " " << DataSaveArry[i - 1].ClientConnectPort
<< " " << to_string(DataSaveArry[i - 1].OnlineTime)
<< " " << to_string(DataSaveArry[i - 1].OfflineTime)
<< " " << DataSaveArry[i - 1].SEID
<< endl;
}
outss.close();
}
void dataSave()
{
while (1)
{
if (dataIsChange)
{
saveData();
}
Sleep(5000);
}
}
void passData()
{
while (1)
{
if (!PassDataInit)
{
for (int i = 1; i <= ClientMap.size(); i++)
{
if (ClientMap[i - 1].state != ClientSocketFlagStruct::states::Use && ClientMap[i - 1].Offline != 0 && (ClientMap[i - 1].Offline - ClientMap[i - 1].Online) >= 3600)
{
delForId(i);
}
else
DataSaveArry.push_back(ClientMap[i - 1]);
}
Sleep(1000);
PassDataInit = true;
continue;
}
for (int i = 1; i <= ClientMap.size(); i++)
{
if (ClientMap[i - 1].state != ClientSocketFlagStruct::states::Use && ClientMap[i - 1].Offline != 0 && (ClientMap[i - 1].Offline - ClientMap[i - 1].Online) >= 3600)
{
delForId(i);
}
else
{
dataIsChange = true;
vector<ClientSocketFlagStruct>::iterator itr = find(DataSaveArry.begin(), DataSaveArry.end(), ClientMap[i - 1]);
if (itr != DataSaveArry.end())
{
DataSaveArry[distance(DataSaveArry.begin(), itr)] = ClientMap[i - 1];
}
}
}
Sleep(10000);
}
}
void loadData()
{
ifstream inss, inPassword;
inPassword.open("password.data", ios::in);
if (!inPassword)
{
ofstream out;
out.open("password.data", ios::out);
out.close();
inPassword.close();
exit(0);
}
else
{
inPassword >> password;
#ifdef _DEBUG
password = "1";
cout << "Load Password:" << password << endl;
#endif
}
inPassword.close();
inss.open("clientData.data", ios::in);
if (!inss)
{
ofstream out;
out.open("clientData.data", ios::out);
out.close();
inss.close();
return;
}
string wanip, lanip, port, OnlineTime, OfflineTime, SEID;
while (inss >> wanip >> lanip >> port >> OnlineTime >> OfflineTime >> SEID)
{
joinClient(wanip, lanip, port, stoi(OnlineTime), stoi(OfflineTime), SEID);
}
inss.close();
inss.open("serverConfig.config", ios::in);
if (!inss)
{
ofstream out;
out.open("serverConfig.config", ios::out);
out.close();
inss.close();
port = 6020;
return;
}
string portstr;
inss >> portstr;
ServerPort = stoi(portstr);
inss.close();
}
#endif