25
25
public class AnalyticsClient {
26
26
27
27
public boolean UploadModel (AnalyticsModel model ) throws Exception {
28
+
29
+ model .Properties .putAll (ForgeAnalyticsConstants .CustomProperties );
30
+
28
31
Gson g = new Gson ();
29
32
String json = g .toJson (model );
30
33
31
34
return this .UploadModel (json );
32
35
}
33
36
34
- public boolean UploadModel (String json ) throws Exception {
37
+ private boolean UploadModel (String json ) throws Exception {
38
+
39
+ // Respect snooper settings...
40
+ if (!Minecraft .getMinecraft ().isSnooperEnabled ()) {
41
+ return false ;
42
+ }
43
+
35
44
System .out .println (json );
36
45
HttpClient httpClient = HttpClientBuilder .create ().build (); //Use this instead
37
46
38
47
try {
39
- HttpPost request = new HttpPost ("http://forgeanalytics.azurewebsites.net/api/Analytics" );
48
+ HttpPost request = new HttpPost (ForgeAnalyticsConstants . serverUrl );
40
49
41
50
StringEntity params =new StringEntity (json );
42
51
request .addHeader ("content-type" , "application/json" );
@@ -52,31 +61,18 @@ public boolean UploadModel(String json) throws Exception {
52
61
return true ;
53
62
}
54
63
55
- public String CreateClientStartupPing () {
56
- Gson g = new Gson ();
57
-
64
+ public AnalyticsModel CreateClientStartupPing () {
58
65
AnalyticsModel am = new AnalyticsModel ();
59
66
am .Table = ForgeAnalyticsConstants .pingClientTable ;
60
67
am .Properties = new HashMap <String , String >();
61
68
am .PartitionKey = ForgeAnalyticsConstants .pingClientStartCommand ;
62
69
am .ClientDateTimeEpoch = System .currentTimeMillis () / 1000L ;
63
70
am .Properties .putAll (this .getCommonValues ());
64
71
65
- /*try {
66
- // TODO figure this out...
67
- // am.Properties.put("UserHash", this.Anonymize(Minecraft.getMinecraft().thePlayer.getUniqueID().toString()));
68
- } catch (NoSuchAlgorithmException e) {
69
- // TODO Auto-generated catch block
70
- e.printStackTrace();
71
- }*/
72
-
73
- String json = g .toJson (am );
74
- return json ;
72
+ return am ;
75
73
}
76
74
77
- public String CreateServerStartupPing () {
78
- Gson g = new Gson ();
79
-
75
+ public AnalyticsModel CreateServerStartupPing () {
80
76
AnalyticsModel am = new AnalyticsModel ();
81
77
am .Table = ForgeAnalyticsConstants .pingServerTable ;
82
78
am .Properties = new HashMap <String , String >();
@@ -102,14 +98,11 @@ public String CreateServerStartupPing() {
102
98
am .Properties .put ("IsDemo" , Boolean .toString (server .isDemo ()));
103
99
am .Properties .put ("IsLanMode" , Boolean .toString (((IntegratedServer )server ).getPublic ()));
104
100
}
105
-
106
- String json = g .toJson (am );
107
- return json ;
101
+
102
+ return am ;
108
103
}
109
104
110
- public String CreateServerStoppedPing () {
111
- Gson g = new Gson ();
112
-
105
+ public AnalyticsModel CreateServerStoppedPing () {
113
106
AnalyticsModel am = new AnalyticsModel ();
114
107
am .Table = ForgeAnalyticsConstants .pingServerTable ;
115
108
am .Properties = new HashMap <String , String >();
@@ -136,36 +129,21 @@ public String CreateServerStoppedPing() {
136
129
am .Properties .put ("IsLanMode" , Boolean .toString (((IntegratedServer )server ).getPublic ()));
137
130
}
138
131
139
-
140
- String json = g .toJson (am );
141
- return json ;
132
+ return am ;
142
133
}
143
134
144
- public String CreateClientKeepAlivePing () {
145
- Gson g = new Gson ();
146
-
135
+ public AnalyticsModel CreateClientKeepAlivePing () {
147
136
AnalyticsModel am = new AnalyticsModel ();
148
137
am .Table = ForgeAnalyticsConstants .pingClientTable ;
149
138
am .Properties = new HashMap <String , String >();
150
139
am .PartitionKey = ForgeAnalyticsConstants .pingClientKeepAlive ;
151
140
am .ClientDateTimeEpoch = System .currentTimeMillis () / 1000L ;
152
141
am .Properties .putAll (this .getCommonValues ());
153
-
154
- try {
155
- // TODO figure this out...
156
- am .Properties .put ("UserHash" , this .Anonymize (Minecraft .getMinecraft ().thePlayer .getUniqueID ().toString ()));
157
- } catch (NoSuchAlgorithmException e ) {
158
- // TODO Auto-generated catch block
159
- e .printStackTrace ();
160
- }
161
-
162
- String json = g .toJson (am );
163
- return json ;
142
+
143
+ return am ;
164
144
}
165
145
166
- public String CreateServerKeepAlivePing () {
167
- Gson g = new Gson ();
168
-
146
+ public AnalyticsModel CreateServerKeepAlivePing () {
169
147
AnalyticsModel am = new AnalyticsModel ();
170
148
am .Table = ForgeAnalyticsConstants .pingServerTable ;
171
149
am .Properties = new HashMap <String , String >();
@@ -193,9 +171,7 @@ public String CreateServerKeepAlivePing() {
193
171
am .Properties .put ("IsLanMode" , Boolean .toString (((IntegratedServer )server ).getPublic ()));
194
172
}
195
173
196
-
197
- String json = g .toJson (am );
198
- return json ;
174
+ return am ;
199
175
}
200
176
201
177
@@ -209,6 +185,7 @@ private Map<String, String> getCommonValues() {
209
185
commonValues .put ("JavaMaxRAM" , Long .toString (Runtime .getRuntime ().maxMemory ()));
210
186
commonValues .put ("JavaAllocatedRAM" , Long .toString (Runtime .getRuntime ().totalMemory ()));
211
187
commonValues .put ("SessionID" , ForgeAnalyticsSingleton .getInstance ().SessionID );
188
+ commonValues .put ("AdID" , ForgeAnalyticsConstants .AdID );
212
189
commonValues .put ("MinecraftVersion" , Minecraft .getMinecraft ().getVersion ());
213
190
commonValues .put ("ForgeVersion" , ForgeVersion .getVersion ());
214
191
commonValues .put ("MCPVersion" , ForgeVersion .mcpVersion );
0 commit comments