public virtual bool rpcReceive(ushort rpc_id, byte[] src, ref int offset)
    {
        bool ret = false;

        switch (rpc_id)
        {
        case 0:
            role = (GameObjectRoles)ClientTest.deserializeToByte(src, ref offset);
            Debug.Log(GetType().ToString() + " clientSetRole:" + role.ToString());
            ret = true;
            break;

        case 1:
            initialReplicationComplete();
            // now that the function is called on the client, call this function on the server.
            ClientTest.self.rpcBegin(goId, 2);
            ClientTest.self.rpcEnd();

            ret = true;
            break;

        case 2:     // ack 1
            // call this function on the server.
            initialReplicationComplete();
            ret = true;
            break;
        }
        return(ret);
    }
Example #2
0
        private void TestClient(ClientTest ct)
        {
            var clientType = ct.ClientType;

            if (clientType == null)
            {
                Console.WriteLine("Could not find client [{0}], skipping test", clientType);
                return;
            }

            Console.WriteLine("Testing client: " + clientType.FullName);
            var region = ct.Region ?? AWSConfigs.RegionEndpoint;
            var client = Activator.CreateInstance(clientType, region) as IDisposable;

            // Optionally modify client config
            //var config = GetConfig(client);
            //config.UseHttp = true;

            using (client)
            {
                Action action = GetClientAction(client, ct.Method, ct.Request);

                // Optionally log the signer type
                //var signer = GetSigner(client);
                //Console.WriteLine("Signer: " + signer.GetType().FullName);

                TestServiceCallForClockSkew(action);
            }
        }
Example #3
0
                internal static void Run(ClientArgs args)
                {
                    Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

                    client.Connect(new IPEndPoint(args.ServerAddress, args.ServerPort));

                    try
                    {
                        switch (args.TestType)
                        {
                        case TestType.Upload:
                            ClientTest.Upload(new TcpSocket(client), args.SizeInMb);
                            break;

                        case TestType.Download:
                            ClientTest.Download(new TcpSocket(client), args.SizeInMb);
                            break;

                        case TestType.Integrity:
                            ClientTest.Integrity(new TcpSocket(client), args.SizeInMb);
                            break;
                        }
                    }
                    finally
                    {
                        client.Close();
                    }
                }
Example #4
0
    void Awake()
    {
        self = this;
        Application.runInBackground = true;
        NetworkTransport.Init();
        GlobalConfig gConfig = new GlobalConfig();

        gConfig.MaxPacketSize = 500;
        NetworkTransport.Init(gConfig);

        ConnectionConfig config = new ConnectionConfig();

        reliableCHN   = config.AddChannel(QosType.AllCostDelivery);
        unreliableCHN = config.AddChannel(QosType.StateUpdate);

        HostTopology topology = new HostTopology(config, 10); // max connections

        socketId = NetworkTransport.AddHost(topology, clientPort);
        Debug.Log("Socket Open. SocketId is: " + socketId);
        recvBuffer             = new byte[1024];
        synchronizedComponents = new Dictionary <int, ReplicatedProperties>();
        sendBuffer             = new SerializedBuffer[2];
        sendBuffer[0]          = new SerializedBuffer();
        sendBuffer[1]          = new SerializedBuffer();
    }
 public void WriteToDB(string path, EntityType type)
 {
     using (var ctx = new StatisticContext())
     {
         var test = new ClientTest()
         {
             Name = path, CreationDate = DateTime.Now, Type = type
         };
         ctx.ClientTests.Add(test);
         ctx.SaveChanges();
     }
 }
 // called on client
 public virtual bool stateRepReceive(ushort varOffset, byte[] src, ref int offset)
 {
     if (varOffset == 0)
     {
         owner = ClientTest.deserializeToInt(src, ref offset);
         return(true);
     }
     else if (varOffset == 1)
     {
         goId = ClientTest.deserializeToInt(src, ref offset);
         return(true);
     }
     return(false);
 }
    /** variable reception method(client)*/

    public override bool stateRepReceive(ushort varOffset, byte[] src, ref int offset)
    {
        if (base.stateRepReceive(varOffset, src, ref offset))
        {
            return(true);
        }
        switch (varOffset)
        {
        case 64:
            float old_serverTime = serverTime;
            serverTime = ClientTest.deserializeToFloat(src, ref offset);
            onrepServerTime(old_serverTime);

            break;
        }
        return(true);
    }
