DB Manageri STD'ye değiştirme

  • Konbuyu başlatan Konbuyu başlatan Admin
  • Başlangıç tarihi Başlangıç tarihi
  • Cevaplar Cevaplar 0
  • Görüntüleme Görüntüleme 65

Admin

Metin2Lobby
Yönetici
Founder
Katılım
6 Mayıs 2022
Mesajlar
52,647
Ticaret : 1 / 0 / 0
Olay basit DBManageri std::unique veya std::auto ya dönüştüreceksiniz.

Örnek bırakıyorum örnekten bakarak kendi filesinizde işlemi gerçekleştirebilirsiniz.

Kod:
DBManager::instance().DirectQuery("UPDATE new_petsystem SET name = '%s' WHERE id = '%d'", szEscapedName, item->GetID());

Kod:
std::unique_ptr<SQLMsg> pMsg(DBManager::instance().DirectQuery("UPDATE new_petsystem SET name = '%s' WHERE id = '%d'", szEscapedName, item->GetID()));

DB Manageri STD'ye Değiştirme

Metin2 özel sunucularında performans artışı ve daha stabil bir veritabanı yönetimi için DB Manager'ın standart C++ kütüphanelerine (STD) dönüştürülmesi oldukça önemli bir adımdır. Bu işlem, hem game server hem de auth server tarafında ciddi optimizasyonlar sağlar. Bu makalede, DB manager yapısının nasıl STD'ye çevrileceği ve bu değişimin avantajları ele alınacaktır.

Neden DB Manager STD'ye Çevrilmeli?

Geleneksel olarak Metin2 özel sunucularında kullanılan DB manager yapıları genellikle third-party kütüphanelere dayanmaktadır. Ancak bu kütüphaneler zamanla bakım zorluğu yaratır, güvenlik açıklarına neden olabilir veya performans sorunlarına yol açabilir. STD kütüphaneleri kullanmak, daha güvenli, daha hızlı ve daha kolay bakım yapılabilir bir yapı sunar. Ayrıca C++ dilinin doğrudan desteklediği bu yöntem, derleme süreçlerinde daha az bağımlılık gerektirir.

DB Manageri STD'ye Dönüştürme Adımları

Öncelikle, mevcut DB manager sınıfının yapılandırması incelenmelidir. Bu yapıda MySQL bağlantısı, sorgu işlemleri, veri çekme ve yazma gibi temel işlemler STD::mysql veya doğrudan socket üzerinden MySQL protokolüne uygun şekilde yeniden yazılmalıdır. Bu dönüşüm sırasında dikkat edilmesi gereken konulardan birisi de thread-safe bağlantı yönetimidir. Game server üzerinde eşzamanlı işlemler yapıldığı için, her sorgunun güvenli bir şekilde yönetilmesi gerekir.

Thread-Safe Bağlantı Yönetimi

STD kütüphaneleriyle yapılan DB bağlantısında mutex gibi senkronizasyon yapıları kullanılarak her sorgu ayrı bir thread tarafından yönetilebilir. Bu sayede, channel sunucularında yüksek trafik esnasında veri kaybı yaşamak mümkün olmaz. Mutex kullanımı, sorguların sırayla çalışmasını sağlar ve veri bütünlüğünü korur.

Sorgu Performansını Artırma

STD kullanılarak hazırlanan sorgular, daha düşük seviyede optimize edilebilir. Örneğin, prepared statement'lar doğrudan STD::string üzerinden hazırlanabilir ve MySQL'e gönderilmeden önce doğrulanabilir. Bu sayede SQL injection gibi saldırılara karşı daha dayanıklı sistemler oluşturulabilir.

Auth ve Game Sunucularında Entegrasyon

Her iki sunucu tipi için de DB manager yapısı aynı prensiplerle dönüştürülmelidir. Auth server, kullanıcı girişi ve hesap doğrulamaları için; game server ise karakter verileri, envanter, guild ve diğer oyun içi veriler için kullanılır. Her ikisinde de aynı STD tabanlı yapı kullanılması, kod tekrarını azaltır ve geliştirme sürecini hızlandırır.

Derleme ve Uyum Sorunlarını Giderme

Yeni DB manager, mevcut source edit süreçlerine entegre edilirken bazı derleme hataları ile karşılaşılabilir. Özellikle CMakeLists.txt dosyasında gerekli kütüphane tanımlamalarının yapılması gerekir. Bu süreçte Metin2Lobby forumundan destek almak faydalı olacaktır.

Sonuç

DB manager'in STD kütüphanelerine dönüştürülmesi, Metin2 özel sunucularında uzun vadeli bir yatırım olarak değerlendirilmelidir. Performans, güvenlik ve bakım kolaylığı açısından büyük faydalar sağlar. Bu dönüşümü doğru bir şekilde uygulayan geliştiriciler, sunucularının daha stabil ve verimli çalışmasını sağlayabilir.


Changing DB Manager to STD

To achieve performance improvements and more stable database management in Metin2 private servers, converting the DB Manager to standard C++ libraries (STD) is a very important step. This process provides significant optimizations on both game server and auth server sides. In this article, we will cover how the DB manager structure can be converted to STD and the advantages of this change.

Why Should DB Manager Be Converted to STD?

Traditionally, DB manager structures used in Metin2 private servers rely on third-party libraries. However, these libraries can create maintenance difficulties over time, cause security vulnerabilities, or lead to performance issues. Using STD libraries provides a more secure, faster, and maintainable structure. Additionally, since this method uses libraries directly supported by the C++ language, it requires fewer dependencies during compilation processes.

Steps for Converting DB Manager to STD

Firstly, the configuration of the existing DB manager class should be examined. In this structure, MySQL connections, query operations, data fetching, and writing must be rewritten using STD::mysql or directly via MySQL protocol through sockets. During this conversion, one important point to consider is thread-safe connection management. Since concurrent operations are performed on the game server, each query must be managed securely.

Thread-Safe Connection Management

In DB connections made with STD libraries, synchronization mechanisms like mutex can be used so that each query can be handled by a separate thread. This way, during high traffic on channel servers, data loss can be avoided. Using mutex ensures queries run sequentially and maintains data integrity.

Improving Query Performance

Queries prepared using STD can be optimized at a lower level. For instance, prepared statements can be created directly via STD::string and validated before being sent to MySQL. This makes systems more resilient against SQL injection attacks.

Integration on Auth and Game Servers

The same principles should be applied when converting DB manager structures for both server types. The auth server is used for user logins and account verification, while the game server handles character data, inventory, guilds, and other in-game information. Using the same STD-based structure for both can reduce code duplication and accelerate the development process.

Resolving Compilation and Compatibility Issues

When integrating the new DB manager into existing source edit processes, some compilation errors may occur. It is especially necessary to make required library definitions in the CMakeLists.txt file. During this process, support from Metin2Lobby forums could be helpful.

Conclusion

Converting the DB manager to STD libraries should be viewed as a long-term investment in Metin2 private servers. It offers significant benefits in terms of performance, security, and maintenance ease. Developers who properly implement this conversion can ensure their servers operate more stably and efficiently.
 

Şuan Bu Konuyu Görüntüleyen Kullanıcılar (Toplam : 0, Üye : 0, Misafir : 0)

Benzer konular

Geri
Üst Alt