From e91ac3d355545b94480b3df4f78910d12e1d8451 Mon Sep 17 00:00:00 2001 From: Jonald Fyookball Date: Thu, 27 Jul 2023 14:29:03 -0400 Subject: [PATCH] Fixes for registerAndWait. --- lib/services/cashfusion/connection.dart | 10 +++++++--- lib/services/cashfusion/fusion.dart | 22 +++++++++++++++------- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/lib/services/cashfusion/connection.dart b/lib/services/cashfusion/connection.dart index b9b4cc64b..970232855 100644 --- a/lib/services/cashfusion/connection.dart +++ b/lib/services/cashfusion/connection.dart @@ -199,6 +199,7 @@ class Connection { Future> 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 diff --git a/lib/services/cashfusion/fusion.dart b/lib/services/cashfusion/fusion.dart index bcb03ac5a..ecef0f855 100644 --- a/lib/services/cashfusion/fusion.dart +++ b/lib/services/cashfusion/fusion.dart @@ -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 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 = []; var displayMid = []; var displayQueued = [];