Exemple #1
0
        static void SERVER_OnClientConnected(ConnectedClient client)         // this will NOT run in the main thread
        {
            ThreadSafeDebug.Log("Client connected from " + client.TcpConnection.RemoteEndPoint.ToString());

            string levelPath = LevelManager.Instance.GetCurrentLevelDescription().LevelJSONPath;

            byte[] bytes = File.ReadAllBytes(levelPath);
            MapSendingMessge.SendTo(bytes, client.ClientNetworkID);             // send map to other client

            ushort playerID = GetNextPlayerID();

            SetLocalPlayerMessage.SendTo(playerID, client.ClientNetworkID);

            var createdPlayerInfo = new PlayerConnectedMessage.CreatedPlayerInfo()
            {
                CharacterModelOverrideType = EnemyType.None,
                PlayerColor    = HumanFactsManager.Instance.FavouriteColors[HumanFactsManager.Instance.GetRandomColorIndex()].ColorValue,
                PlayerID       = playerID,
                PlayerUpgrades = new Dictionary <UpgradeType, int>()
            };

            PlayerConnectMessage.Send(createdPlayerInfo);

            var spawnPlayerMessage = new SpawnPlayerMessage.SpawnedPlayerInfo()
            {
                PlayerID = playerID,
                Position = new Vector3(0f, 10f, 0f),
                Rotation = 0f
            };

            SpawnPlayerMessage.Send(spawnPlayerMessage);
        }
Exemple #2
0
        public static void RegisterNetworkMessageHandelers()
        {
            Mod owner = Main.Instance;

            MapSendingMessge = new MapSendingMessge();
            NetworkManager.AddNetworkMessage(MapSendingMessge, owner);

            PlayerConnectMessage = new PlayerConnectedMessage();
            NetworkManager.AddNetworkMessage(PlayerConnectMessage, owner);

            SpawnPlayerMessage = new SpawnPlayerMessage();
            NetworkManager.AddNetworkMessage(SpawnPlayerMessage, owner);

            SetLocalPlayerMessage = new SetLocalPlayerMessage();
            NetworkManager.AddNetworkMessage(SetLocalPlayerMessage, owner);

            DebugMessage = new DebugMessage();
            NetworkManager.AddNetworkMessage(DebugMessage, owner);
        }