public bool IsLocallyOwned() { if (meshnetReference == null) { Debug.LogError("Meshnet offline"); return(false); } if (meshnetReference.GetLocalPlayerID() == GetOwnerID()) { return(true); } else { return(false); } }
IEnumerator SpawnCapsule() { float timeStart = Time.time; MeshNetworkIdentity requestedID = new MeshNetworkIdentity(0, prefabID, meshnet.GetLocalPlayerID(), false); IDContainer returnedObjectID = new IDContainer((ushort)ReservedObjectIDs.Unspecified); scheduler.ScheduleChange(requestedID, StateChange.Addition, ref returnedObjectID); while (returnedObjectID.id == (ushort)ReservedObjectIDs.Unspecified) { if (Time.time - timeStart > SPAWN_TIMEOUT) { Debug.LogError("Spawn timeout"); yield break; } yield return(new WaitForEndOfFrame()); } MeshNetworkIdentity newIdentity = meshnet.database.LookupObject(returnedObjectID.id); GameObject g = meshnet.game.GetObjectByIdentity(newIdentity.GetObjectID()); if (prefabID != 4) { g.AddComponent <BasicMovementTest>(); } yield break; yield return(new WaitForSeconds(1)); timeStart = Time.time; returnedObjectID = new IDContainer((ushort)ReservedObjectIDs.Unspecified); scheduler.ScheduleChange(newIdentity, StateChange.Removal, ref returnedObjectID); while (returnedObjectID.id == (ushort)ReservedObjectIDs.Unspecified) { if (Time.time - timeStart > SPAWN_TIMEOUT) { Debug.LogError("Spawn timeout"); yield break; } yield return(new WaitForEndOfFrame()); } }
void ParseData(MeshPacket incomingPacket) { //Debug.Log("Packet parsing: type = " + incomingPacket.GetPacketType() + ", source playerID = " + incomingPacket.GetSourcePlayerId() + ", target objectID = " + incomingPacket.GetTargetObjectId()); if (incomingPacket.GetSourcePlayerId() == meshnet.GetLocalPlayerID()) { //Debug.Log("Discarding packet from self"); //return; } if (incomingPacket.GetPacketType() == PacketType.PlayerJoin) { Debug.Log("PlayerJoin packet identified"); if (meshnet.database == null) { Debug.LogError("Database not intialized yet!"); return; } if (meshnet.database.GetAuthorized() == false) { Debug.Log("I'm not the provider. Discarding PlayerJoin packet"); return; } CSteamID sID = new CSteamID(incomingPacket.GetSourcePlayerId()); Player p = meshnet.ConstructPlayer(sID); meshnet.database.AddPlayer(p, true); return; } else if (incomingPacket.GetPacketType() == PacketType.DatabaseUpdate) { if (meshnet.database == null) { Debug.Log("Received first database update, no database to send it to."); Debug.Log("Rerouting to MeshNetwork."); meshnet.InitializeDatabaseClientside(incomingPacket); return; } } else if (incomingPacket.GetPacketType() == PacketType.KickPacket) { meshnet.initiateDisconnect(); } //If the packet is neither a PlayerJoin or a DatabaseUpdate Player source = meshnet.database.LookupPlayer(incomingPacket.GetSourcePlayerId()); //retrieve which player sent this packet if (source == null) //hmmm, the NBD can't find the player { Debug.LogError("Player from which packet originated does not exist on local NDB."); return; } MeshNetworkIdentity targetObject = meshnet.database.LookupObject(incomingPacket.GetTargetObjectId()); if (targetObject == null) { Debug.LogError("Packet's target object doesn't exist on the database!"); //Debug.LogError("type = " + incomingPacket.GetPacketType() + ", sourceObject = " + incomingPacket.GetSourceObjectId() + ", source player = " + incomingPacket.GetSourcePlayerId() + ", target object = " + incomingPacket.GetTargetObjectId()); return; } targetObject.ReceivePacket(incomingPacket); }