Beispiel #1
0
        public NetData()
        {
            //For each type of packet we need to init the array and fill in with empty objects to avoid nullreferences
            //Before a write has filled the slot with data.
            CMD = new NetCMD[Enum.GetValues(typeof(ID_CMD)).Length];
            for (int i = 0; i < Enum.GetValues(typeof(ID_CMD)).Length; i++)
            {
                CMD[i] = new NetCMD();
            }

            NETTRANSFORM = new NetTransform[Enum.GetValues(typeof(ID_NETTRANSFORM)).Length];
            for (int i = 0; i < Enum.GetValues(typeof(ID_NETTRANSFORM)).Length; i++)
            {
                NETTRANSFORM[i] = new NetTransform();
            }
        }
Beispiel #2
0
        public void OnReceive(byte[] raw)
        {
            phtemp = PacketUtils.ReadHeader(raw);

            switch (phtemp.type)
            {
            case NetData.TYPE_NETTRANSFORM:
                netdata.NETTRANSFORM[phtemp.id].DecodeRaw(PacketUtils.Unpack(raw));
                break;

            case NetData.TYPE_CMD:
                NetCMD cmd = new NetCMD();
                cmd.DecodeRaw(PacketUtils.Unpack(raw));
                OnCommandReceived(cmd);
                break;
            }
        }
Beispiel #3
0
        public void OnClientCommandReceived(byte cid, NetCMD cmd)
        {
            switch (NetCMD.ExtractCommand(cmd.command))
            {
            case NetCMD.TEST:
                DebugLog("RECEIVED TEST COMMAND FROM CLIENT " + cid);
                break;

            case NetCMD.UDPINIT:
                DebugLog("[" + cid + "]" + "UDP Socket Initialized on port " + clients[cid].udpep.Port);
                break;


            default:
                DebugLog("Undefined Command Type : " + cmd.command);
                break;
            }
        }
Beispiel #4
0
        public void OnCommandReceived(NetCMD cmd)
        {
            switch (NetCMD.ExtractCommand(cmd.command))
            {
            case NetCMD.CIDINIT:
                cid     = byte.Parse(NetCMD.ExtractArgs(cmd.command));
                cidinit = true;
                DebugLog("Received CID From Server : " + cid);
                break;

            case NetCMD.TEST:
                DebugLog("Received Test CMD from Server!");
                break;

            case NetCMD.UDPINIT:
                SendCommandUDP("/udpinit");
                break;

            default:
                break;
            }
        }
Beispiel #5
0
        public void OnReceive(Packet p)
        {
            phtemp = PacketUtils.ReadHeader(p.data);

            switch (phtemp.type)
            {
            case NetData.TYPE_CMD:
                NetCMD cmd = new NetCMD();
                cmd.DecodeRaw(PacketUtils.Unpack(p.data));
                OnClientCommandReceived(phtemp.cid, cmd);
                break;

            case NetData.TYPE_NETTRANSFORM:
                NetTransform nt = new NetTransform();
                nt.DecodeRaw(PacketUtils.Unpack(p.data));
                OnClientTransformReceived(phtemp.cid, nt);
                break;

            default:
                DebugLog("Undefined Packet Type : " + phtemp.type);

                break;
            }
        }