From 650493f74eab07c508991ef39675965341fe7b83 Mon Sep 17 00:00:00 2001 From: teascade Date: Wed, 22 Nov 2017 22:56:43 +0200 Subject: [PATCH] Fixed two NPE's --- scripts/net/ConnectionList.cs | 9 +++++++-- scripts/net/Peer.cs | 5 +++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/scripts/net/ConnectionList.cs b/scripts/net/ConnectionList.cs index 59f6c0f..e3aa642 100644 --- a/scripts/net/ConnectionList.cs +++ b/scripts/net/ConnectionList.cs @@ -6,7 +6,11 @@ namespace Network { public class ConnectionList { private Peer Peer; - private List Connections; + private List Connections = new List(); + + 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; } diff --git a/scripts/net/Peer.cs b/scripts/net/Peer.cs index e984250..430e833 100644 --- a/scripts/net/Peer.cs +++ b/scripts/net/Peer.cs @@ -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);