예제 #1
0
    void ProcessPackets()
    {
        for (; ;)
        {
            NetIncomingMessage msg = server.ReadMessage();
            if (msg == null)
            {
                return;
            }
            switch (msg.Type)
            {
            case NetworkMessageType.Connect:
                ClientSimple c = new ClientSimple();
                c.MainSocket = server;
                c.Connection = msg.SenderConnection;
                c.chunksseen = new bool[(MapSizeX / ChunkSize) * (MapSizeY / ChunkSize)][];
                clients[0]   = c;
                clientsCount = 1;
                break;

            case NetworkMessageType.Data:
                byte[]        data   = msg.message;
                Packet_Client packet = new Packet_Client();
                Packet_ClientSerializer.DeserializeBuffer(data, msg.messageLength, packet);
                ProcessPacket(0, packet);
                break;

            case NetworkMessageType.Disconnect:
                break;
            }
        }
    }
예제 #2
0
    public static Packet_Client Reload()
    {
        Packet_Client p = new Packet_Client();

        p.Id     = Packet_ClientIdEnum.Reload;
        p.Reload = new Packet_ClientReload();
        return(p);
    }
예제 #3
0
    public static Packet_Client PingReply()
    {
        Packet_ClientPingReply p  = new Packet_ClientPingReply();
        Packet_Client          pp = new Packet_Client();

        pp.Id        = Packet_ClientIdEnum.PingReply;
        pp.PingReply = p;
        return(pp);
    }
예제 #4
0
 public static Packet_Client DialogClick(string widgetId, string[] textValues, int textValuesCount)
 {
     Packet_Client p = new Packet_Client();
     p.Id = Packet_ClientIdEnum.DialogClick;
     p.DialogClick_ = new Packet_ClientDialogClick();
     p.DialogClick_.WidgetId = widgetId;
     p.DialogClick_.SetTextBoxValue(textValues, textValuesCount, textValuesCount);
     return p;
 }
예제 #5
0
    public static Packet_Client Leave(int reason)
    {
        Packet_Client p = new Packet_Client();

        p.Id           = Packet_ClientIdEnum.Leave;
        p.Leave        = new Packet_ClientLeave();
        p.Leave.Reason = reason;
        return(p);
    }
예제 #6
0
    public static Packet_Client Oxygen(int currentOxygen)
    {
        Packet_Client packet = new Packet_Client();

        packet.Id     = Packet_ClientIdEnum.Oxygen;
        packet.Oxygen = new Packet_ClientOxygen();
        packet.Oxygen.CurrentOxygen = currentOxygen;
        return(packet);
    }
예제 #7
0
    public static Packet_Client ServerQuery()
    {
        Packet_ClientServerQuery p1 = new Packet_ClientServerQuery();
        Packet_Client            pp = new Packet_Client();

        pp.Id    = Packet_ClientIdEnum.ServerQuery;
        pp.Query = p1;
        return(pp);
    }
예제 #8
0
    public static Packet_Client SpecialKeyTabPlayerList()
    {
        Packet_Client p = new Packet_Client();

        p.Id               = Packet_ClientIdEnum.SpecialKey;
        p.SpecialKey_      = new Packet_ClientSpecialKey();
        p.SpecialKey_.Key_ = Packet_SpecialKeyEnum.TabPlayerList;
        return(p);
    }
예제 #9
0
 public static Packet_Client Chat(string s, int isTeamchat)
 {
     Packet_ClientMessage p = new Packet_ClientMessage();
     p.Message = s;
     p.IsTeamchat = isTeamchat;
     Packet_Client pp = new Packet_Client();
     pp.Id = Packet_ClientIdEnum.Message;
     pp.Message = p;
     return pp;
 }
예제 #10
0
    internal static Packet_Client HitEntity(int entityId)
    {
        Packet_Client p = new Packet_Client();

        p.Id = Packet_ClientIdEnum.EntityInteraction;
        p.EntityInteraction                 = new Packet_ClientEntityInteraction();
        p.EntityInteraction.EntityId        = entityId;
        p.EntityInteraction.InteractionType = Packet_EntityInteractionTypeEnum.Hit;
        return(p);
    }
예제 #11
0
 public static Packet_Client ActiveMaterialSlot(int ActiveMaterial)
 {
     Packet_Client p = new Packet_Client();
     {
         p.Id = Packet_ClientIdEnum.ActiveMaterialSlot;
         p.ActiveMaterialSlot = new Packet_ClientActiveMaterialSlot();
         p.ActiveMaterialSlot.ActiveMaterialSlot = ActiveMaterial;
     }
     return p;
 }
예제 #12
0
    public static Packet_Client DialogClick(string widgetId, string[] textValues, int textValuesCount)
    {
        Packet_Client p = new Packet_Client();

        p.Id                    = Packet_ClientIdEnum.DialogClick;
        p.DialogClick_          = new Packet_ClientDialogClick();
        p.DialogClick_.WidgetId = widgetId;
        p.DialogClick_.SetTextBoxValue(textValues, textValuesCount, textValuesCount);
        return(p);
    }
예제 #13
0
    public static Packet_Client Health(int currentHealth)
    {
        Packet_Client p = new Packet_Client();

        {
            p.Id     = Packet_ClientIdEnum.Health;
            p.Health = new Packet_ClientHealth();
            p.Health.CurrentHealth = currentHealth;
        }
        return(p);
    }
예제 #14
0
 public static Packet_Client Death(int reason, int sourcePlayer)
 {
     Packet_Client p = new Packet_Client();
     p.Id = Packet_ClientIdEnum.Death;
     p.Death = new Packet_ClientDeath();
     {
         p.Death.Reason = reason;
         p.Death.SourcePlayer = sourcePlayer;
     }
     return p;
 }
예제 #15
0
    public static Packet_Client SpecialKeyRespawn()
    {
        Packet_Client p = new Packet_Client();

        {
            p.Id               = Packet_ClientIdEnum.SpecialKey;
            p.SpecialKey_      = new Packet_ClientSpecialKey();
            p.SpecialKey_.Key_ = Packet_SpecialKeyEnum.Respawn;
        }
        return(p);
    }
예제 #16
0
    public static Packet_Client MonsterHit(int damage)
    {
        Packet_ClientHealth p = new Packet_ClientHealth();

        p.CurrentHealth = damage;
        Packet_Client packet = new Packet_Client();

        packet.Id     = Packet_ClientIdEnum.MonsterHit;
        packet.Health = p;
        return(packet);
    }
예제 #17
0
    public static Packet_Client ActiveMaterialSlot(int ActiveMaterial)
    {
        Packet_Client p = new Packet_Client();

        {
            p.Id = Packet_ClientIdEnum.ActiveMaterialSlot;
            p.ActiveMaterialSlot = new Packet_ClientActiveMaterialSlot();
            p.ActiveMaterialSlot.ActiveMaterialSlot = ActiveMaterial;
        }
        return(p);
    }
예제 #18
0
    public static Packet_Client SpecialKeySelectTeam()
    {
        Packet_Client p = new Packet_Client();

        {
            p.Id               = Packet_ClientIdEnum.SpecialKey;
            p.SpecialKey_      = new Packet_ClientSpecialKey();
            p.SpecialKey_.Key_ = Packet_SpecialKeyEnum.SelectTeam;
        }
        return(p);
    }
예제 #19
0
    public static Packet_Client Chat(string s, int isTeamchat)
    {
        Packet_ClientMessage p = new Packet_ClientMessage();

        p.Message    = s;
        p.IsTeamchat = isTeamchat;
        Packet_Client pp = new Packet_Client();

        pp.Id      = Packet_ClientIdEnum.Message;
        pp.Message = p;
        return(pp);
    }
예제 #20
0
    public static Packet_Client InventoryClick(Packet_InventoryPosition pos)
    {
        Packet_ClientInventoryAction p = new Packet_ClientInventoryAction();

        p.A      = pos;
        p.Action = Packet_InventoryActionTypeEnum.Click;
        Packet_Client pp = new Packet_Client();

        pp.Id = Packet_ClientIdEnum.InventoryAction;
        pp.InventoryAction = p;
        return(pp);
    }
예제 #21
0
 public static Packet_Client Craft(int x, int y, int z, int recipeId)
 {
     Packet_ClientCraft cmd = new Packet_ClientCraft();
     cmd.X = x;
     cmd.Y = y;
     cmd.Z = z;
     cmd.RecipeId = recipeId;
     Packet_Client p = new Packet_Client();
     p.Id = Packet_ClientIdEnum.Craft;
     p.Craft = cmd;
     return p;
 }
예제 #22
0
    public static Packet_Client MoveToInventory(Packet_InventoryPosition from)
    {
        Packet_ClientInventoryAction p = new Packet_ClientInventoryAction();

        p.A      = from;
        p.Action = Packet_InventoryActionTypeEnum.MoveToInventory;
        Packet_Client pp = new Packet_Client();

        pp.Id = Packet_ClientIdEnum.InventoryAction;
        pp.InventoryAction = p;
        return(pp);
    }
