[C++] Hamle Atınca HP Düşme Sorunu Fixed

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

Admin

Metin2Lobby
Yönetici
Founder
Katılım
6 Mayıs 2022
Mesajlar
52,647
Ticaret : 1 / 0 / 0
game/src char.cpp açılır ve aratılır

Kod:
if (GetHP() > GetMaxHP())         PointChange(POINT_HP, GetMaxHP() - GetHP());     if (GetSP() > GetMaxSP())         PointChange(POINT_SP, GetMaxSP() - GetSP());

Bu Şekilde Değiştirilir

Kod:
/*if (GetHP() > GetMaxHP())         PointChange(POINT_HP, GetMaxHP() - GetHP());     if (GetSP() > GetMaxSP())         PointChange(POINT_SP, GetMaxSP() - GetSP()); */

Ardından
Kod:
UpdatePacket();
Aratılır ve Altına Eklenir

Kod:
if (GetHP() > GetMaxHP())         PointChange(POINT_HP, GetMaxHP() - GetHP());     if (GetSP() > GetMaxSP())         PointChange(POINT_SP, GetMaxSP() - GetSP());

Kolay Gelsin.
Metin2 özel sunucularında geliştirme yaparken karşılaşılan yaygın sorunlardan birisi de C++ tabanlı sistemlerde karakter hamlesi sırasında HP düşmesi problemidir. Bu sorun genellikle game core kısmında yer alan damage calculation mekanizmasında eksik veya yanlış tanımlanmış kodlardan kaynaklanmaktadır. Bu yazıda, Metin2 özel sunucu geliştiricileri için bu sorunun kökenine inerek çözümünü adım adım sunacağız.

Sorun Nedir?
Metin2 oyununda oyuncular bir attack komutu gerçekleştirdiğinde, client tarafı server'a bir packet gönderir. Sunucu bu packeti alır, character sınıfında bulunan attack fonksiyonunu çalıştırır. Bu esnada, attacker ve target belirlenir ve hasar hesaplaması yapılır. Ancak bazı durumlarda, attack işlemi sırasında attacker'ın kendi HPsi de azalabilmektedir. Bu, damage hesaplama fonksiyonlarında self-damage kontrolünün eksik olması veya target kontrolünün yapılmamasından kaynaklanabilir.

Nedenleri Nelerdir?
- Target kontrolü yapılmazsa, attacker kendi üzerine hasar uygulayabilir.
- Attack fonksiyonunda attacker ve target aynıysa bu durum göz ardı edilmezse self-damage oluşur.
- Damage hesaplaması sırasında defender kontrolü yapılmadan doğrudan HP azaltılabilir.

Çözüm Adımları
Game server tarafında C++ ile yazılmış olan attack fonksiyonuna aşağıdaki gibi bir kontrol eklenmelidir:

if (attacker == target) { return; }

Bu kontrol sayesinde, attacker kendi kendine saldırı yapamaz. Ayrıca, target[/BR] null değilse ve alive durumundaysa damage işlemleri yapılmalıdır.

Örnek Kod Parçası:
int damage = CalculateDamage(attacker, target);
if (target && target->IsAlive() && attacker != target)
{
target->PointChange(POINT_HP, -damage);
}

Ekstra Güvenlik Önlemleri
Bu tip bugları engellemek için server-side validation kontrolleri artırılmalıdır. Özellikle PvP sistemlerinde bu kontroller exploit riskini azaltır. Metin2 özel sunucularında game core üzerinde çalışan geliştiriciler, auth ve game server kodlarını düzenlerken bu tür küçük ama kritik hatalara dikkat etmelidir.

Sonuç
Metin2 özel sunucularında C++ tabanlı attack sistemlerinde karşılaşılan HP düşme sorunları, doğru validation kontrolleriyle kolayca çözülebilir. Bu tür source edit işlemleri sırasında, character sınıflarında self-target korumaları eklemek büyük önem taşır. Metin2Lobby.com olarak, Metin2 geliştiricilerinin bu gibi teknik konularda destek alabileceği kaynaklar sunmaya devam edeceğiz.


Metin2 custom server development involves encountering common issues such as HP loss during character attacks in C++-based systems. This issue typically stems from missing or incorrectly defined code within the damage calculation mechanism in the game core. In this article, we will examine the root causes of this issue and provide step-by-step solutions for Metin2 custom server developers.

What Is The Problem?
In Metin2, when players execute an attack command, the client sends a packet to the server. The server receives this packet and executes the attack function in the character class. During this process, attacker and target are determined and damage is calculated. However, sometimes the attacker's own HP decreases during the attack operation. This occurs due to missing self-damage checks or failure to validate the target in the damage calculation functions.

Causes
- If no target check is performed, the attacker may apply damage to themselves.
- If attacker and target are the same and not handled properly, self-damage can occur.
- Damage may be applied directly without checking if the defender is valid, leading to unintended behavior.

Solution Steps
The following check should be added to the attack function written in C++ on the game server:

if (attacker == target) { return; }

With this check, the attacker cannot attack itself. Additionally, damage operations should only proceed if target is not null and alive.

Sample Code:
int damage = CalculateDamage(attacker, target);
if (target && target->IsAlive() && attacker != target)
{
target->PointChange(POINT_HP, -damage);
}

Additional Security Measures
To prevent such bugs, server-side validation checks must be increased. Especially in PvP systems, these checks reduce exploit risks. Developers working with Metin2 custom servers should pay attention to small but critical errors while editing auth and game server codes.

Conclusion
HP drop issues during attack operations in C++-based systems can be easily resolved with proper validation checks. When performing such source edit tasks, adding self-target protections in character classes is highly important. As Metin2Lobby.com, we will continue providing resources for Metin2 developers facing such technical challenges.
 

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

Benzer konular

Geri
Üst Alt