private void HandleClanMemberInformation(ParseData pd)
        {
            DataReader dr = new DataReader(pd.Data);
            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];

            byte success = dr.ReadByte();
            if (success != 0)
            {
                m_warcraftProfileRequests.Remove(cookie);
                ProfileLookupFailedEventArgs profileFailed = new ProfileLookupFailedEventArgs(args.Username, args.Product) { EventData = pd };
                OnProfileLookupFailed(profileFailed);
                return;
            }

            string clanName = dr.ReadCString();
            ClanRank rank = (ClanRank)dr.ReadByte();
            DateTime joined = DateTime.FromFileTime(dr.ReadInt64());

            args.Clan = new ClanProfile(clanName, rank, joined);

            BncsPacket pck = new BncsPacket((byte)BncsPacketId.WarcraftGeneral);
            pck.InsertByte((byte)WarcraftCommands.ClanInfoRequest);
            pck.InsertInt32(cookie);
            pck.InsertDwordString(args.Profile.ClanTag, 0);
            pck.InsertDwordString(args.Product.ProductCode);
            Send(pck);

            BattleNetClientResources.IncomingBufferPool.FreeBuffer(pd.Data);
        }
Example #2
0
        private void HandleFriendUpdate(ParseData pd)
        {
            DataReader dr = new DataReader(pd.Data);
            byte entry = dr.ReadByte();
            if (m_friendsList.Count <= entry)
            {
                return;
            }
            FriendUser friend = m_friendsList[entry];
            friend.Status = (FriendStatus)dr.ReadByte();
            friend.LocationType = (FriendLocation)dr.ReadByte();
            string prodID = dr.ReadDwordString(0);
            friend.Location = dr.ReadCString();

            if (friend.LocationType != FriendLocation.Offline)
            {
                friend.Product = Product.GetByProductCode(prodID);
            }
            else
            {
                friend.Product = null;
            }

            FriendUpdatedEventArgs args = new FriendUpdatedEventArgs(friend) { EventData = pd };
            OnFriendUpdated(args);
        }
        private void HandleFriendMoved(ParseData pd)
        {
            DataReader dr = new DataReader(pd.Data);
            byte index = dr.ReadByte();
            byte newIndex = dr.ReadByte();

            FriendUser friend = m_friendsList[index];
            friend.Index = newIndex;
            m_friendsList.Insert(newIndex, friend);

            if (newIndex < index)
            {
                for (int i = newIndex + 1; i <= index; i++)
                {
                    m_friendsList[i].Index += 1;
                }
            }
            else if (newIndex > index)
            {
                for (int i = index; i < newIndex; i++)
                {
                    m_friendsList[i].Index -= 1;
                }
            }

            FriendMovedEventArgs args = new FriendMovedEventArgs(friend, newIndex) { EventData = pd };
            OnFriendMoved(args);
        }
        private static FriendUser __ParseNewFriend(DataReader dr, int i)
        {
            string acct = dr.ReadCString();
            FriendStatus status = (FriendStatus)dr.ReadByte();
            FriendLocation location = (FriendLocation)dr.ReadByte();
            string productID = dr.ReadDwordString(0);
            Product prod = null;
            string locationName = string.Empty;
            if (location == FriendLocation.Offline)
            {
                dr.Seek(1);
            }
            else
            {
                prod = Product.GetByProductCode(productID);
                locationName = dr.ReadCString();
            }

            FriendUser friend = new FriendUser(i, acct, status, location, prod, locationName);
            return friend;
        }
Example #5
0
        private void HandleClanInfo(ParseData pd)
        {
            DataReader dr = new DataReader(pd.Data);
            dr.Seek(1);
            string clanTag = dr.ReadDwordString(0);
            ClanRank rank = (ClanRank)dr.ReadByte();

            ClanMembershipEventArgs args = new ClanMembershipEventArgs(clanTag, rank);
            args.EventData = pd;
            OnClanMembershipReceived(args);

            BncsPacket pck = new BncsPacket((byte)BncsPacketId.ClanMemberList);
            pck.InsertInt32(Interlocked.Increment(ref m_clanCookie));
            Send(pck);
        }
