Beispiel #1
0
        private static async Task HandleUploadRequest(WebSocketSession session, dynamic request)
        {
            using (var ticket = q.EnterQueue()) {
                var getContext  = ticket.GetContext();
                var clientQuery = session.ReceiveTextMessage();

                while (true)
                {
                    var completed = await Task.WhenAny(getContext, clientQuery,
                                                       Task.Delay(TimeSpan.FromSeconds(5)));

                    if (completed == getContext)
                    {
                        await getContext;                         // possible future use
                        // got context, upload starts
                        await session.SendObject(new { Status = "ReadyForUpload" });

                        var      uploadInfo = BsonDocument.Parse(await clientQuery.WithTimeout(ClientReadTimeout));
                        Overview overview;
                        if (uploadInfo["Status"] == "CustomMap")
                        {
                            overview = BsonSerializer.Deserialize <Overview>(uploadInfo["Overview"].AsBsonDocument);
                        }
                        else if (uploadInfo["Status"] == "DefaultMap")
                        {
                            overview = null;
                        }
                        else
                        {
                            throw new NotImplementedException();
                        }
                        Debug.WriteLine("omfg getting stream now");
                        var uploadStream = await session.ReceiveBinaryMessage();

                        Debug.WriteLine("SHIT SHIT SHIT GOT THE STREAM EVERYTHING IS AWESOME");

                        var demoFileName = Guid.NewGuid().ToString() + ".dem";
                        using (var dbStoreStream = File.Create(Path.Combine("demos", demoFileName)))
                            using (var tee = new DoubleBufferedTeeStream(uploadStream, dbStoreStream)) {                     // upload to "db" (file system) WHILE PARSING :D
                                var h = new Heatmap(Database, tee, overview);
                                h.OnRoundAnalysisFinished += async(analysis) => {
                                    var doc = new BsonDocument();
                                    doc["Status"]   = "AnalysisProgress";
                                    doc["Analysis"] = analysis.ToBsonDocument();
                                    await session.SendTextMessage(doc.ToJson(MongoJsonSettings));
                                };
                                var ana = h.ParseHeaderOnly();
                                ana.DemoFile = demoFileName;
                                Database.Save(ana);

                                var asDoc = new BsonDocument();
                                asDoc["Status"]   = "AnalysisStarted";
                                asDoc["Analysis"] = ana.ToBsonDocument();
                                await session.SendTextMessage(asDoc.ToJson(MongoJsonSettings));

                                h.ParseTheRest();
                            }

                        await session.SendObject(new { Status = "UploadComplete" });

                        break;
                    }
                    else if (completed == clientQuery)
                    {
                        // client query? wat? (we don't expect this)
                        // TODO: handle cancellation and stuff
                        throw new System.IO.InvalidDataException("protocol violation");
                    }
                    else
                    {
                        // still there. send them their current position.
                        await session.SendObject(new { Status = "InQueue", QueuePosition = ticket.QueuePosition });
                    }
                }
            }
        }
Beispiel #2
0
        void HandleRoundStart(object sender, RoundStartedEventArgs e)
        {
            foreach (var player in parser.PlayingParticipants)
            {
                var p = GetParticipant(player);
            }



            var CurrentRound = new RoundEventMap(Datastore);

            CurrentRound.CTScore = parser.CTScore;
            CurrentRound.TScore  = parser.TScore;
            CurrentRound.Maps    = new Dictionary <string, EventMap>()
            {
                { "TFlashes", TFlashes },
                { "CTFlashes", CTFlashes },
                { "CTSmokes", CTSmokes },
                { "TSmokes", TSmokes },
                { "CTHEs", CTNades },
                { "THEs", TNades },
                { "BothTeamsFire", Fire },
                { "TKillOrigin", TKillOrigin },
                { "CTKillOrigin", CTKillOrigin },
                { "TDeathPosition", TDeathPosition },
                { "CTDeathPosition", CTDeathPosition },
                { "THoldingPosition", THoldingPosition },
                { "CTHoldingPosition", CTHoldingPosition },
                { "TGoodFlashes", TGoodFlashes },
                { "CTGoodFlashes", CTGoodFlashes },
                { "TBadFlashes", TBadFlashes },
                { "CTBadFlashes", CTBadFlashes },
            };

            CurrentRound.Kills = Kills;


            analysis.Rounds.Add(CurrentRound);

            if (!analysis.IsFinished)
            {
                analysis.Progress = (double)parser.CurrentTick / parser.Header.PlaybackFrames;
            }

            if (OnRoundAnalysisFinished != null)
            {
                OnRoundAnalysisFinished(analysis);
            }
            Datastore.Save(analysis);

            roundNum++;

            TFlashes          = new EventMap();
            CTFlashes         = new EventMap();
            CTSmokes          = new EventMap();
            TSmokes           = new EventMap();
            CTNades           = new EventMap();
            TNades            = new EventMap();
            Fire              = new EventMap();
            TKillOrigin       = new EventMap();
            CTKillOrigin      = new EventMap();
            TDeathPosition    = new EventMap();
            CTDeathPosition   = new EventMap();
            CTHoldingPosition = new EventMap();
            THoldingPosition  = new EventMap();
            CTGoodFlashes     = new EventMap();
            TGoodFlashes      = new EventMap();
            CTBadFlashes      = new EventMap();
            TBadFlashes       = new EventMap();

            Kills = new KillMap();
        }