public void OnNetworkReceiveUnconnected(NetEndPoint remoteEndPoint, NetDataReader reader, UnconnectedMessageType messageType) { Console.WriteLine("[Server] ReceiveUnconnected {0}. From: {1}. Data: {2}", messageType, remoteEndPoint, reader.GetString(100)); NetDataWriter wrtier = new NetDataWriter(); wrtier.Put("SERVER DISCOVERY RESPONSE :)"); Server.SendDiscoveryResponse(wrtier, remoteEndPoint); }
public void OnNetworkReceiveUnconnected(NetEndPoint remoteEndPoint, NetDataReader reader, UnconnectedMessageType messageType) { if (messageType == UnconnectedMessageType.DiscoveryRequest) { Debug.Log("[SERVER] Received discovery request. Send discovery response"); _netServer.SendDiscoveryResponse(new byte[] {1}, remoteEndPoint); } }
public void OnNetworkReceiveUnconnected(NetEndPoint remoteEndPoint, NetDataReader reader, UnconnectedMessageType messageType) { Console.WriteLine("[Client] ReceiveUnconnected {0}. From: {1}. Data: {2}", messageType, remoteEndPoint, reader.GetString(100)); if (messageType == UnconnectedMessageType.DiscoveryResponse) { Client.Connect(remoteEndPoint); } }
public void OnNetworkReceiveUnconnected(NetEndPoint remoteEndPoint, NetDataReader reader, UnconnectedMessageType messageType) { if (messageType == UnconnectedMessageType.DiscoveryResponse && _netClient.Peer == null) { Debug.Log("[CLIENT] Received discovery response. Connecting to: " + remoteEndPoint); _netClient.Connect(remoteEndPoint); } }
public void OnNetworkReceive(NetPeer peer, NetDataReader reader) { _newBallPosX = reader.GetFloat(); var pos = _clientBall.transform.position; _oldBallPosX = pos.x; pos.x = _newBallPosX; _clientBall.transform.position = pos; _lerpTime = 0f; }
public void OnNetworkReceive(NetPeer peer, NetDataReader reader) { if (reader.AvailableBytes == 13218) { Console.WriteLine("[{0}] TestFrag: {1}, {2}", peer.Handler.LocalEndPoint.Port, reader.Data[0], reader.Data[13217]); } else { int type = reader.GetInt(); int num = reader.GetInt(); _messagesReceivedCount++; Console.WriteLine("[{0}] CNT: {1}, TYPE: {2}, NUM: {3}", peer.Handler.LocalEndPoint.Port, _messagesReceivedCount, type, num); } }
/// <summary> /// Считываем структуру в Reader(обертка над массивом байт) /// Только для структур(MarshalAs for pointers) /// </summary> public static bool FromReader <T>(this LiteNetLib.Utils.NetDataReader reader, out T obj, bool acceptOffset = true) { try { int size = Marshal.SizeOf(typeof(T)); obj = reader.RawData.ToStruct <T>(reader.Position); if (acceptOffset) { reader.AddOffset(size); } return(true); } catch (Exception e) { Debug.LogError("FromReader is bad=" + e); } obj = default(T); return(false); }
private void HandleNatIntroductionRequest(NetEndPoint senderEndPoint, NetDataReader dr) { NetEndPoint localEp = dr.GetNetEndPoint(); string token = dr.GetString(MaxTokenLength); lock (_requestEvents) { _requestEvents.Enqueue(new RequestEventData { LocalEndPoint = localEp, RemoteEndPoint = senderEndPoint, Token = token }); } }
internal void ProcessMessage(NetEndPoint senderEndPoint, PacketProperty property, byte[] data) { NetDataReader dr = new NetDataReader(data); switch (property) { case PacketProperty.NatIntroductionRequest: //We got request and must introduce HandleNatIntroductionRequest(senderEndPoint, dr); break; case PacketProperty.NatIntroduction: //We got introduce and must punch HandleNatIntroduction(dr); break; case PacketProperty.NatPunchMessage: //We got punch and can connect HandleNatPunch(senderEndPoint, dr); break; } }
private void HandleNatPunch(NetEndPoint senderEndPoint, NetDataReader dr) { byte fromHostByte = dr.GetByte(); if (fromHostByte != HostByte && fromHostByte != ClientByte) { //garbage return; } //Read info string additionalInfo = dr.GetString(MaxTokenLength); NetUtils.DebugWrite(ConsoleColor.Green, "[NAT] punch received from {0} - additional info: {1}", senderEndPoint, additionalInfo); //Release punch success to client; enabling him to Connect() to msg.Sender if token is ok lock (_successEvents) { _successEvents.Enqueue(new SuccessEventData { TargetEndPoint = senderEndPoint, Token = additionalInfo }); } }
private void HandleNatIntroduction(NetDataReader dr) { // read intro byte hostByte = dr.GetByte(); NetEndPoint remoteInternal = dr.GetNetEndPoint(); NetEndPoint remoteExternal = dr.GetNetEndPoint(); string token = dr.GetString(MaxTokenLength); NetUtils.DebugWrite(ConsoleColor.Cyan, "[NAT] introduction received; we are designated " + (hostByte == HostByte ? "host" : "client")); NetDataWriter writer = new NetDataWriter(); // send internal punch writer.Put(hostByte); writer.Put(token); _netBase.SendRaw(NetPacket.CreateRawPacket(PacketProperty.NatPunchMessage, writer), remoteInternal); NetUtils.DebugWrite(ConsoleColor.Cyan, "[NAT] internal punch sent to " + remoteInternal); // send external punch writer.Reset(); writer.Put(hostByte); writer.Put(token); _netBase.SendRaw(NetPacket.CreateRawPacket(PacketProperty.NatPunchMessage, writer), remoteExternal); NetUtils.DebugWrite(ConsoleColor.Cyan, "[NAT] external punch sent to " + remoteExternal); }
public void OnNetworkReceive(NetPeer peer, NetDataReader reader) { }
/// <summary> /// Reads one packet from NetDataReader and calls OnReceive delegate /// </summary> /// <param name="reader">NetDataReader with packet</param> /// <param name="userData">Argument that passed to OnReceivedEvent</param> /// <exception cref="ParseException">Malformed packet</exception> public void ReadPacket(NetDataReader reader, object userData) { GetCallbackFromData(reader)(reader, userData); }
public void OnNetworkReceive(NetPeer peer, NetDataReader reader) { //echo peer.Send(reader.Data, SendOptions.ReliableUnordered); //fragment log if (reader.AvailableBytes == 13218) { Console.WriteLine("[Server] TestFrag: {0}, {1}", reader.Data[0], reader.Data[13217]); } }
public override void Read(TClass inf, NetDataReader r) { Setter(inf, _reader(r)); }
void INetEventListener.OnNetworkReceiveUnconnected(NetEndPoint remoteEndPoint, NetDataReader reader, UnconnectedMessageType messageType) { if (NetworkReceiveUnconnectedEvent != null) NetworkReceiveUnconnectedEvent(remoteEndPoint, reader, messageType); }
void INetEventListener.OnNetworkReceive(NetPeer peer, NetDataReader reader) { if (NetworkReceiveEvent != null) NetworkReceiveEvent(peer, reader); }
public override void ReadArray(T inf, NetDataReader r) { SetterArr(inf, r.GetIntArray()); }
public override void Read(T inf, NetDataReader r) { Setter(inf, r.GetInt()); }
public override void Read(TClass inf, NetDataReader r) { _p.Deserialize(r); Setter(inf, _p); }
public void OnNetworkReceiveUnconnected(NetEndPoint remoteEndPoint, NetDataReader reader, UnconnectedMessageType messageType) { Console.WriteLine("[Server] ReceiveUnconnected: {0}", reader.GetString(100)); }
/// <summary> /// Reads one packet from NetDataReader and calls OnReceive delegate /// </summary> /// <param name="reader">NetDataReader with packet</param> /// <exception cref="ParseException">Malformed packet</exception> public void ReadPacket(NetDataReader reader) { ReadPacket(reader, null); }
public void OnNetworkReceiveUnconnected(NetEndPoint remoteEndPoint, NetDataReader reader, UnconnectedMessageType messageType) { }
/// <summary> /// Register nested property type /// </summary> /// <typeparam name="T">INetSerializable structure</typeparam> /// <returns>True - if register successful, false - if type already registered</returns> //public bool RegisterNestedType<T>() where T : struct, INetSerializable //{ // return _netSerializer.RegisterNestedType<T>(); //} /// <summary> /// Register nested property type /// </summary> /// <param name="writeDelegate"></param> /// <param name="readDelegate"></param> /// <returns>True - if register successful, false - if type already registered</returns> //public bool RegisterNestedType<T>(Action<NetDataWriter, T> writeDelegate, Func<NetDataReader, T> readDelegate) //{ // return _netSerializer.RegisterNestedType<T>(writeDelegate, readDelegate); //} /// <summary> /// Register nested property type /// </summary> /// <typeparam name="T">INetSerializable class</typeparam> /// <returns>True - if register successful, false - if type already registered</returns> //public bool RegisterNestedType<T>(Func<T> constructor) where T : class, INetSerializable //{ // return _netSerializer.RegisterNestedType(constructor); //} /// <summary> /// Reads all available data from NetDataReader and calls OnReceive delegates /// </summary> /// <param name="reader">NetDataReader with packets data</param> public void ReadAllPackets(NetDataReader reader) { ReadAllPackets(reader, null); }