Locale_inc.h dosyasına aşağıdaki değişiklikleri uygulayın :
// İstediğiniz bir yere ekleyebilirsiniz.
Kod:
#define ENABLE_CHAT_LOG_VIEWER
PythonChat.cpp dosyasına aşağıdaki değişiklikleri uygulayın :
// Aşağıdakini bulun
Kod:
#include "../eterbase/Timer.h"
// Hemen altına ekleyin
Kod:
#ifdef ENABLE_CHAT_LOG_VIEWER #include <windows.h> #define DIRECTORY_NAME_CHAT_LOG "chat_log" #endif
// Aşağıdakini bulun
Kod:
pChatLine->Instance.SetValue(c_szChat);
// Hemen altına ekleyin
Kod:
#ifdef ENABLE_CHAT_LOG_VIEWER CPythonChat::Instance().AppendLog(iType, c_szChat); #endif
// Aşağıdakini bulun
Kod:
CPythonChat::SChatLine* CPythonChat::SChatLine::New() { return ms_kPool.Alloc(); }
// Hemen altına ekleyin
Kod:
#ifdef ENABLE_CHAT_LOG_VIEWER void CPythonChat::AppendLog(BYTE bType, const char * c_szChat) { if (bType >= CHAT_TYPE_MAX_NUM || !*c_szChat) return; if (GetFileAttributes(DIRECTORY_NAME_CHAT_LOG) != FILE_ATTRIBUTE_DIRECTORY) CreateDirectory(DIRECTORY_NAME_CHAT_LOG, NULL); std::string strChatFileName = "chat_log_default"; switch (bType) { case CHAT_TYPE_TALKING: strChatFileName = "chat_log_talk"; break; case CHAT_TYPE_INFO: strChatFileName = "chat_log_info"; break; case CHAT_TYPE_NOTICE: strChatFileName = "chat_log_notice"; break; case CHAT_TYPE_PARTY: strChatFileName = "chat_log_party"; break; case CHAT_TYPE_GUILD: strChatFileName = "chat_log_guild"; break; case CHAT_TYPE_SHOUT: strChatFileName = "chat_log_shout"; break; case CHAT_TYPE_BIG_NOTICE: strChatFileName = "chat_log_big_notice"; break; } char szPathFileName[32]; snprintf(szPathFileName, sizeof(szPathFileName), "%s/%s.txt", DIRECTORY_NAME_CHAT_LOG, strChatFileName.c_str()); FILE * file = fopen(szPathFileName, "a+"); if (!file) return; time_t ct = time(0); char szTimeInfo[30]; strftime(szTimeInfo, sizeof(szTimeInfo), "%d.%m.%Y / %H:%M:%S", localtime(&ct)); fprintf(file, "%s | %s\n", szTimeInfo, c_szChat); fflush(file); fclose(file); } #endif
PythonChat.h dosyasını açın ve aşağıdaki değişiklikleri uygulayın :
// Aşağıdakini bulun
Kod:
int GetLineStep(DWORD dwID);
// Hemen altına ekleyin
Kod:
#ifdef ENABLE_CHAT_LOG_VIEWER void AppendLog(BYTE bType, const char * c_szChat);#endif
Metin2 Sohbet Geçmişini Log Ettirme [C++]
Metin2 özel sunucularında kullanıcıların sohbet geçmişini loglamak, hem moderasyon hem de güvenlik açısından oldukça önemli bir özelliktir.
Bu yazıda, Metin2 özel sunucu geliştirme sürecinde, sohbet geçmişinin nasıl loglanacağını ve bunun için C++ dilinde nasıl bir yapı kurulacağını ele alacağız.
Sohbet Loglama Sistemi Nedir?
Metin2 oyununda oyuncuların gönderdiği mesajlar, genellikle sunucu tarafında geçici olarak tutulur.
Ancak, bu mesajları kalıcı olarak veritabanına veya bir dosyaya yazmak, moderasyon ve anormallik tespiti açısından çok faydalıdır.
Örneğin, bir oyuncunun saldırgan veya küfür içerikli bir mesaj gönderip göndermediğini kontrol edebilmek için bu loglama yapılmalıdır.
Loglama İçin Gerekli Adımlar
1. ChatHandler fonksiyonuna müdahale etmek gerekir.
2. Oyuncunun gönderdiği mesaj yakalanmalı ve bir fonksiyon aracılığıyla loglanmalıdır.
3. Log verisi veritabanına veya bir dosyaya yazılmalıdır.
C++ Kod Örneği
Aşağıda, ChatPacketHeader üzerinden gelen sohbet mesajlarını yakalayıp loglayan örnek bir yapı verilmiştir:
Kod:
[B]void CInputMain::Chat(LPDESC d, const char * c_pData)[/B][BR][/BR][B]{[/B][BR][/BR][B] const TPacketInfoChat * pinfo = (TPacketInfoChat *) c_pData;[/B][BR][/BR][B] std::string chat_message = pinfo->message;[/B][BR][/BR][B] DWORD pid = d->GetCharacterPtr()->GetPlayerID();[/B][BR][/BR][B] std::string name = d->GetCharacterPtr()->GetName();[/B][BR][/BR][BR][/BR][B] // Burada loglama işlemi yapılır[/B][BR][/BR][B] SaveChatLogToDB(pid, name, chat_message);[/B][BR][/BR][B]}[/B]
UYARI: Bu fonksiyon, game/src klasöründe bulunan input_main.cpp dosyasında yer alır.
Veritabanına Kayıt Fonksiyonu
Mesajları veritabanına yazmak için özel bir tablo oluşturulabilir.
Örnek tablo yapısı:
Kod:
[B]CREATE TABLE chat_log ([/B][BR][/BR][B] id INT AUTO_INCREMENT PRIMARY KEY,[/B][BR][/BR][B] player_id INT,[/B][BR][/BR][B] player_name VARCHAR(32),[/B][BR][/BR][B] message TEXT,[/B][BR][/BR][B] timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP[/B][BR][/BR][B]);[/B]
Faydaları
- Oyuncuların gönderdiği mesajlar kaydedilir.
- Küfür, tehdit gibi içerikler tespit edilebilir.
- Hile kullanımı sırasında yapılan sohbetler analiz edilebilir.
- Moderatörler için daha güvenli bir denetim ortamı sağlar.
Sonuç
Metin2 özel sunucu geliştirme sürecinde, kullanıcıların sohbet geçmişini loglamak, güvenlik ve moderasyon açısından büyük önem taşır.
Yukarıda verilen örnek yapı, C++ tabanlı Metin2 sunucularında kolayca entegre edilebilir ve özelleştirilebilir.
Kaynak: Metin2 Lobby
Logging Metin2 Chat History [C++]
In Metin2 private servers, logging user chat history is very important for both moderation and security purposes.
In this article, we will discuss how to log chat history within Metin2 private server development and how to implement such a system using C++.
What is a Chat Logging System?
In Metin2, messages sent by players are usually kept temporarily on the server side.
However, permanently storing these messages in a database or file is highly beneficial for moderation and anomaly detection.
For example, you can check whether a player has sent an offensive or vulgar message by reviewing these logs.
Steps Required for Logging
1. Modify the ChatHandler function.
2. Intercept the message sent by the player and log it via a function.
3. Write the log data to a database or a file.
C++ Code Example
Below is an example structure that captures chat messages through ChatPacketHeader and logs them:
Kod:
[B]void CInputMain::Chat(LPDESC d, const char * c_pData)[/B][BR][/BR][B]{[/B][BR][/BR][B] const TPacketInfoChat * pinfo = (TPacketInfoChat *) c_pData;[/B][BR][/BR][B] std::string chat_message = pinfo->message;[/B][BR][/BR][B] DWORD pid = d->GetCharacterPtr()->GetPlayerID();[/B][BR][/BR][B] std::string name = d->GetCharacterPtr()->GetName();[/B][BR][/BR][BR][/BR][B] // Here, the logging process occurs[/B][BR][/BR][B] SaveChatLogToDB(pid, name, chat_message);[/B][BR][/BR][B]}[/B]
WARNING: This function is located in the input_main.cpp file under the game/src folder.
Database Logging Function
You can create a custom table to store messages in the database.
Example table structure:
Kod:
[B]CREATE TABLE chat_log ([/B][BR][/BR][B] id INT AUTO_INCREMENT PRIMARY KEY,[/B][BR][/BR][B] player_id INT,[/B][BR][/BR][B] player_name VARCHAR(32),[/B][BR][/BR][B] message TEXT,[/B][BR][/BR][B] timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP[/B][BR][/BR][B]);[/B]
Benefits
- Messages sent by players are recorded.
- Offensive or threatening content can be detected.
- Chats during cheating attempts can be analyzed.
- Provides a safer environment for moderators.
Conclusion
In Metin2 private server development, logging chat history is crucial for security and moderation purposes.
The example structure provided above can be easily integrated and customized into C++-based Metin2 servers.
Source: Metin2 Lobby
