Esempio n. 1
0
        public void Connect(string ip, int port)
        {
            AutoResetEvent ev = new AutoResetEvent(false);

            var conn = new TCPConnection();

            conn.ConnectedToServer += delegate { ev.Set(); };

            conn.Connect(ip, port);
            if (!ev.WaitOne(5000))
            {
                throw new Exception("Connection timed out!");
            }

            var cpm = new ClientPacketManagerNetworked(conn);

            conn.Receiving = true;
            Thread.Sleep(100);
            cpm.WaitForUDPConnected();
            cpm.SyncronizeRemotePacketIDs();


            var gen = new NetworkPacketFactoryCodeGenerater(TWDir.Cache.CreateChild("GodGame").CreateFile("ClientPackets" + (new Random()).Next() + ".dll").FullName);

            UserInputHandlerTransporter = cpm.CreatePacketTransporter("UserInputHandler", gen.GetFactory <UserInputHandlerPacket>(), PacketFlags.TCP);
            UserInputTransporter        = cpm.CreatePacketTransporter("UserInput", gen.GetFactory <UserInputPacket>(), PacketFlags.TCP);
            GameStateDeltaTransporter   = cpm.CreatePacketTransporter("GameStateDelta", gen.GetFactory <GameStateDeltaPacket>(), PacketFlags.TCP);

            gen.BuildFactoriesAssembly();
        }
