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);
        }
示例#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 HandleQueryRealms2(PD data)
        {
            DataReader dr = new DataReader(data.Data);
            dr.Seek(4);
            int count = dr.ReadInt32();
            RealmServer[] realms = new RealmServer[count];
            for (int i = 0; i < count; i++)
            {
                dr.Seek(4);
                string title = dr.ReadCString();
                string desc = dr.ReadCString();

                realms[i] = new RealmServer(title, desc);
            }

            AvailableRealmsEventArgs args = new AvailableRealmsEventArgs(realms) { EventData = data };
            OnRealmsRetrieved(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;
        }
        private void HandleLogonRealmEx(PD data)
        {
            DataReader dr = new DataReader(data.Data);
            m_mcpCookie = dr.ReadInt32();
            int status = dr.ReadInt32();
            m_mcpStatus = status;

            if (data.Length > 8)
            {
                m_mcpChunk1 = dr.ReadByteArray(8);
                byte[] ipAddress = dr.ReadByteArray(4);
                m_ip = new IPAddress(ipAddress);
                m_port = dr.ReadInt32();
                m_mcpChunk2 = dr.ReadByteArray(48);
                m_uniqueBnetName = dr.ReadCString();

                BattleNetClientResources.IncomingBufferPool.FreeBuffer(data.Data);
            }
            else
            {
                RealmFailedEventArgs args = new RealmFailedEventArgs((RealmFailureReason)status) { EventData = data };
                OnRealmConnectionFailed(args);
            }
        }
示例#6
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);
        }
示例#7
0
        private void HandleClanInvitationResponse(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();

            ClanInvitationEventArgs args = new ClanInvitationEventArgs(cookie, tag, name, inviter) { EventData = pd };
            OnClanInvitationReceived(args);
        }
示例#8
0
        private void HandleGetChannelList(ParseData data)
        {
            DataReader dr = new DataReader(data.Data);

            List<string> channelList = new List<string>();
            string channel;
            do
            {
                channel = dr.ReadCString();
                if (!string.IsNullOrEmpty(channel))
                    channelList.Add(channel);
            } while (!string.IsNullOrEmpty(channel));

            ChannelListEventArgs e = new ChannelListEventArgs(channelList.ToArray());
            e.EventData = data;
            OnChannelListReceived(e);

            if (!m_firstChannelList)
            {
                m_firstChannelList = true;

                BncsPacket pckJoinChan = new BncsPacket((byte)BncsPacketId.JoinChannel);
                if (m_settings.Client.Equals("D2DV", StringComparison.Ordinal) 
                    || m_settings.Client.Equals("D2XP", StringComparison.Ordinal))
                    pckJoinChan.InsertInt32((int)ChannelJoinFlags.Diablo2FirstJoin);
                else
                    pckJoinChan.InsertInt32((int)ChannelJoinFlags.FirstJoin);

                switch (m_settings.Client)
                {
                    case "STAR":
                    case "SEXP":
                    case "W2BN":
                    case "D2DV":
                    case "D2XP":
                    case "JSTR":
                        pckJoinChan.InsertCString(m_settings.Client);
                        break;
                    case "WAR3":
                    case "W3XP":
                        pckJoinChan.InsertCString("W3");
                        break;
                }

                Send(pckJoinChan);
            }
        }
示例#9
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);
        }
