コード例 #1
0
ファイル: WarcraftRaceRecord.cs プロジェクト: Mofsy/jinxbot
        /// <summary>
        /// Creates a new single <see>WarcraftRaceRecord</see>.
        /// </summary>
        /// <param name="race">The race represented by this record.</param>
        /// <param name="wins">The number of wins represented by this record.</param>
        /// <param name="losses">The number of losses represented by this record.</param>
        /// <exception cref="ArgumentOutOfRangeException">Thrown if <paramref name="wins"/> or 
        /// <paramref name="losses"/> are negative.</exception>
        /// <exception cref="InvalidEnumArgumentException">Thrown if <paramref name="race" />
        /// is not defined by <see>Warcraft3IconRace</see>.</exception>
        public WarcraftRaceRecord(Warcraft3IconRace race, int wins, int losses)
        {
            if (wins < 0)
                throw new ArgumentOutOfRangeException("wins");
            if (losses < 0)
                throw new ArgumentOutOfRangeException("losses");
            if (!Enum.IsDefined(typeof(Warcraft3IconRace), race))
                throw new InvalidEnumArgumentException("race", (int)race, typeof(Warcraft3IconRace));

            m_race = race;
            m_wins = wins;
            m_losses = losses;
        }
コード例 #2
0
        private void HandleWarcraftClanInfoRequest(DataReader dr)
        {
            int cookie = dr.ReadInt32();

            if (!m_warcraftProfileRequests.ContainsKey(cookie))
            {
                Debug.WriteLine(string.Format(CultureInfo.InvariantCulture, "Unable to locate profile request with cookie {0:x2}", cookie));
                return;
            }
            WarcraftProfileEventArgs args = m_warcraftProfileRequests[cookie];

            int recordCount = dr.ReadByte();

            WarcraftClanLadderRecord[] ladderRecords = new WarcraftClanLadderRecord[recordCount];
            for (int i = 0; i < recordCount; i++)
            {
                WarcraftClanLadderType ladderType = (WarcraftClanLadderType)dr.ReadInt32();
                int wins   = dr.ReadInt16();
                int losses = dr.ReadInt16();
                int level  = dr.ReadByte();
                int hrs    = dr.ReadByte();
                int xp     = dr.ReadInt16();
                int rank   = dr.ReadInt32();

                WarcraftClanLadderRecord record = new WarcraftClanLadderRecord(ladderType, wins, losses, level, hrs, xp, rank);
                ladderRecords[i] = record;
            }

            int raceRecordCount = dr.ReadByte();

            Warcraft3IconRace[]  raceOrder   = new Warcraft3IconRace[] { Warcraft3IconRace.Random, Warcraft3IconRace.Human, Warcraft3IconRace.Orc, Warcraft3IconRace.Undead, Warcraft3IconRace.NightElf, Warcraft3IconRace.Tournament };
            WarcraftRaceRecord[] raceRecords = new WarcraftRaceRecord[raceRecordCount];
            for (int i = 0; i < raceRecordCount; i++)
            {
                int wins   = dr.ReadInt16();
                int losses = dr.ReadInt16();

                WarcraftRaceRecord record = new WarcraftRaceRecord(raceOrder[i], wins, losses);
                raceRecords[i] = record;
            }

            args.Clan.SetStats(ladderRecords, raceRecords);

            BncsPacket pck = new BncsPacket((byte)BncsPacketId.WarcraftGeneral);

            pck.InsertByte((byte)WarcraftCommands.UserInfoRequest);
            pck.InsertInt32(cookie);
            pck.InsertCString(args.Username);
            pck.InsertDwordString(args.Product.ProductCode);
            Send(pck);
        }
