Esempio n. 1
0
        public static SquadMsg GenerateMessageFromServerMessageObject(object messageObj)
        {
            Dictionary <string, object> dictionary = messageObj as Dictionary <string, object>;

            if (dictionary == null)
            {
                return(null);
            }
            SquadMsg squadMsg = new SquadMsg();

            if (dictionary.ContainsKey("notification"))
            {
                squadMsg = SquadMsgUtils.GenerateMessageFromNotifObject(dictionary["notification"]);
                if (dictionary.ContainsKey("guildId"))
                {
                    if (squadMsg.SquadData == null)
                    {
                        squadMsg.SquadData = new SqmSquadData();
                    }
                    squadMsg.SquadData.Id = Convert.ToString(dictionary["guildId"]);
                    if (dictionary.ContainsKey("guildName"))
                    {
                        squadMsg.SquadData.Name = WWW.UnEscapeURL(Convert.ToString(dictionary["guildName"]));
                    }
                }
                return(squadMsg);
            }
            if (dictionary.ContainsKey("serverTime"))
            {
                squadMsg.TimeSent = Convert.ToUInt32(dictionary["serverTime"]);
            }
            if (dictionary.ContainsKey("event"))
            {
                string name = Convert.ToString(dictionary["event"]);
                squadMsg.Type = StringUtils.ParseEnum <SquadMsgType>(name);
            }
            if (dictionary.ContainsKey("guildId"))
            {
                SqmSquadData sqmSquadData = new SqmSquadData();
                squadMsg.SquadData = sqmSquadData;
                sqmSquadData.Id    = Convert.ToString(dictionary["guildId"]);
                if (dictionary.ContainsKey("guildName"))
                {
                    sqmSquadData.Name = WWW.UnEscapeURL(Convert.ToString(dictionary["guildName"]));
                }
            }
            if (dictionary.ContainsKey("senderId"))
            {
                SqmFriendInviteData sqmFriendInviteData = new SqmFriendInviteData();
                squadMsg.FriendInviteData    = sqmFriendInviteData;
                sqmFriendInviteData.SenderId = Convert.ToString(dictionary["senderId"]);
                if (dictionary.ContainsKey("senderName"))
                {
                    sqmFriendInviteData.SenderName = Convert.ToString(dictionary["senderName"]);
                }
            }
            if (dictionary.ContainsKey("recipientId"))
            {
                if (squadMsg.FriendInviteData == null)
                {
                    squadMsg.FriendInviteData = new SqmFriendInviteData();
                }
                squadMsg.FriendInviteData.PlayerId = Convert.ToString(dictionary["recipientId"]);
            }
            if (dictionary.ContainsKey("warId"))
            {
                SqmWarEventData sqmWarEventData = new SqmWarEventData();
                squadMsg.WarEventData = sqmWarEventData;
                sqmWarEventData.WarId = Convert.ToString(dictionary["warId"]);
                if (dictionary.ContainsKey("empireName"))
                {
                    sqmWarEventData.EmpireSquadName = Convert.ToString(dictionary["empireName"]);
                }
                if (dictionary.ContainsKey("empireScore"))
                {
                    sqmWarEventData.EmpireScore = Convert.ToInt32(dictionary["empireScore"]);
                }
                if (dictionary.ContainsKey("rebelName"))
                {
                    sqmWarEventData.RebelSquadName = Convert.ToString(dictionary["rebelName"]);
                }
                if (dictionary.ContainsKey("rebelScore"))
                {
                    sqmWarEventData.RebelScore = Convert.ToInt32(dictionary["rebelScore"]);
                }
                if (dictionary.ContainsKey("buffBaseUid"))
                {
                    sqmWarEventData.BuffBaseUid = Convert.ToString(dictionary["buffBaseUid"]);
                }
                if (dictionary.ContainsKey("empireCrateTier"))
                {
                    sqmWarEventData.EmpireCrateId = Convert.ToString(dictionary["empireCrateTier"]);
                }
                else if (dictionary.ContainsKey("empireCrateId"))
                {
                    sqmWarEventData.EmpireCrateId = Convert.ToString(dictionary["empireCrateId"]);
                }
                if (dictionary.ContainsKey("rebelCrateTier"))
                {
                    sqmWarEventData.RebelCrateId = Convert.ToString(dictionary["rebelCrateTier"]);
                }
                else if (dictionary.ContainsKey("rebelCrateId"))
                {
                    sqmWarEventData.RebelCrateId = Convert.ToString(dictionary["rebelCrateId"]);
                }
            }
            if (dictionary.ContainsKey("level") || dictionary.ContainsKey("totalRepInvested"))
            {
                SquadMsgUtils.AddSquadLevelToSquadMessageData(dictionary, squadMsg);
            }
            if (dictionary.ContainsKey("perkId"))
            {
                SquadMsgUtils.AddPerkUnlockUpgrdeDataToSquadMessageData(dictionary, squadMsg);
            }
            return(squadMsg);
        }
