Ejemplo n.º 1
0
    static void VerifyRoleHashesAndSendClientList(UdpClient sender, string playerName, string[] roleHashes)
    {
        // TODO: verify the role hashes

        if (roleHashes.Length < LoadedRoleHashes.Count)
        {
            NetBase.WriteDebug($"Received role hash list from {sender.EndPoint as IPEndPoint} \"{playerName}\" has less roles than the server, impossible to verify roles.");
            ConnectedPlayers.Remove(sender.GetPlayer());
            sender.Disconnect();
            return;
        }

        for (int i = 0; i < LoadedRoleHashes.Count; ++i)
        {
            string hash = LoadedRoleHashes[i];
            if (!roleHashes.Contains(hash))
            {
                NetBase.WriteDebug($"Client {sender.EndPoint as IPEndPoint} \"{playerName}\" missing hash {hash} corresponding to role {LoadedRoleTypes.Values.ElementAt(i).AssemblyQualifiedName}!");
                ConnectedPlayers.Remove(sender.GetPlayer());
                sender.Disconnect();
                return;
            }
            else
            {
                NetBase.WriteDebug($"{sender.EndPoint as IPEndPoint}: {hash} {LoadedRoleTypes.Values.ElementAt(i).AssemblyQualifiedName} success!");
            }
        }

        NetWerewolfPlayer playerRef = sender.GetPlayer();

        playerRef.Name             = playerName;
        playerRef.RoleListVerified = true;

        GameInfo.AddPlayerAndAssignId(playerRef);

        ServerInstance.Send(5, 0u, GenRandomJoinMessage(playerName));

        if (GameInfo.Players.Count == 1)
        {
            playerRef.IsHost = true;
            sender.Send(199, true); //SetHost(UdpClient, bool)
            ServerInstance.Send(5, 0u, $"{playerRef.Name} is now the game master.");
        }

        sender.Send(200, playerRef.PlayerID, ConnectedPlayers.Select(p => p.PlayerID).ToArray(), ConnectedPlayers.Select(p => p.Name).ToArray()); // ReceivePlayerList(uint, uint[], string[]);

        foreach (string hash in ActiveRoleHashes)
        {
            sender.Send(190, hash, false);
        }

        ServerInstance.Send(1, playerRef.PlayerID, playerRef.Name); // UpdateClientInfo(uint, string)
    }
Ejemplo n.º 2
0
 /// <summary>
 /// Disconnects from the remote host.
 /// </summary>
 public UdpClientHelper Disconnect()
 {
     udpClient.Disconnect();
     udpClient.MessageReceived       -= udpClient_MessageReceived;
     udpClient.ConnectedStateChanged -= udpClient_ConnectedStateChanged;
     return(this);
 }
Ejemplo n.º 3
0
        private static void DisconnectUDPClient(UdpClient udpClient)
        {
            udpClient.Disconnect();

            udpClient.ReceiveDataComplete   -= UdpClient_ReceiveDataComplete;
            udpClient.ReceiveDataException  -= UdpClient_ReceiveDataException;
            udpClient.ConnectionTerminated  -= UdpClient_ConnectionTerminated;
            udpClient.ConnectionException   -= UdpClient_ConnectionException;
            udpClient.ConnectionEstablished -= UdpClient_ConnectionEstablished;
            udpClient.ConnectionAttempt     -= UdpClient_ConnectionAttempt;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Attempts to disconnect from data input source.
        /// </summary>
        protected override void AttemptDisconnection()
        {
            // Stops listening for UDP data
            if (m_client != null)
            {
                m_client.Disconnect();
            }

            // Stops historian packet parser
            if (m_parser != null)
            {
                m_parser.Stop();
            }
        }
Ejemplo n.º 5
0
    public static void CloseClientInstance()
    {
        try
        {
            if (udpCl != null)
            {
                udpCl.Disconnect();
                udpCl = null;

                if (udpSv == null)
                {
                    players = null;
                }
            }
        }
        catch (Exception ex)
        {
            Debug.LogError(ex.ToString());
        }
    }
Ejemplo n.º 6
0
        /// <summary>
        /// Stops the <see cref="DataListener"/>.
        /// </summary>
        public void @Stop()
        {
            OnListenerStopping();

            // Abort async startup process if it is running.
            if (m_startupThread != null)
            {
                m_startupThread.Abort();
            }

            // Prevent communication clients from reconnecting.
            m_listenerStopping = true;

            m_tcpServer.Stop();
            m_tcpClient.Disconnect();
            m_udpClient.Disconnect();
            m_parser.Stop();
            m_totalBytesReceived   = 0;
            m_totalPacketsReceived = 0;

            OnListenerStopped();
        }