aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.Client/StatsSyncher.h
blob: 843505bf6a0667065714cd4d28cce2c10aa8e516 (plain)
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
#pragma once
class File;
class StatsCounter;
class User;
class File;
class Stat;
using namespace std;

class StatsSyncher
{
private:
	static const int SAVE_INTERVAL = 20 * 5;
    static const int SEND_INTERVAL = 20 * 60;

    volatile bool busy;

    volatile unordered_map<Stat *, int> *serverStats;
    volatile unordered_map<Stat *, int> *failedSentStats;

    StatsCounter *statsCounter;
    File *unsentFile, *lastServerFile;
    File *unsentFileTmp, *lastServerFileTmp;
    File *unsentFileOld, *lastServerFileOld;
    User *user;

    int noSaveIn, noSendIn;

public:
	StatsSyncher(User *user, StatsCounter *statsCounter, File *dir);
private:
	void attemptRename(File *dir, const wstring& name, File *to);
    unordered_map<Stat *, int> *loadStatsFromDisk(File *file, File *tmp, File *old);
    unordered_map<Stat *, int> *loadStatsFromDisk(File *file);
    void doSend(unordered_map<Stat *, int> *stats);
    void doSave(unordered_map<Stat *, int> *stats, File *file, File *tmp, File *old);
protected:
	unordered_map<Stat *, int> *doGetStats();
public:
	void getStatsFromServer();
    void saveUnsent(unordered_map<Stat *, int> *stats);
    void sendUnsent(unordered_map<Stat *, int> *stats, unordered_map<Stat *, int> *fullStats);
    void forceSendUnsent(unordered_map<Stat *, int> *stats);
    void forceSaveUnsent(unordered_map<Stat *, int> *stats);
    bool maySave();
    bool maySend();
    void tick();
};