Example #1
0
        public void Read(RakNet.BitStream stream, RakNet.Packet packet, Server server)
        {
            int   plID = 0;
            short anim = 0;

            stream.Read(out plID);
            stream.Read(out anim);

            if (plID == 0 || !sWorld.VobDict.ContainsKey(plID))
            {
                throw new Exception("Vob not found!");
            }
            Vob vob = sWorld.VobDict[plID];

            if (!(vob is NPCProto))
            {
                throw new Exception("Vob is not an NPC!");
            }

            short oldAnim = ((NPCProto)vob).Animation;

            ((NPCProto)vob).Animation = anim;


            Write((NPCProto)vob, packet.guid);

            Scripting.Objects.Character.NPCProto.isOnAnimation(((NPCProto)vob).ScriptingNPC, anim, oldAnim);
        }
        public void Read(RakNet.BitStream stream, RakNet.Packet packet, Server server)
        {
            int vobCount = 0;

            stream.Read(out vobCount);

            List <Vob> vobList = new List <Vob>();

            for (int i = 0; i < vobCount; i++)
            {
                int   vobID = 0;
                Vec3f pos, dir;

                stream.Read(out vobID);
                stream.Read(out pos);
                stream.Read(out dir);

                if (vobID == 0 || !sWorld.VobDict.ContainsKey(vobID))
                {
                    throw new Exception("Vob not found!");
                }
                Vob vob = sWorld.VobDict[vobID];
                vob.Position  = pos;
                vob.Direction = dir;

                vobList.Add(vob);
            }


            Write(vobList, packet.systemAddress);
        }
Example #3
0
        public void Read(RakNet.BitStream stream, RakNet.Packet packet, Client client)
        {
            int    callBackID = 0, playerID = 0;
            String md5File;

            stream.Read(out callBackID);
            stream.Read(out playerID);
            stream.Read(out md5File);

            String value = "";

            try
            {
                md5File = Path.GetFullPath(md5File);
                String minName = new DirectoryInfo(StartupState.getSystemPath()).Parent.FullName;
                if (md5File.StartsWith(minName))
                {
                    if (File.Exists(md5File))
                    {
                        value = FileMd5(md5File);
                    }
                }
            }
            catch (Exception ex) {}

            stream.Reset();
            stream.Write((byte)RakNet.DefaultMessageIDTypes.ID_USER_PACKET_ENUM);
            stream.Write((byte)NetworkID.ReadMd5Message);
            stream.Write(callBackID);
            stream.Write(playerID);
            stream.Write(md5File);
            stream.Write(value);

            Program.client.client.Send(stream, PacketPriority.HIGH_PRIORITY, PacketReliability.RELIABLE_ORDERED, (char)0, RakNet.RakNet.UNASSIGNED_SYSTEM_ADDRESS, true);
        }
Example #4
0
        public void Read(RakNet.BitStream stream, RakNet.Packet packet, Client client)
        {
            int callBackID = 0, npcID = 0, vobID = 0;

            stream.Read(out callBackID);
            stream.Read(out npcID);
            stream.Read(out vobID);

            if (!sWorld.VobDict.ContainsKey(npcID) || !sWorld.VobDict.ContainsKey(vobID))
            {
                throw new Exception("Vob or NPC weren't in the List!");
            }

            NPCProto proto = (NPCProto)sWorld.VobDict[npcID];
            Vob      vob   = (Vob)sWorld.VobDict[vobID];

            bool canSee = false;

            if (proto.Address != 0 && vob.Address == 0)
            {
                canSee = (new oCNpc(Process.ThisProcess(), proto.Address).CanSee(new zCVob(Process.ThisProcess(), vob.Address), 0) == 1) ? true : false;
            }

            stream.Reset();
            stream.Write((byte)RakNet.DefaultMessageIDTypes.ID_USER_PACKET_ENUM);
            stream.Write((byte)NetworkID.CallbackNPCCanSee);
            stream.Write(callBackID);
            stream.Write(proto.ID);
            stream.Write(vob.ID);
            stream.Write(canSee);

            Program.client.client.Send(stream, PacketPriority.HIGH_PRIORITY, PacketReliability.RELIABLE_ORDERED, (char)0, RakNet.RakNet.UNASSIGNED_SYSTEM_ADDRESS, true);
        }
Example #5
0
        public void Read(RakNet.BitStream stream, RakNet.Packet packet, Server server)
        {
            String heroName    = "";
            String driveString = "";
            String macString   = "";


            Vec3f pos = new Vec3f();

            stream.Read(out heroName);
            stream.Read(out driveString);
            stream.Read(out macString);
            stream.Read(out pos);


            Player player = new Player(packet.guid, heroName);

            player.DriveString = driveString;
            player.MacString   = macString;
            player.Position    = pos;
            sWorld.addVob(player);

            Write(player);
            CreateVobMessage.Write(player, packet.guid);

            Scripting.GUI.View.SendToPlayer(player);
            Scripting.Objects.Character.Player.isOnPlayerConnect((GUC.Server.Scripting.Objects.Character.Player)player.ScriptingNPC);
        }
Example #6
0
        public void Read(RakNet.BitStream stream, RakNet.Packet packet, Client client)
        {
            int    callBackID = 0, playerID = 0;
            String section, entry;

            stream.Read(out callBackID);
            stream.Read(out playerID);
            stream.Read(out section);
            stream.Read(out entry);

            String value = "";

            try
            {
                value = zCOption.GetOption(Process.ThisProcess()).getEntryValue(section, entry);
            }
            catch (Exception ex) {}

            stream.Reset();
            stream.Write((byte)RakNet.DefaultMessageIDTypes.ID_USER_PACKET_ENUM);
            stream.Write((byte)NetworkID.ReadIniEntryMessage);
            stream.Write(callBackID);
            stream.Write(playerID);
            stream.Write(section);
            stream.Write(entry);
            stream.Write(value);

            Program.client.client.Send(stream, PacketPriority.HIGH_PRIORITY, PacketReliability.RELIABLE_ORDERED, (char)0, RakNet.RakNet.UNASSIGNED_SYSTEM_ADDRESS, true);
        }
Example #7
0
        public void Read(RakNet.BitStream stream, RakNet.Packet packet, Server server)
        {
            int itemID = 0;
            int amount = 0;

            stream.Read(out itemID);
            stream.Read(out amount);


            if (itemID == 0 || !sWorld.VobDict.ContainsKey(itemID))
            {
                throw new Exception("Vob not found!");
            }
            Vob vob = sWorld.VobDict[itemID];

            if (!(vob is Item))
            {
                throw new Exception("Vob is not an item");
            }

            Item item = (Item)vob;

            if (item.Container is NPCProto)
            {
                NPCProto proto = (NPCProto)item.Container;
                proto.removeItem(item, amount);

                Scripting.Objects.Character.NPCProto.isOnUseItem(proto.ScriptingNPC, item.ScriptingProto, -1, -2);
            }

            Write(item, packet.systemAddress);
        }
Example #8
0
        public void Read(RakNet.BitStream stream, RakNet.Packet packet, Server server)
        {
            int    plID      = 0;
            String levelName = "";

            stream.Read(out plID);
            stream.Read(out levelName);

            Vob pl = sWorld.VobDict[plID];

            sWorld.getWorld(levelName).addVob(pl);

            stream.ResetReadPointer();
            Program.server.ServerInterface.Send(stream, PacketPriority.HIGH_PRIORITY, PacketReliability.RELIABLE_ORDERED, (char)0, packet.guid, true);
        }
        private static bool UpdateState(RakNet.BitStream stream)
        {
            bool isX = false;

            stream.Read(out isX);
            return(isX);
        }
        public void Read(RakNet.BitStream stream, RakNet.Packet packet, Server server)
        {
            int casterID = 0;

            stream.Read(out casterID);


            Vob      casterVob = null;
            NPCProto caster    = null;

            sWorld.VobDict.TryGetValue(casterID, out casterVob);


            if (casterVob == null)
            {
                throw new Exception("Caster was not found!");
            }
            if (!(casterVob is NPCProto))
            {
                throw new Exception("Caster was not a npcproto " + casterVob);
            }
            caster = (NPCProto)casterVob;



            Write(caster, packet.guid);
        }
        public void Read(RakNet.BitStream stream, RakNet.Packet packet, Client client)
        {
            int    plID;
            String levelName;
            Vec3f  pos, dir;

            stream.Read(out plID);
            stream.Read(out levelName);
            stream.Read(out pos);
            stream.Read(out dir);

            if (plID == 0 || !sWorld.VobDict.ContainsKey(plID))
            {
                throw new Exception("Vob not found!");
            }
            Vob vob = sWorld.VobDict[plID];

            if (!(vob is NPCProto))
            {
                throw new Exception("Vob is not an NPC!");
            }

            NPCProto playerVob = (NPCProto)vob;

            Process process = Process.ThisProcess();
            oCNpc   npc     = new oCNpc(process, vob.Address);

            if (vob is Player && vob == Player.Hero)
            {
                ((Player)vob).spawned();
                playerVob.Map = levelName;
                zString level = zString.Create(process, playerVob.Map);
                oCGame.Game(process).ChangeLevel(level, level);
                level.Dispose();


                vob.setDirection(dir);
                vob.setPosition(pos);
                Program._state = new GameState();
            }
        }
        public void Read(RakNet.BitStream stream, RakNet.Packet packet, Client client)
        {
            int   plID = 0;
            short anim = 0;

            stream.Read(out plID);
            stream.Read(out anim);

            if (plID == 0 || !sWorld.VobDict.ContainsKey(plID))
            {
                throw new Exception("Vob not found!");
            }
            Vob vob = sWorld.VobDict[plID];

            if (!(vob is NPCProto))
            {
                throw new Exception("Vob is not an NPC!");
            }

            short oldAni = ((NPCProto)vob).Animation;

            ((NPCProto)vob).Animation          = anim;
            ((NPCProto)vob).AnimationStartTime = Program.Now;

            if (vob.Address == 0)
            {
                return;
            }

            Process process = Process.ThisProcess();
            oCNpc   npc     = new oCNpc(process, vob.Address);

            if (oldAni != short.MaxValue)
            {
                npc.GetModel().StopAni(oldAni);
            }
            npc.GetModel().StartAni(anim, 0);

            //npc.GetModel().GetAniFromAniID(anim).AniName.Value;
        }
Example #13
0
        public void Read(RakNet.BitStream stream, RakNet.Packet packet, Server server)
        {
            int   vobID = 0;
            Vec3f pos, dir;

            stream.Read(out vobID);
            stream.Read(out pos);
            stream.Read(out dir);

            if (vobID == 0 || !sWorld.VobDict.ContainsKey(vobID))
            {
                throw new Exception("Vob not found!");
            }
            Vob vob = sWorld.VobDict[vobID];

            vob.Position  = pos;
            vob.Direction = dir;



            Write(vob, packet.systemAddress);
        }
        public void Read(RakNet.BitStream stream, RakNet.Packet packet, Server server)
        {
            int plID = 0, itemID = 0;

            stream.Read(out plID);
            stream.Read(out itemID);

            if (plID == 0 || !sWorld.VobDict.ContainsKey(plID))
            {
                throw new Exception("Vob not found!");
            }
            Vob vob = sWorld.VobDict[plID];

            if (!(vob is NPCProto))
            {
                throw new Exception("Vob is not an NPC!");
            }

            if (itemID == 0 || !sWorld.VobDict.ContainsKey(itemID))
            {
                throw new Exception("Item not found!");
            }
            Vob item = sWorld.VobDict[itemID];

            if (!(item is Item))
            {
                throw new Exception("Vob is not an Item!");
            }

            int amount = ((Item)item).Amount;

            NPCProto proto = (NPCProto)vob;

            item = proto.TakeItem((Item)item);

            Scripting.Objects.Character.NPCProto.OnItemTakes(proto.ScriptingNPC, (Scripting.Objects.Item)item.ScriptingVob, amount);

            Write(proto, (Item)item, packet.guid);
        }