예제 #23
0
    public static Packet_Client Death(int reason, int sourcePlayer)
    {
        Packet_Client p = new Packet_Client();

        p.Id    = Packet_ClientIdEnum.Death;
        p.Death = new Packet_ClientDeath();
        {
            p.Death.Reason       = reason;
            p.Death.SourcePlayer = sourcePlayer;
        }
        return(p);
    }
예제 #24
0
    public static Packet_Client GameResolution(int width, int height)
    {
        Packet_ClientGameResolution p = new Packet_ClientGameResolution();

        p.Width  = width;
        p.Height = height;
        Packet_Client pp = new Packet_Client();

        pp.Id             = Packet_ClientIdEnum.GameResolution;
        pp.GameResolution = p;
        return(pp);
    }
예제 #25
0
    public bool CheckPacket(int clientId, Packet_Client packet)
    {
        if (!monitorClients.ContainsKey(clientId))
        {
            monitorClients.Add(clientId, new MonitorClient()
            {
                Id = clientId
            });
        }

        monitorClients[clientId].PacketsReceived++;
        if (monitorClients[clientId].PacketsReceived > config.MaxPackets)
        {
            server.Kick(server.ServerConsoleId, clientId, "Packet Overflow");
            return(false);
        }

        switch (packet.Id)
        {
        case Packet_ClientIdEnum.SetBlock:
        case Packet_ClientIdEnum.FillArea:
            if (monitorClients[clientId].SetBlockPunished())
            {
                // TODO: revert block at client
                return(false);
            }
            if (monitorClients[clientId].BlocksSet < config.MaxBlocks)
            {
                monitorClients[clientId].BlocksSet++;
                return(true);
            }
            // punish client
            return(this.ActionSetBlock(clientId));

        case Packet_ClientIdEnum.Message:
            if (monitorClients[clientId].MessagePunished())
            {
                server.SendMessage(clientId, server.language.ServerMonitorChatNotSent(), Server.MessageType.Error);
                return(false);
            }
            if (monitorClients[clientId].MessagesSent < config.MaxMessages)
            {
                monitorClients[clientId].MessagesSent++;
                return(true);
            }
            // punish client
            return(this.ActionMessage(clientId));

        default:
            return(true);
        }
    }
예제 #26
0
 public static Packet_Client CreateLoginPacket(GamePlatform platform, string username, string verificationKey)
 {
     Packet_ClientIdentification p = new Packet_ClientIdentification();
     {
         p.Username = username;
         p.MdProtocolVersion = platform.GetGameVersion();
         p.VerificationKey = verificationKey;
     }
     Packet_Client pp = new Packet_Client();
     pp.Id = Packet_ClientIdEnum.PlayerIdentification;
     pp.Identification = p;
     return pp;
 }
예제 #27
0
    public static Packet_Client WearItem(Packet_InventoryPosition from, Packet_InventoryPosition to)
    {
        Packet_ClientInventoryAction p = new Packet_ClientInventoryAction();

        p.A      = from;
        p.B      = to;
        p.Action = Packet_InventoryActionTypeEnum.WearItem;
        Packet_Client pp = new Packet_Client();

        pp.Id = Packet_ClientIdEnum.InventoryAction;
        pp.InventoryAction = p;
        return(pp);
    }
예제 #28
0
    public static Packet_Client CreateLoginPacket(GamePlatform platform, string username, string verificationKey)
    {
        Packet_ClientIdentification p = new Packet_ClientIdentification();
        {
            p.Username          = username;
            p.MdProtocolVersion = platform.GetGameVersion();
            p.VerificationKey   = verificationKey;
        }
        Packet_Client pp = new Packet_Client();

        pp.Id             = Packet_ClientIdEnum.PlayerIdentification;
        pp.Identification = p;
        return(pp);
    }
예제 #29
0
    public static Packet_Client Craft(int x, int y, int z, int recipeId)
    {
        Packet_ClientCraft cmd = new Packet_ClientCraft();

        cmd.X        = x;
        cmd.Y        = y;
        cmd.Z        = z;
        cmd.RecipeId = recipeId;
        Packet_Client p = new Packet_Client();

        p.Id    = Packet_ClientIdEnum.Craft;
        p.Craft = cmd;
        return(p);
    }
예제 #30
0
    public static Packet_Client RequestBlob(Game game, string[] required, int requiredCount)
    {
        Packet_ClientRequestBlob p = new Packet_ClientRequestBlob(); //{ RequestBlobMd5 = needed };

        if (GameVersionHelper.ServerVersionAtLeast(game.platform, game.serverGameVersion, 2014, 4, 13))
        {
            p.RequestedMd5 = new Packet_StringList();
            p.RequestedMd5.SetItems(required, requiredCount, requiredCount);
        }
        Packet_Client pp = new Packet_Client();

        pp.Id          = Packet_ClientIdEnum.RequestBlob;
        pp.RequestBlob = p;
        return(pp);
    }
예제 #31
0
    public bool CheckPacket(int clientId, Packet_Client packet)
    {
        if (!monitorClients.ContainsKey(clientId))
        {
            monitorClients.Add(clientId, new MonitorClient() { Id = clientId });
        }

        monitorClients[clientId].PacketsReceived++;
        if (monitorClients[clientId].PacketsReceived > config.MaxPackets)
        {
            server.Kick(server.ServerConsoleId, clientId, "Packet Overflow");
            return false;
        }

        switch (packet.Id)
        {
            case Packet_ClientIdEnum.SetBlock:
            case Packet_ClientIdEnum.FillArea:
                if (monitorClients[clientId].SetBlockPunished())
                {
                    // TODO: revert block at client
                    return false;
                }
                if (monitorClients[clientId].BlocksSet < config.MaxBlocks)
                {
                    monitorClients[clientId].BlocksSet++;
                    return true;
                }
                // punish client
                return this.ActionSetBlock(clientId);
            case Packet_ClientIdEnum.Message:
                if (monitorClients[clientId].MessagePunished())
                {
                    server.SendMessage(clientId, server.language.ServerMonitorChatNotSent(), Server.MessageType.Error);
                    return false;
                }
                if (monitorClients[clientId].MessagesSent < config.MaxMessages)
                {
                    monitorClients[clientId].MessagesSent++;
                    return true;
                }
                // punish client
                return this.ActionMessage(clientId);
            default:
                return true;
        }
    }
예제 #32
0
    void SendRequest(NetClient client)
    {
        //Create request packet
        Packet_Client pp = ClientPackets.ServerQuery();

        //Serialize packet
        CitoMemoryStream ms = new CitoMemoryStream();

        Packet_ClientSerializer.Serialize(ms, pp);
        byte[] data = ms.ToArray();

        //Send packet to server
        INetOutgoingMessage msg = new INetOutgoingMessage();

        msg.Write(data, ms.Length());
        client.SendMessage(msg, MyNetDeliveryMethod.ReliableOrdered);
    }
예제 #33
0
    public static Packet_Client SetBlock(int x, int y, int z, int mode, int type, int materialslot)
    {
        Packet_ClientSetBlock p = new Packet_ClientSetBlock();
        {
            p.X            = x;
            p.Y            = y;
            p.Z            = z;
            p.Mode         = mode;
            p.BlockType    = type;
            p.MaterialSlot = materialslot;
        }
        Packet_Client pp = new Packet_Client();

        pp.Id       = Packet_ClientIdEnum.SetBlock;
        pp.SetBlock = p;
        return(pp);
    }
예제 #34
0
    public static Packet_Client PositionAndOrientation(Game game, int playerId, float positionX, float positionY, float positionZ, float orientationX, float orientationY, float orientationZ, byte stance)
    {
        Packet_ClientPositionAndOrientation p = new Packet_ClientPositionAndOrientation();
        {
            p.PlayerId = playerId;
            p.X        = game.platform.FloatToInt(positionX * 32);
            p.Y        = game.platform.FloatToInt(positionY * 32);
            p.Z        = game.platform.FloatToInt(positionZ * 32);
            p.Heading  = game.platform.FloatToInt(Game.RadToAngle256(orientationY));
            p.Pitch    = game.platform.FloatToInt(Game.RadToAngle256(orientationX));
            p.Stance   = stance;
        }
        Packet_Client pp = new Packet_Client();

        pp.Id = Packet_ClientIdEnum.PositionandOrientation;
        pp.PositionAndOrientation = p;
        return(pp);
    }
예제 #35
0
    public static Packet_Client FillArea(int startx, int starty, int startz, int endx, int endy, int endz, int blockType, int ActiveMaterial)
    {
        Packet_ClientFillArea p = new Packet_ClientFillArea();
        {
            p.X1           = startx;
            p.Y1           = starty;
            p.Z1           = startz;
            p.X2           = endx;
            p.Y2           = endy;
            p.Z2           = endz;
            p.BlockType    = blockType;
            p.MaterialSlot = ActiveMaterial;
        }
        Packet_Client pp = new Packet_Client();

        pp.Id       = Packet_ClientIdEnum.FillArea;
        pp.FillArea = p;
        return(pp);
    }