Example #8
0
        public IActionResult EditClient(ClientTest model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            model.TypeId = 4;
            var dbModel = _service.Client.GetClient(model.Id);

            if (dbModel == null)
            {
                throw new Exception("object not found");
            }

            _mapper.Map <ClientTest, Client>(model, dbModel);
            _service.Client.Update(dbModel);
            _service.Commit();

            return(RedirectToAction(nameof(ClientList)));
        }
    /** rpc reception method(client)*/

    public override bool rpcReceive(ushort rpc_id, byte[] src, ref int offset)
    {
        if (base.rpcReceive(rpc_id, src, ref offset))
        {
            return(true);
        }
        switch (rpc_id)
        {
        case 64:
        {
            UnityEngine.Vector3 pos = ClientTest.deserializeToVector3(src, ref offset); UnityEngine.Vector3 rot = ClientTest.deserializeToVector3(src, ref offset); System.Single estTime = ClientTest.deserializeToFloat(src, ref offset); UnityEngine.Vector3 _frameVelocity = ClientTest.deserializeToVector3(src, ref offset); System.Byte interpolationMode = ClientTest.deserializeToByte(src, ref offset); ReceiveUpdate(pos, rot, estTime, _frameVelocity, interpolationMode);
        }
        break;


        case 65:
        {
            UnityEngine.Vector3 pos = ClientTest.deserializeToVector3(src, ref offset); UnityEngine.Vector3 rot = ClientTest.deserializeToVector3(src, ref offset); System.Single estTime = ClientTest.deserializeToFloat(src, ref offset); UnityEngine.Vector3 _frameVelocity = ClientTest.deserializeToVector3(src, ref offset); System.Byte interpolationMode = ClientTest.deserializeToByte(src, ref offset); ReceiveUpdateFromHost(pos, rot, estTime, _frameVelocity, interpolationMode);
        }
        break;


        case 66:
        {
            System.Int32 id = ClientTest.deserializeToInt(src, ref offset); PingServer(id);
        }
        break;


        case 67:
        {
            System.Int32 id = ClientTest.deserializeToInt(src, ref offset); PingClient(id);
        }
        break;
        }
        return(true);
    }
Example #10
0
        private void TestClient(ClientTest ct)
        {
            var clientType = ct.ClientType;

            if (clientType == null)
            {
                Console.WriteLine("Could not find client [{0}], skipping test", clientType);
                return;
            }

            Console.WriteLine("Testing client: " + clientType.FullName);
            var region = ct.Region ?? AWSConfigs.RegionEndpoint;
            var client = Activator.CreateInstance(clientType, region) as IDisposable;

            // Optionally modify client config
            //var config = GetConfig(client);
            //config.UseHttp = true;

            using (client)
            {
                Action action = GetClientAction(client, ct.Method, ct.Request);

                // Optionally log the signer type
                //var signer = GetSigner(client);
                //Console.WriteLine("Signer: " + signer.GetType().FullName);

                TestServiceCallForClockSkew(action);
            }
        }
Example #11
0
	public static void Main(string[] args){
		var server = new ServerTest();
		var client = new ClientTest();
var client2 = new ClientTest();
var outputs = BitConverter.GetBytes(1337);
Packet testpack = new Packet(-1,1,outputs,52);
var test = Packet.ToBytes(new Packet[]{testpack}[0]);
var test2 = Packet.FromBytes(test);
Console.WriteLine(test2.PacketType);
//RequestHandler.Request testx = new RequestHandler.Request(-1, 1, BitConverter.GetBytes(1231), 32);
  //  Packet test5 = RequestHandler.Request.ToPacket(testx);
  //  Console.WriteLine(RequestHandler.Request.FromPacket(test5).RequestType);
		Console.ReadLine();
//server.SendData(BitConverter.GetBytes(3021),client2._client);
client2.WriteData(Packet.ToBytes(testpack));
Console.ReadLine();
	}
