Beispiel #1
0
        void Awake()
        {
            client = new NetManager(this);
            client.Start();

            processor = PacketUtils.CreateProcessor();

            processor.Subscribe <ClientID>(
                (packet) =>
            {
                clientID    = packet.ID;
                clientIDSet = true;
            },
                () => new ClientID()
                );
            processor.Subscribe <WorldInitPacket>(NotifyPacketListeners <WorldInitPacket>, () => new WorldInitPacket());
            processor.Subscribe <WorldChunkPacket>(NotifyPacketListeners <WorldChunkPacket>, () => new WorldChunkPacket());
            //processor.Subscribe<StateChangePacket>(NotifyPacketListeners<StateChangePacket>, () => new StateChangePacket());
            processor.Subscribe <NetCreatePacket>(NotifyPacketListeners <NetCreatePacket>, () => new NetCreatePacket());
            processor.Subscribe <NetUpdatePacket>(NotifyPacketListeners <NetUpdatePacket>, () => new NetUpdatePacket());
            processor.Subscribe <NetDestroyPacket>(NotifyPacketListeners <NetDestroyPacket>, () => new NetDestroyPacket());

            //eventTable = new Dictionary<Type, List<Action<object>>>();
            eventTable = new EventTable <object>();
        }
        void Start()
        {
            writer = new NetDataWriter();

            // Start the server on port 5000
            server = new NetManager(this);
            server.Start(5000);
            server.DiscoveryEnabled = true;
            server.UpdateTime       = 15;

            connectedClients = new Dictionary <int, NetPeer>();
            clientVersions   = new Dictionary <int, int>();

            stateManager = new WorldStateManager(this, Constants.WORLD_SIZE);

            processor = PacketUtils.CreateProcessor();
            //processor.Subscribe<UpdatePacket, NetPeer>(OnUpdatePacket, () => new UpdatePacket());
            processor.Subscribe <ClientRequestPacket, NetPeer>(OnClientRequest, () => new ClientRequestPacket());
        }