예제 #36
0
 public static Packet_Client SetBlock(int x, int y, int z, int mode, int type, int materialslot)
 {
     Packet_ClientSetBlock p = new Packet_ClientSetBlock();
     {
         p.X = x;
         p.Y = y;
         p.Z = z;
         p.Mode = mode;
         p.BlockType = type;
         p.MaterialSlot = materialslot;
     }
     Packet_Client pp = new Packet_Client();
     pp.Id = Packet_ClientIdEnum.SetBlock;
     pp.SetBlock = p;
     return pp;
 }
예제 #37
0
 public static Packet_Client ServerQuery()
 {
     Packet_ClientServerQuery p1 = new Packet_ClientServerQuery();
     Packet_Client pp = new Packet_Client();
     pp.Id = Packet_ClientIdEnum.ServerQuery;
     pp.Query = p1;
     return pp;
 }
예제 #38
0
 public static Packet_Client RequestBlob(Game game, string[] required, int requiredCount)
 {
     Packet_ClientRequestBlob p = new Packet_ClientRequestBlob(); //{ RequestBlobMd5 = needed };
     if (GameVersionHelper.ServerVersionAtLeast(game.platform, game.serverGameVersion, 2014, 4, 13))
     {
         p.RequestedMd5 = new Packet_StringList();
         p.RequestedMd5.SetItems(required, requiredCount, requiredCount);
     }
     Packet_Client pp = new Packet_Client();
     pp.Id = Packet_ClientIdEnum.RequestBlob;
     pp.RequestBlob = p;
     return pp;
 }
예제 #39
0
 public static Packet_Client GameResolution(int width, int height)
 {
     Packet_ClientGameResolution p = new Packet_ClientGameResolution();
     p.Width = width;
     p.Height = height;
     Packet_Client pp = new Packet_Client();
     pp.Id = Packet_ClientIdEnum.GameResolution;
     pp.GameResolution = p;
     return pp;
 }
예제 #40
0
 internal static Packet_Client UseEntity(int entityId)
 {
     Packet_Client p = new Packet_Client();
     p.Id = Packet_ClientIdEnum.EntityInteraction;
     p.EntityInteraction = new Packet_ClientEntityInteraction();
     p.EntityInteraction.EntityId = entityId;
     p.EntityInteraction.InteractionType = Packet_EntityInteractionTypeEnum.Use;
     return p;
 }
예제 #41
0
 public static Packet_Client SpecialKeyTabPlayerList()
 {
     Packet_Client p = new Packet_Client();
     p.Id = Packet_ClientIdEnum.SpecialKey;
     p.SpecialKey_ = new Packet_ClientSpecialKey();
     p.SpecialKey_.Key_ = Packet_SpecialKeyEnum.TabPlayerList;
     return p;
 }
