mirror of
https://github.com/Aurorastation/Aurora.3.git
synced 2026-08-25 14:00:18 +01:00
rustg for UDP shipping (#7897)
The C++ UDP logging library has been swapped out with a rustg implementation. The rustg library uses non-blocking IO mode, and hopefully has less trouble than the C++ one. Though we'll have to see. It should error when the call is supposed to block. The old library has been removed.
This commit is contained in:
Binary file not shown.
@@ -1,3 +1,5 @@
|
||||
// rust_g.dm - DM API for rust_g extension library
|
||||
#define RUST_G "rust_g"
|
||||
#define WRITE_LOG(log, text) call(RUST_G, "log_write")(log, text) // Using Rust g dll to log faster with less CPU usage.
|
||||
#define RUST_G "rust_g"
|
||||
#define WRITE_LOG(log, text) call(RUST_G, "log_write")(log, text) // Using Rust g dll to log faster with less CPU usage.
|
||||
|
||||
#define rustg_udp_shipper_send(addr, text) call(RUST_G, "udp_shipper_send")(addr, text)
|
||||
|
||||
@@ -280,5 +280,4 @@
|
||||
/proc/key_name_admin(var/whom, var/include_name = 1)
|
||||
return key_name(whom, 1, include_name, 1)
|
||||
|
||||
#undef RUST_G
|
||||
#undef WRITE_LOG
|
||||
|
||||
@@ -251,8 +251,7 @@ var/list/gamemode_cache = list()
|
||||
|
||||
//UDP GELF Logging
|
||||
var/log_gelf_enabled = 0
|
||||
var/log_gelf_ip = ""
|
||||
var/log_gelf_port = ""
|
||||
var/log_gelf_addr = ""
|
||||
|
||||
//IP Intel vars
|
||||
var/ipintel_email
|
||||
@@ -834,11 +833,8 @@ var/list/gamemode_cache = list()
|
||||
if("log_gelf_enabled")
|
||||
config.log_gelf_enabled = text2num(value)
|
||||
|
||||
if("log_gelf_ip")
|
||||
config.log_gelf_ip = value
|
||||
|
||||
if("log_gelf_port")
|
||||
config.log_gelf_port = value
|
||||
if("log_gelf_addr")
|
||||
config.log_gelf_addr = value
|
||||
|
||||
if("ipintel_email")
|
||||
if (value != "ch@nge.me")
|
||||
|
||||
@@ -24,72 +24,67 @@
|
||||
| |
|
||||
@===================================@
|
||||
|
||||
You can easily send UDP Data via the UDPSHipper.dll
|
||||
The prerequisite for using this is rustg compiled with the udp_shipper feature.
|
||||
|
||||
Simply use the call() function to call the udp shipper DLL and enter your details!
|
||||
|
||||
The first bit of code needed will always be the same, You will never have to touch this, Copy-pasta all you like:
|
||||
|
||||
call("UDPShipper.dll", "send_udp_data")
|
||||
|
||||
Well thats the first part, the harder part is to input the details into DLL. Lets do that now! The syntax to add arguments to the post request is:
|
||||
|
||||
call("UDPShipper.dll", "send_udp_data")(DestinationIP, DestinationPort, Data)
|
||||
|
||||
DLL Written by Arrow768
|
||||
Rustg's rustg_udp_shipper_send function is used to send data.
|
||||
*/
|
||||
|
||||
/*
|
||||
* A generic proc for sending udp request with the aforementioned .DLL files.
|
||||
* Expected arg structure:
|
||||
* 1st arg - the destination ip
|
||||
* 2nd arg - the destination port
|
||||
* 3rd arg - The Data to send
|
||||
*
|
||||
* @return int - Error code
|
||||
* -1 indicates proc or library failure.
|
||||
/**
|
||||
* Sends data via UDP.
|
||||
*
|
||||
* addr must be formatted as "ip:port".
|
||||
* data must be a string to be sent.
|
||||
*/
|
||||
/proc/send_udp_data()
|
||||
if (args.len < 3)
|
||||
return -1
|
||||
/proc/send_udp_data(addr, data)
|
||||
#ifdef RUST_G
|
||||
# ifndef rustg_udp_shipper_send
|
||||
# error rustg_udp_shipper_send macro is not defined for rustg.
|
||||
# endif // rustg_udp_shipper_send
|
||||
|
||||
var/result = call("UDPShipper.dll", "send_udp_data")(arglist(args))
|
||||
if (!addr || !data)
|
||||
return "Not enough args."
|
||||
|
||||
return result
|
||||
. = rustg_udp_shipper_send(addr, data)
|
||||
|
||||
if (.)
|
||||
error("UDP Shipper error: [.]")
|
||||
|
||||
#else
|
||||
return
|
||||
#endif // RUST_G
|
||||
|
||||
/proc/send_gelf_log(short_message="", long_message="", level = 5, category="", additional_data=list())
|
||||
if (!config)
|
||||
return 100
|
||||
if (!config.log_gelf_enabled)
|
||||
return 101
|
||||
var/list/log_data = list()
|
||||
log_data["version"] = "1.1"
|
||||
log_data["host"] = world.name
|
||||
log_data["short_message"] = html_encode(short_message)
|
||||
log_data["long_message"] = html_encode(long_message)
|
||||
log_data["level"] = level
|
||||
log_data["_category"] = category
|
||||
log_data["_game_id"] = game_id
|
||||
if (!config)
|
||||
return "Configuration not loaded."
|
||||
if (!config.log_gelf_enabled)
|
||||
return "Gelf logging not enabled."
|
||||
var/list/log_data = list()
|
||||
log_data["version"] = "1.1"
|
||||
log_data["host"] = world.name
|
||||
log_data["short_message"] = html_encode(short_message)
|
||||
log_data["long_message"] = html_encode(long_message)
|
||||
log_data["level"] = level
|
||||
log_data["_category"] = category
|
||||
log_data["_game_id"] = game_id
|
||||
|
||||
log_data.Add(additional_data)
|
||||
var/gelf_log = json_encode(log_data)
|
||||
return send_udp_data(config.log_gelf_ip,config.log_gelf_port,gelf_log)
|
||||
log_data.Add(additional_data)
|
||||
var/gelf_log = json_encode(log_data)
|
||||
return send_udp_data(config.log_gelf_addr, gelf_log)
|
||||
|
||||
/obj/item/device/udp_debugger
|
||||
name = "udp_debugger"
|
||||
desc = "Used to debug UDP Data sent to the log server."
|
||||
icon = 'icons/obj/hacktool.dmi'
|
||||
icon_state = "hacktool-g"
|
||||
force = 5.0
|
||||
w_class = 2.0
|
||||
throwforce = 5.0
|
||||
throw_range = 15
|
||||
throw_speed = 3
|
||||
desc = "You can use this to debug sending udp logs to the log server"
|
||||
name = "udp_debugger"
|
||||
desc = "Used to debug UDP Data sent to the log server."
|
||||
icon = 'icons/obj/hacktool.dmi'
|
||||
icon_state = "hacktool-g"
|
||||
force = 5.0
|
||||
w_class = 2.0
|
||||
throwforce = 5.0
|
||||
throw_range = 15
|
||||
throw_speed = 3
|
||||
desc = "You can use this to debug sending udp logs to the log server"
|
||||
|
||||
/obj/item/device/udp_debugger/proc/raw(ip=config.log_gelf_ip,port=config.log_gelf_port,data="RAW Test String")
|
||||
return send_udp_data(ip,port,data)
|
||||
/obj/item/device/udp_debugger/proc/raw(addr=config.log_gelf_addr, data="RAW Test String")
|
||||
return send_udp_data(addr,data)
|
||||
|
||||
/obj/item/device/udp_debugger/proc/gelf(short_message="", long_message="", level = 1)
|
||||
return send_gelf_log(short_message, long_message, level)
|
||||
return send_gelf_log(short_message, long_message, level)
|
||||
|
||||
@@ -479,8 +479,8 @@ MC_TICKLIMIT_INIT 500
|
||||
|
||||
## GELF Logging Configuration
|
||||
LOG_GELF_ENABLED 0
|
||||
LOG_GELF_IP 192.168.100.80
|
||||
LOG_GELF_PORT 12201
|
||||
# Make sure the IP string is written in a manner of "IP:port", without the quotes.
|
||||
#LOG_GELF_ADDR 127.0.0.1:5667
|
||||
|
||||
### IPINTEL:
|
||||
### This allows you to detect likely proxies by checking ips against getipintel.net
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
author: Skull132
|
||||
delete-after: True
|
||||
|
||||
changes:
|
||||
- backend: "Updated remote logging capabilities."
|
||||
@@ -1,69 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2017 "Werner Maisl"
|
||||
*
|
||||
* This file is part of Aurora.3
|
||||
* Aurora.3 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#define EXTERN_DLL_EXPORT extern "C" __declspec(dllexport)
|
||||
|
||||
#include <fstream>
|
||||
|
||||
#include "boost/asio.hpp"
|
||||
using namespace boost::asio;
|
||||
|
||||
// Expects 3 Args:
|
||||
// Arg 1: Destination IP
|
||||
// Arg 2: Destination Port
|
||||
// Arg 3: Message String
|
||||
EXTERN_DLL_EXPORT const char *send_udp_data(int argc, char *argv[])
|
||||
{
|
||||
std::ofstream myfile;
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
if (argc < 3)
|
||||
{
|
||||
return "proc=2";
|
||||
}
|
||||
|
||||
int port = std::stoi(argv[1]);
|
||||
|
||||
io_service io_service;
|
||||
ip::udp::socket socket(io_service);
|
||||
ip::udp::endpoint remote_endpoint;
|
||||
socket.open(ip::udp::v4());
|
||||
|
||||
remote_endpoint = ip::udp::endpoint(ip::address::from_string(argv[0]), port);
|
||||
|
||||
boost::system::error_code err;
|
||||
|
||||
size_t request_length = strlen(argv[2]);
|
||||
|
||||
socket.send_to(buffer(argv[2], request_length), remote_endpoint, 0, err);
|
||||
|
||||
socket.close();
|
||||
myfile.close();
|
||||
return "proc=0";
|
||||
}
|
||||
catch (std::exception& ex)
|
||||
{
|
||||
myfile.open("UDP-ERROR.txt");
|
||||
myfile << ex.what() << std::endl;
|
||||
myfile.close();
|
||||
return ex.what();
|
||||
}
|
||||
}
|
||||
BIN
Binary file not shown.
Reference in New Issue
Block a user