Example #6
0
        private void HandleFriendsList(ParseData pd)
        {
            DataReader dr = new DataReader(pd.Data);
            int numEntries = dr.ReadByte();
            FriendUser[] list = new FriendUser[numEntries];
            for (int i = 0; i < numEntries; i++)
            {
                FriendUser friend = __ParseNewFriend(dr, i);
                list[i] = friend;
            }

            m_friendsList.AddRange(list);

            Debug.WriteLine("Received friends list; " + list.Length + " user on it.");

            FriendListReceivedEventArgs args = new FriendListReceivedEventArgs(list) { EventData = pd };
            OnFriendListReceived(args);
        }
Example #7
0
        private void HandleClanFindCandidates(ParseData pd)
        {
            DataReader dr = new DataReader(pd.Data);
            dr.Seek(4); // skip the cookie
            ClanCandidatesSearchStatus status = (ClanCandidatesSearchStatus)dr.ReadByte();
            int numCandidates = dr.ReadByte();
            string[] usernames = new string[numCandidates];
            for (int i = 0; i < numCandidates; i++)
            {
                usernames[i] = dr.ReadCString();
            }

            ClanCandidatesSearchEventArgs args = new ClanCandidatesSearchEventArgs(status, usernames);
            args.EventData = pd;
            OnClanCandidatesSearchCompleted(args);
        }
Example #8
0
        private void HandleClanRankChange(ParseData pd)
        {
            DataReader dr = new DataReader(pd.Data);
            int cookie = dr.ReadInt32();
            string userName = m_clanRankChangeToMemberList[cookie];
            m_clanRankChangeToMemberList.Remove(cookie);
            ClanRankChangeStatus status = (ClanRankChangeStatus)dr.ReadByte();

            ClanRankChangeEventArgs args = new ClanRankChangeEventArgs(userName, status) { EventData = pd };
            OnClanRankChangeResponseReceived(args);
        }
Example #9
0
        private void HandleClanInvitation(ParseData pd)
        {
            DataReader dr = new DataReader(pd.Data);
            int cookie = dr.ReadInt32();
            ClanInvitationResponse response = (ClanInvitationResponse)dr.ReadByte();

            ClanInvitationResponseEventArgs args = new ClanInvitationResponseEventArgs(cookie, response) { EventData = pd };
            OnClanInvitationResponseReceived(args);
        }
Example #10
0
        private void HandleClanRemoveMember(ParseData pd)
        {
            DataReader dr = new DataReader(pd.Data);
            int reqID = dr.ReadInt32();
            ClanMemberRemovalResponse response = (ClanMemberRemovalResponse)dr.ReadByte();

            ClanRemovalResponseEventArgs args = new ClanRemovalResponseEventArgs(reqID, response) { EventData = pd };
            OnClanRemovalResponse(args);
        }
Example #11
0
 // 0x73
 private void HandleDisbandClan(ParseData pd)
 {
     DataReader dr = new DataReader(pd.Data);
     dr.Seek(4);
     ClanResponseCode status = (ClanResponseCode)dr.ReadByte();
     ClanDisbandEventArgs args = new ClanDisbandEventArgs(status == ClanResponseCode.Success);
     args.EventData = pd;
     OnClanDisbandCompleted(args);
 }
Example #12
0
 private void HandleClanMakeChieftan(ParseData pd)
 {
     DataReader dr = new DataReader(pd.Data);
     dr.Seek(4);
     ClanChieftanChangeResult result = (ClanChieftanChangeResult)dr.ReadByte();
     ClanChieftanChangeEventArgs args = new ClanChieftanChangeEventArgs(result);
     args.EventData = pd;
     OnClanChangeChieftanCompleted(args);
 }
