forked from worthingtonse/CloudCoinCore4
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFrack_Fixer.cs
More file actions
260 lines (228 loc) · 13.2 KB
/
Frack_Fixer.cs
File metadata and controls
260 lines (228 loc) · 13.2 KB
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
using System;
using System.IO;
using System.Linq;
namespace Foundation
{
class Frack_Fixer
{
/* INSTANCE VARIABLES */
private FileUtils fileUtils;
private int totalValueToBank;
private int totalValueToFractured;
private int totalValueToCounterfeit;
private RAIDA raida;
/* CONSTRUCTORS */
public Frack_Fixer(FileUtils fileUtils, int timeout)
{
this.fileUtils = fileUtils;
raida = new RAIDA(timeout);
totalValueToBank = 0;
totalValueToCounterfeit = 0;
totalValueToFractured = 0;
}//constructor
public string fixOneGuidCorner(int raida_ID, CloudCoin cc, int corner, int[] trustedTriad) {
/*1. WILL THE BROKEN RAIDA FIX? check to see if it has problems echo, detect, or fix. */
if ( RAIDA_Status.failsFix[raida_ID] || RAIDA_Status.failsEcho[raida_ID] || RAIDA_Status.failsEcho[raida_ID])
{
Console.ForegroundColor = ConsoleColor.Red;
Console.Out.WriteLine("");
Console.Out.WriteLine( StringHolder.frackfixer_1 );// "RAIDA Fails Echo or Fix. Try again when RAIDA online.");
Console.Out.WriteLine("");
Console.ForegroundColor = ConsoleColor.White;
return "RAIDA Fails Echo or Fix. Try again when RAIDA online.";
}
else
{
/*2. ARE ALL TRUSTED RAIDA IN THE CORNER READY TO HELP?*/
// Console.Out.WriteLine("Fails echo 0 " + RAIDA_Status.failsEcho[trustedTriad[0]]);
// Console.Out.WriteLine("Fails echo 1 " + RAIDA_Status.failsEcho[trustedTriad[1]]);
// Console.Out.WriteLine("Fails echo 2 " + RAIDA_Status.failsEcho[trustedTriad[2]]);
// Console.Out.WriteLine("Fails failsDetect 0 " + RAIDA_Status.failsDetect[trustedTriad[0]]);
// Console.Out.WriteLine("Fails failsDetect 1 " + RAIDA_Status.failsDetect[trustedTriad[1]]);
// Console.Out.WriteLine("Fails failsDetect 2 " + RAIDA_Status.failsDetect[trustedTriad[2]]);
if ( !RAIDA_Status.failsEcho[trustedTriad[0]] || !RAIDA_Status.failsDetect[trustedTriad[0]] || !RAIDA_Status.failsEcho[trustedTriad[1]] || !RAIDA_Status.failsDetect[trustedTriad[1]] || !RAIDA_Status.failsEcho[trustedTriad[2]] || !RAIDA_Status.failsDetect[trustedTriad[2]] )
{
/*3. GET TICKETS AND UPDATE RAIDA STATUS TICKETS*/
string[] ans = { cc.ans[trustedTriad[0]], cc.ans[trustedTriad[1]], cc.ans[trustedTriad[2]] };
raida.get_Tickets(trustedTriad, ans, cc.nn, cc.sn, cc.getDenomination(), 3000);
/*4. ARE ALL TICKETS GOOD?*/
if (RAIDA_Status.hasTicket[trustedTriad[0]] && RAIDA_Status.hasTicket[trustedTriad[0]] && RAIDA_Status.hasTicket[trustedTriad[0]])
{
/*5.T YES, so REQUEST FIX*/
DetectionAgent da = new DetectionAgent(raida_ID, 5000);
Response fixResponse = da.fix( trustedTriad, RAIDA_Status.tickets[trustedTriad[0]], RAIDA_Status.tickets[trustedTriad[1]], RAIDA_Status.tickets[trustedTriad[2]], cc.ans[raida_ID] );
/*6. DID THE FIX WORK?*/
if (fixResponse.success) {
Console.ForegroundColor = ConsoleColor.Green;
Console.Out.WriteLine("");
Console.Out.WriteLine( "RAIDA" + raida_ID + StringHolder.frackfixer_2 );//" unfracked successfully.");
Console.Out.WriteLine("");
Console.ForegroundColor = ConsoleColor.White;
return "RAIDA" + raida_ID + " unfracked successfully.";
}
else
{
Console.ForegroundColor = ConsoleColor.Red;
Console.Out.WriteLine("");
Console.Out.WriteLine(StringHolder.frackfixer_3 + corner);//"RAIDA failed to accept tickets on corner " + corner);
Console.Out.WriteLine("");
Console.ForegroundColor = ConsoleColor.White;
return "RAIDA failed to accept tickets on corner " + corner;
}//end if fix respons was success or fail
}
else
{
Console.ForegroundColor = ConsoleColor.Red;
Console.Out.WriteLine("");
Console.Out.WriteLine(StringHolder.frackfixer_4 + corner);//"Trusted servers failed to provide tickets for corner " + corner);
Console.Out.WriteLine("");
Console.ForegroundColor = ConsoleColor.White;
return "Trusted servers failed to provide tickets for corner " + corner;//no three good tickets
}//end if all good
}//end if trused triad will echo and detect (Detect is used to get ticket)
Console.ForegroundColor = ConsoleColor.Red;
Console.Out.WriteLine("");
Console.Out.WriteLine(StringHolder.frackfixer_5 );//"One or more of the trusted triad will not echo and detect.So not trying.");
Console.Out.WriteLine("");
Console.ForegroundColor = ConsoleColor.White;
return "One or more of the trusted triad will not echo and detect. So not trying.";
}//end if RAIDA fails to fix.
}//end fix one
/* PUBLIC METHODS */
public int[] fixAll()
{
int[] results = new int[3];
String[] frackedFileNames = new DirectoryInfo(this.fileUtils.frackedFolder ).GetFiles().Select(o => o.Name).ToArray();
CloudCoin frackedCC;
if ( frackedFileNames.Length < 0) {
Console.ForegroundColor = ConsoleColor.Green;
Console.Out.WriteLine(StringHolder.frackfixer_6 );// "You have no fracked coins.");
Console.ForegroundColor = ConsoleColor.White;
}//no coins to unfrack
for ( int i = 0; i < frackedFileNames.Length; i++ )
{
Console.WriteLine(StringHolder.frackfixer_unfracking + (i+1) +" of " + frackedFileNames.Length);
try
{
frackedCC = fileUtils.loadOneCloudCoinFromJsonFile( this.fileUtils.frackedFolder + frackedFileNames[i] );
String value = frackedCC.aoid["fracked"];
// Console.WriteLine("Fracked Coin: ");
frackedCC.consoleReport();
CloudCoin fixedCC = fixCoin( frackedCC ); // Will attempt to unfrack the coin.
fixedCC.consoleReport();
switch (fixedCC.getFolder().ToLower())
{
case "bank":
this.totalValueToBank++;
this.fileUtils.overWrite(this.fileUtils.bankFolder, fixedCC);
this.deleteCoin(this.fileUtils.frackedFolder + frackedFileNames[i]);
Console.WriteLine(StringHolder.frackfixer_8);//"CloudCoin was moved to Bank.");
break;
case "counterfeit":
this.totalValueToCounterfeit++;
this.fileUtils.overWrite(this.fileUtils.counterfeitFolder, fixedCC);
this.deleteCoin(this.fileUtils.frackedFolder + frackedFileNames[i]);
Console.WriteLine(StringHolder.frackfixer_9);//"CloudCoin was moved to Trash.");
break;
default://Move back to fracked folder
this.totalValueToFractured++;
this.deleteCoin(this.fileUtils.frackedFolder + frackedFileNames[i]);
this.fileUtils.overWrite(this.fileUtils.frackedFolder, fixedCC);
Console.WriteLine(StringHolder.frackfixer_10);//"CloudCoin was moved back to Fraked folder.");
break;
}
// end switch on the place the coin will go
}
catch (FileNotFoundException ex)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(ex);
Console.ForegroundColor = ConsoleColor.White;
}
catch (IOException ioex)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(ioex);
Console.ForegroundColor = ConsoleColor.White;
} // end try catch
}// end for each file name that is fracked
results[0] = this.totalValueToBank;
results[1] = this.totalValueToCounterfeit; // System.out.println("Counterfeit and Moved to trash: "+totalValueToCounterfeit);
results[2] = this.totalValueToFractured; // System.out.println("Fracked and Moved to Fracked: "+ totalValueToFractured);
return results;
}// end fix all
// End select all file names in a folder
public bool deleteCoin(String path)
{
bool deleted = false;
// System.out.println("Deleteing Coin: "+path + this.fileName + extension);
try
{
File.Delete(path);
}
catch (Exception e)
{
Console.WriteLine(e);
}
return deleted;
}//end delete coin
public CloudCoin fixCoin(CloudCoin brokeCoin)
{
/*0. RESET TICKETS IN RAIDA STATUS TO EMPTY*/
RAIDA_Status.resetTickets();
/*0. RESET THE DETECTION to TRUE if it is a new COIN */
RAIDA_Status.newCoin();
brokeCoin.setAnsToPans();// Make sure we set the RAIDA to the cc ans and not new pans.
DateTime before = DateTime.Now;
String fix_result = "";
FixitHelper fixer;
/*START*/
/*1. PICK THE CORNER TO USE TO TRY TO FIX */
int corner = 1;
// For every guid, check to see if it is fractured
for (int raida_ID = 0; raida_ID < 25; raida_ID++)
{
// Console.WriteLine("Past Status for " + raida_ID + ", " + brokeCoin.pastStatus[raida_ID]);
if (brokeCoin.getPastStatus(raida_ID).ToLower() == "fail")
{
Console.ForegroundColor = ConsoleColor.Cyan;
Console.Out.WriteLine("");
Console.WriteLine(StringHolder.frackfixer_11 );//"Attempting to fix RAIDA " + raida_ID);
Console.Out.WriteLine("");
Console.ForegroundColor = ConsoleColor.White;
fixer = new FixitHelper(raida_ID, brokeCoin.ans);
//trustedServerAns = new String[] { brokeCoin.ans[fixer.currentTriad[0]], brokeCoin.ans[fixer.currentTriad[1]], brokeCoin.ans[fixer.currentTriad[2]] };
corner = 1;
while (!fixer.finnished)
{
Console.WriteLine( StringHolder.frackfixer_12 + corner );//" Using corner " + corner);
fix_result = fixOneGuidCorner(raida_ID, brokeCoin, corner, fixer.currentTriad);
// Console.WriteLine(" fix_result: " + fix_result + " for corner " + corner);
if (fix_result.Contains("success"))
{
//Fixed. Do the fixed stuff
brokeCoin.setPastStatus("pass", raida_ID);
fixer.finnished = true;
corner = 1;
}
else
{
//Still broken, do the broken stuff.
corner++;
fixer.setCornerToCheck(corner);
}
}//End whild fixer not finnished
}//end if RAIDA past status is passed and does not need to be fixed
}//end for each AN
DateTime after = DateTime.Now;
TimeSpan ts = after.Subtract(before);
Console.WriteLine(StringHolder.frackfixer_13);//"Time spent fixing RAIDA in milliseconds: " + ts.Milliseconds);
brokeCoin.calculateHP();//how many fails did it get
brokeCoin.gradeCoin();
// sets the grade and figures out what the file extension should be (bank, fracked, counterfeit, lost
brokeCoin.calcExpirationDate();
brokeCoin.grade();
return brokeCoin;
}// end fix coin
}//end class
}//end namespace