Esempio n. 1
0
 public override void Handle(Game game, Packet_Server packet)
 {
     Entity entity = game.entities[packet.EntityPosition.Id];
     EntityPosition_ pos = ClientPacketHandlerEntitySpawn.ToClientEntityPosition(packet.EntityPosition.PositionAndOrientation);
     entity.networkPosition = pos;
     entity.networkPosition.PositionLoaded = true;
     entity.networkPosition.LastUpdateMilliseconds = game.platform.TimeMillisecondsFromStart();
     if (packet.EntityPosition.Id == game.LocalPlayerId)
     {
         // Override local player position if necessary (teleport)
         game.player.position.x = pos.x;
         game.player.position.y = pos.y;
         game.player.position.z = pos.z;
         game.player.position.rotx = pos.rotx;
         game.player.position.roty = pos.roty;
         game.player.position.rotz = pos.rotz;
         entity.networkPosition = null;
     }
     else if (entity.push != null)
     {
         // Create push force for any player except local player
         entity.push.XFloat = packet.EntityPosition.PositionAndOrientation.X;
         entity.push.YFloat = packet.EntityPosition.PositionAndOrientation.Z;
         entity.push.ZFloat = packet.EntityPosition.PositionAndOrientation.Y;
     }
 }
Esempio n. 2
0
    public override void Handle(Game game, Packet_Server packet)
    {
        Entity          entity = game.entities[packet.EntityPosition.Id];
        EntityPosition_ pos    = ClientPacketHandlerEntitySpawn.ToClientEntityPosition(packet.EntityPosition.PositionAndOrientation);

        entity.networkPosition = pos;
        entity.networkPosition.PositionLoaded         = true;
        entity.networkPosition.LastUpdateMilliseconds = game.platform.TimeMillisecondsFromStart();
        if (packet.EntityPosition.Id == game.LocalPlayerId)
        {
            // Override local player position if necessary (teleport)
            game.player.position.x    = pos.x;
            game.player.position.y    = pos.y;
            game.player.position.z    = pos.z;
            game.player.position.rotx = pos.rotx;
            game.player.position.roty = pos.roty;
            game.player.position.rotz = pos.rotz;
            entity.networkPosition    = null;
        }
        else if (entity.push != null)
        {
            // Create push force for any player except local player
            entity.push.XFloat = packet.EntityPosition.PositionAndOrientation.X;
            entity.push.YFloat = packet.EntityPosition.PositionAndOrientation.Z;
            entity.push.ZFloat = packet.EntityPosition.PositionAndOrientation.Y;
        }
    }
Esempio n. 3
0
 void SendPacketToAll(Packet_Server packet)
 {
     for (int i = 0; i < clientsCount; i++)
     {
         SendPacket(i, packet);
     }
 }
Esempio n. 4
0
    void ReadPacket(NetClient client)
    {
        bool success = false;
        int  started = p.TimeMillisecondsFromStart();
        int  timeout = 2000;

        while (p.TimeMillisecondsFromStart() < started + timeout)
        {
            if (success)
            {
                //Return if already received answer from server
                querySuccess = true;
                return;
            }
            NetIncomingMessage msg;
            msg = client.ReadMessage();
            if (msg == null)
            {
                //Message empty - skip processing.
                continue;
            }

            Packet_Server packet = new Packet_Server();
            Packet_ServerSerializer.DeserializeBuffer(msg.message, msg.messageLength, packet);

            switch (packet.Id)
            {
            case Packet_ServerIdEnum.QueryAnswer:
                //Got answer from server. Process it.
                result.Name            = packet.QueryAnswer.Name;
                result.MOTD            = packet.QueryAnswer.MOTD;
                result.PlayerCount     = packet.QueryAnswer.PlayerCount;
                result.MaxPlayers      = packet.QueryAnswer.MaxPlayers;
                result.PlayerList      = packet.QueryAnswer.PlayerList;
                result.Port            = packet.QueryAnswer.Port;
                result.GameMode        = packet.QueryAnswer.GameMode;
                result.Password        = packet.QueryAnswer.Password;
                result.PublicHash      = packet.QueryAnswer.PublicHash;
                result.ServerVersion   = packet.QueryAnswer.ServerVersion;
                result.MapSizeX        = packet.QueryAnswer.MapSizeX;
                result.MapSizeY        = packet.QueryAnswer.MapSizeY;
                result.MapSizeZ        = packet.QueryAnswer.MapSizeZ;
                result.ServerThumbnail = packet.QueryAnswer.ServerThumbnail;
                success = true;
                continue;

            case Packet_ServerIdEnum.DisconnectPlayer:
                serverMessage = packet.DisconnectPlayer.DisconnectReason;
                //End method as server kicked us out
                return;

            default:
                //Drop all other packets sent by server (not relevant)
                continue;
            }
        }
        //Set timeout message if query did not finish in time
        serverMessage = "Timeout while querying server!";
    }