Example #15
0
    private void DoReceive()
    {
        Packet recvPkg = this.client.Receive();

        if (recvPkg == null)
        {
            return;
        }

        byte type = recvPkg.data[0];

        switch ((DefaultMessageIDTypes)type)
        {
        case DefaultMessageIDTypes.ID_DISCONNECTION_NOTIFICATION:
        case DefaultMessageIDTypes.ID_CONNECTION_LOST:
        case DefaultMessageIDTypes.ID_REMOTE_DISCONNECTION_NOTIFICATION:
        case DefaultMessageIDTypes.ID_REMOTE_CONNECTION_LOST:
            UnityEngine.Debug.Log("连接断开");
            break;

        case DefaultMessageIDTypes.ID_NEW_INCOMING_CONNECTION:
            UnityEngine.Debug.LogFormat("终端 {0} 连入", recvPkg.systemAddress.ToString(true));
            break;

        // 主动连接成功
        case DefaultMessageIDTypes.ID_CONNECTION_REQUEST_ACCEPTED:
            Log.WriteLine("连接成功");
            break;

        // 主动连接失败
        case DefaultMessageIDTypes.ID_CONNECTION_ATTEMPT_FAILED:
            Log.WriteLine("目标不可达");
            break;

        // raknet自定义事件类型
        case DefaultMessageIDTypes.ID_USER_PACKET_ENUM:
        {
            RakNet.BitStream reader = new RakNet.BitStream();
            reader.Write(recvPkg.data, recvPkg.length);
            reader.IgnoreBytes(1);

            string msg;
            reader.Read(out msg);

            Log.WriteLine(msg);

            Debug.LogFormat("response msg:{0}", msg);
        }
        break;
        }
    }
Example #16
0
        public void Read(RakNet.BitStream stream, RakNet.Packet packet, Server server)
        {
            int plID = 0, itemID = 0;

            stream.Read(out plID);
            stream.Read(out itemID);

            if (plID == 0 || !sWorld.VobDict.ContainsKey(plID))
            {
                throw new Exception("Vob not found! ID:" + plID);
            }
            Vob vob = sWorld.VobDict[plID];

            if (!(vob is NPCProto))
            {
                throw new Exception("Vob is not an NPC!");
            }

            if (itemID == 0 || !sWorld.VobDict.ContainsKey(itemID))
            {
                throw new Exception("Item not found! ID:" + itemID);
            }
            Vob item = sWorld.VobDict[itemID];

            if (!(item is Item))
            {
                throw new Exception("Vob is not an Item!");
            }

            NPCProto proto = (NPCProto)vob;
            Item     itm   = (Item)item;

            proto.DropItem(itm);

            Scripting.Objects.Character.NPCProto.isOnDropItem(proto.ScriptingNPC, (Scripting.Objects.Item)itm.ScriptingProto, itm.Amount);

            Write(proto, itm, packet.guid);
        }
        private Item UpdateItem(RakNet.BitStream stream)
        {
            int itemID = 0;

            stream.Read(out itemID);
            if (itemID > 0)
            {
                return((Item)sWorld.VobDict[itemID]);
            }
            else
            {
                return(null);
            }
        }
        private static Vob UpdateVob(RakNet.BitStream stream)
        {
            int vobID = 0;

            stream.Read(out vobID);

            if (vobID == 0)
            {
                return(null);
            }
            else
            {
                return(sWorld.VobDict[vobID]);
            }
        }
        public void Read(RakNet.BitStream stream, RakNet.Packet packet, Server server)
        {
            Vec3f locHit = null, flydir = null;
            int   victim = 0, attacker = 0, weaponMode = 0, spellID = 0, weapon = 0;
            float fallDownDistanceY = 0.0f;

            byte sendFlags, damageMode;

            stream.Read(out victim);
            stream.Read(out damageMode);
            stream.Read(out sendFlags);

            if ((sendFlags & 1) == 1)
            {
                stream.Read(out locHit);
            }
            if ((sendFlags & 2) == 2)
            {
                stream.Read(out flydir);
            }
            if ((sendFlags & 4) == 4)
            {
                stream.Read(out attacker);
            }
            if ((sendFlags & 8) == 8)
            {
                stream.Read(out weaponMode);
            }
            if ((sendFlags & 16) == 16)
            {
                stream.Read(out spellID);
            }
            if ((sendFlags & 32) == 32)
            {
                stream.Read(out weapon);
            }
            if ((sendFlags & 64) == 64)
            {
                stream.Read(out fallDownDistanceY);
            }

            NPCProto vicProto = (NPCProto)sWorld.VobDict[victim];
            Vob      attProto = null;

            Scripting.Objects.Vob attackerScriptProto = null;

            if (attacker != 0)
            {
                attProto            = sWorld.VobDict[attacker];
                attackerScriptProto = attProto.ScriptingVob;
            }

            Item weaponIt = null;

            Scripting.Objects.Item weaponScriptItem = null;
            if (weapon != 0)
            {
                weaponIt         = (Item)sWorld.VobDict[weapon];
                weaponScriptItem = weaponIt.ScriptingProto;
            }


            Spell spell = null;

            Scripting.Objects.Spell scriptSpell = null;
            if (spellID > 100)
            {
                Spell.SpellDict.TryGetValue(spellID, out spell);
                if (spell != null)
                {
                    scriptSpell = spell.ScriptingProto;
                }
            }

            Scripting.Objects.Character.NPCProto.isOnDamage(vicProto.ScriptingNPC, (DamageTypes)damageMode, locHit, flydir, attackerScriptProto, weaponMode, scriptSpell, weaponScriptItem, fallDownDistanceY);
            Write(vicProto, (DamageTypes)damageMode, locHit, flydir, attProto, weaponMode, spell, weaponIt, fallDownDistanceY, packet.guid);
        }
Example #20
0
        public void Read(RakNet.BitStream stream, RakNet.Packet packet, Server server)
        {
            int casterID = 0, targetID = 0, spellID = 0, itemID = 0, castLevel = 0;

            stream.Read(out itemID);
            stream.Read(out casterID);
            stream.Read(out targetID);
            stream.Read(out spellID);
            stream.Read(out castLevel);

            Vob  itemVob = null;
            Item item    = null;

            Vob   casterVob = null;
            Spell spell     = null;

            NPCProto caster = null;
            Vob      target = null;

            sWorld.VobDict.TryGetValue(casterID, out casterVob);
            sWorld.VobDict.TryGetValue(itemID, out itemVob);

            if (casterVob == null)
            {
                throw new Exception("Caster was not found!");
            }
            if (!(casterVob is NPCProto))
            {
                throw new Exception("Caster was not a npcproto " + casterVob);
            }
            caster = (NPCProto)casterVob;
            if (targetID != 0)
            {
                sWorld.VobDict.TryGetValue(targetID, out target);
            }

            Spell.SpellDict.TryGetValue(spellID, out spell);
            if (spell == null)
            {
                throw new Exception("Spell can not be null!");
            }


            Scripting.Objects.Vob sT = (target == null) ? null : target.ScriptingVob;


            if (itemVob != null)
            {
                item = (Item)itemVob;
                if (item.ItemInstance.Flags.HasFlag(Flags.ITEM_MULTI))
                {
                    item.Amount -= 1;
                }
            }

            int manaInvested = 0;
            int realLevel    = (spell.processMana.Length > castLevel + 1) ? castLevel : spell.processMana.Length - 1;

            for (int i = 0; i <= realLevel; i++)
            {
                manaInvested += spell.processMana[i];
            }
            caster.ScriptingNPC.MP -= manaInvested;

            Scripting.Objects.Character.NPCProto.isOnCastSpell(
                caster.ScriptingNPC, spell.ScriptingProto, sT);



            Write(caster, item, target, spell, packet.guid);
        }
