Exemplo n.º 1
0
        private void HandleGetWorld(NetworkMessage msg)
        {
            MsgGetWorld wldChunk = msg as MsgGetWorld;

            if (Unpacker == null)
            {
                Unpacker = new WorldUnpacker();
            }

            Unpacker.AddData(wldChunk.Data);

            if (wldChunk.Offset > 0)
            {
                if (WorldDownloadProgress != null)
                {
                    WorldDownloadProgress.Invoke(this, new WorldDownloadProgressEventArgs((float)Unpacker.Size() / (float)(((UInt32)wldChunk.Offset + Unpacker.Size()))));
                }
                NetClient.SendMessage(new MsgGetWorld((UInt32)Unpacker.Size()));
            }
            else
            {
                if (WorldDownloadProgress != null)
                {
                    WorldDownloadProgress.Invoke(this, new WorldDownloadProgressEventArgs(1));
                }

                SetMap(Unpacker.Unpack());
                if (WorldCache != null)
                {
                    WorldCache.SaveMapToCache(WorldHash, Unpacker.GetBuffer());
                }
                SendEnter();
            }
        }
Exemplo n.º 2
0
        private void HandleGetWorld(ServerPlayer player, NetworkMessage msg)
        {
            MsgGetWorld getW = msg as MsgGetWorld;

            if (getW == null)
            {
                return;
            }

            Logger.Log4("Getting world chunk for " + player.PlayerID.ToString() + " at offset " + getW.Offset);

            UInt32 len   = (UInt32)World.GetWorldData().Length;
            UInt32 start = getW.Offset;

            if (start >= len)
            {
                start = len - 1;
            }

            UInt32 end = start + 1024;

            if (end > len)
            {
                end = len;
            }

            UInt32 realLen = end - start;

            getW.Data   = new byte[realLen];
            getW.Offset = len - end;
            Array.Copy(World.GetWorldData(), start, getW.Data, 0, getW.Data.Length);

            player.SendMessage(getW);
        }
Exemplo n.º 3
0
        private static void HandleGetWorld(NetworkMessage msg)
        {
            MsgGetWorld wldChunk = msg as MsgGetWorld;

            WriteLine("World Data Received, " + (wldChunk.Offset / 1024.0).ToString() + "Kb is left");

            Unpacker.AddData(wldChunk.Data);

            if (wldChunk.Offset > 0)
            {
                client.SendMessage(new MsgGetWorld((UInt32)Unpacker.Size()));
            }
            else
            {
                WriteLine("World Data Received, size " + (Unpacker.Size() / 1024.0).ToString() + "Kb, unpacking");
                Map = Unpacker.Unpack();

                WriteLine("World Data unpacked, " + Map.Objects.Count.ToString() + " objects");

                SendEnter();
            }
        }