Example #13
0
        private void HandleNewsInfo(ParseData data)
        {
            DateTime UNIX_EPOCH = new DateTime(1970, 1, 1).ToUniversalTime();

            DataReader dr = new DataReader(data.Data);
            int numEntriesInPacket = dr.ReadByte();
            dr.ReadInt32(); // last login timestamp
            dr.Seek(8); // oldest news, newest news timestamps.
            //int oldestNews = dr.ReadInt32();
            //int newestNews = dr.ReadInt32();

            //DateTime oldestNewsDateUtc = UNIX_EPOCH + TimeSpan.FromSeconds(oldestNews);
            //DateTime oldestNewsDateLocal = oldestNewsDateUtc.ToLocalTime();
            //DateTime newestNewsDateUtc = UNIX_EPOCH + TimeSpan.FromSeconds(newestNews);
            //DateTime newestNewsDateLocal = newestNewsDateUtc.ToLocalTime();

            lock (m_news)
            {
                for (int i = 0; i < numEntriesInPacket; i++)
                {
                    int newsTS = dr.ReadInt32();
                    DateTime newsDateUtc = UNIX_EPOCH + TimeSpan.FromSeconds(newsTS);
                    if (newsTS == 0)
                        newsDateUtc = DateTime.UtcNow;

                    string text = dr.ReadCString();
                    NewsEntry news = new NewsEntry(newsDateUtc, text);
                    OnServerNews(new ServerNewsEventArgs(news));
                }

                BattleNetClientResources.IncomingBufferPool.FreeBuffer(data.Data);
            }
        }
Example #14
0
        // 0x72
        private void HandleClanCreationInvitation(ParseData pd)
        {
            DataReader dr = new DataReader(pd.Data);
            int cookie = dr.ReadInt32();
            string tag = dr.ReadDwordString(0);
            string name = dr.ReadCString();
            string inviter = dr.ReadCString();
            int inviteeCount = dr.ReadByte();
            string[] invitees = new string[inviteeCount];
            for (int i = 0; i < inviteeCount; i++)
            {
                invitees[i] = dr.ReadCString();
            }

            ClanFormationInvitationEventArgs args = new ClanFormationInvitationEventArgs(cookie, tag, name, inviter, invitees) { EventData = pd };
            OnClanFormationInvitationReceived(args);
        }
Example #15
0
        private void HandleClanMemberStatusChanged(ParseData pd)
        {
            DataReader dr = new DataReader(pd.Data);
            string userName = dr.ReadCString();
            if (m_clanList.ContainsKey(userName))
            {
                ClanMember member = m_clanList[userName];
                ClanRank rank = (ClanRank)dr.ReadByte();
                ClanMemberStatus status = (ClanMemberStatus)dr.ReadByte();
                string location = dr.ReadCString();
                member.Rank = rank;
                member.CurrentStatus = status;
                member.Location = location;

                ClanMemberStatusEventArgs args = new ClanMemberStatusEventArgs(member);
                args.EventData = pd;
                OnClanMemberStatusChanged(args);
            }
        }
