Close() public méthode

public Close ( ) : void
Résultat void
        public async Task <string> Base64DecompressAsync(string data, Base64CompressionOptions options = null)
        {
            var _options = GetOptions(options);
            var inStream = new MemoryStream();
            var bytes    = System.Convert.FromBase64String(data);

            await inStream.WriteAsync(bytes, 0, bytes.Length);

            inStream.Position = 0;

            var outStream  = new MemoryStream();
            var outZStream = new zlib.ZOutputStream(outStream);

            try
            {
                await copyStreamAsync(inStream, outZStream, _options.DecompressBufferSize);
            }
            finally
            {
                outZStream.Close();
                outStream.Close();
                inStream.Close();
            }

            var x = outStream.ToArray();

            return(Encoding.UTF8.GetString(x));
        }
        public async Task <byte[]> DecompressAsync(byte[] data, ZlibCompressionOptions options)
        {
            var _options = GetOptions(options);
            var inStream = new MemoryStream();
            var bytes    = data;

            await inStream.WriteAsync(bytes, 0, bytes.Length);

            inStream.Position = 0;

            var outStream  = new MemoryStream();
            var outZStream = new zlib.ZOutputStream(outStream);

            try
            {
                await copyStreamAsync(inStream, outZStream, _options.DecompressBufferSize);
            }
            finally
            {
                outZStream.Close();
                outStream.Close();
                inStream.Close();
            }

            return(outStream.ToArray());
        }
        public string Base64Compress(string data, Base64CompressionOptions options = null)
        {
            var _options  = GetOptions(options);
            var bytes     = Encoding.UTF8.GetBytes(data);
            var outStream = new MemoryStream();
            var inStream  = new MemoryStream();

            inStream.Write(bytes, 0, bytes.Length);
            inStream.Position = 0;

            var outZStream = new zlib.ZOutputStream(outStream, zlib.zlibConst.Z_DEFAULT_COMPRESSION);

            try
            {
                copyStream(inStream, outZStream, _options.CompressBufferSize);
            }
            finally
            {
                outZStream.Close();
                outStream.Close();
                inStream.Close();
            }

            var x = outStream.ToArray();

            return(System.Convert.ToBase64String(x));
        }
        public byte[] Compress(byte[] data, ZlibCompressionOptions options)
        {
            var _options  = GetOptions(options);
            var bytes     = data;
            var outStream = new MemoryStream();
            var inStream  = new MemoryStream();

            inStream.Write(bytes, 0, bytes.Length);
            inStream.Position = 0;

            var outZStream = new zlib.ZOutputStream(outStream, zlib.zlibConst.Z_DEFAULT_COMPRESSION);

            try
            {
                copyStream(inStream, outZStream, _options.CompressBufferSize);
            }
            finally
            {
                outZStream.Close();
                outStream.Close();
                inStream.Close();
            }

            return(outStream.ToArray());
        }
 public static byte[] decompress(byte[] data,UInt32 realsize)
 {
     MemoryStream o=new MemoryStream();
     ZOutputStream z = new ZOutputStream(o);
     MemoryStream i = new MemoryStream(data);
     CopyStream(i, z);
     byte[] res = o.ToArray();
     i.Close();
     z.Close();
     o.Close();
     return res;
 }
        public async Task <Stream> DecompressAsync(Stream data, ZlibCompressionOptions options)
        {
            var _options   = GetOptions(options);
            var inStream   = data;
            var outStream  = new MemoryStream();
            var outZStream = new zlib.ZOutputStream(outStream);

            try
            {
                await copyStreamAsync(inStream, outZStream, _options.DecompressBufferSize);
            }
            finally
            {
                outZStream.Close();
                outStream.Close();
                inStream.Close();
            }

            return(outStream);
        }
        public Stream Compress(Stream data, ZlibCompressionOptions options)
        {
            var _options  = GetOptions(options);
            var outStream = new MemoryStream();
            var inStream  = data;

            var outZStream = new zlib.ZOutputStream(outStream, zlib.zlibConst.Z_DEFAULT_COMPRESSION);

            try
            {
                copyStream(inStream, outZStream, _options.CompressBufferSize);
            }
            finally
            {
                outZStream.Close();
                outStream.Close();
                inStream.Close();
            }

            return(outStream);
        }
