Exemplo n.º 1
0
        /// <summary>
        /// Event Handler for Application Event UnregisterHost
        /// </summary>
        /// <param name="netMsg"></param>
        void OnUnregisterHost(NetworkMessage netMsg)
        {
            if (IsConnectionVerified(netMsg.conn))
            {
                MessageTypes.CustomEventType result = MessageTypes.CustomEventType.UnknownError;
                var msg = netMsg.ReadMessage <MessageTypes.UnregisterHostMessage>();

                // find the instance
                if (ConnectedHosts.RemoveHost(msg.hostName, msg.hostPassword))
                {
                    result = MessageTypes.CustomEventType.NoError;
                }
                else
                {
                    Debug.LogError("<MasterServer> OnHostUnregister Host not found: " + msg.hostName);
                }

                if (MasterServer.ViewDebugMessages)
                {
                    Debug.Log("<MasterServer> OnHostUnregister result: " + result);
                }

                // tell other hosts?

                var response = new MessageTypes.UnregisterHostResponseMessage();
                response.resultCode = (int)result;
                netMsg.conn.Send(MessageTypes.UnregisterHostResponse, response);

                UpdateUI();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Event Handler for System Event Disconnect
        /// </summary>
        /// <param name="netMsg"></param>
        void OnHostDisconnect(NetworkMessage netMsg)
        {
            Debug.Log("<MasterServer> Host Disconnected: " + netMsg.conn.connectionId);
            RemoveConnection(netMsg.conn);

            // remove the associated host
            foreach (var host in ConnectedHosts.Connected.Values)
            {
                // a network message does not have a custom identifier, so we have to check for matching connectionID
                if (host.ConnectionId == netMsg.conn.connectionId)
                {
                    // tell other players?

                    // remove room
                    ConnectedHosts.RemoveHost(host.HostName, "", true);

                    Debug.Log("<MasterServer> Host Instance [" + host.HostName + "] disconnected");
                    break;
                }
            }
            UpdateUI();
        }