Ejemplo n.º 1
0
        /// <summary>
        /// Sets up a client with server data
        /// </summary>
        /// <param name="data">incoming server data</param>
        public static void SetupAsClient(InitialNetworkData data)
        {
            Instance.MaxPlayers = data.MaxPlayers;
            Instance.PlayerId = data.PlayerId;

            Instance.PlayerNames = data.PlayerNames;
            Instance.PlayerNames[Instance.PlayerId] = data.PlayerName;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Adds to a server's data when a client connects
        /// </summary>
        /// <param name="data">incoming client data</param>
        public static InitialNetworkData SetupClientData(InitialNetworkData data)
        {
            ++Instance.PlayerIdIndex;
            Instance.PlayerNames[Instance.PlayerIdIndex] = data.PlayerName;

            return new InitialNetworkData()
            {
                MaxPlayers = Instance.MaxPlayers,
                PlayerId = Instance.PlayerIdIndex,
                PlayerNames = Instance.PlayerNames,
            };
        }
Ejemplo n.º 3
0
        private bool InitialHandshake()
        {
            BinaryFormatter formatter = new BinaryFormatter();
            var stream = thisClient.Client.GetStream();

            InitialNetworkData initialData = new InitialNetworkData()
            {
                PlayerName = MechanicSingleton.Instance.PlayerName,
            };

            formatter.Serialize(stream,initialData);
            var response = (InitialNetworkData)formatter.Deserialize(stream);

            this.thisClient.ClientId = response.PlayerId;

            recvThread.Start();

            MechanicSingleton.SetupAsClient(response);

            if (OnServerConnected != null)
            {
                OnServerConnected(this, initialData);
            }
            return true;
        }