Пример #1
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();
            }
        }
Пример #2
0
        /// <summary>
        /// Responds to a clan invitation received via the <see>ClanInvitationReceived</see> event.
        /// </summary>
        /// <param name="invitation">The arguments that accompanied the invitation.</param>
        /// <param name="accept"><see langword="true" /> to accept the invitation and join the clan; otherwise <see langword="false" />.</param>
        /// <remarks>
        /// <para>Following the acceptance of an invitation, the client should receive <see>ClanMembershipReceived</see> and automatically respond by requesting clan
        /// membership information.</para>
        /// </remarks>
        public void RespondToClanInvitation(ClanInvitationEventArgs invitation, bool accept)
        {
            BncsPacket pck = new BncsPacket((byte)BncsPacketId.ClanInvitationResponse);

            pck.InsertInt32(invitation.RequestID);
            pck.InsertDwordString(invitation.ClanTag);
            pck.InsertCString(invitation.Inviter);
            pck.InsertByte(accept ? (byte)6 : (byte)4);

            Send(pck);
        }
Пример #3
0
        /// <summary>
        /// Responds to the invitation to form a new clan.
        /// </summary>
        /// <param name="requestID">The request ID, provided by the <see cref="ClanFormationInvitationEventArgs.RequestID">ClanFormationInvitationEventArgs</see>.</param>
        /// <param name="clanTag">The clan tag.</param>
        /// <param name="inviter">The user who invited the client to the clan.</param>
        /// <param name="accept">Whether to accept the invitation.</param>
        public void RespondToNewClanInvitation(int requestID, string clanTag, string inviter, bool accept)
        {
            BncsPacket pck = new BncsPacket((byte)BncsPacketId.ClanCreationInvitation);

            pck.InsertInt32(requestID);
            pck.InsertDwordString(clanTag, 0);
            pck.InsertCString(inviter);
            pck.InsertByte((byte)(accept ? ClanResponseCode.Accept : ClanResponseCode.Decline));

            Send(pck);
        }
Пример #4
0
        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);
        }
Пример #5
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);
        }
Пример #6
0
        /// <summary>
        /// Invites the specified number of users to form a new clan.
        /// </summary>
        /// <param name="clanName">The name of the clan to form.</param>
        /// <param name="clanTag">The tag of the clan to form.</param>
        /// <param name="usersToInvite">The list of users to invite.  This parameter must be exactly 9 items long.</param>
        /// <returns>The request ID assigned to this request.</returns>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="clanName"/>, <paramref name="clanTag"/>,
        /// <paramref name="usersToInvite"/>, or any of the strings in the array of <paramref name="usersToInvite"/>
        /// is <see langword="null" />.</exception>
        /// <exception cref="ArgumentOutOfRangeException">Thrown if <paramref name="usersToInvite"/> is not exactly 9 items long.</exception>
        public int InviteUsersToNewClan(string clanName, string clanTag, string[] usersToInvite)
        {
            if (object.ReferenceEquals(null, clanName))
            {
                throw new ArgumentNullException(Strings.param_clanName);
            }
            if (object.ReferenceEquals(null, clanTag))
            {
                throw new ArgumentNullException(Strings.param_clanTag);
            }
            if (object.ReferenceEquals(null, usersToInvite))
            {
                throw new ArgumentNullException(Strings.param_usersToInvite);
            }
            if (usersToInvite.Length != 9)
            {
                throw new ArgumentOutOfRangeException(Strings.param_usersToInvite, usersToInvite, Strings.BnetClient_InviteUsersToNewClan_WrongUserCount);
            }
            for (int i = 0; i < 9; i++)
            {
                if (object.ReferenceEquals(usersToInvite[i], null))
                {
                    throw new ArgumentNullException(Strings.param_usersToInvite, Strings.BnetClient_InviteUsersToNewClan_NullUser);
                }
            }

            int result = Interlocked.Increment(ref m_clanCookie);

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

            pck.InsertInt32(result);
            pck.InsertCString(clanName);
            pck.InsertDwordString(clanTag, 0);
            pck.InsertByte(9);
            for (int i = 0; i < 9; i++)
            {
                pck.InsertCString(usersToInvite[i]);
            }

            Send(pck);

            return(result);
        }
