public bool AddClientToZone(int clientId, EntityNetworkClient networkClient) { var channelDown = new ProtobufChannelToClientZoneOutbound() { OutboundChannel = new EntityNetworkChannelToClientZone { NetworkClient = networkClient }, TypeTable = GetTypeAliasTable(), TypeModel = GetTypeModel(), }; if (_zone.AddClient(clientId, channelDown) == false) { return(false); } var channelUp = new ProtobufChannelToServerZoneInbound { TypeTable = GetTypeAliasTable(), TypeModel = GetTypeModel(), ClientId = clientId, InboundServerZone = _zone }; _zoneChannelMap.Add(clientId, channelUp); OnClientAdd(clientId); return(true); }
public KeyValuePair <int, TestClientZone> AddClient() { var clientId = ++_lastClientId; var channelUp = new ProtobufChannelToServerZoneOutbound { TypeTable = _typeTable, TypeModel = _typeModel, OutboundChannel = new DummyChannelToServerZoneInbound { Channel = new ProtobufChannelToServerZoneInbound { TypeTable = _typeTable, TypeModel = _typeModel, ClientId = clientId, InboundServerZone = ServerZone, } } }; var clientZone = new TestClientZone(EntityFactory.Default, channelUp); ((EntityTimerProvider)clientZone.TimerProvider).ActionScheduled = OnActionSchedule; var channelDown = new ProtobufChannelToClientZoneOutbound { TypeTable = _typeTable, TypeModel = _typeModel, OutboundChannel = new ProtobufChannelToClientZoneInbound() { TypeTable = _typeTable, TypeModel = _typeModel, InboundClientZone = clientZone, } }; ServerZone.AddClient(clientId, channelDown); ClientZoneMap.Add(clientId, clientZone); ClientZones = ClientZoneMap.Values.ToArray(); return(new KeyValuePair <int, TestClientZone>(clientId, clientZone)); }
private static void Main(string[] args) { var typeTable = new TypeAliasTable(); var typeModel = TypeModel.Create(); typeModel.Add(typeof(TrackablePocoTracker <ISpaceShipData>), false) .SetSurrogate(typeof(TrackableSpaceShipDataTrackerSurrogate)); var serverZone = new ServerZone(EntityFactory.Default); var clientZones = Enumerable.Range(0, 2).Select(i => { var channelUp = new ProtobufChannelToServerZoneOutbound { TypeTable = typeTable, TypeModel = typeModel, OutboundChannel = new DummyChannelToServerZoneInbound { Channel = new ProtobufChannelToServerZoneInbound { TypeTable = typeTable, TypeModel = typeModel, ClientId = i + 1, InboundServerZone = serverZone, } } }; var clientZone = new ClientZone(EntityFactory.Default, channelUp); var channel = new ProtobufChannelToClientZoneOutbound { TypeTable = typeTable, TypeModel = typeModel, OutboundChannel = new ProtobufChannelToClientZoneInbound() { TypeTable = typeTable, TypeModel = typeModel, InboundClientZone = clientZone, } }; serverZone.AddClient(i + 1, channel); return(clientZone); }).ToArray(); serverZone.RunAction(zone => { zone.Spawn(typeof(ISpaceShip), 0, EntityFlags.AnyoneCanControl); }); var cship1A = (ClientSpaceShip)clientZones[0].GetEntity(1); var cship1B = (ClientSpaceShip)clientZones[1].GetEntity(1); Console.WriteLine($"cship1A.Score = {cship1A.Data.Score}"); clientZones[0].RunAction(_ => cship1A.Say("Hello")); Console.WriteLine($"cship1A.Score = {cship1A.Data.Score}"); clientZones[0].RunAction(_ => cship1A.Stop(1, 2)); clientZones[1].RunAction(_ => { cship1B.Say("World"); cship1B.Shoot(1, 2, 3, 4); }); }