Fixed two NPE's

This commit is contained in:
Sofia 2017-11-22 22:56:43 +02:00
parent 4f75801ed8
commit 650493f74e
2 changed files with 10 additions and 4 deletions

View File

@ -6,7 +6,11 @@ namespace Network {
public class ConnectionList {
private Peer Peer;
private List<Connection> Connections;
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] {
@ -25,7 +29,8 @@ namespace Network {
}
public bool Contains(Connection conn) {
foreach (Connection inList in Connections) {
for (int i = 0; i < Connections.Count; i++) {
Connection inList = Connections[i];
if (inList.Equals(conn)) {
return true;
}

View File

@ -13,10 +13,11 @@ namespace Network {
private static byte[] ConfirmationBytes = { 154, 211 };
public ConnectionList ConnectionList = new ConnectionList();
public ConnectionList ConnectionList;
public Peer(PacketPeerUDP packetPeer) {
PacketPeer = packetPeer;
ConnectionList = new ConnectionList(this);
}
public abstract void Initialize(string address, int port);
@ -65,7 +66,6 @@ namespace Network {
int Port = PacketPeer.GetPacketPort();
PacketBuffer PB = PacketBuffer.FromByteBuffer(Buffer);
if (PB.Length > ConfirmationBytes.Length) {
bool Confirmed = true;
foreach (byte B in ConfirmationBytes) {
@ -75,6 +75,7 @@ namespace Network {
break;
}
}
GD.print("Wow nice");
if (Confirmed) {
Connection conn = new Connection(Address, Port);
Singleton.ConnectionList.AddConnection(conn);