public void HandleConnectionData(HandshakeMessage type, ByteStreamReader stream, IPEndPoint endpoint) { Console.WriteLine(type); if (type == HandshakeMessage.SYN) { PendingConnectionEntity ce = new PendingConnectionEntity(); ce.m_connectionId = m_connectionId.Allocate(); ce.m_sender = new Connection(); int port = stream.ReadInt(); ce.m_pendingStartTime = DateTime.Now; ce.m_sender.Connect(new IPEndPoint(endpoint.Address, port)); m_pending.Add(ce); HandshakeStepTwo(ce); } else if (type == HandshakeMessage.ACK) { int id = stream.ReadInt(); PendingConnectionEntity chosen = m_pending.FirstOrDefault(x => x.m_connectionId == id); if (chosen != null) { m_pending.Remove(chosen); m_entities[chosen.m_connectionId] = new ConnectionEntity(chosen); Network.Server.World.AddPlayer(chosen.m_connectionId); } } else if (type == HandshakeMessage.Disconnect) { int id = stream.ReadInt(); Disconnect(id, false); } }
public int Add(T val) { int id = m_id.Allocate(); #if UNITY_EDITOR Debug.Assert(m_keys.Count == m_values.Count); #endif m_keys.Add(id); m_values.Add(val); return(id); }