예제 #42
0
    internal void NextBullet(Game game, int bulletsshot)
    {
        float one    = 1;
        bool  left   = game.mouseLeft;
        bool  middle = game.mouseMiddle;
        bool  right  = game.mouseRight;

        bool IsNextShot = bulletsshot != 0;

        if (!game.leftpressedpicking)
        {
            if (game.mouseleftclick)
            {
                game.leftpressedpicking = true;
            }
            else
            {
                left = false;
            }
        }
        else
        {
            if (game.mouseleftdeclick)
            {
                game.leftpressedpicking = false;
                left = false;
            }
        }
        if (!left)
        {
            game.currentAttackedBlock = null;
        }

        Packet_Item item          = game.d_Inventory.RightHand[game.ActiveMaterial];
        bool        ispistol      = (item != null && game.blocktypes[item.BlockId].IsPistol);
        bool        ispistolshoot = ispistol && left;
        bool        isgrenade     = ispistol && game.blocktypes[item.BlockId].PistolType == Packet_PistolTypeEnum.Grenade;

        if (ispistol && isgrenade)
        {
            ispistolshoot = game.mouseleftdeclick;
        }
        //grenade cooking - TODO: fix instant explosion when closing ESC menu
        if (game.mouseleftclick)
        {
            game.grenadecookingstartMilliseconds = game.platform.TimeMillisecondsFromStart();
            if (ispistol && isgrenade)
            {
                if (game.blocktypes[item.BlockId].Sounds.ShootCount > 0)
                {
                    game.AudioPlay(game.platform.StringFormat("{0}.ogg", game.blocktypes[item.BlockId].Sounds.Shoot[0]));
                }
            }
        }
        float wait = ((one * (game.platform.TimeMillisecondsFromStart() - game.grenadecookingstartMilliseconds)) / 1000);

        if (isgrenade && left)
        {
            if (wait >= game.grenadetime && isgrenade && game.grenadecookingstartMilliseconds != 0)
            {
                ispistolshoot         = true;
                game.mouseleftdeclick = true;
            }
            else
            {
                return;
            }
        }
        else
        {
            game.grenadecookingstartMilliseconds = 0;
        }

        if (ispistol && game.mouserightclick && (game.platform.TimeMillisecondsFromStart() - game.lastironsightschangeMilliseconds) >= 500)
        {
            game.IronSights = !game.IronSights;
            game.lastironsightschangeMilliseconds = game.platform.TimeMillisecondsFromStart();
        }

        IntRef pick2count = new IntRef();
        Line3D pick       = new Line3D();

        GetPickingLine(game, pick, ispistolshoot);
        BlockPosSide[] pick2 = game.Pick(game.s, pick, pick2count);

        if (left)
        {
            game.handSetAttackDestroy = true;
        }
        else if (right)
        {
            game.handSetAttackBuild = true;
        }

        if (game.overheadcamera && pick2count.value > 0 && left)
        {
            //if not picked any object, and mouse button is pressed, then walk to destination.
            if (game.Follow == null)
            {
                //Only walk to destination when not following someone
                game.playerdestination = Vector3Ref.Create(pick2[0].blockPos[0], pick2[0].blockPos[1] + 1, pick2[0].blockPos[2]);
            }
        }
        bool pickdistanceok = (pick2count.value > 0); //&& (!ispistol);

        if (pickdistanceok)
        {
            if (game.Dist(pick2[0].blockPos[0] + one / 2, pick2[0].blockPos[1] + one / 2, pick2[0].blockPos[2] + one / 2,
                          pick.Start[0], pick.Start[1], pick.Start[2]) > CurrentPickDistance(game))
            {
                pickdistanceok = false;
            }
        }
        bool playertileempty = game.IsTileEmptyForPhysics(
            game.platform.FloatToInt(game.player.position.x),
            game.platform.FloatToInt(game.player.position.z),
            game.platform.FloatToInt(game.player.position.y + (one / 2)));
        bool playertileemptyclose = game.IsTileEmptyForPhysicsClose(
            game.platform.FloatToInt(game.player.position.x),
            game.platform.FloatToInt(game.player.position.z),
            game.platform.FloatToInt(game.player.position.y + (one / 2)));
        BlockPosSide pick0 = new BlockPosSide();

        if (pick2count.value > 0 &&
            ((pickdistanceok && (playertileempty || (playertileemptyclose))) ||
             game.overheadcamera)
            )
        {
            game.SelectedBlockPositionX = game.platform.FloatToInt(pick2[0].Current()[0]);
            game.SelectedBlockPositionY = game.platform.FloatToInt(pick2[0].Current()[1]);
            game.SelectedBlockPositionZ = game.platform.FloatToInt(pick2[0].Current()[2]);
            pick0 = pick2[0];
        }
        else
        {
            game.SelectedBlockPositionX = -1;
            game.SelectedBlockPositionY = -1;
            game.SelectedBlockPositionZ = -1;
            pick0.blockPos    = new float[3];
            pick0.blockPos[0] = -1;
            pick0.blockPos[1] = -1;
            pick0.blockPos[2] = -1;
        }
        PickEntity(game, pick, pick2, pick2count);
        if (game.cameratype == CameraType.Fpp || game.cameratype == CameraType.Tpp)
        {
            int ntileX = game.platform.FloatToInt(pick0.Current()[0]);
            int ntileY = game.platform.FloatToInt(pick0.Current()[1]);
            int ntileZ = game.platform.FloatToInt(pick0.Current()[2]);
            if (game.IsUsableBlock(game.map.GetBlock(ntileX, ntileZ, ntileY)))
            {
                game.currentAttackedBlock = Vector3IntRef.Create(ntileX, ntileZ, ntileY);
            }
        }
        if (game.GetFreeMouse())
        {
            if (pick2count.value > 0)
            {
                OnPick_(pick0);
            }
            return;
        }

        if ((one * (game.platform.TimeMillisecondsFromStart() - lastbuildMilliseconds) / 1000) >= BuildDelay(game) ||
            IsNextShot)
        {
            if (left && game.d_Inventory.RightHand[game.ActiveMaterial] == null)
            {
                game.SendPacketClient(ClientPackets.MonsterHit(game.platform.FloatToInt(2 + game.rnd.NextFloat() * 4)));
            }
            if (left && !fastclicking)
            {
                //todo animation
                fastclicking = false;
            }
            if ((left || right || middle) && (!isgrenade))
            {
                lastbuildMilliseconds = game.platform.TimeMillisecondsFromStart();
            }
            if (isgrenade && game.mouseleftdeclick)
            {
                lastbuildMilliseconds = game.platform.TimeMillisecondsFromStart();
            }
            if (game.reloadstartMilliseconds != 0)
            {
                PickingEnd(left, right, middle, ispistol);
                return;
            }
            if (ispistolshoot)
            {
                if ((!(game.LoadedAmmo[item.BlockId] > 0)) ||
                    (!(game.TotalAmmo[item.BlockId] > 0)))
                {
                    game.AudioPlay("Dry Fire Gun-SoundBible.com-2053652037.ogg");
                    PickingEnd(left, right, middle, ispistol);
                    return;
                }
            }
            if (ispistolshoot)
            {
                float toX = pick.End[0];
                float toY = pick.End[1];
                float toZ = pick.End[2];
                if (pick2count.value > 0)
                {
                    toX = pick2[0].blockPos[0];
                    toY = pick2[0].blockPos[1];
                    toZ = pick2[0].blockPos[2];
                }

                Packet_ClientShot shot = new Packet_ClientShot();
                shot.FromX     = game.SerializeFloat(pick.Start[0]);
                shot.FromY     = game.SerializeFloat(pick.Start[1]);
                shot.FromZ     = game.SerializeFloat(pick.Start[2]);
                shot.ToX       = game.SerializeFloat(toX);
                shot.ToY       = game.SerializeFloat(toY);
                shot.ToZ       = game.SerializeFloat(toZ);
                shot.HitPlayer = -1;

                for (int i = 0; i < game.entitiesCount; i++)
                {
                    if (game.entities[i] == null)
                    {
                        continue;
                    }
                    if (game.entities[i].drawModel == null)
                    {
                        continue;
                    }
                    Entity p_ = game.entities[i];
                    if (p_.networkPosition == null)
                    {
                        continue;
                    }
                    if (!p_.networkPosition.PositionLoaded)
                    {
                        continue;
                    }
                    float feetposX = p_.position.x;
                    float feetposY = p_.position.y;
                    float feetposZ = p_.position.z;
                    //var p = PlayerPositionSpawn;
                    Box3D bodybox  = new Box3D();
                    float headsize = (p_.drawModel.ModelHeight - p_.drawModel.eyeHeight) * 2; //0.4f;
                    float h        = p_.drawModel.ModelHeight - headsize;
                    float r        = one * 35 / 100;

                    bodybox.AddPoint(feetposX - r, feetposY + 0, feetposZ - r);
                    bodybox.AddPoint(feetposX - r, feetposY + 0, feetposZ + r);
                    bodybox.AddPoint(feetposX + r, feetposY + 0, feetposZ - r);
                    bodybox.AddPoint(feetposX + r, feetposY + 0, feetposZ + r);

                    bodybox.AddPoint(feetposX - r, feetposY + h, feetposZ - r);
                    bodybox.AddPoint(feetposX - r, feetposY + h, feetposZ + r);
                    bodybox.AddPoint(feetposX + r, feetposY + h, feetposZ - r);
                    bodybox.AddPoint(feetposX + r, feetposY + h, feetposZ + r);

                    Box3D headbox = new Box3D();

                    headbox.AddPoint(feetposX - r, feetposY + h, feetposZ - r);
                    headbox.AddPoint(feetposX - r, feetposY + h, feetposZ + r);
                    headbox.AddPoint(feetposX + r, feetposY + h, feetposZ - r);
                    headbox.AddPoint(feetposX + r, feetposY + h, feetposZ + r);

                    headbox.AddPoint(feetposX - r, feetposY + h + headsize, feetposZ - r);
                    headbox.AddPoint(feetposX - r, feetposY + h + headsize, feetposZ + r);
                    headbox.AddPoint(feetposX + r, feetposY + h + headsize, feetposZ - r);
                    headbox.AddPoint(feetposX + r, feetposY + h + headsize, feetposZ + r);

                    float[] p;
                    float   localeyeposX = game.EyesPosX();
                    float   localeyeposY = game.EyesPosY();
                    float   localeyeposZ = game.EyesPosZ();
                    p = Intersection.CheckLineBoxExact(pick, headbox);
                    if (p != null)
                    {
                        //do not allow to shoot through terrain
                        if (pick2count.value == 0 || (game.Dist(pick2[0].blockPos[0], pick2[0].blockPos[1], pick2[0].blockPos[2], localeyeposX, localeyeposY, localeyeposZ)
                                                      > game.Dist(p[0], p[1], p[2], localeyeposX, localeyeposY, localeyeposZ)))
                        {
                            if (!isgrenade)
                            {
                                Entity entity = new Entity();
                                Sprite sprite = new Sprite();
                                sprite.positionX = p[0];
                                sprite.positionY = p[1];
                                sprite.positionZ = p[2];
                                sprite.image     = "blood.png";
                                entity.sprite    = sprite;
                                entity.expires   = Expires.Create(one * 2 / 10);
                                game.EntityAddLocal(entity);
                            }
                            shot.HitPlayer = i;
                            shot.IsHitHead = 1;
                        }
                    }
                    else
                    {
                        p = Intersection.CheckLineBoxExact(pick, bodybox);
                        if (p != null)
                        {
                            //do not allow to shoot through terrain
                            if (pick2count.value == 0 || (game.Dist(pick2[0].blockPos[0], pick2[0].blockPos[1], pick2[0].blockPos[2], localeyeposX, localeyeposY, localeyeposZ)
                                                          > game.Dist(p[0], p[1], p[2], localeyeposX, localeyeposY, localeyeposZ)))
                            {
                                if (!isgrenade)
                                {
                                    Entity entity = new Entity();
                                    Sprite sprite = new Sprite();
                                    sprite.positionX = p[0];
                                    sprite.positionY = p[1];
                                    sprite.positionZ = p[2];
                                    sprite.image     = "blood.png";
                                    entity.sprite    = sprite;
                                    entity.expires   = Expires.Create(one * 2 / 10);
                                    game.EntityAddLocal(entity);
                                }
                                shot.HitPlayer = i;
                                shot.IsHitHead = 0;
                            }
                        }
                    }
                }
                shot.WeaponBlock = item.BlockId;
                game.LoadedAmmo[item.BlockId] = game.LoadedAmmo[item.BlockId] - 1;
                game.TotalAmmo[item.BlockId]  = game.TotalAmmo[item.BlockId] - 1;
                float projectilespeed = game.DeserializeFloat(game.blocktypes[item.BlockId].ProjectileSpeedFloat);
                if (projectilespeed == 0)
                {
                    {
                        Entity entity = game.CreateBulletEntity(
                            pick.Start[0], pick.Start[1], pick.Start[2],
                            toX, toY, toZ, 150);
                        game.EntityAddLocal(entity);
                    }
                }
                else
                {
                    float vX      = toX - pick.Start[0];
                    float vY      = toY - pick.Start[1];
                    float vZ      = toZ - pick.Start[2];
                    float vLength = game.Length(vX, vY, vZ);
                    vX /= vLength;
                    vY /= vLength;
                    vZ /= vLength;
                    vX *= projectilespeed;
                    vY *= projectilespeed;
                    vZ *= projectilespeed;
                    shot.ExplodesAfter = game.SerializeFloat(game.grenadetime - wait);

                    {
                        Entity grenadeEntity = new Entity();

                        Sprite sprite = new Sprite();
                        sprite.image          = "ChemicalGreen.png";
                        sprite.size           = 14;
                        sprite.animationcount = 0;
                        sprite.positionX      = pick.Start[0];
                        sprite.positionY      = pick.Start[1];
                        sprite.positionZ      = pick.Start[2];
                        grenadeEntity.sprite  = sprite;

                        Grenade_ projectile = new Grenade_();
                        projectile.velocityX    = vX;
                        projectile.velocityY    = vY;
                        projectile.velocityZ    = vZ;
                        projectile.block        = item.BlockId;
                        projectile.sourcePlayer = game.LocalPlayerId;

                        grenadeEntity.expires = Expires.Create(game.grenadetime - wait);

                        grenadeEntity.grenade = projectile;
                        game.EntityAddLocal(grenadeEntity);
                    }
                }
                Packet_Client packet = new Packet_Client();
                packet.Id   = Packet_ClientIdEnum.Shot;
                packet.Shot = shot;
                game.SendPacketClient(packet);

                if (game.blocktypes[item.BlockId].Sounds.ShootEndCount > 0)
                {
                    game.pistolcycle = game.rnd.Next() % game.blocktypes[item.BlockId].Sounds.ShootEndCount;
                    game.AudioPlay(game.platform.StringFormat("{0}.ogg", game.blocktypes[item.BlockId].Sounds.ShootEnd[game.pistolcycle]));
                }

                bulletsshot++;
                if (bulletsshot < game.DeserializeFloat(game.blocktypes[item.BlockId].BulletsPerShotFloat))
                {
                    NextBullet(game, bulletsshot);
                }

                //recoil
                game.player.position.rotx -= game.rnd.NextFloat() * game.CurrentRecoil();
                game.player.position.roty += game.rnd.NextFloat() * game.CurrentRecoil() * 2 - game.CurrentRecoil();

                PickingEnd(left, right, middle, ispistol);
                return;
            }
            if (ispistol && right)
            {
                PickingEnd(left, right, middle, ispistol);
                return;
            }
            if (pick2count.value > 0)
            {
                if (middle)
                {
                    int newtileX = game.platform.FloatToInt(pick0.Current()[0]);
                    int newtileY = game.platform.FloatToInt(pick0.Current()[1]);
                    int newtileZ = game.platform.FloatToInt(pick0.Current()[2]);
                    if (game.map.IsValidPos(newtileX, newtileZ, newtileY))
                    {
                        int  clonesource  = game.map.GetBlock(newtileX, newtileZ, newtileY);
                        int  clonesource2 = game.d_Data.WhenPlayerPlacesGetsConvertedTo()[clonesource];
                        bool gotoDone     = false;
                        //find this block in another right hand.
                        for (int i = 0; i < 10; i++)
                        {
                            if (game.d_Inventory.RightHand[i] != null &&
                                game.d_Inventory.RightHand[i].ItemClass == Packet_ItemClassEnum.Block &&
                                game.d_Inventory.RightHand[i].BlockId == clonesource2)
                            {
                                game.ActiveMaterial = i;
                                gotoDone            = true;
                            }
                        }
                        if (!gotoDone)
                        {
                            IntRef freehand = game.d_InventoryUtil.FreeHand(game.ActiveMaterial);
                            //find this block in inventory.
                            for (int i = 0; i < game.d_Inventory.ItemsCount; i++)
                            {
                                Packet_PositionItem k = game.d_Inventory.Items[i];
                                if (k == null)
                                {
                                    continue;
                                }
                                if (k.Value_.ItemClass == Packet_ItemClassEnum.Block &&
                                    k.Value_.BlockId == clonesource2)
                                {
                                    //free hand
                                    if (freehand != null)
                                    {
                                        game.WearItem(
                                            game.InventoryPositionMainArea(k.X, k.Y),
                                            game.InventoryPositionMaterialSelector(freehand.value));
                                        break;
                                    }
                                    //try to replace current slot
                                    if (game.d_Inventory.RightHand[game.ActiveMaterial] != null &&
                                        game.d_Inventory.RightHand[game.ActiveMaterial].ItemClass == Packet_ItemClassEnum.Block)
                                    {
                                        game.MoveToInventory(
                                            game.InventoryPositionMaterialSelector(game.ActiveMaterial));
                                        game.WearItem(
                                            game.InventoryPositionMainArea(k.X, k.Y),
                                            game.InventoryPositionMaterialSelector(game.ActiveMaterial));
                                    }
                                }
                            }
                        }
                        string[] sound = game.d_Data.CloneSound()[clonesource];
                        if (sound != null)            // && sound.Length > 0)
                        {
                            game.AudioPlay(sound[0]); //todo sound cycle
                        }
                    }
                }
                if (left || right)
                {
                    BlockPosSide tile = pick0;
                    int          newtileX;
                    int          newtileY;
                    int          newtileZ;
                    if (right)
                    {
                        newtileX = game.platform.FloatToInt(tile.Translated()[0]);
                        newtileY = game.platform.FloatToInt(tile.Translated()[1]);
                        newtileZ = game.platform.FloatToInt(tile.Translated()[2]);
                    }
                    else
                    {
                        newtileX = game.platform.FloatToInt(tile.Current()[0]);
                        newtileY = game.platform.FloatToInt(tile.Current()[1]);
                        newtileZ = game.platform.FloatToInt(tile.Current()[2]);
                    }
                    if (game.map.IsValidPos(newtileX, newtileZ, newtileY))
                    {
                        //Console.WriteLine(". newtile:" + newtile + " type: " + d_Map.GetBlock(newtileX, newtileZ, newtileY));
                        if (!(pick0.blockPos[0] == -1 &&
                              pick0.blockPos[1] == -1 &&
                              pick0.blockPos[2] == -1))
                        {
                            int blocktype;
                            if (left)
                            {
                                blocktype = game.map.GetBlock(newtileX, newtileZ, newtileY);
                            }
                            else
                            {
                                blocktype = ((game.BlockInHand() == null) ? 1 : game.BlockInHand().value);
                            }
                            if (left && blocktype == game.d_Data.BlockIdAdminium())
                            {
                                PickingEnd(left, right, middle, ispistol);
                                return;
                            }
                            string[] sound = left ? game.d_Data.BreakSound()[blocktype] : game.d_Data.BuildSound()[blocktype];
                            if (sound != null)            // && sound.Length > 0)
                            {
                                game.AudioPlay(sound[0]); //todo sound cycle
                            }
                        }
                        //normal attack
                        if (!right)
                        {
                            //attack
                            int posx = newtileX;
                            int posy = newtileZ;
                            int posz = newtileY;
                            game.currentAttackedBlock = Vector3IntRef.Create(posx, posy, posz);
                            if (!game.blockHealth.ContainsKey(posx, posy, posz))
                            {
                                game.blockHealth.Set(posx, posy, posz, game.GetCurrentBlockHealth(posx, posy, posz));
                            }
                            game.blockHealth.Set(posx, posy, posz, game.blockHealth.Get(posx, posy, posz) - game.WeaponAttackStrength());
                            float health = game.GetCurrentBlockHealth(posx, posy, posz);
                            if (health <= 0)
                            {
                                if (game.currentAttackedBlock != null)
                                {
                                    game.blockHealth.Remove(posx, posy, posz);
                                }
                                game.currentAttackedBlock = null;
                                OnPick(game, game.platform.FloatToInt(newtileX), game.platform.FloatToInt(newtileZ), game.platform.FloatToInt(newtileY),
                                       game.platform.FloatToInt(tile.Current()[0]), game.platform.FloatToInt(tile.Current()[2]), game.platform.FloatToInt(tile.Current()[1]),
                                       tile.collisionPos,
                                       right);
                            }
                            PickingEnd(left, right, middle, ispistol);
                            return;
                        }
                        if (!right)
                        {
                            game.particleEffectBlockBreak.StartParticleEffect(newtileX, newtileY, newtileZ);//must be before deletion - gets ground type.
                        }
                        if (!game.map.IsValidPos(newtileX, newtileZ, newtileY))
                        {
                            game.platform.ThrowException("Error in picking - NextBullet()");
                        }
                        OnPick(game, game.platform.FloatToInt(newtileX), game.platform.FloatToInt(newtileZ), game.platform.FloatToInt(newtileY),
                               game.platform.FloatToInt(tile.Current()[0]), game.platform.FloatToInt(tile.Current()[2]), game.platform.FloatToInt(tile.Current()[1]),
                               tile.collisionPos,
                               right);
                        //network.SendSetBlock(new Vector3((int)newtile.X, (int)newtile.Z, (int)newtile.Y),
                        //    right ? BlockSetMode.Create : BlockSetMode.Destroy, (byte)MaterialSlots[activematerial]);
                    }
                }
            }
        }
        PickingEnd(left, right, middle, ispistol);
    }
