Example #1
0
    private byte[] BuildPacket(OFConnection client)
    {
        byte[] packet = null;


        throw new NotImplementedException();
        // build packet

        // networkid
        // packetnumber

        // acknowledged packetnumber
        // cl_state
        // transform, speed

        return(packet);
    }
Example #2
0
    private void DecodePacket(string[] msgs, int id)
    {
        OFConnection peer = connections.First(c => c.NetworkID == id);
        SnapShot     ss   = new SnapShot();

        ss.PacketData = msgs;
        Player p = null;

        for (int i = 0; i < msgs.Length; i++)
        {
            string type = msgs[i];
            i++;
            string data = msgs[i];

            switch (type)
            {
            case "packetNumber":
                ss.PacketNumber = Convert.ToInt32(data);
                if (ss.PacketNumber <= peer.AcknowledgedPacketNumber)
                {
                    return;
                }
                else
                {
                    peer.AcknowledgedPacketNumber = ss.PacketNumber;
                }
                break;

            case "clientID":
                ss.ClientID = Convert.ToInt32(data);
                p           = (Player)GetNode("/root/openFortress/" + data);

                if (p == null)
                {
                    // spawn a player
                    throw new NotImplementedException();
                }
                break;

            case "transform":
                float[] vecs = data.Split(",").Select(float.Parse).ToArray();
                Vector3 x    = new Vector3(vecs[0], vecs[1], vecs[2]);
                Vector3 y    = new Vector3(vecs[3], vecs[4], vecs[5]);
                Vector3 z    = new Vector3(vecs[6], vecs[7], vecs[8]);
                Vector3 org  = new Vector3(vecs[9], vecs[10], vecs[11]);

                // for now find player and apply, later we need to put on all ents
                p.PlayerController.Transform = new Transform(x, y, z, org);
                break;

            case "velocity":
                throw new NotImplementedException();
                break;

            case "move_forward":
                p.PlayerController.move_forward = (float)Convert.ToInt16(data);
                break;

            case "move_right":
                p.PlayerController.move_right = (float)Convert.ToInt16(data);
                break;

            case "impulses":
                int[] imps = data.Split(",").Select(Int32.Parse).ToArray();
                foreach (Impulse imp in imps)
                {
                    p.PlayerController.Impulses.Add(imp);
                }
                break;
            }
        }
    }