Пример #1
0
        /// <summary>
        ///     Call when a client connects
        /// </summary>
        /// <param name="conn"></param>
        internal static void OnServerAddClient(NetworkConnection conn)
        {
            //Sent to client the server config
            conn.Send(TCNetworkManager.Instance.serverConfig);

            //Lets just hope our transport never assigns the first connection max value of int
            if (closeServerOnFirstClientDisconnect && firstConnectionId == int.MaxValue)
            {
                firstConnectionId = conn.connectionId;
            }

            Logger.Info(
                "Client from '{Address}' connected with the connection ID of {ConnectionID}.",
                conn.address, conn.connectionId);
            IUser user = netManager.tcAuthenticator.GetAccount(conn.connectionId);

            if (user != null)
            {
                ServerChat.SendChatMessage("<b>Join</b>", user.UserName);
            }
        }
Пример #2
0
        /// <summary>
        ///     Call when a client disconnects
        /// </summary>
        /// <param name="conn"></param>
        internal static void OnServerRemoveClient(NetworkConnection conn)
        {
            NetworkServer.DestroyPlayerForConnection(conn);
            if (netManager == null)
            {
                CloseServerIfNecessary(conn);
                return;
            }

            if (netManager.tcAuthenticator != null)
            {
                IUser user = netManager.tcAuthenticator.GetAccount(conn.connectionId);
                if (user != null)
                {
                    ServerChat.SendChatMessage("<b>Disconnect</b>", user.UserName);
                }
            }

            netManager.tcAuthenticator.OnServerClientDisconnect(conn);
            Logger.Info("Client '{ConnectionId}' disconnected from the server.", conn.connectionId);

            CloseServerIfNecessary(conn);
        }