예제 #43
0
 public static Packet_Client MonsterHit(int damage)
 {
     Packet_ClientHealth p = new Packet_ClientHealth();
     p.CurrentHealth = damage;
     Packet_Client packet = new Packet_Client();
     packet.Id = Packet_ClientIdEnum.MonsterHit;
     packet.Health = p;
     return packet;
 }
예제 #44
0
 public static Packet_Client Leave(int reason)
 {
     Packet_Client p = new Packet_Client();
     p.Id = Packet_ClientIdEnum.Leave;
     p.Leave = new Packet_ClientLeave();
     p.Leave.Reason = reason;
     return p;
 }
예제 #45
0
 public static Packet_Client InventoryClick(Packet_InventoryPosition pos)
 {
     Packet_ClientInventoryAction p = new Packet_ClientInventoryAction();
     p.A = pos;
     p.Action = Packet_InventoryActionTypeEnum.Click;
     Packet_Client pp = new Packet_Client();
     pp.Id = Packet_ClientIdEnum.InventoryAction;
     pp.InventoryAction = p;
     return pp;
 }
예제 #46
0
 public static Packet_Client Health(int currentHealth)
 {
     Packet_Client p = new Packet_Client();
     {
         p.Id = Packet_ClientIdEnum.Health;
         p.Health = new Packet_ClientHealth();
         p.Health.CurrentHealth = currentHealth;
     }
     return p;
 }
예제 #47
0
 public byte[] Serialize(Packet_Client packet, IntRef retLength)
 {
     CitoMemoryStream ms = new CitoMemoryStream();
     Packet_ClientSerializer.Serialize(ms, packet);
     byte[] data = ms.ToArray();
     retLength.value = ms.Length();
     return data;
 }
예제 #48
0
 public static Packet_Client Oxygen(int currentOxygen)
 {
     Packet_Client packet = new Packet_Client();
     packet.Id = Packet_ClientIdEnum.Oxygen;
     packet.Oxygen = new Packet_ClientOxygen();
     packet.Oxygen.CurrentOxygen = currentOxygen;
     return packet;
 }
