public void TestGenerateFactoryProperties() { NetworkPacketFactoryCodeGenerater gen = new NetworkPacketFactoryCodeGenerater( System.Windows.Forms.Application.StartupPath + "\\Test\\Networking\\TestFactoriesGeneratedProperties.dll"); INetworkPacketFactory <PacketPropertiesTest> factory = gen.GetFactory <PacketPropertiesTest>(); gen.BuildFactoriesAssembly(); PacketPropertiesTest p = new PacketPropertiesTest(); p.Text = "Hello"; p.Getal = 38; MemoryStream memStrm = new MemoryStream(); BinaryWriter bw = new BinaryWriter(memStrm); BinaryReader br = new BinaryReader(memStrm); factory.ToStream(bw, p); memStrm.Position = 0; PacketPropertiesTest pCheck = factory.FromStream(br); Assert.AreEqual(pCheck, p); }
public void TestGenerateFactoryFields() { NetworkPacketFactoryCodeGenerater gen = new NetworkPacketFactoryCodeGenerater( System.Windows.Forms.Application.StartupPath + "\\Test\\Networking\\TestFactoriesGeneratedFields.dll"); INetworkPacketFactory <PacketFieldsTest> factory = gen.GetFactory <PacketFieldsTest>(); gen.BuildFactoriesAssembly(); PacketFieldsTest p = new PacketFieldsTest(); p.Text = "Hello"; p.Getal = 38; p.Boolean = true; p.GetalFloat = 456f; p.Buffer = new byte[] { 1, 1, 2, 3, 5, 7, 13, 21 }; p.Guid = Guid.NewGuid(); p.Enum = ByteEnum.Second; p.Array = new int[] { 1, 3, 6, 10, 15, 21 }; MemoryStream memStrm = new MemoryStream(); BinaryWriter bw = new BinaryWriter(memStrm); BinaryReader br = new BinaryReader(memStrm); factory.ToStream(bw, p); memStrm.Position = 0; PacketFieldsTest pCheck = factory.FromStream(br); Assert.AreEqual(pCheck, p); }
public ClientPacketTransporterNetworked(PacketFlags flags, int networkId, INetworkPacketFactory <T> factory, ClientPacketManagerNetworked manager, string _uniqueName) { this.Flags = flags; NetworkID = networkId; this.factory = factory; this.manager = manager; this.uniqueName = _uniqueName; internalTransporter = new BasicPacketTransporter <T>(p => manager.SendPacket(this, p)); }
public void TestGenerateFactory() { NetworkPacketFactoryCodeGenerater gen = new NetworkPacketFactoryCodeGenerater( System.Windows.Forms.Application.StartupPath + "\\Test\\Networking\\TestFactoriesGenerated.dll"); INetworkPacketFactory <DataPacket> factory = gen.GetFactory <DataPacket>(); gen.BuildFactoriesAssembly(); }
public ClientPacketRequesterNetworked(ClientPacketRequestDelegate <TSend, TReceive> callback, ClientPacketManagerNetworked manager, INetworkPacketFactory <TSend> sendFactory, INetworkPacketFactory <TReceive> receiveFactory, string uniqueName) { this.callback = callback; this.manager = manager; this.sendFactory = sendFactory; this.receiveFactory = receiveFactory; this.uniqueName = uniqueName; networkID = -1; nextRequestID = 2; }
private void assignInternalFactory() { internalFactory = generater.getGeneratedFactory <T>(); if (internalFactory != null) { return; } generater.BuildFactoriesAssembly(); internalFactory = generater.getGeneratedFactory <T>(); if (internalFactory == null) { throw new Exception("Error in generater!"); } }
public void TestGenerateMultiple() { NetworkPacketFactoryCodeGenerater gen = new NetworkPacketFactoryCodeGenerater( Application.StartupPath + "\\Test\\Networking\\TestGenerateMultiple.dll"); INetworkPacketFactory <PacketFieldsTest> factory1 = gen.GetFactory <PacketFieldsTest>(); INetworkPacketFactory <PacketPropertiesTest> factory2 = gen.GetFactory <PacketPropertiesTest>(); gen.BuildFactoriesAssembly(); PacketFieldsTest p1 = new PacketFieldsTest(); p1.Text = "Hello"; p1.Getal = 38; MemoryStream memStrm; BinaryWriter bw; BinaryReader br; memStrm = new MemoryStream(); bw = new BinaryWriter(memStrm); br = new BinaryReader(memStrm); factory1.ToStream(bw, p1); memStrm.Position = 0; PacketFieldsTest pCheck1 = factory1.FromStream(br); Assert.AreEqual(pCheck1, p1); PacketPropertiesTest p2 = new PacketPropertiesTest(); p2.Text = "Hello"; p2.Getal = 38; memStrm = new MemoryStream(); bw = new BinaryWriter(memStrm); br = new BinaryReader(memStrm); factory2.ToStream(bw, p2); memStrm.Position = 0; PacketPropertiesTest pCheck2 = factory2.FromStream(br); Assert.AreEqual(pCheck2, p2); }
/// <summary> /// This creates a requester, that uses given callback for processing remote requests /// TODO: WARNING: not completely implemented /// </summary> /// <typeparam name="TSend"></typeparam> /// <typeparam name="TReceive"></typeparam> /// <param name="sendFactory"></param> /// <param name="receiveFactory"></param> /// <param name="callback"></param> /// <param name="flags"></param> /// <returns></returns> public IClientPacketRequester <TSend, TReceive> CreatePacketRequester <TSend, TReceive>(string uniqueName, INetworkPacketFactory <TSend> sendFactory, INetworkPacketFactory <TReceive> receiveFactory, ClientPacketRequestDelegate <TSend, TReceive> callback, PacketFlags flags) where TReceive : INetworkPacket where TSend : INetworkPacket { ClientPacketRequesterNetworked <TSend, TReceive> requester = new ClientPacketRequesterNetworked <TSend, TReceive>(callback, this, sendFactory, receiveFactory, uniqueName); if ((flags & PacketFlags.TCP) == PacketFlags.None) { throw new NotImplementedException("Only TCP is currently supported!"); } if (packetTransportersMap.ContainsKey(uniqueName)) { throw new InvalidOperationException("Already constains smth with uniqueName!"); } packetTransportersMap[requester.UniqueName] = requester; packetTransporters.Add(requester); return(requester); }
/// <summary> /// This functions returns a transporter that can send/receive one type of packets. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="factory"></param> /// <param name="flags"></param> /// <returns></returns> public ClientPacketManagerNetworked.ClientPacketTransporterNetworked <T> CreatePacketTransporter <T>(string uniqueName, INetworkPacketFactory <T> factory, PacketFlags flags) where T : INetworkPacket { var transporter = new ClientPacketTransporterNetworked <T>( flags, -1, factory, this, uniqueName); if (packetTransportersMap.ContainsKey(uniqueName)) { throw new InvalidOperationException("Already constains smth with uniqueName!"); } packetTransportersMap[transporter.UniqueName] = transporter; packetTransporters.Add(transporter); if (networkIDMap.ContainsKey(uniqueName)) { setTransporterNetworkID(networkIDMap[uniqueName], transporter); } else { networkIDsUpToDate = false; serverSideNetworkIDsAssigned = false; } return(transporter); }
IClientPacketTransporter <T> IClientPacketManager.CreatePacketTransporter <T>(string uniqueName, INetworkPacketFactory <T> factory, PacketFlags flags) { return(CreatePacketTransporter(uniqueName, factory, flags)); }
public IServerPacketTransporter <T> CreatePacketTransporter <T>(string uniqueName, INetworkPacketFactory <T> factory, PacketFlags flags) where T : INetworkPacket { firstTransporter = false; var t = new ServerPacketTransporterNetworked <T>(); for (int i = 0; i < Clients.Count; i++) { var cl = Clients[i]; var clt = cl.PacketManager.CreatePacketTransporter <T>(uniqueName, factory, flags); t.AddClientTransporter(cl, clt); } return(t); }
public ServerPacketTransporterNetworked <T> CreatePacketTransporter <T>(string uniqueName, INetworkPacketFactory <T> factory, PacketFlags flags) where T : INetworkPacket { if (Clients.Count > 0) { throw new InvalidOperationException( "Clients have already connected, adding factories is atm not supported in this case!"); } var transporter = new ServerPacketTransporterNetworked <T>(); transporters.Add(transporter); var fact = new TransporterFactory <T>(uniqueName, factory, flags); transporterFactories.Add(transporter, fact); return(transporter); }
public IClientPacketTransporter <T> CreatePacketTransporter <T>(string uniqueName, INetworkPacketFactory <T> factory, PacketFlags flags) where T : INetworkPacket { if (Transporters.ContainsKey(uniqueName)) { return((IClientPacketTransporter <T>)Transporters[uniqueName]); } //throw new InvalidOperationException("This transporter has already been created!"); var t = new SimpleClientPacketTransporter <T>(); Transporters[uniqueName] = t; return(t); }
public TransporterFactory(string uniqueName, INetworkPacketFactory <T> factory, PacketFlags flags) { this.uniqueName = uniqueName; this.factory = factory; this.flags = flags; }
/// <summary> /// This creates a requester. It can't process remote requests, since no callback is given /// TODO: WARNING: not completely implemented /// </summary> /// <typeparam name="TSend"></typeparam> /// <typeparam name="TReceive"></typeparam> /// <param name="sendFactory"></param> /// <param name="receiveFactory"></param> /// <param name="callback"></param> /// <param name="flags"></param> /// <returns></returns> public IClientPacketRequester <TSend, TReceive> CreatePacketRequester <TSend, TReceive>(string uniqueName, INetworkPacketFactory <TSend> sendFactory, INetworkPacketFactory <TReceive> receiveFactory, PacketFlags flags) where TReceive : INetworkPacket where TSend : INetworkPacket { return(CreatePacketRequester(uniqueName, sendFactory, receiveFactory, null, flags)); }
public IClientPacketRequester <TSend, TReceive> CreatePacketRequester <TSend, TReceive>(string uniqueName, INetworkPacketFactory <TSend> sendFactory, INetworkPacketFactory <TReceive> receiveFactory, PacketFlags flags) where TSend : INetworkPacket where TReceive : INetworkPacket { throw new NotImplementedException(); }
/// <summary> /// What is THIS? /// DO NOT USE THIS is WTF /// </summary> /// <typeparam name="T"></typeparam> /// <param name="factory"></param> /// <param name="flags"></param> public void AddPacketType <T>(INetworkPacketFactory <T> factory, PacketFlags flags) where T : INetworkPacket { throw new NotImplementedException(); }