コード例 #3
0
ファイル: Warcraft3Stats.cs プロジェクト: wjlafrance/jinxbot
        internal Warcraft3Stats(byte[] stats)
        {
            m_literal = Encoding.ASCII.GetString(stats);

            DataReader dr          = new DataReader(stats);
            string     productCode = dr.ReadDwordString(0);

            m_prod = Product.GetByProductCode(productCode);
            if (m_prod == null)
            {
                m_prod = Product.UnknownProduct;
            }

            if (stats.Length > 4)
            {
                dr.Seek(1);
                string iconInfo = dr.ReadDwordString((byte)' ');
                char   raceID   = iconInfo[2];
                if (RaceMap.ContainsKey(raceID))
                {
                    m_race = RaceMap[raceID];
                }
                else
                {
                    m_race = Warcraft3IconRace.Unknown;
                }

                m_iconTier = (int)(iconInfo[3] - '0');

                dr.Seek(1);
                string sLevel = dr.ReadTerminatedString(' ', Encoding.ASCII);
                int.TryParse(sLevel, out m_level);
                if (m_level == 0)
                {
                    m_level = 1;
                }

                try
                {
                    if (dr.Position < dr.Length)
                    {
                        m_clanTag = dr.ReadDwordString((byte)' ');
                    }
                }
                catch { }
            }
        }
コード例 #4
0
        /// <summary>
        /// Creates a new single <see>WarcraftRaceRecord</see>.
        /// </summary>
        /// <param name="race">The race represented by this record.</param>
        /// <param name="wins">The number of wins represented by this record.</param>
        /// <param name="losses">The number of losses represented by this record.</param>
        /// <exception cref="ArgumentOutOfRangeException">Thrown if <paramref name="wins"/> or
        /// <paramref name="losses"/> are negative.</exception>
        /// <exception cref="InvalidEnumArgumentException">Thrown if <paramref name="race" />
        /// is not defined by <see>Warcraft3IconRace</see>.</exception>
        public WarcraftRaceRecord(Warcraft3IconRace race, int wins, int losses)
        {
            if (wins < 0)
            {
                throw new ArgumentOutOfRangeException("wins");
            }
            if (losses < 0)
            {
                throw new ArgumentOutOfRangeException("losses");
            }
            if (!Enum.IsDefined(typeof(Warcraft3IconRace), race))
            {
                throw new InvalidEnumArgumentException("race", (int)race, typeof(Warcraft3IconRace));
            }

            m_race   = race;
            m_wins   = wins;
            m_losses = losses;
        }
コード例 #5
0
ファイル: Warcraft3Stats.cs プロジェクト: MusicDemon/BNSharp
        internal Warcraft3Stats(byte[] stats)
        {
            m_literal = Encoding.ASCII.GetString(stats);

            DataReader dr = new DataReader(stats);
            string productCode = dr.ReadDwordString(0);
            m_prod = Product.GetByProductCode(productCode);
            if (m_prod == null)
                m_prod = Product.UnknownProduct;

            if (stats.Length > 4)
            {
                dr.Seek(1);
                string iconInfo = dr.ReadDwordString((byte)' ');
                char raceID = iconInfo[2];
                if (RaceMap.ContainsKey(raceID))
                {
                    m_race = RaceMap[raceID];
                }
                else
                    m_race = Warcraft3IconRace.Unknown;

                m_iconTier = (int)(iconInfo[3] - '0');

                dr.Seek(1);
                string sLevel = dr.ReadTerminatedString(' ', Encoding.ASCII);
                int.TryParse(sLevel, out m_level);
                if (m_level == 0)
                    m_level = 1;

                try
                {
                    if (dr.Position < dr.Length)
                        m_clanTag = dr.ReadDwordString((byte)' ');
                }
                catch { }
            }
        }
