MT2Dev Work - Geliştirme Günlüğü

Metin2’nin Elon Musk’ı hocam, bu gidişle bir sonraki güncellemede Starlink uyduları oyunculara cep telefonu internet. Elleriniz dert görmesin, harikasınız!♥️
 
Konuya yorum gelince şöyle ana mesaja tekrar bir göz atarken dikkatimi çekti, (dosyalarla o kadar uzun zamandır uğraşamadım ki ne yaptığımı unutacağım tuttuğum notlar olmasa 😅 ) bütün ana ayarları tuttuğum dosyada aslında yanlış bir tarz tercih ediyorum, sebebi benim eski alışkanlıklarımdır ama tabii ki değişmeli, bu konuyu yeni başlayan veya tarz olarak fikir almak için inceleyenler de olabilir o sebeple gözüme çarpmışken doğrusunu göstereyim.

Settings.h:
Genişlet Daralt Kopyala
/***********************************************************************/
/* FILE:    Settings.h                                                 */
/* INFO:    All important settings are linked to a single header file. */
/* AUTHOR:  MT2Dev                                                     */
/* DATE:    26/11/2020                                                 */
/***********************************************************************/
#ifndef __MT2DEV_SERVER_SETTINGS_H__
#define __MT2DEV_SERVER_SETTINGS_H__

// SECURITY_SETTINGS
#define CLIENT_VERSION_KEY                2407972020       // Client Version Key, it's must be same on the serverside!
#define LSS_SECURITY_KEY                4321dcba5678efgz // Ymir Security Key (Only used if _OLD_PACKET_ENCRYPTION_ is enabled)
// END_OF_SECURITY_SETTINGS