Exemple #8
0
 /// <summary>
 /// 解压文件
 /// </summary>
 /// <param name="CompressedFileName">被解压文件名(必须输入绝对路径)</param>
 /// <param name="DecompressFileName">解压后保存的文件名(必须输入绝对路径)</param>
 /// <returns></returns>
 public static bool DecompressFile(string CompressedFileName, string DecompressFileName)
 {
     bool bResult = false;
     FileStream outFileStream = new FileStream(DecompressFileName, FileMode.Create);
     ZOutputStream outZStream = new ZOutputStream(outFileStream);
     FileStream inFileStream = new FileStream(CompressedFileName, FileMode.Open);
     try
     {
         CopyStream(inFileStream, outZStream);
         bResult = true;
     }
     catch
     {
         bResult = false;
     }
     finally
     {
         outZStream.Close();
         outFileStream.Close();
         inFileStream.Close();
     }
     return bResult;
 }
        public static OSD ZCompressOSD(OSD inOsd, bool useHeader)
        {
            OSD osd = null;

            using (MemoryStream msSinkCompressed = new MemoryStream())
            {
                using (ZOutputStream zOut = new ZOutputStream(msSinkCompressed,1))
                {
                    CopyStream(new MemoryStream(OSDParser.SerializeLLSDBinary(inOsd, useHeader)), zOut);
                    msSinkCompressed.Seek(0L, SeekOrigin.Begin);
                    osd = OSD.FromBinary(msSinkCompressed.ToArray());
                    zOut.Close();
                }

            }

            return osd;
        }