Esempio n. 5
0
    public static Packet_Server LevelFinalize()
    {
        Packet_Server p = new Packet_Server();

        p.Id            = Packet_ServerIdEnum.LevelFinalize;
        p.LevelFinalize = new Packet_ServerLevelFinalize();
        return(p);
    }
Esempio n. 6
0
    public static Packet_Server BlockTypes()
    {
        Packet_Server p = new Packet_Server();

        p.Id         = Packet_ServerIdEnum.BlockTypes;
        p.BlockTypes = new Packet_ServerBlockTypes();
        return(p);
    }
Esempio n. 7
0
    internal static Packet_Server Ping()
    {
        Packet_Server p = new Packet_Server();

        p.Id   = Packet_ServerIdEnum.Ping;
        p.Ping = new Packet_ServerPing();
        return(p);
    }
Esempio n. 8
0
    internal static Packet_Server AnswerQuery(Packet_ServerQueryAnswer answer)
    {
        Packet_Server p = new Packet_Server();

        p.Id          = Packet_ServerIdEnum.QueryAnswer;
        p.QueryAnswer = answer;
        return(p);
    }
Esempio n. 9
0
    public static Packet_Server ChunkPart(byte[] compressedChunkPart)
    {
        Packet_Server p = new Packet_Server();

        p.Id        = Packet_ServerIdEnum.ChunkPart;
        p.ChunkPart = new Packet_ServerChunkPart();
        p.ChunkPart.CompressedChunkPart = compressedChunkPart;
        return(p);
    }
Esempio n. 10
0
    public static byte[] Serialize(Packet_Server packet, IntRef retLength)
    {
        CitoMemoryStream ms = new CitoMemoryStream();

        Packet_ServerSerializer.Serialize(ms, packet);
        byte[] data = ms.ToArray();
        retLength.value = ms.Length();
        return(data);
    }
Esempio n. 11
0
    public static Packet_Server Message(string text)
    {
        Packet_Server p = new Packet_Server();

        p.Id              = Packet_ServerIdEnum.Message;
        p.Message         = new Packet_ServerMessage();
        p.Message.Message = text;
        return(p);
    }
Esempio n. 12
0
    public static SendPacketAction Create(ServerSimple server_, int client_, Packet_Server packet_)
    {
        SendPacketAction a = new SendPacketAction();

        a.server = server_;
        a.client = client_;
        a.packet = packet_;
        return(a);
    }
Esempio n. 13
0
    internal static Packet_Server EntityDespawn(int id)
    {
        Packet_Server p = new Packet_Server();

        p.Id               = Packet_ServerIdEnum.EntityDespawn;
        p.EntityDespawn    = new Packet_ServerEntityDespawn();
        p.EntityDespawn.Id = id;
        return(p);
    }
Esempio n. 14
0
    internal static Packet_Server Inventory(Packet_Inventory inventory)
    {
        Packet_Server p = new Packet_Server();

        p.Id                  = Packet_ServerIdEnum.FiniteInventory;
        p.Inventory           = new Packet_ServerInventory();
        p.Inventory.Inventory = inventory;
        return(p);
    }
Esempio n. 15
0
    internal static Packet_Server DisconnectPlayer(string disconnectReason)
    {
        Packet_Server p = new Packet_Server();

        p.Id = Packet_ServerIdEnum.DisconnectPlayer;
        p.DisconnectPlayer = new Packet_ServerDisconnectPlayer();
        p.DisconnectPlayer.DisconnectReason = disconnectReason;
        return(p);
    }
Esempio n. 16
0
    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);
    }
Esempio n. 17
0
    internal static Packet_Server EntityPositionAndOrientation(int id, Packet_PositionAndOrientation positionAndOrientation)
    {
        Packet_Server p = new Packet_Server();

        p.Id                = Packet_ServerIdEnum.EntityPosition;
        p.EntityPosition    = new Packet_ServerEntityPositionAndOrientation();
        p.EntityPosition.Id = id;
        p.EntityPosition.PositionAndOrientation = positionAndOrientation;
        return(p);
    }
Esempio n. 18
0
    internal static Packet_Server EntitySpawn(int id, Packet_ServerEntity entity)
    {
        Packet_Server p = new Packet_Server();

        p.Id                  = Packet_ServerIdEnum.EntitySpawn;
        p.EntitySpawn         = new Packet_ServerEntitySpawn();
        p.EntitySpawn.Id      = id;
        p.EntitySpawn.Entity_ = entity;
        return(p);
    }