예제 #49
0
 public static Packet_Client SpecialKeySetSpawn()
 {
     Packet_Client p = new Packet_Client();
     {
         p.Id = Packet_ClientIdEnum.SpecialKey;
         p.SpecialKey_ = new Packet_ClientSpecialKey();
         p.SpecialKey_.Key_ = Packet_SpecialKeyEnum.SetSpawn;
     }
     return p;
 }
예제 #50
0
 public static Packet_Client PingReply()
 {
     Packet_ClientPingReply p = new Packet_ClientPingReply();
     Packet_Client pp = new Packet_Client();
     pp.Id = Packet_ClientIdEnum.PingReply;
     pp.PingReply = p;
     return pp;
 }
예제 #51
0
 public static Packet_Client WearItem(Packet_InventoryPosition from, Packet_InventoryPosition to)
 {
     Packet_ClientInventoryAction p = new Packet_ClientInventoryAction();
     p.A = from;
     p.B = to;
     p.Action = Packet_InventoryActionTypeEnum.WearItem;
     Packet_Client pp = new Packet_Client();
     pp.Id = Packet_ClientIdEnum.InventoryAction;
     pp.InventoryAction = p;
     return pp;
 }
예제 #52
0
 public static Packet_Client PositionAndOrientation(Game game, int playerId, float positionX, float positionY, float positionZ, float orientationX, float orientationY, float orientationZ, byte stance)
 {
     Packet_ClientPositionAndOrientation p = new Packet_ClientPositionAndOrientation();
     {
         p.PlayerId = playerId;
         p.X = game.platform.FloatToInt(positionX * 32);
         p.Y = game.platform.FloatToInt(positionY * 32);
         p.Z = game.platform.FloatToInt(positionZ * 32);
         p.Heading = game.platform.FloatToInt(Game.RadToAngle256(orientationY));
         p.Pitch = game.platform.FloatToInt(Game.RadToAngle256(orientationX));
         p.Stance = stance;
     }
     Packet_Client pp = new Packet_Client();
     pp.Id = Packet_ClientIdEnum.PositionandOrientation;
     pp.PositionAndOrientation = p;
     return pp;
 }
예제 #53
0
 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;
     }
 }
예제 #54
0
 public static Packet_Client Reload()
 {
     Packet_Client p = new Packet_Client();
     p.Id = Packet_ClientIdEnum.Reload;
     p.Reload = new Packet_ClientReload();
     return p;
 }
예제 #55
0
 public static Packet_Client MoveToInventory(Packet_InventoryPosition from)
 {
     Packet_ClientInventoryAction p = new Packet_ClientInventoryAction();
     p.A = from;
     p.Action = Packet_InventoryActionTypeEnum.MoveToInventory;
     Packet_Client pp = new Packet_Client();
     pp.Id = Packet_ClientIdEnum.InventoryAction;
     pp.InventoryAction = p;
     return pp;
 }
