private void NewPlayer(BeardedManStudios.Forge.Networking.NetworkingPlayer player, BeardedManStudios.Forge.Networking.NetWorker sender) { MainThreadManager.Run(() => { MovableObjectBehavior go = NetworkManager.Instance.InstantiateMovableObject(0, position: networkObject.SpawnPos2); go.networkObject.playerID = player.NetworkId; go.networkObject.position = networkObject.SpawnPos2; networkObject.BothSpawned = true; }); }
public CommonServerLogic(NetWorker server) { this.server = server; }
private void NewPlayer(BeardedManStudios.Forge.Networking.NetworkingPlayer player, BeardedManStudios.Forge.Networking.NetWorker sender) { MainThreadManager.Run(() => { PlayerControllerBehavior go = NetworkManager.Instance.InstantiatePlayerController(0, position: Vector3.zero + UnityEngine.Random.insideUnitSphere * 10); go.networkObject.position = go.transform.position; go.networkObject.ID = player.NetworkId; }); }
public SteamNetworkingPlayer(uint networkId, SteamId steamId, bool isHost, NetWorker networker) : base(networkId, "", isHost, null, networker) #endif { PacketManager = new UDPPacketManager(); SteamID = steamId; }
/// <summary> /// Add a packet to the group that it is associated with /// </summary> /// <param name="packet">The packet to be added</param> /// <param name="packetCompleteHandle">The method to call and pass the data to when a sequence is complete</param> public void AddPacket(UDPPacket packet, BaseUDP.PacketComplete packetCompleteHandle, NetWorker networker) { // Check to see if we have already started this sequence if (!packetGroups.ContainsKey(packet.groupId)) { packetGroups.Add(packet.groupId, new UDPPacketGroup(packet.groupId)); } packetGroups[packet.groupId].AddPacket(packet, packetCompleteHandle, networker); }
public SteamNetworkingPlayer(uint networkId, CSteamID steamId, bool isHost, NetWorker networker) : base(networkId, "", isHost, null, networker)
/// <summary> /// Constructor for the NetworkingPlayer /// </summary> /// <param name="networkId">NetworkId set for the NetworkingPlayer</param> /// <param name="ip">IP address of the NetworkingPlayer</param> /// <param name="socketEndpoint">The socket to the Networking player</param> /// <param name="name">Name of the NetworkingPlayer</param> public NetworkingPlayer(uint networkId, string ip, bool isHost, object socketEndpoint, NetWorker networker) { Networker = networker; NetworkId = networkId; Ip = ip.Split('+')[0]; IsHost = isHost; SocketEndpoint = socketEndpoint; LastPing = networker.Time.Timestep; TimeoutMilliseconds = PLAYER_TIMEOUT_DISCONNECT; PingInterval = DEFAULT_PING_INTERVAL; if (SocketEndpoint != null) { #if WINDOWS_UWP // Check to see if the supplied socket endpoint is TCP, if so // assign it to the TcpClientHandle for ease of access if (socketEndpoint is StreamSocket) { TcpClientHandle = (StreamSocket)socketEndpoint; IPEndPointHandle = (IPEndPoint)TcpClientHandle.Client.RemoteEndPoint; } else if (socketEndpoint is StreamSocketListener) { TcpListenerHandle = (StreamSocketListener)socketEndpoint; IPEndPointHandle = (IPEndPoint)TcpListenerHandle.LocalEndpoint; } else if (SocketEndpoint is IPEndPoint) { IPEndPointHandle = (IPEndPoint)SocketEndpoint; } #else // Check to see if the supplied socket endpoint is TCP, if so // assign it to the TcpClientHandle for ease of access if (socketEndpoint is TcpClient) { TcpClientHandle = (TcpClient)socketEndpoint; IPEndPointHandle = (IPEndPoint)TcpClientHandle.Client.RemoteEndPoint; } else if (socketEndpoint is TcpListener) { TcpListenerHandle = (TcpListener)socketEndpoint; IPEndPointHandle = (IPEndPoint)TcpListenerHandle.LocalEndpoint; } else if (SocketEndpoint is IPEndPoint) { IPEndPointHandle = (IPEndPoint)SocketEndpoint; } #endif Port = (ushort)IPEndPointHandle.Port; } }
/// <summary> /// Add a packet to a sequence based on the server timestamp /// </summary> /// <param name="packet">The packet to be added</param> /// <param name="packetCompleteHandle">The method to call and pass the data to when a sequence is complete</param> public void AddPacket(UDPPacket packet, BaseUDP.PacketComplete packetCompleteHandle, NetWorker networker) { // Don't process packets that have a timestep within a specified range //if (Time.Milliseconds - packet.timeStep > MAX_ACCEPT_TIME_WINDOW) //{ // TODO: Send an event for old message received or packet rejected // return; //} // Removal of packets from this lookup is done on a separate thread lock (packets) { // Check to see if we have already started this sequence if (!packets.ContainsKey(packet.uniqueId)) { packets.Add(packet.uniqueId, new UDPPacketSequence()); } } // Cache the sequence so we don't repeatedly look it up UDPPacketSequence sequence = packets[packet.uniqueId]; // Do not continue to add the packet if the sequence is already complete if (sequence.Done) { return; } if (sequence.AddPacket(packet)) { // The packet sequence is complete CompleteSequence(packet.uniqueId, sequence, packetCompleteHandle, networker); } }
/// <summary> /// Calls the supplied completion handler and passes the complete packet, then removes /// the sequence from the pending list /// </summary> /// <param name="id">The timestamp for the packet to be used to lookup in packets dictionary</param> /// <param name="sequence">The actual sequence reference to skip another lookup</param> /// <param name="packetCompleteHandle">The method to call and pass this sequence into</param> private void CompleteSequence(ulong id, UDPPacketSequence sequence, BaseUDP.PacketComplete packetCompleteHandle, NetWorker networker) { packetCompleteHandle(sequence.GetData(networker), GroupId, (byte)sequence.Receivers, sequence.Reliable); lock (packets) { trackers.Add(new IdTracker() { storeTime = time.Timestep, id = id }); } lock (packets) { for (int i = 0; i < trackers.Count; i++) { if (trackers[i].storeTime + MAX_ACCEPT_TIME_WINDOW <= time.Timestep) { packets.Remove(trackers[i].id); trackers.RemoveAt(i--); } } } }
/// <summary> /// Add a packet to a sequence based on the server timestamp /// </summary> /// <param name="packet">The packet to be added</param> /// <param name="packetCompleteHandle">The method to call and pass the data to when a sequence is complete</param> /// <summary> ///根据服务器时间戳添加一个数据包到一个序列 /// </ summary> /// <param name =“packet”>要添加的数据包</ param> /// <param name =“packetCompleteHandle”>在序列完成时调用和传递数据的方法</ param> public void AddPacket(UDPPacket packet, BaseUDP.PacketComplete packetCompleteHandle, NetWorker networker) { //不要处理具有指定范围内时间步长的数据包 // Don't process packets that have a timestep within a specified range //if (Time.Milliseconds - packet.timeStep > MAX_ACCEPT_TIME_WINDOW) //{ // TODO: Send an event for old message received or packet rejected // return; //} //从这个查询中删除数据包是在一个单独的线程上完成的 // Removal of packets from this lookup is done on a separate thread lock (packets) { // 检查,看看我们是否已经开始这个序列 // Check to see if we have already started this sequence if (!packets.ContainsKey(packet.uniqueId)) { packets.Add(packet.uniqueId, new UDPPacketSequence()); } } //缓存序列,所以我们不要反复查找它 // Cache the sequence so we don't repeatedly look it up UDPPacketSequence sequence = packets[packet.uniqueId]; //如果序列已经完成,则不要继续添加数据包 // Do not continue to add the packet if the sequence is already complete if (sequence.Done) { return; } // 返回true是完整的数据包 if (sequence.AddPacket(packet)) { //数据包序列完整 // The packet sequence is complete CompleteSequence(packet.uniqueId, sequence, packetCompleteHandle, networker); } }