public TestPlane(IGame game, float posX, float posY, int syncedTransformId)
        {
            tickTriggerAmount = 1f / tickRate;
            this.body         = game.GetPhysicsManager().CreateBody(posX, posY, 5, 5);
            speed             = 10;
            this.body.SetVelocity(speed);
            transform2D = new SyncedTransform2D(syncedTransformId, game, body);
            this.game   = game;

            handleInput = NetworkMagic.RegisterAtServer <InputNetworkData>(0, HandleInput_AtServer, 123);
        }
 private void Update()
 {
     if (Input.GetKeyDown(addTestPlayer))
     {
         string name   = $"testplayer:{GenerateRandomName(6)}";
         var    action = NetworkMagic.GetHandler <Core.NameNetworkData>("BroadcastAdd", GameManager.instance.PlayerManager.Players.EntityId);
         action(new Core.NameNetworkData()
         {
             Name = name
         });
         DebugLog.Info($"<color=#FF69B4>[Debugger] Added new test player: {name}</color>");
     }
 }
        public SyncedListOfString(int entityId)
        {
            this.EntityId = entityId;

            initialize       = NetworkMagic.RegisterAtServer <NetworkData>(0, Initialize_AtServer, entityId);
            handleInitialize = NetworkMagic.RegisterAtClient <ListOfStringData>(0, HandleInitialize_AtClient, entityId);
            addItem          = NetworkMagic.RegisterAtAllClients <NameNetworkData>(0, Add_AtAllClients, entityId);
            removeItem       = NetworkMagic.RegisterAtAllClients <NameNetworkData>(1, Remove_AtAllClients, entityId);

            if (NetworkMagic.IsClient)
            {
                initialize(new NetworkData());
            }
        }
        public SyncedTransform2D(int entityId, IGame game, PhysicsBody body = null)
        {
            this.EntityId     = entityId;
            tickTriggerAmount = 1f / tickRate;
            this.game         = game;
            this.body         = body;

            stateBuffer = new Transform2DNetworkData[StateAmount];
            stateTimeOffsets.Add(0f);
            stateBuffer[0] = new Transform2DNetworkData()
            {
                Timestamp = 0.0000000001f, Position = new Vec2(0, 0), Rotation = 0f
            };
            stateBuffer[1] = new Transform2DNetworkData()
            {
                Timestamp = 0f, Position = new Vec2(0, 0), Rotation = 0f
            };
            transmitState = NetworkMagic.RegisterAtAllClients <Transform2DNetworkData>(0, TransmitState_AtAllClients, entityId);
        }
        private static void HandleDataPackets(string connectionID, byte[] data)
        {
            ByteBuffer buffer = new ByteBuffer();

            DebugLog.Info("[Connection] Receiving data!");
            buffer.WriteBytes(data);
            // Console.WriteLine(string.Join(",", data.ToList().Select(b => b.ToString())));
            int packageType = buffer.ReadInteger();
            int packetID    = buffer.ReadInteger();
            int entityId    = buffer.ReadInteger();

            // if (packets.TryGetValue(packetID, out Packet packet))
            // {
            //     packet.Invoke(connectionID, buffer);
            // }
            // if (packetsNew.TryGetValue(packetID, out Requestor requestor))
            //     requestor.Receive(buffer, connectionID);
            NetworkMagic.Receive(packageType, connectionID, packetID, entityId, buffer);
            buffer.Dispose();
        }
        private static void HandleDataPackets(byte[] data)
        {
            ByteBuffer buffer = new ByteBuffer();

            // Debug.Log(string.Join(" ", data));
            DebugLog.Info("[Connection] Receiving Data!");

            buffer.WriteBytes(data);
            int packageType = buffer.ReadInteger();
            int packetID    = buffer.ReadInteger();
            int entityId    = buffer.ReadInteger();

            // if (packets.TryGetValue(packetID, out Packet packet))
            // {
            //     packet.Invoke(buffer);
            // }
            NetworkMagic.Receive(packageType, "", packetID, entityId, buffer);
            // if (packetsNew.TryGetValue(packetID, out Requestor requestor))
            //     requestor.Receive(buffer);
            buffer.Dispose();
        }
Esempio n. 7
0
 public Authenticator()
 {
     entityId    = 23135;
     tryLogin    = NetworkMagic.RegisterAtServer <NameNetworkData>(1, TryLogin_AtServer, entityId);
     handleLogin = NetworkMagic.RegisterAtClient <MessageResponseNetworkData>(1, HandleLogin_AtClient, entityId);
 }