Пример #7
0
        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);
        }
Пример #8
0
        /// <summary>
        /// Attempts to change the specified clan member's rank.
        /// </summary>
        /// <remarks>
        /// <para>This method does not attempt to verify that the current user is allowed to change the specified user's rank, or even if the specified
        /// user exists or is in the current user's clan.  The results of this method call are returned via the
        /// <see>ClanRankChangeResponseReceived</see> event.</para>
        /// </remarks>
        /// <param name="name">The name of the user to change.</param>
        /// <param name="newRank">The user's new rank.</param>
        /// <exception cref="InvalidEnumArgumentException">Thrown if <paramref name="newRank"/> is not a valid value of the <see>ClanRank</see>
        /// enumeration</exception>.
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="name"/> is <see langword="null" /> or zero-length.</exception>
        public void ChangeClanMemberRank(string name, ClanRank newRank)
        {
            if (!Enum.IsDefined(typeof(ClanRank), newRank))
            {
                throw new InvalidEnumArgumentException(Strings.param_newRank, (int)newRank, typeof(ClanRank));
            }
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException(Strings.param_name);
            }

            BncsPacket pck    = new BncsPacket((byte)BncsPacketId.ClanRankChange);
            int        cookie = Interlocked.Increment(ref m_clanCookie);

            m_clanRankChangeToMemberList.Add(cookie, name);
            pck.InsertInt32(cookie);
            pck.InsertCString(name);
            pck.InsertByte((byte)newRank);

            Send(pck);
        }
Пример #9
0
        private async void HandleAuthInfo(BncsReader dr)
        {
            try
            {
                //DataReader dr = new DataReader(data.Data);
                //if (m_pingPck != null)
                //{
                //    Send(m_pingPck);
                //    m_pingPck = null;
                //}
                _received0x50 = true;

                _loginType          = dr.ReadUInt32();
                _srvToken           = dr.ReadInt32();
                _udpVal             = dr.ReadUInt32();
                _mpqFileTime        = dr.ReadInt64();
                _versioningFilename = dr.ReadCString();
                _usingLockdown      = _versioningFilename.StartsWith("LOCKDOWN", StringComparison.OrdinalIgnoreCase);

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

                if (!_usingLockdown)
                {
                    _valString = dr.ReadCString();
                    int mpqNum = CheckRevision.ExtractMPQNumber(_versioningFilename);
                    crResult = CheckRevision.DoCheckRevision(_valString, new Stream[] { File.OpenRead(_settings.GameExe), File.OpenRead(_settings.GameFile2), File.OpenRead(_settings.GameFile3) }, mpqNum);
                    exeVer   = CheckRevision.GetExeInfo(_settings.GameExe, out exeInfo);
                }
                else
                {
                    _ldValStr = dr.ReadNullTerminatedByteArray();
                    string dllName = _versioningFilename.Replace(".mpq", ".dll");

                    BnFtpVersion1Request req = new BnFtpVersion1Request(_settings.Client, _versioningFilename, null);
                    req.Gateway       = _settings.Gateway;
                    req.LocalFileName = Path.Combine(Path.GetTempPath(), _versioningFilename);
                    await 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);
                        }
                    }

                    _ldDigest = CheckRevision.DoLockdownCheckRevision(_ldValStr, new string[] { _settings.GameExe, _settings.GameFile2, _settings.GameFile3 },
                                                                      ldPath, _settings.ImageFile, ref exeVer, ref crResult);
                }

                string prodCode = _settings.Client.ProductCode;

                if (prodCode == "WAR3" || prodCode == "W3XP")
                {
                    _w3srv = dr.ReadByteArray(128);

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

                //    BattleNetClientResources.IncomingBufferPool.FreeBuffer(data.Data);

                CdKey key1 = _settings.CdKey1, key2 = _settings.CdKey2;
                _clientToken = new Random().Next();

                byte[] key1Hash = key1.GetHash(_clientToken, _srvToken);
                if (WardenHandler != null)
                {
                    try
                    {
                        if (!WardenHandler.InitWarden(BitConverter.ToInt32(key1Hash, 0)))
                        {
                            WardenHandler.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));
                            WardenHandler = 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));
                        WardenHandler.UninitWarden();
                        WardenHandler = null;
                    }
                }

                BncsPacket pck0x51 = new BncsPacket(BncsPacketId.AuthCheck, _connection.NetworkBuffers.Acquire());
                pck0x51.InsertInt32(_clientToken);
                pck0x51.InsertInt32(exeVer);
                pck0x51.InsertInt32(crResult);
                if (prodCode == "D2XP" || prodCode == "W3XP")
                {
                    pck0x51.InsertInt32(2);
                }
                else
                {
                    pck0x51.InsertInt32(1);
                }
                pck0x51.InsertBoolean(false);
                pck0x51.InsertInt32(key1.Key.Length);
                pck0x51.InsertInt32(key1.Product);
                pck0x51.InsertInt32(key1.Value1);
                pck0x51.InsertInt32(0);
                pck0x51.InsertByteArray(key1Hash);
                if (key2 != null)
                {
                    pck0x51.InsertInt32(key2.Key.Length);
                    pck0x51.InsertInt32(key2.Product);
                    pck0x51.InsertInt32(key2.Value1);
                    pck0x51.InsertInt32(0);
                    pck0x51.InsertByteArray(key2.GetHash(_clientToken, _srvToken));
                }

                if (_usingLockdown)
                {
                    pck0x51.InsertByteArray(_ldDigest);
                    pck0x51.InsertByte(0);
                }
                else
                {
                    pck0x51.InsertCString(exeInfo);
                }

                pck0x51.InsertCString(_settings.CdKeyOwner);

                await pck0x51.SendAsync(_connection);
            }
            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));
                Disconnect();

                Console.WriteLine(ex.ToString());
            }
        }