예제 #56
0
    internal void NextBullet(Game game, int bulletsshot)
    {
        float one = 1;
        bool left = game.mouseLeft;
        bool middle = game.mouseMiddle;
        bool right = game.mouseRight;

        bool IsNextShot = bulletsshot != 0;

        if (!game.leftpressedpicking)
        {
            if (game.mouseleftclick)
            {
                game.leftpressedpicking = true;
            }
            else
            {
                left = false;
            }
        }
        else
        {
            if (game.mouseleftdeclick)
            {
                game.leftpressedpicking = false;
                left = false;
            }
        }
        if (!left)
        {
            game.currentAttackedBlock = null;
        }

        Packet_Item item = game.d_Inventory.RightHand[game.ActiveMaterial];
        bool ispistol = (item != null && game.blocktypes[item.BlockId].IsPistol);
        bool ispistolshoot = ispistol && left;
        bool isgrenade = ispistol && game.blocktypes[item.BlockId].PistolType == Packet_PistolTypeEnum.Grenade;
        if (ispistol && isgrenade)
        {
            ispistolshoot = game.mouseleftdeclick;
        }
        //grenade cooking - TODO: fix instant explosion when closing ESC menu
        if (game.mouseleftclick)
        {
            game.grenadecookingstartMilliseconds = game.platform.TimeMillisecondsFromStart();
            if (ispistol && isgrenade)
            {
                if (game.blocktypes[item.BlockId].Sounds.ShootCount > 0)
                {
                    game.AudioPlay(game.platform.StringFormat("{0}.ogg", game.blocktypes[item.BlockId].Sounds.Shoot[0]));
                }
            }
        }
        float wait = ((one * (game.platform.TimeMillisecondsFromStart() - game.grenadecookingstartMilliseconds)) / 1000);
        if (isgrenade && left)
        {
            if (wait >= game.grenadetime && isgrenade && game.grenadecookingstartMilliseconds != 0)
            {
                ispistolshoot = true;
                game.mouseleftdeclick = true;
            }
            else
            {
                return;
            }
        }
        else
        {
            game.grenadecookingstartMilliseconds = 0;
        }

        if (ispistol && game.mouserightclick && (game.platform.TimeMillisecondsFromStart() - game.lastironsightschangeMilliseconds) >= 500)
        {
            game.IronSights = !game.IronSights;
            game.lastironsightschangeMilliseconds = game.platform.TimeMillisecondsFromStart();
        }

        IntRef pick2count = new IntRef();
        Line3D pick = new Line3D();
        GetPickingLine(game, pick, ispistolshoot);
        BlockPosSide[] pick2 = game.Pick(game.s, pick, pick2count);

        if (left)
        {
            game.handSetAttackDestroy = true;
        }
        else if (right)
        {
            game.handSetAttackBuild = true;
        }

        if (game.overheadcamera && pick2count.value > 0 && left)
        {
            //if not picked any object, and mouse button is pressed, then walk to destination.
            if (game.Follow == null)
            {
                //Only walk to destination when not following someone
                game.playerdestination = Vector3Ref.Create(pick2[0].blockPos[0], pick2[0].blockPos[1] + 1, pick2[0].blockPos[2]);
            }
        }
        bool pickdistanceok = (pick2count.value > 0); //&& (!ispistol);
        if (pickdistanceok)
        {
            if (game.Dist(pick2[0].blockPos[0] + one / 2, pick2[0].blockPos[1] + one / 2, pick2[0].blockPos[2] + one / 2,
                pick.Start[0], pick.Start[1], pick.Start[2]) > CurrentPickDistance(game))
            {
                pickdistanceok = false;
            }
        }
        bool playertileempty = game.IsTileEmptyForPhysics(
                  game.platform.FloatToInt(game.player.position.x),
                  game.platform.FloatToInt(game.player.position.z),
                  game.platform.FloatToInt(game.player.position.y + (one / 2)));
        bool playertileemptyclose = game.IsTileEmptyForPhysicsClose(
                  game.platform.FloatToInt(game.player.position.x),
                  game.platform.FloatToInt(game.player.position.z),
                  game.platform.FloatToInt(game.player.position.y + (one / 2)));
        BlockPosSide pick0 = new BlockPosSide();
        if (pick2count.value > 0 &&
            ((pickdistanceok && (playertileempty || (playertileemptyclose)))
            || game.overheadcamera)
            )
        {
            game.SelectedBlockPositionX = game.platform.FloatToInt(pick2[0].Current()[0]);
            game.SelectedBlockPositionY = game.platform.FloatToInt(pick2[0].Current()[1]);
            game.SelectedBlockPositionZ = game.platform.FloatToInt(pick2[0].Current()[2]);
            pick0 = pick2[0];
        }
        else
        {
            game.SelectedBlockPositionX = -1;
            game.SelectedBlockPositionY = -1;
            game.SelectedBlockPositionZ = -1;
            pick0.blockPos = new float[3];
            pick0.blockPos[0] = -1;
            pick0.blockPos[1] = -1;
            pick0.blockPos[2] = -1;
        }
        PickEntity(game, pick, pick2, pick2count);
        if (game.cameratype == CameraType.Fpp || game.cameratype == CameraType.Tpp)
        {
            int ntileX = game.platform.FloatToInt(pick0.Current()[0]);
            int ntileY = game.platform.FloatToInt(pick0.Current()[1]);
            int ntileZ = game.platform.FloatToInt(pick0.Current()[2]);
            if (game.IsUsableBlock(game.map.GetBlock(ntileX, ntileZ, ntileY)))
            {
                game.currentAttackedBlock = Vector3IntRef.Create(ntileX, ntileZ, ntileY);
            }
        }
        if (game.GetFreeMouse())
        {
            if (pick2count.value > 0)
            {
                OnPick_(pick0);
            }
            return;
        }

        if ((one * (game.platform.TimeMillisecondsFromStart() - lastbuildMilliseconds) / 1000) >= BuildDelay(game)
            || IsNextShot)
        {
            if (left && game.d_Inventory.RightHand[game.ActiveMaterial] == null)
            {
                game.SendPacketClient(ClientPackets.MonsterHit(game.platform.FloatToInt(2 + game.rnd.NextFloat() * 4)));
            }
            if (left && !fastclicking)
            {
                //todo animation
                fastclicking = false;
            }
            if ((left || right || middle) && (!isgrenade))
            {
                lastbuildMilliseconds = game.platform.TimeMillisecondsFromStart();
            }
            if (isgrenade && game.mouseleftdeclick)
            {
                lastbuildMilliseconds = game.platform.TimeMillisecondsFromStart();
            }
            if (game.reloadstartMilliseconds != 0)
            {
                PickingEnd(left, right, middle, ispistol);
                return;
            }
            if (ispistolshoot)
            {
                if ((!(game.LoadedAmmo[item.BlockId] > 0))
                    || (!(game.TotalAmmo[item.BlockId] > 0)))
                {
                    game.AudioPlay("Dry Fire Gun-SoundBible.com-2053652037.ogg");
                    PickingEnd(left, right, middle, ispistol);
                    return;
                }
            }
            if (ispistolshoot)
            {
                float toX = pick.End[0];
                float toY = pick.End[1];
                float toZ = pick.End[2];
                if (pick2count.value > 0)
                {
                    toX = pick2[0].blockPos[0];
                    toY = pick2[0].blockPos[1];
                    toZ = pick2[0].blockPos[2];
                }

                Packet_ClientShot shot = new Packet_ClientShot();
                shot.FromX = game.SerializeFloat(pick.Start[0]);
                shot.FromY = game.SerializeFloat(pick.Start[1]);
                shot.FromZ = game.SerializeFloat(pick.Start[2]);
                shot.ToX = game.SerializeFloat(toX);
                shot.ToY = game.SerializeFloat(toY);
                shot.ToZ = game.SerializeFloat(toZ);
                shot.HitPlayer = -1;

                for (int i = 0; i < game.entitiesCount; i++)
                {
                    if (game.entities[i] == null)
                    {
                        continue;
                    }
                    if (game.entities[i].drawModel == null)
                    {
                        continue;
                    }
                    Entity p_ = game.entities[i];
                    if (p_.networkPosition == null)
                    {
                        continue;
                    }
                    if (!p_.networkPosition.PositionLoaded)
                    {
                        continue;
                    }
                    float feetposX = p_.position.x;
                    float feetposY = p_.position.y;
                    float feetposZ = p_.position.z;
                    //var p = PlayerPositionSpawn;
                    Box3D bodybox = new Box3D();
                    float headsize = (p_.drawModel.ModelHeight - p_.drawModel.eyeHeight) * 2; //0.4f;
                    float h = p_.drawModel.ModelHeight - headsize;
                    float r = one * 35 / 100;

                    bodybox.AddPoint(feetposX - r, feetposY + 0, feetposZ - r);
                    bodybox.AddPoint(feetposX - r, feetposY + 0, feetposZ + r);
                    bodybox.AddPoint(feetposX + r, feetposY + 0, feetposZ - r);
                    bodybox.AddPoint(feetposX + r, feetposY + 0, feetposZ + r);

                    bodybox.AddPoint(feetposX - r, feetposY + h, feetposZ - r);
                    bodybox.AddPoint(feetposX - r, feetposY + h, feetposZ + r);
                    bodybox.AddPoint(feetposX + r, feetposY + h, feetposZ - r);
                    bodybox.AddPoint(feetposX + r, feetposY + h, feetposZ + r);

                    Box3D headbox = new Box3D();

                    headbox.AddPoint(feetposX - r, feetposY + h, feetposZ - r);
                    headbox.AddPoint(feetposX - r, feetposY + h, feetposZ + r);
                    headbox.AddPoint(feetposX + r, feetposY + h, feetposZ - r);
                    headbox.AddPoint(feetposX + r, feetposY + h, feetposZ + r);

                    headbox.AddPoint(feetposX - r, feetposY + h + headsize, feetposZ - r);
                    headbox.AddPoint(feetposX - r, feetposY + h + headsize, feetposZ + r);
                    headbox.AddPoint(feetposX + r, feetposY + h + headsize, feetposZ - r);
                    headbox.AddPoint(feetposX + r, feetposY + h + headsize, feetposZ + r);

                    float[] p;
                    float localeyeposX = game.EyesPosX();
                    float localeyeposY = game.EyesPosY();
                    float localeyeposZ = game.EyesPosZ();
                    p = Intersection.CheckLineBoxExact(pick, headbox);
                    if (p != null)
                    {
                        //do not allow to shoot through terrain
                        if (pick2count.value == 0 || (game.Dist(pick2[0].blockPos[0], pick2[0].blockPos[1], pick2[0].blockPos[2], localeyeposX, localeyeposY, localeyeposZ)
                            > game.Dist(p[0], p[1], p[2], localeyeposX, localeyeposY, localeyeposZ)))
                        {
                            if (!isgrenade)
                            {
                                Entity entity = new Entity();
                                Sprite sprite = new Sprite();
                                sprite.positionX = p[0];
                                sprite.positionY = p[1];
                                sprite.positionZ = p[2];
                                sprite.image = "blood.png";
                                entity.sprite = sprite;
                                entity.expires = Expires.Create(one * 2 / 10);
                                game.EntityAddLocal(entity);
                            }
                            shot.HitPlayer = i;
                            shot.IsHitHead = 1;
                        }
                    }
                    else
                    {
                        p = Intersection.CheckLineBoxExact(pick, bodybox);
                        if (p != null)
                        {
                            //do not allow to shoot through terrain
                            if (pick2count.value == 0 || (game.Dist(pick2[0].blockPos[0], pick2[0].blockPos[1], pick2[0].blockPos[2], localeyeposX, localeyeposY, localeyeposZ)
                                > game.Dist(p[0], p[1], p[2], localeyeposX, localeyeposY, localeyeposZ)))
                            {
                                if (!isgrenade)
                                {
                                    Entity entity = new Entity();
                                    Sprite sprite = new Sprite();
                                    sprite.positionX = p[0];
                                    sprite.positionY = p[1];
                                    sprite.positionZ = p[2];
                                    sprite.image = "blood.png";
                                    entity.sprite = sprite;
                                    entity.expires = Expires.Create(one * 2 / 10);
                                    game.EntityAddLocal(entity);
                                }
                                shot.HitPlayer = i;
                                shot.IsHitHead = 0;
                            }
                        }
                    }
                }
                shot.WeaponBlock = item.BlockId;
                game.LoadedAmmo[item.BlockId] = game.LoadedAmmo[item.BlockId] - 1;
                game.TotalAmmo[item.BlockId] = game.TotalAmmo[item.BlockId] - 1;
                float projectilespeed = game.DeserializeFloat(game.blocktypes[item.BlockId].ProjectileSpeedFloat);
                if (projectilespeed == 0)
                {
                    {
                        Entity entity = game.CreateBulletEntity(
                          pick.Start[0], pick.Start[1], pick.Start[2],
                          toX, toY, toZ, 150);
                        game.EntityAddLocal(entity);
                    }
                }
                else
                {
                    float vX = toX - pick.Start[0];
                    float vY = toY - pick.Start[1];
                    float vZ = toZ - pick.Start[2];
                    float vLength = game.Length(vX, vY, vZ);
                    vX /= vLength;
                    vY /= vLength;
                    vZ /= vLength;
                    vX *= projectilespeed;
                    vY *= projectilespeed;
                    vZ *= projectilespeed;
                    shot.ExplodesAfter = game.SerializeFloat(game.grenadetime - wait);

                    {
                        Entity grenadeEntity = new Entity();

                        Sprite sprite = new Sprite();
                        sprite.image = "ChemicalGreen.png";
                        sprite.size = 14;
                        sprite.animationcount = 0;
                        sprite.positionX = pick.Start[0];
                        sprite.positionY = pick.Start[1];
                        sprite.positionZ = pick.Start[2];
                        grenadeEntity.sprite = sprite;

                        Grenade_ projectile = new Grenade_();
                        projectile.velocityX = vX;
                        projectile.velocityY = vY;
                        projectile.velocityZ = vZ;
                        projectile.block = item.BlockId;
                        projectile.sourcePlayer = game.LocalPlayerId;

                        grenadeEntity.expires = Expires.Create(game.grenadetime - wait);

                        grenadeEntity.grenade = projectile;
                        game.EntityAddLocal(grenadeEntity);
                    }
                }
                Packet_Client packet = new Packet_Client();
                packet.Id = Packet_ClientIdEnum.Shot;
                packet.Shot = shot;
                game.SendPacketClient(packet);

                if (game.blocktypes[item.BlockId].Sounds.ShootEndCount > 0)
                {
                    game.pistolcycle = game.rnd.Next() % game.blocktypes[item.BlockId].Sounds.ShootEndCount;
                    game.AudioPlay(game.platform.StringFormat("{0}.ogg", game.blocktypes[item.BlockId].Sounds.ShootEnd[game.pistolcycle]));
                }

                bulletsshot++;
                if (bulletsshot < game.DeserializeFloat(game.blocktypes[item.BlockId].BulletsPerShotFloat))
                {
                    NextBullet(game, bulletsshot);
                }

                //recoil
                game.player.position.rotx -= game.rnd.NextFloat() * game.CurrentRecoil();
                game.player.position.roty += game.rnd.NextFloat() * game.CurrentRecoil() * 2 - game.CurrentRecoil();

                PickingEnd(left, right, middle, ispistol);
                return;
            }
            if (ispistol && right)
            {
                PickingEnd(left, right, middle, ispistol);
                return;
            }
            if (pick2count.value > 0)
            {
                if (middle)
                {
                    int newtileX = game.platform.FloatToInt(pick0.Current()[0]);
                    int newtileY = game.platform.FloatToInt(pick0.Current()[1]);
                    int newtileZ = game.platform.FloatToInt(pick0.Current()[2]);
                    if (game.map.IsValidPos(newtileX, newtileZ, newtileY))
                    {
                        int clonesource = game.map.GetBlock(newtileX, newtileZ, newtileY);
                        int clonesource2 = game.d_Data.WhenPlayerPlacesGetsConvertedTo()[clonesource];
                        bool gotoDone = false;
                        //find this block in another right hand.
                        for (int i = 0; i < 10; i++)
                        {
                            if (game.d_Inventory.RightHand[i] != null
                                && game.d_Inventory.RightHand[i].ItemClass == Packet_ItemClassEnum.Block
                                && game.d_Inventory.RightHand[i].BlockId == clonesource2)
                            {
                                game.ActiveMaterial = i;
                                gotoDone = true;
                            }
                        }
                        if (!gotoDone)
                        {
                            IntRef freehand = game.d_InventoryUtil.FreeHand(game.ActiveMaterial);
                            //find this block in inventory.
                            for (int i = 0; i < game.d_Inventory.ItemsCount; i++)
                            {
                                Packet_PositionItem k = game.d_Inventory.Items[i];
                                if (k == null)
                                {
                                    continue;
                                }
                                if (k.Value_.ItemClass == Packet_ItemClassEnum.Block
                                    && k.Value_.BlockId == clonesource2)
                                {
                                    //free hand
                                    if (freehand != null)
                                    {
                                        game.WearItem(
                                            game.InventoryPositionMainArea(k.X, k.Y),
                                            game.InventoryPositionMaterialSelector(freehand.value));
                                        break;
                                    }
                                    //try to replace current slot
                                    if (game.d_Inventory.RightHand[game.ActiveMaterial] != null
                                        && game.d_Inventory.RightHand[game.ActiveMaterial].ItemClass == Packet_ItemClassEnum.Block)
                                    {
                                        game.MoveToInventory(
                                            game.InventoryPositionMaterialSelector(game.ActiveMaterial));
                                        game.WearItem(
                                            game.InventoryPositionMainArea(k.X, k.Y),
                                            game.InventoryPositionMaterialSelector(game.ActiveMaterial));
                                    }
                                }
                            }
                        }
                        string[] sound = game.d_Data.CloneSound()[clonesource];
                        if (sound != null) // && sound.Length > 0)
                        {
                            game.AudioPlay(sound[0]); //todo sound cycle
                        }
                    }
                }
                if (left || right)
                {
                    BlockPosSide tile = pick0;
                    int newtileX;
                    int newtileY;
                    int newtileZ;
                    if (right)
                    {
                        newtileX = game.platform.FloatToInt(tile.Translated()[0]);
                        newtileY = game.platform.FloatToInt(tile.Translated()[1]);
                        newtileZ = game.platform.FloatToInt(tile.Translated()[2]);
                    }
                    else
                    {
                        newtileX = game.platform.FloatToInt(tile.Current()[0]);
                        newtileY = game.platform.FloatToInt(tile.Current()[1]);
                        newtileZ = game.platform.FloatToInt(tile.Current()[2]);
                    }
                    if (game.map.IsValidPos(newtileX, newtileZ, newtileY))
                    {
                        //Console.WriteLine(". newtile:" + newtile + " type: " + d_Map.GetBlock(newtileX, newtileZ, newtileY));
                        if (!(pick0.blockPos[0] == -1
                             && pick0.blockPos[1] == -1
                            && pick0.blockPos[2] == -1))
                        {
                            int blocktype;
                            if (left) { blocktype = game.map.GetBlock(newtileX, newtileZ, newtileY); }
                            else { blocktype = ((game.BlockInHand() == null) ? 1 : game.BlockInHand().value); }
                            if (left && blocktype == game.d_Data.BlockIdAdminium())
                            {
                                PickingEnd(left, right, middle, ispistol);
                                return;
                            }
                            string[] sound = left ? game.d_Data.BreakSound()[blocktype] : game.d_Data.BuildSound()[blocktype];
                            if (sound != null) // && sound.Length > 0)
                            {
                                game.AudioPlay(sound[0]); //todo sound cycle
                            }
                        }
                        //normal attack
                        if (!right)
                        {
                            //attack
                            int posx = newtileX;
                            int posy = newtileZ;
                            int posz = newtileY;
                            game.currentAttackedBlock = Vector3IntRef.Create(posx, posy, posz);
                            if (!game.blockHealth.ContainsKey(posx, posy, posz))
                            {
                                game.blockHealth.Set(posx, posy, posz, game.GetCurrentBlockHealth(posx, posy, posz));
                            }
                            game.blockHealth.Set(posx, posy, posz, game.blockHealth.Get(posx, posy, posz) - game.WeaponAttackStrength());
                            float health = game.GetCurrentBlockHealth(posx, posy, posz);
                            if (health <= 0)
                            {
                                if (game.currentAttackedBlock != null)
                                {
                                    game.blockHealth.Remove(posx, posy, posz);
                                }
                                game.currentAttackedBlock = null;
                                OnPick(game, game.platform.FloatToInt(newtileX), game.platform.FloatToInt(newtileZ), game.platform.FloatToInt(newtileY),
                                    game.platform.FloatToInt(tile.Current()[0]), game.platform.FloatToInt(tile.Current()[2]), game.platform.FloatToInt(tile.Current()[1]),
                                    tile.collisionPos,
                                    right);
                            }
                            PickingEnd(left, right, middle, ispistol);
                            return;
                        }
                        if (!right)
                        {
                            game.particleEffectBlockBreak.StartParticleEffect(newtileX, newtileY, newtileZ);//must be before deletion - gets ground type.
                        }
                        if (!game.map.IsValidPos(newtileX, newtileZ, newtileY))
                        {
                            game.platform.ThrowException("Error in picking - NextBullet()");
                        }
                        OnPick(game, game.platform.FloatToInt(newtileX), game.platform.FloatToInt(newtileZ), game.platform.FloatToInt(newtileY),
                            game.platform.FloatToInt(tile.Current()[0]), game.platform.FloatToInt(tile.Current()[2]), game.platform.FloatToInt(tile.Current()[1]),
                            tile.collisionPos,
                            right);
                        //network.SendSetBlock(new Vector3((int)newtile.X, (int)newtile.Z, (int)newtile.Y),
                        //    right ? BlockSetMode.Create : BlockSetMode.Destroy, (byte)MaterialSlots[activematerial]);
                    }
                }
            }
        }
        PickingEnd(left, right, middle, ispistol);
    }