Esempio n. 19
0
    public void SendPacket(int client, Packet_Server packet)
    {
        IntRef length = new IntRef();

        byte[] data             = ServerPackets.Serialize(packet, length);
        INetOutgoingMessage msg = new INetOutgoingMessage();

        msg.Write(data, length.value);
        clients[client].Connection.SendMessage(msg, MyNetDeliveryMethod.ReliableOrdered, 0);
    }
Esempio n. 20
0
    internal static Packet_Server SetBlock(int x, int y, int z, int block)
    {
        Packet_Server p = new Packet_Server();

        p.Id                 = Packet_ServerIdEnum.SetBlock;
        p.SetBlock           = new Packet_ServerSetBlock();
        p.SetBlock.X         = x;
        p.SetBlock.Y         = y;
        p.SetBlock.Z         = z;
        p.SetBlock.BlockType = block;
        return(p);
    }
Esempio n. 21
0
    internal static Packet_Server PlayerStats(int health, int maxHealth, int oxygen, int maxOxygen)
    {
        Packet_Server p = new Packet_Server();

        p.Id          = Packet_ServerIdEnum.PlayerStats;
        p.PlayerStats = new Packet_ServerPlayerStats();
        p.PlayerStats.CurrentHealth = health;
        p.PlayerStats.MaxHealth     = maxHealth;
        p.PlayerStats.CurrentOxygen = oxygen;
        p.PlayerStats.MaxOxygen     = maxOxygen;
        return(p);
    }
Esempio n. 22
0
    public static Packet_Server Identification(int assignedClientId, int mapSizeX, int mapSizeY, int mapSizeZ, string version)
    {
        Packet_Server p = new Packet_Server();

        p.Id             = Packet_ServerIdEnum.ServerIdentification;
        p.Identification = new Packet_ServerIdentification();
        p.Identification.AssignedClientId  = assignedClientId;
        p.Identification.MapSizeX          = mapSizeX;
        p.Identification.MapSizeY          = mapSizeY;
        p.Identification.MapSizeZ          = mapSizeZ;
        p.Identification.ServerName        = "Simple";
        p.Identification.MdProtocolVersion = version;
        return(p);
    }
Esempio n. 23
0
    public static Packet_Server Chunk_(int x, int y, int z, int chunksize)
    {
        Packet_Server p = new Packet_Server();

        p.Id           = Packet_ServerIdEnum.Chunk_;
        p.Chunk_       = new Packet_ServerChunk();
        p.Chunk_.X     = x;
        p.Chunk_.Y     = y;
        p.Chunk_.Z     = z;
        p.Chunk_.SizeX = chunksize;
        p.Chunk_.SizeY = chunksize;
        p.Chunk_.SizeZ = chunksize;
        return(p);
    }
Esempio n. 24
0
    public void TryReadPacket(byte[] data, int dataLength)
    {
        Packet_Server packet = new Packet_Server();
        Packet_ServerSerializer.DeserializeBuffer(data, dataLength, packet);

        ProcessInBackground(packet);

        ProcessPacketTask task = new ProcessPacketTask();
        task.game = game;
        task.packet_ = packet;
        game.QueueActionCommit(task);

        game.LastReceivedMilliseconds = game.currentTimeMilliseconds;
        //return lengthPrefixLength + packetLength;
    }
Esempio n. 25
0
 public override void Handle(Game game, Packet_Server packet)
 {
     Entity entity = game.entities[packet.EntityPosition.Id];
     EntityPosition_ pos = ClientPacketHandlerEntitySpawn.ToClientEntityPosition(packet.EntityPosition.PositionAndOrientation);
     entity.networkPosition = pos;
     entity.networkPosition.PositionLoaded = true;
     entity.networkPosition.LastUpdateMilliseconds = game.platform.TimeMillisecondsFromStart();
     if (packet.EntityPosition.Id == game.LocalPlayerId)
     {
         game.player.position.x = pos.x;
         game.player.position.y = pos.y;
         game.player.position.z = pos.z;
         entity.networkPosition = null;
     }
 }
Esempio n. 26
0
    public override void Handle(Game game, Packet_Server packet)
    {
        Packet_ServerDialog d = packet.Dialog;

        if (d.Dialog == null)
        {
            if (game.GetDialogId(d.DialogId) != -1 && game.dialogs[game.GetDialogId(d.DialogId)].value.IsModal != 0)
            {
                game.GuiStateBackToGame();
            }
            if (game.GetDialogId(d.DialogId) != -1)
            {
                game.dialogs[game.GetDialogId(d.DialogId)] = null;
            }
            if (game.DialogsCount_() == 0)
            {
                game.SetFreeMouse(false);
            }
        }
        else
        {
            VisibleDialog d2 = new VisibleDialog();
            d2.key         = d.DialogId;
            d2.value       = d.Dialog;
            d2.screen      = ConvertDialog(game, d2.value);
            d2.screen.game = game;
            if (game.GetDialogId(d.DialogId) == -1)
            {
                for (int i = 0; i < game.dialogsCount; i++)
                {
                    if (game.dialogs[i] == null)
                    {
                        game.dialogs[i] = d2;
                        break;
                    }
                }
            }
            else
            {
                game.dialogs[game.GetDialogId(d.DialogId)] = d2;
            }
            if (d.Dialog.IsModal != 0)
            {
                game.guistate = GuiState.ModalDialog;
                game.SetFreeMouse(true);
            }
        }
    }