Example #12
0
        public void TestEntityClientPhysis()
        {
            XNAGame game = new XNAGame();

            Database.Database database = loadDatabaseServices();

            EntityManagerService ems = new EntityManagerService(database);

            BoundingBox bb = new BoundingBox();



            PhysicsEngine           engine        = new PhysicsEngine();
            PhysicsDebugRendererXNA debugRenderer = null;

            TheWizards.Client.ClientPhysicsQuadTreeNode root;
            root = new ClientPhysicsQuadTreeNode(
                new BoundingBox(
                    new Vector3(-16 * 16 / 2f, -100, -16 * 16 / 2f),
                    new Vector3(16 * 16 / 2f, 100, 16 * 16 / 2f)));

            QuadTree.Split(root, 4);


            ClientPhysicsTestSphere sphere = new ClientPhysicsTestSphere(Vector3.Zero, 2);

            Curve3D curve1 = ClientTest.CreateTestObject1MovementCurve();


            QuadTreeVisualizerXNA visualizer = new QuadTreeVisualizerXNA();
            float time = 0;

            List <ClientPhysicsTestSphere> spheres  = new List <ClientPhysicsTestSphere>();
            List <EntityClientPhysics>     entities = new List <EntityClientPhysics>();


            game.InitializeEvent += delegate
            {
                engine.Initialize();
                debugRenderer = new PhysicsDebugRendererXNA(game, engine.Scene);
                debugRenderer.Initialize(game);

                EntityFullData      entityData;
                EntityClientPhysics entPhysics;



                entityData           = CreatePyramidEntity(ems, 5);
                entityData.Transform = new Transformation(
                    Vector3.One, Quaternion.Identity,
                    new Vector3(10, 2, 20));

                entPhysics = new EntityClientPhysics(entityData);
                entPhysics.LoadInClientPhysics(engine.Scene, root);
                entities.Add(entPhysics);

                entityData           = CreatePyramidEntity(ems, 20);
                entityData.Transform = new Transformation(
                    Vector3.One, Quaternion.Identity,
                    new Vector3(-32, 0, -40));

                entPhysics = new EntityClientPhysics(entityData);
                entPhysics.LoadInClientPhysics(engine.Scene, root);
                entities.Add(entPhysics);


                entityData = CreateTwoPyramidEntity(ems, 5, 3);
                entityData.ObjectFullData.Models[0].ObjectMatrix *= Matrix.CreateTranslation(new Vector3(-3, 0, 3));
                entityData.ObjectFullData.Models[1].ObjectMatrix *= Matrix.CreateTranslation(new Vector3(3, 1, 2));
                entityData.Transform = new Transformation(
                    Vector3.One * 2, Quaternion.Identity,
                    new Vector3(80, 0, -45));

                entPhysics = new EntityClientPhysics(entityData);
                entPhysics.LoadInClientPhysics(engine.Scene, root);
                entities.Add(entPhysics);
            };

            game.DrawEvent += delegate
            {
                debugRenderer.Render(game);


                visualizer.RenderNodeGroundBoundig(game, root,
                                                   delegate(ClientPhysicsQuadTreeNode node, out Color col)
                {
                    col = Color.Green;

                    return(node.PhysicsObjects.Count == 0);
                });

                visualizer.RenderNodeGroundBoundig(game, root,
                                                   delegate(ClientPhysicsQuadTreeNode node, out Color col)
                {
                    col = Color.Orange;

                    return(node.PhysicsObjects.Count > 0);
                });
                game.LineManager3D.AddCenteredBox(sphere.Center, sphere.Radius, Color.Red);

                for (int i = 0; i < entities.Count; i++)
                {
                    game.LineManager3D.AddCenteredBox(entities[i].BoundingSphere.Center,
                                                      entities[i].BoundingSphere.Radius * 2, Color.Black);
                }
            };
            game.UpdateEvent += delegate
            {
                time += game.Elapsed;


                sphere.Move(root, curve1.Evaluate(time * (1 / 4f)));


                if (game.Keyboard.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.F))
                {
                    ClientPhysicsTestSphere iSphere = new ClientPhysicsTestSphere(engine.Scene,
                                                                                  game.SpectaterCamera.CameraPosition + game.SpectaterCamera.CameraDirection
                                                                                  , 1);

                    iSphere.InitDynamic();
                    iSphere.Actor.LinearVelocity = game.SpectaterCamera.CameraDirection * 10;

                    spheres.Add(iSphere);
                }



                for (int i = 0; i < spheres.Count; i++)
                {
                    spheres[i].Update(root, game);
                }



                engine.Update(game.Elapsed);
            };


            game.Run();
        }
