public bool IsTileEmptyForPhysics(int x, int y, int z) { if (z >= game.map.MapSizeZ) { return(true); } bool enableFreemove = false; if (x < 0 || y < 0 || z < 0)// || z >= mapsizez) { return(enableFreemove); } if (x >= game.map.MapSizeX || y >= game.map.MapSizeY)// || z >= mapsizez) { return(enableFreemove); } int block = game.map.GetBlockValid(x, y, z); if (block == 0) { return(true); } Packet_BlockType blocktype = game.blocktypes[block]; return(blocktype.WalkableType == Packet_WalkableTypeEnum.Fluid || game.IsEmptyForPhysics(blocktype) || game.IsRail(blocktype)); }
public static Packet_Server BlockType(int id, Packet_BlockType blockType) { Packet_Server p = new Packet_Server(); p.Id = Packet_ServerIdEnum.BlockType; p.BlockType = new Packet_ServerBlockType(); p.BlockType.Id = id; p.BlockType.Blocktype = blockType; return(p); }
public ServerSimple() { one = 1; clients = new ClientSimple[256]; clientsCount = 0; blockTypes = new Packet_BlockType[GlobalVar.MAX_BLOCKTYPES]; blockTypesCount = 0; mods = new ModSimple[128]; ModManagerSimple1 m = new ModManagerSimple1(); m.Start(this); mods[modsCount++] = new ModSimpleDefault(); mods[modsCount++] = new ModSimpleWorldGenerator(); for (int i = 0; i < modsCount; i++) { mods[i].Start(m); } MapSizeX = 8192; MapSizeY = 8192; MapSizeZ = 128; chunks = new ChunkSimple[(MapSizeX / ChunkSize) * (MapSizeY / ChunkSize)][]; chunkdrawdistance = 4; actions = new QueueAction(); mainThreadActions = new QueueAction(); spawnGlX = MapSizeX / 2; spawnGlY = MapSizeZ; for (int i = 0; i < modsCount; i++) { int spawnHeight = mods[i].GetHeight(); if (spawnHeight != -1) { spawnGlY = spawnHeight; } } spawnGlZ = MapSizeY / 2; }
public bool IsTransparentForLight(int block) { Packet_BlockType b = game.blocktypes[block]; return(b.DrawType != Packet_DrawTypeEnum.Solid && b.DrawType != Packet_DrawTypeEnum.ClosedDoor); }
public BlockTypeSimple() { block = new Packet_BlockType(); }
void ProcessPacket(int client, Packet_Client packet) { switch (packet.GetId()) { case Packet_ClientIdEnum.PlayerIdentification: { if (packet.Identification == null) { return; } SendPacket(client, ServerPackets.Identification(0, MapSizeX, MapSizeY, MapSizeZ, platform.GetGameVersion())); clients[client].Name = packet.Identification.Username; } break; case Packet_ClientIdEnum.RequestBlob: { SendPacket(client, ServerPackets.LevelInitialize()); for (int i = 0; i < blockTypesCount; i++) { Packet_BlockType blocktype = blockTypes[i]; if (blocktype == null) { blocktype = new Packet_BlockType(); } SendPacket(client, ServerPackets.BlockType(i, blocktype)); } SendPacket(client, ServerPackets.BlockTypes()); SendPacket(client, ServerPackets.LevelFinalize()); for (int i = 0; i < clientsCount; i++) { if (clients[i] == null) { continue; } clients[i].glX = spawnGlX; clients[i].glY = spawnGlY; clients[i].glZ = spawnGlZ; Packet_PositionAndOrientation pos = new Packet_PositionAndOrientation(); pos.X = platform.FloatToInt(32 * clients[i].glX); pos.Y = platform.FloatToInt(32 * clients[i].glY); pos.Z = platform.FloatToInt(32 * clients[i].glZ); pos.Pitch = 255 / 2; //SendPacket(client, ServerPackets.Spawn(i, clients[i].Name, pos)); Packet_ServerEntity e = new Packet_ServerEntity(); e.DrawModel = new Packet_ServerEntityAnimatedModel(); e.DrawModel.Model_ = "player.txt"; e.DrawModel.ModelHeight = platform.FloatToInt((one * 17 / 10) * 32); e.DrawModel.EyeHeight = platform.FloatToInt((one * 15 / 10) * 32); e.Position = pos; SendPacket(client, ServerPackets.EntitySpawn(0, e)); SendPacket(client, ServerPackets.PlayerStats(100, 100, 100, 100)); } for (int i = 0; i < modsCount; i++) { mods[i].OnPlayerJoin(client); } clients[client].connected = true; } break; case Packet_ClientIdEnum.Message: { SendPacketToAll(ServerPackets.Message(platform.StringFormat2("{0}: &f{1}", clients[client].Name, packet.Message.Message))); } break; case Packet_ClientIdEnum.SetBlock: { int x = packet.SetBlock.X; int y = packet.SetBlock.Y; int z = packet.SetBlock.Z; int block = packet.SetBlock.BlockType; int mode = packet.SetBlock.Mode; if (mode == Packet_BlockSetModeEnum.Create) { } if (mode == Packet_BlockSetModeEnum.Destroy) { SendPacketToAll(ServerPackets.SetBlock(x, y, z, 0)); } if (mode == Packet_BlockSetModeEnum.Use) { } if (mode == Packet_BlockSetModeEnum.UseWithTool) { } } break; case Packet_ClientIdEnum.PositionandOrientation: { clients[client].glX = one * packet.PositionAndOrientation.X / 32; clients[client].glY = one * packet.PositionAndOrientation.Y / 32; clients[client].glZ = one * packet.PositionAndOrientation.Z / 32; } break; case Packet_ClientIdEnum.InventoryAction: { switch (packet.InventoryAction.Action) { case Packet_InventoryActionTypeEnum.Click: break; } } break; } }
public static Packet_Server BlockType(int id, Packet_BlockType blockType) { Packet_Server p = new Packet_Server(); p.Id = Packet_ServerIdEnum.BlockType; p.BlockType = new Packet_ServerBlockType(); p.BlockType.Id = id; p.BlockType.Blocktype = blockType; return p; }
public static bool IsTransparentForLight(Packet_BlockType b) { return b.DrawType != Packet_DrawTypeEnum.Solid && b.DrawType != Packet_DrawTypeEnum.ClosedDoor; }
public bool IsEmptyForPhysics(Packet_BlockType block) { return (block.DrawType == Packet_DrawTypeEnum.Ladder) || (block.WalkableType != Packet_WalkableTypeEnum.Solid && block.WalkableType != Packet_WalkableTypeEnum.Fluid); }
public void UseBlockType(GamePlatform platform, int id, Packet_BlockType b) { if (b.Name == null)//!b.IsValid) { return; } //public bool[] IsWater { get { return mIsWater; } } // public bool[] IsTransparentForLight { get { return mIsTransparentForLight; } } //public bool[] IsEmptyForPhysics { get { return mIsEmptyForPhysics; } } if (b.WhenPlacedGetsConvertedTo != 0) { mWhenPlayerPlacesGetsConvertedTo[id] = b.WhenPlacedGetsConvertedTo; } else { mWhenPlayerPlacesGetsConvertedTo[id] = id; } IsFlower()[id] = b.DrawType == Packet_DrawTypeEnum.Plant; Rail()[id] = b.Rail; WalkSpeed()[id] = DeserializeFloat(b.WalkSpeedFloat); IsSlipperyWalk()[id] = b.IsSlipperyWalk; WalkSound()[id] = new string[SoundCount]; BreakSound()[id] = new string[SoundCount]; BuildSound()[id] = new string[SoundCount]; CloneSound()[id] = new string[SoundCount]; if (b.Sounds != null) { for (int i = 0; i < b.Sounds.WalkCount; i++) { WalkSound()[id][i] = StringTools.StringAppend(platform, b.Sounds.Walk[i], ".wav"); } for (int i = 0; i < b.Sounds.Break1Count; i++) { BreakSound()[id][i] = StringTools.StringAppend(platform, b.Sounds.Break1[i], ".wav"); } for (int i = 0; i < b.Sounds.BuildCount; i++) { BuildSound()[id][i] = StringTools.StringAppend(platform, b.Sounds.Build[i], ".wav"); } for (int i = 0; i < b.Sounds.CloneCount; i++) { CloneSound()[id][i] = StringTools.StringAppend(platform, b.Sounds.Clone[i], ".wav"); } } LightRadius()[id] = b.LightRadius; //StartInventoryAmount { get; } Strength()[id] = b.Strength; DamageToPlayer()[id] = b.DamageToPlayer; WalkableType1()[id] = b.WalkableType; SetSpecialBlock(b, id); }
public void UseBlockTypes(GamePlatform platform, Packet_BlockType[] blocktypes, int count) { for (int i = 0; i < count; i++) { if (blocktypes[i] != null) { UseBlockType(platform, i, blocktypes[i]); } } }
// TODO: atm it sets sepcial block id from block name - better use new block property public bool SetSpecialBlock(Packet_BlockType b, int id) { switch (b.Name) { case "Empty": this.mBlockIdEmpty = id; return true; case "Dirt": this.mBlockIdDirt = id; return true; case "Sponge": this.mBlockIdSponge = id; return true; case "Trampoline": this.mBlockIdTrampoline = id; return true; case "Adminium": this.mBlockIdAdminium = id; return true; case "Compass": this.mBlockIdCompass = id; return true; case "Ladder": this.mBlockIdLadder = id; return true; case "EmptyHand": this.mBlockIdEmptyHand = id; return true; case "CraftingTable": this.mBlockIdCraftingTable = id; return true; case "Lava": this.mBlockIdLava = id; return true; case "StationaryLava": this.mBlockIdStationaryLava = id; return true; case "FillStart": this.mBlockIdFillStart = id; return true; case "Cuboid": this.mBlockIdCuboid = id; return true; case "FillArea": this.mBlockIdFillArea = id; return true; case "Minecart": this.mBlockIdMinecart = id; return true; case "Rail0": this.mBlockIdRailstart = id; return true; default: return false; } }
internal void ProcessPacket(Packet_Server packet) { if (game.packetHandlers[packet.Id] != null) { game.packetHandlers[packet.Id].Handle(game, packet); } switch (packet.Id) { case Packet_ServerIdEnum.ServerIdentification: { string invalidversionstr = game.language.InvalidVersionConnectAnyway(); game.serverGameVersion = packet.Identification.MdProtocolVersion; if (game.serverGameVersion != game.platform.GetGameVersion()) { game.ChatLog("[GAME] Different game versions"); string q = game.platform.StringFormat2(invalidversionstr, game.platform.GetGameVersion(), game.serverGameVersion); game.invalidVersionDrawMessage = q; game.invalidVersionPacketIdentification = packet; } else { game.ProcessServerIdentification(packet); } game.ReceivedMapLength = 0; } break; case Packet_ServerIdEnum.Ping: { game.SendPingReply(); game.ServerInfo.ServerPing.Send(game.platform); } break; case Packet_ServerIdEnum.PlayerPing: { game.ServerInfo.ServerPing.Receive(game.platform); } break; case Packet_ServerIdEnum.LevelInitialize: { game.ChatLog("[GAME] Initialized map loading"); game.ReceivedMapLength = 0; game.InvokeMapLoadingProgress(0, 0, game.language.Connecting()); } break; case Packet_ServerIdEnum.LevelDataChunk: { game.InvokeMapLoadingProgress(packet.LevelDataChunk.PercentComplete, game.ReceivedMapLength, packet.LevelDataChunk.Status); } break; case Packet_ServerIdEnum.LevelFinalize: { game.ChatLog("[GAME] Finished map loading"); } break; case Packet_ServerIdEnum.SetBlock: { int x = packet.SetBlock.X; int y = packet.SetBlock.Y; int z = packet.SetBlock.Z; int type = packet.SetBlock.BlockType; //try { game.SetTileAndUpdate(x, y, z, type); } //catch { Console.WriteLine("Cannot update tile!"); } } break; case Packet_ServerIdEnum.FillArea: { int ax = packet.FillArea.X1; int ay = packet.FillArea.Y1; int az = packet.FillArea.Z1; int bx = packet.FillArea.X2; int by = packet.FillArea.Y2; int bz = packet.FillArea.Z2; int startx = MathCi.MinInt(ax, bx); int endx = MathCi.MaxInt(ax, bx); int starty = MathCi.MinInt(ay, by); int endy = MathCi.MaxInt(ay, by); int startz = MathCi.MinInt(az, bz); int endz = MathCi.MaxInt(az, bz); int blockCount = packet.FillArea.BlockCount; { for (int x = startx; x <= endx; x++) { for (int y = starty; y <= endy; y++) { for (int z = startz; z <= endz; z++) { // if creative mode is off and player run out of blocks if (blockCount == 0) { return; } //try { game.SetTileAndUpdate(x, y, z, packet.FillArea.BlockType); } //catch //{ // Console.WriteLine("Cannot update tile!"); //} blockCount--; } } } } } break; case Packet_ServerIdEnum.FillAreaLimit: { game.fillAreaLimit = packet.FillAreaLimit.Limit; if (game.fillAreaLimit > 100000) { game.fillAreaLimit = 100000; } } break; case Packet_ServerIdEnum.Freemove: { game.AllowFreemove = packet.Freemove.IsEnabled != 0; if (!game.AllowFreemove) { game.controls.SetFreemove(FreemoveLevelEnum.None); game.movespeed = game.basemovespeed; game.Log(game.language.MoveNormal()); } } break; case Packet_ServerIdEnum.PlayerSpawnPosition: { int x = packet.PlayerSpawnPosition.X; int y = packet.PlayerSpawnPosition.Y; int z = packet.PlayerSpawnPosition.Z; game.playerPositionSpawnX = x; game.playerPositionSpawnY = z; game.playerPositionSpawnZ = y; game.Log(game.platform.StringFormat(game.language.SpawnPositionSetTo(), game.platform.StringFormat3("{0},{1},{2}", game.platform.IntToString(x), game.platform.IntToString(y), game.platform.IntToString(z)))); } break; case Packet_ServerIdEnum.Message: { game.AddChatline(packet.Message.Message); game.ChatLog(packet.Message.Message); } break; case Packet_ServerIdEnum.DisconnectPlayer: { game.ChatLog(game.platform.StringFormat("[GAME] Disconnected by the server ({0})", packet.DisconnectPlayer.DisconnectReason)); //Exit mouse pointer lock if necessary if (game.platform.IsMousePointerLocked()) { game.platform.ExitMousePointerLock(); } //When server disconnects player, return to main menu game.platform.MessageBoxShowError(packet.DisconnectPlayer.DisconnectReason, "Disconnected from server"); game.ExitToMainMenu_(); break; } case Packet_ServerIdEnum.PlayerStats: { Packet_ServerPlayerStats p = packet.PlayerStats; game.PlayerStats = p; } break; case Packet_ServerIdEnum.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(ConvertInventory(packet.Inventory.Inventory)); game.UseInventory(packet.Inventory.Inventory); } //FiniteInventory = packet.FiniteInventory.BlockTypeAmount; //ENABLE_FINITEINVENTORY = packet.FiniteInventory.IsFinite; //FiniteInventoryMax = packet.FiniteInventory.Max; } break; case Packet_ServerIdEnum.Season: { packet.Season.Hour -= 1; if (packet.Season.Hour < 0) { //shouldn't happen packet.Season.Hour = 12 * Game.HourDetail; } int sunlight = game.NightLevels[packet.Season.Hour]; game.SkySphereNight = sunlight < 8; game.d_SunMoonRenderer.day_length_in_seconds = 60 * 60 * 24 / packet.Season.DayNightCycleSpeedup; int hour = packet.Season.Hour / Game.HourDetail; if (game.d_SunMoonRenderer.GetHour() != hour) { game.d_SunMoonRenderer.SetHour(hour); } if (game.sunlight_ != sunlight) { game.sunlight_ = sunlight; //d_Shadows.ResetShadows(); game.RedrawAllBlocks(); } } break; case Packet_ServerIdEnum.BlobInitialize: { game.blobdownload = new CitoMemoryStream(); //blobdownloadhash = ByteArrayToString(packet.BlobInitialize.hash); game.blobdownloadname = packet.BlobInitialize.Name; game.blobdownloadmd5 = packet.BlobInitialize.Md5; } break; case Packet_ServerIdEnum.BlobPart: { int length = game.platform.ByteArrayLength(packet.BlobPart.Data); game.blobdownload.Write(packet.BlobPart.Data, 0, length); game.ReceivedMapLength += length; } break; case Packet_ServerIdEnum.BlobFinalize: { byte[] downloaded = game.blobdownload.ToArray(); if (game.blobdownloadname != null) // old servers { game.SetFile(game.blobdownloadname, game.blobdownloadmd5, downloaded, game.blobdownload.Length()); } game.blobdownload = null; } break; case Packet_ServerIdEnum.Sound: { game.PlaySoundAt(packet.Sound.Name, packet.Sound.X, packet.Sound.Y, packet.Sound.Z); } break; case Packet_ServerIdEnum.RemoveMonsters: { for (int i = Game.entityMonsterIdStart; i < Game.entityMonsterIdStart + Game.entityMonsterIdCount; i++) { game.entities[i] = null; } } break; case Packet_ServerIdEnum.Translation: game.language.Override(packet.Translation.Lang, packet.Translation.Id, packet.Translation.Translation); break; case Packet_ServerIdEnum.BlockType: game.NewBlockTypes[packet.BlockType.Id] = packet.BlockType.Blocktype; break; case Packet_ServerIdEnum.SunLevels: game.NightLevels = packet.SunLevels.Sunlevels; break; case Packet_ServerIdEnum.LightLevels: for (int i = 0; i < packet.LightLevels.LightlevelsCount; i++) { game.mLightLevels[i] = game.DeserializeFloat(packet.LightLevels.Lightlevels[i]); } break; case Packet_ServerIdEnum.Follow: IntRef oldFollowId = game.FollowId(); game.Follow = packet.Follow.Client; if (packet.Follow.Tpp != 0) { game.SetCamera(CameraType.Overhead); game.player.position.rotx = Game.GetPi(); game.GuiStateBackToGame(); } else { game.SetCamera(CameraType.Fpp); } break; case Packet_ServerIdEnum.Bullet: game.EntityAddLocal(game.CreateBulletEntity( game.DeserializeFloat(packet.Bullet.FromXFloat), game.DeserializeFloat(packet.Bullet.FromYFloat), game.DeserializeFloat(packet.Bullet.FromZFloat), game.DeserializeFloat(packet.Bullet.ToXFloat), game.DeserializeFloat(packet.Bullet.ToYFloat), game.DeserializeFloat(packet.Bullet.ToZFloat), game.DeserializeFloat(packet.Bullet.SpeedFloat))); break; case Packet_ServerIdEnum.Ammo: if (!game.ammostarted) { game.ammostarted = true; for (int i = 0; i < packet.Ammo.TotalAmmoCount; i++) { Packet_IntInt k = packet.Ammo.TotalAmmo[i]; game.LoadedAmmo[k.Key_] = MathCi.MinInt(k.Value_, game.blocktypes[k.Key_].AmmoMagazine); } } game.TotalAmmo = new int[GlobalVar.MAX_BLOCKTYPES]; for (int i = 0; i < packet.Ammo.TotalAmmoCount; i++) { game.TotalAmmo[packet.Ammo.TotalAmmo[i].Key_] = packet.Ammo.TotalAmmo[i].Value_; } break; case Packet_ServerIdEnum.Explosion: { Entity entity = new Entity(); entity.expires = new Expires(); entity.expires.timeLeft = game.DeserializeFloat(packet.Explosion.TimeFloat); entity.push = packet.Explosion; game.EntityAddLocal(entity); } break; case Packet_ServerIdEnum.Projectile: { Entity entity = new Entity(); Sprite sprite = new Sprite(); sprite.image = "ChemicalGreen.png"; sprite.size = 14; sprite.animationcount = 0; sprite.positionX = game.DeserializeFloat(packet.Projectile.FromXFloat); sprite.positionY = game.DeserializeFloat(packet.Projectile.FromYFloat); sprite.positionZ = game.DeserializeFloat(packet.Projectile.FromZFloat); entity.sprite = sprite; Grenade_ grenade = new Grenade_(); grenade.velocityX = game.DeserializeFloat(packet.Projectile.VelocityXFloat); grenade.velocityY = game.DeserializeFloat(packet.Projectile.VelocityYFloat); grenade.velocityZ = game.DeserializeFloat(packet.Projectile.VelocityZFloat); grenade.block = packet.Projectile.BlockId; grenade.sourcePlayer = packet.Projectile.SourcePlayerID; entity.grenade = grenade; entity.expires = Expires.Create(game.DeserializeFloat(packet.Projectile.ExplodesAfterFloat)); game.EntityAddLocal(entity); } break; case Packet_ServerIdEnum.BlockTypes: game.blocktypes = game.NewBlockTypes; game.NewBlockTypes = new Packet_BlockType[GlobalVar.MAX_BLOCKTYPES]; int textureInAtlasIdsCount = 1024; string[] textureInAtlasIds = new string[textureInAtlasIdsCount]; int lastTextureId = 0; for (int i = 0; i < GlobalVar.MAX_BLOCKTYPES; i++) { if (game.blocktypes[i] != null) { string[] to_load = new string[7]; int to_loadLength = 7; { to_load[0] = game.blocktypes[i].TextureIdLeft; to_load[1] = game.blocktypes[i].TextureIdRight; to_load[2] = game.blocktypes[i].TextureIdFront; to_load[3] = game.blocktypes[i].TextureIdBack; to_load[4] = game.blocktypes[i].TextureIdTop; to_load[5] = game.blocktypes[i].TextureIdBottom; to_load[6] = game.blocktypes[i].TextureIdForInventory; } for (int k = 0; k < to_loadLength; k++) { if (!Contains(textureInAtlasIds, textureInAtlasIdsCount, to_load[k])) { textureInAtlasIds[lastTextureId++] = to_load[k]; } } } } game.d_Data.UseBlockTypes(game.platform, game.blocktypes, GlobalVar.MAX_BLOCKTYPES); for (int i = 0; i < GlobalVar.MAX_BLOCKTYPES; i++) { Packet_BlockType b = game.blocktypes[i]; if (b == null) { continue; } //Indexed by block id and TileSide. if (textureInAtlasIds != null) { game.TextureId[i][0] = IndexOf(textureInAtlasIds, textureInAtlasIdsCount, b.TextureIdTop); game.TextureId[i][1] = IndexOf(textureInAtlasIds, textureInAtlasIdsCount, b.TextureIdBottom); game.TextureId[i][2] = IndexOf(textureInAtlasIds, textureInAtlasIdsCount, b.TextureIdFront); game.TextureId[i][3] = IndexOf(textureInAtlasIds, textureInAtlasIdsCount, b.TextureIdBack); game.TextureId[i][4] = IndexOf(textureInAtlasIds, textureInAtlasIdsCount, b.TextureIdLeft); game.TextureId[i][5] = IndexOf(textureInAtlasIds, textureInAtlasIdsCount, b.TextureIdRight); game.TextureIdForInventory[i] = IndexOf(textureInAtlasIds, textureInAtlasIdsCount, b.TextureIdForInventory); } } game.UseTerrainTextures(textureInAtlasIds, textureInAtlasIdsCount); game.handRedraw = true; game.RedrawAllBlocks(); break; case Packet_ServerIdEnum.ServerRedirect: game.ChatLog("[GAME] Received server redirect"); //Leave current server game.SendLeave(Packet_LeaveReasonEnum.Leave); //Exit game screen and create new game instance game.ExitAndSwitchServer(packet.Redirect); break; } }
public bool IsRail(Packet_BlockType block) { return block.Rail > 0; //Does not include Rail0, but this can't be placed. }