Esempio n. 27
0
    public override void Handle(Game game, Packet_Server packet)
    {
        Entity          entity = game.entities[packet.EntityPosition.Id];
        EntityPosition_ pos    = ClientPacketHandlerEntitySpawn.ToClientEntityPosition(packet.EntityPosition.PositionAndOrientation);

        entity.networkPosition = pos;
        entity.networkPosition.PositionLoaded         = true;
        entity.networkPosition.LastUpdateMilliseconds = game.platform.TimeMillisecondsFromStart();
        if (packet.EntityPosition.Id == game.LocalPlayerId)
        {
            game.player.position.x = pos.x;
            game.player.position.y = pos.y;
            game.player.position.z = pos.z;
            entity.networkPosition = null;
        }
    }
Esempio n. 28
0
 public override void Handle(Game game, Packet_Server packet)
 {
     Packet_ServerDialog d = packet.Dialog;
     if (d.Dialog == null)
     {
         if (game.GetDialogId(d.DialogId) != -1 && game.dialogs[game.GetDialogId(d.DialogId)].value.IsModal != 0)
         {
             game.GuiStateBackToGame();
         }
         if (game.GetDialogId(d.DialogId) != -1)
         {
             game.dialogs[game.GetDialogId(d.DialogId)] = null;
         }
         if (game.DialogsCount_() == 0)
         {
             game.SetFreeMouse(false);
         }
     }
     else
     {
         VisibleDialog d2 = new VisibleDialog();
         d2.key = d.DialogId;
         d2.value = d.Dialog;
         d2.screen = ConvertDialog(game, d2.value);
         d2.screen.game = game;
         if (game.GetDialogId(d.DialogId) == -1)
         {
             for (int i = 0; i < game.dialogsCount; i++)
             {
                 if (game.dialogs[i] == null)
                 {
                     game.dialogs[i] = d2;
                     break;
                 }
             }
         }
         else
         {
             game.dialogs[game.GetDialogId(d.DialogId)] = d2;
         }
         if (d.Dialog.IsModal != 0)
         {
             game.guistate = GuiState.ModalDialog;
             game.SetFreeMouse(true);
         }
     }
 }
Esempio n. 29
0
    public void TryReadPacket(byte[] data, int dataLength)
    {
        Packet_Server packet = new Packet_Server();

        Packet_ServerSerializer.DeserializeBuffer(data, dataLength, packet);

        ProcessInBackground(packet);

        ProcessPacketTask task = new ProcessPacketTask();

        task.game    = game;
        task.packet_ = packet;
        game.QueueActionCommit(task);

        game.LastReceivedMilliseconds = game.currentTimeMilliseconds;
        //return lengthPrefixLength + packetLength;
    }
Esempio n. 30
0
 public override void Handle(Game game, Packet_Server packet)
 {
     //Check if Entity has DownloadSkin set and texture is not empty or default player texture
     if (game.entities[packet.EntityDespawn.Id] != null)
     {
         if (game.entities[packet.EntityDespawn.Id].drawModel != null && game.entities[packet.EntityDespawn.Id].drawModel.DownloadSkin)
         {
             int currentTex = game.entities[packet.EntityDespawn.Id].drawModel.CurrentTexture;
             if (currentTex > 0 && currentTex != game.GetTexture("mineplayer.png"))
             {
                 //Entity probably is a player. Set CurrentTexture to -1 and then delete stored texture.
                 game.entities[packet.EntityDespawn.Id].drawModel.CurrentTexture = -1;
                 game.DeleteTexture(game.entities[packet.EntityDespawn.Id].drawName.Name);
             }
         }
     }
     game.entities[packet.EntityDespawn.Id] = null;
 }
Esempio n. 31
0
 public override void Handle(Game game, Packet_Server packet)
 {
     //Check if Entity has DownloadSkin set and texture is not empty or default player texture
     if (game.entities[packet.EntityDespawn.Id] != null)
     {
         if (game.entities[packet.EntityDespawn.Id].drawModel != null && game.entities[packet.EntityDespawn.Id].drawModel.DownloadSkin)
         {
             int currentTex = game.entities[packet.EntityDespawn.Id].drawModel.CurrentTexture;
             if (currentTex > 0 && currentTex != game.GetTexture("mineplayer.png"))
             {
                 //Entity probably is a player. Set CurrentTexture to -1 and then delete stored texture.
                 game.entities[packet.EntityDespawn.Id].drawModel.CurrentTexture = -1;
                 game.DeleteTexture(game.entities[packet.EntityDespawn.Id].drawName.Name);
             }
         }
     }
     game.entities[packet.EntityDespawn.Id] = null;
 }