示例#10
0
        /// <summary>
        /// Executes the BnFTP request, downloading the file to where <see cref="BnFtpRequestBase.LocalFileName">LocalFileName</see>
        /// specifies, and closes the connection.
        /// </summary>
        /// <remarks>
        /// <para>By default, <c>LocalFileName</c> is the same name as the remote file, which will cause the file
        /// to be saved in the local application path.  The desired location of the file must be set before 
        /// <b>ExecuteRequest</b> is called.</para>
        /// </remarks>
        /// <exception cref="IOException">Thrown if the local file cannot be written.</exception>
        /// <exception cref="SocketException">Thrown if the remote host closes the connection prematurely.</exception>
        public override void ExecuteRequest()
        {
            DataBuffer buffer = new DataBuffer();
            buffer.InsertInt16((short)(33 + FileName.Length));
            buffer.InsertInt16(0x0100);
            buffer.InsertDwordString("IX86");
            buffer.InsertDwordString(Product);
            if (m_ad)
            {
                buffer.InsertInt32(m_adId);
                buffer.InsertDwordString(m_adExt);
            }
            else
            {
                buffer.InsertInt64(0);
            }
            // currently resuming is not supported
            buffer.InsertInt32(0);
            if (FileTime.HasValue)
            {
                buffer.InsertInt64(FileTime.Value.ToFileTimeUtc());
            }
            else
            {
                buffer.InsertInt64(0);
            }
            buffer.InsertCString(FileName);

            Socket sck = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            sck.Connect(Server, 6112);
            sck.Send(new byte[] { 2 });
            sck.Send(buffer.UnderlyingBuffer, 0, buffer.Count, SocketFlags.None);

            BattleNetClientResources.OutgoingBufferPool.FreeBuffer(buffer.UnderlyingBuffer);

            byte[] hdrLengthBytes = new byte[2];
            sck.Receive(hdrLengthBytes, 2, SocketFlags.None);

            int hdrLen = BitConverter.ToInt16(hdrLengthBytes, 0);
            Debug.WriteLine(hdrLen, "Header Length");
            byte[] hdrBytes = new byte[hdrLen - 2];
            sck.Receive(hdrBytes, hdrLen - 2, SocketFlags.None);
            DataReader rdr = new DataReader(hdrBytes);
            rdr.Seek(2);
            int fileSize = rdr.ReadInt32();
            this.FileSize = fileSize;
            rdr.Seek(8);
            long fileTime = rdr.ReadInt64();
            string name = rdr.ReadCString();
            if (string.Compare(name, FileName, StringComparison.OrdinalIgnoreCase) != 0 || FileSize == 0)
            {
                throw new FileNotFoundException(Resources.bnftp_filenotfound);
            }
            Debug.WriteLine(fileSize, "File Size");

            byte[] data = ReceiveLoop(sck, fileSize);
            sck.Close();

            FileStream fs = new FileStream(LocalFileName, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None);
            fs.SetLength(fileSize);
            fs.Write(data, 0, fileSize);
            fs.Flush();
            fs.Close();
            DateTime time = DateTime.FromFileTimeUtc(fileTime);
            File.SetLastWriteTimeUtc(LocalFileName, time);
        }
示例#11
0
        private void HandleCheckAd(ParseData data)
        {
            DataReader dr = new DataReader(data.Data);
            int adID = dr.ReadInt32();
            dr.Seek(4); // extension
            long filetime = dr.ReadInt64();
            DateTime ft = DateTime.FromFileTimeUtc(filetime);
            string filename = dr.ReadCString(Encoding.ASCII);
            string link = dr.ReadCString(Encoding.ASCII);

            AdChangedEventArgs args = new AdChangedEventArgs(adID, ft, filename, link);
            m_lastAd = adID;
            OnAdChanged(args);

            BattleNetClientResources.IncomingBufferPool.FreeBuffer(data.Data);
        }
示例#12
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);
        }
示例#13
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);
            }
        }
示例#14
0
        private void HandleAuthAccountLogonProof(ParseData data)
        {
            DataReader dr = new DataReader(data.Data);

            int status = dr.ReadInt32();
            byte[] m2 = dr.ReadByteArray(20);
            // 0 = success
            // 2 = incorrect password
            // 14 = success; register e-mail
            // 15 = custom error
            switch (status)
            {
                case 0:
                    // success
                    if (!m_nls.VerifyServerProof(m2))
                    {
                        //CloseWithError(BattleNet.LoginProofServerProofFailed);
                        OnError(new ErrorEventArgs(ErrorType.LoginServerProofFailed, Strings.LoginProofServerProofFailed, false));
                        EnterChat();
                    }
                    else
                    {
                        OnInformation(new InformationEventArgs(Strings.LoginProofSuccess));
                        OnLoginSucceeded(BaseEventArgs.GetEmpty(null));
                        EnterChat();
                    }
                    break;
                case 2:
                    CloseWithError(Strings.LoginProofClientProofFailed, ErrorType.InvalidUsernameOrPassword);
                    break;
                case 14:
                    if (!m_nls.VerifyServerProof(m2))
                    {
                        OnError(new ErrorEventArgs(ErrorType.LoginServerProofFailed, Strings.LoginProofServerProofFailed, false));
                        EnterChat();
                    }
                    else
                    {
                        OnInformation(new InformationEventArgs(Strings.LoginProofRegisterEmail));
                        EnterChat();
                    }
                    break;
                case 15:
                    CloseWithError(
                        string.Format(CultureInfo.CurrentCulture, Strings.LoginProofCustomError, dr.ReadCString()),
                        ErrorType.InvalidUsernameOrPassword
                    );
                    break;
            }

            BattleNetClientResources.IncomingBufferPool.FreeBuffer(data.Data);
        }
