Exemplo n.º 1
0
        public static void KickJudge(int judgeIndex)
        {
            try
            {
                _judges.Remove(judgeIndex);
                _presenter.LogoutClient(judgeIndex);

                Console.WriteLine("Kick index: " + judgeIndex);
                foreach (IPEndPoint ipep in _judgeClients.Keys)
                {
                    Console.WriteLine("ipep: " + ipep.ToString());
                    Console.WriteLine("Index: " + _judgeClients[ipep]);
                    if (_judgeClients[ipep] == judgeIndex)
                    {
                        //Skapa terminate message...
                        SimhoppMessage msg;
                        msg = new SimhoppMessage(-2, SimhoppMessage.ClientAction.ServerTerminating);
                        var sendData = Encoding.ASCII.GetBytes(msg.Serialize());

                        //...och skicka
                        _server.Send(sendData, sendData.Length, ipep);

                        //Och ta bort den
                        _judgeClients.Remove(ipep);

                        //Sen break
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                /* Ignore */
            }
        }
Exemplo n.º 2
0
        public void ScoreRequested(SimhoppMessage msg)
        {
            CurrentRoundIndex = msg.Status.RoundIndex;
            CurrentDiverIndex = msg.Status.DiverIndex;

            _view.ToggleControls(true);
            _view.RedrawContestInfo(true);
        }
Exemplo n.º 3
0
        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 */
                }
            }
        }
Exemplo n.º 4
0
        public void StatusUpdated(SimhoppMessage msg)
        {
            while (CurrentDive.Scores.Count < CurrentEvent.Judges.Count && Mode == ViewMode.Standalone)
            {
                Thread.Sleep(100);
            }

            CurrentRoundIndex = msg.Status.RoundIndex;
            CurrentDiverIndex = msg.Status.DiverIndex;

            _view.RedrawContestInfo();
        }
Exemplo n.º 5
0
        private static SimhoppMessage AssignIdToJudge(SimhoppMessage msg, IPEndPoint ipep)
        {
            int index = 0;

            foreach (Judge judge in _presenter.Judges)
            {
                if (judge.Name == msg.Data)
                {
                    Guid guid = Guid.NewGuid();
                    _judges[index] = judge;

                    _judgeClients.Add(ipep, index);

                    SimhoppMessage.SimhoppStatus status = new SimhoppMessage.SimhoppStatus(0, 0, _presenter.CurrentEvent);
                    SimhoppMessage response             = new SimhoppMessage(-2, SimhoppMessage.ClientAction.AssignId, guid.ToString(), judge.Index(_presenter.Judges), status);
                    _presenter.AssignJudgeAsClient(index);
                    return(response);
                }
                index++;
            }
            return(SimhoppMessage.ErrorMessage("Judge not found"));
        }
Exemplo n.º 6
0
        private static void UdpListener()
        {
            try
            {
                _server = new UdpClient(60069); //60069
                _server.EnableBroadcast = true;
            }
            catch (Exception ex)
            {
                ExceptionHandler.Handle(ex);
            }

            while (true)
            {
                try
                {
                    if (_server == null)
                    {
                        return;
                    }

                    //Vänta på broadcast från klient
                    IPEndPoint ipep = new IPEndPoint(IPAddress.Any, 60069);

                    //Ta emot msg från klienten
                    byte[] data           = _server.Receive(ref ipep);
                    string receiveMessage = Encoding.ASCII.GetString(data, 0, data.Length);

                    SimhoppMessage msg = SimhoppMessage.Deserialize(receiveMessage);
                    SimhoppMessage response;

                    switch (msg.Action)
                    {
                    case SimhoppMessage.ClientAction.Ping:
                        response = SendContestStatus();
                        break;

                    case SimhoppMessage.ClientAction.Login:
                        if (_presenter.NewConnections)
                        {
                            response = AssignIdToJudge(msg, ipep);
                        }
                        else
                        {
                            response = new SimhoppMessage(-2, SimhoppMessage.ClientAction.NotAccepted);
                        }
                        break;

                    case SimhoppMessage.ClientAction.SubmitScore:
                        SubmitScore(msg);
                        response = new SimhoppMessage(-2, SimhoppMessage.ClientAction.Confirm);
                        break;

                    case SimhoppMessage.ClientAction.Logout:
                        LogoutClient(msg);
                        response = new SimhoppMessage(-2, SimhoppMessage.ClientAction.Confirm);
                        break;

                    default:
                        response = SimhoppMessage.ErrorMessage("Not implemented");
                        break;
                    }

                    //Svara
                    var responseData = Encoding.ASCII.GetBytes(response.Serialize());
                    _server.Send(responseData, responseData.Length, ipep);
                }
                catch (Exception ex)
                {
                    ExceptionHandler.Handle(ex);
                }
            }
        }
Exemplo n.º 7
0
 private static void SubmitScore(SimhoppMessage msg)
 {
     _presenter.SubmitClientScore(msg.Value, msg.Id, msg.Status.RoundIndex, msg.Status.DiverIndex);
     //_presenter.ScoreDive(msg.Value, msg.Id);
 }
Exemplo n.º 8
0
 private static void LogoutClient(SimhoppMessage msg)
 {
     _judges.Remove(msg.Id);
     _presenter.LogoutClient(msg.Id);
 }