/// <summary> /// Informs the server that an ad has been displayed. This should be sent whenever an ad /// is updated on the client. /// </summary> /// <param name="adID">The ID of the ad assigned by the server.</param> public virtual void DisplayAd(int adID) { BncsPacket pck = new BncsPacket((byte)BncsPacketId.DisplayAd); pck.InsertDwordString(PLATFORM_TYPE); pck.InsertDwordString(Settings.Client); pck.InsertInt32(adID); pck.InsertInt16(0); // NULL strings for filename and URL. Send(pck); }
void SendAdCheck(object sender, System.Timers.ElapsedEventArgs e) { BncsPacket pck = new BncsPacket((byte)BncsPacketId.CheckAd); pck.InsertDwordString("IX86"); pck.InsertDwordString(Settings.Client); pck.InsertInt32(m_lastAd); pck.InsertInt32(m_lastAd + 1); Send(pck); }
private void RequestChannelList() { BncsPacket pckChanReq = new BncsPacket((byte)BncsPacketId.GetChannelList); pckChanReq.InsertDwordString(m_settings.Client); Send(pckChanReq); }
private async void RequestChannelList() { BncsPacket pckChanReq = new BncsPacket(BncsPacketId.GetChannelList, _storage.Acquire()); pckChanReq.InsertDwordString(_settings.Client.ProductCode); await pckChanReq.SendAsync(_connection); }
private async void HandleLogonResponse2(BncsReader dr) { int success = dr.ReadInt32(); if (success == 0) { OnLoginSucceeded(); ClassicProduct product = _settings.Client; if (product.UsesUdpPing) { BncsPacket pck = new BncsPacket(BncsPacketId.UdpPingResponse, _storage.Acquire()); pck.InsertDwordString("bnet"); await pck.SendAsync(_connection); } 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()); OnLoginFailed(args); } }
private void HandleLogonResponse(ParseData data) { DataReader dr = new DataReader(data.Data); int status = dr.ReadInt32(); if (status == 1) { 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 { LoginFailedEventArgs args = new LoginFailedEventArgs(LoginFailureReason.InvalidAccountOrPassword, status) { EventData = data }; OnLoginFailed(args); } }
/// <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> /// 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 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); }
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); }
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> /// Begins searching for clan candidates in the channel and friends list, and checks the availability of the specified clan tag. /// </summary> /// <param name="clanTag">The clan tag to check for availability.</param> /// <returns>The request ID assigned to the request.</returns> /// <remarks> /// <para>This method will return immediately, but will cause the <see>ClanCandidatesSearchCompleted</see> event to be fired. That event does not /// specifically indicate that the proper number of candidates were found, simply that Battle.net responded. The event arguments sent /// as part of the event indicate the success or failure of the request.</para> /// </remarks> /// <exception cref="ArgumentNullException">Thrown if <paramref name="clanTag"/> is <see langword="null" />.</exception> public int BeginClanCandidatesSearch(string clanTag) { if (object.ReferenceEquals(clanTag, null)) { throw new ArgumentNullException(Strings.param_clanTag); } int result = Interlocked.Increment(ref m_clanCookie); BncsPacket pck = new BncsPacket((byte)BncsPacketId.ClanFindCandidates); pck.InsertInt32(result); pck.InsertDwordString(clanTag, 0); Send(pck); return(result); }
/// <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); }
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); } }
private async void HandleLogonResponse(BncsReader dr) { int status = dr.ReadInt32(); if (status == 1) { OnLoginSucceeded(); ClassicProduct product = _settings.Client; if (product.UsesUdpPing) { BncsPacket pck = new BncsPacket(BncsPacketId.UdpPingResponse, _storage.Acquire()); pck.InsertDwordString("bnet"); await pck.SendAsync(_connection); } EnterChat(); } else { LoginFailedEventArgs args = new LoginFailedEventArgs(LoginFailureReason.InvalidAccountOrPassword, status); OnLoginFailed(args); } }
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(); }
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(); }