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); } }
private async void HandleGetChannelList(BncsReader dr) { 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()); ((IChatConnectionEventSource)this).OnChannelListReceived(e); if (!_firstChannelList) { _firstChannelList = true; BncsPacket pckJoinChan = CreatePacket(BncsPacketId.JoinChannel); if (_settings.Client == ClassicProduct.Diablo2Retail || _settings.Client == ClassicProduct.Diablo2Expansion) { pckJoinChan.InsertInt32((int)ChannelJoinFlags.Diablo2FirstJoin); } else { pckJoinChan.InsertInt32((int)ChannelJoinFlags.FirstJoin); } switch (_settings.Client.ProductCode) { case "STAR": case "SEXP": case "W2BN": case "D2DV": case "D2XP": case "JSTR": pckJoinChan.InsertCString(_settings.Client.ProductCode); break; case "WAR3": case "W3XP": pckJoinChan.InsertCString("W3"); break; } await pckJoinChan.SendAsync(_connection); } }
private async void LoginAccountOld() { switch (_settings.Client.ProductCode) { case "W2BN": BncsPacket pck0x29 = new BncsPacket(BncsPacketId.LogonResponse, _storage.Acquire()); pck0x29.InsertInt32(_clientToken); pck0x29.InsertInt32(_srvToken); pck0x29.InsertByteArray(OldAuth.DoubleHashPassword(_settings.Password, _clientToken, _srvToken)); pck0x29.InsertCString(_settings.Username); await pck0x29.SendAsync(_connection); break; case "STAR": case "SEXP": case "D2DV": case "D2XP": BncsPacket pck0x3a = new BncsPacket(BncsPacketId.LogonResponse2, _storage.Acquire()); pck0x3a.InsertInt32(_clientToken); pck0x3a.InsertInt32(_srvToken); pck0x3a.InsertByteArray(OldAuth.DoubleHashPassword(_settings.Password, _clientToken, _srvToken)); pck0x3a.InsertCString(_settings.Username); await pck0x3a.SendAsync(_connection); break; default: throw new NotSupportedException(string.Format("Client '{0}' is not supported with old-style account login.", _settings.Client.ProductCode)); } }
public void Send(string text) { if (IsConnected) { BncsPacket pck = new BncsPacket(BncsPacketId.ChatCommand, _storage.Acquire()); pck.InsertCString(text, Encoding.UTF8); pck.SendAsync(_connection); if (text.StartsWith(EMOTE_1, StringComparison.OrdinalIgnoreCase) || text.StartsWith(EMOTE_2, StringComparison.OrdinalIgnoreCase)) { // do nothing, but we need this case first so that command sent doesn't fire for emotes. } else if (text.StartsWith(COMMAND_START, StringComparison.Ordinal)) { //OnCommandSent(new InformationEventArgs(text)); } else { ChatMessageEventArgs <UserFlags> cme = new ChatMessageEventArgs <UserFlags>(ChatEventType.Talk, UserFlags.None, "(me)", text); _channel.HandleChatMessageEvent(cme); //ChatMessageEventArgs<UserFlags> cme = new ChatMessageEventArgs<UserFlags>(ChatEventType.Talk, UserFlags.None, this._uniqueUN, text); OnMessageSent(text); } } }
private void LoginAccountOld() { switch (m_settings.Client) { case "W2BN": BncsPacket pck0x29 = new BncsPacket((byte)BncsPacketId.LogonResponse); pck0x29.Insert(m_clientToken); pck0x29.Insert(m_srvToken); pck0x29.InsertByteArray(OldAuth.DoubleHashPassword(m_settings.Password, m_clientToken, m_srvToken)); pck0x29.InsertCString(m_settings.Username); Send(pck0x29); break; case "STAR": case "SEXP": case "D2DV": case "D2XP": BncsPacket pck0x3a = new BncsPacket((byte)BncsPacketId.LogonResponse2); pck0x3a.Insert(m_clientToken); pck0x3a.Insert(m_srvToken); pck0x3a.InsertByteArray(OldAuth.DoubleHashPassword( m_settings.Password, m_clientToken, m_srvToken)); pck0x3a.InsertCString(m_settings.Username); Send(pck0x3a); break; default: throw new NotSupportedException(string.Format(CultureInfo.InvariantCulture, Strings.BnetClient_LoginAccountOld_ClientNotSupported_fmt, m_settings.Client)); } }
/// <summary> /// Begins the connection to Battle.net. /// </summary> /// <returns><see langword="true" /> if the connection succeeded; otherwise <see langword="false" />.</returns> public override bool Connect() { BattleNetClientResources.RegisterClient(this); bool ok = base.Connect(); if (ok) { InitializeListenState(); CultureInfo ci = CultureInfo.CurrentCulture; RegionInfo ri = RegionInfo.CurrentRegion; TimeSpan ts = DateTime.UtcNow - DateTime.Now; OnConnected(BaseEventArgs.GetEmpty(null)); Send(new byte[] { 1 }); BncsPacket pck = new BncsPacket((byte)BncsPacketId.AuthInfo); pck.Insert(0); pck.InsertDwordString(PLATFORM_TYPE); // platform pck.InsertDwordString(m_settings.Client); // product pck.InsertInt32(m_settings.VersionByte); // verbyte pck.InsertDwordString(string.Concat(ci.TwoLetterISOLanguageName, ri.TwoLetterISORegionName)); pck.InsertByteArray(LocalEP.Address.GetAddressBytes()); pck.InsertInt32((int)ts.TotalMinutes); pck.InsertInt32(ci.LCID); pck.InsertInt32(ci.LCID); pck.InsertCString(ri.ThreeLetterWindowsRegionName); pck.InsertCString(ri.DisplayName); Send(pck); if (Settings.PingMethod == PingType.ZeroMs) { pck = new BncsPacket((byte)BncsPacketId.Ping); pck.InsertInt32(new Random().Next()); Send(pck); } StartParsing(); StartListening(); } return(ok); }
private void Chat_Connection() { byte[] bytes = new byte[] { 1 }; this.SendPacket(bytes); Thread.Sleep(5); BncsPacket bncsPacket = new BncsPacket(80); bncsPacket.InsertInt32(0); bncsPacket.InsertDwordString("IX86"); List <string> list = new List <string>(); string[] collection = File.ReadAllLines(MyProject.Application.Info.DirectoryPath + "/Settings/cdkeys.txt"); list.AddRange(collection); string[] array = list[Plugintab.DeclareKey].Split(new char[] { '/' }); if (Operators.CompareString(array[0], "", false) != 0) { this.Exp = false; if (array.Count <string>() == 2 && Operators.CompareString(array[1], "", false) != 0) { this.Exp = true; } } if (this.Exp) { bncsPacket.InsertDwordString("D2XP"); } else { bncsPacket.InsertDwordString("D2DV"); } bncsPacket.InsertInt32(BattleNetClient.g_bVerbyte); bncsPacket.InsertInt32(CultureInfo.CurrentUICulture.LCID); bncsPacket.InsertInt32(16777343); bncsPacket.InsertInt32(checked ((int)Math.Round(DateTime.UtcNow.Subtract(DateTime.Now).TotalMinutes))); bncsPacket.InsertInt32(CultureInfo.CurrentUICulture.LCID); bncsPacket.InsertInt32(CultureInfo.CurrentUICulture.LCID); bncsPacket.InsertCString(RegionInfo.CurrentRegion.ThreeLetterISORegionName); bncsPacket.InsertCString(RegionInfo.CurrentRegion.DisplayName); this.SendPacket(bncsPacket.UnderlyingBuffer); }
/// <summary> /// If the client is logged on as a clan Chieftan or Shaman, sets the clan message-of-the-day. /// </summary> /// <param name="motd">The new message-of-the-day.</param> public void SetClanMessageOfTheDay(string motd) { BncsPacket pck = new BncsPacket((byte)BncsPacketId.ClanSetMOTD); pck.InsertInt32(Interlocked.Increment(ref m_clanCookie)); pck.InsertCString(motd); Send(pck); }
private void CreateAccountOld() { byte[] passwordHash = OldAuth.HashPassword(m_settings.Password); BncsPacket pck = new BncsPacket((byte)BncsPacketId.CreateAccount2); pck.InsertByteArray(passwordHash); pck.InsertCString(m_settings.Username); Send(pck); }
/// <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); }
/// <summary> /// Requests a user's profile. /// </summary> /// <param name="accountName">The name of the user for whom to request information.</param> /// <param name="profile">The profile request, which should contain the keys to request.</param> public virtual void RequestUserProfile(string accountName, UserProfileRequest profile) { BncsPacket pck = new BncsPacket((byte)BncsPacketId.ReadUserData); pck.InsertInt32(1); pck.InsertInt32(profile.Count); int currentRequest = Interlocked.Increment(ref m_currentProfileRequestID); pck.InsertInt32(currentRequest); pck.InsertCString(accountName); foreach (UserProfileKey key in profile) { pck.InsertCString(key.Key); } m_profileRequests.Add(currentRequest, profile); Send(pck); }
private async void CreateAccountOld() { byte[] passwordHash = OldAuth.HashPassword(_settings.Password); BncsPacket pck = new BncsPacket(BncsPacketId.CreateAccount2, _storage.Acquire()); pck.InsertByteArray(passwordHash); pck.InsertCString(_settings.Username); await pck.SendAsync(_connection); }
private void Send_SID_LOGONREALMEX(string a_sRealmTitle) { BncsPacket bncsPacket = new BncsPacket(62); byte[] b = OldAuth.DoubleHashPassword("password", this.g_iClientToken, this.g_iServerToken); bncsPacket.InsertInt32(this.g_iClientToken); bncsPacket.InsertByteArray(b); bncsPacket.InsertCString(a_sRealmTitle); this.SendPacket(bncsPacket.UnderlyingBuffer); }
/// <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); }
/// <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); }
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 Send_SID_LOGONRESPONSE() { byte[] b = new byte[0]; b = OldAuth.DoubleHashPassword(this.BnetInfo.BnetPassword, this.g_iClientToken, this.g_iServerToken); BncsPacket bncsPacket = new BncsPacket(58); bncsPacket.InsertInt32(this.g_iClientToken); bncsPacket.InsertInt32(this.g_iServerToken); bncsPacket.InsertByteArray(b); bncsPacket.InsertCString(this.BnetInfo.BnetUserName); this.SendPacket(bncsPacket.UnderlyingBuffer); }
public async Task <bool> ConnectAsync() { bool ok = await _connection.ConnectAsync(); if (ok) { CultureInfo ci = CultureInfo.CurrentCulture; RegionInfo ri = RegionInfo.CurrentRegion; TimeSpan ts = DateTime.UtcNow - DateTime.Now; ((IChatConnectionEventSource)this).OnConnected(); await _connection.SendAsync(new byte[] { 1 }); BncsPacket pck = new BncsPacket(BncsPacketId.AuthInfo, _storage.Acquire()); pck.InsertInt32(0); pck.InsertDwordString("IX86"); pck.InsertDwordString(_settings.Client.ProductCode); pck.InsertInt32(_settings.VersionByte); pck.InsertDwordString(ci.TwoLetterISOLanguageName + ri.TwoLetterISORegionName); pck.InsertByteArray(_connection.LocalEP.Address.GetAddressBytes()); pck.InsertInt32((int)ts.TotalMinutes); pck.InsertInt32(ci.LCID); pck.InsertInt32(ci.LCID); pck.InsertCString(ri.ThreeLetterISORegionName, Encoding.UTF8); pck.InsertCString(ri.DisplayName, Encoding.UTF8); await pck.SendAsync(_connection); if (_settings.PingMethod == PingKind.ZeroMs) { pck = new BncsPacket(BncsPacketId.Ping, _storage.Acquire()); pck.InsertInt32(new Random().Next()); await pck.SendAsync(_connection); } Listen(); } return(ok); }
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); }
/// <summary> /// Sends a binary channel join command. /// </summary> /// <param name="channelName">The name of the channel to join.</param> /// <param name="method">The specific way by which to join. This should typically be /// set to <see cref="JoinMethod">JoinMethod.NoCreate</see>.</param> public virtual void JoinChannel(string channelName, JoinMethod method) { if (string.IsNullOrEmpty(channelName)) { throw new ArgumentNullException(Strings.param_channelName); } BncsPacket pck = new BncsPacket((byte)BncsPacketId.JoinChannel); pck.InsertInt32((int)method); pck.InsertCString(channelName); Send(pck); }
/// <summary> /// Requests a Warcraft 3 profile. /// </summary> /// <param name="username">The name of the user to request.</param> /// <param name="getFrozenThroneProfile"><see langword="true" /> to get the Frozen Throne profile; /// <see langword="false" /> to get the Reign of Chaos profile.</param> public virtual void RequestWarcraft3Profile(string username, bool getFrozenThroneProfile) { Product pr = getFrozenThroneProfile ? Product.Warcraft3Expansion : Product.Warcraft3Retail; int cookie = Interlocked.Increment(ref m_curProfileCookie); BncsPacket pck = new BncsPacket((byte)BncsPacketId.Profile); pck.InsertInt32(cookie); pck.InsertCString(username); WarcraftProfileEventArgs args = new WarcraftProfileEventArgs(username, pr); m_warcraftProfileRequests.Add(cookie, args); Send(pck); }
/// <summary> /// Begins the process of inviting a user to join a clan. /// </summary> /// <param name="userToInvite">The name of the user to invite.</param> /// <returns>A unique request identifier.</returns> public int InviteUserToClan(string userToInvite) { if (string.IsNullOrEmpty(userToInvite)) { throw new ArgumentNullException(Strings.param_userToInvite, Strings.BnetClient_InviteUserToClan_NullUser); } int result = Interlocked.Increment(ref m_clanCookie); BncsPacket pck = new BncsPacket((byte)BncsPacketId.ClanInvitation); pck.InsertInt32(result); pck.InsertCString(userToInvite); return(result); }
/// <summary> /// Designates a user as a new clan chieftan (leader). /// </summary> /// <returns>The unique request ID assigned to the request.</returns> /// <param name="newChieftanName">The name of the new clan chieftan.</param> public int DesignateClanChieftan(string newChieftanName) { if (object.ReferenceEquals(null, newChieftanName)) { throw new ArgumentNullException(Strings.param_newChieftanName); } int result = Interlocked.Increment(ref m_clanCookie); BncsPacket pck = new BncsPacket((byte)BncsPacketId.ClanMakeChieftan); pck.InsertInt32(result); pck.InsertCString(newChieftanName); Send(pck); return(result); }
/// <summary> /// Begins the process for removing a member from the clan. /// </summary> /// <param name="memberToRemove">The name of the clan member to remove.</param> /// <returns>The request ID assigned to this request.</returns> /// <exception cref="ArgumentNullException">Thrown if <paramref name="memberToRemove"/> is <see langword="null" /> or zero-length.</exception> public int RemoveClanMember(string memberToRemove) { if (string.IsNullOrEmpty(memberToRemove)) { throw new ArgumentNullException(Strings.param_memberToRemove); } int result = Interlocked.Increment(ref m_clanCookie); BncsPacket pck = new BncsPacket((byte)BncsPacketId.ClanRemoveMember); pck.InsertInt32(result); pck.InsertCString(memberToRemove); Send(pck); return(result); }
public virtual void LogonRealm(RealmServer server) { if (object.ReferenceEquals(server, null)) { throw new ArgumentNullException("server"); } Random r = new Random(); int clientToken = r.Next(); byte[] passwordHash = OldAuth.DoubleHashPassword("password", clientToken, m_serverToken); BncsPacket pck = new BncsPacket((byte)BncsPacketId.LogonRealmEx); pck.InsertInt32(clientToken); pck.InsertByteArray(passwordHash); pck.InsertCString(server.Title); m_client.Send(pck); }
/// <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); }
// Implements the actual sending of the text. This method is called as the callback referenced by m_messageReadyCallback, hooked into // the queue's MessageReady event. private void SendCallbackImpl(string text) { if (IsConnected) { BncsPacket pck = new BncsPacket((byte)BncsPacketId.ChatCommand); pck.InsertCString(text, Encoding.UTF8); Send(pck); if (text.StartsWith(EMOTE_1, StringComparison.OrdinalIgnoreCase) || text.StartsWith(EMOTE_2, StringComparison.OrdinalIgnoreCase)) { // do nothing, but we need this case first so that command sent doesn't fire for emotes. } else if (text.StartsWith(COMMAND_START, StringComparison.Ordinal)) { OnCommandSent(new InformationEventArgs(text)); } else { ChatMessageEventArgs cme = new ChatMessageEventArgs(ChatEventType.Talk, UserFlags.None, this.m_uniqueUN, text); OnMessageSent(cme); } } }
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()); } }
public void Handle_SID_AUTH_INFO(BncsReader Reader) { int num = Reader.ReadInt32(); int num2 = Reader.ReadInt32(); int num3 = Reader.ReadInt32(); long num4 = Reader.ReadInt64(); string mpqName = Reader.ReadCString(); byte[] array = Reader.ReadNullTerminatedByteArray(); List <string> list = new List <string>(); this.g_iServerToken = num2; int num5; if (this.Exp) { num5 = 2; } else { num5 = 1; } BattleNetClient battleNetClient = new BattleNetClient(this.Exp); checked { string[] array2 = new string[num5]; CdKey[] array3 = new CdKey[num5]; byte[][] array4 = new byte[num5][]; int[] array5 = new int[num5]; array2[0] = this.BnetInfo.ClassicCdKey; array2[0] = array2[0].Replace("-", ""); array2[0] = array2[0].Replace(" ", ""); if (num5 >= 2) { array2[1] = this.BnetInfo.ExpCdKey; array2[1] = array2[1].Replace("-", ""); array2[1] = array2[1].Replace(" ", ""); } int arg_111_0 = 0; int num6 = num5 - 1; for (int i = arg_111_0; i <= num6; i++) { try { array5[i] = array2[i].Length; array3[i] = CdKey.CreateDecoder(array2[i]); array4[i] = array3[i].GetHash(this.g_iClientToken, this.g_iServerToken); if (!array3[i].IsValid) { this.WriteToLog("Warning Cd-Key(" + Conversions.ToString(i) + ") is invalid", Color.Red); this.Disconnect(); } } catch (Exception expr_186) { ProjectData.SetProjectError(expr_186); this.WriteToLog("Error while preparing the cd-key " + i, Color.Red); this.Disconnect(); ProjectData.ClearProjectError(); return; } } string str = ""; char[] array6 = new char[array.Length]; int arg_1EF_0 = 0; int num7 = array.Length - 1; for (int j = arg_1EF_0; j <= num7; j++) { array6[j] = Strings.ChrW((int)array[j]); } int exeInfo = CheckRevision.GetExeInfo(battleNetClient.g_sHashes[0], out str); int i2 = CheckRevision.DoCheckRevision(new string(array6), battleNetClient.g_sHashes, CheckRevision.ExtractMPQNumber(mpqName)); BncsPacket bncsPacket = new BncsPacket(81); bncsPacket.InsertInt32(this.g_iClientToken); bncsPacket.InsertInt32(exeInfo); bncsPacket.InsertInt32(i2); bncsPacket.InsertInt32(num5); bncsPacket.InsertBoolean(false); int arg_27B_0 = 0; int num8 = num5 - 1; for (int k = arg_27B_0; k <= num8; k++) { bncsPacket.InsertInt32(array5[k]); bncsPacket.InsertInt32(array3[k].Product); bncsPacket.InsertInt32(array3[k].Value1); bncsPacket.InsertInt32(0); bncsPacket.InsertByteArray(array4[k]); } bncsPacket.InsertCString(str); bncsPacket.InsertCString(this.BnetInfo.CdKeyOwner); this.SendPacket(bncsPacket.UnderlyingBuffer); } }
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(); }