示例#15
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);
        }
示例#16
0
        private void HandleAuthCheck(ParseData data)
        {
            DataReader dr = new DataReader(data.Data);
            uint result = dr.ReadUInt32();
            string extraInfo = dr.ReadCString();

            BattleNetClientResources.IncomingBufferPool.FreeBuffer(data.Data);

            if (result == 0)
            {
                OnClientCheckPassed(BaseEventArgs.GetEmpty(null));
            }
            else
            {
                OnClientCheckFailed(new ClientCheckFailedEventArgs((ClientCheckFailureCause)result, extraInfo));
                Close();
                return;
            }

            ContinueLogin();
        }
示例#17
0
        private void HandleAuthInfo(ParseData data)
        {
            try
            {
                DataReader dr = new DataReader(data.Data);
                if (m_pingPck != null)
                {
                    Send(m_pingPck);
                    m_pingPck = null;
                }
                m_received0x50 = true;

                m_loginType = dr.ReadUInt32();
                m_srvToken = dr.ReadUInt32();
                m_udpVal = dr.ReadUInt32();
                m_mpqFiletime = dr.ReadInt64();
                m_versioningFilename = dr.ReadCString();
                m_usingLockdown = m_versioningFilename.StartsWith("LOCKDOWN", StringComparison.OrdinalIgnoreCase);

                int crResult = -1, exeVer = -1;
                string exeInfo = null;

                if (!m_usingLockdown)
                {
                    m_valString = dr.ReadCString();
                    int mpqNum = CheckRevision.ExtractMPQNumber(m_versioningFilename);
                    crResult = CheckRevision.DoCheckRevision(m_valString, new string[] { m_settings.GameExe, m_settings.GameFile2, m_settings.GameFile3 }, mpqNum);
                    exeVer = CheckRevision.GetExeInfo(m_settings.GameExe, out exeInfo);
                }
                else
                {
                    m_ldValStr = dr.ReadNullTerminatedByteArray();
                    string dllName = m_versioningFilename.Replace(".mpq", ".dll");

                    BnFtpVersion1Request req = new BnFtpVersion1Request(m_settings.Client, m_versioningFilename, null);
                    req.Server = m_settings.Gateway.ServerHost;
                    req.LocalFileName = Path.Combine(Path.GetTempPath(), m_versioningFilename);
                    req.ExecuteRequest();

                    string ldPath = null;
                    using (MpqArchive arch = MpqServices.OpenArchive(req.LocalFileName))
                    {
                        if (arch.ContainsFile(dllName))
                        {
                            ldPath = Path.Combine(Path.GetTempPath(), dllName);
                            arch.SaveToPath(dllName, Path.GetTempPath(), false);
                        }
                    }

                    m_ldDigest = CheckRevision.DoLockdownCheckRevision(m_ldValStr, new string[] { m_settings.GameExe, m_settings.GameFile2, m_settings.GameFile3 },
                                    ldPath, m_settings.ImageFile, ref exeVer, ref crResult);
                }

                m_prodCode = m_settings.Client;

                if (m_prodCode == "WAR3" ||
                    m_prodCode == "W3XP")
                {
                    m_w3srv = dr.ReadByteArray(128);

                    if (!NLS.ValidateServerSignature(m_w3srv, RemoteEP.Address.GetAddressBytes()))
                    {
                        OnError(new ErrorEventArgs(ErrorType.Warcraft3ServerValidationFailure, Strings.War3ServerValidationFailed, false));
                        //Close();
                        //return;
                    }
                }

                BattleNetClientResources.IncomingBufferPool.FreeBuffer(data.Data);

                CdKey key1, key2 = null;
                key1 = new CdKey(m_settings.CdKey1);
                if (m_prodCode == "D2XP" || m_prodCode == "W3XP")
                {
                    key2 = new CdKey(m_settings.CdKey2);
                }

                m_clientToken = unchecked((uint)new Random().Next());

                byte[] key1Hash = key1.GetHash(m_clientToken, m_srvToken);
                if (m_warden != null)
                {
                    try
                    {
                        if (!m_warden.InitWarden(BitConverter.ToInt32(key1Hash, 0)))
                        {
                            m_warden.UninitWarden();
                            OnError(new ErrorEventArgs(ErrorType.WardenModuleFailure, "The Warden module failed to initialize.  You will not be immediately disconnected; however, you may be disconnected after a short period of time.", false));
                            m_warden = null;
                        }
                    }
                    catch (Win32Exception we)
                    {
                        OnError(new ErrorEventArgs(ErrorType.WardenModuleFailure, "The Warden module failed to initialize.  You will not be immediately disconnected; however, you may be disconnected after a short period of time.", false));
                        OnError(new ErrorEventArgs(ErrorType.WardenModuleFailure, string.Format(CultureInfo.CurrentCulture, "Additional information: {0}", we.Message), false));
                        m_warden.UninitWarden();
                        m_warden = null;
                    }
                }

                BncsPacket pck0x51 = new BncsPacket((byte)BncsPacketId.AuthCheck);
                pck0x51.Insert(m_clientToken);
                pck0x51.Insert(exeVer);
                pck0x51.Insert(crResult);
                if (m_prodCode == "D2XP" || m_prodCode == "W3XP")
                    pck0x51.Insert(2);
                else
                    pck0x51.Insert(1);
                pck0x51.Insert(false);
                pck0x51.Insert(key1.Key.Length);
                pck0x51.Insert(key1.Product);
                pck0x51.Insert(key1.Value1);
                pck0x51.Insert(0);
                pck0x51.Insert(key1Hash);
                if (key2 != null)
                {
                    pck0x51.Insert(key2.Key.Length);
                    pck0x51.Insert(key2.Product);
                    pck0x51.Insert(key2.Value1);
                    pck0x51.Insert(0);
                    pck0x51.Insert(key2.GetHash(m_clientToken, m_srvToken));
                }

                if (m_usingLockdown)
                {
                    pck0x51.InsertByteArray(m_ldDigest);
                    pck0x51.InsertByte(0);
                }
                else
                    pck0x51.InsertCString(exeInfo);

                pck0x51.InsertCString(m_settings.CdKeyOwner);

                Send(pck0x51);
            }
            catch (Exception ex)
            {
                OnError(new ErrorEventArgs(ErrorType.General, "There was an error while initializing your client.  Refer to the exception message for more information.\n" + ex.ToString(), true));
                Close();
            }
        }