Esempio n. 32
0
    public override void Handle(Game game, Packet_Server packet)
    {
        Entity entity = game.entities[packet.EntitySpawn.Id];

        if (entity == null)
        {
            entity = new Entity();
        }
        ToClientEntity(game, packet.EntitySpawn.Entity_, entity, packet.EntitySpawn.Id != game.LocalPlayerId);
        game.entities[packet.EntitySpawn.Id] = entity;
        if (packet.EntitySpawn.Id == game.LocalPlayerId)
        {
            entity.networkPosition = null;
            game.player            = entity;
            if (!game.spawned)
            {
                entity.scripts[entity.scriptsCount++] = new ScriptCharacterPhysics();
                game.MapLoaded();
                game.spawned = true;
            }
        }
    }
Esempio n. 33
0
 internal static Packet_Server Ping()
 {
     Packet_Server p = new Packet_Server();
     p.Id = Packet_ServerIdEnum.Ping;
     p.Ping = new Packet_ServerPing();
     return p;
 }
Esempio n. 34
0
 internal static Packet_Server Inventory(Packet_Inventory inventory)
 {
     Packet_Server p = new Packet_Server();
     p.Id = Packet_ServerIdEnum.FiniteInventory;
     p.Inventory = new Packet_ServerInventory();
     p.Inventory.Inventory = inventory;
     return p;
 }
Esempio n. 35
0
 internal static Packet_Server EntitySpawn(int id, Packet_ServerEntity entity)
 {
     Packet_Server p = new Packet_Server();
     p.Id = Packet_ServerIdEnum.EntitySpawn;
     p.EntitySpawn = new Packet_ServerEntitySpawn();
     p.EntitySpawn.Id = id;
     p.EntitySpawn.Entity_ = entity;
     return p;
 }
Esempio n. 36
0
 public static Packet_Server BlockTypes()
 {
     Packet_Server p = new Packet_Server();
     p.Id = Packet_ServerIdEnum.BlockTypes;
     p.BlockTypes = new Packet_ServerBlockTypes();
     return p;
 }
Esempio n. 37
0
 void ProcessInBackground(Packet_Server packet)
 {
     switch (packet.Id)
     {
         case Packet_ServerIdEnum.ChunkPart:
             byte[] arr = packet.ChunkPart.CompressedChunkPart;
             int arrLength = game.platform.ByteArrayLength(arr); // todo
             for (int i = 0; i < arrLength; i++)
             {
                 CurrentChunk[CurrentChunkCount++] = arr[i];
             }
             break;
         case Packet_ServerIdEnum.Chunk_:
             {
                 Packet_ServerChunk p = packet.Chunk_;
                 if (CurrentChunkCount != 0)
                 {
                     game.platform.GzipDecompress(CurrentChunk, CurrentChunkCount, decompressedchunk);
                     {
                         int i = 0;
                         for (int zz = 0; zz < p.SizeZ; zz++)
                         {
                             for (int yy = 0; yy < p.SizeY; yy++)
                             {
                                 for (int xx = 0; xx < p.SizeX; xx++)
                                 {
                                     int block = (decompressedchunk[i + 1] << 8) + decompressedchunk[i];
                                     if (block < GlobalVar.MAX_BLOCKTYPES)
                                     {
                                         receivedchunk[Index3d(xx, yy, zz, p.SizeX, p.SizeY)] = block;
                                     }
                                     i += 2;
                                 }
                             }
                         }
                     }
                 }
                 else
                 {
                     int size = p.SizeX * p.SizeY * p.SizeZ;
                     for (int i = 0; i < size; i++)
                     {
                         receivedchunk[i] = 0;
                     }
                 }
                 {
                     game.map.SetMapPortion(p.X, p.Y, p.Z, receivedchunk, p.SizeX, p.SizeY, p.SizeZ);
                     for (int xx = 0; xx < 2; xx++)
                     {
                         for (int yy = 0; yy < 2; yy++)
                         {
                             for (int zz = 0; zz < 2; zz++)
                             {
                                 //d_Shadows.OnSetChunk(p.X + 16 * xx, p.Y + 16 * yy, p.Z + 16 * zz);//todo
                             }
                         }
                     }
                 }
                 game.ReceivedMapLength += CurrentChunkCount;// lengthPrefixLength + packetLength;
                 CurrentChunkCount = 0;
             }
             break;
         case Packet_ServerIdEnum.HeightmapChunk:
             {
                 Packet_ServerHeightmapChunk p = packet.HeightmapChunk;
                 game.platform.GzipDecompress(p.CompressedHeightmap, game.platform.ByteArrayLength(p.CompressedHeightmap), decompressedchunk);
                 int[] decompressedchunk1 = Game.ByteArrayToUshortArray(decompressedchunk, p.SizeX * p.SizeY * 2);
                 for (int xx = 0; xx < p.SizeX; xx++)
                 {
                     for (int yy = 0; yy < p.SizeY; yy++)
                     {
                         int height = decompressedchunk1[MapUtilCi.Index2d(xx, yy, p.SizeX)];
                         game.d_Heightmap.SetBlock(p.X + xx, p.Y + yy, height);
                     }
                 }
             }
             break;
     }
 }