Example #13
0
    void FixedUpdate()
    {
        bool loop = true;

        int recHostId;
        int recConnectionId;
        int channelId;

        int  dataSize;
        byte error;

        newConnectionList.Clear();
        for (int i = 0; i < 10 && loop; ++i)
        {
            NetworkEventType recData = NetworkTransport.Receive(out recHostId, out recConnectionId, out channelId, recvBuffer, bufferSize, out dataSize, out error);
            if (dataSize >= bufferSize)
            {
                Debug.LogWarning("the data received exceeds the buffer size!");
            }
            //if (channelId == unreliableCHN) {
            //    Debug.Log("unreliable: " + dataSize);
            //}
            switch (recData)
            {
            case NetworkEventType.Nothing:             //1
                loop = false;
                break;

            case NetworkEventType.ConnectEvent:        //2
                Debug.Log("socket id " + recHostId + ", conn " + recConnectionId + ", channel " + channelId);
                newConnectionList.Add(recConnectionId);
                break;

            case NetworkEventType.DataEvent:           //3
                ClientTest.decodeRawData(recvBuffer, synchronizedComponents);
                break;

            case NetworkEventType.DisconnectEvent:     //4
                int idx = getIndexByConnectionId(recConnectionId);
                if (idx >= 0)
                {
                    Debug.Log("player " + recConnectionId + " disconnected.");
                    for (int j = 0; j < playerOwned.Count; ++j)
                    {
                        if (playerOwned[j].connectionId == recConnectionId)
                        {
                            //playerStates.RemoveAt(j);
                            //sendBuffers.RemoveAt(j * 2 + 1);
                            //sendBuffers.RemoveAt(j * 2);

                            List <GameObjectSpawnInfo> toRemove = playerOwned[j].gameObjectsOwned;
                            for (int k = 0; k < toRemove.Count; ++k)
                            {
                                GameObject.Destroy(toRemove[k].obj);
                            }
                            playerOwned.RemoveAt(j);
                            break;
                        }
                    }
                }
                Debug.Log(recData.ToString());
                break;
            }
        }
        for (int i = 0; i < newConnectionList.Count; ++i)
        {
            // create player state
            playerOwned.Add(new PlayerOwnedInfo(newConnectionList[i]));
            replicateExistingGameObjectsToNewClient(newConnectionList[i]);
            spawnReplicatedGameObject(newConnectionList[i], PlayerStatePrefabPath);
        }
        sendAllBuffers();
    }