// VARIOUS_SETTINGS
#define MAP_ALLOW_LIMIT                    32         // Map Allow Limit.
#define PK_LEVEL_FOR_PROTECT            15         // PK Protect Level For New Players (Ex; If this is 15, nobody can hit (PvP) new players if they under 15 level)
#define MAX_STAT                        95         // Maximum Stat Points. (Note: The packside needs to be change too when you set another value here, to avoid gauge bug.)
#define MAX_LEVEL_POINT_CAN_STEP        98         // Maximum Level at Which The Character Will Continue to Gain Status.
#define MAX_ITEM_INTRO_STACK            200        // Maximum Number of Items Stacked (Maximum setting that can be made for now; 255).
#define GOLD_MAX                        2000000000 // Maximum Yang Limit (Maximum setting that can be made for now {int}; 2.147.483.647 Yang).
#define INVENTORY_MAX_NUM                90         // Number of Inventory Slots (90 Slots = 2 Inventory). (Note: The sum of the slots of the inventory should not exceed 255 !!)
#define INVENTORY_PAGE_COUNT            2          // Inventory Total Page Count.
#define ITEM_DROP_PENALTY_LEVEL            50         // Minimum Level to Item Drop Penalty (Note: If the low rank character is below level 50, their item will not drop.)
#define MOBS_DISAPPEARANCE_TIME            3          // Mobs disappearance time(Second) after death, it needs to be kept low to avoid lag.
#define AUTO_RESTART_TOWN_TIME            180        // After Player's die, if they not choose start here/town, after this time they will be spawn in town automatically.
#define BRAVE_CAPE_POSSIBILITY            80         // Brave Cape - Possibility(%) (With just one click) to Attract Monsters.
#define BRAVE_CAPE_MAX_DISTANCE            5000       // Brave Cape - Maximum Distance Of Monsters You Can Attract.
#define CAMPFIRE_TIME                    30         // How many seconds will the campfire be active after using it ?
#define STONE_INSERT_PERCENT_CHANCE        30         // Chance(%) For Stones to be Added.
#define ORE_INSERT_PERCENT_CHANCE        50         // Percentage(%) of Success When Adding Ores to The Item.
#define ITEM_ACCESSORY_SOCKET_MAX_NUM    3          // Maximum Number of Ores That Can Be Added to Interior Items.
#define KILLER_MODE_COOLDOWN            30         // After PC's set PvP mode Free or Guild, how many seconds need to set Peace after not hit anyone.
#define SHORT_PORTAL_LIMIT_TIME            3          // Cooldown Before Warp When Not Doing Anything Recently.
#define PORTAL_LIMIT_TIME                10         // Cooldown Before Warp For Trading or Post-Battle Control.
#define REQUEST_LIMIT_TIME                10         // Validity Seconds Of Requests Received By Players.
#define ITEM_DESTROY_TIME                10         // The Time(Second) It Takes For an Item The Player Throws to Disappear.
#define OWNER_ITEM_DESTROY_TIME            240        // The Time(Second) It Takes For an Item To Drop Specifically For One Player To Disappear or Delete Ownership. (Items with an anti-flag against dropping, that is, only the owner can take that item.)
#define DROP_ITEM_DESTROY_TIME            60         // The Time(Second) It Takes For an Item To Drop Player. (with ownership)
#define ORE_ITEM_OWNERSHIP_TIME            20         // The Time(Second) It Takes For an Ore Item(Mining) To Drop Player. (with ownership)
#define CAN_RESET_HERE_TIME                170        // How Soon After The Character Dies Will He Be Able to Stand Up ? (170 = 10 Seconds) (Respawn Here)
#define CAN_RESET_TOWN_TIME                173        // How Soon After The Character Dies Will He Be Able to Stand Up ? (173 =  7 Seconds) (Respawn Town)
#define CAN_SHOUT_LEVEL_LIMIT            15         // Level Required to Shout.
#define CAN_SHOUT_TIME_LIMIT            15         // Time Required to Shout.
#define PARTY_CAN_JOIN_MAX_LEVEL        30         // Maximum Level Difference Between Players to Enter a Group.
#define MAX_MEMBER_INTRO_PARTY            8          // Maximum Number of Players That Can Be in a Group.
#define SAFEBOX_MAX_NUM                    135        // Maximum Number of Safebox Slots (135 Slots = 3 Page).
#define SAFEBOX_PASSWORD_MAX_LEN        6          // Safebox Maximum Password Length.
#define DEAD_HORSE_DISAPPEAR_TIME        20         // When Player Summon Their Dead Horse, How Many Seconds Take To Disappear ?
#define NEW_CHAR_CREATE_COOLDOWN        30         // Players Can Only Create One Character Per 30 Seconds (To Prevent Spam).
#define NECESSARY_GOLD_FOR_GUILD        200000     // Necessary Yang For Create a New Guild.
#define NECESSARY_LEVEL_FOR_GUILD        40         // Necessary Level For Create a New Guild.
// END_OF_VARIOUS_SETTINGS

// TRICKY_SETTINGS
// WARNING: Don't change this one's, if you don't know what are you doing exactly.. - [MT2Dev Note] - 30/05/2023
#define QUEST_NAME_MAX_LEN                32
#define QUEST_STATE_MAX_LEN                64
#define MAX_ALLOW_USER                    4096
#define DRAGON_SOUL_STRENGTH_MAX        7
#define MAX_BLEND_ITEM_VALUE            5
#define POLYMORPH_SKILL_ID                129
#define POLYMORPH_BOOK_ID                50322
#define OXEVENT_MAP_INDEX                113
#define NORM_ATTR_MAX                    5
#define RARE_ATTR_MAX                    2
#define GUILD_SYMBOL_FILENAME            "guild_symbol.tga"
#define OLD_MARK_INDEX_FILENAME            "guild_mark.idx"
#define OLD_MARK_DATA_FILENAME            "guild_mark.tga"
// END_OF_TRICKY_SETTINGS
#endif //__MT2DEV_SERVER_SETTINGS_H__