コード例 #6
0
        private void HandleWarcraftUserInfoRequest(ParseData data, DataReader dr)
        {
            int cookie = dr.ReadInt32();

            if (!m_warcraftProfileRequests.ContainsKey(cookie))
            {
                Debug.WriteLine(string.Format(CultureInfo.InvariantCulture, "Unable to locate profile request with cookie {0:x2}", cookie));
                return;
            }
            WarcraftProfileEventArgs args = m_warcraftProfileRequests[cookie];

            string iconID = dr.ReadDwordString(0);

            args.Profile.IconID = iconID;

            int recordCount = dr.ReadByte();

            WarcraftLadderRecord[] ladderRecords = new WarcraftLadderRecord[recordCount];
            for (int i = 0; i < recordCount; i++)
            {
                WarcraftLadderType ladderType = (WarcraftLadderType)dr.ReadInt32();
                int wins   = dr.ReadInt16();
                int losses = dr.ReadInt16();
                int level  = dr.ReadByte();
                int hrs    = dr.ReadByte();
                int xp     = dr.ReadInt16();
                int rank   = dr.ReadInt32();

                WarcraftLadderRecord record = new WarcraftLadderRecord(ladderType, wins, losses, level, hrs, xp, rank);
                ladderRecords[i] = record;
            }

            int raceRecordCount = dr.ReadByte();

            Warcraft3IconRace[]  raceOrder   = new Warcraft3IconRace[] { Warcraft3IconRace.Random, Warcraft3IconRace.Human, Warcraft3IconRace.Orc, Warcraft3IconRace.Undead, Warcraft3IconRace.NightElf, Warcraft3IconRace.Tournament };
            WarcraftRaceRecord[] raceRecords = new WarcraftRaceRecord[raceRecordCount];
            for (int i = 0; i < raceRecordCount; i++)
            {
                int wins   = dr.ReadInt16();
                int losses = dr.ReadInt16();

                WarcraftRaceRecord record = new WarcraftRaceRecord(raceOrder[i], wins, losses);
                raceRecords[i] = record;
            }

            int teamRecordsCount = dr.ReadByte();

            ArrangedTeamRecord[] teamRecords = new ArrangedTeamRecord[teamRecordsCount];
            for (int i = 0; i < teamRecordsCount; i++)
            {
                ArrangedTeamType teamType = (ArrangedTeamType)dr.ReadInt32();
                int      wins             = dr.ReadInt16();
                int      losses           = dr.ReadInt16();
                int      level            = dr.ReadByte();
                int      hrs            = dr.ReadByte();
                int      xp             = dr.ReadInt16();
                int      rank           = dr.ReadInt32();
                long     ftLastGameplay = dr.ReadInt64();
                DateTime lastGamePlayed = DateTime.FromFileTime(ftLastGameplay);
                int      numPartners    = dr.ReadByte();
                string[] partnerList    = new string[numPartners];
                for (int p = 0; p < numPartners; p++)
                {
                    partnerList[p] = dr.ReadCString();
                }

                ArrangedTeamRecord record = new ArrangedTeamRecord(teamType, wins, losses, level, hrs, xp, rank, lastGamePlayed, partnerList);
                teamRecords[i] = record;
            }

            args.Profile.SetStats(ladderRecords, teamRecords, raceRecords);

            args.EventData = data;

            OnWarcraftProfileReceived(args);
        }
