public static void SendOwnership(ushort viewId, netvrkPlayer player) { object[] data = { viewId, player.SteamId.m_SteamID }; byte[] bytes = netvrkSerialization.SerializeInternal((byte)InternalMethod.SetOwnership, data); for (int i = 0; i < playerList.Count; i++) { SteamNetworking.SendP2PPacket(playerList[i].SteamId, bytes, (uint)bytes.Length, EP2PSend.k_EP2PSendReliable, 0); } }
private void UnpackEvent(byte[] buffer, CSteamID remoteId) { netvrkSerialization.unpackOutput output = netvrkSerialization.UnserializeEvent(buffer); netvrkPlayer player = IsInPlayerList(remoteId); if (eventCall != null) { eventCall(output.eventId, output.data, player); } }
private IEnumerator PlayerJoin(InternalData internalData) { netvrkPlayer newPlayer = new netvrkPlayer(new CSteamID((ulong)internalData.data[0]), false, false); playerList.Add(newPlayer); if (playerJoin != null) { playerJoin(newPlayer); } yield return(null); }
private IEnumerator PlayerDisconnect(InternalData internalData) { netvrkPlayer player = IsInPlayerList(new CSteamID((ulong)internalData.data[0])); if (player != null) { playerList.Remove(player); if (playerDisconnect != null) { playerDisconnect(player); } } yield return(null); }
public static void CreateGame(byte maxPlayers) { if (isConnected) { Debug.LogWarning("netVRk: Can not create a new game while still connected!"); return; } isMasterClient = true; isConnected = true; masterClient = new netvrkPlayer(SteamUser.GetSteamID(), true, true); localClient = masterClient; maxPlayersAllowed = maxPlayers; instance.StartCoroutine("TickLoop"); }
public static void Disconnect() { isMasterClient = false; isConnected = false; object[] data = { SteamUser.GetSteamID().m_SteamID }; for (int i = 0; i < playerList.Count; i++) { SendInternalRpc(playerList[i].SteamId, InternalMethod.PlayerDisconnect, data); } playerList.Clear(); masterClient = null; maxPlayersAllowed = 0; instance.StopCoroutine("TickLoop"); }
private IEnumerator SetOwnership(InternalData internalData) { ushort viewId = (ushort)internalData.data[0]; netvrkPlayer player = IsInPlayerList(new CSteamID((ulong)internalData.data[1])); netvrkView netView = objList[viewId].netObj; if (player.Equals(localClient)) { netView.isMine = true; netView.owner = localClient; } else { netView.owner = player; } yield return(null); }
private IEnumerator ConnectionResponse(InternalData internalData) { CancelInvoke("ConnectionFail"); masterClient = new netvrkPlayer(internalData.remoteId, false, true); localClient = new netvrkPlayer(SteamUser.GetSteamID(), false, true); isConnected = true; if (IsInPlayerList(masterClient.SteamId) == null) { playerList.Add(masterClient); } if (connectSuccess != null) { connectSuccess(); } StartCoroutine("TickLoop"); yield return(null); }
public static void SendRpc(ushort objId, string method, object[] data, netvrkPlayer player, int channel = 0) { if (!isConnected) { Debug.LogWarning("netVRk: Can not send RPCs when not connected!"); return; } int methodId = GetObjMethodId(objId, method); if (methodId < 0) { Debug.LogError("netVRk: Rpc method: " + method + " not found!"); return; } byte[] bytes = netvrkSerialization.SerializeRpc(objId, (byte)methodId, data); SteamNetworking.SendP2PPacket(player.SteamId, bytes, (uint)bytes.Length, EP2PSend.k_EP2PSendReliable, channel); }
private IEnumerator InstantiatePrefab(InternalData internalData) { Vector3 position = (Vector3)internalData.data[0]; Quaternion rotation = Quaternion.Euler((Vector3)internalData.data[1]); string prefabName = (string)internalData.data[2]; netvrkPlayer owner = IsInPlayerList(internalData.remoteId); GameObject go = (GameObject)Resources.Load(prefabName); GameObject instanceGo = Instantiate(go, position, rotation); netvrkView netView = instanceGo.GetComponent <netvrkView>(); netView.isMine = false; netView.isSceneView = false; netView.owner = owner; int len = internalData.data.Length - 3; if (len > 0) { netView.instantiateData = new object[len]; Array.Copy(internalData.data, 3, netView.instantiateData, 0, len); } yield return(null); }
private IEnumerator ConnectionRequest(InternalData internalData) { CSteamID clientId = internalData.remoteId; object[] data = { SteamUser.GetSteamID().m_SteamID }; byte[] bytes = netvrkSerialization.SerializeInternal((byte)InternalMethod.PlayerJoin, data); netvrkPlayer newPlayer = new netvrkPlayer(clientId, false, false); SendInternalRpc(clientId, InternalMethod.ConnectionResponse); for (int i = 0; i < playerList.Count; i++) { SteamNetworking.SendP2PPacket(playerList[i].SteamId, bytes, (uint)bytes.Length, EP2PSend.k_EP2PSendReliable, 0); } if (IsInPlayerList(clientId) == null) { playerList.Add(newPlayer); } if (playerJoin != null) { playerJoin(newPlayer); } yield return(null); }
public void TransferOwnership(netvrkPlayer player) { owner = player; isMine = false; netvrkManager.SendOwnership(id, player); }
public void Rpc(string method, netvrkPlayer player, int channel = 0, params object[] message) { netvrkManager.SendRpc(id, method, message, player, channel); }