Bu header dosyası sadece bu tarz ayarları tutmak için kullanılıyor ama gördüğünüz üzere ben hepsini eski usul #define ile tanımlamışım, burada yanlış bir tercih olduğunu net olarak söyleyebiliriz, nedeni şu; burada tanımlanan değerler hem derleme zamanında hem de çalışma zamanında sabit kalmalı, eğer bunların sabit kalacağını derleyiciye belirtirsek hem optimizasyon açısından hem de güvenlik açısından avantaj sağlarız, peki modern C++'da bunu yapmak için en iyi yol ne ? Bence constexpr bunun için uygun, örnek kullanım;

New_Settings.h:
Genişlet Daralt Kopyala
constexpr unsigned short MAP_ALLOW_LIMIT             = 32;         // Map Allow Limit.
constexpr unsigned short PK_LEVEL_FOR_PROTECT        = 15;         // PK Protect Level For New Players (Ex; If this is 15, nobody can hit (PvP) new players if they under 15 level)
constexpr unsigned short MAX_STAT                    = 95;         // Maximum Stat Points. (Note: The packside needs to be change too when you set another value here, to avoid gauge bug.)
constexpr unsigned short MAX_LEVEL_POINT_CAN_STEP    = 98;         // Maximum Level at Which The Character Will Continue to Gain Status.
constexpr unsigned short MAX_ITEM_INTRO_STACK        = 200;        // Maximum Number of Items Stacked (Maximum setting that can be made for now; 255).
constexpr unsigned long long GOLD_MAX                = 2000000000; // Maximum Yang Limit (Maximum setting that can be made for now {int}; 2.147.483.647 Yang).
constexpr unsigned short INVENTORY_MAX_NUM           = 90;         // Number of Inventory Slots (90 Slots = 2 Inventory). (Note: The sum of the slots of the inventory should not exceed 255 !!)

Bu şekilde hem optimize olması adına hem de çok daha güvenli bir tarz olması adına iyi bir adım atmış oluruz, siz benim yaptığımı yapmayın, sevgiler. :coffee:
 
Konuya yorum gelince şöyle ana mesaja tekrar bir göz atarken dikkatimi çekti, (dosyalarla o kadar uzun zamandır uğraşamadım ki ne yaptığımı unutacağım tuttuğum notlar olmasa 😅 ) bütün ana ayarları tuttuğum dosyada aslında yanlış bir tarz tercih ediyorum, sebebi benim eski alışkanlıklarımdır ama tabii ki değişmeli, bu konuyu yeni başlayan veya tarz olarak fikir almak için inceleyenler de olabilir o sebeple gözüme çarpmışken doğrusunu göstereyim.

Settings.h:
Genişlet Daralt Kopyala
/***********************************************************************/
/* FILE:    Settings.h                                                 */
/* INFO:    All important settings are linked to a single header file. */
/* AUTHOR:  MT2Dev                                                     */
/* DATE:    26/11/2020                                                 */
/***********************************************************************/
#ifndef __MT2DEV_SERVER_SETTINGS_H__
#define __MT2DEV_SERVER_SETTINGS_H__

// SECURITY_SETTINGS
#define CLIENT_VERSION_KEY                2407972020       // Client Version Key, it's must be same on the serverside!
#define LSS_SECURITY_KEY                4321dcba5678efgz // Ymir Security Key (Only used if _OLD_PACKET_ENCRYPTION_ is enabled)
// END_OF_SECURITY_SETTINGS