Example #14
0
        public void TestMeshPhysicsElementFactoryStatic()
        {
            XNAGame game = new XNAGame();

            var mesh = new RAMMesh();
            var data = mesh.GetCollisionData();

            var box = new MeshCollisionData.Box();

            box.Dimensions  = Vector3.One * 2;
            box.Orientation = Matrix.Identity;

            data.Boxes.Add(box);


            box             = new MeshCollisionData.Box();
            box.Dimensions  = Vector3.One * 4;
            box.Orientation = Matrix.CreateTranslation(new Vector3(2, 2, 2));

            data.Boxes.Add(box);


            BoundingBox bb = new BoundingBox();



            PhysicsEngine           engine        = new PhysicsEngine();
            PhysicsDebugRendererXNA debugRenderer = null;

            TheWizards.Client.ClientPhysicsQuadTreeNode root;
            root = new ClientPhysicsQuadTreeNode(
                new BoundingBox(
                    new Vector3(-16 * 16 / 2f, -100, -16 * 16 / 2f),
                    new Vector3(16 * 16 / 2f, 100, 16 * 16 / 2f)));

            QuadTree.Split(root, 4);


            ClientPhysicsTestSphere sphere = new ClientPhysicsTestSphere(Vector3.Zero, 2);

            Curve3D curve1 = ClientTest.CreateTestObject1MovementCurve();


            var   visualizer = new QuadTreeVisualizerXNA();
            float time       = 0;

            var spheres = new List <ClientPhysicsTestSphere>();
            var meshes  = new List <MeshStaticPhysicsElement>();

            var physicsElementFactoryXNA = new MeshPhysicsFactoryXNA(engine, root);
            var factory = physicsElementFactoryXNA.Factory;

            game.AddXNAObject(physicsElementFactoryXNA);

            var el = factory.CreateStaticElement(mesh, Matrix.CreateTranslation(new Vector3(20, 0, 20)));

            meshes.Add(el);


            el = factory.CreateStaticElement(mesh, Matrix.CreateTranslation(new Vector3(-40, 0, 8)));
            meshes.Add(el);


            el = factory.CreateStaticElement(mesh, Matrix.CreateTranslation(new Vector3(80, 0, 70)));
            meshes.Add(el);

            game.InitializeEvent += delegate
            {
                engine.Initialize();
                debugRenderer = new PhysicsDebugRendererXNA(game, engine.Scene);
                debugRenderer.Initialize(game);
            };

            game.DrawEvent += delegate
            {
                debugRenderer.Render(game);


                visualizer.RenderNodeGroundBoundig(game, root,
                                                   delegate(ClientPhysicsQuadTreeNode node, out Color col)
                {
                    col = Color.Green;

                    return(node.PhysicsObjects.Count == 0);
                });

                visualizer.RenderNodeGroundBoundig(game, root,
                                                   delegate(ClientPhysicsQuadTreeNode node, out Color col)
                {
                    col = Color.Orange;

                    return(node.PhysicsObjects.Count > 0);
                });
                game.LineManager3D.AddCenteredBox(sphere.Center, sphere.Radius, Color.Red);

                for (int i = 0; i < meshes.Count; i++)
                {
                    game.LineManager3D.AddCenteredBox(meshes[i].BoundingSphere.Center,
                                                      meshes[i].BoundingSphere.Radius * 2, Color.Black);
                }
            };
            game.UpdateEvent += delegate
            {
                time += game.Elapsed;


                sphere.Move(root, curve1.Evaluate(time * (1 / 4f)));


                if (game.Keyboard.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.F))
                {
                    ClientPhysicsTestSphere iSphere = new ClientPhysicsTestSphere(engine.Scene,
                                                                                  game.SpectaterCamera.CameraPosition + game.SpectaterCamera.CameraDirection
                                                                                  , 1);

                    iSphere.InitDynamic();
                    iSphere.Actor.LinearVelocity = game.SpectaterCamera.CameraDirection * 10;

                    spheres.Add(iSphere);
                }



                for (int i = 0; i < spheres.Count; i++)
                {
                    spheres[i].Update(root, game);
                }



                engine.Update(game.Elapsed);
            };


            game.Run();
        }
Example #15
0
	public static void Main(string[] args){
		var server = new ServerTest();
		var client = new ClientTest();
var client2 = new ClientTest();
var outputs = BitConverter.GetBytes(1337);
Packet testpack = new Packet(-1,1,outputs);
var test = Packet.ArrayToBytes(new Packet[]{testpack});
var test2 = Packet.ArrayFromBytes(test);
Console.WriteLine(BitConverter.ToInt32(test2[0].data,0));

		Console.ReadLine();
//server.SendData(BitConverter.GetBytes(3021),client2._client);
client2.WriteData(Packet.ToBytes(testpack));
Console.ReadLine();
	}