示例#18
0
        private void HandleLogonResponse2(ParseData data)
        {
            DataReader dr = new DataReader(data.Data);
            int success = dr.ReadInt32();
            if (success == 0)
            {
                OnLoginSucceeded(BaseEventArgs.GetEmpty(data));
                Product product = Product.GetByProductCode(m_settings.Client);
                if (product.UsesUdpPing)
                {
                    BncsPacket pck = new BncsPacket((byte)BncsPacketId.UdpPingResponse);
                    pck.InsertDwordString("bnet");
                    Send(pck);
                }

                EnterChat();
            }
            else
            {
                LoginFailureReason reason = LoginFailureReason.Unknown;
                switch (success)
                {
                    case 1: // account DNE
                        reason = LoginFailureReason.AccountDoesNotExist; break;
                    case 2: // invalid password
                        reason = LoginFailureReason.InvalidAccountOrPassword; break;
                    case 6: // account closed
                        reason = LoginFailureReason.AccountClosed; break;
                }
                LoginFailedEventArgs args = new LoginFailedEventArgs(reason, success, dr.ReadCString()) { EventData = data };
                OnLoginFailed(args);
            }
        }
示例#19
0
        private void HandleChatEvent(ParseData data)
        {
            DataReader dr = new DataReader(data.Data);
            ChatEventType type = (ChatEventType)dr.ReadInt32();
            int flags = dr.ReadInt32();
            int ping = dr.ReadInt32();
            dr.Seek(12);
            string user = dr.ReadCString();
            byte[] userInfo = dr.ReadNullTerminatedByteArray();
            string text = Encoding.ASCII.GetString(userInfo);

            switch (type)
            {
                case ChatEventType.UserInChannel:
                case ChatEventType.UserJoinedChannel:
                    ChatUser newUser = new ChatUser(user, ping, (UserFlags)flags, UserStats.Parse(user, userInfo));
                    if (m_namesToUsers.ContainsKey(user))
                    {
                        m_namesToUsers.Remove(user);
                    }
                    m_namesToUsers.Add(user, newUser);
                    UserEventArgs uArgs = new UserEventArgs(type, newUser);
                    HandleUserChatEvent(uArgs);
                    break;
                case ChatEventType.UserFlagsChanged:
                    if (m_namesToUsers.ContainsKey(user))
                    {
                        ChatUser changedUser = m_namesToUsers[user];
                        changedUser.Flags = (UserFlags)flags;
                        UserEventArgs updatedArgs = new UserEventArgs(type, changedUser);
                        HandleUserChatEvent(updatedArgs);
                    }
                    else if (m_channelName.Equals("The Void", StringComparison.OrdinalIgnoreCase))
                    {
                        ChatUser voidUser = new ChatUser(user, ping, (UserFlags)flags, UserStats.Parse(user, userInfo));
                        m_namesToUsers.Add(user, voidUser);
                        UserEventArgs voidArgs = new UserEventArgs(type, voidUser);
                        HandleUserChatEvent(voidArgs);
                    }
                    break;
                case ChatEventType.UserLeftChannel:
                    if (m_namesToUsers.ContainsKey(user))
                    {
                        ChatUser goneUser = m_namesToUsers[user];
                        UserEventArgs leftArgs = new UserEventArgs(type, goneUser);
                        HandleUserChatEvent(leftArgs);
                    }
                    break;
                case ChatEventType.Emote:
                case ChatEventType.Talk:
                case ChatEventType.WhisperReceived:
                case ChatEventType.WhisperSent:
                    ChatMessageEventArgs cmArgs = new ChatMessageEventArgs(type, (UserFlags)flags, user, Encoding.UTF8.GetString(userInfo));
                    HandleChatMessageEvent(cmArgs);
                    break;
                case ChatEventType.NewChannelJoined:
                    ServerChatEventArgs joinArgs = new ServerChatEventArgs(type, flags, text);
                    m_channelName = text;
                    m_namesToUsers.Clear();
                    OnJoinedChannel(joinArgs);
                    break;
                case ChatEventType.Broadcast:
                case ChatEventType.ChannelDNE:
                case ChatEventType.ChannelFull:
                case ChatEventType.ChannelRestricted: 
                case ChatEventType.Error:
                case ChatEventType.Information:
                    ServerChatEventArgs scArgs = new ServerChatEventArgs(type, flags, text);
                    HandleServerChatEvent(scArgs);
                    break;
            }

            BattleNetClientResources.IncomingBufferPool.FreeBuffer(data.Data);
        }
