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
|
#include "stdafx.h"
#include "Include\SenClientMain.h"
#include "Include\SenClientDynamicConfig.h"
#include "DynamicConfigurations.h"
MinecraftDynamicConfigurations::Dynamic_Config_Trial_Data MinecraftDynamicConfigurations::trialData;
bool MinecraftDynamicConfigurations::s_bFirstUpdateStarted = false;
bool MinecraftDynamicConfigurations::s_bUpdatedConfigs[MinecraftDynamicConfigurations::eDynamic_Config_Max];
MinecraftDynamicConfigurations::EDynamic_Configs MinecraftDynamicConfigurations::s_eCurrentConfig = MinecraftDynamicConfigurations::eDynamic_Config_Max;
size_t MinecraftDynamicConfigurations::s_currentConfigSize = 0;
size_t MinecraftDynamicConfigurations::s_dataWrittenSize = 0;
byte *MinecraftDynamicConfigurations::s_dataWritten = NULL;
void MinecraftDynamicConfigurations::Tick()
{
if(!s_bFirstUpdateStarted)
{
UpdateAllConfigurations();
s_bFirstUpdateStarted = true;
}
}
DWORD MinecraftDynamicConfigurations::GetTrialTime()
{
return trialData.trialTimeSeconds;
}
void MinecraftDynamicConfigurations::UpdateAllConfigurations()
{
for(DWORD i = 0; i < eDynamic_Config_Max; ++i)
{
s_bUpdatedConfigs[i] = false;
}
UpdateNextConfiguration();
}
void MinecraftDynamicConfigurations::UpdateNextConfiguration()
{
EDynamic_Configs update = eDynamic_Config_Max;
for(DWORD i = 0; i < eDynamic_Config_Max; ++i)
{
if(!s_bUpdatedConfigs[i])
{
update = (EDynamic_Configs)i;
break;
}
}
if( update < eDynamic_Config_Max )
{
UpdateConfiguration( update );
}
}
void MinecraftDynamicConfigurations::UpdateConfiguration(EDynamic_Configs id)
{
app.DebugPrintf("DynamicConfig: Attempting to update dynamic configuration %d\n", id);
HRESULT hr = Sentient::SenDynamicConfigGetSize( id, &s_currentConfigSize, &MinecraftDynamicConfigurations::GetSizeCompletedCallback, NULL);
switch(hr)
{
case S_OK:
s_eCurrentConfig = id;
//The server call was spawned successfully.
break;
case E_FAIL:
app.DebugPrintf("DynamicConfig: Failed to get size for config\n");
//Sentient failed to spawn the call to the server.
//An unknown error occurred. For more information, see the debug log that is available when you compile your application against the debug version of the library (SenCoreD.lib).
break;
case Sentient::SENTIENT_E_NOT_INITIALIZED:
app.DebugPrintf("DynamicConfig: Failed to get size for config as sentient not initialized\n");
//Sentient is not initialized. You must call SentientInitialize before you call this function.
break;
case E_POINTER:
app.DebugPrintf("DynamicConfig: Failed to get size for config as pointer is invalid\n");
//The out_size pointer is NULL.
break;
}
if(FAILED(hr) )
{
s_bUpdatedConfigs[s_eCurrentConfig] = true;
UpdateNextConfiguration();
}
}
void MinecraftDynamicConfigurations::GetSizeCompletedCallback(HRESULT taskResult, void *userCallbackData)
{
if( HRESULT_SUCCEEDED(taskResult) )
{
s_dataWritten = new byte[s_currentConfigSize];
HRESULT hr = Sentient::SenDynamicConfigGetBytes(
s_eCurrentConfig,
s_currentConfigSize,
&s_dataWrittenSize,
s_dataWritten,
&MinecraftDynamicConfigurations::GetDataCompletedCallback,
NULL
);
switch(hr)
{
case S_OK:
//The server call was spawned successfully.
break;
case E_FAIL:
app.DebugPrintf("DynamicConfig : Failed to get bytes for config\n");
//Sentient failed to spawn the call to the server.
//An unknown error occurred. For more information, see the debug log that is available when you compile your application against the debug version of the library (SenCoreD.lib).
break;
case Sentient::SENTIENT_E_NOT_INITIALIZED:
app.DebugPrintf("DynamicConfig : Failed to get bytes for config as sentient not initialized\n");
//Sentient is not initialized. You must call SentientInitialize before you call this function.
break;
case E_POINTER:
app.DebugPrintf("DynamicConfig: Failed to get bytes for config as pointer is NULL\n");
//The out_size pointer is NULL.
break;
}
if(FAILED(hr) )
{
s_bUpdatedConfigs[s_eCurrentConfig] = true;
UpdateNextConfiguration();
}
}
else
{
s_bUpdatedConfigs[s_eCurrentConfig] = true;
UpdateNextConfiguration();
app.DebugPrintf("MinecraftDynamicConfigurations::GetSizeCompletedCallback : FAILED\n");
}
}
void MinecraftDynamicConfigurations::GetDataCompletedCallback(HRESULT taskResult, void *userCallbackData)
{
if(HRESULT_SUCCEEDED(taskResult) && s_currentConfigSize == s_dataWrittenSize)
{
switch(s_eCurrentConfig)
{
case eDynamic_Config_Trial:
{
int version = *(int *)s_dataWritten;
switch(version)
{
case DYNAMIC_CONFIG_TRIAL_VERSION:
//case 1:
memcpy(&trialData,s_dataWritten+4,sizeof(_dynamic_config_trial_data_version1));
app.DebugPrintf("Updated dynamic config TRIAL: timer is %d\n", trialData.trialTimeSeconds);
break;
};
}
break;
};
}
else
{
app.DebugPrintf("MinecraftDynamicConfigurations::GetDataCompletedCallback : FAILED\n");
}
delete [] s_dataWritten;
s_dataWritten = NULL;
s_bUpdatedConfigs[s_eCurrentConfig] = true;
UpdateNextConfiguration();
}
|