Пример #10
0
        private async void EnterChat()
        {
            // this does two things.
            // in War3 and W3xp both string fields are null, but in older clients, the first string field is
            // the username.  And, War3 and W3xp send the SID_NETGAMEPORT packet before entering chat, so we
            // send that packet, then insert the empty string into the ENTERCHAT packet.  We of course go to
            // the other branch that inserts the username into the packet for older clients.
            // new for War3: it also sends a packet that seems to be required, 0x44 subcommand 2 (get ladder map info)
            BncsPacket pck = new BncsPacket(BncsPacketId.EnterChat, _storage.Acquire());

            bool isClientWar3 = (_settings.Client.Equals(ClassicProduct.Warcraft3Retail) || _settings.Client.Equals(ClassicProduct.Warcraft3Expansion));
            bool isClientStar = (_settings.Client.Equals(ClassicProduct.StarcraftRetail) || _settings.Client.Equals(ClassicProduct.StarcraftBroodWar));

            if (isClientWar3)
            {
                BncsPacket pck0x45 = new BncsPacket(BncsPacketId.NetGamePort, _storage.Acquire());
                pck0x45.InsertInt16(6112);
                await pck0x45.SendAsync(_connection);

                BncsPacket pckGetLadder = new BncsPacket(BncsPacketId.WarcraftGeneral, _storage.Acquire());
                pckGetLadder.InsertByte((byte)WarcraftCommands.RequestLadderMap);
                pckGetLadder.InsertInt32(1); // cookie
                pckGetLadder.InsertByte(5);  // number of types requested
                //pckGetLadder.InsertDwordString("URL");
                pckGetLadder.InsertInt32(0x004d4150);
                pckGetLadder.InsertInt32(0);
                //pckGetLadder.InsertDwordString("MAP");
                pckGetLadder.InsertInt32(0x0055524c);
                pckGetLadder.InsertInt32(0);
                pckGetLadder.InsertDwordString("TYPE");
                pckGetLadder.InsertInt32(0);
                pckGetLadder.InsertDwordString("DESC");
                pckGetLadder.InsertInt32(0);
                pckGetLadder.InsertDwordString("LADR");
                pckGetLadder.InsertInt32(0);
                await pckGetLadder.SendAsync(_connection);

                pck.InsertCString(string.Empty);
            }
            else
            {
                pck.InsertCString(_settings.Username);
            }
            pck.InsertCString(string.Empty);
            await pck.SendAsync(_connection);

            if (!isClientWar3)
            {
                RequestChannelList();

                //BncsPacket pckJoinChannel = new BncsPacket(BncsPacketId.JoinChannel, _storage.Acquire());
                //string client = "Starcraft";
                //switch (_settings.Client.ProductCode)
                //{
                //    case "SEXP":
                //        client = "Brood War";
                //        break;
                //    case "W2BN":
                //        client = "Warcraft II BNE";
                //        break;
                //    case "D2DV":
                //        client = "Diablo II";
                //        break;
                //    case "D2XP":
                //        client = "Lord of Destruction";
                //        break;
                //}
                //pckJoinChannel.InsertInt32((int)ChannelJoinFlags.FirstJoin);
                //pckJoinChannel.InsertCString(client);
                //await pckJoinChannel.SendAsync(_connection);
            }

            if (isClientWar3 || isClientStar)
            {
                pck = new BncsPacket(BncsPacketId.FriendsList, _storage.Acquire());
                await pck.SendAsync(_connection);
            }

            //m_tmr.Start();
        }
