protected virtual void SendNetworkPackage() { int count = this.inputBuffer.Count; FrameInput[] buffer = new FrameInput[count]; for (int i = 0; i < count; ++i) { float horizontalAxis = 0f; float horizontalAxisRaw = 0f; float verticalAxis = 0f; float verticalAxisRaw = 0f; NetworkButtonPress buttons = NetworkButtonPress.None; foreach (KeyValuePair <InputReferences, InputEvents> pair in this.inputBuffer[i]) { InputReferences inputReference = pair.Key; InputEvents inputEvent = pair.Value; if (inputReference.inputType == InputType.HorizontalAxis) { horizontalAxis = inputEvent.axis; horizontalAxisRaw = inputEvent.axisRaw; } else if (inputReference.inputType == InputType.VerticalAxis) { verticalAxis = inputEvent.axis; verticalAxisRaw = inputEvent.axisRaw; } else if (inputReference.inputType == InputType.Button && inputEvent.button) { buttons |= inputReference.engineRelatedButton.ToNetworkButtonPress(); } } buffer[i] = new FrameInput( horizontalAxis, horizontalAxisRaw, verticalAxis, verticalAxisRaw, buttons, this.optionSelections[i] == null ? -2 : this.optionSelections[i].Value ); } InputBufferMessage msg = new InputBufferMessage(this.player, this.currentFrame, buffer); if (UFE.config.networkOptions.fakeNetwork) { RemotePlayerController remoteController = UFE.GetController(UFE.GetRemotePlayer()) as RemotePlayerController; remoteController.OnMessageReceived(msg.Serialize(), new NetworkMessageInfo()); } else { UFE.multiplayerAPI.SendNetworkMessage(msg); } }
protected virtual void ProcessInputBufferMessage(InputBufferMessage msg) { if (msg.Data != null) { int offset = (int)(msg.CurrentFrame - this.currentFrame); FrameInput frame; int index; for (int i = 0; i < msg.Data.Length; ++i) { frame = msg.Data[i]; index = i + offset; if (index >= 0) { if (index >= this.inputBuffer.Count) { this.inputBuffer.Add(new Dictionary <InputReferences, InputEvents>()); this.optionSelections.Add(frame.selectedOption <= -2 ? null : new int?(frame.selectedOption)); } foreach (InputReferences input in this.inputReferences) { if (input.inputType == InputType.HorizontalAxis) { this.inputBuffer[index][input] = new InputEvents( frame.horizontalAxis, frame.horizontalAxisRaw ); } else if (input.inputType == InputType.VerticalAxis) { this.inputBuffer[index][input] = new InputEvents( frame.verticalAxis, frame.verticalAxisRaw ); } else { this.inputBuffer[index][input] = new InputEvents( (frame.buttons & input.engineRelatedButton.ToNetworkButtonPress()) != 0 ); } } } } } }