Example #16
0
 private void HandleWarcraftGeneral(ParseData data)
 {
     DataReader dr = new DataReader(data.Data);
     WarcraftCommands cmd = (WarcraftCommands)dr.ReadByte();
     switch (cmd)
     {
         case WarcraftCommands.RequestLadderMap:
             HandleWarcraftRequestLadderMap(data, dr);
             break;
         case WarcraftCommands.UserInfoRequest:
             HandleWarcraftUserInfoRequest(data, dr);
             break;
         case WarcraftCommands.ClanInfoRequest:
             HandleWarcraftClanInfoRequest(dr);
             break;
         default:
             BattleNetClientResources.IncomingBufferPool.FreeBuffer(data.Data);
             break;
     }
 }
        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);
        }
        private void HandleProfile(ParseData pd)
        {
            DataReader dr = new DataReader(pd.Data);
            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];

            byte success = dr.ReadByte();
            if (success != 0)
            {
                m_warcraftProfileRequests.Remove(cookie);
                ProfileLookupFailedEventArgs profileFailed = new ProfileLookupFailedEventArgs(args.Username, args.Product) { EventData = pd };
                OnProfileLookupFailed(profileFailed);
                return;
            }

            string desc = dr.ReadCString();
            string location = dr.ReadCString();
            string tag = dr.ReadDwordString(0);

            WarcraftProfile profile = new WarcraftProfile(desc, location, tag);
            args.Profile = profile;
            if (!string.IsNullOrEmpty(tag))
            {
                BncsPacket pck = new BncsPacket((byte)BncsPacketId.ClanMemberInformation);
                pck.InsertInt32(cookie);
                pck.InsertDwordString(tag, 0);
                pck.InsertCString(args.Username);
                Send(pck);
            }
            else
            {
                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);
            }
            

            BattleNetClientResources.IncomingBufferPool.FreeBuffer(pd.Data);
        }
        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);
        }
Example #20
0
        private void HandleClanMemberList(ParseData pd)
        {
            DataReader dr = new DataReader(pd.Data);
            dr.Seek(4);
            byte memCount = dr.ReadByte();
            for (int i = 0; i < memCount; i++)
            {
                string userName = dr.ReadCString();
                ClanRank rank = (ClanRank)dr.ReadByte();
                ClanMemberStatus status = (ClanMemberStatus)dr.ReadByte();
                string location = dr.ReadCString();
                m_clanList.Add(userName, new ClanMember(userName, rank, status, location));

            }

            ClanMember[] members = new ClanMember[m_clanList.Count];
            m_clanList.Values.CopyTo(members, 0);

            ClanMemberListEventArgs args = new ClanMemberListEventArgs(members);
            args.EventData = pd;
            OnClanMemberListReceived(args);
        }
        private void HandleFriendRemoved(ParseData pd)
        {
            DataReader dr = new DataReader(pd.Data);
            byte index = dr.ReadByte();

            FriendUser removed = m_friendsList[index];
            m_friendsList.RemoveAt(index);

            for (int i = index; i < m_friendsList.Count; i++)
            {
                m_friendsList[i].Index -= 1;
            }

            FriendRemovedEventArgs args = new FriendRemovedEventArgs(removed) { EventData = pd };
            OnFriendRemoved(args);
        }
Example #22
0
        private void HandleClanMemberRankChange(ParseData pd)
        {
            DataReader dr = new DataReader(pd.Data);
            ClanRank old = (ClanRank)dr.ReadByte();
            ClanRank newRank = (ClanRank)dr.ReadByte();
            string memberName = dr.ReadCString();
            ClanMember member = null;
            if (m_clanList.ContainsKey(memberName))
                member = m_clanList[memberName];

            ClanMemberRankChangeEventArgs args = new ClanMemberRankChangeEventArgs(old, newRank, member);
            args.EventData = pd;
            OnClanMemberRankChanged(args);
        }
Example #23
0
        // 0x71
        private void HandleClanInviteMultiple(ParseData pd)
        {
            DataReader dr = new DataReader(pd.Data);
            dr.Seek(4); // cookie
            ClanResponseCode response = (ClanResponseCode)dr.ReadByte();
            ClanFormationEventArgs args = null;
            if (response == ClanResponseCode.Success)
            {
                args = new ClanFormationEventArgs();
            }
            else
            {
                List<string> names = new List<string>();
                int nextByte = dr.Peek();
                while (nextByte > 0)
                {
                    names.Add(dr.ReadCString());
                    nextByte = dr.Peek();
                }
                args = new ClanFormationEventArgs(response == ClanResponseCode.InvitationDeclined, response == ClanResponseCode.Decline, names.ToArray());
            }
            args.EventData = pd;

            OnClanFormationCompleted(args);
        }