public static LNSCreateRoomParameters FromReader(NetPacketReader reader) { if (reader.AvailableBytes > 0) { LNSCreateRoomParameters o = new LNSCreateRoomParameters(); try { o.isPublic = reader.GetBool(); if (reader.GetBool()) { o.password = reader.GetString(); } o.filters = LNSJoinRoomFilter.FromReader(reader); o.maxPlayers = reader.GetInt(); o.isQuadTreeAllowed = reader.GetBool(); if (o.isQuadTreeAllowed) { Rect bounds = new Rect(reader.GetFloat(), reader.GetFloat(), reader.GetFloat(), reader.GetFloat()); //bounds.center = new Vector2, reader.GetFloat()); o.quadTreeBounds = bounds; } o.idleLife = reader.GetLong(); } catch { o.isQuadTreeAllowed = false; } return(o); } return(null); }
void SendDepthDataToReceivers(int streamingClientId, NetPacketReader reader) { // Debug.Log("SendDepthData: " + reader.UserDataSize); int frameCount = reader.GetInt(); bool isKeyFrame = reader.GetBool(); int depthWidth = reader.GetInt(); int depthHeight = reader.GetInt(); CompressionMethod compressionMethod = (CompressionMethod)reader.GetInt(); int encodedDepthDataLength = reader.GetInt(); byte[] encodedDepthData = new byte[encodedDepthDataLength]; reader.GetBytes(encodedDepthData, encodedDepthDataLength); _dataWriter.Reset(); _dataWriter.Put((int)NetworkDataType.ReceiveDepthData); _dataWriter.Put(frameCount); _dataWriter.Put(isKeyFrame); _dataWriter.Put(depthWidth); _dataWriter.Put(depthHeight); _dataWriter.Put((int)compressionMethod); _dataWriter.Put(encodedDepthData.Length); _dataWriter.Put(encodedDepthData); foreach (int receiverClientId in _streamingReceivers[streamingClientId]) { _liteNetLibServer.SendData(receiverClientId, _dataWriter, DeliveryMethod.ReliableOrdered); } }
private void RegisterPlayer(NetPacketReader reader) { if (isHost) { var pinf = new PlayerInfo(MyNetworkId, rand.Next(0, 10000000), isHost, "test", new ColorPacket(myColor.r, myColor.g, myColor.b)); InitPlayer(pinf); } else { NetDataWriter writer = new NetDataWriter(); var networkId = reader.GetInt(); var playerId = reader.GetInt(); var ishost = reader.GetBool(); var playerColor = myColor; var pName = myName; MyNetworkId = networkId; var playerInfo = new PlayerInfo(networkId, playerId, ishost, pName, new ColorPacket(playerColor.r, playerColor.g, playerColor.b)); InitPlayer(playerInfo); writer.Put((ushort)1); writer.PutBytesWithLength(playerInfo.ToByteArray()); Send(writer, DeliveryMethod.ReliableOrdered); writer.Reset(); } }
public void OnNetworkReceive(NetPeer peer, NetPacketReader reader, DeliveryMethod deliveryMethod) { recivedSpelarData = new SpelarData { X = reader.GetFloat(), Y = reader.GetFloat(), Attack = reader.GetBool() }; reader.Recycle(); }
void INetEventListener.OnNetworkReceive(NetPeer peer, NetPacketReader reader, DeliveryMethod deliveryMethod) { var isReliable = reader.GetBool(); var data = reader.GetString(); if (isReliable) { ReliableReceived++; } else { UnreliableReceived++; } }
void OnReceivedDepthData(NetPeer peer, NetPacketReader reader) { int frameCount = reader.GetInt(); bool isKeyFrame = reader.GetBool(); int depthWidth = reader.GetInt(); int depthHeight = reader.GetInt(); CompressionMethod compressionMethod = (CompressionMethod)reader.GetInt(); int encodedDepthDataLength = reader.GetInt(); byte[] encodedDepthData = new byte[encodedDepthDataLength]; reader.GetBytes(encodedDepthData, encodedDepthDataLength); OnReceivedDepthData(frameCount, isKeyFrame, depthWidth, depthHeight, compressionMethod, encodedDepthData); }
public void OnNetworkReceive(NetPeer peer, NetPacketReader reader, DeliveryMethod deliveryMethod) { //Check if event is intended to lib or application if (!reader.GetBool()) { //Forward event to app if it's not intended to lib appListener.OnNetworkReceive(peer, reader, deliveryMethod); } switch (reader.GetByte()) { case 0: break; case 1: break; } }
void ReceivePackage(NetPeer peer, NetPacketReader reader, DeliveryMethod deliveryMethod) { client.Statistics.BytesReceived += (ulong)reader.RawDataSize; client.Statistics.PacketsReceived++; NetDataWriter writer = new NetDataWriter(); ushort msgid = reader.GetUShort(); Debug.Log(msgid); switch (msgid) { case 1: //register to server var networkId = reader.GetInt(); var playerId = reader.GetInt(); var isHost = reader.GetBool(); var charId = 0; var playerColor = _myColor; var pName = _myName; MyNetworkId = networkId; IsHost = isHost; InitPlayer(networkId, playerId, pName, isHost, charId, playerColor); writer.Put((ushort)1); writer.Put(playerId); writer.Put(pName); writer.Put(isHost); writer.Put(charId); writer.Put(playerColor.r); writer.Put(playerColor.g); writer.Put(playerColor.b); Send(writer, DeliveryMethod.ReliableOrdered); writer.Reset(); LobbyManager.Instance.NeedUpdate = true; break; case 2: //register new player; var newNetworkId = reader.GetInt(); var newPlayerId = reader.GetInt(); var npName = reader.GetString(); var nIsHost = reader.GetBool(); var newCharId = reader.GetInt(); var newPlayerColor = new Color( reader.GetFloat(), reader.GetFloat(), reader.GetFloat()); InitPlayer(newNetworkId, newPlayerId, npName, nIsHost, newCharId, newPlayerColor); LobbyManager.Instance.NeedUpdate = true; break; case 3: //remove disconnected player var rnid = reader.GetInt(); List <int> plrs = new List <int>(); foreach (var pl in Players) { if (pl.Value.networkId == rnid) { plrs.Add(pl.Key); } } foreach (var i in plrs) { Players.Remove(i); } foreach (var no in NetworkObjects) { if (no.Value.networkId == rnid) { objectsToDestroy.Add(no.Key); } } LobbyManager.Instance.NeedUpdate = true; break; case 4: Players[reader.GetInt()].ReadPlayerData(reader); LobbyManager.Instance.NeedUpdate = true; break; case 101: var OBobjectType = reader.GetInt(); var OBobjectId = reader.GetInt(); var OBplayerId = reader.GetInt(); var OBnetId = reader.GetInt(); var OBposX = reader.GetFloat(); var OBposY = reader.GetFloat(); var OBposZ = reader.GetFloat(); var OBrotX = reader.GetFloat(); var OBrotY = reader.GetFloat(); var OBrotZ = reader.GetFloat(); var OBrotW = reader.GetFloat(); var OBpos = new Vector3(OBposX, OBposY, OBposZ); var OBrot = new Quaternion(OBrotX, OBrotY, OBrotZ, OBrotW); var OBnetObj = objectDataFactory.createObjectData( OBobjectType, OBnetId, OBplayerId, OBobjectId, OBpos, OBrot); objectsToCreate.Add(OBnetObj); break; case 102: var objectToDelete = reader.GetInt(); objectsToDestroy.Add(objectToDelete); break; case 103: var UobjectId = reader.GetInt(); if (NetworkObjects.ContainsKey(UobjectId)) { NetworkObjects[UobjectId].ReadData(reader); } break; case 201: var rpcTarget = reader.GetByte(); var rpcName = reader.GetString(); var rpcObjectId = reader.GetInt(); rpcList.Add(new Tuple <string, int, byte[]>(rpcName, rpcObjectId, reader.GetRemainingBytes())); break; case 301: var levelId = reader.GetInt(); LevelToLoad = levelId; break; } reader.Recycle(); }
private static void OnListenerOnNetworkReceiveEvent(NetPeer fromPeer, NetPacketReader dataReader, DeliveryMethod deliveryMethod) { ushort msgid = dataReader.GetUShort(); NetDataWriter writer = new NetDataWriter(); switch (msgid) { case 1: var playerId = dataReader.GetInt(); var pName = dataReader.GetString(); var isHost = dataReader.GetBool(); var charId = dataReader.GetInt(); var pColorR = dataReader.GetFloat(); var pColorG = dataReader.GetFloat(); var pColorB = dataReader.GetFloat(); var player = new Player(fromPeer, playerId, isHost, pName, charId, pColorR, pColorG, pColorB); Players.Add(playerId, player); player.SendNewPlayerData(writer); SendOthers(fromPeer, writer, DeliveryMethod.ReliableOrdered); Console.WriteLine("registering player " + pName + " pid " + playerId); break; case 101: //create networkObject int objectId; do { objectId = rand.Next(1000000, 9999999); } while (NetworkObjects.ContainsKey(objectId)); var netObj = new NetworkObject( fromPeer, dataReader.GetInt(), objectId, dataReader.GetInt(), dataReader.GetFloat(), dataReader.GetFloat(), dataReader.GetFloat(), dataReader.GetFloat(), dataReader.GetFloat(), dataReader.GetFloat(), dataReader.GetFloat()); NetworkObjects.Add(objectId, netObj); netObj.SendObjectData(writer); server.SendToAll(writer, DeliveryMethod.ReliableOrdered); break; case 102: var objectToDelete = dataReader.GetInt(); NetworkObjects.Remove(objectToDelete); writer.Put((ushort)102); writer.Put(objectToDelete); server.SendToAll(writer, DeliveryMethod.ReliableOrdered); break; case 103: var objectToUpdate = dataReader.GetInt(); if (NetworkObjects.ContainsKey(objectToUpdate)) { NetworkObjects[objectToUpdate].ReadData(dataReader); NetworkObjects[objectToUpdate].WriteData(writer); SendOthers(fromPeer, writer, DeliveryMethod.Unreliable); } break; case 201: byte[] data = new byte[dataReader.UserDataSize]; Array.Copy(dataReader.RawData, dataReader.UserDataOffset, data, 0, dataReader.UserDataSize); var target = dataReader.GetByte(); var rpcName = dataReader.GetString(); var rpcObjectId = dataReader.GetInt(); switch (target) { case 0: NetworkObjects[rpcObjectId].peer.Send(data, DeliveryMethod.ReliableUnordered); break; case 1: SendOthers(NetworkObjects[rpcObjectId].peer, data, DeliveryMethod.ReliableUnordered); break; case 2: server.SendToAll(data, DeliveryMethod.ReliableUnordered); break; } break; } dataReader.Recycle(); }