Esempio n. 38
0
 public static byte[] Serialize(Packet_Server packet, IntRef retLength)
 {
     CitoMemoryStream ms = new CitoMemoryStream();
     Packet_ServerSerializer.Serialize(ms, packet);
     byte[] data = ms.ToArray();
     retLength.value = ms.Length();
     return data;
 }
Esempio n. 39
0
 public override void Handle(Game game, Packet_Server packet)
 {
     mod.d_CraftingRecipes      = packet.CraftingRecipes.CraftingRecipes;
     mod.d_CraftingRecipesCount = packet.CraftingRecipes.CraftingRecipesCount;
 }
Esempio n. 40
0
 public static Packet_Server LevelInitialize()
 {
     Packet_Server p = new Packet_Server();
     p.Id = Packet_ServerIdEnum.LevelInitialize;
     p.LevelInitialize = new Packet_ServerLevelInitialize();
     return p;
 }
Esempio n. 41
0
 public static Packet_Server Message(string text)
 {
     Packet_Server p = new Packet_Server();
     p.Id = Packet_ServerIdEnum.Message;
     p.Message = new Packet_ServerMessage();
     p.Message.Message = text;
     return p;
 }
Esempio n. 42
0
 public static Packet_Server Identification(int assignedClientId, int mapSizeX, int mapSizeY, int mapSizeZ, string version)
 {
     Packet_Server p = new Packet_Server();
     p.Id = Packet_ServerIdEnum.ServerIdentification;
     p.Identification = new Packet_ServerIdentification();
     p.Identification.AssignedClientId = assignedClientId;
     p.Identification.MapSizeX = mapSizeX;
     p.Identification.MapSizeY = mapSizeY;
     p.Identification.MapSizeZ = mapSizeZ;
     p.Identification.ServerName = "Simple";
     p.Identification.MdProtocolVersion = version;
     return p;
 }
Esempio n. 43
0
 public static Packet_Server Chunk_(int x, int y, int z, int chunksize)
 {
     Packet_Server p = new Packet_Server();
     p.Id = Packet_ServerIdEnum.Chunk_;
     p.Chunk_ = new Packet_ServerChunk();
     p.Chunk_.X = x;
     p.Chunk_.Y = y;
     p.Chunk_.Z = z;
     p.Chunk_.SizeX = chunksize;
     p.Chunk_.SizeY = chunksize;
     p.Chunk_.SizeZ = chunksize;
     return p;
 }
Esempio n. 44
0
 public static Packet_Server ChunkPart(byte[] compressedChunkPart)
 {
     Packet_Server p = new Packet_Server();
     p.Id = Packet_ServerIdEnum.ChunkPart;
     p.ChunkPart = new Packet_ServerChunkPart();
     p.ChunkPart.CompressedChunkPart = compressedChunkPart;
     return p;
 }
Esempio n. 45
0
 internal static Packet_Server PlayerStats(int health, int maxHealth, int oxygen, int maxOxygen)
 {
     Packet_Server p = new Packet_Server();
     p.Id = Packet_ServerIdEnum.PlayerStats;
     p.PlayerStats = new Packet_ServerPlayerStats();
     p.PlayerStats.CurrentHealth = health;
     p.PlayerStats.MaxHealth = maxHealth;
     p.PlayerStats.CurrentOxygen = oxygen;
     p.PlayerStats.MaxOxygen = maxOxygen;
     return p;
 }
Esempio n. 46
0
 internal static Packet_Server AnswerQuery(Packet_ServerQueryAnswer answer)
 {
     Packet_Server p = new Packet_Server();
     p.Id = Packet_ServerIdEnum.QueryAnswer;
     p.QueryAnswer = answer;
     return p;
 }
Esempio n. 47
0
 internal static Packet_Server SetBlock(int x, int y, int z, int block)
 {
     Packet_Server p = new Packet_Server();
     p.Id = Packet_ServerIdEnum.SetBlock;
     p.SetBlock = new Packet_ServerSetBlock();
     p.SetBlock.X = x;
     p.SetBlock.Y = y;
     p.SetBlock.Z = z;
     p.SetBlock.BlockType = block;
     return p;
 }