Пример #11
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();
            }
        }
Пример #12
0
        private void EnterChat()
        {
            // this does two things.
            // in War3 and W3xp both string fields are null, but in older clients, the first string field is
            // the username.  And, War3 and W3xp send the SID_NETGAMEPORT packet before entering chat, so we
            // send that packet, then insert the empty string into the ENTERCHAT packet.  We of course go to
            // the other branch that inserts the username into the packet for older clients.
            // new for War3: it also sends a packet that seems to be required, 0x44 subcommand 2 (get ladder map info)
            BncsPacket pck = new BncsPacket((byte)BncsPacketId.EnterChat);

            bool isClientWar3 = (m_settings.Client.Equals("WAR3", StringComparison.Ordinal) || m_settings.Client.Equals("W3XP", StringComparison.Ordinal));
            bool isClientStar = (m_settings.Client.Equals("STAR", StringComparison.Ordinal) || m_settings.Client.Equals("SEXP", StringComparison.Ordinal));

            if (isClientWar3)
            {
                BncsPacket pck0x45 = new BncsPacket((byte)BncsPacketId.NetGamePort);
                pck0x45.InsertInt16(6112);
                Send(pck0x45);

                BncsPacket pckGetLadder = new BncsPacket((byte)BncsPacketId.WarcraftGeneral);
                pckGetLadder.InsertByte((byte)WarcraftCommands.RequestLadderMap);
                pckGetLadder.InsertInt32(1); // cookie
                pckGetLadder.InsertByte(5);  // number of types requested
                //pckGetLadder.InsertDwordString("URL");
                pckGetLadder.InsertInt32(0x004d4150);
                pckGetLadder.InsertInt32(0);
                //pckGetLadder.InsertDwordString("MAP");
                pckGetLadder.InsertInt32(0x0055524c);
                pckGetLadder.InsertInt32(0);
                pckGetLadder.InsertDwordString("TYPE");
                pckGetLadder.InsertInt32(0);
                pckGetLadder.InsertDwordString("DESC");
                pckGetLadder.InsertInt32(0);
                pckGetLadder.InsertDwordString("LADR");
                pckGetLadder.InsertInt32(0);
                Send(pckGetLadder);

                pck.InsertCString(string.Empty);
            }
            else
            {
                pck.InsertCString(m_settings.Username);
            }
            pck.InsertCString(string.Empty);
            Send(pck);

            if (!isClientWar3)
            {
                RequestChannelList();

                BncsPacket pckJoinChannel = new BncsPacket((byte)BncsPacketId.JoinChannel);
                string     client         = "Starcraft";
                switch (m_settings.Client)
                {
                case "SEXP":
                    client = "Brood War";
                    break;

                case "W2BN":
                    client = "Warcraft II BNE";
                    break;

                case "D2DV":
                    client = "Diablo II";
                    break;

                case "D2XP":
                    client = "Lord of Destruction";
                    break;
                }
                pckJoinChannel.InsertInt32((int)ChannelJoinFlags.FirstJoin);
                pckJoinChannel.InsertCString(client);
                Send(pckJoinChannel);
            }

            if (isClientWar3 || isClientStar)
            {
                pck = new BncsPacket((byte)BncsPacketId.FriendsList);
                Send(pck);
            }

            m_tmr.Start();
        }