コード例 #1
0
        public void ListenForConnectionRequests()
        {
            Console.WriteLine("Listening for connection requests...");

            while (listener != null) {
                if (listener.Pending()) {
                    Connection conn = new Connection(listener.AcceptTcpClient(), false);
                    ConnectionsRepository.AddConnection(conn, false);
                    conn.DataTransfered += DataProcessor.ProcessData;
                    conn.InitializeDataListener();
                    Console.WriteLine("New connection accepted.");
                }
            }
        }
コード例 #2
0
        public static void ProcessData(Connection conn, DataTransfer transfer)
        {
            if (conn == null || transfer == null)
                return;

            if (transfer is AuthenticationRequest) {
                AuthenticationRequest authenticationRequest = (AuthenticationRequest)transfer;
                PlayerAccount player = new PlayerAccount(authenticationRequest.Username, authenticationRequest.Password);
                string authenticationResponseMessage = AccountFileHandler.ReadAccount(player);

                if (authenticationResponseMessage == null)
                    PlayerHandler.AddPlayer(player);

                conn.SendData(new AuthenticationResponse(authenticationResponseMessage));
            }
        }
コード例 #3
0
 public static void ProcessData(Connection conn, DataTransfer transfer)
 {
     if (conn == null || transfer == null)
         return;
 }
コード例 #4
0
 public static void RemoveConnection(Connection connection)
 {
     connections.Remove(connection);
 }
コード例 #5
0
 public static void AddConnection(Connection connection, bool client)
 {
     connections.Add(connection, client);
 }