public override void Send(ulong clientId, ArraySegment <byte> data, string channelName) { if (!channelNameToId.ContainsKey(channelName)) { if (NetworkingManager.Singleton.LogLevel <= LogLevel.Error) { NetworkLog.LogWarningServer("SteamP2PTransport - Can't Send to client, channel with channelName: " + channelName + " is not present"); } return; } int channelId = channelNameToId[channelName]; EP2PSend sendType = channelSendTypes[channelId]; if (clientId == ServerClientId) { SteamNetworking.SendP2PPacket(serverUser.SteamId, data.Array, (uint)data.Count, sendType, channelId); } else { if (connectedUsers.ContainsKey(clientId)) { SteamNetworking.SendP2PPacket(connectedUsers[clientId].SteamId, data.Array, (uint)data.Count, sendType, channelId); } else { if (NetworkingManager.Singleton.LogLevel <= LogLevel.Error) { NetworkLog.LogWarningServer("SteamP2PTransport - Can't Send to client, client not connected, clientId: " + clientId); } } } }
public override ulong GetCurrentRtt(ulong clientId) { if (isServer) { if (clientId == ServerClientId) { return(0); } if (connectedUsers.ContainsKey(clientId)) { return(connectedUsers[clientId].Ping.Get()); } else { if (NetworkingManager.Singleton.LogLevel <= LogLevel.Error) { NetworkLog.LogWarningServer("SteamP2PTransport - Can't GetCurrentRtt from client, client not connected, clientId: " + clientId); } } } else { return(serverUser.Ping.Get()); } return(0ul); }
public override void Init() { Type steamManagerType = Type.GetType("SteamManager"); PropertyInfo property = steamManagerType == null ? null : steamManagerType.GetProperty("Initialized", BindingFlags.Static | BindingFlags.Public); if (steamManagerType == null || property == null || !property.CanRead || property.PropertyType != typeof(bool)) { if (NetworkingManager.Singleton.LogLevel <= LogLevel.Error) { NetworkLog.LogWarningServer("SteamP2PTransport - Init - Steamworks.NET SteamManager.Initialized not found, SteamP2PTransport can not run without it"); } return; } bool propertyValue = (bool)property.GetValue(null); if (!propertyValue) { if (NetworkingManager.Singleton.LogLevel <= LogLevel.Error) { NetworkLog.LogWarningServer("SteamP2PTransport - Init - Steamworks.NET is not Initialized, SteamP2PTransport can not run without it"); } return; } channelIdToName.Clear(); channelNameToId.Clear(); channelSendTypes.Clear(); channelCounter = 0; currentPollChannel = 0; // Add SteamP2PTransport internal channels for (int i = 0; i < (int)InternalChannelType.InternalChannelsCount; i++) { int channelId = AddChannel(ChannelType.Reliable); } // MLAPI Channels for (int i = 0; i < MLAPI_CHANNELS.Length; i++) { int channelId = AddChannel(MLAPI_CHANNELS[i].Type); channelIdToName.Add(channelId, MLAPI_CHANNELS[i].Name); channelNameToId.Add(MLAPI_CHANNELS[i].Name, channelId); } // User Channels for (int i = 0; i < UserChannels.Count; i++) { int channelId = AddChannel(UserChannels[i].Type); channelIdToName.Add(channelId, UserChannels[i].Name); channelNameToId.Add(UserChannels[i].Name, channelId); } }