示例#20
0
        private void HandleUserProfileRequest(ParseData data)
        {
            DataReader dr = new DataReader(data.Data);
            int numAccounts = dr.ReadInt32(); // should always be 1; number of accounts
            if (numAccounts != 1)
            {
                Trace.WriteLine("BN# cannot handle more than one account per user profile request; quitting.");
                BattleNetClientResources.IncomingBufferPool.FreeBuffer(data.Data);
                return;
            }

            int numKeys = dr.ReadInt32();
            int requestID = dr.ReadInt32(); // request ID
            string[] keyValues = new string[numKeys];
            for (int i = 0; i < numKeys; i++)
            {
                keyValues[i] = dr.ReadCString(Encoding.UTF8);
            }

            if (m_profileRequests.ContainsKey(requestID))
            {
                UserProfileRequest req = m_profileRequests[requestID];
                int value = 0;
                foreach (UserProfileKey key in req.Keys)
                {
                    req[key] = keyValues[value++];
                }
                m_profileRequests.Remove(requestID);

                UserProfileEventArgs args = new UserProfileEventArgs(req) { EventData = data };
                OnUserProfileReceived(args);
            }
            else
            {
                Debug.WriteLine(requestID, "Unknown profile request response.");
                BattleNetClientResources.IncomingBufferPool.FreeBuffer(data.Data);
                return;
            }
        }
