PhantomSDR Support Forum

General Category => PhantomSDR Wishlist => Topic started by: Bas ON5HB on Jun 07, 2025, 11:36 AM

Title: Chat messages log with IP-address..
Post by: Bas ON5HB on Jun 07, 2025, 11:36 AM
Anyone an idea how we write a logfile of chat-posters with IP-address so they can be banned via iptables?

Some people keep posting nasty stuff, I want to ban them from using the websdr in total.

How do we write a log with IP via chat.cpp? Anyone?
Title: Re: Chat messages log with IP-address..
Post by: F1NSK on Feb 05, 2026, 01:32 PM
Hello Bas

I've not find the solution but something useful.

In /src/chat.cpp

std::string ChatClient::get_or_generate_username(const std::string& user_id) {
    auto it = user_id_to_name.find(user_id);
    if (it != user_id_to_name.end()) {
        return it->second;
    } else {
        std::hash<std::string> hasher;
        auto hashed = hasher(user_id);
        std::string numeric_part = std::to_string(hashed).substr(0, 6);
        std::string username = "Call?" + numeric_part;

// Check if the username is blocked
    if (!is_valid_username(username)) {
        // Generate a random username
        std::string random_username = "Call?" + std::to_string(rand() % 1000000);
        printf("Blocked username '%s' detected. Assigned random username: %s\n", username.c_str(), random_username.c_str());
        username = random_username;

I've replaced "user" by "Call?"

Now the Chatbox show : Chatting as [Anonymous] and you can't post a message

This force a name or Call to be registred before posting

I will study Chat.cpp for made something better but i'm not an expert with code !  :)  :)

73's

Title: Re: Chat messages log with IP-address..
Post by: F1NSK on Feb 05, 2026, 02:37 PM
Sorry ! Don't Work on a new session ! Bad way !  ::)