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

View file

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