Esempio n. 2
0
        public static SquadMsg GenerateMessageFromNotifObject(object notif)
        {
            Dictionary <string, object> dictionary = notif as Dictionary <string, object>;

            if (dictionary == null)
            {
                return(null);
            }
            SquadMsg squadMsg = new SquadMsg();

            if (dictionary.ContainsKey("id"))
            {
                squadMsg.NotifId = Convert.ToString(dictionary["id"]);
            }
            if (dictionary.ContainsKey("date"))
            {
                squadMsg.TimeSent = Convert.ToUInt32(dictionary["date"]);
            }
            if (dictionary.ContainsKey("type"))
            {
                string name = Convert.ToString(dictionary["type"]);
                squadMsg.Type = StringUtils.ParseEnum <SquadMsgType>(name);
            }
            if (dictionary.ContainsKey("playerId"))
            {
                SqmOwnerData sqmOwnerData = new SqmOwnerData();
                squadMsg.OwnerData    = sqmOwnerData;
                sqmOwnerData.PlayerId = Convert.ToString(dictionary["playerId"]);
                if (dictionary.ContainsKey("name"))
                {
                    sqmOwnerData.PlayerName = Convert.ToString(dictionary["name"]);
                }
            }
            if (dictionary.ContainsKey("message"))
            {
                SqmChatData sqmChatData = new SqmChatData();
                squadMsg.ChatData   = sqmChatData;
                sqmChatData.Message = WWW.UnEscapeURL(Convert.ToString(dictionary["message"]));
            }
            if (dictionary.ContainsKey("data"))
            {
                Dictionary <string, object> dictionary2 = dictionary["data"] as Dictionary <string, object>;
                if (dictionary2 != null)
                {
                    if (dictionary2.ContainsKey("senderName"))
                    {
                        SqmFriendInviteData sqmFriendInviteData = new SqmFriendInviteData();
                        squadMsg.FriendInviteData      = sqmFriendInviteData;
                        sqmFriendInviteData.SenderName = Convert.ToString(dictionary2["senderName"]);
                    }
                    if (dictionary2.ContainsKey("toRank"))
                    {
                        SqmMemberData sqmMemberData = new SqmMemberData();
                        squadMsg.MemberData = sqmMemberData;
                        string name2 = Convert.ToString(dictionary2["toRank"]);
                        sqmMemberData.MemberRole = StringUtils.ParseEnum <SquadRole>(name2);
                    }
                    if (dictionary2.ContainsKey("acceptor"))
                    {
                        SqmApplyData sqmApplyData = new SqmApplyData();
                        squadMsg.ApplyData      = sqmApplyData;
                        sqmApplyData.AcceptorId = Convert.ToString(dictionary2["acceptor"]);
                    }
                    if (dictionary2.ContainsKey("rejector"))
                    {
                        SqmApplyData sqmApplyData2 = new SqmApplyData();
                        squadMsg.ApplyData       = sqmApplyData2;
                        sqmApplyData2.RejectorId = Convert.ToString(dictionary2["rejector"]);
                    }
                    if (dictionary2.ContainsKey("battleId"))
                    {
                        SqmReplayData sqmReplayData = new SqmReplayData();
                        squadMsg.ReplayData    = sqmReplayData;
                        sqmReplayData.BattleId = Convert.ToString(dictionary2["battleId"]);
                        if (dictionary2.ContainsKey("battleVersion"))
                        {
                            sqmReplayData.BattleVersion = Convert.ToString(dictionary2["battleVersion"]);
                        }
                        if (dictionary2.ContainsKey("cmsVersion"))
                        {
                            sqmReplayData.CMSVersion = Convert.ToString(dictionary2["cmsVersion"]);
                        }
                        if (dictionary2.ContainsKey("type"))
                        {
                            string name3 = Convert.ToString(dictionary2["type"]);
                            sqmReplayData.BattleType = StringUtils.ParseEnum <SquadBattleReplayType>(name3);
                        }
                        if (dictionary2.ContainsKey("battleScoreDelta"))
                        {
                            object obj = dictionary2["battleScoreDelta"];
                            if (obj != null)
                            {
                                sqmReplayData.MedalDelta = Convert.ToInt32(obj);
                            }
                        }
                        if (dictionary2.ContainsKey("damagePercent"))
                        {
                            sqmReplayData.DamagePercent = Convert.ToInt32(dictionary2["damagePercent"]);
                        }
                        if (dictionary2.ContainsKey("stars"))
                        {
                            sqmReplayData.Stars = Convert.ToInt32(dictionary2["stars"]);
                        }
                        if (dictionary2.ContainsKey("opponentId"))
                        {
                            sqmReplayData.OpponentId = Convert.ToString(dictionary2["opponentId"]);
                        }
                        if (dictionary2.ContainsKey("opponentName"))
                        {
                            sqmReplayData.OpponentName = Convert.ToString(dictionary2["opponentName"]);
                        }
                        if (dictionary2.ContainsKey("opponentFaction"))
                        {
                            string name4 = Convert.ToString(dictionary2["opponentFaction"]);
                            sqmReplayData.OpponentFaction = StringUtils.ParseEnum <FactionType>(name4);
                        }
                        if (dictionary2.ContainsKey("faction"))
                        {
                            string name5 = Convert.ToString(dictionary2["faction"]);
                            sqmReplayData.SharerFaction = StringUtils.ParseEnum <FactionType>(name5);
                        }
                    }
                    if (dictionary2.ContainsKey("totalCapacity"))
                    {
                        SqmRequestData sqmRequestData = new SqmRequestData();
                        squadMsg.RequestData         = sqmRequestData;
                        sqmRequestData.TotalCapacity = Convert.ToInt32(dictionary2["totalCapacity"]);
                        if (dictionary2.ContainsKey("amount"))
                        {
                            sqmRequestData.StartingAvailableCapacity = Convert.ToInt32(dictionary2["amount"]);
                        }
                        if (dictionary2.ContainsKey("warId"))
                        {
                            sqmRequestData.WarId = Convert.ToString(dictionary2["warId"]);
                        }
                        if (dictionary2.ContainsKey("troopDonationLimit"))
                        {
                            sqmRequestData.TroopDonationLimit = Convert.ToInt32(dictionary2["troopDonationLimit"]);
                        }
                        else
                        {
                            Service.Logger.Error("Missing troop request data param: troopDonationLimitdefaulting to " + GameConstants.MAX_PER_USER_TROOP_DONATION);
                            sqmRequestData.TroopDonationLimit = GameConstants.MAX_PER_USER_TROOP_DONATION;
                        }
                    }
                    if (dictionary2.ContainsKey("troopsDonated"))
                    {
                        SqmDonationData sqmDonationData = new SqmDonationData();
                        squadMsg.DonationData = sqmDonationData;
                        Dictionary <string, object> dictionary3 = dictionary2["troopsDonated"] as Dictionary <string, object>;
                        if (dictionary3 != null)
                        {
                            sqmDonationData.Donations = new Dictionary <string, int>();
                            foreach (KeyValuePair <string, object> current in dictionary3)
                            {
                                string key   = current.Key;
                                int    value = Convert.ToInt32(current.Value);
                                sqmDonationData.Donations.Add(key, value);
                            }
                        }
                        if (dictionary2.ContainsKey("requestId"))
                        {
                            sqmDonationData.RequestId = Convert.ToString(dictionary2["requestId"]);
                        }
                        if (dictionary2.ContainsKey("recipientId"))
                        {
                            sqmDonationData.RecipientId = Convert.ToString(dictionary2["recipientId"]);
                        }
                        if (dictionary2.ContainsKey("amount"))
                        {
                            sqmDonationData.DonationCount = Convert.ToInt32(dictionary2["amount"]);
                        }
                    }
                    if (dictionary2.ContainsKey("warId"))
                    {
                        SqmWarEventData sqmWarEventData = new SqmWarEventData();
                        squadMsg.WarEventData = sqmWarEventData;
                        sqmWarEventData.WarId = Convert.ToString(dictionary2["warId"]);
                        if (dictionary2.ContainsKey("buffBaseUid"))
                        {
                            sqmWarEventData.BuffBaseUid = Convert.ToString(dictionary2["buffBaseUid"]);
                        }
                        if (dictionary2.ContainsKey("captured"))
                        {
                            sqmWarEventData.BuffBaseCaptured = Convert.ToBoolean(dictionary2["captured"]);
                        }
                        if (dictionary2.ContainsKey("opponentId"))
                        {
                            sqmWarEventData.OpponentId = Convert.ToString(dictionary2["opponentId"]);
                        }
                        if (dictionary2.ContainsKey("opponentName"))
                        {
                            sqmWarEventData.OpponentName = Convert.ToString(dictionary2["opponentName"]);
                        }
                        if (dictionary2.ContainsKey("stars"))
                        {
                            sqmWarEventData.StarsEarned = Convert.ToInt32(dictionary2["stars"]);
                        }
                        if (dictionary2.ContainsKey("victoryPoints"))
                        {
                            sqmWarEventData.VictoryPointsTaken = Convert.ToInt32(dictionary2["victoryPoints"]);
                        }
                        if (dictionary2.ContainsKey("attackExpirationDate"))
                        {
                            sqmWarEventData.AttackExpirationTime = Convert.ToUInt32(dictionary2["attackExpirationDate"]);
                        }
                    }
                    if (dictionary2.ContainsKey("level") || dictionary2.ContainsKey("totalRepInvested"))
                    {
                        SquadMsgUtils.AddSquadLevelToSquadMessageData(dictionary2, squadMsg);
                    }
                    if (dictionary2.ContainsKey("perkId"))
                    {
                        SquadMsgUtils.AddPerkUnlockUpgrdeDataToSquadMessageData(dictionary2, squadMsg);
                    }
                }
            }
            return(squadMsg);
        }