Esempio n. 2
0
        public ClientSyncer(IClientPacketManager packetManager)
        {
            //TODO: cleanup
            var gen         = new NetworkPacketFactoryCodeGenerater(TWDir.Cache.FullName + "\\ClientSyncerGenTemp" + (new Random()).Next(0, 10000) + ".dll");
            var timeFactory = gen.GetFactory <TimeUpdatePacket>();

            gen.BuildFactoriesAssembly();

            deltaTransport = packetManager.CreatePacketTransporter("WorldSyncerDeltaSnapshot", new DataPacket.Factory(),
                                                                   PacketFlags.UDP);

            timeTransport = packetManager.CreatePacketTransporter("WorldSyncerTimeUpdate", timeFactory,
                                                                  PacketFlags.UDP);

            var t = new Thread(receiveDeltaJob)
            {
                Name = "ClientSyncerDeltaJob", IsBackground = true
            };

            t.Start();

            t = new Thread(receiveTimeJob)
            {
                Name = "ClientSyncerTimeJob", IsBackground = true
            };
            t.Start();
        }
        public ClientStaticWorldObjectSyncer(IClientPacketManager pm, IStaticWorldObjectFactory worldObjectFactory)
        {
            this.worldObjectFactory = worldObjectFactory;
            var gen =
                new Networking.NetworkPacketFactoryCodeGenerater(TWDir.Cache + "\\ClientStaticWorldObjectSyncer" +
                                                                 (new Random()).Next(0, 100000) + ".dll");

            updateTransporter = pm.CreatePacketTransporter("StaticWorldObjectSyncer_UpdatePacket", gen.GetFactory <StaticWorldObjectUpdatePacket>(), Networking.PacketFlags.TCP);
            deleteTransporter = pm.CreatePacketTransporter("StaticWorldObjectSyncer_DeletePacket", gen.GetFactory <StaticWorldObjectDeletePacket>(), Networking.PacketFlags.TCP);

            gen.BuildFactoriesAssembly();
        }
        public NetworkedPlayer CreatePlayer(IClient client, IClientPacketTransporter <UserInputHandlerPacket> inputTransporter)
        {
            //Note: This could go to a networkedplayerfactory
            var state = new PlayerState();

            gameState.AddPlayer(state);
            state.Name = "Player" + (nextId++).ToString();
            var handler        = createInputHandler(state);
            var nInputReceiver = createNetworkedInputReceiver(inputTransporter, handler);

            return(new NetworkedPlayer(nInputReceiver, client, state));
        }
        public void AddClientTransporter(IClient client, IClientPacketTransporter <T> transporter)
        {
            var t = transporter;

            transporters.Add(t);
            transportersDict.Add(client, t);

            if (receiveMode)
            {
                setupReceiveJob(client);
            }
        }
        public ClientVersioningSyncer(VersioningSystem sys, IClientPacketManager pm)
        {
            this.sys = sys;
            var gen = new NetworkPacketFactoryCodeGenerater(TWDir.GenerateRandomCacheFile("CVS", "dll"));

            revisionTransporter = pm.CreatePacketTransporter("Versioning_Revision",
                                                             gen.GetFactory <RevisionPacket>(), PacketFlags.TCP);
            requestRevisionTransporter = pm.CreatePacketTransporter("Versioning_RequestRevision",
                                                                    gen.GetFactory <RevisionRequestPacket>(), PacketFlags.TCP);
            commandTransporter = pm.CreatePacketTransporter("Versioning_CMD",
                                                            new BytePacket.Factory(), PacketFlags.TCP);

            fileTransporter = new ClientFileTransporter <RevisionFilePacket>("Versioning_File", pm, TWDir.Cache.CreateSubdirectory("Versioning").FullName);
            fileTransporter.StartReceiving();

            gen.BuildFactoriesAssembly();
        }
        public ClientFileTransporter(string uniqueName, IClientPacketManager pm, string downloadCachePath)
        {
            this.downloadCachePath = downloadCachePath;
            UniqueName             = uniqueName;
            i = (new Random()).Next(0, 1000);

            var gen = new NetworkPacketFactoryCodeGenerater(Application.StartupPath + "\\ClientFileTrans" + uniqueName + i.ToString() + ".dll");

            startTransporter = pm.CreatePacketTransporter("SFTFileStart" + uniqueName, gen.GetFactory <FileStartPacket>(),
                                                          PacketFlags.TCP);
            endTransporter = pm.CreatePacketTransporter("SFTFileComplete" + uniqueName, gen.GetFactory <T>(),
                                                        PacketFlags.TCP);
            partTransporter = pm.CreatePacketTransporter("SFTFilePart" + uniqueName, gen.GetFactory <FilePartPacket>(),
                                                         PacketFlags.TCP);
            gen.BuildFactoriesAssembly();

            StartReceiving();
        }
        private static void testInputHandler(IClientPacketTransporter <UserInputHandlerPacket> proxyTrans, IClientPacketTransporter <UserInputHandlerPacket> realTrans)
        {
            var world         = TestWorldBuilder.createTestWorld(20, 10);
            var proxyHandler  = new ProxyPlayerInputHandler(proxyTrans);
            var realHandler   = Substitute.For <IPlayerInputHandler>();
            var inputReceiver = new NetworkPlayerInputForwarder(realTrans, realHandler, world);

            proxyHandler.OnSave();
            Thread.Sleep(100);
            inputReceiver.ForwardReceivedInputs();
            realHandler.Received().OnSave();

            proxyHandler.OnNextTool();
            Thread.Sleep(100);
            inputReceiver.ForwardReceivedInputs();
            realHandler.Received().OnNextTool();

            proxyHandler.OnPreviousTool();
            Thread.Sleep(100);
            inputReceiver.ForwardReceivedInputs();
            realHandler.Received().OnPreviousTool();

            var pos1 = new Point2(3, 4);

            proxyHandler.OnLeftClick(world.GetVoxel(pos1));
            Thread.Sleep(100);
            inputReceiver.ForwardReceivedInputs();
            realHandler.Received().OnLeftClick(world.GetVoxel(pos1));


            var pos2 = new Point2(3, 4);

            proxyHandler.OnRightClick(world.GetVoxel(pos2));
            Thread.Sleep(100);
            inputReceiver.ForwardReceivedInputs();
            realHandler.Received().OnRightClick(world.GetVoxel(pos2));
        }
 public ProxyPlayerInputHandler(IClientPacketTransporter <UserInputHandlerPacket> transporter)
 {
     this.transporter = transporter;
 }
 public NetworkPlayerInputForwarder(IClientPacketTransporter <UserInputHandlerPacket> transporter, IPlayerInputHandler handler, Internal.Model.World world)
 {
     this.transporter = transporter;
     this.handler     = handler;
     this.world       = world;
 }