Esempio n. 48
0
 internal static Packet_Server DisconnectPlayer(string disconnectReason)
 {
     Packet_Server p = new Packet_Server();
     p.Id = Packet_ServerIdEnum.DisconnectPlayer;
     p.DisconnectPlayer = new Packet_ServerDisconnectPlayer();
     p.DisconnectPlayer.DisconnectReason = disconnectReason;
     return p;
 }
Esempio n. 49
0
 public abstract void Handle(Game game, Packet_Server packet);
Esempio n. 50
0
 public override void Handle(Game game, Packet_Server packet)
 {
     Entity entity = game.entities[packet.EntitySpawn.Id];
     if (entity == null)
     {
         entity = new Entity();
     }
     ToClientEntity(game, packet.EntitySpawn.Entity_, entity, packet.EntitySpawn.Id != game.LocalPlayerId);
     game.entities[packet.EntitySpawn.Id] = entity;
     if (packet.EntitySpawn.Id == game.LocalPlayerId)
     {
         entity.networkPosition = null;
         game.player = entity;
         if (!game.spawned)
         {
             entity.scripts[entity.scriptsCount++] = new ScriptCharacterPhysics();
             game.MapLoaded();
             game.spawned = true;
         }
     }
 }
Esempio n. 51
0
    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.freemove = false;
                        game.controls.noclip = false;
                        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));
                    //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;
        }
    }
Esempio n. 52
0
 public static SendPacketAction Create(ServerSimple server_, int client_, Packet_Server packet_)
 {
     SendPacketAction a = new SendPacketAction();
     a.server = server_;
     a.client = client_;
     a.packet = packet_;
     return a;
 }
Esempio n. 53
0
 internal static Packet_Server EntityDespawn(int id)
 {
     Packet_Server p = new Packet_Server();
     p.Id = Packet_ServerIdEnum.EntityDespawn;
     p.EntityDespawn = new Packet_ServerEntityDespawn();
     p.EntityDespawn.Id = id;
     return p;
 }
Esempio n. 54
0
 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;
 }
Esempio n. 55
0
 internal void InvalidVersionAllow()
 {
     if (invalidVersionDrawMessage != null)
     {
         invalidVersionDrawMessage = null;
         ProcessServerIdentification(invalidVersionPacketIdentification);
         invalidVersionPacketIdentification = null;
     }
 }
Esempio n. 56
0
 internal static Packet_Server EntityPositionAndOrientation(int id, Packet_PositionAndOrientation positionAndOrientation)
 {
     Packet_Server p = new Packet_Server();
     p.Id = Packet_ServerIdEnum.EntityPosition;
     p.EntityPosition = new Packet_ServerEntityPositionAndOrientation();
     p.EntityPosition.Id = id;
     p.EntityPosition.PositionAndOrientation = positionAndOrientation;
     return p;
 }
Esempio n. 57
0
    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;
        }
    }
Esempio n. 58
0
    internal void ProcessServerIdentification(Packet_Server packet)
    {
        this.LocalPlayerId = packet.Identification.AssignedClientId;
        this.ServerInfo.connectdata = this.connectdata;
        this.ServerInfo.ServerName = packet.Identification.ServerName;
        this.ServerInfo.ServerMotd = packet.Identification.ServerMotd;
        this.d_TerrainChunkTesselator.ENABLE_TEXTURE_TILING = packet.Identification.RenderHint_ == RenderHintEnum.Fast;
        Packet_StringList requiredMd5 = packet.Identification.RequiredBlobMd5;
        Packet_StringList requiredName = packet.Identification.RequiredBlobName;
        ChatLog("[GAME] Processed server identification");
        int getCount = 0;
        if (requiredMd5 != null)
        {
            ChatLog(platform.StringFormat("[GAME] Server has {0} assets", platform.IntToString(requiredMd5.ItemsCount)));
            for (int i = 0; i < requiredMd5.ItemsCount; i++)
            {
                string md5 = requiredMd5.Items[i];

                //check if file with that content is already in cache
                if (platform.IsCached(md5))
                {
                    //File has been cached. load cached version.
                    Asset cachedAsset = platform.LoadAssetFromCache(md5);
                    string name;
                    if (requiredName != null)
                    {
                        name = requiredName.Items[i];
                    }
                    else // server older than 2014-07-13.
                    {
                        name = cachedAsset.name;
                    }
                    SetFile(name, cachedAsset.md5, cachedAsset.data, cachedAsset.dataLength);
                }
                else
                {
                    //Asset not present in cache
                    if (requiredName != null)
                    {
                        //If list of names is given (server > 2014-07-13) lookup if asset is already loaded
                        if (!HasAsset(md5, requiredName.Items[i]))
                        {
                            //Request asset from server if not already loaded
                            getAsset[getCount++] = md5;
                        }
                    }
                    else
                    {
                        //Server didn't send list of required asset names
                        getAsset[getCount++] = md5;
                    }
                }
            }
            ChatLog(platform.StringFormat("[GAME] Will download {0} missing assets", platform.IntToString(getCount)));
        }
        SendGameResolution();
        ChatLog("[GAME] Sent window resolution to server");
        sendResize = true;
        SendRequestBlob(getAsset, getCount);
        ChatLog("[GAME] Sent BLOB request");
        if (packet.Identification.MapSizeX != map.MapSizeX
            || packet.Identification.MapSizeY != map.MapSizeY
            || packet.Identification.MapSizeZ != map.MapSizeZ)
        {
            map.Reset(packet.Identification.MapSizeX,
                packet.Identification.MapSizeY,
                packet.Identification.MapSizeZ);
            d_Heightmap.Restart();
        }
        shadowssimple = packet.Identification.DisableShadows == 1 ? true : false;
        //maxdrawdistance = packet.Identification.PlayerAreaSize / 2;
        //if (maxdrawdistance == 0)
        //{
        //    maxdrawdistance = 128;
        //}
        maxdrawdistance = 256;
        ChatLog("[GAME] Map initialized");
    }
