public void UpdateInput(UdpConnector connector) { current = default(InputData); if (mIndex % mCmdOverTick == 0) { if (mChoke > 0) { --mChoke; return; } } current.index = mIndex; current.keyboard = (byte)(GetKey(KeyCode.W) << 3 | GetKey(KeyCode.A) << 2 | GetKey(KeyCode.S) << 1 | GetKey(KeyCode.D)); Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (current.mouseHasHit = Physics.Raycast(ray, out hit, 100f, (1 << Layers.Ground))) { current.mouseHit = hit.point; } mInputQueue.Add(current); if ((mIndex++) % mCmdOverTick == 0) { using (var builder = MessageBuilder.Get()) { FlatBufferBuilder fbb = builder.fbb; try { var array = OffsetArrayPool.Alloc <Protocol.InputData>((int)mCmdOverTick); for (int i = 0; i < mCmdOverTick; ++i) { InputData d = mInputQueue[mInputQueue.Count - (int)mCmdOverTick + i]; Protocol.InputData.StartInputData(fbb); Protocol.InputData.AddIndex(fbb, d.index); Protocol.InputData.AddKeyboard(fbb, d.keyboard); Protocol.InputData.AddMouseHasHit(fbb, d.mouseHasHit); if (d.mouseHasHit) { Protocol.InputData.AddMouseHit(fbb, Protocol.Vec3.CreateVec3(fbb, d.mouseHit.x, d.mouseHit.y, d.mouseHit.z)); } array.offsets[array.position++] = Protocol.InputData.EndInputData(fbb); } Protocol.Msg_CS_InputDataArray.StartInputDataVector(fbb, array.position); var offset = Helpers.SetVector(fbb, array); fbb.Finish(Protocol.Msg_CS_InputDataArray.CreateMsg_CS_InputDataArray(fbb, offset).Value); connector.SendMessage( connector.CreateMessage(Protocol.MessageID.Msg_CS_InputDataArray, fbb), NetDeliveryMethod.UnreliableSequenced, 1); } catch (Exception e) { TCLog.Exception(e); } } } }
void MonitorNetwork(UdpConnector netlayer, NetConnectionStatus status, string reason) { if (ConnectionLost(status)) { GameStateLog.ErrorFormat("net status:{0}, reason:{1}", status, reason); TransitTo <Error>(reason); } }
public void testSendMessageWithoutConnectionReturnException() { //Arrange String message = "Teste"; var data = Encoding.ASCII.GetBytes(message); var connector = new UdpConnector("127.0.0.1", 9999, 9998); var udp = new UdpIntegration(connector); //Act and Assert udp.close(); udp.send(message); }
void OnNetStatusChanged(UdpConnector netlayer, NetConnectionStatus status, string reason) { if (!ConnectionLost(status)) { GameStateLog.Info("connect net status:" + status); if (status == NetConnectionStatus.Connected) { TransitTo <Login>(); } } else { GameStateLog.ErrorFormat("connect net status:{0}, reason:{1}", status, reason); TransitTo <Error>(reason); } }
void Run() { updaterate = AppConfig.Instance.updaterate; tickrate = AppConfig.Instance.tickrate; cmdrate = AppConfig.Instance.cmdrate; snapshotOverTick = (uint)Mathf.FloorToInt(updaterate / tickrate); Singletons.Add <InputManager>(); Singletons.Add <SyncManagerClient>(); Singletons.Add <PlayerManagerClient>(); netlayer = new UdpConnector(); mGameState = new GameState.Init(); Time.fixedDeltaTime = tickrate; mGameState.Start(); }
public static void InputShouldProduceGivenOutput(byte[] input, byte[] output) { (List <Clip> clips, string formula, ushort id, byte trackNo) = UdpConnector.DecodeData(input); var chainedCommandWrapper = Parser.ParseFormulaToChainedCommand(formula, clips, new ClipMetaData(id, trackNo)); Assert.IsTrue(chainedCommandWrapper.Success); var processedClipWrapper = ClipProcessor.ProcessChainedCommand(chainedCommandWrapper.Result); Assert.IsTrue(processedClipWrapper.Success); Assert.IsTrue(processedClipWrapper.Result.Length > 0); var processedClip = processedClipWrapper.Result[0]; byte[] clipData = IOUtilities.GetClipAsBytes(chainedCommandWrapper.Result.TargetMetaData.Id, processedClip).ToArray(); Assert.IsTrue(output.Length == clipData.Length); Assert.IsTrue(output.SequenceEqual(clipData)); }
private void btnConnect_Click(object sender, EventArgs e) { string remoteIP = txtRemoteIP.Text; int remotePort = int.Parse(txtRemotePort.Text); int port = int.Parse(txtPort.Text); connector = new UdpConnector(remoteIP, remotePort, port); udpMessages = new UdpIntegration(connector); txtRemoteIP.Enabled = false; txtRemotePort.Enabled = false; txtPort.Enabled = false; btnConnect.Enabled = false; btnDisconnect.Enabled = true; txtMessage.Enabled = true; btnSend.Enabled = true; verifyMessages = new System.Timers.Timer(); verifyMessages.Interval = 500; verifyMessages.Enabled = true; verifyMessages.Elapsed += new ElapsedEventHandler(receive); }
void OnNetStatusChanged(UdpConnector connector, NetConnectionStatus status, string reason) { GameLog.InfoFormat("Connection status changed {0} {1}", status, reason); }
void OnNetStatusChanged(UdpConnector netlayer, NetConnectionStatus status, string reason) { GameStateLog.Info("reconnect net status:" + status); }
public static void Start() { while (true) { var generateUnitTest = false; var generateSvgDoc = false; var inputData = UdpConnector.WaitForData(); if (UdpConnector.IsString(inputData)) { string text = UdpConnector.GetText(inputData); Console.WriteLine(text); continue; } (List <Clip> clips, string formula, ushort id, byte trackNo) = UdpConnector.DecodeData(inputData); Console.WriteLine($"Received {clips.Count} clips and formula: {formula}"); if (formula.EndsWith(UnitTestDirective)) { Console.WriteLine( $"Saving autogenerated unit test to {Path.Join(Environment.CurrentDirectory, "GeneratedUnitTests.txt")}"); formula = formula.Substring(0, formula.Length - UnitTestDirective.Length); generateUnitTest = true; } if (formula.EndsWith(SvgDocDirective)) { Console.WriteLine( $"Saving autogenerated SVG documentation for this formula to {Path.Join(Environment.CurrentDirectory, "GeneratedDocs.svg")}"); formula = formula.Substring(0, formula.Length - SvgDocDirective.Length); generateSvgDoc = true; } var chainedCommandWrapper = Parser.ParseFormulaToChainedCommand(formula, clips, new ClipMetaData(id, trackNo)); if (!chainedCommandWrapper.Success) { Console.WriteLine(chainedCommandWrapper.ErrorMessage); continue; } var processedClipWrapper = ClipProcessor.ProcessChainedCommand(chainedCommandWrapper.Result); if (processedClipWrapper.WarningMessage.Length > 0) { Console.WriteLine($"Warnings were generated:{System.Environment.NewLine}" + $"{processedClipWrapper.WarningMessage}"); } if (processedClipWrapper.Success && processedClipWrapper.Result.Length > 0) { var processedClip = processedClipWrapper.Result[0]; byte[] processedClipData = IOUtilities.GetClipAsBytes(chainedCommandWrapper.Result.TargetMetaData.Id, processedClip) .ToArray(); if (generateUnitTest) { TestUtilities.AppendUnitTest(formula, inputData, processedClipData); } if (generateSvgDoc) { SvgUtilities.GenerateSvgDoc(formula, clips, processedClip, 882, 300); } UdpConnector.SetClipAsBytesById(processedClipData); } else { Console.WriteLine($"Error applying formula: {processedClipWrapper.ErrorMessage}"); } } }
public static byte[] HandleInput(byte[] inputData) { var generateUnitTest = false; var generateSvgDoc = false; if (UdpConnector.IsString(inputData)) { string text = UdpConnector.GetText(inputData); Console.WriteLine(text); return(new byte[0]); } (List <Clip> clips, string formula, ushort id, byte trackNo) = UdpConnector.DecodeData(inputData); formula = formula.Trim(' '); Console.WriteLine($"Received {clips.Count} clips and formula: {formula}"); if (formula.EndsWith(UnitTestDirective)) { Console.WriteLine( $"Saving autogenerated unit test to {Path.Join(Environment.CurrentDirectory, "GeneratedUnitTests.txt")}"); formula = formula.Substring(0, formula.Length - UnitTestDirective.Length); generateUnitTest = true; } if (formula.EndsWith(SvgDocDirective)) { Console.WriteLine( $"Saving autogenerated SVG documentation for this formula to {Path.Join(Environment.CurrentDirectory, "GeneratedDocs.svg")}"); formula = formula.Substring(0, formula.Length - SvgDocDirective.Length); generateSvgDoc = true; } var chainedCommandWrapper = Parser.ParseFormulaToChainedCommand(formula, clips, new ClipMetaData(id, trackNo)); if (!chainedCommandWrapper.Success) { Console.WriteLine(chainedCommandWrapper.ErrorMessage); return(new byte[0]); } ProcessResultArray <Clip> processedClipWrapper; try { processedClipWrapper = ClipProcessor.ProcessChainedCommand(chainedCommandWrapper.Result); } catch (Exception e) { processedClipWrapper = new ProcessResultArray <Clip>($"{formula}. Please check your syntax. Exception: {e.Message}"); } if (processedClipWrapper.WarningMessage.Length > 0) { Console.WriteLine($"Warnings were generated:{System.Environment.NewLine}" + $"{processedClipWrapper.WarningMessage}"); } if (processedClipWrapper.Success && processedClipWrapper.Result.Length > 0) { var processedClip = processedClipWrapper.Result[0]; byte[] processedClipData = IOUtilities .GetClipAsBytes(chainedCommandWrapper.Result.TargetMetaData.Id, processedClip) .ToArray(); if (generateUnitTest) { TestUtilities.AppendUnitTest(formula, inputData, processedClipData); } if (generateSvgDoc) { SvgUtilities.GenerateSvgDoc(formula, clips, processedClip, 882, 300); } return(processedClipData); } Console.WriteLine($"Error applying formula: {processedClipWrapper.ErrorMessage}"); return(new byte[0]); }