private bool ValidateSimInput(SimInput input, INetworkInterfaceConnection instigator) { PlayerInfo instigatorPlayer = PlayerHelpers.GetPlayerInfo(instigator); if (instigatorPlayer == null) { Log.Info($"[{nameof(SimulationController)}] We refused an input from connection {instigator.Id} " + $"because no player seems associated with that connection."); return(false); } if (input is SimPlayerInput playerInput) { playerInput.SimPlayerId = instigatorPlayer.SimPlayerId; if (playerInput.SimPlayerId == PersistentId.Invalid) { Log.Info($"[{nameof(SimulationController)}] We refused {instigatorPlayer.PlayerName}'s input " + $"because (s)he doesn't have a valid {nameof(instigatorPlayer.SimPlayerId)} yet."); return(false); } } return(true); }
private void OnConnectionRemoved(INetworkInterfaceConnection connection) { if (connection == _connection) { TerminateWithNormalFailure("Connection ended"); } }
SimulationSyncFromTransferServerOperation LaunchSyncForClient(INetworkInterfaceConnection clientConnection) { Log.Info($"Starting new sync..."); var newOp = new SimulationSyncFromTransferServerOperation(_session, clientConnection, _simWorldSystem.SimulationWorld); _constructTickSystem.RequestRepackBeforeNextTick(); newOp.OnFailCallback = (op) => { Log.Info($"Sync failed. {op.Message}"); }; newOp.OnSucceedCallback = (op) => { Log.Info($"Sync complete. {op.Message}"); }; newOp.Execute(); _ongoingOperations.Add(newOp); if (s_pauseSimulationWhilePlayersAreJoining) { _tickSystem.PauseSimulation(key: "PlayerJoining"); } return(newOp); }
void OnConnectionRemoved(INetworkInterfaceConnection oldConnection) { Log.Info("[PlayerRepertoireServer] OnConnectionRemoved: " + oldConnection.Id); _newConnectionsNotYetPlayers.Remove(oldConnection); int playerIndex = _playerConnections.IndexOf(oldConnection); if (playerIndex == -1) { // The connection was not yet a valid player. Nothing else to do return; } PlayerId playerId = _players[playerIndex].PlayerId; // destroy DestroyPlayer(playerId); // remove connection _playerConnections.RemoveAt(playerIndex); // Notify other players NetMessagePlayerLeft playerLeftMessage = new NetMessagePlayerLeft() { playerId = playerId }; _serverSession.SendNetMessage(playerLeftMessage, _playerConnections); Log.Info("[PlayerRepertoireServer] sent NetMessagePlayerLeft"); }
private void OnProgressUpdate(NetMessageViaStreamUpdate message, INetworkInterfaceConnection connection) { if (connection == _connection) { Progress = message.Progress; } }
void OnMsg_PlayerIdAssignement(NetMessagePlayerIdAssignment message, INetworkInterfaceConnection source) { Log.Info("[PlayerRepertoireClient] OnMsg_PlayerIdAssignement"); _localPlayerInfo.PlayerId = message.playerId; _localPlayerIdAssigned = true; }
private void OnAssetUpdatedByClient(NetMessagePlayerAssets netMessage, INetworkInterfaceConnection source) { if (netMessage.Assets == null || netMessage.Assets.Length == 0) { return; } UpdateOrCreateLocalAssets(netMessage); List <PlayerAsset> assetsToSend = new List <PlayerAsset>(netMessage.Assets.Length); for (int i = 0; i < netMessage.Assets.Length; i++) { PlayerAsset playerAsset = GetAsset(netMessage.Assets[i].Guid); if (playerAsset != null) { assetsToSend.Add(playerAsset); } } List <INetworkInterfaceConnection> clientsToSendTo = _session.Connections.ToList(); clientsToSendTo.Remove(source); SendPlayerAssetsToClients(assetsToSend.ToArray(), clientsToSendTo.ToArray()); }
private void OnStreamDataAborted(INetworkInterfaceConnection connection, IStreamChannel channel, ulong streamID) { if (streamID == _streamID) { WasCancelledByDestination = true; TerminateWithNormalFailure("StreamData aborted"); } }
private void OnStreamDataStarted(INetworkInterfaceConnection connection, IStreamChannel channel, ulong streamID) { // if our id is unset and the connection and channel match, associate streamID if (connection == _connection && channel.Type == StreamChannelType.LargeDataTransfer && _streamID == ulong.MaxValue) { _streamID = streamID; } }
private void OnTransferCancel(NetMessageCancel message, INetworkInterfaceConnection source) { if (message.TransferId == _transferId && source == _connection) { WasCancelledByDestination = true; TerminateWithNormalFailure("Connection cancelled the transfer"); } }
private void OnStreamAborted(INetworkInterfaceConnection connection, IStreamChannel channel, ulong streamID) { if (connection == Connection && channel.Type == StreamChannelType.LargeDataTransfer) { _sessionInterface.NetworkInterface.StreamDataAborted -= OnStreamAborted; TerminateWithNormalFailure("Stream aborted"); } }
private void OnRequestValueSync(NetMessageRequestValueSync arg1, INetworkInterfaceConnection clientConnection) { foreach (SyncedValueContainer container in SyncedValues.s_Containers) { _sessionInterface.SendNetMessage(CreateSyncMessage(container), clientConnection); } _sessionInterface.SendNetMessage(new NetMessageValueSyncComplete(), clientConnection); }
private void OnResponse(T arg1, INetworkInterfaceConnection arg2) { if (_messagePredicate(arg2, arg1)) { _hasReceivedResponse = true; Response = arg1; Source = arg2; } }
void OnPaquetReceived(NetMessagePacket netMessage, INetworkInterfaceConnection source) { // Our source has sent us a paquet! // the message comes from our source ? if (source != _connection) { return; } // the message is about our transfer ? (we could have many in parallel) if (netMessage.TransferId != _transferInfo.TransferId) { return; } // the paquet index is valid ? if (netMessage.PacketIndex < 0 || netMessage.PacketIndex >= _paquetStates.Length) { return; } // the paquet is already acknowledged ? if (_paquetStates[netMessage.PacketIndex] == PacketState.Received) { return; } // mark paquet as acknowledged if (_paquetStates[netMessage.PacketIndex] != PacketState.Received) { _paquetStates[netMessage.PacketIndex] = PacketState.Received; _remainingUnreceivedPaquets--; // copy paquet data into _data int startPos = netMessage.Data.Length * netMessage.PacketIndex; int endPos = Mathf.Min(startPos + netMessage.Data.Length, _data.Length); Array.Copy( sourceArray: netMessage.Data, sourceIndex: 0, destinationArray: _data, destinationIndex: startPos, length: endPos - startPos); } // notify our source that the paquet was received NetMessagePacketACK acknowledgeMessage = new NetMessagePacketACK() { TransferId = _transferInfo.TransferId, PacketIndex = netMessage.PacketIndex }; _sessionInterface.SendNetMessage(acknowledgeMessage, source); }
public PlayerInfo GetPlayerInfo(INetworkInterfaceConnection connection) { for (int i = 0; i < _playerConnections.Count; i++) { if (_playerConnections[i] != null && _playerConnections[i].Id == connection.Id) { return(_players[i]); } } return(null); }
public void ReceiveLargeData(NetMessageChatMessage netMessage, INetworkInterfaceConnection source) { if (netMessage.message.Length < 100) { DebugScreenMessage.DisplayMessage(netMessage.message); } else { DebugScreenMessage.DisplayMessage(netMessage.message.Length.ToString()); } }
public PlayerInfo GetPlayerInfo(INetworkInterfaceConnection connection) { if (_clientSession != null && _clientSession.ServerConnection != null && _clientSession.ServerConnection.Id == connection.Id) { return(GetServerPlayerInfo()); } else { return(null); } }
public void Event_OnEvent(BoltCommunicationEvent evnt) { INetworkInterfaceConnection connection = _connections.Find((con) => con.Id == evnt.RaisedBy.ConnectionId); if (connection == null) { Log.Info(LogChannel, "[PhotonNetworkInterface] Failed to find who raised the event: " + evnt.GetType() + " / " + evnt.RaisedBy); return; } _messageReader?.Invoke(connection, evnt.BinaryData); }
/// <summary> /// DO NOT MODIFY THE BYTE[] DATA WILL THE TRANSFER IS ONGOING /// </summary> public SendViaStreamChannelOperation(byte[] data, INetworkInterfaceConnection destination, SessionInterface sessionInterface, string description = "") : base(sessionInterface, destination, Transfers.s_NextTransferId++) { if (data.Length > Transfers.MAX_TRANSFER_SIZE) { throw new Exception($"Data transfer ({data.Length} bytes) cannot exceed {Transfers.MAX_TRANSFER_SIZE} bytes."); } _data = data; Description = description; CurrentState = TransferState.NotStarted; }
private void OnNetMessageReceived(NetMessageDestroyValue destroyMessage, INetworkInterfaceConnection arg2) { if (NetSerializer.IsValidType(destroyMessage.TypeId)) { Type type = NetSerializer.GetTypeFromId(destroyMessage.TypeId); var container = SyncedValues.GetContainer(type); if (container != null) { SyncedValues.DestroyContainer(container); } } }
private void OnStreamDataReceived(byte[] data, IStreamChannel streamChannel, INetworkInterfaceConnection source) { if (source == _connection) { _streamDataReceived = true; ReceivedData = data; if (_sessionInterface.NetworkInterface != null) { _sessionInterface.NetworkInterface.StreamDataReceived -= OnStreamDataReceived; } } }
void OnNetMessageChatMessage(NetMessageChatMessage chatMessage, INetworkInterfaceConnection source) { // Server tells us a new message should be displayed in the chat box! PlayerInfo sourcePlayer = PlayerRepertoireSystem.Instance.GetPlayerInfo(chatMessage.playerId); string playerName = sourcePlayer == null ? "ERROR UNKNOWN PLAYER" : sourcePlayer.PlayerName; AddNewLine(new ChatLine() { Message = chatMessage.message, ChatterName = playerName }); }
void OnMsg_NetMessagePlayerLeft(NetMessagePlayerLeft message, INetworkInterfaceConnection source) { if (SystemReady) { Log.Info("[PlayerRepertoireClient] OnMsg_NetMessagePlayerLeft"); _players.RemoveFirst((p) => p.PlayerId == message.playerId); } else { Log.Info("[PlayerRepertoireClient] *Deferring* OnMsg_NetMessagePlayerLeft"); _deferredNetMessages.Enqueue(message); } }
void OnMsg_NetMessagePlayerJoined(NetMessagePlayerJoined message, INetworkInterfaceConnection source) { if (SystemReady) { Log.Info("[PlayerRepertoireClient] OnMsg_NetMessagePlayerJoined"); _players.Add(new PlayerInfo(message.playerInfo)); } else { Log.Info("[PlayerRepertoireClient] *Deferring* OnMsg_NetMessagePlayerJoined"); _deferredNetMessages.Enqueue(message); } }
void OnClientHello(NetMessageClientHello message, INetworkInterfaceConnection clientConnection) { Log.Info("[PlayerRepertoireServer] OnClientHello"); int index = _newConnectionsNotYetPlayers.IndexOf(clientConnection); if (index == -1) { Log.Warning("[PlayerRepertoireServer] We received a client hello, but the client is not in the _newConnectionsNotYetPlayers list. The hello will be ignored."); return; } _newConnectionsNotYetPlayers.RemoveAt(index); // Add new player to list PlayerInfo newPlayerInfo = CreateNewPlayer(message.playerName, false); // Notify other players NetMessagePlayerJoined playerJoinedMessage = new NetMessagePlayerJoined { playerInfo = newPlayerInfo }; _serverSession.SendNetMessage(playerJoinedMessage, _playerConnections); Log.Info("[PlayerRepertoireServer] sent NetMessagePlayerJoined"); // add new connection _playerConnections.Add(clientConnection); // Assign id to the new player NetMessagePlayerIdAssignment playerIdAssignementMessage = new NetMessagePlayerIdAssignment { playerId = newPlayerInfo.PlayerId }; _serverSession.SendNetMessage(playerIdAssignementMessage, clientConnection); Log.Info("[PlayerRepertoireServer] sent NetMessagePlayerIdAssignment"); // Send the complete player list to the new player NetMessagePlayerRepertoireSync syncMessage = new NetMessagePlayerRepertoireSync() { players = _players.ToArray() }; _serverSession.SendNetMessage(syncMessage, clientConnection); Log.Info("[PlayerRepertoireServer] sent NetMessagePlayerRepertoireSync"); }
public static PlayerInfo GetPlayerInfo(INetworkInterfaceConnection connection) { if (connection == null) { return(GetLocalPlayerInfo()); } if (PlayerRepertoireServer.Instance != null) { return(PlayerRepertoireServer.Instance.GetPlayerInfo(connection)); } else { return(PlayerRepertoireClient.Instance.GetServerPlayerInfo()); } }
public override void SendMessage(INetworkInterfaceConnection connection, byte[] data, bool reliableAndOrdered) { if (connection == null) { Log.Error("[PhotonNetworkInterface] Cannot send message to null connection"); return; } BoltConnection boltConnection = ((PhotonNetworkInterfaceConnection)connection).BoltConnection; BoltCommunicationEvent evt = BoltCommunicationEvent.Create(boltConnection, reliableAndOrdered ? ReliabilityModes.ReliableOrdered : ReliabilityModes.Unreliable); if (evt != null) // evt might be null if the connection is not valid anymore { evt.BinaryData = data; evt.Send(); } }
//public bool IsLocallySubmittedInputInQueue(InputSubmissionId inputSubmissionId) //{ // foreach (var item in _inputSubmissionQueue) // { // if (item.InstigatorConnectionId == uint.MaxValue && item.ClientSubmissionId == inputSubmissionId) // return true; // } // return false; //} public void SubmitInputInternal(SimInput input, INetworkInterfaceConnection instigatorConnection, InputSubmissionId submissionId) { if (ValidateInput(input, instigatorConnection)) { Log.Info(SimulationIO.LogChannel, $"Accepted sim input from '{(instigatorConnection == null ? "local player" : instigatorConnection.Id.ToString())}': {input}"); _inputSubmissionQueue.Enqueue(new SimInputSubmission() { Input = input, InstigatorConnectionId = instigatorConnection == null ? uint.MaxValue : instigatorConnection.Id, ClientSubmissionId = submissionId }); } else { Log.Info(SimulationIO.LogChannel, $"Refused sim input from '{(instigatorConnection == null ? "local player" : instigatorConnection.Id.ToString())}': {input}"); } }
private void OnNetMessageReceived(NetMessageSyncValue syncMessage, INetworkInterfaceConnection arg2) { if (syncMessage.ValueData == null) { return; } // get value type Type type = NetMessageInterpreter.GetMessageType(syncMessage.ValueData); // find synced obj SyncedValueContainer container = SyncedValues.GetOrCreateContainer(type); // set data container.SetRawData(syncMessage.ValueData); container.RaiseChangeEventIfNecessary(); }
private void OnStreamDataProgress(INetworkInterfaceConnection connection, IStreamChannel channel, ulong streamID, float progress) { if (streamID == _streamID) { Progress = progress; // send a message back to the uploader with the 'progress' of the large data transfer (needed because of a Bolt api limitation ...) if (_nextProgressUpdateTime < Time.time) { _nextProgressUpdateTime = Time.time + PROGRESS_UPDATE_INTERVAL; _sessionInterface.SendNetMessage(new NetMessageViaStreamUpdate() { Progress = progress }, connection); } } }