Exemple #10
0
        public static void Convertitems()
        {

            SqlWrapper sql = new SqlWrapper();
            DataTable dt_items = sql.ReadDatatable("SELECT * FROM Items order by aoid asc");

            Stream sf = new FileStream("items.dat", FileMode.Create);

            ZOutputStream ds = new ZOutputStream(sf, zlibConst.Z_BEST_COMPRESSION);
            MemoryStream sm = new MemoryStream();

            //DeflateStream sm = new DeflateStream(sf, CompressionMode.Compress);



            BinaryFormatter bf = new BinaryFormatter();

            Console.WriteLine("Processing data... This will take a while!");
            List<AOItem> ITEMS = new List<AOItem>();
            int count = dt_items.Rows.Count;
            int oldperc = 0;
            int countall = 0;
            byte[] buffer = BitConverter.GetBytes(maxnum);
            sm.Write(buffer, 0, buffer.Length);
            if (File.Exists("items2.dat"))
            {
                ItemHandler.CacheAllItems("items2.dat");
                foreach (AOItem aoi in ItemHandler.ItemList)
                {
                    ITEMS.Add(aoi);
                    if (ITEMS.Count == maxnum)
                    {
                        bf.Serialize(sm, ITEMS);
                        sm.Flush();
                        ITEMS.Clear();
                        countall += maxnum;
                    }
                }
            }
            else
            {
                foreach (DataRow itemrow in dt_items.Rows)
                {
                    AOItem _item = new AOItem();
                    _item.LowID = (Int32)itemrow[0];
                    _item.HighID = (Int32)itemrow[0];
                    _item.Quality = (Int32)itemrow[2];
                    _item.ItemType = (Int32)itemrow[3];

                    DataTable dt_itemevents = sql.ReadDatatable("SELECT * FROM item_events WHERE itemid=" + _item.LowID + " ORDER BY eventid asc");

                    foreach (DataRow eventrow in dt_itemevents.Rows)
                    {
                        AOEvents aoe = new AOEvents();
                        aoe.EventType = (Int32)eventrow[2];
                        int eventid = (Int32)eventrow["eventid"];

                        DataTable dt_itemeventfunctions = sql.ReadDatatable("SELECT * FROM item_functions WHERE itemid=" + _item.LowID + " AND eventid=" + eventid + " ORDER BY functionid asc");

                        foreach (DataRow eventfunctionrow in dt_itemeventfunctions.Rows)
                        {
                            int eventfuncid = (Int32)eventfunctionrow["functionid"];
                            AOFunctions aof = new AOFunctions();
                            aof.FunctionType = (Int32)eventfunctionrow[3];
                            aof.Target = (Int32)eventfunctionrow[4];
                            aof.TickCount = (Int32)eventfunctionrow[5];
                            aof.TickInterval = (uint)(Int32)eventfunctionrow[6];

                            DataTable functionargs = sql.ReadDatatable("SELECT * FROM item_function_arguments WHERE functionid=" + eventfuncid + " AND eventid=" + eventid + " AND itemid=" + _item.LowID + " ORDER BY attrid asc");

                            foreach (DataRow attrs in functionargs.Rows)
                            {
                                if (!(attrs["argvalint"] is DBNull))
                                {
                                    aof.Arguments.Add((Int32)attrs["argvalint"]);
                                }
                                else
                                    if (!(attrs["argvalsingle"] is DBNull))
                                    {
                                        aof.Arguments.Add((Single)(float)attrs["argvalsingle"]);
                                    }
                                    else
                                        if (!(attrs["argvalstring"] is DBNull))
                                        {
                                            string s = attrs["argvalstring"].ToString();
                                            aof.Arguments.Add(s);
                                        }
                                        else
                                            throw (new NotSupportedException("No Argument value given, all NULL: " + _item.LowID));
                            }

                            DataTable reqs = sql.ReadDatatable("SELECT * from  item_function_reqs WHERE functionid=" + eventfuncid + " AND eventid=" + eventid + " AND itemid=" + _item.LowID + " ORDER BY reqid asc");

                            foreach (DataRow rrow in reqs.Rows)
                            {
                                AORequirements aor = new AORequirements();
                                aor.Statnumber = (Int32)rrow["attrnum"];
                                aor.Value = (Int32)rrow["attrval"];
                                aor.Target = (Int32)rrow["target"];
                                aor.Operator = (Int32)rrow["operator"];
                                aor.ChildOperator = (Int32)rrow["child_op"];
                                aof.Requirements.Add(aor);
                            }

                            aoe.Functions.Add(aof);
                        }

                        _item.Events.Add(aoe);
                    }

                    DataTable dt_actions = sql.ReadDatatable("SELECT * FROM item_actions WHERE itemid=" + _item.LowID);

                    foreach (DataRow acrow in dt_actions.Rows)
                    {
                        AOActions aoa = new AOActions();
                        aoa.ActionType = (Int32)acrow["actionnum"];

                        DataTable reqs = sql.ReadDatatable("SELECT * FROM item_action_reqs WHERE itemid=" + _item.LowID + " AND actionid=" + ((Int32)acrow["actionid"]) + " ORDER BY reqid ASC");

                        foreach (DataRow rrow in reqs.Rows)
                        {
                            AORequirements aor = new AORequirements();
                            aor.Statnumber = (Int32)rrow["attrnum"];
                            aor.Value = (Int32)rrow["attrval"];
                            aor.Target = (Int32)rrow["target"];
                            aor.Operator = (Int32)rrow["operator"];
                            aor.ChildOperator = (Int32)rrow["child_op"];
                            aoa.Requirements.Add(aor);
                        }
                        _item.Actions.Add(aoa);
                    }

                    DataTable dtdef = sql.ReadDatatable("SELECT * FROM item_defense_attributes where itemid=" + _item.LowID + " ORDER BY defenseid asc");

                    foreach (DataRow defrow in dtdef.Rows)
                    {
                        AOItemAttribute aoia = new AOItemAttribute();
                        aoia.Stat = (Int32)defrow["num"];
                        aoia.Value = (Int32)defrow["value"];
                        _item.Defend.Add(aoia);
                    }

                    DataTable dtatt = sql.ReadDatatable("select * FROM item_attack_attributes where itemid=" + _item.LowID + " ORDER BY attackid asc");
                    foreach (DataRow defrow in dtatt.Rows)
                    {
                        AOItemAttribute aoia = new AOItemAttribute();
                        aoia.Stat = (Int32)defrow["num"];
                        aoia.Value = (Int32)defrow["value"];
                        _item.Defend.Add(aoia);
                    }

                    DataTable attributes = sql.ReadDatatable("SELECT * FROM item_attributes WHERE itemid=" + _item.LowID + " ORDER BY attributeid asc");
                    foreach (DataRow atrow in attributes.Rows)
                    {
                        AOItemAttribute aoia = new AOItemAttribute();
                        aoia.Stat = (Int32)atrow["num"];
                        aoia.Value = (Int32)atrow["value"];
                        _item.Stats.Add(aoia);
                    }


                    ITEMS.Add(_item);

                    int perc = Convert.ToInt32(Math.Floor((double)(ITEMS.Count + countall) / count * 100.0));
                    if (perc != oldperc)
                    {
                        Console.Write("\rDone " + perc.ToString().PadLeft(3) + "%");
                        oldperc = perc;
                    }
                    if (ITEMS.Count == maxnum)
                    {
                        bf.Serialize(sm, ITEMS);
                        sm.Flush();
                        ITEMS.Clear();
                        countall += maxnum;
                    }
                }
            }
            bf.Serialize(sm, ITEMS);
            sm.Seek(0, SeekOrigin.Begin);
            Console.WriteLine();
            CopyStream(sm, ds);
            sm.Close();
            ds.Close();
        }
        /// <summary>
        /// The main.
        /// </summary>
        /// <param name="args">
        /// The args.
        /// </param>
        private static void Main(string[] args)
        {
            Console.WriteLine("**********************************************************************");
            Console.WriteLine("**                                                                  **");
            Console.WriteLine("**  AO Item and Nano Extractor/Serializer v0.85beta                  **");
            Console.WriteLine("**                                                                  **");
            Console.WriteLine("**********************************************************************");

            Console.WriteLine();

            string AOPath = string.Empty;
            bool foundAO = false;
            Console.WriteLine("Enter exit to close program");
            while (!foundAO)
            {
                if (File.Exists("config.txt"))
                {
                    TextReader tr = new StreamReader("config.txt");
                    AOPath = tr.ReadLine();
                    tr.Close();
                }

                foundAO = false;
                Console.Write("Please enter your AO Install Path [" + AOPath + "]:");
                string temp = Console.ReadLine();
                if (temp != string.Empty)
                {
                    AOPath = temp;
                }

                if (temp.ToLower() == "exit")
                {
                    return;
                }

                if (!Directory.Exists(AOPath))
                {
                    continue;
                }

                try
                {
                    extractor = new Extractor(AOPath);
                    TextWriter tw2 = new StreamWriter("config.txt", false, Encoding.GetEncoding("windows-1252"));
                    tw2.WriteLine(AOPath);
                    tw2.Close();
                    foundAO = true;
                    Console.WriteLine("Found AO Database on " + AOPath);
                }
                catch (Exception)
                {
                    foundAO = false;
                }

                // Try to add cd_image\data\db
                if (!foundAO)
                {
                    try
                    {
                        AOPath = Path.Combine(AOPath, "cd_image\\data\\db");
                        extractor = new Extractor(AOPath);
                        TextWriter tw2 = new StreamWriter("config.txt", false, Encoding.GetEncoding("windows-1252"));
                        tw2.WriteLine(AOPath);
                        tw2.Close();
                        foundAO = true;
                        Console.WriteLine("Found AO Database on " + AOPath);
                    }
                    catch (Exception)
                    {
                        foundAO = false;
                    }
                }
            }

            TextWriter tw = new StreamWriter("itemnames.sql", false, Encoding.GetEncoding("windows-1252"));
            tw.WriteLine("DROP TABLE IF EXISTS `itemnames`;");
            tw.WriteLine("CREATE TABLE `itemnames` (");
            tw.WriteLine("  `AOID` int(10) NOT NULL,");
            tw.WriteLine("  `Name` varchar(250) NOT NULL,");
            tw.WriteLine("  PRIMARY KEY (`AOID`)");
            tw.WriteLine(") ENGINE=MyIsam DEFAULT CHARSET=latin1;");
            tw.WriteLine();
            tw.Close();

            Console.WriteLine("Number of Items to extract: " + extractor.GetRecordInstances(0xF4254).Length);

            // ITEM RECORD TYPE
            Console.WriteLine("Number of Nanos to extract: " + extractor.GetRecordInstances(0xFDE85).Length);

            // NANO RECORD TYPE

            // Console.WriteLine(extractor.GetRecordInstances(0xF4241).Length); // Playfields
            // Console.WriteLine(extractor.GetRecordInstances(0xF4266).Length); // Nano Strains
            // Console.WriteLine(extractor.GetRecordInstances(0xF4264).Length); // Perks

            // GetData(@"D:\c#\extractor serializer\data\items\",0xf4254);
            // GetData(@"D:\c#\extractor serializer\data\nanos\",0xfde85);
            // GetData(@"D:\c#\extractor serializer\data\playfields\",0xf4241);
            // GetData(@"D:\c#\extractor serializer\data\nanostrains\",0xf4266);
            // GetData(@"D:\c#\extractor serializer\data\perks\",0xf4264);
            var np = new NewParser();
            var rawItemList = new List<AOItem>();
            var rawNanoList = new List<AONanos>();
            foreach (int recnum in extractor.GetRecordInstances(0xFDE85))
            {
                rawNanoList.Add(np.ParseNano(0xFDE85, recnum, extractor.GetRecordData(0xFDE85, recnum), "temp.sql"));
            }

            File.Delete("temp.sql");
            Console.WriteLine();
            Console.WriteLine("Nanos extracted: " + rawNanoList.Count);

            List<string> ItemNamesSql = new List<string>();

            foreach (int recnum in extractor.GetRecordInstances(0xF4254))
            {
                rawItemList.Add(np.ParseItem(0xF4254, recnum, extractor.GetRecordData(0xF4254, recnum), ItemNamesSql));
            }

            Console.WriteLine();

            Console.WriteLine();
            Console.WriteLine("Compacting itemnames.sql");
            TextWriter itnsql = new StreamWriter("itemnames.sql", true, Encoding.GetEncoding("windows-1252"));
            while (ItemNamesSql.Count > 0)
            {
                int count = 0;
                string toWrite = string.Empty;
                while ((count < 20) && (ItemNamesSql.Count > 0))
                {
                    if (toWrite.Length > 0)
                    {
                        toWrite += ",";
                    }

                    toWrite += ItemNamesSql[0];
                    ItemNamesSql.RemoveAt(0);
                    count++;
                }

                if (toWrite != string.Empty)
                {
                    itnsql.WriteLine("INSERT INTO itemnames VALUES " + toWrite + ";");
                }
            }

            itnsql.Close();

            // SerializationContext.Default.Serializers.Register(new AOFunctionArgumentsSerializer());
            Console.WriteLine();
            Console.WriteLine("Items extracted: " + rawItemList.Count);

            Console.WriteLine();
            Console.WriteLine("Creating serialized nano data file - please wait");
            Stream sf = new FileStream("nanos.dat", FileMode.Create);

            var ds = new ZOutputStream(sf, zlibConst.Z_BEST_COMPRESSION);
            var sm = new MemoryStream();
            MessagePackSerializer<List<AONanos>> bf = MessagePackSerializer.Create<List<AONanos>>();

            var nanoList2 = new List<AONanos>();

            int maxnum = 5000;
            byte[] buffer = BitConverter.GetBytes(maxnum);
            sm.Write(buffer, 0, buffer.Length);

            foreach (AONanos nanos in rawNanoList)
            {
                nanoList2.Add(nanos);
                if (nanoList2.Count == maxnum)
                {
                    bf.Pack(sm, nanoList2);
                    sm.Flush();
                    nanoList2.Clear();
                }
            }

            bf.Pack(sm, nanoList2);
            sm.Seek(0, SeekOrigin.Begin);
            CopyStream(sm, ds);
            sm.Close();
            ds.Close();

            Console.WriteLine();
            Console.WriteLine("Checking Nanos...");
            Console.WriteLine();
            NanoHandler.CacheAllNanos("nanos.dat");
            Console.WriteLine();
            Console.WriteLine("Nanos: " + NanoHandler.NanoList.Count + " successfully converted");

            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine("Creating serialized item data file - please wait");

            sf = new FileStream("items.dat", FileMode.Create);

            ds = new ZOutputStream(sf, zlibConst.Z_BEST_COMPRESSION);
            sm = new MemoryStream();
            MessagePackSerializer<List<AOItem>> bf2 = MessagePackSerializer.Create<List<AOItem>>();

            List<AOItem> items = new List<AOItem>();

            maxnum = 5000;
            buffer = BitConverter.GetBytes(maxnum);
            sm.Write(buffer, 0, buffer.Length);

            foreach (AOItem it in rawItemList)
            {
                items.Add(it);
                if (items.Count == maxnum)
                {
                    bf2.Pack(sm, items);
                    sm.Flush();
                    items.Clear();
                }
            }

            bf2.Pack(sm, items);
            sm.Seek(0, SeekOrigin.Begin);
            CopyStream(sm, ds);
            sm.Close();
            ds.Close();

            Console.WriteLine();
            Console.WriteLine("Checking Items...");
            Console.WriteLine();

            ItemHandler.CacheAllItems("items.dat");

            Console.WriteLine("Items: " + ItemHandler.ItemList.Count + " successfully converted");

            Console.WriteLine();
            Console.WriteLine("Further Instructions:");
            Console.WriteLine("- Copy items.dat and nanos.dat into your CellAO folder and overwrite.");
            Console.WriteLine("- Apply itemnames.sql to your database");
            Console.WriteLine("Press Enter to exit and have fun with CellAO");
            Console.ReadLine();
        }
