mirror of
https://github.com/valmojr/armatak.git
synced 2026-06-13 18:03:30 +00:00
added log feature on extension
This commit is contained in:
3
addons/main/functions/api/fn_log_message.sqf
Normal file
3
addons/main/functions/api/fn_log_message.sqf
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
params[_type, _message];
|
||||||
|
|
||||||
|
"armatak" callExtension ["log", [_type, _message]]
|
||||||
@@ -39,6 +39,7 @@ pub fn init() -> Extension {
|
|||||||
)
|
)
|
||||||
.command("local_ip", util::get_local_address)
|
.command("local_ip", util::get_local_address)
|
||||||
.command("uuid", util::get_uuid)
|
.command("uuid", util::get_uuid)
|
||||||
|
.command("log", util::log_info)
|
||||||
.group(
|
.group(
|
||||||
"ots_api",
|
"ots_api",
|
||||||
Group::new()
|
Group::new()
|
||||||
|
|||||||
@@ -1,6 +1,28 @@
|
|||||||
use arma_rs::{FromArma, FromArmaError};
|
use arma_rs::{FromArma, FromArmaError};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
|
pub struct LogPayload {
|
||||||
|
pub status: String,
|
||||||
|
pub message: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl IntoMessage for LogPayload {
|
||||||
|
fn into_message(self) -> String {
|
||||||
|
serde_json::to_string(&self).unwrap()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FromArma for LogPayload {
|
||||||
|
fn from_arma(data: String) -> Result<LogPayload, FromArmaError> {
|
||||||
|
let (status, message) = <(String, String)>::from_arma(data)?;
|
||||||
|
Ok(Self {
|
||||||
|
status,
|
||||||
|
message
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
pub struct LocationPayload {
|
pub struct LocationPayload {
|
||||||
pub latitude: f64,
|
pub latitude: f64,
|
||||||
@@ -21,7 +43,7 @@ impl IntoMessage for String {
|
|||||||
|
|
||||||
impl IntoMessage for LocationPayload {
|
impl IntoMessage for LocationPayload {
|
||||||
fn into_message(self) -> String {
|
fn into_message(self) -> String {
|
||||||
serde_json::to_string(&self).unwrap() // Convert struct to JSON
|
serde_json::to_string(&self).unwrap()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
14
src/util.rs
14
src/util.rs
@@ -1,7 +1,17 @@
|
|||||||
use log::{error, info};
|
use log::{error, info, warn};
|
||||||
use reqwest::Client;
|
use reqwest::Client;
|
||||||
use std::net::{IpAddr, UdpSocket};
|
use std::net::{IpAddr, UdpSocket};
|
||||||
use crate::structs::{LoginInfo, LoginPayload, Marker, MarkerPayload};
|
use crate::structs::{LogPayload, LoginInfo, LoginPayload, Marker, MarkerPayload};
|
||||||
|
|
||||||
|
pub fn log_info(data: LogPayload) -> String {
|
||||||
|
match data.status.as_str() {
|
||||||
|
"info" => info!("{}", data.message),
|
||||||
|
"warn" => warn!("{}", data.message),
|
||||||
|
"error" => error!("{}", data.message),
|
||||||
|
_ => error!("{}","Wrong log call")
|
||||||
|
}
|
||||||
|
"logged".to_string()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn get_uuid() -> String {
|
pub fn get_uuid() -> String {
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|||||||
@@ -17,6 +17,10 @@ pub struct WsServer {
|
|||||||
|
|
||||||
impl WsServer {
|
impl WsServer {
|
||||||
pub fn start(&self, rx: Receiver<WsCommand>) {
|
pub fn start(&self, rx: Receiver<WsCommand>) {
|
||||||
|
if let Some(ref server) = *WEBSOCKET_SERVER.lock().unwrap() {
|
||||||
|
server.stop();
|
||||||
|
}
|
||||||
|
|
||||||
let clients = Arc::new(Mutex::new(Vec::new()));
|
let clients = Arc::new(Mutex::new(Vec::new()));
|
||||||
let clients_clone = Arc::clone(&clients);
|
let clients_clone = Arc::clone(&clients);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user