コード例 #1
0
 public bool NetworkPacketReceived(PacketServer packet)
 {
     switch (packet.PacketId)
     {
         case ServerPacketId.FiniteInventory:
             {
                 FiniteInventory = packet.FiniteInventory.BlockTypeAmount;
                 ENABLE_FINITEINVENTORY = packet.FiniteInventory.IsFinite;
                 FiniteInventoryMax = packet.FiniteInventory.Max;
             }
             return true;
         case ServerPacketId.Season:
             {
                 CurrentSeason = packet.Season.Season;
                 if (CurrentSeason == 0 || CurrentSeason == 3)
                 {
                     terrain.UpdateAllTiles();
                 }
             }
             return true;
         default:
             return false;
     }
 }
コード例 #2
0
        public bool NetworkPacketReceived(PacketServer packet)
        {
            switch (packet.PacketId)
            {
                case ServerPacketId.FiniteInventory:
                    {
                        //check for null so it's possible to connect
                        //to old versions of game (before 2011-05-05)
                        if (packet.Inventory.Inventory != null)
                        {
                            d_Inventory.CopyFrom(packet.Inventory.Inventory);
                        }
                        /*
                        FiniteInventory = packet.FiniteInventory.BlockTypeAmount;
                        ENABLE_FINITEINVENTORY = packet.FiniteInventory.IsFinite;
                        FiniteInventoryMax = packet.FiniteInventory.Max;
                        */
                    }
                    return true;
                case ServerPacketId.Season:
                    {
                        if (packet.Season.Season != CurrentSeason)
                        {
                            CurrentSeason = packet.Season.Season;
                            d_Data.Update();
                            if (CurrentSeason >= 0 && CurrentSeason <= 3)
                            {
                                RedrawAllBlocks();
                            }
                        }
                        packet.Season.Hour -= 1;
                        if (packet.Season.Hour < 0)
                        {
                            //shouldn't happen
                            packet.Season.Hour = 12 * HourDetail;
                        }
                        if (NightLevels == null)
                        {
                            string[] l = MyStream.ReadAllLines(d_GetFile.GetFile("sunlevels.csv"));
                            NightLevels = new int[24 * HourDetail];
                            for (int i = 0; i < 24 * HourDetail; i++)
                            {
                                string s = l[i];
                                if (s.Contains(";")) { s = s.Substring(0, s.IndexOf(";")); }
                                if (s.Contains(",")) { s = s.Substring(0, s.IndexOf(",")); }
                                s = s.Trim();
                                NightLevels[i] = int.Parse(s);
                            }
                        }
                        int sunlight = NightLevels[packet.Season.Hour];
                        SkySphereNight = sunlight < 8;
                        d_SunMoonRenderer.day_length_in_seconds = 60 * 60 * 24 / packet.Season.DayNightCycleSpeedup;
                        int hour = packet.Season.Hour / HourDetail;
                        if (d_SunMoonRenderer.Hour != hour)
                        {
                            d_SunMoonRenderer.Hour = hour;
                        }

                        if (d_Shadows.sunlight != sunlight)
                        {
                            d_Shadows.sunlight = sunlight;
                            d_Shadows.ResetShadows();
                            RedrawAllBlocks();
                        }
                    }
                    return true;
                case ServerPacketId.BlobInitialize:
                    {
                        blobdownload = new MemoryStream();
                        blobdownloadhash = ByteArrayToString(packet.BlobInitialize.hash);
                        blobdownloadname = packet.BlobInitialize.name;
                        ReceivedMapLength = 0; //todo
                    }
                    return true;
                case ServerPacketId.BlobPart:
                    {
                        BinaryWriter bw = new BinaryWriter(blobdownload);
                        bw.Write(packet.BlobPart.data);
                        ReceivedMapLength += packet.BlobPart.data.Length; //todo
                    }
                    return true;
                case ServerPacketId.BlobFinalize:
                    {
                        byte[] downloaded = blobdownload.ToArray();
                        if (ENABLE_PER_SERVER_TEXTURES || Options.UseServerTextures)
                        {
                            if (blobdownloadhash == serverterraintexture)
                            {
                                using (Bitmap bmp = new Bitmap(new MemoryStream(downloaded)))
                                {
                                    d_TerrainTextures.UseTerrainTextureAtlas2d(bmp);
                                }
                            }
                        }
                        if (blobdownloadname != null) // old servers
                        {
                            d_GetFile.SetFile(blobdownloadname, downloaded);
                        }
                        blobdownload = null;
                    }
                    return true;
                case ServerPacketId.ServerIdentification:
                    {
                        serverterraintexture = ByteArrayToString(packet.Identification.TerrainTextureMd5);
                    }
                    return true;
                case ServerPacketId.Sound:
                    {
                        d_Audio.Play(packet.Sound.Name);
                    }
                    return true;
                case ServerPacketId.RemoveMonsters:
                    {
                        foreach (int id in new List<int>(players.Keys))
                        {
                            if (id >= MonsterIdFirst)
                            {
                                players.Remove(id);
                            }
                        }
                    }
                    return true;
                default:
                    return false;
            }
        }