コード例 #7
0
        private void HandleWarcraftUserInfoRequest(ParseData data, DataReader dr)
        {
            int cookie = dr.ReadInt32();
            if (!m_warcraftProfileRequests.ContainsKey(cookie))
            {
                Debug.WriteLine(string.Format(CultureInfo.InvariantCulture, "Unable to locate profile request with cookie {0:x2}", cookie));
                return;
            }
            WarcraftProfileEventArgs args = m_warcraftProfileRequests[cookie];

            string iconID = dr.ReadDwordString(0);
            args.Profile.IconID = iconID;

            int recordCount = dr.ReadByte();
            WarcraftLadderRecord[] ladderRecords = new WarcraftLadderRecord[recordCount];
            for (int i = 0; i < recordCount; i++)
            {
                WarcraftLadderType ladderType = (WarcraftLadderType)dr.ReadInt32();
                int wins = dr.ReadInt16();
                int losses = dr.ReadInt16();
                int level = dr.ReadByte();
                int hrs = dr.ReadByte();
                int xp = dr.ReadInt16();
                int rank = dr.ReadInt32();

                WarcraftLadderRecord record = new WarcraftLadderRecord(ladderType, wins, losses, level, hrs, xp, rank);
                ladderRecords[i] = record;
            }

            int raceRecordCount = dr.ReadByte();
            Warcraft3IconRace[] raceOrder = new Warcraft3IconRace[] { Warcraft3IconRace.Random, Warcraft3IconRace.Human, Warcraft3IconRace.Orc, Warcraft3IconRace.Undead, Warcraft3IconRace.NightElf, Warcraft3IconRace.Tournament };
            WarcraftRaceRecord[] raceRecords = new WarcraftRaceRecord[raceRecordCount];
            for (int i = 0; i < raceRecordCount; i++)
            {
                int wins = dr.ReadInt16();
                int losses = dr.ReadInt16();

                WarcraftRaceRecord record = new WarcraftRaceRecord(raceOrder[i], wins, losses);
                raceRecords[i] = record;
            }

            int teamRecordsCount = dr.ReadByte();
            ArrangedTeamRecord[] teamRecords = new ArrangedTeamRecord[teamRecordsCount];
            for (int i = 0; i < teamRecordsCount; i++)
            {
                ArrangedTeamType teamType = (ArrangedTeamType)dr.ReadInt32();
                int wins = dr.ReadInt16();
                int losses = dr.ReadInt16();
                int level = dr.ReadByte();
                int hrs = dr.ReadByte();
                int xp = dr.ReadInt16();
                int rank = dr.ReadInt32();
                long ftLastGameplay = dr.ReadInt64();
                DateTime lastGamePlayed = DateTime.FromFileTime(ftLastGameplay);
                int numPartners = dr.ReadByte();
                string[] partnerList = new string[numPartners];
                for (int p = 0; p < numPartners; p++)
                    partnerList[p] = dr.ReadCString();

                ArrangedTeamRecord record = new ArrangedTeamRecord(teamType, wins, losses, level, hrs, xp, rank, lastGamePlayed, partnerList);
                teamRecords[i] = record;
            }

            args.Profile.SetStats(ladderRecords, teamRecords, raceRecords);

            args.EventData = data;

            OnWarcraftProfileReceived(args);
        }
コード例 #8
0
        private void HandleWarcraftClanInfoRequest(DataReader dr)
        {
            int cookie = dr.ReadInt32();
            if (!m_warcraftProfileRequests.ContainsKey(cookie))
            {
                Debug.WriteLine(string.Format(CultureInfo.InvariantCulture, "Unable to locate profile request with cookie {0:x2}", cookie));
                return;
            }
            WarcraftProfileEventArgs args = m_warcraftProfileRequests[cookie];

            int recordCount = dr.ReadByte();
            WarcraftClanLadderRecord[] ladderRecords = new WarcraftClanLadderRecord[recordCount];
            for (int i = 0; i < recordCount; i++)
            {
                WarcraftClanLadderType ladderType = (WarcraftClanLadderType)dr.ReadInt32();
                int wins = dr.ReadInt16();
                int losses = dr.ReadInt16();
                int level = dr.ReadByte();
                int hrs = dr.ReadByte();
                int xp = dr.ReadInt16();
                int rank = dr.ReadInt32();

                WarcraftClanLadderRecord record = new WarcraftClanLadderRecord(ladderType, wins, losses, level, hrs, xp, rank);
                ladderRecords[i] = record;
            }

            int raceRecordCount = dr.ReadByte();
            Warcraft3IconRace[] raceOrder = new Warcraft3IconRace[] { Warcraft3IconRace.Random, Warcraft3IconRace.Human, Warcraft3IconRace.Orc, Warcraft3IconRace.Undead, Warcraft3IconRace.NightElf, Warcraft3IconRace.Tournament };
            WarcraftRaceRecord[] raceRecords = new WarcraftRaceRecord[raceRecordCount];
            for (int i = 0; i < raceRecordCount; i++)
            {
                int wins = dr.ReadInt16();
                int losses = dr.ReadInt16();

                WarcraftRaceRecord record = new WarcraftRaceRecord(raceOrder[i], wins, losses);
                raceRecords[i] = record;
            }

            args.Clan.SetStats(ladderRecords, raceRecords);

            BncsPacket pck = new BncsPacket((byte)BncsPacketId.WarcraftGeneral);
            pck.InsertByte((byte)WarcraftCommands.UserInfoRequest);
            pck.InsertInt32(cookie);
            pck.InsertCString(args.Username);
            pck.InsertDwordString(args.Product.ProductCode);
            Send(pck);
        }