예제 #57
0
 public static Packet_Client FillArea(int startx, int starty, int startz, int endx, int endy, int endz, int blockType, int ActiveMaterial)
 {
     Packet_ClientFillArea p = new Packet_ClientFillArea();
     {
         p.X1 = startx;
         p.Y1 = starty;
         p.Z1 = startz;
         p.X2 = endx;
         p.Y2 = endy;
         p.Z2 = endz;
         p.BlockType = blockType;
         p.MaterialSlot = ActiveMaterial;
     }
     Packet_Client pp = new Packet_Client();
     pp.Id = Packet_ClientIdEnum.FillArea;
     pp.FillArea = p;
     return pp;
 }
예제 #58
0
 public void SendPacketClient(Packet_Client packetClient)
 {
     byte[] packet = Serialize(packetClient, packetLen);
     SendPacket(packet, packetLen.value);
 }
예제 #59
0
    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;
        }
    }
예제 #60
0
 void ProcessPackets()
 {
     for (; ; )
     {
         NetIncomingMessage msg = server.ReadMessage();
         if (msg == null)
         {
             return;
         }
         switch (msg.Type)
         {
             case NetworkMessageType.Connect:
                 ClientSimple c = new ClientSimple();
                 c.MainSocket = server;
                 c.Connection = msg.SenderConnection;
                 c.chunksseen = new bool[(MapSizeX / ChunkSize) * (MapSizeY / ChunkSize)][];
                 clients[0] = c;
                 clientsCount = 1;
                 break;
             case NetworkMessageType.Data:
                 byte[] data = msg.message;
                 Packet_Client packet = new Packet_Client();
                 Packet_ClientSerializer.DeserializeBuffer(data, msg.messageLength, packet);
                 ProcessPacket(0, packet);
                 break;
             case NetworkMessageType.Disconnect:
                 break;
         }
     }
 }