Пример #1
0
        static public void RunCommand(CMDS command, byte argument, string sender)
        {
            switch (command)
            {
            case CMDS.StartListeningToLoop:
                if (!clients[sender].GetSources().Contains((int)argument))
                {
                    clients[sender].AddSource((int)argument);
                    loops[(int)argument].addListenerToLoop(sender);
                    UdpServer.Reply(CMD.GetCmdBytes(CMDS.TurnOnLoopListenLight, argument), clients[sender].endpoint);
                }
                break;

            case CMDS.StopListeningToLoop:
                if (clients[sender].GetSources().Contains((int)argument))
                {
                    clients[sender].RemoveSource((int)argument);
                    loops[(int)argument].removeListenerFromLoop(sender);
                    UdpServer.Reply(CMD.GetCmdBytes(CMDS.TurnOffLoopListenLight, argument), clients[sender].endpoint);
                }
                break;

            case CMDS.StartTalkingToLoop:
                // REMOVE TALKER FROM ALL LOOPS
                for (int i = 0; i < loops.Count; i++)
                {
                    if (loops[i].talkers.Contains(sender))
                    {
                        loops[i].removeTalkerFromLoop(sender);
                        clients[sender].destinations.Remove(i);
                        UdpServer.Reply(CMD.GetCmdBytes(CMDS.TurnOffLoopTalkFlash, (byte)i), clients[sender].endpoint);
                    }
                }

                if (!clients[sender].destinations.Contains((int)argument))
                {
                    clients[sender].destinations.Add((int)argument);
                    loops[(int)argument].addTalkerToLoop(sender);
                    UdpServer.Reply(CMD.GetCmdBytes(CMDS.TurnOnLoopTalkFlash, argument), clients[sender].endpoint);

                    // ACTIVATE ACTIVE-LIGHT FOR ALL USERS
                    foreach (KeyValuePair <string, Client> kvp in clients)
                    {
                        Client c = kvp.Value;

                        if (c.IsConnected() && kvp.Key != sender)
                        {
                            UdpServer.Reply(CMD.GetCmdBytes(CMDS.TurnOnLoopTalkLight, argument), c.endpoint);
                        }
                    }
                }

                // Check if loop is left without talkers
                for (int i = 0; i < loops.Count; i++)
                {
                    if (loops[i].talkers.Count == 0)
                    {
                        // No more talkers in this loop, turn of active talker light for all users
                        foreach (KeyValuePair <string, Client> kvp in clients)
                        {
                            Client c = kvp.Value;

                            if (c.IsConnected())
                            {
                                UdpServer.Reply(CMD.GetCmdBytes(CMDS.TurnOffLoopTalkLight, (byte)i), c.endpoint);
                            }
                        }
                    }
                }
                break;

            case CMDS.StopTalkingToLoop:
                if (clients[sender].destinations.Contains((int)argument))
                {
                    clients[sender].destinations.Remove((int)argument);
                    loops[(int)argument].removeTalkerFromLoop(sender);
                    UdpServer.Reply(CMD.GetCmdBytes(CMDS.TurnOffLoopTalkFlash, argument), clients[sender].endpoint);

                    // IF LOOP IS EMPTY BLANK TALK BUTTONS
                    if (loops[(int)argument].talkers.Count == 0)
                    {
                        foreach (KeyValuePair <string, Client> kvp in clients)
                        {
                            Client c = kvp.Value;

                            if (c.IsConnected())
                            {
                                UdpServer.Reply(CMD.GetCmdBytes(CMDS.TurnOffLoopTalkLight, argument), c.endpoint);
                            }
                        }
                    }
                }
                break;

            case CMDS.TurnOnLoopListenLight:
                if (lButtons.ContainsKey((int)argument))
                {
                    lButtons[(int)argument].Invoke(new Action(() => { lButtons[(int)argument].setLitState(true); }));
                }
                break;

            case CMDS.TurnOffLoopListenLight:
                if (lButtons.ContainsKey((int)argument))
                {
                    lButtons[(int)argument].Invoke(new Action(() => { lButtons[(int)argument].setLitState(false); }));
                }
                break;

            case CMDS.TurnOnLoopTalkLight:
                if (tButtons.ContainsKey((int)argument))
                {
                    tButtons[(int)argument].Invoke(new Action(() => { tButtons[(int)argument].setLitState(true); }));
                }
                break;

            case CMDS.TurnOffLoopTalkLight:
                if (tButtons.ContainsKey((int)argument))
                {
                    tButtons[(int)argument].Invoke(new Action(() => { tButtons[(int)argument].setLitState(false); }));
                }
                break;

            case CMDS.SetClientAudioFormat:
                clients[sender].audioFormat = (int)argument;
                clients[sender].decoder.SetFormat((int)argument);
                clients[sender].encoder.SetFormat((int)argument);
                break;


            case CMDS.Ping:
                UdpServer.Reply(CMD.GetCmdBytes(CMDS.Pong, (byte)0), clients[sender].endpoint);
                break;
            }
        }