Exemple #1
0
        public Server()
        {
            serializer = new Serializer();
            MessageExtensions.Setup(serializer);
            processor = new Processor(serializer);

            manager = new NetManager(this, 128);
            manager.PingInterval      = Config.pingInterval;
            manager.DisconnectTimeout = Config.disconnectTimeout;
            manager.MergeEnabled      = true;
            // manager.SimulateLatency = true;
            // manager.SimulatePacketLoss = true;

            AddPeerHandler <ServerJoinRequest>(Process);
            AddClientHandler <ClientGameReload>(Process);
            AddClientHandler <ClientPlayerMovement>(Process);
            AddClientHandler <ClientPlayerVitals>(Process);
            AddClientHandler <ClientPlayerDeath>(Process);
            AddClientHandler <ClientVehicleMovement>(Process);
            AddClientHandler <ClientVehicleDocking>(Process);
            AddClientHandler <ClientVehicleKill>(Process);
            AddClientHandler <ClientVehicleColorChange>(Process);
            AddClientHandler <ClientVehicleNameChange>(Process);
            AddClientHandler <ClientCyclopsHorn>(ProcessAuthPass);
            AddClientHandler <ClientCyclopsState>(Process);
            AddClientHandler <ClientCreatureUpdate>(ProcessAuthPass);
            AddClientHandler <ClientLiveMixinChange>(Process);
            AddClientHandler <ClientBuildConstruct>(ProcessBuildPass);
            AddClientHandler <ClientBuildConstructChange>(ProcessBuildPass);
            AddClientHandler <ClientBuildDeconstructBase>(ProcessBuildPass);
            AddClientHandler <ClientItemDropped>(Process);
            AddClientHandler <ClientItemGrabbed>(Process);
            AddClientHandler <ClientItemLabel>(Process);
            AddClientHandler <ClientResourceBreak>(Process);
            AddClientHandler <ClientObjectUpdate>(Process);
            AddClientHandler <ClientFabricatorStart>(ProcessAuthPass);
            AddClientHandler <ClientFabricatorPickup>(ProcessAuthPass);
            AddClientHandler <ClientConstructorCraft>(Process);
            AddClientHandler <ClientOpenableStateChanged>(ProcessAuthPass);
            AddClientHandler <ClientEquipmentAddItem>(Process);
            AddClientHandler <ClientEquipmentRemoveItem>(Process);
            AddClientHandler <ClientContainerAddItem>(Process);
            AddClientHandler <ClientContainerRemoveItem>(Process);
            AddClientHandler <ClientScanProgress>(ProcessUnlock);
            AddClientHandler <ClientScanEncyclopedia>(ProcessUnlock);
            AddClientHandler <ClientStoryGoal>(ProcessUnlock);
            AddClientHandler <ClientScanKnownTech>(ProcessUnlock);
            AddClientHandler <ClientCommandSpawn>(Process);
            AddClientHandler <ClientCommandChat>(Process);
            AddClientHandler <ClientToggleLight>(ProcessAuthPass);
            AddClientHandler <ClientPowerChange>(Process);
            AddClientHandler <ServerSaveRequest>(Process);
            AddClientHandler <ServerSyncRequest>(Process);

            foreach (var type in typeof(Message).Assembly.GetTypes())
            {
                if (typeof(Message).IsAssignableFrom(type) && !type.IsAbstract && type.IsClass)
                {
                    if (processor.Has(type) == false)
                    {
                        Log.Warn("Unhandled message type: " + type.FullName);
                    }
                }
            }

            Load();
        }
Exemple #2
0
        public void Awake()
        {
            main = this;
            DontDestroyOnLoad(this);

            serializer = new Serializer();
            MessageExtensions.Setup(serializer);
            processor = new Processor(serializer);

            self          = new PlayerJoinInfo();
            remotePlayers = new Dictionary <int, RemotePlayer>();

            AddHostHandler <ServerJoinInfo>(Process);
            AddHostHandler <ServerJoinReject>(Process);
            AddHostHandler <ServerTimeUpdate>(Process);
            AddHostHandler <ServerSyncRequest>(Process);
            AddHostHandler <ServerSyncFinish>(Process);
            AddHostHandler <ClientPlayerJoin>(Process);
            AddHostHandler <ClientPlayerLeave>(Process);
            AddHostHandler <ClientPlayerDeath>(Process);
            AddHostHandler <ClientPlayerMovement>(Process);
            AddHostHandler <ClientPlayerVitals>(Process);
            AddHostHandler <ClientVehicleMovement>(Process);
            AddHostHandler <ClientVehicleKill>(Process);
            AddHostHandler <ClientVehicleColorChange>(Process);
            AddHostHandler <ClientVehicleNameChange>(Process);
            AddHostHandler <ClientCreatureUpdate>(Process);
            AddHostHandler <ClientLiveMixinChange>(Process);
            AddHostHandler <ClientBuildConstruct>(Process);
            AddHostHandler <ClientBuildConstructChange>(Process);
            AddHostHandler <ClientBuildDeconstructBase>(Process);
            AddHostHandler <ClientItemDropped>(Process);
            AddHostHandler <ClientItemGrabbed>(Process);
            AddHostHandler <ClientFabricatorStart>(Process);
            AddHostHandler <ClientFabricatorPickup>(Process);
            AddHostHandler <ClientOpenableStateChanged>(Process);
            AddHostHandler <ClientObjectUpdate>(Process);
            AddHostHandler <ClientEquipmentAddItem>(Process);
            AddHostHandler <ClientEquipmentRemoveItem>(Process);
            AddHostHandler <ClientContainerAddItem>(Process);
            AddHostHandler <ClientContainerRemoveItem>(Process);
            AddHostHandler <ClientScanProgress>(Process);
            AddHostHandler <ClientScanEncyclopedia>(Process);
            AddHostHandler <ClientStoryGoal>(Process);
            AddHostHandler <ClientScanKnownTech>(Process);
            AddHostHandler <ClientVehicleDocking>(Process);
            AddHostHandler <ClientConstructorCraft>(Process);
            AddHostHandler <ClientCommandSpawn>(Process);
            AddHostHandler <ClientCommandChat>(Process);
            AddHostHandler <ClientToggleLight>(Process);
            AddHostHandler <ClientPowerChange>(Process);
            AddHostHandler <ClientCyclopsHorn>(Process);
            AddHostHandler <ClientCyclopsState>(Process);
            AddHostHandler <ClientItemLabel>(Process);

            foreach (var type in typeof(Message).Assembly.GetTypes())
            {
                if (typeof(Message).IsAssignableFrom(type) && !type.IsAbstract && type.IsClass)
                {
                    if (processor.Has(type) == false)
                    {
                        Log.Warn("Unhandled message type: " + type.FullName);
                    }
                }
            }

            playerChat      = gameObject.EnsureComponent <PlayerChat>();
            playerChatInput = gameObject.EnsureComponent <PlayerChatInput>();
            playerChatInput.SetManager(playerChat);

            typeof(DevConsole).GetField("keyCodes", BindingFlags.NonPublic | BindingFlags.Static).SetValue(null, new KeyCode[] { KeyCode.BackQuote });
        }