GodotTicTacToe/scripts/net/ConnectionList.cs

45 lines
1.1 KiB
C#
Raw Normal View History


using System.Collections.Generic;
using Util;
namespace Network {
public class ConnectionList {
private Peer Peer;
private List<Connection> Connections;
public int Length { get { return Connections.Count; } }
public Connection this[int i] {
get {
return Connections[i];
}
}
public bool AddConnection(Connection conn) {
if (!Contains(conn)) {
Connections.Add(conn);
Peer.Connected(conn);
return true;
}
return false;
}
public bool Contains(Connection conn) {
foreach (Connection inList in Connections) {
if (inList.Equals(conn)) {
return true;
}
}
return false;
}
public Optional<Connection> GetOriginal(Connection conn) {
foreach (Connection inList in Connections) {
if (inList.Equals(conn)) {
return inList;
}
}
return null;
}
}
}