Esempio n. 59
0
    void ProcessInBackground(Packet_Server packet)
    {
        switch (packet.Id)
        {
        case Packet_ServerIdEnum.ChunkPart:
            byte[] arr       = packet.ChunkPart.CompressedChunkPart;
            int    arrLength = game.platform.ByteArrayLength(arr);  // todo
            for (int i = 0; i < arrLength; i++)
            {
                CurrentChunk[CurrentChunkCount++] = arr[i];
            }
            break;

        case Packet_ServerIdEnum.Chunk_:
        {
            Packet_ServerChunk p = packet.Chunk_;
            if (CurrentChunkCount != 0)
            {
                game.platform.GzipDecompress(CurrentChunk, CurrentChunkCount, decompressedchunk);
                {
                    int i = 0;
                    for (int zz = 0; zz < p.SizeZ; zz++)
                    {
                        for (int yy = 0; yy < p.SizeY; yy++)
                        {
                            for (int xx = 0; xx < p.SizeX; xx++)
                            {
                                int block = (decompressedchunk[i + 1] << 8) + decompressedchunk[i];
                                if (block < GlobalVar.MAX_BLOCKTYPES)
                                {
                                    receivedchunk[Index3d(xx, yy, zz, p.SizeX, p.SizeY)] = block;
                                }
                                i += 2;
                            }
                        }
                    }
                }
            }
            else
            {
                int size = p.SizeX * p.SizeY * p.SizeZ;
                for (int i = 0; i < size; i++)
                {
                    receivedchunk[i] = 0;
                }
            }
            {
                game.map.SetMapPortion(p.X, p.Y, p.Z, receivedchunk, p.SizeX, p.SizeY, p.SizeZ);
                for (int xx = 0; xx < 2; xx++)
                {
                    for (int yy = 0; yy < 2; yy++)
                    {
                        for (int zz = 0; zz < 2; zz++)
                        {
                            //d_Shadows.OnSetChunk(p.X + 16 * xx, p.Y + 16 * yy, p.Z + 16 * zz);//todo
                        }
                    }
                }
            }
            game.ReceivedMapLength += CurrentChunkCount;        // lengthPrefixLength + packetLength;
            CurrentChunkCount       = 0;
        }
        break;

        case Packet_ServerIdEnum.HeightmapChunk:
        {
            Packet_ServerHeightmapChunk p = packet.HeightmapChunk;
            game.platform.GzipDecompress(p.CompressedHeightmap, game.platform.ByteArrayLength(p.CompressedHeightmap), decompressedchunk);
            int[] decompressedchunk1 = Game.ByteArrayToUshortArray(decompressedchunk, p.SizeX * p.SizeY * 2);
            for (int xx = 0; xx < p.SizeX; xx++)
            {
                for (int yy = 0; yy < p.SizeY; yy++)
                {
                    int height = decompressedchunk1[MapUtilCi.Index2d(xx, yy, p.SizeX)];
                    game.d_Heightmap.SetBlock(p.X + xx, p.Y + yy, height);
                }
            }
        }
        break;
        }
    }
Esempio n. 60
0
 public override void Handle(Game game, Packet_Server packet)
 {
     mod.d_CraftingRecipes = packet.CraftingRecipes.CraftingRecipes;
     mod.d_CraftingRecipesCount = packet.CraftingRecipes.CraftingRecipesCount;
 }