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());
            }
        }
Beispiel #2
0
        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 void HandleChatEvent(BncsReader dr)
        {
            if (_oldParseCallback != null)
            {
                _oldParseCallback(dr);
                dr.Seek(-dr.Position);
                dr.Seek(4);
            }

            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, (ClassicUserFlags)flags, UserStats.Parse(user, userInfo));
                if (_namesToUsers.ContainsKey(user))
                {
                    _namesToUsers.Remove(user);
                }
                _namesToUsers.Add(user, newUser);
                UserEventArgs <ChatUser> uArgs = new UserEventArgs <ChatUser>(type, newUser);
                HandleUserChatEvent(uArgs);
                break;

            case ChatEventType.UserFlagsChanged:
                if (_namesToUsers.ContainsKey(user))
                {
                    ChatUser changedUser = _namesToUsers[user];
                    changedUser.Flags = (ClassicUserFlags)flags;
                    UserEventArgs <ChatUser> updatedArgs = new UserEventArgs <ChatUser>(type, changedUser);
                    HandleUserChatEvent(updatedArgs);
                }
                else if (_channelName.Equals("The Void", StringComparison.OrdinalIgnoreCase))
                {
                    ChatUser voidUser = new ChatUser(user, ping, (ClassicUserFlags)flags, UserStats.Parse(user, userInfo));
                    _namesToUsers.Add(user, voidUser);
                    UserEventArgs <ChatUser> voidArgs = new UserEventArgs <ChatUser>(type, voidUser);
                    HandleUserChatEvent(voidArgs);
                }
                break;

            case ChatEventType.UserLeftChannel:
                if (_namesToUsers.ContainsKey(user))
                {
                    ChatUser goneUser = _namesToUsers[user];
                    UserEventArgs <ChatUser> leftArgs = new UserEventArgs <ChatUser>(type, goneUser);
                    HandleUserChatEvent(leftArgs);
                }
                break;

            case ChatEventType.Emote:
            case ChatEventType.Talk:
            case ChatEventType.WhisperReceived:
            case ChatEventType.WhisperSent:
                ChatMessageEventArgs <UserFlags> cmArgs = new ChatMessageEventArgs <UserFlags>(type, (UserFlags)flags, user, Encoding.UTF8.GetString(userInfo));
                HandleChatMessageEvent(cmArgs);
                break;

            case ChatEventType.NewChannelJoined:
                ServerChatEventArgs joinArgs = new ServerChatEventArgs(type, flags, text);
                _channelName = text;
                _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;
            }
        }