public static void SendLobbyNewPlayerPacket(LobbyNewPlayerPacket pkt, [Optional()][DefaultParameterValue(-1)] int connectionId) { MemoryStream m = new MemoryStream(); m.WriteByte(9); LiteNetworking.Networking.localPacketPlayer = LiteNetworking.LobbyConnector.ConvertConnectionToPlayer(connectionId); ConstRefs.mirror_LobbyNewPlayerPacket._Serialize(pkt, m); Networking.TransmitPacket(m, connectionId); }
private void ChunkReady(WorldChunk chunk, LitePlayer player) { // Move the player ent Vector3 oldOffset = ChunkHandler.i.GetChunkOffset(player.GetChunkId()); Vector3 newOffset = ChunkHandler.i.GetChunkOffset(chunk.chunk); player.transform.position += (newOffset - oldOffset); // Send data about all the players and the connected entitits. OnSceneChangedClient clientUpdate = new OnSceneChangedClient(); // Network Players List <LitePlayer> players = chunk.connectedPlayers; clientUpdate.playerPositions = new Vector3[players.Count]; clientUpdate.playersInScene = new int[players.Count]; for (int i = 0; i < players.Count; i++) { clientUpdate.playerPositions[i] = players[i].transform.position; clientUpdate.playersInScene[i] = players[i].id; } player.SetChunkId(chunk.chunk); // Network entities // [ todo ] Debug.Log("Sending scene changed packet to player " + player.id); Debug.Log("Broadcasting over that tehr are indeed " + players.Count + " players in scene"); LiteNetworkingGenerated.PacketSender.SendOnSceneChangedClient(clientUpdate, player.GetConnectionId()); // Broadcast to existing players that they are in foreach (LitePlayer p in players) { LobbyNewPlayerPacket pkt = new LobbyNewPlayerPacket(); pkt.newPlayerId = player.id; PacketSender.SendLobbyNewPlayerPacket(pkt, p.GetConnectionId()); } // ADd this player to the connected entities chunk.connectedPlayers.Add(player); }
public static IEnumerator SendPacketsLater(int connectionId) { yield return(new WaitForSeconds(0.1f)); Debug.Log("OnPlayerJoined"); //hostId = connectionId; // Send the introduction packet to this client Debug.Log("Sending out the intro packet"); LobbyHostIntroductionPacket introPkt = new LobbyHostIntroductionPacket(); connectedClients.Add(connectionId); introPkt.myPlayerId = nextPlayerIndex++; List <int> activePlayers = new List <int>(); foreach (int i in connectedClients) { if (i != connectionId) { activePlayers.Add(connectionToPlayer[i]); } } introPkt.activePlayerIds = activePlayers.ToArray(); connectionToPlayer[connectionId] = nextPlayerIndex - 1; SpawnEntityPacket epkt = new SpawnEntityPacket(); foreach (NetworkedEntity e in EntityManager.ents.Values) { if (e.GetComponent <LitePlayer>() == null) { epkt.authority = e.GetComponent <NetworkAuthority>()?.owner?.id ?? 0; epkt.entityId = (int)e.EntityIndex; epkt.prefabId = e.GetComponent <UniqueId>().prefabId; epkt.uniqueId = e.GetComponent <UniqueId>().uniqueId; epkt.position = e.transform.position; PacketSender.SendSpawnEntityPacket(epkt, connectionId); } } Debug.Log("Spawining player prefab"); SpawnPlayerPrefab(false, (nextPlayerIndex - 1)); Debug.Log("Actually sending the packet now"); introPkt.instanceIdToEntity = new int[0]; introPkt.preplacedInstanceIds = new long[0]; LiteNetworkingGenerated.PacketSender.SendLobbyHostIntroductionPacket(introPkt, connectionId); Debug.Log("Done sending packet"); // Send the player joined packet to all other clients foreach (int i in connectedClients) { if (i != connectionId) { LobbyNewPlayerPacket pkt = new LobbyNewPlayerPacket(); pkt.newPlayerId = (nextPlayerIndex - 1); Debug.Log("Sending NP Packet"); PacketSender.SendLobbyNewPlayerPacket(pkt, i); Debug.Log("Done Sending NP Packet"); } } Debug.Log("Done SendPacketsLater"); }
public void _Deserialize(LobbyNewPlayerPacket pkt, MemoryStream m) { pkt.newPlayerId = Data_serializers_const.ser_M_liteIntSerializer.Deserialize(m); }
public void _Serialize(LobbyNewPlayerPacket pkt, MemoryStream m) { byte[] newPlayerId = Data_serializers_const.ser_M_liteIntSerializer.Serialize(pkt.newPlayerId); m.Write(newPlayerId, 0, newPlayerId.Length); }