// VARIOUS_SETTINGS
#define MAP_ALLOW_LIMIT                    32         // Map Allow Limit.
#define PK_LEVEL_FOR_PROTECT            15         // PK Protect Level For New Players (Ex; If this is 15, nobody can hit (PvP) new players if they under 15 level)
#define MAX_STAT                        95         // Maximum Stat Points. (Note: The packside needs to be change too when you set another value here, to avoid gauge bug.)
#define MAX_LEVEL_POINT_CAN_STEP        98         // Maximum Level at Which The Character Will Continue to Gain Status.
#define MAX_ITEM_INTRO_STACK            200        // Maximum Number of Items Stacked (Maximum setting that can be made for now; 255).
#define GOLD_MAX                        2000000000 // Maximum Yang Limit (Maximum setting that can be made for now {int}; 2.147.483.647 Yang).
#define INVENTORY_MAX_NUM                90         // Number of Inventory Slots (90 Slots = 2 Inventory). (Note: The sum of the slots of the inventory should not exceed 255 !!)
#define INVENTORY_PAGE_COUNT            2          // Inventory Total Page Count.
#define ITEM_DROP_PENALTY_LEVEL            50         // Minimum Level to Item Drop Penalty (Note: If the low rank character is below level 50, their item will not drop.)
#define MOBS_DISAPPEARANCE_TIME            3          // Mobs disappearance time(Second) after death, it needs to be kept low to avoid lag.
#define AUTO_RESTART_TOWN_TIME            180        // After Player's die, if they not choose start here/town, after this time they will be spawn in town automatically.
#define BRAVE_CAPE_POSSIBILITY            80         // Brave Cape - Possibility(%) (With just one click) to Attract Monsters.
#define BRAVE_CAPE_MAX_DISTANCE            5000       // Brave Cape - Maximum Distance Of Monsters You Can Attract.
#define CAMPFIRE_TIME                    30         // How many seconds will the campfire be active after using it ?
#define STONE_INSERT_PERCENT_CHANCE        30         // Chance(%) For Stones to be Added.
#define ORE_INSERT_PERCENT_CHANCE        50         // Percentage(%) of Success When Adding Ores to The Item.
#define ITEM_ACCESSORY_SOCKET_MAX_NUM    3          // Maximum Number of Ores That Can Be Added to Interior Items.
#define KILLER_MODE_COOLDOWN            30         // After PC's set PvP mode Free or Guild, how many seconds need to set Peace after not hit anyone.
#define SHORT_PORTAL_LIMIT_TIME            3          // Cooldown Before Warp When Not Doing Anything Recently.
#define PORTAL_LIMIT_TIME                10         // Cooldown Before Warp For Trading or Post-Battle Control.
#define REQUEST_LIMIT_TIME                10         // Validity Seconds Of Requests Received By Players.
#define ITEM_DESTROY_TIME                10         // The Time(Second) It Takes For an Item The Player Throws to Disappear.
#define OWNER_ITEM_DESTROY_TIME            240        // The Time(Second) It Takes For an Item To Drop Specifically For One Player To Disappear or Delete Ownership. (Items with an anti-flag against dropping, that is, only the owner can take that item.)
#define DROP_ITEM_DESTROY_TIME            60         // The Time(Second) It Takes For an Item To Drop Player. (with ownership)
#define ORE_ITEM_OWNERSHIP_TIME            20         // The Time(Second) It Takes For an Ore Item(Mining) To Drop Player. (with ownership)
#define CAN_RESET_HERE_TIME                170        // How Soon After The Character Dies Will He Be Able to Stand Up ? (170 = 10 Seconds) (Respawn Here)
#define CAN_RESET_TOWN_TIME                173        // How Soon After The Character Dies Will He Be Able to Stand Up ? (173 =  7 Seconds) (Respawn Town)
#define CAN_SHOUT_LEVEL_LIMIT            15         // Level Required to Shout.
#define CAN_SHOUT_TIME_LIMIT            15         // Time Required to Shout.
#define PARTY_CAN_JOIN_MAX_LEVEL        30         // Maximum Level Difference Between Players to Enter a Group.
#define MAX_MEMBER_INTRO_PARTY            8          // Maximum Number of Players That Can Be in a Group.
#define SAFEBOX_MAX_NUM                    135        // Maximum Number of Safebox Slots (135 Slots = 3 Page).
#define SAFEBOX_PASSWORD_MAX_LEN        6          // Safebox Maximum Password Length.
#define DEAD_HORSE_DISAPPEAR_TIME        20         // When Player Summon Their Dead Horse, How Many Seconds Take To Disappear ?
#define NEW_CHAR_CREATE_COOLDOWN        30         // Players Can Only Create One Character Per 30 Seconds (To Prevent Spam).
#define NECESSARY_GOLD_FOR_GUILD        200000     // Necessary Yang For Create a New Guild.
#define NECESSARY_LEVEL_FOR_GUILD        40         // Necessary Level For Create a New Guild.
// END_OF_VARIOUS_SETTINGS

