Beispiel #1
0
        public ConnectionListener(IPAddress host, uint port)
        {
            var listener = new TcpListener(host, (int)port);

            listener.Start();

            var thread = new Thread(() =>
            {
                while (!shutdownRequested)
                {
                    while (listener.Pending())
                    {
                        var session = new T();
                        session.OnAccept(listener.AcceptSocket());

                        OnNewSession?.Invoke(session);
                    }

                    Thread.Sleep(1);
                }

                listener.Stop();
            });

            thread.Start();
        }
Beispiel #2
0
        public ConnectionListener(IPAddress host, int port)
        {
            var listener = new TcpListener(host, port);

            listener.Start();

            Thread listenerThread = new Thread(async() =>
            {
                while (!shutdownRequested)
                {
                    var session = new T();
                    session.Accept(await listener.AcceptSocketAsync());

                    OnNewSession?.Invoke(session);
                }

                listener.Stop();
            });

            listenerThread.Start();
        }
 private void OnNewSession_callback(IntPtr session)
 {
     OnNewSession?.Invoke(this, manager.DistSessionInstanceManager.GetSession(session));
 }
Beispiel #4
0
        public void StartAsync(MediaDevice device = null)
        {
            RunningTask = Task.Run(() =>
            {
                IsRunning = true;
                string questSongDirectoryPath = null;

                if (device != null)
                {
                    var base_folder        = device.GetDirectories(@"\")[0];
                    questSongDirectoryPath = $"{base_folder}{Oculus.QuestSongDirectoryName}";
                }

                var file   = new FileInfo(SongLogFilePath);
                var length = file.Length;

                using var stream = File.Open(SongLogFilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                using var reader = new StreamReader(stream);

                var session = new Session();

                while (IsRunning)
                {
                    var line = reader.ReadLine();

                    var songLevelLineHint       = "LogTemp: Warning: Song level str";
                    var songNameLineHint        = "LogTemp: Loading song";
                    var songScoreDetailLineHint = "LogTemp: Warning: Notes missed :";
                    var songScoreLineHint       = "raw distance =";

                    if (line.Contains(songLevelLineHint))
                    {
                        session            = new Session();
                        session.Song.Level = line.Substring(line.IndexOf(songLevelLineHint) + songLevelLineHint.Length)
                                             .Trim(' ', '.');
                    }
                    else if (line.Contains(songScoreDetailLineHint))
                    {
                        //        LogTemp: Warning: Notes missed : 0 / Notes hit  : 784 / Notes not processed : 0 / hit accuracy : 0.015131 / percentage : 0.848690 / hit speed : 1077.700073 / percentage : 0.698357 / combos : 7
                        var startIndex      = line.IndexOf(songScoreDetailLineHint) + songScoreDetailLineHint.Length;
                        var endIndex        = line.IndexOf(" / Notes hit  : ");
                        session.NotesMissed =
                            int.Parse(line.Substring(startIndex, endIndex - startIndex).Trim(' ', '.'));

                        startIndex       = line.IndexOf(" / Notes hit  : ") + " / Notes hit  : ".Length;
                        endIndex         = line.IndexOf(" / Notes not processed : ");
                        session.NotesHit = int.Parse(line.Substring(startIndex, endIndex - startIndex).Trim(' ', '.'));

                        startIndex = line.IndexOf(" / Notes not processed : ") + " / Notes not processed : ".Length;
                        endIndex   = line.IndexOf(" / hit accuracy : ");
                        session.NotesNotProcessed =
                            int.Parse(line.Substring(startIndex, endIndex - startIndex).Trim(' ', '.'));

                        startIndex          = line.IndexOf(" / hit accuracy : ") + " / hit accuracy : ".Length;
                        endIndex            = line.IndexOf(" / percentage : ");
                        session.HitAccuracy = line.Substring(startIndex, endIndex - startIndex).Trim(' ', '.');

                        startIndex          = line.IndexOf(" / hit accuracy : ") + " / hit accuracy : ".Length;
                        endIndex            = startIndex + 9;
                        session.HitAccuracy = line.Substring(startIndex, endIndex - startIndex).Trim(' ', '.');

                        startIndex         = endIndex + 14;
                        endIndex           = startIndex + 9;
                        session.Percentage = line.Substring(startIndex, endIndex - startIndex).Trim(' ', '.');

                        startIndex       = endIndex + 14;
                        endIndex         = startIndex + 12;
                        session.HitSpeed = line.Substring(startIndex, endIndex - startIndex).Trim(' ', '.');

                        startIndex          = endIndex + 15;
                        endIndex            = startIndex + 8;
                        session.Percentage2 = line.Substring(startIndex, endIndex - startIndex).Trim(' ', '.');

                        startIndex     = endIndex + 12;
                        endIndex       = line.Length;
                        var content    = line.Substring(startIndex, endIndex - startIndex).Trim(' ', '.');
                        session.Combos = int.Parse(content);
                    }
                    else if (line.Contains(songNameLineHint))
                    {
                        var songOggPath = line.Substring(line.IndexOf(songNameLineHint) + songNameLineHint.Length)
                                          .Trim(' ', '.');
                        var songDirectoryPath = Path.GetDirectoryName(songOggPath);

                        // if log file is coming from quest, we need to download song before calculating hash file
                        if (device != null)
                        {
                            var songName         = songDirectoryPath.Split('\\').Last();
                            var tempDir          = Path.GetDirectoryName(SongLogFilePath);
                            var tempSongFolder   = tempDir + "\\" + songName;
                            var oculusSongFolder = questSongDirectoryPath + "\\" + songName;
                            if (!device.DirectoryExists(oculusSongFolder))
                            {
                                continue;
                            }
                            device.DownloadFolder(oculusSongFolder, tempSongFolder);
                            songDirectoryPath = tempSongFolder;
                        }

                        var songDirectory = new DirectoryInfo(songDirectoryPath);
                        if (!songDirectory.Exists)
                        {
                            continue;
                        }

                        var songDatFiles = songDirectory.EnumerateFiles("*.dat");

                        var filesHashs        = songDatFiles.Select(ComputeMd5).OrderBy(hash => hash);
                        var concatenatedHashs = string.Concat(filesHashs);

                        session.Song.Hash = ComputeMd5(concatenatedHashs);
                        Trace.WriteLine(
                            $"{DateTime.Now} - New file - Hash: {session.Song.Hash}; File: {songDirectoryPath}");
                    }
                    else if (line.Contains(songScoreLineHint))
                    {
                        var startIndex = line.IndexOf(songScoreLineHint) + songScoreLineHint.Length;
                        var endIndex   = line.IndexOf("and adjusted distance =");

                        session.Score = line.Substring(startIndex, endIndex - startIndex).Trim(' ', '.');

                        if (session.Song.Hash is null)
                        {
                            continue;
                        }
                        Trace.WriteLine(
                            $"{DateTime.Now} - New session - Hash: {session.Song.Hash}; Level: {session.Song.Level}; Score: {session.Score}");
                        OnNewSession?.Invoke(session);
                        line = reader.ReadLine();
                    }

                    while (reader.EndOfStream)
                    {
                        file = new FileInfo(SongLogFilePath);

                        if (file.Length < length)
                        {
                            stream.Seek(0, SeekOrigin.Begin);
                            reader.DiscardBufferedData();
                        }

                        length = file.Length;

                        Thread.Sleep(WaitForNewContentMilliseconds);

                        // there will be no new data once the end of file is reach for oculus log
                        if (device != null)
                        {
                            IsRunning = false;
                            return;
                        }
                    }
                }
            });

            // Waiting for oculus send score to finish before continuig and thus removing temp folder
            if (device != null)
            {
                RunningTask.Wait();
            }
        }
        private void ProcessEvent()
        {
            if (isEvent)
            {
                switch (eventTypeString)
                {
                case "LoginStateChangeEvent":
                    OnLoginStateChange?.Invoke(cookie, accountHandle, statusCode, statusString, state);
                    break;

                case "SessionNewEvent":
                    OnNewSession?.Invoke(cookie, accountHandle, eventSessionHandle, state, nameString, uriString);
                    break;

                case "SessionStateChangeEvent":
                    OnSessionStateChange?.Invoke(cookie, uriString, statusCode, statusString, eventSessionHandle, state, isChannel, nameString);
                    break;

                case "ParticipantStateChangeEvent":
                    OnParticipantStateChange?.Invoke(cookie, uriString, statusCode, statusString, state, nameString, displayNameString, participantType);
                    break;

                case "ParticipantPropertiesEvent":
                    OnParticipantProperties?.Invoke(cookie, uriString, statusCode, statusString, isLocallyMuted, isModeratorMuted, isSpeaking, volume, energy);
                    break;

                case "AuxAudioPropertiesEvent":
                    OnAuxAudioProperties?.Invoke(cookie, energy);
                    break;
                }
            }
            else
            {
                switch (actionString)
                {
                case "Connector.Create.1":
                    OnConnectorCreated?.Invoke(cookie, statusCode, statusString, connectorHandle);
                    break;

                case "Account.Login.1":
                    OnLogin?.Invoke(cookie, statusCode, statusString, accountHandle);
                    break;

                case "Session.Create.1":
                    OnSessionCreated?.Invoke(cookie, statusCode, statusString, sessionHandle);
                    break;

                case "Session.Connect.1":
                    OnSessionConnected?.Invoke(cookie, statusCode, statusString);
                    break;

                case "Session.Terminate.1":
                    OnSessionTerminated?.Invoke(cookie, statusCode, statusString);
                    break;

                case "Account.Logout.1":
                    OnAccountLogout?.Invoke(cookie, statusCode, statusString);
                    break;

                case "Connector.InitiateShutdown.1":
                    OnConnectorInitiateShutdown?.Invoke(cookie, statusCode, statusString);
                    break;

                case "Account.ChannelGetList.1":
                    OnAccountChannelGetList?.Invoke(cookie, statusCode, statusString);
                    break;

                case "Aux.GetCaptureDevices.1":
                    OnCaptureDevices?.Invoke(cookie, statusCode, statusString, nameString);
                    break;

                case "Aux.GetRenderDevices.1":
                    OnRenderDevices?.Invoke(cookie, statusCode, statusString, nameString);
                    break;
                }
            }
        }