Exemple #12
0
        private ErrCode OnRecvPacket(SmartPacket packet)
        {
            ErrCode            errCode             = ErrCode.Success;
            PacketCode         packetCode          = (PacketCode)packet.Code;
            NotifyEventCode   nec                 = NotifyEventCode.None;
            bool                isNotifyPacket      = false;
            bool                isHandlerCalled     = false;
            object              param1              = null;
            object              param2              = null;

            Log(string.Format("[VAAL] OnRecvPacket : PacketCode={0}", packetCode));

            lock (m_lockVal)
            {
                m_packetCode    = packetCode;
                m_resultCode    = packet.Process(m_proxyServer);
                param1          = packet.Param1;
                param2          = packet.Param2;
                nec             = (NotifyEventCode)packet.Nec;
                isNotifyPacket  = !(packet is TwoWayPacket);

                OneWayPacket onewayPacket = packet as OneWayPacket;
                if (onewayPacket != null && onewayPacket.RecvTransNum > 0)
                {
                    if (m_recvTransNum >= onewayPacket.RecvTransNum)
                    {
                        Log(string.Format("[VAAL] OnRecvPacket : CurRecvTransNum = {0}, PacketRecvTransNum = {1}", m_recvTransNum, onewayPacket.RecvTransNum));
                        return errCode;
                    }
                    m_recvTransNum = onewayPacket.RecvTransNum;
                }

                switch (packetCode)
                {
                    case PacketCode.Hello:
                        {
                            m_eventSyncPacket.Set();

                            if (m_resultCode == (uint)ErrCode.VaalSvrClientVersion)
                            {
                                CallNotifyHandler(NotifyEventCode.LowerClientVersion, m_resultCode, null, null);
                            }

                            isNotifyPacket = true;
                            isHandlerCalled = true;
                        }
                        break;

                    case PacketCode.GetItemListReply:
                        {
                            if (m_resultCode == (uint)ErrCode.Success)
                            {
                                GetItemListReplyPacket packetReply = (GetItemListReplyPacket)packet;

                                byte[] temp = new byte[m_buffer.Length + packetReply.m_buffer.Length];
                                Array.Copy(m_buffer, temp, m_buffer.Length);
                                Array.Copy(packetReply.m_buffer, 0, temp, m_buffer.Length, packetReply.m_buffer.Length);
                                m_buffer = temp;

                                if (packetReply.m_isLastPacket == 0)
                                {
                                    // Waits for next packets.
                                    isHandlerCalled = true;
                                    isNotifyPacket = true;
                                }
                                else
                                {
                                    MemoryStream inMStream = new MemoryStream(m_buffer);
                                    MemoryStream outMStream = new MemoryStream();
                                    ZOutputStream outZStream = new ZOutputStream(outMStream);

                                    CopyStream(inMStream, outZStream);

                                    ItemDataType itemType = (ItemDataType)(byte)param1;

                                    switch (itemType)
                                    {
                                        case ItemDataType.Stage:
                                            StageManager stageManager = new StageManager();
                                            SimpleStream streamStage = new SimpleStream();

                                            streamStage.SetBuffer(outMStream.ToArray(), false);
                                            stageManager.SetHash(m_proxyServer.StageManager.Hash);
                                            stageManager.DeSerialize(streamStage);
                                            m_proxyServer.SetStageManager(stageManager);

                                            param2 = stageManager.Hash;
                                            break;

                                        case ItemDataType.Item:
                                            ItemManager itemManager = new ItemManager();
                                            SimpleStream streamItem = new SimpleStream();

                                            streamItem.SetBuffer(outMStream.ToArray(), false);
                                            itemManager.SetHash(m_proxyServer.ItemManager.Hash);
                                            itemManager.DeSerialize(streamItem);
                                            m_proxyServer.SetItemManager(itemManager);

                                            param2 = itemManager.Hash;
                                            break;
                                    }

                                    outZStream.Close();
                                    outMStream.Close();
                                    inMStream.Close();
                                }
                            }
                        }
                        break;

                    case PacketCode.Login:
                        {
                            LoginPacket packetReply = (LoginPacket)packet;

                            if (m_isLoginPacketSync)
                            {
                                m_eventSyncPacket.Set();
                                isNotifyPacket = true;
                            }

                            if (m_resultCode == (uint)ErrCode.Success)
                            {
                                m_proxyServer.SetLoginState(true);

                                if (packetReply.m_isAlreadyLogined == 0)
                                {
                                    m_sendTransNum = 0;
                                    m_recvTransNum = 0;
                                }
                            }
                        }
                        break;
                }
            }

            if (nec != NotifyEventCode.None)
            {
                if (!isNotifyPacket)
                {
                    lock (m_retryPackets)
                    {
                        List<RetryPacket> packetToBeRemoved = new List<RetryPacket>();

                        foreach (RetryPacket rp in m_retryPackets)
                        {
                            rp.m_event.Set();
                            rp.m_packet.Dispose();

                            if (rp.m_nec == nec)
                            {
                                m_retryPackets.Remove(rp);
                                break;
                            }
                            else
                            {
                                packetToBeRemoved.Add(rp);
                                Log(string.Format("[VAAL] No response. NC={0}", rp.m_nec));
                            }
                        }

                        foreach (RetryPacket rp in packetToBeRemoved)
                        {
                            m_retryPackets.Remove(rp);
                        }
                    }
                }

                if (!isHandlerCalled)
                    CallNotifyHandler(nec, m_resultCode, param1, param2);
            }

            return errCode;
        }
        private byte[] CompressResult(string strResult)
        {
            byte[] byteArrayIn = Encoding.UTF8.GetBytes(strResult);

            MemoryStream outStream = new MemoryStream();
            ZOutputStream zOutputStream = new ZOutputStream(outStream, zlibConst.Z_BEST_COMPRESSION);
            zOutputStream.Write(byteArrayIn, 0, byteArrayIn.Length);
            zOutputStream.Close();

            byte[] byteArrayOut = outStream.ToArray();

            byte[] compresedDataLengthBytes = BitConverter.GetBytes(byteArrayOut.Length);
            byte[] dataLengthBytes = BitConverter.GetBytes(strResult.Length);

            byte[] bytesToSend = new byte[byteArrayOut.Length + 8];

            bytesToSend[0] = dataLengthBytes[3];
            bytesToSend[1] = dataLengthBytes[2];
            bytesToSend[2] = dataLengthBytes[1];
            bytesToSend[3] = dataLengthBytes[0];
            bytesToSend[4] = compresedDataLengthBytes[3];
            bytesToSend[5] = compresedDataLengthBytes[2];
            bytesToSend[6] = compresedDataLengthBytes[1];
            bytesToSend[7] = compresedDataLengthBytes[0];
            int index = 8;
            foreach (byte b in byteArrayOut)
            {
                bytesToSend[index] = b;
                index++;
            }
            return bytesToSend;
        }
Exemple #14
0
        /// <summary>
        /// 压缩
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        static public void CompressByteZipNet(byte[] inBytes, uint startPos, uint inLen, ref byte[] outBytes, ref uint outLen)
        {
            MemoryStream ms = new MemoryStream();
            ZOutputStream zipStream = new ZOutputStream(ms, 9);

            try
            {
                zipStream.Write(inBytes, (int)startPos, (int)inLen);

                zipStream.Flush();
                zipStream.Close();      // 一定要先 Close ZipOutputStream ,然后再获取 ToArray ,如果不关闭, ToArray 将不能返回正确的值

                outBytes = ms.ToArray();
                outLen = (uint)outBytes.Length;
                ms.Close();
            }
            catch
            {
                Ctx.m_instance.m_logSys.error("CompressByteZipNet error");
            }
        }