// TRICKY_SETTINGS
// WARNING: Don't change this one's, if you don't know what are you doing exactly.. - [MT2Dev Note] - 30/05/2023
#define QUEST_NAME_MAX_LEN                32
#define QUEST_STATE_MAX_LEN                64
#define MAX_ALLOW_USER                    4096
#define DRAGON_SOUL_STRENGTH_MAX        7
#define MAX_BLEND_ITEM_VALUE            5
#define POLYMORPH_SKILL_ID                129
#define POLYMORPH_BOOK_ID                50322
#define OXEVENT_MAP_INDEX                113
#define NORM_ATTR_MAX                    5
#define RARE_ATTR_MAX                    2
#define GUILD_SYMBOL_FILENAME            "guild_symbol.tga"
#define OLD_MARK_INDEX_FILENAME            "guild_mark.idx"
#define OLD_MARK_DATA_FILENAME            "guild_mark.tga"
// END_OF_TRICKY_SETTINGS
#endif //__MT2DEV_SERVER_SETTINGS_H__

Bu header dosyası sadece bu tarz ayarları tutmak için kullanılıyor ama gördüğünüz üzere ben hepsini eski usul #define ile tanımlamışım, burada yanlış bir tercih olduğunu net olarak söyleyebiliriz, nedeni şu; burada tanımlanan değerler hem derleme zamanında hem de çalışma zamanında sabit kalmalı, eğer bunların sabit kalacağını derleyiciye belirtirsek hem optimizasyon açısından hem de güvenlik açısından avantaj sağlarız, peki modern C++'da bunu yapmak için en iyi yol ne ? Bence constexpr bunun için uygun, örnek kullanım;

New_Settings.h:
Genişlet Daralt Kopyala
constexpr unsigned short MAP_ALLOW_LIMIT             = 32;         // Map Allow Limit.
constexpr unsigned short PK_LEVEL_FOR_PROTECT        = 15;         // PK Protect Level For New Players (Ex; If this is 15, nobody can hit (PvP) new players if they under 15 level)
constexpr unsigned short MAX_STAT                    = 95;         // Maximum Stat Points. (Note: The packside needs to be change too when you set another value here, to avoid gauge bug.)
constexpr unsigned short MAX_LEVEL_POINT_CAN_STEP    = 98;         // Maximum Level at Which The Character Will Continue to Gain Status.
constexpr unsigned short MAX_ITEM_INTRO_STACK        = 200;        // Maximum Number of Items Stacked (Maximum setting that can be made for now; 255).
constexpr unsigned long long GOLD_MAX                = 2000000000; // Maximum Yang Limit (Maximum setting that can be made for now {int}; 2.147.483.647 Yang).
constexpr unsigned short INVENTORY_MAX_NUM           = 90;         // Number of Inventory Slots (90 Slots = 2 Inventory). (Note: The sum of the slots of the inventory should not exceed 255 !!)

Bu şekilde hem optimize olması adına hem de çok daha güvenli bir tarz olması adına iyi bir adım atmış oluruz, siz benim yaptığımı yapmayın, sevgiler. :coffee:
short yerine uint8_t tercih edebilirsin. He ne dersin ? 🤣
 
Son düzenleme:
Geri
Üst