コード例 #1
0
ファイル: Main.cs プロジェクト: mikastamm/sound-mixer-server
 public void Close()
 {
     Console.WriteLine("\n##Stopping Server##");
     BroadcastReceiver.respondToNdRequests = false;
     Console.WriteLine("Broadcastreceiver disabled");
     ListenerFactory.listener.stopListening();
     audioManager.Close();
     ClientMangager.disconnectAllDevices();
     Console.WriteLine("##Server Stopped##\n");
 }
コード例 #2
0
        private void handleData(string recv)
        {
            Console.WriteLine("\nReceived " + recv);

            if (recv.StartsWith("DEVINFO"))
            {
                recv = recv.Substring("DEVINFO".Length);

                ClientInformation dev = new ClientInformation();
                dev = JSONManager.deserialize <ClientInformation>(recv);
                dev.LastConnected = DateTime.Now;
                dev.IP            = clientEP.Address.ToString();
                dev.Connected     = true;
                device            = dev;
            }
            else
            {
                if (recv.StartsWith("AUTH"))
                {
                    string encryptedPassword     = recv.Remove(0, 4);
                    string decryptedPasswordHash = decryptMessage(encryptedPassword);

                    if (AuthentificationManager.Instance.checkPasswordHash(decryptedPasswordHash))
                    {
                        device.verifiedUntil = DateTime.Now + AuthentificationManager.timeToReAuth;
                        Console.WriteLine("Client authenticated for another period");

                        if (string.IsNullOrEmpty(unprocessedReceiveUntilAuthentication))
                        {
                            return; //No data to handle
                        }
                        else
                        {
                            recv = unprocessedReceiveUntilAuthentication;
                        }

                        unprocessedReceiveUntilAuthentication = "";
                    }
                    else
                    {
                        Console.WriteLine("Wrong password\ngot:" + decryptedPasswordHash + "\nexp:" + AuthentificationManager.Instance.getPasswordHash());
                        send("AUTHWPW");//Code for Wrong Password
                        disconnect();
                    }
                }
                else if (AuthentificationManager.Instance.usesPassword && device.verifiedUntil < DateTime.Now)
                {
                    Console.WriteLine("Client Authentification Expired, requesting new authentication");
                    unprocessedReceiveUntilAuthentication = recv;
                    send("AUTH");
                    return;
                }

                if (device != null && ClientMangager.knownDevices.ContainsKey(device.id))
                {
                    ClientMangager.knownDevices[device.id] = device;
                }
                else
                {
                    if (device != null)
                    {
                        ClientMangager.knownDevices.Add(device.id, device);
                    }
                }
                ClientMangager.saveDevices();
                MainWindow.Instance.NotifyDeviceDatasetChanged();

                if (recv.Equals("GETAUDIOSESSIONS"))
                {
                    int sessionsSent = sendAllAudioSessions();
                    Console.WriteLine("\tSent " + sessionsSent + "Sessions");
                }
                else if (recv.StartsWith("EDIT"))
                {
                    recv = recv.Substring(4);
                    AudioSession session = JSONManager.deserialize <AudioSession>(recv).toSessionId();
                    Main.Instance.audioManager.updateChangedSession(session);
                }
                else if (recv.StartsWith("TRACK"))
                {
                    recv = recv.Substring(5);
                    sendVolumeBlacklist.Add(AudioSession.getSessionId(recv));
                }
                else if (recv.StartsWith("ENDTRACK"))
                {
                    recv = recv.Substring(8);
                    sendVolumeBlacklist.Remove(AudioSession.getSessionId(recv));
                    AudioSession session = Main.Instance.audioManager.getAudioSessionWithID(AudioSession.getSessionId(recv));
                }
                else
                {
                    Console.WriteLine("\nReceived unknown command: " + recv);
                }
            }
        }