示例#1
0
        public static async Task <MinorExperienceEventRecord> Parse(JsonObject json)
        {
            MinorExperienceEventRecord record = new MinorExperienceEventRecord();
            JsonString characterId            = json["character_id"] as JsonString;
            JsonString otherId       = json["other_id"] as JsonString;
            JsonString loadoutId     = json["loadout_id"] as JsonString;
            JsonString experienceId  = json["experience_id"] as JsonString;
            JsonString timestamp     = json["timestamp"] as JsonString;
            var        characterTask = PS2APIUtils.GetCharacterName(characterId);
            var        otherTask     = PS2APIUtils.GetCharacterName(otherId);

            record.characterLoadout = PS2APIUtils.GetLoadoutName(loadoutId);

            long ts;

            if (timestamp == null || !long.TryParse(timestamp.InnerString, out ts))
            {
                ts = 0;
            }
            record.timestamp = ts;
            record.type      = GetExperienceType(experienceId?.InnerString);

            await Task.WhenAll(characterTask, otherTask);

            record.character = await characterTask;
            record.other     = await otherTask;
            return(record);
        }
示例#2
0
        async Task <MinorExperienceEventRecord> ProcessMinorExperienceRecord(JsonObject payload)
        {
            MinorExperienceEventRecord record = await MinorExperienceEventRecord.Parse(payload);

            foreach (var handler in handlers)
            {
                handlersLock.EnterReadLock();
                try
                {
                    handler.Handle(record);
                }
                finally
                {
                    handlersLock.ExitReadLock();
                }
            }

            return(record);
        }
示例#3
0
        /// <summary>
        /// Actual processing of the received message, identifying event type and further proceeding by that
        /// </summary>
        /// <param name="message"></param>
        async Task ProcessEventMessage(JsonObject message)
        {
            // check for only event message
            string type = (message["type"] as JsonString)?.InnerString;

            if (type == null || type != "serviceMessage")
            {
                return;
            }

            var    payload   = message["payload"];
            string eventType = (payload["event_name"] as JsonString)?.InnerString;

            // create particular event record and dispatch it further to consumers
            EventRecord record;

            switch (eventType)
            {
            case "Death":
                record = await ProcessDeathRecord(payload);

                break;

            case "GainExperience":
                string xpId = (payload?["experience_id"] as JsonString)?.InnerString;
                if (xpId == PS2APIConstants.ExperienceIdRevive || xpId == PS2APIConstants.ExperienceIdSquadRevive)
                {
                    record = await ProcessReviveRecord(payload, xpId);
                }
                else if (MinorExperienceEventRecord.GetExperienceType(xpId) != MinorExperienceEventRecord.ExperienceType.Unknown)
                {
                    record = await ProcessMinorExperienceRecord(payload);
                }
                else
                {
                    Program.Logger.Log($"Received unknown experience gained! {xpId}");
                    record = null;
                }
                break;

            case "PlayerLogin":
                record = await ProcessLoginRecord(payload);

                break;

            case "PlayerLogout":
                record = await ProcessLogoutRecord(payload);

                break;

            case "VehicleDestroy":
                record = await ProcessVehicleDestroyRecord(payload);

                break;

            default:
                Console.WriteLine($"Unknown event type! {eventType}");
                record = null;
                break;
            }

            // print human readable output to console
            if (record != null /* && !(record is MinorExperienceEventRecord)*/)
            {
                Program.Logger.Log(record.ToString(), record.timestamp);
            }
        }