示例#21
0
 private void HandleClanMotd(ParseData pd)
 {
     DataReader dr = new DataReader(pd.Data);
     dr.Seek(8);
     string motd = dr.ReadCString();
     InformationEventArgs args = new InformationEventArgs(motd);
     args.EventData = pd;
     OnClanMessageOfTheDay(args);
 }
        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);
        }
示例#23
0
        private void HandleClanMemberRemoved(ParseData pd)
        {
            DataReader dr = new DataReader(pd.Data);
            string memberName = dr.ReadCString();
            ClanMember member = m_clanList[memberName];
            m_clanList.Remove(memberName);

            ClanMemberStatusEventArgs args = new ClanMemberStatusEventArgs(member) { EventData = pd };
            OnClanMemberRemoved(args);
        }
示例#24
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);
            }
        }
示例#25
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);
        }
        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);
        }
示例#27
0
        public override void ExecuteRequest()
        {
            DataBuffer buf1 = new DataBuffer();
            buf1.InsertInt16(20);
            buf1.InsertInt16(0x0200);
            buf1.InsertDwordString("IX86");
            buf1.InsertDwordString(Product);
            if (m_ad)
            {
                buf1.InsertInt32(m_adId);
                buf1.InsertDwordString(m_adExt);
            }
            else
            {
                buf1.InsertInt64(0);
            }

            Socket sck = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            sck.Connect(Server, 6112);

            sck.Send(new byte[] { 2 });
            sck.Send(buf1.UnderlyingBuffer, 0, buf1.Count, SocketFlags.None);

            NetworkStream ns = new NetworkStream(sck, false);
            DataReader rdr = new DataReader(ns, 4);
            int serverToken = rdr.ReadInt32();

            DataBuffer buf2 = new DataBuffer();
            buf2.InsertInt32(0); // no resuming
            if (FileTime.HasValue)
            {
                buf2.InsertInt64(FileTime.Value.ToFileTimeUtc());
            }
            else
            {
                buf2.InsertInt64(0);
            }

            int clientToken = new Random().Next();
            buf2.InsertInt32(clientToken);

            buf2.InsertInt32(m_key.Key.Length);
            buf2.InsertInt32(m_key.Product);
            buf2.InsertInt32(m_key.Value1);
            buf2.InsertInt32(0);
            buf2.InsertByteArray(m_key.GetHash(clientToken, serverToken));
            buf2.InsertCString(FileName);

            sck.Send(buf2.UnderlyingBuffer, 0, buf2.Count, SocketFlags.None);

            rdr = new DataReader(ns, 4);
            int msg2Size = rdr.ReadInt32() - 4;
            rdr = new DataReader(ns, msg2Size);

            this.FileSize = rdr.ReadInt32();
            rdr.Seek(8);
            long fileTime = rdr.ReadInt64();
            DateTime time = DateTime.FromFileTimeUtc(fileTime);
            string name = rdr.ReadCString();
            if (string.Compare(name, FileName, StringComparison.OrdinalIgnoreCase) != 0 || FileSize == 0)
            {
                throw new FileNotFoundException(Resources.bnftp_filenotfound);
            }

            byte[] data = ReceiveLoop(sck, FileSize);
            sck.Close();

            FileStream fs = new FileStream(LocalFileName, FileMode.OpenOrCreate, FileAccess.Write);
            fs.Write(data, 0, FileSize);
            fs.Flush();
            fs.Close();
        }
示例#28
0
        private void HandleEnterChat(ParseData data)
        {
            DataReader dr = new DataReader(data.Data);
            EnteredChatEventArgs e = new EnteredChatEventArgs(dr.ReadCString(), dr.ReadCString(), dr.ReadCString());
            m_uniqueUN = e.UniqueUsername;
            e.EventData = data;
            OnEnteredChat(e);

            if (m_settings.Client.Equals("WAR3", StringComparison.Ordinal) ||
                m_settings.Client.Equals("W3XP", StringComparison.Ordinal))
            {
                BncsPacket pck = new BncsPacket((byte)BncsPacketId.WarcraftGeneral);
                pck.InsertByte((byte)WarcraftCommands.IconListRequest);
                pck.InsertInt32(1);

                Send(pck);

                pck = new BncsPacket((byte)BncsPacketId.NewsInfo);
                pck.InsertInt32(0);
                Send(pck);

                RequestChannelList();
            }
        }