GodotTicTacToe/scripts/net/ConnectionList.cs

54 lines
1.4 KiB
C#
Raw Normal View History


using System.Collections.Generic;
using Util;
namespace Network {
public class ConnectionList {
private Peer Peer;
2017-11-22 21:56:43 +01:00
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) {
2017-11-22 21:56:43 +01:00
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;
}
}
2017-11-25 12:20:59 +01:00
return Optional<Connection>.None;
}
2017-11-25 12:34:17 +01:00
public Optional<Connection> GetOriginal(string address, int port) {
return GetOriginal(new Connection(address, port));
}
}
}