Did a bit of polishing up

This commit is contained in:
2026-04-29 00:40:29 +01:00
parent c53138b163
commit 660f7cad7e
11 changed files with 293 additions and 461 deletions
-36
View File
@@ -1,36 +0,0 @@
use warp::Filter;
use std::{
thread,
sync::{Arc, Mutex},
}
use crate::config;
use serde::{Deserialize, Serialize};
use crate::mpsc::*;
use tokio::sync::RwLock;
use crate::api;
#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct Data_to_send {
pub action_type: String,
pub content: String,
pub character: String,
}
#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct Data_to_receive {
pub response: String,
}
pub async fn api_process(data_to_send: Arc<api::Data_to_send>)
{
let route = warp::path("happening")
.map({
let state = Arc::clone(&data_to_send);
move || {
let current_data = state.lock().unwrap().clone();
warp::reply::json(current_data)
}
});
warp::serve(routes)
.run(([127, 0, 0, 1],config::API_PORT));
.await;
}
-30
View File
@@ -1,30 +0,0 @@
{
"$schema": "https://download.qt.io/official_releases/qtcreator/latest/installer_source/jsonschemas/project.json",
"build.configuration": [
{
"name": "cargo build",
"steps": [
{
"arguments": [
"build"
],
"executable": "cargo",
"workingDirectory": "%{ActiveProject:ProjectDirectory}"
}
]
}
],
"files.exclude": [
".qtcreator/project.json.user"
],
"targets": [
{
"arguments": [
"run"
],
"executable": "cargo",
"name": "cargo run",
"workingDirectory": "%{ActiveProject:ProjectDirectory}"
}
]
}
-294
View File
@@ -1,294 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 19.0.0, 2026-04-12T13:17:24. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
<value type="QByteArray">{feb331f8-7617-4b45-82a8-67687dcf787d}</value>
</data>
<data>
<variable>ProjectExplorer.Project.ActiveTarget</variable>
<value type="qlonglong">0</value>
</data>
<data>
<variable>ProjectExplorer.Project.EditorSettings</variable>
<valuemap type="QVariantMap">
<value type="bool" key="EditorConfiguration.AutoDetect">true</value>
<value type="bool" key="EditorConfiguration.AutoIndent">true</value>
<value type="bool" key="EditorConfiguration.CamelCaseNavigation">true</value>
<valuemap type="QVariantMap" key="EditorConfiguration.CodeStyle.0">
<value type="QString" key="language">Cpp</value>
<valuemap type="QVariantMap" key="value">
<value type="QByteArray" key="CurrentPreferences">CppGlobal</value>
</valuemap>
</valuemap>
<valuemap type="QVariantMap" key="EditorConfiguration.CodeStyle.1">
<value type="QString" key="language">QmlJS</value>
<valuemap type="QVariantMap" key="value">
<value type="QByteArray" key="CurrentPreferences">QmlJSGlobal</value>
</valuemap>
</valuemap>
<value type="qlonglong" key="EditorConfiguration.CodeStyle.Count">2</value>
<value type="QByteArray" key="EditorConfiguration.Codec">UTF-8</value>
<value type="bool" key="EditorConfiguration.ConstrainTooltips">false</value>
<value type="int" key="EditorConfiguration.IndentSize">4</value>
<value type="bool" key="EditorConfiguration.KeyboardTooltips">false</value>
<value type="int" key="EditorConfiguration.LineEndingBehavior">0</value>
<value type="int" key="EditorConfiguration.MarginColumn">80</value>
<value type="bool" key="EditorConfiguration.MouseHiding">true</value>
<value type="bool" key="EditorConfiguration.MouseNavigation">true</value>
<value type="int" key="EditorConfiguration.PaddingMode">1</value>
<value type="int" key="EditorConfiguration.PreferAfterWhitespaceComments">0</value>
<value type="bool" key="EditorConfiguration.PreferSingleLineComments">false</value>
<value type="bool" key="EditorConfiguration.ScrollWheelZooming">true</value>
<value type="bool" key="EditorConfiguration.ShowMargin">false</value>
<value type="int" key="EditorConfiguration.SmartBackspaceBehavior">2</value>
<value type="bool" key="EditorConfiguration.SmartSelectionChanging">true</value>
<value type="bool" key="EditorConfiguration.SpacesForTabs">true</value>
<value type="int" key="EditorConfiguration.TabKeyBehavior">0</value>
<value type="int" key="EditorConfiguration.TabSize">8</value>
<value type="bool" key="EditorConfiguration.UseGlobal">true</value>
<value type="bool" key="EditorConfiguration.UseIndenter">false</value>
<value type="int" key="EditorConfiguration.Utf8BomBehavior">1</value>
<value type="bool" key="EditorConfiguration.addFinalNewLine">false</value>
<value type="bool" key="EditorConfiguration.cleanIndentation">true</value>
<value type="bool" key="EditorConfiguration.cleanWhitespace">true</value>
<value type="QString" key="EditorConfiguration.ignoreFileTypes">*.md, *.MD, Makefile</value>
<value type="bool" key="EditorConfiguration.inEntireDocument">false</value>
<value type="bool" key="EditorConfiguration.skipTrailingWhitespace">true</value>
<value type="bool" key="EditorConfiguration.tintMarginArea">true</value>
</valuemap>
</data>
<data>
<variable>ProjectExplorer.Project.PluginSettings</variable>
<valuemap type="QVariantMap">
<valuemap type="QVariantMap" key="AutoTest.ActiveFrameworks">
<value type="bool" key="AutoTest.Framework.Boost">true</value>
<value type="bool" key="AutoTest.Framework.CTest">false</value>
<value type="bool" key="AutoTest.Framework.Catch">true</value>
<value type="bool" key="AutoTest.Framework.GTest">true</value>
<value type="bool" key="AutoTest.Framework.QtQuickTest">true</value>
<value type="bool" key="AutoTest.Framework.QtTest">true</value>
</valuemap>
<value type="bool" key="AutoTest.ApplyFilter">false</value>
<valuemap type="QVariantMap" key="AutoTest.CheckStates"/>
<valuelist type="QVariantList" key="AutoTest.PathFilters"/>
<value type="int" key="AutoTest.RunAfterBuild">0</value>
<value type="bool" key="AutoTest.UseGlobal">true</value>
<valuemap type="QVariantMap" key="ClangTools">
<value type="bool" key="ClangTools.AnalyzeOpenFiles">true</value>
<value type="bool" key="ClangTools.BuildBeforeAnalysis">true</value>
<value type="QString" key="ClangTools.DiagnosticConfig">Builtin.DefaultTidyAndClazy</value>
<value type="int" key="ClangTools.ParallelJobs">6</value>
<value type="bool" key="ClangTools.PreferConfigFile">true</value>
<valuelist type="QVariantList" key="ClangTools.SelectedDirs"/>
<valuelist type="QVariantList" key="ClangTools.SelectedFiles"/>
<valuelist type="QVariantList" key="ClangTools.SuppressedDiagnostics"/>
<value type="bool" key="ClangTools.UseGlobalSettings">true</value>
</valuemap>
<value type="int" key="RcSync">0</value>
</valuemap>
</data>
<data>
<variable>ProjectExplorer.Project.Target.0</variable>
<valuemap type="QVariantMap">
<value type="QString" key="DeviceType">Desktop</value>
<value type="bool" key="HasPerBcDcs">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Desktop</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">{120e6ad0-5207-4289-8a6a-7630e1616590}</value>
<value type="qlonglong" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value>
<value type="qlonglong" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
<value type="qlonglong" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/home/deadvey/code/rust/happening</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProcessStep.Arguments">build</value>
<value type="QString" key="ProjectExplorer.ProcessStep.Command">cargo</value>
<value type="QString" key="ProjectExplorer.ProcessStep.WorkingDirectory">%{ActiveProject:ProjectDirectory}</value>
<value type="QString" key="ProjectExplorer.ProcessStep.WorkingDirectoryRelativeBasePath">/home/deadvey/code/rust/happening</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.ProcessStep</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Build</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Build</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1">
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">0</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Clean</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Clean</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.CustomParsers"/>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ParseStandardOutput">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">cargo build</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">WorkspaceProject.BuildConfiguration</value>
<value type="qlonglong" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
<value type="qlonglong" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.DeployConfiguration.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">0</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Deploy</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Deploy</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Deploy</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">1</value>
<valuemap type="QVariantMap" key="ProjectExplorer.DeployConfiguration.CustomData"/>
<value type="bool" key="ProjectExplorer.DeployConfiguration.CustomDataEnabled">false</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.DefaultDeployConfiguration</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.Target.DeployConfigurationCount">1</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.RunConfiguration.0">
<value type="bool" key="Analyzer.Perf.Settings.UseGlobalSettings">true</value>
<value type="bool" key="Analyzer.QmlProfiler.Settings.UseGlobalSettings">true</value>
<value type="int" key="Analyzer.Valgrind.Callgrind.CostFormat">0</value>
<value type="bool" key="Analyzer.Valgrind.Settings.UseGlobalSettings">true</value>
<valuelist type="QVariantList" key="Analyzer.Valgrind.SuppressionFiles"/>
<valuelist type="QVariantList" key="CustomOutputParsers"/>
<value type="int" key="PE.EnvironmentAspect.Base">2</value>
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
<value type="bool" key="PE.EnvironmentAspect.PrintOnRun">false</value>
<value type="QString" key="PerfRecordArgsId">-e cpu-cycles --call-graph dwarf,4096 -F 250</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">cargo run</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">WorkspaceProject.RunConfiguration:</value>
<value type="QString" key="ProjectExplorer.RunConfiguration.BuildKey">cargo run1</value>
<value type="bool" key="ProjectExplorer.RunConfiguration.Customized">false</value>
<value type="QString" key="ProjectExplorer.RunConfiguration.UniqueId"></value>
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
<value type="bool" key="RunConfiguration.UseTerminal">false</value>
<value type="QString" key="Workspace.RunConfiguration.Arguments">run</value>
<value type="QString" key="Workspace.RunConfiguration.Executable">cargo</value>
<value type="QString" key="Workspace.RunConfiguration.WorkingDirectory.default">%{ActiveProject:ProjectDirectory}</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
<valuemap type="QVariantMap" key="extraInfo">
<value type="bool" key="forSetup">true</value>
<value type="QString" key="name">cargo build</value>
<valuelist type="QVariantList" key="steps">
<valuemap type="QVariantMap">
<valuelist type="QVariantList" key="arguments">
<value type="QString">build</value>
</valuelist>
<value type="QString" key="executable">cargo</value>
<value type="QString" key="workingDirectory">%{ActiveProject:ProjectDirectory}</value>
</valuemap>
</valuelist>
</valuemap>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.1">
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/home/deadvey/code/rust/happening/build</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">0</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Build</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Build</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1">
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">0</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Clean</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Clean</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.CustomParsers"/>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ParseStandardOutput">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Default</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">WorkspaceProject.BuildConfiguration</value>
<value type="qlonglong" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
<value type="qlonglong" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.DeployConfiguration.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">0</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Deploy</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Deploy</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Deploy</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">1</value>
<valuemap type="QVariantMap" key="ProjectExplorer.DeployConfiguration.CustomData"/>
<value type="bool" key="ProjectExplorer.DeployConfiguration.CustomDataEnabled">false</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.DefaultDeployConfiguration</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.Target.DeployConfigurationCount">1</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.RunConfiguration.0">
<value type="bool" key="Analyzer.Perf.Settings.UseGlobalSettings">true</value>
<value type="bool" key="Analyzer.QmlProfiler.Settings.UseGlobalSettings">true</value>
<value type="int" key="Analyzer.Valgrind.Callgrind.CostFormat">0</value>
<value type="bool" key="Analyzer.Valgrind.Settings.UseGlobalSettings">true</value>
<valuelist type="QVariantList" key="Analyzer.Valgrind.SuppressionFiles"/>
<valuelist type="QVariantList" key="CustomOutputParsers"/>
<value type="int" key="PE.EnvironmentAspect.Base">2</value>
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
<value type="bool" key="PE.EnvironmentAspect.PrintOnRun">false</value>
<value type="QString" key="PerfRecordArgsId">-e cpu-cycles --call-graph dwarf,4096 -F 250</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">cargo run</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">WorkspaceProject.RunConfiguration:</value>
<value type="QString" key="ProjectExplorer.RunConfiguration.BuildKey">cargo run1</value>
<value type="bool" key="ProjectExplorer.RunConfiguration.Customized">false</value>
<value type="QString" key="ProjectExplorer.RunConfiguration.UniqueId"></value>
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
<value type="bool" key="RunConfiguration.UseTerminal">false</value>
<value type="QString" key="Workspace.RunConfiguration.Arguments">run</value>
<value type="QString" key="Workspace.RunConfiguration.Executable">cargo</value>
<value type="QString" key="Workspace.RunConfiguration.WorkingDirectory.default">%{ActiveProject:ProjectDirectory}</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.Target.BuildConfigurationCount">2</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.DeployConfiguration.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">0</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Deploy</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Deploy</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Deploy</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">1</value>
<valuemap type="QVariantMap" key="ProjectExplorer.DeployConfiguration.CustomData"/>
<value type="bool" key="ProjectExplorer.DeployConfiguration.CustomDataEnabled">false</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.DefaultDeployConfiguration</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.Target.DeployConfigurationCount">1</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.RunConfiguration.0">
<value type="bool" key="Analyzer.Perf.Settings.UseGlobalSettings">true</value>
<value type="bool" key="Analyzer.QmlProfiler.Settings.UseGlobalSettings">true</value>
<value type="int" key="Analyzer.Valgrind.Callgrind.CostFormat">0</value>
<value type="bool" key="Analyzer.Valgrind.Settings.UseGlobalSettings">true</value>
<valuelist type="QVariantList" key="Analyzer.Valgrind.SuppressionFiles"/>
<valuelist type="QVariantList" key="CustomOutputParsers"/>
<value type="int" key="PE.EnvironmentAspect.Base">2</value>
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
<value type="bool" key="PE.EnvironmentAspect.PrintOnRun">false</value>
<value type="QString" key="PerfRecordArgsId">-e cpu-cycles --call-graph dwarf,4096 -F 250</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">cargo run</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">WorkspaceProject.RunConfiguration:</value>
<value type="QString" key="ProjectExplorer.RunConfiguration.BuildKey">cargo run1</value>
<value type="bool" key="ProjectExplorer.RunConfiguration.Customized">false</value>
<value type="QString" key="ProjectExplorer.RunConfiguration.UniqueId"></value>
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
<value type="bool" key="RunConfiguration.UseTerminal">false</value>
<value type="QString" key="Workspace.RunConfiguration.Arguments">run</value>
<value type="QString" key="Workspace.RunConfiguration.Executable">cargo</value>
<value type="QString" key="Workspace.RunConfiguration.WorkingDirectory.default">%{ActiveProject:ProjectDirectory}</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
</valuemap>
</data>
<data>
<variable>ProjectExplorer.Project.TargetCount</variable>
<value type="qlonglong">1</value>
</data>
<data>
<variable>Version</variable>
<value type="int">22</value>
</data>
</qtcreator>
Generated
+176
View File
@@ -2,6 +2,65 @@
# It is not intended for manual editing. # It is not intended for manual editing.
version = 4 version = 4
[[package]]
name = "aho-corasick"
version = "1.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ddd31a130427c27518df266943a5308ed92d4b226cc639f5a8f1002816174301"
dependencies = [
"memchr",
]
[[package]]
name = "anstream"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "824a212faf96e9acacdbd09febd34438f8f711fb84e09a8916013cd7815ca28d"
dependencies = [
"anstyle",
"anstyle-parse",
"anstyle-query",
"anstyle-wincon",
"colorchoice",
"is_terminal_polyfill",
"utf8parse",
]
[[package]]
name = "anstyle"
version = "1.0.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "940b3a0ca603d1eade50a4846a2afffd5ef57a9feac2c0e2ec2e14f9ead76000"
[[package]]
name = "anstyle-parse"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "52ce7f38b242319f7cabaa6813055467063ecdc9d355bbb4ce0c68908cd8130e"
dependencies = [
"utf8parse",
]
[[package]]
name = "anstyle-query"
version = "1.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc"
dependencies = [
"windows-sys",
]
[[package]]
name = "anstyle-wincon"
version = "3.0.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d"
dependencies = [
"anstyle",
"once_cell_polyfill",
"windows-sys",
]
[[package]] [[package]]
name = "atomic-waker" name = "atomic-waker"
version = "1.1.2" version = "1.1.2"
@@ -35,6 +94,12 @@ version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
[[package]]
name = "colorchoice"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d07550c9036bf2ae0c684c4297d503f838287c83c53686d05370d0e139ae570"
[[package]] [[package]]
name = "cpufeatures" name = "cpufeatures"
version = "0.2.17" version = "0.2.17"
@@ -64,6 +129,29 @@ dependencies = [
"crypto-common", "crypto-common",
] ]
[[package]]
name = "env_filter"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32e90c2accc4b07a8456ea0debdc2e7587bdd890680d71173a15d4ae604f6eef"
dependencies = [
"log",
"regex",
]
[[package]]
name = "env_logger"
version = "0.11.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0621c04f2196ac3f488dd583365b9c09be011a4ab8b9f37248ffcc8f6198b56a"
dependencies = [
"anstream",
"anstyle",
"env_filter",
"jiff",
"log",
]
[[package]] [[package]]
name = "equivalent" name = "equivalent"
version = "1.0.2" version = "1.0.2"
@@ -157,6 +245,8 @@ dependencies = [
name = "happening-server" name = "happening-server"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"env_logger",
"log",
"serde", "serde",
"tokio", "tokio",
"warp", "warp",
@@ -283,12 +373,42 @@ dependencies = [
"hashbrown", "hashbrown",
] ]
[[package]]
name = "is_terminal_polyfill"
version = "1.70.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695"
[[package]] [[package]]
name = "itoa" name = "itoa"
version = "1.0.18" version = "1.0.18"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682"
[[package]]
name = "jiff"
version = "0.2.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f00b5dbd620d61dfdcb6007c9c1f6054ebd75319f163d886a9055cec1155073d"
dependencies = [
"jiff-static",
"log",
"portable-atomic",
"portable-atomic-util",
"serde_core",
]
[[package]]
name = "jiff-static"
version = "0.2.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e000de030ff8022ea1da3f466fbb0f3a809f5e51ed31f6dd931c35181ad8e6d7"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]] [[package]]
name = "libc" name = "libc"
version = "0.2.184" version = "0.2.184"
@@ -340,6 +460,12 @@ version = "1.21.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
[[package]]
name = "once_cell_polyfill"
version = "1.70.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe"
[[package]] [[package]]
name = "percent-encoding" name = "percent-encoding"
version = "2.3.2" version = "2.3.2"
@@ -372,6 +498,21 @@ version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd"
[[package]]
name = "portable-atomic"
version = "1.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c33a9471896f1c69cecef8d20cbe2f7accd12527ce60845ff44c153bb2a21b49"
[[package]]
name = "portable-atomic-util"
version = "0.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c2a106d1259c23fac8e543272398ae0e3c0b8d33c88ed73d0cc71b0f1d902618"
dependencies = [
"portable-atomic",
]
[[package]] [[package]]
name = "proc-macro2" name = "proc-macro2"
version = "1.0.106" version = "1.0.106"
@@ -390,6 +531,35 @@ dependencies = [
"proc-macro2", "proc-macro2",
] ]
[[package]]
name = "regex"
version = "1.12.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e10754a14b9137dd7b1e3e5b0493cc9171fdd105e0ab477f51b72e7f3ac0e276"
dependencies = [
"aho-corasick",
"memchr",
"regex-automata",
"regex-syntax",
]
[[package]]
name = "regex-automata"
version = "0.4.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e1dd4122fc1595e8162618945476892eefca7b88c52820e74af6262213cae8f"
dependencies = [
"aho-corasick",
"memchr",
"regex-syntax",
]
[[package]]
name = "regex-syntax"
version = "0.8.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc897dd8d9e8bd1ed8cdad82b5966c3e0ecae09fb1907d58efaa013543185d0a"
[[package]] [[package]]
name = "ryu" name = "ryu"
version = "1.0.23" version = "1.0.23"
@@ -584,6 +754,12 @@ version = "1.0.24"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75"
[[package]]
name = "utf8parse"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
[[package]] [[package]]
name = "version_check" name = "version_check"
version = "0.9.5" version = "0.9.5"
+2
View File
@@ -4,6 +4,8 @@ version = "0.1.0"
edition = "2024" edition = "2024"
[dependencies] [dependencies]
env_logger = "0.11.10"
log = "0.4.29"
serde = { version = "1.0.228", features = ["derive"] } serde = { version = "1.0.228", features = ["derive"] }
tokio = { version = "1.51.0", features = ["rt-multi-thread","macros"] } tokio = { version = "1.51.0", features = ["rt-multi-thread","macros"] }
warp = { version = "0.4.2", features = ["server"] } warp = { version = "0.4.2", features = ["server"] }
+28 -20
View File
@@ -1,40 +1,48 @@
use warp::Filter;
use std::{
thread,
sync::{Arc, Mutex},
};
use crate::config;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::mpsc::*; use warp::Filter;
use tokio::sync::RwLock; use crate::
use crate::api; {
Arc,
Mutex,
config,
mpsc::Sender,
info,
warn,
debug,
};
#[derive(Debug, Deserialize, Serialize, Clone)] #[derive(Debug, Deserialize, Serialize, Clone)]
pub struct Data_to_send { pub struct DataToSend {
pub action_type: String, pub action_type: String,
pub content: String, pub content: String,
pub character: String, pub character: String,
} }
#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct Data_to_receive {
pub response: String,
}
pub async fn api_process(data_to_send: Arc<Mutex<Data_to_send>>, tx: Sender<u8>) // Async function that runs the api server in the background.
// Waits for the client to load it, at which point it sends a 1 over
// tx to allow the program executor to move onto the next bit of code
pub async fn api_process(data_to_send: Arc<Mutex<DataToSend>>, tx: Sender<u8>)
{ {
// This data must be passed through to the api route in order to be used
let data_filter = warp::any().map(move || Arc::clone(&data_to_send)); let data_filter = warp::any().map(move || Arc::clone(&data_to_send));
let tx_filter = warp::any().map(move || tx.clone()); let tx_filter = warp::any().map(move || tx.clone());
println!("Running server");
debug!("Running server");
// The server route is loaded at address:port/happening
let route = warp::path("happening") let route = warp::path("happening")
.and(warp::get()) .and(warp::get())
.and(data_filter) .and(data_filter)
.and(tx_filter) .and(tx_filter)
.map(|state: Arc<Mutex<Data_to_send>>, tx_handle: Sender<u8>| { // Perform this code on a GET request
println!("GET: {:?}", state); .map(|state: Arc<Mutex<DataToSend>>, tx_handle: Sender<u8>| {
info!("GET: {:?}", state);
let reply = state.as_ref(); let reply = state.as_ref();
tx_handle.send(1); let _ = tx_handle.send(1);
warp::reply::json(&reply) warp::reply::json(&reply) // Send the reply data (data_to_send formatted as JSON)
}).boxed(); }).boxed();
// Start the server
warp::serve(route) warp::serve(route)
.run(([127, 0, 0, 1],config::API_PORT)) .run(([127, 0, 0, 1],config::API_PORT))
.await; .await;
+14 -10
View File
@@ -1,14 +1,16 @@
use std:: use std::
{ {
fs, fs,
thread,
collections::HashMap, collections::HashMap,
sync::{Arc, Mutex, mpsc}, sync::{Arc, Mutex, mpsc},
}; };
use serde::{Deserialize, Serialize}; use log::
use tokio::runtime::Runtime; {
use tokio::task; info,
use warp::Filter; trace,
warn,
debug,
};
mod parsing; mod parsing;
mod character; mod character;
@@ -16,9 +18,11 @@ mod config;
mod api; mod api;
#[tokio::main] #[tokio::main]
async fn main() { async fn main()
{
env_logger::init();
let (tx,rx) = mpsc::channel(); let (tx,rx) = mpsc::channel();
let mut data_to_send = Arc::new(Mutex::new(api::Data_to_send let data_to_send = Arc::new(Mutex::new(api::DataToSend
{ {
action_type: "initialise".to_string(), action_type: "initialise".to_string(),
content: "".to_string(), content: "".to_string(),
@@ -32,7 +36,7 @@ async fn main() {
async move { async move {
api::api_process(data, tx_clone).await; api::api_process(data, tx_clone).await;
}); });
println!("and continue"); debug!("and continue");
let mut characters = HashMap::<String, character::Character>::new(); let mut characters = HashMap::<String, character::Character>::new();
let file_contents: String = fs::read_to_string("stories/story.ha").unwrap(); let file_contents: String = fs::read_to_string("stories/story.ha").unwrap();
// Split the file contents into tokens // Split the file contents into tokens
@@ -43,7 +47,7 @@ async fn main() {
let data_clone = Arc::clone(&data_to_send); let data_clone = Arc::clone(&data_to_send);
match parsing::token_parse(&tokens, &mut characters, data_clone, &rx).await match parsing::token_parse(&tokens, &mut characters, data_clone, &rx).await
{ {
Ok(()) => println!("Program exited successfully"), Ok(()) => info!("Program exited successfully"),
Err(error) => println!("{}", error), Err(error) => eprintln!("{}", error),
} }
} }
+36 -32
View File
@@ -1,19 +1,29 @@
use std::collections::HashMap; use std::collections::HashMap;
use crate::character;
use crate::api;
use crate::mpsc::*;
use std::{thread};
use std::sync::{Arc,Mutex};
use std::time::Duration; use std::time::Duration;
use std::thread;
mod strings; mod strings;
use crate::
{
// Internal code
character,
api,
// Libraries
mpsc::Receiver,
Arc,
Mutex,
info,
warn,
debug,
};
// Parse the tokens in a file // Parse the tokens in a file
// Returns success or an error string // Returns success or an error string
pub async fn token_parse( pub async fn token_parse(
tokens: &Vec<&str>, tokens: &Vec<&str>,
mut characters: &mut HashMap::<String, character::Character>, mut characters: &mut HashMap::<String, character::Character>,
data_to_send: Arc<Mutex<api::Data_to_send>>, data_to_send: Arc<Mutex<api::DataToSend>>,
rx: &Receiver<u8>, rx: &Receiver<u8>,
) -> Result<(),String> ) -> Result<(),String>
{ {
@@ -21,14 +31,19 @@ pub async fn token_parse(
// Run an infinite loop // Run an infinite loop
loop loop
{ {
match rx.try_recv() // If the client hasn't responded then continue (after a short pause)
if rx.try_recv().is_err()
{ {
Ok(_) => thread::sleep(Duration::from_millis(300));
{ continue
match tokens.get(index) { }
Some(token) => { // Get the next token
let token = tokens
.get(index)
.ok_or_else(|| "File reached termination point".to_string())?;
// The instructions are related to characters // The instructions are related to characters
if token.chars().next().unwrap() == '@' if token.starts_with('@')
{ {
let character_name: String = token.chars().skip(1).collect(); let character_name: String = token.chars().skip(1).collect();
// If the character doesn't exist, then create it // If the character doesn't exist, then create it
@@ -41,9 +56,7 @@ pub async fn token_parse(
// The index is incremented to after the character's instructions // The index is incremented to after the character's instructions
index += match character_parse(index+1, &tokens, character_name, &mut characters, &data_to_send, &rx).await index += match character_parse(index+1, &tokens, character_name, &mut characters, &data_to_send, &rx).await
{ {
Ok(increment) => { Ok(increment) => increment,
increment
},
Err(error) => return Err(error), Err(error) => return Err(error),
} }
} }
@@ -52,13 +65,7 @@ pub async fn token_parse(
{ {
return Ok(()) // quit return Ok(()) // quit
} }
},
None => return Err(String::from("File reached termination point")),
}
index += 1; index += 1;
},
Err(_) => thread::sleep(Duration::from_millis(4000)),
}
} }
} }
// Parsing character related instructions // Parsing character related instructions
@@ -68,7 +75,7 @@ async fn character_parse
tokens: &Vec<&str>, tokens: &Vec<&str>,
character_name: String, character_name: String,
characters: &mut HashMap::<String, character::Character>, characters: &mut HashMap::<String, character::Character>,
data_to_send: &Arc<Mutex<api::Data_to_send>>, data_to_send: &Arc<Mutex<api::DataToSend>>,
rx: &Receiver<u8>, rx: &Receiver<u8>,
) -> Result<usize,String> ) -> Result<usize,String>
{ {
@@ -76,20 +83,20 @@ async fn character_parse
loop loop
{ {
// Ensure the index is valid (the index is not beyond the vector) // Ensure the index is valid (the index is not beyond the vector)
let _ = match tokens.get(sum_index) let token = tokens
{ .get(sum_index)
Some(token) => { .ok_or_else(|| "File reached termination point".to_string())?;
match token.to_lowercase().as_str() match token.to_lowercase().as_str()
{ {
// The character is saying something, so grab the text and pass it // The character is saying something, so grab the text and pass it
// to the client // to the client
"says" => "says" =>
{ {
match strings::extract_quoted(&tokens[sum_index+1..]) match strings::extract_quoted(&tokens[sum_index+1..]) // TODO increment to after the string
{ {
Some(output_string) => Some(output_string) =>
{ {
println!("{}", output_string); debug!("{}", output_string);
let mut data = data_to_send.lock().unwrap(); let mut data = data_to_send.lock().unwrap();
data.action_type = String::from("output"); data.action_type = String::from("output");
data.content = output_string; data.content = output_string;
@@ -100,11 +107,8 @@ async fn character_parse
}, },
// Catch all condition, if the instruction is unrecognised as a // Catch all condition, if the instruction is unrecognised as a
// character command // character command
_ => return Err(String::from("Invalid command")), _ => return Err(String::from(format!("Invalid command: {}", token))),
} }
},
None => return Err(String::from("File reached termination point"))
};
sum_index += 1; sum_index += 1;
} }
} }
Binary file not shown.
+1 -2
View File
@@ -1,8 +1,7 @@
pub fn extract_quoted(parts: &[&str]) -> Option<String> { pub fn extract_quoted(parts: &[&str]) -> Option<String> { // TODO also return a number to increment by
let mut vec_string = Vec::new(); let mut vec_string = Vec::new();
for part in parts for part in parts
{ {
println!("{}",part);
if part.chars().next_back().unwrap() == '"' if part.chars().next_back().unwrap() == '"'
{ {
vec_string.push(*part); vec_string.push(*part);
+1 -2
View File
@@ -1,2 +1 @@
@tim says "this text is outputted" @tim says "hello to all the world"
END