Merge remote-tracking branch 'fyookball/fusion' into fusion

This commit is contained in:
sneurlax 2023-07-27 13:40:08 -05:00
commit 59379faa4c
2 changed files with 27 additions and 17 deletions

View file

@ -198,8 +198,9 @@ class Connection {
return recvBuf; return recvBuf;
} }
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;
} }
@ -247,8 +248,8 @@ class Connection {
'Got a frame with msg_length=$messageLength > $MAX_MSG_LENGTH (max)'); '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 ");
print(recvBuf.length); print(recvBuf.length);
@ -256,13 +257,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( //print("DEBUG recv_message2 4 - message received, length: ${message.length}");
"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

@ -779,14 +779,14 @@ class Fusion {
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;
} }
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;
@ -826,8 +826,8 @@ class Fusion {
}; };
while (true) { while (true) {
var msg = await recv2(socketwrapper, ['tierstatusupdate', 'fusionbegin'], print ("RECEIVE LOOP 870............DEBUG");
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"];
if (fieldInfoFusionBegin != null && if (fieldInfoFusionBegin != null &&
@ -865,23 +865,31 @@ class Fusion {
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>[];