Example #21
0
        static void Main(string[] args)
        {
            if (!File.Exists("RakNet.dll"))
            {
                Console.WriteLine("The SWIG build of the DLL has not been copied to the executable directory\nCopy from Swig/SwigWindowsCSharpSample/SwigTestApp/bin/X86/Debug/RakNet.dll to\nSwigWindowsCSharpSample/SwigTestApp/bin/Debug/RakNet.dll\nPress enter to quit.");
                Console.Read();
                return;
            }

            try
            {
                RakString dllCallTest = new RakString();
            }
            catch (Exception e)
            {
                Console.WriteLine("DLL issue\nAdd SwigOutput/CplusDLLIncludes/RakNetWrap.cxx to the project\nDLL_Swig/RakNet.sln and rebuild.\nPress enter to quit.");
                Console.Read();
                return;
            }

            Packet testPacket;
            int loopNumber;
            BitStream stringTestSendBitStream = new BitStream();
            BitStream rakStringTestSendBitStream = new BitStream();
            BitStream receiveBitStream = new BitStream();
            String holdingString;
            TimeSpan startTimeSpan;
            RakString rakStringTest = new RakString();

            RakPeerInterface testClient = RakPeer.GetInstance();
            
            testClient.Startup(1, new SocketDescriptor(60000, "127.0.0.1"), 1);

            RakPeerInterface testServer = RakPeer.GetInstance();
            testServer.Startup(1, new SocketDescriptor(60001, "127.0.0.1"), 1);
            testServer.SetMaximumIncomingConnections(1);

            Console.WriteLine("Send and receive loop using BitStream.\nBitStream read done into RakString");

            testClient.Connect("127.0.0.1", 60001, "", 0);

            String sendString = "The test string";
            stringTestSendBitStream.Write((byte)DefaultMessageIDTypes.ID_USER_PACKET_ENUM);
            stringTestSendBitStream.Write(sendString);

            RakString testRakString = new RakString("Test RakString");
            rakStringTestSendBitStream.Write((byte)DefaultMessageIDTypes.ID_USER_PACKET_ENUM);
            rakStringTestSendBitStream.Write(testRakString);

            startTimeSpan = (DateTime.UtcNow - new DateTime(1970, 1, 1));
            loopNumber = 0;

            while (startTimeSpan.TotalSeconds + 5 > (DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds)
            {
                testPacket = testServer.Receive();
                if (testPacket != null && testPacket.data[0] == (byte)DefaultMessageIDTypes.ID_USER_PACKET_ENUM)
                {
                    receiveBitStream.Reset();
                    receiveBitStream.Write(testPacket.data, testPacket.length);
                    receiveBitStream.IgnoreBytes(1);
                    receiveBitStream.Read(rakStringTest);
                    Console.WriteLine("Loop number: " + loopNumber + "\nData: " + rakStringTest.C_String());
                }
                testServer.DeallocatePacket(testPacket);
                loopNumber++;
                System.Threading.Thread.Sleep(50);
                testClient.Send(rakStringTestSendBitStream, PacketPriority.LOW_PRIORITY, PacketReliability.RELIABLE_ORDERED, (char)0, new AddressOrGUID(new SystemAddress("127.0.0.1", 60001)), false);
            }

            Console.WriteLine("String send and receive loop using BitStream.\nBitStream read done into String");

            SystemAddress[] remoteSystems;
            ushort numberOfSystems=1;
            testServer.GetConnectionList(out remoteSystems, ref numberOfSystems);

            startTimeSpan = (DateTime.UtcNow - new DateTime(1970, 1, 1));
            loopNumber = 0;
            while (startTimeSpan.TotalSeconds + 5 > (DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds)
            {
                testPacket = testServer.Receive();
                if (testPacket != null && testPacket.data[0] == (byte)DefaultMessageIDTypes.ID_USER_PACKET_ENUM)
                {
                    receiveBitStream.Reset();
                    receiveBitStream.Write(testPacket.data, testPacket.length);
                    receiveBitStream.IgnoreBytes(1);
                    receiveBitStream.Read(out holdingString);
                    Console.WriteLine("Loop number: " + loopNumber + "\nData: " + holdingString);
                }
                testServer.DeallocatePacket(testPacket);
                loopNumber++;
                System.Threading.Thread.Sleep(50);
                SystemAddress sa = RakNet.RakNet.UNASSIGNED_SYSTEM_ADDRESS;
                testClient.Send(stringTestSendBitStream, PacketPriority.LOW_PRIORITY, PacketReliability.RELIABLE_ORDERED, (char)0, new AddressOrGUID(new SystemAddress("127.0.0.1", 60001)), false);
            }
            //If RakString is not freed before program exit it will crash
            rakStringTest.Dispose();
            testRakString.Dispose();

            RakPeer.DestroyInstance(testClient);
            RakPeer.DestroyInstance(testServer);
            Console.WriteLine("Demo complete. Press Enter.");
            Console.Read();
        }
Example #22
0
    // Use this for initialization
    void Start()
    {
        try
        {
            RakString dllCallTest = new RakString();
        }
        catch (Exception e)
        {
            Debug.Log("DLL issue\nAdd SwigOutput/CplusDLLIncludes/RakNetWrap.cxx to the project\nDLL_Swig/RakNet.sln and rebuild.\nPress enter to quit.");
            return;
        }

        Packet testPacket;
        int    loopNumber;

        RakNet.BitStream stringTestSendBitStream    = new RakNet.BitStream();
        RakNet.BitStream rakStringTestSendBitStream = new RakNet.BitStream();
        RakNet.BitStream receiveBitStream           = new RakNet.BitStream();
        String           holdingString;
        TimeSpan         startTimeSpan;
        RakString        rakStringTest = new RakString();

        RakPeerInterface testClient = RakPeer.GetInstance();

        testClient.Startup(1, new SocketDescriptor(60000, "127.0.0.1"), 1);

        RakPeerInterface testServer = RakPeer.GetInstance();

        testServer.Startup(1, new SocketDescriptor(60001, "127.0.0.1"), 1);
        testServer.SetMaximumIncomingConnections(1);

        Console.WriteLine("Send and receive loop using BitStream.\nBitStream read done into RakString");

        testClient.Connect("127.0.0.1", 60001, "", 0);

        String sendString = "The test string";

        stringTestSendBitStream.Write((byte)DefaultMessageIDTypes.ID_USER_PACKET_ENUM);
        stringTestSendBitStream.Write(sendString);

        RakString testRakString = new RakString("Test RakString");

        rakStringTestSendBitStream.Write((byte)DefaultMessageIDTypes.ID_USER_PACKET_ENUM);
        rakStringTestSendBitStream.Write(testRakString);

        startTimeSpan = (DateTime.UtcNow - new DateTime(1970, 1, 1));
        loopNumber    = 0;

        while (startTimeSpan.TotalSeconds + 5 > (DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds)
        {
            testPacket = testServer.Receive();
            if (testPacket != null && testPacket.data[0] == (byte)DefaultMessageIDTypes.ID_USER_PACKET_ENUM)
            {
                receiveBitStream.Reset();
                receiveBitStream.Write(testPacket.data, testPacket.length);
                receiveBitStream.IgnoreBytes(1);
                receiveBitStream.Read(rakStringTest);
                Debug.Log("Loop number: " + loopNumber + "\nData: " + rakStringTest.C_String());
            }
            testServer.DeallocatePacket(testPacket);
            loopNumber++;
            System.Threading.Thread.Sleep(50);
            testClient.Send(rakStringTestSendBitStream, PacketPriority.LOW_PRIORITY, PacketReliability.RELIABLE_ORDERED, (char)0, new AddressOrGUID(new SystemAddress("127.0.0.1", 60001)), false);
        }

        Debug.Log("String send and receive loop using BitStream.\nBitStream read done into String");

        SystemAddress[] remoteSystems;
        ushort          numberOfSystems = 1;

        testServer.GetConnectionList(out remoteSystems, ref numberOfSystems);

        startTimeSpan = (DateTime.UtcNow - new DateTime(1970, 1, 1));
        loopNumber    = 0;
        while (startTimeSpan.TotalSeconds + 5 > (DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds)
        {
            testPacket = testServer.Receive();
            if (testPacket != null && testPacket.data[0] == (byte)DefaultMessageIDTypes.ID_USER_PACKET_ENUM)
            {
                receiveBitStream.Reset();
                receiveBitStream.Write(testPacket.data, testPacket.length);
                receiveBitStream.IgnoreBytes(1);
                receiveBitStream.Read(out holdingString);
                Debug.Log("Loop number: " + loopNumber + "\nData: " + holdingString);
            }
            testServer.DeallocatePacket(testPacket);
            loopNumber++;
            System.Threading.Thread.Sleep(50);
            SystemAddress sa = RakNet.RakNet.UNASSIGNED_SYSTEM_ADDRESS;
            testClient.Send(stringTestSendBitStream, PacketPriority.LOW_PRIORITY, PacketReliability.RELIABLE_ORDERED, (char)0, new AddressOrGUID(new SystemAddress("127.0.0.1", 60001)), false);
        }
        //If RakString is not freed before program exit it will crash
        rakStringTest.Dispose();
        testRakString.Dispose();

        RakPeer.DestroyInstance(testClient);
        RakPeer.DestroyInstance(testServer);
        Debug.Log("Demo complete. Press Enter.");
    }
        public void Read(RakNet.BitStream stream, RakNet.Packet packet, Client client)
        {
            int id = 0;

            stream.Read(out id);
            Player.Hero.ID = id;

            sWorld.addVob(Player.Hero);

            using (BitStream stream2 = new BitStream())
            {
                Zip.Decompress(stream, stream2);
                stream = stream2;



                stream.Read(out Player.EnableStatusMenu);
                stream.Read(out Player.EnableLogMenu);

                //Player-Defaults:
                if (Player.EnableStatusMenu)
                {
                    Gothic.mClasses.InputHooked.deactivateStatusScreen(Process.ThisProcess(), true);
                }
                if (Player.EnableLogMenu)
                {
                    Gothic.mClasses.InputHooked.deactivateLogScreen(Process.ThisProcess(), true);
                }



                stream.Read(out Player.sSendAllKeys);
                int playerKeyCount = 0;
                stream.Read(out playerKeyCount);
                for (int i = 0; i < playerKeyCount; i++)
                {
                    byte key = 0;
                    stream.Read(out key);
                    Player.sSendKeys.Add(key);
                }


                int  day = 0;
                byte hour = 0, minute = 0;
                stream.Read(out day);
                stream.Read(out hour);
                stream.Read(out minute);

                sWorld.Day    = day;
                sWorld.Hour   = hour;
                sWorld.Minute = minute;


                byte wt = 0, starthour = 0, startminute = 0, endhour = 0, endminute;

                stream.Read(out wt);
                stream.Read(out starthour);
                stream.Read(out startminute);
                stream.Read(out endhour);
                stream.Read(out endminute);

                sWorld.WeatherType     = wt;
                sWorld.StartRainHour   = starthour;
                sWorld.StartRainMinute = startminute;
                sWorld.EndRainHour     = endhour;
                sWorld.EndRainMinute   = endminute;


                short spellCount = 0;
                stream.Read(out spellCount);
                for (int i = 0; i < spellCount; i++)
                {
                    Spell spell = new Spell();
                    spell.Read(stream);
                    Spell.addItemInstance(spell);
                }

                short itemInstancesCount = 0;
                stream.Read(out itemInstancesCount);
                for (int i = 0; i < itemInstancesCount; i++)
                {
                    ItemInstance ii = new ItemInstance();
                    ii.Read(stream);


                    ItemInstance.addItemInstance(ii);
                }
                CreateItems();

                //ItemList:
                int iLC = 0;
                stream.Read(out iLC);
                for (int i = 0; i < iLC; i++)
                {
                    Item item = new Item();
                    item.Read(stream);
                    sWorld.addVob(item);
                }

                //Vob-List:
                int vLC = 0;
                stream.Read(out vLC);
                for (int i = 0; i < vLC; i++)
                {
                    int vobType = 0;
                    stream.Read(out vobType);
                    Vob vob = Vob.createVob((VobType)vobType);
                    vob.Read(stream);
                    sWorld.addVob(vob);
                }

                //NPC-List:
                int nLC = 0;
                stream.Read(out nLC);
                for (int i = 0; i < nLC; i++)
                {
                    NPC npc = new NPC();
                    npc.Read(stream);
                    sWorld.addVob(npc);
                }

                //Player-List:
                int pLC = 0;
                stream.Read(out pLC);
                for (int i = 0; i < pLC; i++)
                {
                    Player player = new Player(false, "");
                    player.Read(stream);

                    if (player.ID == id)
                    {
                        continue;
                    }
                    sWorld.addVob(player);
                }

                //WorldSpawnList:
                int worldListCount = 0;
                stream.Read(out worldListCount);
                for (int i = 0; i < worldListCount; i++)
                {
                    World w = new World();
                    w.Read(stream);

                    sWorld.WorldDict.Add(w.Map, w);
                }
            }
        }
Example #24
0
        static void Main(string[] args)
        {

           if(!File.Exists("RakNet.dll"))
           {
                Console.WriteLine("Error: The SWIG build of the DLL has not been copied to the executable directory.\nPress enter.");
                Console.Read();
                return;
           }
            
            Packet testPacket;
            int loopNumber;
            BitStream stringTestSendBitStream = new BitStream();
            BitStream rakStringTestSendBitStream = new BitStream();
            BitStream receiveBitStream = new BitStream();
            String holdingString;
            TimeSpan startTimeSpan;
            RakString rakStringTest = new RakString();

            RakPeerInterface testClient = RakPeer.GetInstance();
            testClient.Startup(1, new SocketDescriptor(60000, "127.0.0.1"), 1);

            RakPeerInterface testServer = RakPeer.GetInstance();
            testServer.Startup(1, new SocketDescriptor(60001, "127.0.0.1"), 1);
            testServer.SetMaximumIncomingConnections(1);

            Console.WriteLine("Press enter to start RakString send and receive loop using BitStream.\nBitStream read done into RakString");
            Console.WriteLine("Loop will run for 15 seconds");
            Console.ReadLine();

            testClient.Connect("127.0.0.1", 60001, "", 0);

            String sendString = "The test string";
            stringTestSendBitStream.Write((byte)DefaultMessageIDTypes.ID_USER_PACKET_ENUM);
            stringTestSendBitStream.Write(sendString);

            RakString testRakString = new RakString("Test RakString");
            rakStringTestSendBitStream.Write((byte)DefaultMessageIDTypes.ID_USER_PACKET_ENUM);
            rakStringTestSendBitStream.Write(testRakString);

            startTimeSpan = (DateTime.UtcNow - new DateTime(1970, 1, 1));
            loopNumber = 0;
                while (startTimeSpan.TotalSeconds + 15 > (DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds)
                {
                    testPacket = testServer.Receive();
                    if (testPacket != null && testPacket.data[0] == (byte)DefaultMessageIDTypes.ID_USER_PACKET_ENUM)
                    {
                        receiveBitStream.Reset();
                        receiveBitStream.Write(testPacket.data, testPacket.length);
                        receiveBitStream.IgnoreBytes(1);
                        receiveBitStream.Read(rakStringTest);
                        Console.WriteLine("Loop number: " + loopNumber + "\nData: " + rakStringTest.C_String());
                    }
                    testServer.DeallocatePacket(testPacket);
                    loopNumber++;
                    System.Threading.Thread.Sleep(50);
                    testClient.Send(rakStringTestSendBitStream, PacketPriority.LOW_PRIORITY, PacketReliability.RELIABLE_ORDERED, (char)0, new AddressOrGUID(new SystemAddress("127.0.0.1", 60001)), false);
                }

                Console.WriteLine("Press enter to start String send and receive loop using BitStream.\nBitStream read done into String");
                Console.WriteLine("Loop will run for 15 seconds");
                Console.ReadLine();

                startTimeSpan = (DateTime.UtcNow - new DateTime(1970, 1, 1));
                loopNumber = 0;
                while (startTimeSpan.TotalSeconds + 15 > (DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds)
                {
                    testPacket = testServer.Receive();
                    if (testPacket != null && testPacket.data[0] == (byte)DefaultMessageIDTypes.ID_USER_PACKET_ENUM)
                    {
                        receiveBitStream.Reset();
                        receiveBitStream.Write(testPacket.data, testPacket.length);
                        receiveBitStream.IgnoreBytes(1);
                        receiveBitStream.Read(out holdingString);
                        Console.WriteLine("Loop number: " + loopNumber + "\nData: " + holdingString);
                    }
                    testServer.DeallocatePacket(testPacket);
                    loopNumber++;
                    System.Threading.Thread.Sleep(50);
                    testClient.Send(stringTestSendBitStream, PacketPriority.LOW_PRIORITY, PacketReliability.RELIABLE_ORDERED, (char)0, new AddressOrGUID(new SystemAddress("127.0.0.1", 60001)), false);
                }
            //-----------------------------Above is the same as the public tests, below the internal tests are ran.
            /*Member variables are also tested to assure working typemaps
             * Also variables use functions as well, they are not direct access
             * act like it. Test write and read on these items, especially arrays.
             * Most tests in this section are simple running functions with no verification.
             * 
             * 
            */

            RakString workingRakStringCopy;//This is needed for temp RakString Instances in the main function so dispose can be called

            //RakNetStatistics
            Console.WriteLine("RakNetStatistics");
            string rakNetStatisticsTestString;
            RakNetStatistics testRakNetStatistics = new RakNetStatistics();
            testRakNetStatistics.bytesInSendBuffer[0] = 22.44;
            testRakNetStatistics.BPSLimitByCongestionControl = 9;
            testRakNetStatistics.BPSLimitByOutgoingBandwidthLimit = 9;
            testRakNetStatistics.connectionStartTime = 9;
            testRakNetStatistics.isLimitedByCongestionControl = false;
            testRakNetStatistics.isLimitedByOutgoingBandwidthLimit = true;
            testRakNetStatistics.messageInSendBuffer[0] = 112;
            testRakNetStatistics.messagesInResendBuffer = 9;
            testRakNetStatistics.packetlossLastSecond = 4.3f;
            testRakNetStatistics.packetlossTotal = 9.9f;
            testRakNetStatistics.runningTotal[0] = 121;
            testRakNetStatistics.valueOverLastSecond[0] = 112;

            Console.WriteLine(testRakNetStatistics.bytesInSendBuffer[0]);
            Console.WriteLine(testRakNetStatistics.BPSLimitByCongestionControl);
            Console.WriteLine(testRakNetStatistics.BPSLimitByOutgoingBandwidthLimit);
            Console.WriteLine(testRakNetStatistics.connectionStartTime);
            Console.WriteLine(testRakNetStatistics.isLimitedByCongestionControl);
            Console.WriteLine(testRakNetStatistics.isLimitedByOutgoingBandwidthLimit);
            Console.WriteLine(testRakNetStatistics.messageInSendBuffer[0]);
            Console.WriteLine(testRakNetStatistics.messagesInResendBuffer);
            Console.WriteLine(testRakNetStatistics.packetlossLastSecond);
            Console.WriteLine(testRakNetStatistics.packetlossTotal);
            Console.WriteLine(testRakNetStatistics.runningTotal[0]);
            Console.WriteLine(testRakNetStatistics.valueOverLastSecond[0]);

            RakNet.RakNet.StatisticsToString(testRakNetStatistics, out rakNetStatisticsTestString, 1);
            Console.WriteLine(rakNetStatisticsTestString);

            //SystemAddress
            Console.WriteLine("SystemAddress");
            SystemAddress testSystemAddress = new SystemAddress("127.0.0.1", 60001);

            //RakNetGUID
            RakNetGUID testRakNetGUID = testClient.GetGuidFromSystemAddress(RakNet.RakNet.UNASSIGNED_SYSTEM_ADDRESS);

            Console.WriteLine(testRakNetGUID);

            //AddressOrGUID
            Console.WriteLine("AddressOrGUID");
            AddressOrGUID testAddressOrGUIDAddress = new AddressOrGUID(testSystemAddress);

            Console.WriteLine(testAddressOrGUIDAddress.systemAddress);

            AddressOrGUID testAddressOrGUIDRakNetGUID = new AddressOrGUID(testRakNetGUID);

            Console.WriteLine(testAddressOrGUIDRakNetGUID.rakNetGuid);

            //BitStream
            Console.WriteLine("BitStream");
            BitStream testBitStream1 = new BitStream();
            BitStream testBitStream2 = new BitStream();
            byte[] testBuffer = new byte[999];
            byte[] writeArray = new byte[99];
            Packet bitStreamTestPacket = null;

            testBitStream1.Write((byte)DefaultMessageIDTypes.ID_USER_PACKET_ENUM);
            testBitStream1.ResetWritePointer();
            testBitStream1.Write((byte)DefaultMessageIDTypes.ID_USER_PACKET_ENUM);

            writeArray[0] = (byte)127;
            testBitStream1.Write("xy");
            testBitStream1.WriteCompressed("xy");
            testBitStream1.WriteFloat16(23.5f, 0, 100);
            testBitStream1.WriteBits(writeArray, 7);
            testBitStream1.WriteAlignedBytesSafe(writeArray, 1, 1);
            testBitStream1.WriteAlignedBytes(writeArray, 1);
            testBitStream1.Write0();
            testBitStream1.Write1();
            int intForSerialization = 99;
            testBitStream1.Serialize(true, ref intForSerialization);

            testClient.Send(testBitStream1, PacketPriority.HIGH_PRIORITY, PacketReliability.RELIABLE_ORDERED, (char)0, new AddressOrGUID(RakNet.RakNet.UNASSIGNED_SYSTEM_ADDRESS), true);

            while (bitStreamTestPacket == null || bitStreamTestPacket.data[0] != (byte)DefaultMessageIDTypes.ID_USER_PACKET_ENUM)
            {
                if (bitStreamTestPacket != null)
                {
                    testServer.DeallocatePacket(bitStreamTestPacket);
                }
                bitStreamTestPacket = testServer.Receive();
                testClient.Send(testBitStream1, PacketPriority.HIGH_PRIORITY, PacketReliability.RELIABLE_ORDERED, (char)0, new AddressOrGUID(RakNet.RakNet.UNASSIGNED_SYSTEM_ADDRESS), true);
            }

            testBitStream2.Reset();
            testBitStream2 = new BitStream(bitStreamTestPacket.data, bitStreamTestPacket.length, true);

            testBitStream2.IgnoreBytes(1);
            testBitStream2.ResetReadPointer();
            testBitStream2.IgnoreBits(8);
            testBitStream2.ResetReadPointer();
            testBitStream2.ReadBits(testBuffer, 8);
            Console.WriteLine(testBuffer[0]);
            Console.WriteLine(DefaultMessageIDTypes.ID_USER_PACKET_ENUM);
            testBitStream2.ResetReadPointer();
            testBitStream2.ReadAlignedVar8(testBuffer);
            Console.WriteLine(testBuffer[0]);
            testBitStream2.ResetReadPointer();
            testBitStream2.ReadAlignedVar16(testBuffer);
            Console.WriteLine(testBuffer[1]);
            testBitStream2.ResetReadPointer();
            testBitStream2.ReadAlignedVar32(testBuffer);
            Console.WriteLine(testBuffer[1]);
            testBitStream2.ResetReadPointer();
            testBitStream2.IgnoreBits(8);

            Console.WriteLine("testBitStream1 hex and bits");
            testBitStream1.PrintHex();
            Console.WriteLine("\n");
            testBitStream1.PrintBits();
            Console.WriteLine("\ntestBitStream1 hex and bits");

            Console.WriteLine("testBitStream2 hex and bits end");
            testBitStream2.PrintHex();
            Console.WriteLine("\n");
            testBitStream2.PrintBits();
            Console.WriteLine("\ntestBitStream2 hex and bits end");

            String testString;
            Console.WriteLine("testBitStream2 hex and bits string output");
            testBitStream2.PrintHex(out testString);
            Console.WriteLine(testString + "\n");
            testBitStream2.PrintBits(out testString);
            Console.WriteLine(testString);
            Console.WriteLine("testBitStream2 hex and bits string output end");

            testBitStream2.Read(out testString);
            Console.WriteLine(testString);

            Console.WriteLine(testBitStream2.ReadCompressed(out testString));
            Console.WriteLine(testString);
            testBitStream2.WriteCompressedDelta("xy", "yz");
            testBitStream2.WriteCompressedDelta("xy", "xy");
            Console.WriteLine(testBitStream2.ReadCompressedDelta(out testString));
            Console.WriteLine(testString);
            Console.WriteLine(testBitStream2.ReadCompressedDelta(out testString));
            Console.WriteLine(testString);
            testBitStream2.WriteDelta("xy", "yz");
            testBitStream2.WriteDelta("xy", "xy");
            Console.WriteLine(testBitStream2.ReadDelta(out testString));
            Console.WriteLine(testString);
            Console.WriteLine(testBitStream2.ReadDelta(out testString));
            Console.WriteLine(testString);

            float testFloat;
            testBitStream2.ReadFloat16(out testFloat, 0, 100);
            Console.WriteLine(testFloat);
            testBitStream2.ReadBits(testBuffer, 7);
            Console.WriteLine(testBuffer[0]);
            testBitStream2.ReadAlignedBytesSafe(testBuffer, 1, 1);
            Console.WriteLine(testBuffer[0]);
            testBitStream2.ReadAlignedBytes(testBuffer, 1);
            Console.WriteLine(testBuffer[0]);
            Console.WriteLine(testBitStream2.ReadBit());
            Console.WriteLine(testBitStream2.ReadBit());
            int intForSerialization2 = 0;
            testBitStream2.Serialize(false, ref intForSerialization2);
            Console.WriteLine(intForSerialization2);

            testBitStream2.PadWithZeroToByteLength(99);
            testBitStream2.PrintBits();
            testBitStream2.SetData(testBuffer);
            Console.WriteLine("setbuff");
            testBitStream2.PrintBits();

            Console.WriteLine(testBitStream2.GetNumberOfBitsAllocated());

            //ByteQueue
            Console.WriteLine("ByteQueue");
            ByteQueue testByteQueue = new ByteQueue();
            testByteQueue.WriteBytes(testBuffer, (uint)testBuffer.Length, "", 0);
            testByteQueue.DecrementReadOffset(1);
            Console.WriteLine(testByteQueue.GetBytesWritten());
            testByteQueue.IncrementReadOffset(1);
            uint testUint;
            byte[] returnArray = testByteQueue.PeekContiguousBytes(out testUint);
            testByteQueue.Print();
            testByteQueue.ReadBytes(returnArray, (uint)returnArray.Length, true);
            testByteQueue.Clear("", 0);

            testBitStream2.AddBitsAndReallocate(99);
            testBitStream2.AlignReadToByteBoundary();
            testBitStream2.AlignWriteToByteBoundary();
            testBitStream2.EndianSwapBytes(5, 5);
            returnArray = testBitStream2.GetData();
            Console.WriteLine(testBitStream2.GetNumberOfBitsAllocated());
            Console.WriteLine(testBitStream2.GetNumberOfBitsUsed());
            Console.WriteLine(testBitStream2.GetNumberOfBytesUsed());
            Console.WriteLine(testBitStream2.GetNumberOfUnreadBits());
            Console.WriteLine(testBitStream2.GetReadOffset());
            Console.WriteLine(testBitStream2.GetWriteOffset());
            testBitStream2.SetData(returnArray);
            testBitStream2.SetNumberOfBitsAllocated(testBitStream2.GetNumberOfBitsAllocated());
            testBitStream2.SetReadOffset(3);
            testBitStream2.SetWriteOffset(3);
            testBitStream2.WriteBits(returnArray, (uint)returnArray.Length);

            //Cell, Table, Row
            Console.WriteLine("Cell, Table, Row");
            Cell testCell = new Cell();
            Byte[] tableTestByteArray = new byte[1];
            tableTestByteArray[0] = (byte)'t';
            int outInt;
            double outDouble;

            testCell.Set("test1232");
            testCell.Get(out testString);
            Console.WriteLine(testString);
            Console.WriteLine((int)testCell.EstimateColumnType());
            testCell.CopyData(testCell);
            testCell.Set(12.5d);
            testCell.Get(out outDouble);
            Console.WriteLine(outDouble);
            testCell.Set((uint)1);
            testCell.Set((int)1);
            testCell.Get(out outInt);
            Console.WriteLine(outInt);
            testCell.Set(tableTestByteArray, tableTestByteArray.Length);
            testCell.Get(tableTestByteArray, out outInt);
            Console.WriteLine(testCell.i);
            Console.WriteLine(testCell.isEmpty);

            Table testTable = new Table();
            testTable.Clear();
            testTable.AddColumn("testNumeric", Table.ColumnType.NUMERIC);
            testTable.AddColumn("testString", Table.ColumnType.STRING);
            testTable.AddColumn("testBinary", Table.ColumnType.BINARY);
            testTable.AddRow(0, new RakNetListCell());
            testTable.AddRow(1, new RakNetListCell());
            testTable.AddRow(2);
            testTable.AddRow(3);
            testTable.AddRow(4);
            testTable.AddRow(5);

            Console.WriteLine(testTable.ColumnIndex("testNumeric"));
            Console.WriteLine(testTable.ColumnName(0));
            Console.WriteLine(testTable.GetAvailableRowId());
            testTable.UpdateCell(0, 0, 9);
            testTable.UpdateCell(0, 1, "testCell");
            testTable.UpdateCell(0, 2, 1, tableTestByteArray);
            testTable.GetCellValueByIndex(0, 0, out outInt);
            Console.WriteLine(outInt);
            string outString;
            testTable.GetCellValueByIndex(0, 1, out outString);
            Console.WriteLine(outString);

            int outLen;
            testTable.GetCellValueByIndex(0, 2, out tableTestByteArray, out outLen);
            Console.WriteLine(tableTestByteArray[0]);
            Console.WriteLine(outLen);
            Console.WriteLine(testTable.GetColumnCount());
            RakNetListColumnDescriptor descriptorList = testTable.GetColumns();
            Console.WriteLine(testTable.GetColumnType(1) == Table.ColumnType.STRING);

            RakNetPageRow testPageRow = testTable.GetListHead();
            Console.WriteLine(testPageRow.isLeaf);
            Console.WriteLine(testPageRow.size);
            Row testRow = testTable.GetRowByID(0);
            Console.WriteLine(testRow.cells[0]);

            Console.WriteLine(testTable.GetRowCount());
            RakNetBPlusTreeRow bplus = testTable.GetRows();

            byte[] byteTest = new byte[999];
            testTable.PrintColumnHeaders(byteTest, 999, ';');

            testTable.PrintRow(byteTest, 999, ';', true, testRow);

            uint[] columnIds = new uint[1];
            columnIds[0] = 0;
            uint[] rowIds = new uint[1];
            rowIds[0] = 0;

            Table outTable = new Table();
            testTable.QueryTable(columnIds, 1, null, 0, rowIds, 1, outTable);
            Row[] testRows;
            testTable.SortTable(null, 0, out testRows);

            testTable.UpdateCellByIndex(0, 1, "5");
            testTable.PrintColumnHeaders(testBuffer, testBuffer.Length, ';');
            Console.WriteLine(System.Text.Encoding.GetEncoding(1251).GetString(testBuffer).Trim('\0'));

            testTable.PrintRow(testBuffer, testBuffer.Length, ';', true, testRow);
            Console.WriteLine(System.Text.Encoding.GetEncoding(1251).GetString(testBuffer).Trim('\0'));

            testTable.RemoveColumn(2);
            testTable.RemoveRow(2);
            testTable.RemoveRows(outTable);

            //ColumnDescriptor
            Console.WriteLine("ColumnDescriptor");
            ColumnDescriptor testColumnDescriptor = descriptorList.Pop();
            Console.WriteLine(testColumnDescriptor.columnName);
            Console.WriteLine(testColumnDescriptor.columnType);

            //ConnectionGraph2
            Console.WriteLine("ConnectionGraph2");
            ConnectionGraph2 testConnectionGraph2 = new ConnectionGraph2();

            testClient.AttachPlugin(testConnectionGraph2);
            testConnectionGraph2.ConnectionExists(testClient.GetGuidFromSystemAddress(RakNet.RakNet.UNASSIGNED_SYSTEM_ADDRESS), testServer.GetGuidFromSystemAddress(RakNet.RakNet.UNASSIGNED_SYSTEM_ADDRESS));
            SystemAddress[] outSystemAddressList = new SystemAddress[1];
            RakNetGUID[] outGuidList = new RakNetGUID[1];
            uint inOutUint = 1;
            testConnectionGraph2.GetConnectionListForRemoteSystem(testServer.GetGuidFromSystemAddress(RakNet.RakNet.UNASSIGNED_SYSTEM_ADDRESS), outSystemAddressList, outGuidList, ref inOutUint);

            //DirectoryDeltaTransfer
            Console.WriteLine("DirectoryDeltaTransfer");
            DirectoryDeltaTransfer testDirectoryDeltaTransfer = new DirectoryDeltaTransfer();
            testClient.AttachPlugin(testDirectoryDeltaTransfer);

            testDirectoryDeltaTransfer.AddUploadsFromSubdirectory("./");
            testDirectoryDeltaTransfer.ClearUploads();

            FileListTransferCBInterface testCallBack = new FileListTransferCB();
            FileListProgress testFileListProgress = new FileListProgress();

            Console.WriteLine(testDirectoryDeltaTransfer.GetNumberOfFilesForUpload());
            testDirectoryDeltaTransfer.SetApplicationDirectory("./");
           
            IncrementalReadInterface testIncrementalReadInterface = null;
            testDirectoryDeltaTransfer.SetDownloadRequestIncrementalReadInterface(testIncrementalReadInterface, 24);
            FileListTransfer testFileListTransfer = new FileListTransfer();
            testDirectoryDeltaTransfer.SetFileListTransferPlugin(testFileListTransfer);
            testDirectoryDeltaTransfer.SetUploadSendParameters(PacketPriority.HIGH_PRIORITY, (char)0);

            testDirectoryDeltaTransfer.DownloadFromSubdirectory("./", "./", false, testClient.GetSystemAddressFromIndex(0), testCallBack, PacketPriority.HIGH_PRIORITY, (char)0, testFileListProgress);

            //FileListNode
            Console.WriteLine("FileListNode");
            FileListNode testFileListNode = new FileListNode();

            //FileListNodeContext
            Console.WriteLine("FileListNodeContext");
            FileListNodeContext testFileListNodeContext = new FileListNodeContext();
            testFileListNodeContext.op = 0;
            testFileListNodeContext.fileId = 0;
            Console.WriteLine(testFileListNodeContext.op);
            Console.WriteLine(testFileListNodeContext.fileId);

            //FileList
            Console.WriteLine("FileList");
            FileList testFileList = FileList.GetInstance();

            testFileList.AddFile("./", "RakNet.dll", testFileListNodeContext);
            testFileList.AddFilesFromDirectory("./", "./", true, true, false, testFileListNodeContext);
            testFileList.FlagFilesAsReferences();
            FileList outFileList = FileList.GetInstance();
            testFileList.GetDeltaToCurrent(testFileList, outFileList, "", "./");
            Console.WriteLine(testFileList.fileList);
            testFileList.Clear();
            testFileList.DeleteFiles("./notexisting");
            testFileList.ListMissingOrChangedFiles("./", outFileList, false, false);
            testFileList.PopulateDataFromDisk("./", false, false, false);
            testFileList.WriteDataToDisk("./notexisting/");
            testFileList.Serialize(testBitStream2);
            testFileList.SetCallback(testFileListProgress);

            //FileListProgress
            Console.WriteLine("FileListProgress");
            testFileListProgress.OnAddFilesFromDirectoryStarted(testFileList, "./");
            testFileListProgress.OnDirectory(testFileList, "./", 9);
            testFileListProgress.OnFile(testFileList, "./", "nonexist", 22);
            testFileListProgress.OnFilePush("./Nonexist", 99, 99, 99, true, RakNet.RakNet.UNASSIGNED_SYSTEM_ADDRESS);

            //FileListTransferCBInterface
            Console.WriteLine("FileListTransferCBInterface");
            FileListTransferCBInterface testFileListTransferCBInterface = new FileListTransferCBInterface();

            //FileListTransfer
            Console.WriteLine("FileListTransfer");
            FileListTransfer testFileListTransferServer = new FileListTransfer();

            testClient.AttachPlugin(testFileListTransfer);
            testServer.AttachPlugin(testFileListTransferServer);
            testFileListTransfer.GetCallback();
            testFileListTransfer.GetPendingFilesToAddress(RakNet.RakNet.UNASSIGNED_SYSTEM_ADDRESS);
            testFileListTransfer.IsHandlerActive(99);
            testFileListTransfer.SetCallback(testFileListProgress);
            testFileListTransfer.SetupReceive(testFileListTransferCBInterface, false, RakNet.RakNet.UNASSIGNED_SYSTEM_ADDRESS);
            testFileListTransfer.Send(testFileList, testClient, RakNet.RakNet.UNASSIGNED_SYSTEM_ADDRESS, 99, PacketPriority.LOW_PRIORITY, (char)0, testIncrementalReadInterface);
            testFileListTransfer.CancelReceive(0);
            testFileListTransfer.RemoveReceiver(RakNet.RakNet.UNASSIGNED_SYSTEM_ADDRESS);

            //FileProgressStruct
            Console.WriteLine("FileProgressStruct");
            FileProgressStruct testFileProgressStruct = new FileProgressStruct();

            testFileProgressStruct.allocateIrIDataChunkAutomatically = true;
            testFileProgressStruct.dataChunkLength = 99;
            testFileProgressStruct.firstDataChunk = testBuffer;
            testFileProgressStruct.iriDataChunk = testBuffer;
            testFileProgressStruct.iriWriteOffset = 99;
            testFileProgressStruct.onFileStruct = new OnFileStruct();
            testFileProgressStruct.partCount = 99;
            testFileProgressStruct.partTotal = 99;

            Console.WriteLine(testFileProgressStruct.allocateIrIDataChunkAutomatically);
            Console.WriteLine(testFileProgressStruct.dataChunkLength);
            Console.WriteLine(testFileProgressStruct.firstDataChunk[0]);
            Console.WriteLine(testFileProgressStruct.iriDataChunk[0]);
            Console.WriteLine(testFileProgressStruct.iriWriteOffset);
            Console.WriteLine(testFileProgressStruct.onFileStruct);
            Console.WriteLine(testFileProgressStruct.partCount);
            Console.WriteLine(testFileProgressStruct.partTotal);

            //FilterQuery
            Console.WriteLine("FilterQuery");
            FilterQuery testFilterQuery = new FilterQuery();
            testFilterQuery.cellValue = testCell;
            testFilterQuery.columnIndex = 0;
            testFilterQuery.columnName = "TestName";
            testFilterQuery.operation = Table.FilterQueryType.QF_EQUAL;

            Console.WriteLine(testFilterQuery.cellValue);
            Console.WriteLine(testFilterQuery.columnIndex);
            Console.WriteLine(testFilterQuery.columnName);
            Console.WriteLine(testFilterQuery.operation);

            //FLP_Printf
            Console.WriteLine("FLP_Printf");
            FLP_Printf testFLP_Printf = new FLP_Printf();

            testFLP_Printf.OnAddFilesFromDirectoryStarted(testFileList, "./");
            testFLP_Printf.OnDirectory(testFileList, "./", 9);
            testFLP_Printf.OnFile(testFileList, "./", "nonexist", 22);
            testFLP_Printf.OnFilePush("./Nonexist", 99, 99, 99, true, RakNet.RakNet.UNASSIGNED_SYSTEM_ADDRESS);

            //FullyConnectedMesh2
            Console.WriteLine("FullyConnectedMesh2");
            FullyConnectedMesh2 testFullyConnectedMesh2 = FullyConnectedMesh2.GetInstance();
            testClient.AttachPlugin(testFullyConnectedMesh2);
            testFullyConnectedMesh2.AddParticipant(testServer.GetGuidFromSystemAddress(RakNet.RakNet.UNASSIGNED_SYSTEM_ADDRESS));
            Console.WriteLine(testFullyConnectedMesh2.GetConnectedHost());
            Console.WriteLine(testFullyConnectedMesh2.GetConnectedHostAddr());
            Console.WriteLine(testFullyConnectedMesh2.GetHostSystem());
            Console.WriteLine(testFullyConnectedMesh2.GetParticipantCount());
            uint outUint;
            testFullyConnectedMesh2.GetParticipantCount(out outUint);
            Console.WriteLine(outUint);
            Console.WriteLine(testFullyConnectedMesh2.IsConnectedHost());
            Console.WriteLine(testFullyConnectedMesh2.IsHostSystem());
            testFullyConnectedMesh2.ResetHostCalculation();
            testFullyConnectedMesh2.SetAutoparticipateConnections(true);
            workingRakStringCopy = "none";
            testFullyConnectedMesh2.SetConnectOnNewRemoteConnection(false, workingRakStringCopy);
            workingRakStringCopy.Dispose();

            //MessageFilter
            Console.WriteLine("MessageFilter");
            MessageFilter testMessageFilter = new MessageFilter();
            testClient.AttachPlugin(testMessageFilter);

            testMessageFilter.SetSystemFilterSet(testClient.GetSystemAddressFromIndex(0), 99);
            testMessageFilter.SetAllowRPC(false, "test", 99);
            testMessageFilter.SetAllowMessageID(true, 99, 99, 99);
            testMessageFilter.SetAutoAddNewConnectionsToFilter(99);
            testMessageFilter.SetFilterMaxTime(99, false, 0, 98);
            testMessageFilter.GetSystemFilterSet(testClient.GetSystemAddressFromIndex(0));
            testMessageFilter.GetSystemCount(99);
            testMessageFilter.GetSystemByIndex(99, 0);
            testMessageFilter.GetFilterSetIDByIndex(0);
            testMessageFilter.GetFilterSetCount();
            testMessageFilter.DeleteFilterSet(99);

            //NatPunchthroughClient
            Console.WriteLine("NatPunchthroughClient");
            NatPunchthroughClient testNatPunchthroughClient = new NatPunchthroughClient();
            testClient.AttachPlugin(testNatPunchthroughClient);
            testNatPunchthroughClient.GetPunchthroughConfiguration();
            testNatPunchthroughClient.GetUPNPExternalPort();
            workingRakStringCopy = testNatPunchthroughClient.GetUPNPInternalAddress();
            workingRakStringCopy.Dispose();
            testNatPunchthroughClient.GetUPNPInternalPort();
            testNatPunchthroughClient.OpenNAT(testServer.GetGuidFromSystemAddress(RakNet.RakNet.UNASSIGNED_SYSTEM_ADDRESS), testClient.GetSystemAddressFromIndex(0));
            NatPunchthroughDebugInterface_PacketLogger testNatPunchthroughDebugInterface_PacketLogger = new NatPunchthroughDebugInterface_PacketLogger();
            testNatPunchthroughClient.SetDebugInterface(testNatPunchthroughDebugInterface_PacketLogger);
            
            //NatPunchthroughDebugInterface_PacketLogger
            Console.WriteLine("NatPunchthroughDebugInterface_PacketLogger");
            testNatPunchthroughDebugInterface_PacketLogger.OnClientMessage("test");
            Console.WriteLine(testNatPunchthroughDebugInterface_PacketLogger.pl);

            //NatPunchthroughDebugInterface_Printf
            Console.WriteLine("NatPunchthroughDebugInterface_Printf");
            NatPunchthroughDebugInterface_Printf testNatPunchthroughDebugInterface_Printf = new NatPunchthroughDebugInterface_Printf();
            testNatPunchthroughClient.SetDebugInterface(testNatPunchthroughDebugInterface_Printf);
            testNatPunchthroughDebugInterface_Printf.OnClientMessage("test");
 
            //NatTypeDetectionClient
            Console.WriteLine("NatTypeDetectionClient");
            NatTypeDetectionClient testNatTypeDetectionClient = new NatTypeDetectionClient();
            testClient.AttachPlugin(testNatTypeDetectionClient);
            testNatTypeDetectionClient.DetectNATType(testClient.GetSystemAddressFromIndex(0));

            //NatTypeDetectionServer
            Console.WriteLine("NatTypeDetectionServer");
            NatTypeDetectionServer testNatTypeDetectionServer = new NatTypeDetectionServer();
            testServer.AttachPlugin(testNatTypeDetectionServer);
            testNatTypeDetectionServer.Startup("127.0.0.1","127.0.0.1","127.0.0.1");
            testNatTypeDetectionServer.Shutdown();

            //NetworkIDObject
            Console.WriteLine("NetworkIDObject");
            NetworkIDManager testNetworkIDManager = new NetworkIDManager();
            NetworkIDObject testNetworkIDObject = new TestNetworkIDObjectSubClass();
            testNetworkIDObject.SetNetworkIDManager(testNetworkIDManager);
            testNetworkIDObject.GetNetworkIDManager();
            testNetworkIDObject.GetNetworkID();

            //OnFileStruct
            Console.WriteLine("OnFileStruct");
            OnFileStruct testOnFileStruct = new OnFileStruct();
            testOnFileStruct.byteLengthOfThisFile = 99;
            testOnFileStruct.byteLengthOfThisSet = 99;
            testOnFileStruct.bytesDownloadedForThisFile = 99;
            testOnFileStruct.bytesDownloadedForThisSet = 99;
            testOnFileStruct.context = testFileListNodeContext;
            testOnFileStruct.fileIndex = 99;
            testOnFileStruct.fileName = "99";
            testOnFileStruct.numberOfFilesInThisSet = 99;
            testOnFileStruct.setID = 99;
            testOnFileStruct.fileData = testBuffer;
            Console.WriteLine(testOnFileStruct.fileData[0]);

            //OutOfBandIdentifiers
            Console.WriteLine("OutOfBandIdentifiers");
            OutOfBandIdentifiers testOutOfBandIdentifiers = new OutOfBandIdentifiers();

            //Packet
            Console.WriteLine("Packet");

            //PacketConsoleLogger
            Console.WriteLine("PacketConsoleLogger");
            PacketConsoleLogger testPacketConsoleLogger = new PacketConsoleLogger();

            testClient.AttachPlugin(testPacketConsoleLogger);

            LogCommandParser testLogCommandParser = new LogCommandParser();

            testPacketConsoleLogger.SetLogCommandParser(testLogCommandParser);

            //LogCommandParser
            Console.WriteLine("LogCommandParser");

            //PacketFileLogger
            Console.WriteLine("PacketFileLogger");
            PacketFileLogger testPacketFileLogger = new PacketFileLogger();
            string bigString = new string('c', 9999);

            testPacketFileLogger.StartLog("TestLog");
            testClient.AttachPlugin(testPacketFileLogger);
            testPacketFileLogger.FormatLine(ref bigString, "./", "none", 9, 9, 99, 99, 99, testClient.GetSystemAddressFromIndex(0), testClient.GetSystemAddressFromIndex(0), 99, 99, 99, 99);
            testPacketFileLogger.LogHeader();
            testPacketFileLogger.SetLogDirectMessages(false);
            testPacketFileLogger.SetPrefix("lv");
            testPacketFileLogger.SetPrintAcks(false);
            testPacketFileLogger.SetPrintID(false);
            testPacketFileLogger.SetSuffix("tr");
            testPacketFileLogger.WriteLog("gr");
            testPacketFileLogger.WriteMiscellaneous("lf", "mr");

            testClient.DetachPlugin(testPacketFileLogger);
            testPacketFileLogger.Dispose();

            foreach (string file in Directory.GetFiles("./", "TestLog*.csv"))
            {
                File.Delete(file);
            }
             
            //PluginInterface2
            Console.WriteLine("PluginInterface2");
            PluginInterface2 testPluginInterface2 = new PluginInterface2();

            //PluginReceiveResult
            Console.WriteLine("PluginReceiveResult");
            PluginReceiveResult testPluginReceiveResult = new PluginReceiveResult();

            //PunchthroughConfiguration
            Console.WriteLine("PunchthroughConfiguration");
            PunchthroughConfiguration testPunchthroughConfiguration = new PunchthroughConfiguration();

            //Raknet
            RakNet.RakNet.NonNumericHostString("12");

            //RakNetBPlusTreeRow
            Console.WriteLine("RakNetBPlusTreeRow");
            RakNetBPlusTreeRow testRakNetBPlusTreeRow = new RakNetBPlusTreeRow();

            //RakNetGUID
            Console.WriteLine("RakNetGUID");
            Console.WriteLine(testRakNetGUID.g);
            Console.WriteLine(testRakNetGUID.systemIndex);
            Console.WriteLine(testRakNetGUID == RakNet.RakNet.UNASSIGNED_RAKNET_GUID);
            Console.WriteLine(testRakNetGUID > RakNet.RakNet.UNASSIGNED_RAKNET_GUID);
            Console.WriteLine(testRakNetGUID < RakNet.RakNet.UNASSIGNED_RAKNET_GUID);

            //RakNetList, only one is needed
            //RakNetListSystemAddress
            Console.WriteLine("RakNetListSystemAddress");
            RakNetListSystemAddress testRakNetListSystemAddress = new RakNetListSystemAddress();
            testRakNetListSystemAddress.Insert(RakNet.RakNet.UNASSIGNED_SYSTEM_ADDRESS,"",0);
            testRakNetListSystemAddress.Preallocate(99, "", 0);
            testRakNetListSystemAddress.Push(RakNet.RakNet.UNASSIGNED_SYSTEM_ADDRESS,"",0);
            testRakNetListSystemAddress.RemoveAtIndex(0);
            testRakNetListSystemAddress.RemoveAtIndexFast(0);
            testRakNetListSystemAddress.Insert(RakNet.RakNet.UNASSIGNED_SYSTEM_ADDRESS, "", 0);
            testRakNetListSystemAddress.Push(RakNet.RakNet.UNASSIGNED_SYSTEM_ADDRESS, "", 0);
            testRakNetListSystemAddress.RemoveFromEnd();
            testRakNetListSystemAddress.Replace(RakNet.RakNet.UNASSIGNED_SYSTEM_ADDRESS);
            testRakNetListSystemAddress.Size();
            testRakNetListSystemAddress.Pop();
            testRakNetListSystemAddress.Compress("", 0);
            testRakNetListSystemAddress.CopyData(testRakNetListSystemAddress);
            testRakNetListSystemAddress.Clear(false, "", 0);
            testRakNetListSystemAddress.Insert(RakNet.RakNet.UNASSIGNED_SYSTEM_ADDRESS, "", 0);
            testRakNetListSystemAddress.Push(RakNet.RakNet.UNASSIGNED_SYSTEM_ADDRESS, "", 0);
            testRakNetListSystemAddress.Get(0);
            testRakNetListSystemAddress.GetIndexOf(RakNet.RakNet.UNASSIGNED_SYSTEM_ADDRESS);

            //RakNetPageRow
            Console.WriteLine("RakNetPageRow");
            RakNetPageRow testRakNetPageRow = new RakNetPageRow();
            testRakNetPageRow.isLeaf = false;
            testRakNetPageRow.next = testRakNetPageRow;
            testRakNetPageRow.previous = testRakNetPageRow;
            testRakNetPageRow.size = 9;

            Console.WriteLine(testRakNetPageRow.isLeaf);
            Console.WriteLine(testRakNetPageRow.next);
            Console.WriteLine(testRakNetPageRow.previous);
            Console.WriteLine(testRakNetPageRow.size);

            //RakNetSocket
            Console.WriteLine("RakNetSocket");
            RakNetSocket testRakNetSocket = new RakNetSocket();
            testRakNetSocket.boundAddress = RakNet.RakNet.UNASSIGNED_SYSTEM_ADDRESS;
            testRakNetSocket.remotePortRakNetWasStartedOn_PS3 = 0;
            testRakNetSocket.s = 99;
            testRakNetSocket.userConnectionSocketIndex = 0;

            Console.WriteLine(testRakNetSocket.boundAddress);
            Console.WriteLine(testRakNetSocket.remotePortRakNetWasStartedOn_PS3);
            Console.WriteLine(testRakNetSocket.s);
            Console.WriteLine(testRakNetSocket.userConnectionSocketIndex);

            //ReadyEvent
            Console.WriteLine("ReadyEvent");
            ReadyEvent testReadyEvent = new ReadyEvent();
            testClient.AttachPlugin(testReadyEvent);
            testReadyEvent.AddToWaitList(99, RakNet.RakNet.UNASSIGNED_SYSTEM_ADDRESS);
            testReadyEvent.GetEventAtIndex(0);
            testReadyEvent.GetEventListSize();
            testReadyEvent.GetFromWaitListAtIndex(99, 0);
            testReadyEvent.GetReadyStatus(99, RakNet.RakNet.UNASSIGNED_SYSTEM_ADDRESS);
            testReadyEvent.GetRemoteWaitListSize(99);
            testReadyEvent.HasEvent(99);
            testReadyEvent.IsEventCompleted(99);
            testReadyEvent.IsEventCompletionProcessing(99);
            testReadyEvent.IsEventSet(99);
            testReadyEvent.IsInWaitList(99, RakNet.RakNet.UNASSIGNED_SYSTEM_ADDRESS);
            testReadyEvent.SetEvent(99, false);
            testReadyEvent.SetSendChannel(9);
            testReadyEvent.RemoveFromWaitList(99, RakNet.RakNet.UNASSIGNED_SYSTEM_ADDRESS);
            testReadyEvent.ForceCompletion(99);
            testReadyEvent.DeleteEvent(99);

            //RemoteSystemIndex
            Console.WriteLine("RemoteSystemIndex");
            RemoteSystemIndex testRemoteSystemIndex = new RemoteSystemIndex();
            testRemoteSystemIndex.index = 5;
            testRemoteSystemIndex.next = testRemoteSystemIndex;

            Console.WriteLine(testRemoteSystemIndex.index);
            Console.WriteLine(testRemoteSystemIndex.next);

            //Router2
            Console.WriteLine("Router2");
            Router2 testRouter2 = new Router2();
            testClient.AttachPlugin(testRouter2);
            testRouter2.EstablishRouting(testClient.GetGUIDFromIndex(0));
            testRouter2.GetConnectionRequestIndex(testClient.GetGUIDFromIndex(0));
            testRouter2.SetMaximumForwardingRequests(99);
         

            //SimpleMutex
            Console.WriteLine("SimpleMutex");
            SimpleMutex testSimpleMutex = new SimpleMutex();
            testSimpleMutex.Lock();
            testSimpleMutex.Unlock();

            //SocketDescriptor
            Console.WriteLine("SocketDescriptor");
            SocketDescriptor testSocketDescriptor = new SocketDescriptor();
            testSocketDescriptor.hostAddress = "127.0.0.1";
            testSocketDescriptor.port = 60002;
            testSocketDescriptor.remotePortRakNetWasStartedOn_PS3 = 0;

            Console.WriteLine(testSocketDescriptor.hostAddress);
            Console.WriteLine(testSocketDescriptor.port);
            Console.WriteLine(testSocketDescriptor.remotePortRakNetWasStartedOn_PS3);

            //TeamBalancer
            Console.WriteLine("TeamBalancer");
            TeamBalancer testTeamBalancer = new TeamBalancer();
            testClient.AttachPlugin(testTeamBalancer);
            testTeamBalancer.SetAllowHostMigration(false);
            testTeamBalancer.SetDefaultAssignmentAlgorithm(TeamBalancer.DefaultAssigmentAlgorithm.FILL_IN_ORDER);
            testTeamBalancer.SetHostGuid(testClient.GetGUIDFromIndex(0));
            testTeamBalancer.SetLockTeams(false);
            RakNetListUnsignedShort ushortList = new RakNetListUnsignedShort();
            ushortList.Push(5, "", 0);
            testTeamBalancer.SetTeamSizeLimits(ushortList);
            testTeamBalancer.SetForceEvenTeams(true);
            testTeamBalancer.CancelRequestSpecificTeam();
            testTeamBalancer.GetMyTeam();
            testTeamBalancer.RequestAnyTeam(); 
            testTeamBalancer.RequestSpecificTeam(0);
            
            //ThreadsafePacketLogger
            Console.WriteLine("ThreadsafePacketLogger");
            ThreadsafePacketLogger testThreadsafePacketLogger = new ThreadsafePacketLogger();
            testClient.AttachPlugin(testThreadsafePacketLogger);
            testThreadsafePacketLogger.FormatLine(ref bigString,"./","none",9,9,99,99,99,testClient.GetSystemAddressFromIndex(0),testClient.GetSystemAddressFromIndex(0),99,99,99,99);
            testThreadsafePacketLogger.LogHeader();
            testThreadsafePacketLogger.SetLogDirectMessages(false);
            testThreadsafePacketLogger.SetPrefix("lv");
            testThreadsafePacketLogger.SetPrintAcks(false);
            testThreadsafePacketLogger.SetPrintID(false);
            testThreadsafePacketLogger.SetSuffix("tr");
            testThreadsafePacketLogger.WriteLog("gr");
            testThreadsafePacketLogger.WriteMiscellaneous("lf","mr");

            //UDPForwarder
            Console.WriteLine("UDPForwarder");
            UDPForwarder testUDPForwarder = new UDPForwarder();
            testUDPForwarder.Startup();
            testUDPForwarder.GetMaxForwardEntries();
            testUDPForwarder.GetUsedForwardEntries();
            testUDPForwarder.SetMaxForwardEntries(99);
            ushort outUshort;
            testUDPForwarder.StartForwarding(testClient.GetSystemAddressFromIndex(0), testServer.GetSystemAddressFromIndex(0), 99, "127.0.0.1", out outUshort, out outUint);
            testUDPForwarder.StopForwarding(testClient.GetSystemAddressFromIndex(0),testServer.GetSystemAddressFromIndex(0));
            Thread.Sleep(2000);
            testUDPForwarder.StartForwardingThreaded(testClient.GetSystemAddressFromIndex(0), testServer.GetSystemAddressFromIndex(0), 99, "127.0.0.1", out outUshort, out outUint);
            testUDPForwarder.StopForwardingThreaded(testClient.GetSystemAddressFromIndex(0), testServer.GetSystemAddressFromIndex(0));
            Thread.Sleep(1000);
            //testUDPForwarder.threadOperationIncomingMutex=new SimpleMutex();
           // testUDPForwarder.threadOperationOutgoingMutex=new SimpleMutex();
            testUDPForwarder.threadRunning=false;
            testUDPForwarder.isRunning=false;
            testUDPForwarder.maxForwardEntries = 99;

            Console.WriteLine(testUDPForwarder.threadOperationIncomingMutex);
            Console.WriteLine(testUDPForwarder.threadOperationOutgoingMutex);
            Console.WriteLine(testUDPForwarder.threadRunning);
            Console.WriteLine(testUDPForwarder.isRunning);
            Console.WriteLine(testUDPForwarder.maxForwardEntries);

            testUDPForwarder.Shutdown();

            //UDPProxyClient
            Console.WriteLine("UDPProxyClient");
            UDPProxyClient testUDPProxyClient = new UDPProxyClient();
            UDPProxyClientResultHandler testUDPProxyClientResultHandler= new UDPProxyClientResultHandlerCB();

            testUDPProxyClient.SetResultHandler(testUDPProxyClientResultHandler);
            testClient.AttachPlugin(testUDPProxyClient);
            testUDPProxyClient.RequestForwarding(testClient.GetSystemAddressFromIndex(0), testServer.GetSystemAddressFromIndex(0),testClient.GetGUIDFromIndex(0),1);
 
            //UDPProxyCoordinator
            Console.WriteLine("UDPProxyCoordinator");
            UDPProxyCoordinator testUDPProxyCoordinator = new UDPProxyCoordinator();
            testClient.AttachPlugin(testUDPProxyCoordinator);
            testUDPProxyCoordinator.SetRemoteLoginPassword(rakStringTest);
           
            //UDPProxyServer
            Console.WriteLine("UDPProxyServer");
            UDPProxyServer testUDPProxyServer = new UDPProxyServer();
            UDPProxyServerResultHandler testUDPProxyServerResultHandler= new UDPProxyServerResultHandlerCB();
            testServer.AttachPlugin(testUDPProxyServer);
            testUDPProxyServer.SetResultHandler(testUDPProxyServerResultHandler);
            testUDPProxyServer.LoginToCoordinator(rakStringTest,testServer.GetSystemAddressFromIndex(0));
            testUDPProxyServer.udpForwarder = testUDPProxyServer.udpForwarder;
            Console.WriteLine(testUDPProxyServer.udpForwarder);

            //RakString
            Console.WriteLine("RakString");
            testRakString.AppendBytes(testBuffer, (uint)testBuffer.Length);
            Console.WriteLine(testRakString.C_String());
            Console.WriteLine(testRakString.C_StringUnsafe());
            testRakString.Clear();
            Console.WriteLine(testRakString.ContainsNonprintableExceptSpaces());
            workingRakStringCopy = testRakString.Assign("MayJuneJuly", 0, 3);
            workingRakStringCopy.Dispose();
            Console.WriteLine(testRakString);
            testRakString.CopyData(testRakString);
            testRakString.Serialize(testBitStream2);
            testRakString.Deserialize(testBitStream2);
            testRakString.SerializeCompressed(testBitStream2);
            testRakString.DeserializeCompressed(testBitStream2);
            workingRakStringCopy = testRakString.Assign("MayJuneJuly", 0, 3);
            workingRakStringCopy.Dispose();

            testRakString.Erase(0, 1);

            Console.WriteLine(testRakString.Find("y", 0));
            Console.WriteLine(testRakString.GetLength());
            Console.WriteLine(testRakString.IPAddressMatch("127.0.0.1"));
            Console.WriteLine(testRakString.IsEmailAddress());
            Console.WriteLine(testRakString.IsEmpty());
            Console.WriteLine(testRakString.MakeFilePath());
            testRakString.Printf();
            testRakString.RemoveCharacter('a');
            testRakString.Replace(0, 1, 'c');
            testRakString.Set("cat");
            testRakString.SetChar(0, 'r');
            testRakString.SQLEscape();
            Console.WriteLine(testRakString.StrCmp(testRakString));
            Console.WriteLine(testRakString.StrICmp(testRakString));
            workingRakStringCopy = testRakString.SubStr(0, 2);
            Console.WriteLine(workingRakStringCopy);
            workingRakStringCopy.Dispose();
            Console.WriteLine(testRakString);
            testRakString.TerminateAtFirstCharacter('y');
            testRakString.TerminateAtLastCharacter('y');
            Console.WriteLine(testRakString.ToLower());
            Console.WriteLine(testRakString.ToUpper());
            testRakString.Truncate(2);
            testRakString.URLDecode();
            testRakString.URLEncode();

            //PluginInterface2
            testUDPProxyServer.GetRakPeerInterface();

            //RakPeerInterface
            testPacket = testClient.AllocatePacket(5);
            testClient.AddToBanList("127.0.0.1", 10);
            testClient.AddToSecurityExceptionList("127.0.0.1");
            testBuffer = testPacket.data;
            testClient.AdvertiseSystem("127.0.0.1",60002,testBuffer,testBuffer.Length);
            testClient.AllowConnectionResponseIPMigration(false);
            testClient.CancelConnectionAttempt(testClient.GetSystemAddressFromIndex(0));
            testClient.ChangeSystemAddress(testClient.GetGUIDFromIndex(0),testClient.GetSystemAddressFromIndex(0));
            testClient.ClearBanList();
            uint[] testFrequencyTable = new uint[256];
            testClient.DisableSecurity();
            testClient.GetAveragePing(new AddressOrGUID(RakNet.RakNet.UNASSIGNED_SYSTEM_ADDRESS));
            SystemAddress[] remoteSystems;
            ushort numberOfSystems=4;
            testClient.GetConnectionList(out remoteSystems,ref numberOfSystems);
            testClient.GetExternalID(RakNet.RakNet.UNASSIGNED_SYSTEM_ADDRESS);
            testClient.GetGUIDFromIndex(0);
            testClient.GetGuidFromSystemAddress(RakNet.RakNet.UNASSIGNED_SYSTEM_ADDRESS);
            int inOutInt=testBuffer.Length;
            testClient.GetIncomingPassword(testBuffer,ref inOutInt);
            testClient.GetIndexFromSystemAddress(testClient.GetSystemAddressFromIndex(0));
            testClient.GetInternalID();
            testClient.GetLastPing(new AddressOrGUID(RakNet.RakNet.UNASSIGNED_SYSTEM_ADDRESS));
            testClient.GetLocalIP(0);
            testClient.GetLowestPing(new AddressOrGUID(RakNet.RakNet.UNASSIGNED_SYSTEM_ADDRESS));
            testClient.GetMaximumIncomingConnections();
            testClient.GetMaximumNumberOfPeers();
            testClient.GetMTUSize(RakNet.RakNet.UNASSIGNED_SYSTEM_ADDRESS);
            testClient.GetNextSendReceipt();
            testClient.GetNumberOfAddresses();
            testClient.SetOfflinePingResponse(testBuffer, (uint)testBuffer.Length);
            testClient.GetOfflinePingResponse(testBuffer,out outUint);
            testClient.GetReceiveBufferSize();
            testClient.GetSplitMessageProgressInterval();
            testClient.GetStatistics(RakNet.RakNet.UNASSIGNED_SYSTEM_ADDRESS);
            testClient.GetSystemAddressFromGuid(testClient.GetGUIDFromIndex(0));
            testClient.GetSystemAddressFromIndex(0);
            RakNetListSystemAddress systemAddressList= new RakNetListSystemAddress();
            RakNetListRakNetGUID guidList= new RakNetListRakNetGUID();
            testClient.GetSystemList(systemAddressList,guidList);
            testClient.GetTimeoutTime(RakNet.RakNet.UNASSIGNED_SYSTEM_ADDRESS);
            testClient.IncrementNextSendReceipt();
            testClient.InitializeSecurity("dsf","sdaf");
            testClient.IsActive();
            testClient.IsBanned("127.0.0.1");
            testClient.GetConnectionState(new AddressOrGUID(testClient.GetSystemAddressFromIndex(0)));
            testClient.IsInSecurityExceptionList("127.0.0.1");
            testClient.IsLocalIP("127.0.0.1");
            testClient.NumberOfConnections();
            testClient.Ping(testClient.GetSystemAddressFromIndex(0));
            testClient.PushBackPacket(testPacket,true);
            testClient.RemoveFromBanList("127.0.0.1");
            testClient.RemoveFromSecurityExceptionList("127.0.0.1");
            testClient.SendLoopback(testBuffer,testBuffer.Length);
            testClient.SendTTL("127.0.0.1",60002,5);
            testClient.SetIncomingPassword(testBuffer,testBuffer.Length);
            testClient.SetLimitIPConnectionFrequency(true);
            testClient.SetMaximumIncomingConnections(99);
            testClient.SetOccasionalPing(true);
            testClient.SetPerConnectionOutgoingBandwidthLimit(10);
            testClient.SetSplitMessageProgressInterval(99);
            testClient.SetTimeoutTime(99,RakNet.RakNet.UNASSIGNED_SYSTEM_ADDRESS);
            testClient.SetUnreliableTimeout(99);
            testClient.WriteOutOfBandHeader(testBitStream1);
            testClient.CloseConnection(testClient.GetSystemAddressFromIndex(0),false);
            testClient.Shutdown(20);

            RakPeer.DestroyInstance(testClient);
            RakPeer.DestroyInstance(testServer);

            //These need to be freed if used in the main function.
            testUDPForwarder.Dispose();
            testUDPProxyCoordinator.Dispose();
            FileList.DestroyInstance(testFileList);
            FileList.DestroyInstance(outFileList);
            FullyConnectedMesh2.DestroyInstance(testFullyConnectedMesh2);
            //If RakString is not freed before program exit it will crash
            rakStringTest.Dispose();
            testRakString.Dispose();
            workingRakStringCopy.Dispose();
            RakString.FreeMemory();

            Console.WriteLine("Demo complete. Press enter.");
            Console.Read();
        }
Example #25
0
        static void Main(string[] args)
        {
            Packet testPacket;
            int loopNumber;
            BitStream stringTestSendBitStream = new BitStream();
            BitStream rakStringTestSendBitStream = new BitStream();
            BitStream receiveBitStream = new BitStream();
            String holdingString;
            TimeSpan startTimeSpan;
            RakString rakStringTest = new RakString();

            RakPeerInterface testClient = RakPeer.GetInstance();

            testClient.Startup(1, new SocketDescriptor(60000, "127.0.0.1"), 1);

            RakPeerInterface testServer = RakPeer.GetInstance();
            testServer.Startup(1, new SocketDescriptor(60001, "127.0.0.1"), 1);
            testServer.SetMaximumIncomingConnections(1);

            Console.WriteLine("Press enter to start RakString send and receive loop using BitStream.\nBitStream read done into RakString");
            Console.WriteLine("Loop will run for 15 seconds");
            Console.ReadLine();

            testClient.Connect("127.0.0.1", 60001, "", 0);

            String sendString = "The test string";
            stringTestSendBitStream.Write((byte)DefaultMessageIDTypes.ID_USER_PACKET_ENUM);
            stringTestSendBitStream.Write(sendString);

            RakString testRakString = new RakString("Test RakString");
            rakStringTestSendBitStream.Write((byte)DefaultMessageIDTypes.ID_USER_PACKET_ENUM);
            rakStringTestSendBitStream.Write(testRakString);

            startTimeSpan = (DateTime.UtcNow - new DateTime(1970, 1, 1));
            loopNumber = 0;

            while (startTimeSpan.TotalSeconds + 15 > (DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds)
            {
                testPacket = testServer.Receive();
                if (testPacket != null && testPacket.data[0] == (byte)DefaultMessageIDTypes.ID_USER_PACKET_ENUM)
                {
                    receiveBitStream.Reset();
                    receiveBitStream.Write(testPacket.data, testPacket.length);
                    receiveBitStream.IgnoreBytes(1);
                    receiveBitStream.Read(rakStringTest);
                    Console.WriteLine("Loop number: " + loopNumber + "\nData: " + rakStringTest.C_String());
                }
                testServer.DeallocatePacket(testPacket);
                loopNumber++;
                System.Threading.Thread.Sleep(50);
                testClient.Send(rakStringTestSendBitStream, PacketPriority.LOW_PRIORITY, PacketReliability.RELIABLE_ORDERED, (char)0, new AddressOrGUID(new SystemAddress("127.0.0.1", 60001)), false);
            }

            Console.WriteLine("Press enter to start String send and receive loop using BitStream.\nBitStream read done into String");
            Console.WriteLine("Loop will run for 15 seconds");
            Console.ReadLine();

            startTimeSpan = (DateTime.UtcNow - new DateTime(1970, 1, 1));
            loopNumber = 0;
            while (startTimeSpan.TotalSeconds + 15 > (DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds)
            {
                testPacket = testServer.Receive();
                if (testPacket != null && testPacket.data[0] == (byte)DefaultMessageIDTypes.ID_USER_PACKET_ENUM)
                {
                    receiveBitStream.Reset();
                    receiveBitStream.Write(testPacket.data, testPacket.length);
                    receiveBitStream.IgnoreBytes(1);
                    receiveBitStream.Read(out holdingString);
                    Console.WriteLine("Loop number: " + loopNumber + "\nData: " + holdingString);
                }
                testServer.DeallocatePacket(testPacket);
                loopNumber++;
                System.Threading.Thread.Sleep(50);
                testClient.Send(stringTestSendBitStream, PacketPriority.LOW_PRIORITY, PacketReliability.RELIABLE_ORDERED, (char)0, new AddressOrGUID(new SystemAddress("127.0.0.1", 60001)), false);
            }
            //If RakString is not freed before program exit it will crash
            rakStringTest.Dispose();
            testRakString.Dispose();

            RakPeer.DestroyInstance(testClient);
            RakPeer.DestroyInstance(testServer);
            Console.WriteLine("Demo complete. Press Enter.");
            Console.Read();
        }
Example #26
0
        public void Read(RakNet.BitStream stream, RakNet.Packet packet, Server server)
        {
            int  vobID = 0, playerID = 0;
            byte mobInterTypeInt = 0;
            char mobInterKey     = '0';

            stream.Read(out mobInterTypeInt);
            stream.Read(out playerID);
            stream.Read(out vobID);

            MobInterNetwork mobInterFlags = (MobInterNetwork)mobInterTypeInt;

            if (mobInterFlags.HasFlag(MobInterNetwork.PickLock))
            {
                stream.Read(out mobInterKey);
            }


            if (playerID == 0 || !sWorld.VobDict.ContainsKey(playerID))
            {
                throw new Exception("Player not found!");
            }
            Vob plVob = sWorld.VobDict[playerID];

            if (!(plVob is NPCProto))
            {
                throw new Exception("PlayerVob was not from type Player: " + plVob);
            }
            NPCProto player = (NPCProto)plVob;

            if (vobID == 0 || !sWorld.VobDict.ContainsKey(vobID))
            {
                throw new Exception("Vob not found!");
            }
            Vob vob = sWorld.VobDict[vobID];

            if (!(vob is MobInter))
            {
                throw new Exception("Vob was not from type MobInter: " + vob);
            }

            stream.ResetReadPointer();
            Program.server.ServerInterface.Send(stream, PacketPriority.HIGH_PRIORITY, PacketReliability.RELIABLE_ORDERED, (char)0, packet.guid, true);


            MobInter mob = (MobInter)vob;

            if (mobInterFlags == MobInterNetwork.PickLock)
            {
                if (!(vob is MobLockable))
                {
                    throw new Exception("Vob was not from type MobLockable: " + vob);
                }
                MobLockable mobLock = (MobLockable)mob;
                Scripting.Objects.Mob.MobLockable.OnContainerPickLock((Scripting.Objects.Mob.MobLockable)mobLock.ScriptingVob, player.ScriptingNPC, mobInterKey);
            }
            else if (mobInterFlags == MobInterNetwork.OnTrigger)
            {
                mob.State = 1;
                Scripting.Objects.Mob.MobInter.isOnTrigger((Scripting.Objects.Mob.MobInter)mob.ScriptingVob, player.ScriptingNPC);
            }
            else if (mobInterFlags == MobInterNetwork.OnUnTrigger)
            {
                mob.State = 0;
                Scripting.Objects.Mob.MobInter.isOnUnTrigger((Scripting.Objects.Mob.MobInter)mob.ScriptingVob, player.ScriptingNPC);
            }
            else if (mobInterFlags == MobInterNetwork.StartInteraction)
            {
                Scripting.Objects.Mob.MobInter.isOnStartInteraction((Scripting.Objects.Mob.MobInter)mob.ScriptingVob, player.ScriptingNPC);
            }
            else if (mobInterFlags == MobInterNetwork.StopInteraction)
            {
                Scripting.Objects.Mob.MobInter.isOnStopInteraction((Scripting.Objects.Mob.MobInter)mob.ScriptingVob, player.ScriptingNPC);
            }
        }
        public void Read(RakNet.BitStream stream, RakNet.Packet packet, Server server)
        {
            int  playerID = 0, itemID = 0;
            bool equip = false;

            stream.Read(out playerID);
            stream.Read(out itemID);
            stream.Read(out equip);

            if (!sWorld.VobDict.ContainsKey(playerID))
            {
                throw new Exception("Player-ID was not found: " + playerID + " Equipped: " + equip);
            }
            if (!sWorld.VobDict.ContainsKey(itemID))
            {
                throw new Exception("Item-ID was not found: " + itemID + " Equipped: " + equip + " playerID: " + playerID);
            }


            NPCProto player = (NPCProto)sWorld.VobDict[playerID];
            Item     item   = (Item)sWorld.VobDict[itemID];

            if (equip)
            {
                if (item.ItemInstance.MainFlags.HasFlag(MainFlags.ITEM_KAT_ARMOR))
                {
                    player.Armor = item;
                }
                else if (item.ItemInstance.MainFlags.HasFlag(MainFlags.ITEM_KAT_NF))
                {
                    player.Weapon = item;
                }
                else if (item.ItemInstance.MainFlags.HasFlag(MainFlags.ITEM_KAT_FF))
                {
                    player.RangeWeapon = item;
                }

                player.EquippedList.Add(item);
                Scripting.Objects.Character.NPCProto.isOnEquip(player.ScriptingNPC, item.ScriptingProto);
            }
            else
            {
                if (item.ItemInstance.MainFlags.HasFlag(MainFlags.ITEM_KAT_ARMOR))
                {
                    player.Armor = null;
                }
                else if (item.ItemInstance.MainFlags.HasFlag(MainFlags.ITEM_KAT_NF))
                {
                    player.Weapon = null;
                }
                else if (item.ItemInstance.MainFlags.HasFlag(MainFlags.ITEM_KAT_FF))
                {
                    player.RangeWeapon = null;
                }

                player.EquippedList.Remove(item);
                Scripting.Objects.Character.NPCProto.isOnUnEquip(player.ScriptingNPC, item.ScriptingProto);
            }


            stream.ResetReadPointer();
            Program.server.ServerInterface.Send(stream, PacketPriority.HIGH_PRIORITY, PacketReliability.RELIABLE_ORDERED, (char)0, packet.guid, true);
        }
        public void Read(RakNet.BitStream stream, RakNet.Packet packet, Server server)
        {
            int playerID = 0, cF = 0;

            stream.Read(out playerID);
            stream.Read(out cF);

            NPCProto proto = (NPCProto)sWorld.VobDict[playerID];

            NPCChangedFlags changeFlags = (NPCChangedFlags)cF;

            //Equipment:
            if (changeFlags.HasFlag(NPCChangedFlags.EQUIP_ARMOR))
            {
                proto.Armor = UpdateItem(stream);
            }

            if (changeFlags.HasFlag(NPCChangedFlags.EQUIP_NW))
            {
                proto.Weapon = UpdateItem(stream);
            }

            if (changeFlags.HasFlag(NPCChangedFlags.EQUIP_RW))
            {
                proto.RangeWeapon = UpdateItem(stream);
            }

            if (changeFlags.HasFlag(NPCChangedFlags.WeaponMode))
            {
                int weaponMode = 0;
                stream.Read(out weaponMode);
                proto.WeaponMode = weaponMode;
            }

            for (int i = 0; i < 9; i++)
            {
                if (changeFlags.HasFlag((NPCChangedFlags)((int)NPCChangedFlags.SLOT1 << i)))
                {
                    int slotItemID = 0;
                    stream.Read(out slotItemID);

                    if (slotItemID > 0)
                    {
                        Item slotItem = (Item)sWorld.VobDict[slotItemID];
                        //Item oldSlotItem = proto.Slots[i];

                        proto.Slots[i] = slotItem;
                    }
                    else
                    {
                        proto.Slots[i] = null;
                    }
                }
            }

            if (changeFlags.HasFlag(NPCChangedFlags.VOBFOCUS))
            {
                proto.FocusVob = UpdateVob(stream);
            }

            if (changeFlags.HasFlag(NPCChangedFlags.ENEMYFOCUS))
            {
                proto.Enemy = (NPCProto)UpdateVob(stream);
            }

            if (changeFlags.HasFlag(NPCChangedFlags.MOBINTERACT))
            {
                proto.MobInter = (MobInter)UpdateVob(stream);
            }

            if (changeFlags.HasFlag(NPCChangedFlags.ISDEAD))
            {
                proto.IsDead = UpdateState(stream);
            }

            if (changeFlags.HasFlag(NPCChangedFlags.ISUNCONSCIOUS))
            {
                proto.IsUnconcious = UpdateState(stream);
            }

            if (changeFlags.HasFlag(NPCChangedFlags.ISSWIMMING))
            {
                proto.IsSwimming = UpdateState(stream);
            }

            if (changeFlags.HasFlag(NPCChangedFlags.PORTALROOM))
            {
                String portalRoom = "";
                stream.Read(out portalRoom);
                proto.PortalRoom = portalRoom;
            }

            if (changeFlags.HasFlag(NPCChangedFlags.ACTIVE_SPELL))
            {
                int vobID = 0;
                stream.Read(out vobID);

                if (vobID == 0)
                {
                    proto.ActiveSpell = null;
                }
                else
                {
                    proto.ActiveSpell = (Item)sWorld.VobDict[vobID];
                }
            }

            //Sending back:
            stream.ResetReadPointer();

            Program.server.ServerInterface.Send(stream, PacketPriority.MEDIUM_PRIORITY, PacketReliability.RELIABLE_ORDERED, (char)0, packet.guid, true);
        }