Fixes for registerAndWait.

This commit is contained in:
Jonald Fyookball 2023-07-27 14:29:03 -04:00
parent 6c0dbfbde8
commit e91ac3d355
2 changed files with 22 additions and 10 deletions

View file

@ -199,6 +199,7 @@ class Connection {
Future<List<int>> recv_message2(SocketWrapper socketwrapper, {Duration? timeout}) async {
print ("START OF RECV2");
if (timeout == null) {
timeout = this.timeout;
}
@ -244,6 +245,7 @@ class Connection {
throw BadFrameError('Got a frame with msg_length=$messageLength > $MAX_MSG_LENGTH (max)');
}
/*
print("DEBUG recv_message2 3 - about to read the message body, messageLength: $messageLength");
print ("DEBUG recvfbuf len is ");
@ -252,12 +254,14 @@ class Connection {
print (bytesRead);
print ("message length is ");
print(messageLength);
*/
if (recvBuf.length == bytesRead && bytesRead == 12 + messageLength) {
final message = recvBuf.sublist(12, 12 + messageLength);
print("DEBUG recv_message2 4 - message received, length: ${message.length}");
print("DEBUG recv_message2 5 - message content: $message");
//print("DEBUG recv_message2 4 - message received, length: ${message.length}");
//print("DEBUG recv_message2 5 - message content: $message");
print ("END OF RECV2");
return message;
} else {
// Throwing exception if the length doesn't match

View file

@ -814,8 +814,6 @@ static double nextDoubleNonZero(Random rng) {
print('Possible tiers: $tierOutputs');
print ("CHECK socketwrapper 839");
socketwrapper.status();
safety_sum_in = sumInputsValue;
safety_exess_fees = excessFees;
return;
@ -825,6 +823,7 @@ static double nextDoubleNonZero(Random rng) {
Future<void> registerAndWait(SocketWrapper socketwrapper) async {
print ("DEBUG register and wait top.");
// msg can be different classes depending on which protobuf msg is sent.
dynamic? msg;
@ -866,6 +865,7 @@ static double nextDoubleNonZero(Random rng) {
var tiersStrings = {for (var entry in tierOutputs.entries) entry.key: (entry.key * 1e-8).toStringAsFixed(8).replaceAll(RegExp(r'0+$'), '')};
while (true) {
print ("RECEIVE LOOP 870............DEBUG");
var msg = await recv2(socketwrapper,['tierstatusupdate', 'fusionbegin'], timeout: Duration(seconds: 10));
var fieldInfoFusionBegin = msg.info_.byName["fusionbegin"];
@ -905,23 +905,31 @@ static double nextDoubleNonZero(Random rng) {
int? besttime;
int? besttimetier;
for (var entry in statuses.entries) {
double frac = entry.value.players / entry.value.min_players;
double frac = entry.value.players.toInt() / entry.value.minPlayers.toInt();
if (frac >= maxfraction) {
if (frac > maxfraction) {
maxfraction = frac;
maxtiers.clear();
}
maxtiers.add(entry.key);
maxtiers.add(entry.key.toInt());
}
if (entry.value.hasField('time_remaining')) {
int tr = entry.value.time_remaining;
var fieldInfoTimeRemaining = entry.value.info_.byName["timeRemaining"];
if (fieldInfoTimeRemaining == null) {
throw FusionError('Expected field not found in message: timeRemaining');
}
if (entry.value.hasField(fieldInfoTimeRemaining.tagNumber)) {
int tr = entry.value.timeRemaining.toInt();
if (besttime == null || tr < besttime) {
besttime = tr;
besttimetier = entry.key;
besttimetier = entry.key.toInt();
}
}
}
var displayBest = <String>[];
var displayMid = <String>[];
var displayQueued = <String>[];