Skip to content

Commit 8b6f74f

Browse files
committed
2 parents f615472 + 70bc3c2 commit 8b6f74f

5 files changed

Lines changed: 64 additions & 54 deletions

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ f-run:
2323
e-run:
2424
${MAKE} --no-print-directory -C echo run
2525
clean:
26-
rm -f backend interscore frontend/script.js
26+
rm -f frontend/script.js MessageType.js MessageType.ts backend/interscore-backend

backend/main.c

Lines changed: 46 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -126,22 +126,23 @@ void handle_message(enum MessageType *msg, int msg_len, struct mg_connection * c
126126
log_msg(LOG, "Received a Input from con %lu: %d\n", con->id, *msg);
127127
switch (*msg) {
128128
// All of these cases should be forwarded to frontend
129-
case PLS_SEND_SIDES_SWITCHED:
130-
case PLS_SEND_GAMEPART:
131-
case PLS_SEND_GAMEINDEX:
132-
case PLS_SEND_IS_PAUSE:
133-
case PLS_SEND_TIME:
134-
case PLS_SEND_JSON:
135-
case PLS_SEND_OBS_REPLAY_ON:
136-
case PLS_SEND_OBS_STREAM_ON:
137-
case PLS_SEND_WIDGET_AD_ON:
138-
case PLS_SEND_WIDGET_GAMESTART_ON:
139-
case PLS_SEND_WIDGET_GAMEPLAN_ON:
140-
case PLS_SEND_WIDGET_LIVETABLE_ON:
141-
case PLS_SEND_WIDGET_SCOREBOARD_ON:
142-
case PLS_SEND_GAME_ACTION:
143-
case PLS_SEND_TIMESTAMP:
129+
case PLS_SEND_META:
130+
case PLS_SEND_META_GAME:
131+
case PLS_SEND_META_OBS:
132+
case PLS_SEND_META_WIDGETS:
133+
case PLS_SEND_META_TIME:
134+
case PLS_SEND_GAMES:
144135
case PLS_SEND_GAME:
136+
case PLS_SEND_GAMEACTIONS:
137+
case PLS_SEND_GAMEACTION:
138+
case PLS_SEND_FORMATS:
139+
case PLS_SEND_FORMAT:
140+
case PLS_SEND_TEAMS:
141+
case PLS_SEND_TEAM:
142+
case PLS_SEND_GROUPS:
143+
case PLS_SEND_GROUP:
144+
case PLS_SEND_TIMESTAMP:
145+
case PLS_SEND_JSON:
145146
log_msg(LOG, "clients.boss: %p\n", clients.boss);
146147
ws_send(clients.boss, (char *)msg, msg_len);
147148
break;
@@ -151,30 +152,30 @@ void handle_message(enum MessageType *msg, int msg_len, struct mg_connection * c
151152
ws_send(con, tmp, 2);
152153
break;
153154
}
154-
case DATA_OBS_STREAM_ON: {
155-
if (msg_len < 2) {
156-
log_msg(WARN, "Received DATA_OBS_STREAM_ON without data about the Status\n");
157-
break;
158-
}
159-
if (msg[1])
160-
obs_send_cmd("{\"op\": 6, \"d\": {\"requestType\": \"StartStream\", \"requestId\": \"1\"}}");
161-
else
162-
obs_send_cmd("{\"op\": 6, \"d\": {\"requestType\": \"StopStream\", \"requestId\": \"2\"}}");
163-
break;
164-
}
165-
case DATA_OBS_REPLAY_ON: {
166-
if (!replays_instant_working) break;
167-
if (msg_len < 2) {
168-
log_msg(WARN, "Received DATA_OBS_STREAM_ON without data about the Status\n");
169-
break;
170-
}
171-
if (msg[1])
172-
// Tell OBS to save replay buffer
173-
obs_send_cmd("{\"op\": 6, \"d\": {\"requestType\": \"SaveReplayBuffer\", \"requestId\": \"save_replay\"}}");
174-
else
175-
obs_switch_scene("live");
176-
break;
177-
}
155+
// case DATA_OBS_STREAM_ON: {
156+
// if (msg_len < 2) {
157+
// log_msg(WARN, "Received DATA_OBS_STREAM_ON without data about the Status\n");
158+
// break;
159+
// }
160+
// if (msg[1])
161+
// obs_send_cmd("{\"op\": 6, \"d\": {\"requestType\": \"StartStream\", \"requestId\": \"1\"}}");
162+
// else
163+
// obs_send_cmd("{\"op\": 6, \"d\": {\"requestType\": \"StopStream\", \"requestId\": \"2\"}}");
164+
// break;
165+
// }
166+
// case DATA_OBS_REPLAY_ON: {
167+
// if (!replays_instant_working) break;
168+
// if (msg_len < 2) {
169+
// log_msg(WARN, "Received DATA_OBS_STREAM_ON without data about the Status\n");
170+
// break;
171+
// }
172+
// if (msg[1])
173+
// // Tell OBS to save replay buffer
174+
// obs_send_cmd("{\"op\": 6, \"d\": {\"requestType\": \"SaveReplayBuffer\", \"requestId\": \"save_replay\"}}");
175+
// else
176+
// obs_switch_scene("live");
177+
// break;
178+
// }
178179
case IM_THE_BOSS:
179180
if (msg_len < 2 || !msg[1]) { log_msg(WARN, "Boss sent illegal message\n"); break;}
180181
if (clients.boss == con) {
@@ -192,11 +193,12 @@ void handle_message(enum MessageType *msg, int msg_len, struct mg_connection * c
192193
char tmp[2] = {DATA_IM_BOSS, true};
193194
ws_send(clients.boss, tmp, 2);
194195
break;
195-
case DATA_GAMEINDEX:
196-
log_msg(LOG, "Received DATA: Gameindex: %d\n", ((char *)msg)[1]);
197-
gameindex = msg[1];
198-
// Now we go into default
199-
__attribute__((fallthrough)); // silence compiler warning
196+
// TODO gameindex is now not available anymore
197+
// case DATA_GAMEINDEX:
198+
// log_msg(LOG, "Received DATA: Gameindex: %d\n", ((char *)msg)[1]);
199+
// gameindex = msg[1];
200+
// // Now we go into default
201+
// __attribute__((fallthrough)); // silence compiler warning
200202
default:
201203
for (Client *c = clients.first; c != NULL; c = c->next) {
202204
if (c->con == clients.boss && *msg != DATA_GAME) continue;

rentnerend/lib/lib.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
33
import 'dart:io';
44
import 'dart:convert';
55
import 'dart:async';
6+
import 'dart:math';
67
import 'package:path_provider/path_provider.dart';
78

89
import 'MessageType.dart';
@@ -343,6 +344,14 @@ List<int>? signalToMsg(MessageType msg, Matchday md, {int? additionalInfo, int?
343344
// DATA_IM_BOSS should not be send by us because we are not a server!
344345
}
345346

347+
final _rng = Random.secure();
348+
349+
int generateId() {
350+
final t = DateTime.now().millisecondsSinceEpoch; // ~41 bits
351+
final r = _rng.nextInt(1 << 7); // 7 random bits
352+
return (t << 7) | r;
353+
}
354+
346355
// Returns if b == wanted, else null
347356
// Why you ask? Its needed in md.dart in @JsonKey(toJson: boolOrNull) to omit default keys when writing to json
348357
// Why not a lambda function you ask? Guess what: fuck you, it doesnt work because comptime

rentnerend/lib/md.dart

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,16 +103,15 @@ class Matchday with _$Matchday {
103103
}
104104

105105
Matchday goalAdd(final int team, {final int? gameIndex, final void Function(MessageType, {int? additionalInfo, int? additionalInfo2, Matchday? md})? send = null}) {
106-
final Game g = games[gameIndex ?? meta.game.index];
107-
final int id = g.actions?.length ?? 0;
108-
109-
final GameActionChange change = GameActionChange.score(
110-
GameActionChangeScore(
111-
t1: team == 1 ? 1 : 0,
112-
t2: team == 2 ? 1 : 0
106+
final goalAction = GameAction.goal(
107+
id: generateId(),
108+
change: GameActionChange.score(
109+
GameActionChangeScore(
110+
t1: team == 1 ? 1 : 0,
111+
t2: team == 2 ? 1 : 0
112+
)
113113
)
114114
);
115-
final goalAction = GameAction.goal(id: id, change: change);
116115
return addGameAction(goalAction, gameIndex ?? meta.game.index, send: send);
117116
}
118117

rentnerend/lib/ws_client.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ abstract class WSClient {
108108
return;
109109
}
110110
Game newGame = md.games[index].copyWith(
111-
actions: (jsonDecode(utf8.decode(msg.sublist(1))) as List)
111+
actions: (jsonDecode(utf8.decode(msg.sublist(2))) as List)
112112
.map((e) => GameAction.fromJson(e as Map<String, dynamic>))
113113
.toList()
114114
);

0 commit comments

Comments
 (0)