private static void SendScoreToConnectedClients(Score score, int roundIndex, int diverIndex, SimhoppMessage.ClientAction action = SimhoppMessage.ClientAction.Ping) { if (_judgeClients == null) { return; } IPEndPoint toDelete = null; bool delete = false; //Skicka poƤng (eller status / request) till anslutna domarklienter foreach (IPEndPoint ipep in _judgeClients.Keys) { try { //Skapa statusmeddelande med runda/hopp SimhoppMessage.SimhoppStatus status = new SimhoppMessage.SimhoppStatus( roundIndex, diverIndex, null); SimhoppMessage msg; if (score == null) { msg = new SimhoppMessage(-2, action, "", 0, status); } else { msg = new SimhoppMessage(score.judge.Index((_presenter.Judges)), SimhoppMessage.ClientAction.SubmitScore, "", score.Points, status); } LogToServer("Send: " + msg.Serialize()); var sendData = Encoding.ASCII.GetBytes(msg.Serialize()); _server.Send(sendData, sendData.Length, ipep); } catch (Exception ex) { delete = true; ExceptionHandler.Handle(ex); } } if (delete && toDelete != null) { try { int judgeIndex = _judgeClients[toDelete]; _judgeClients.Remove(toDelete); _judges.Remove(judgeIndex); _presenter.LogoutClient(judgeIndex); } catch (Exception ex) { /* Ignore */ } } }
public static void BroadcastScore(Score score, int roundIndex, int diverIndex, SimhoppMessage.ClientAction action = SimhoppMessage.ClientAction.Ping) { if (_server == null) { return; } _serverThread = new Thread(() => SendScoreToConnectedClients(score, roundIndex, diverIndex, action)) { IsBackground = true }; _serverThread.Start(); }