/// <summary> /// Called when host/client receives a NatIntroduction message from a master server /// </summary> private void HandleNatIntroduction(int ptr) { VerifyNetworkThread(); // read intro NetIncomingMessage tmp = SetupReadHelperMessage(ptr, 1000); // never mind length byte hostByte = tmp.ReadByte(); IPEndPoint remoteInternal = tmp.ReadIPEndpoint(); IPEndPoint remoteExternal = tmp.ReadIPEndpoint(); string token = tmp.ReadString(); bool isHost = (hostByte != 0); LogDebug("NAT introduction received; we are designated " + (isHost ? "host" : "client")); NetOutgoingMessage punch; if (!isHost && m_configuration.IsMessageTypeEnabled(NetIncomingMessageType.NatIntroductionSuccess) == false) { return; // no need to punch - we're not listening for nat intros! } // send internal punch punch = CreateMessage(1); punch.m_messageType = NetMessageType.NatPunchMessage; punch.Write(hostByte); punch.Write(token); m_unsentUnconnectedMessages.Enqueue(new NetTuple <IPEndPoint, NetOutgoingMessage>(remoteInternal, punch)); // send external punch punch = CreateMessage(1); punch.m_messageType = NetMessageType.NatPunchMessage; punch.Write(hostByte); punch.Write(token); m_unsentUnconnectedMessages.Enqueue(new NetTuple <IPEndPoint, NetOutgoingMessage>(remoteExternal, punch)); }
/// <summary> /// Reads the transport into the contents of this type. /// </summary> public void ReadPayload(NetIncomingMessage message) { Identity = message.ReadString(); NovaId = message.ReadString(); PasswordHash = message.ReadString(); PublicEndPoint = message.ReadIPEndpoint(); PrivateEndPoint = message.ReadIPEndpoint(); }
private void HandleRequestIntroduction(NetIncomingMessage msg) { IPEndPoint clientInternal = msg.ReadIPEndpoint(); long hostId = msg.ReadInt64(); string token = msg.ReadString(); Object[] elist; if (registeredHosts.TryGetValue(hostId, out elist)) { peer.Introduce( (IPEndPoint) elist[0], (IPEndPoint) elist[1], clientInternal, msg.SenderEndpoint, token ); } else { Console.WriteLine("Client requested introduction to nonlisted host!"); } }
private void HandleRegisterHost(NetIncomingMessage inc) { var id = inc.ReadInt64(); var name = inc.ReadString(); var population = inc.ReadUInt16(); var maxPopulation = inc.ReadUInt16(); var guid = inc.ReadString(); var endpoint = inc.ReadIPEndpoint(); var game = inc.ReadInt32(); //if (manager.Register(id, new Guid(guid))) { registeredHosts[id] = new Object[] { endpoint, inc.SenderEndpoint, name, population, maxPopulation, NetTime.Now, game }; } }