GodotTicTacToe/scripts/net/ConnectionList.cs
2017-11-22 22:56:43 +02:00

50 lines
1.3 KiB
C#

using System.Collections.Generic;
using Util;
namespace Network {
public class ConnectionList {
private Peer Peer;
private List<Connection> Connections = new List<Connection>();
public ConnectionList(Peer peer) {
Peer = peer;
}
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) {
for (int i = 0; i < Connections.Count; i++) {
Connection inList = Connections[i];
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;
}
}
}