### Database Setup Source: https://context7.com/danielbrockhaus/astonia_server/llms.txt Installs MariaDB server and imports necessary SQL tables for the game database. ```bash # Database setup (MySQL/MariaDB required) sudo apt install mariadb-server ./my : Set the area ID this server handles // -m : Set the mirror number // -d : Daemonize the server // -c : Disable concurrent database access // Starting the server for area 1: ./server -a 1 -m 0 // Server version is defined in server.h: #define VERSION 0x030100 // Version 3.01.00 // Core tick timing constants: #define TICKS 24 // Ticks per second #define TICK (1000000ull/TICKS) // Microseconds per tick // Memory limits (configurable): #define MAXMAP 256 // Map dimensions #define TOTAL_MAXCHARS 2048 // Maximum characters ``` -------------------------------- ### Build Server with Make Source: https://context7.com/danielbrockhaus/astonia_server/llms.txt Compiles the Astonia server and its modules using the provided Makefile. ```bash # Build the complete server make ``` -------------------------------- ### Run Astonia Server Scripts Source: https://github.com/danielbrockhaus/astonia_server/blob/main/readme.md Executes SQL scripts to create tables and load data for the Astonia server using the 'my' script. ```bash ./my motd.txt rm MYSQLPASSWD ``` -------------------------------- ### Initialize Database Connection Source: https://context7.com/danielbrockhaus/astonia_server/llms.txt Initializes the connection to the MySQL database. This function must be called before any other database operations can be performed. ```c // database.h - Database API // Initialize database connection int success = init_database(); ``` -------------------------------- ### Create Message of the Day Source: https://context7.com/danielbrockhaus/astonia_server/llms.txt Creates a text file to store the server's message of the day. ```bash # Create message of the day echo "Welcome to Astonia" > motd.txt ``` -------------------------------- ### Transfer Player to Another Server in C Source: https://context7.com/danielbrockhaus/astonia_server/llms.txt Initiates the transfer of a player's session to a different game server. ```c player_to_server(player_nr, server_address, port); ``` -------------------------------- ### Astonia Server Security Note Source: https://github.com/danielbrockhaus/astonia_server/blob/main/readme.md A warning that the 'my' script, while handy, can be a security risk. ```bash # the "my" script is very handy, but also a security risk! ``` -------------------------------- ### Compute Path for Navigation in C Source: https://context7.com/danielbrockhaus/astonia_server/llms.txt Calculates the next direction to move a character towards a target destination using pathfinding algorithms. ```c int next_dir = compute_path(cn, target_x, target_y); ``` -------------------------------- ### Player Login Authentication Source: https://context7.com/danielbrockhaus/astonia_server/llms.txt Handles player login by verifying credentials against the database. It retrieves character information, including area, object ID, and mirror status, for the logged-in player. ```c // Player login - finds character and returns area info int result = find_login(name, password, &area, &cn, &mirror, &ID, vendor, &unique, client_ip); ``` -------------------------------- ### Character and Item Creation API Source: https://context7.com/danielbrockhaus/astonia_server/llms.txt API for creating characters and items from templates or by allocating raw slots. Includes functions for character lookup and freeing. ```c // create.h - Character and item creation API // Create a new character from template name int cn = create_char("orc_warrior", areaID); if (cn == 0) { elog("Failed to create character"); return; } // Create character from template number int cn = create_char_nr(template_number, area_id); // Create an item from template name int in = create_item("iron_sword"); if (in == 0) { elog("Failed to create item"); return; } // Allocate a raw character slot (for custom initialization) int cn = alloc_char(); if (cn) { ch[cn].flags = CF_USED | CF_PLAYER; strcpy(ch[cn].name, "NewPlayer"); ch[cn].x = 100; ch[cn].y = 100; update_char(cn); // Recalculate derived values } // Free a character when no longer needed free_char(cn); // Lookup character by name int cn = lookup_char("PlayerName"); if (cn) { log_char(cn, LOG_SYSTEM, 0, "Found you!"); } ``` -------------------------------- ### Send Inventory Update to Client in C Source: https://context7.com/danielbrockhaus/astonia_server/llms.txt Notifies a player's client about changes to their inventory. ```c plr_send_inv(cn, target_cn); ``` -------------------------------- ### Grant Experience Points in C Source: https://context7.com/danielbrockhaus/astonia_server/llms.txt Functions to award experience points to a character. `give_exp_bonus` includes a clan learning bonus. ```c give_exp(cn, exp_value); ``` ```c give_exp_bonus(cn, exp_value); // With clan learning bonus ``` -------------------------------- ### Create Persistent Storage Source: https://context7.com/danielbrockhaus/astonia_server/llms.txt Creates a new entry in the persistent storage system. This is used to store arbitrary game data that needs to be saved across server restarts. ```c // Storage system for persistent data int result = create_storage(id, description, content, size); ``` -------------------------------- ### Define NPC Driver Numbers and Entry Point Source: https://context7.com/danielbrockhaus/astonia_server/llms.txt Defines constants for character driver types and the main entry point function for NPC driver modules. The `driver` function dispatches calls to specific handlers based on the type of event. ```c // drvlib.h - Driver numbers and helper functions // Character driver numbers (CDR_*) #define CDR_LOSTCON 5 // Player who lost connection #define CDR_MERCHANT 6 // Generic merchant #define CDR_SIMPLEBADDY 7 // Generic aggressive NPC #define CDR_BANK 22 // Bank NPC #define CDR_PROFESSOR 55 // Profession teacher // Driver entry point in DLL modules (base.c example): int driver(int type, int nr, int obj, int ret, int lastact) { switch (type) { case CDT_DRIVER: return ch_driver(nr, obj, ret, lastact); case CDT_ITEM: return it_driver(nr, obj, ret); case CDT_DEAD: return ch_died_driver(nr, obj, ret); case CDT_RESPAWN: return ch_respawn_driver(nr, obj); default: return 0; } } ``` -------------------------------- ### Join/Leave Chat Channels in C Source: https://context7.com/danielbrockhaus/astonia_server/llms.txt Manipulates a character's channel subscription using bitmasks. `|=` joins, `&= ~` leaves. ```c ch[cn].channel |= (1 << 2); // Join Gossip ch[cn].channel &= ~(1 << 2); // Leave Gossip ``` -------------------------------- ### Character Data Structures and Flags Source: https://context7.com/danielbrockhaus/astonia_server/llms.txt Defines character flags (e.g., used, player, staff, dead) and value indices for attributes like HP, mana, and skills. Shows how to access character values. ```c // server.h - Character structure and flags // Character flags (CF_*) #define CF_USED (1ull<<0) // Slot is in use #define CF_PLAYER (1ull<<3) // Is a player character #define CF_STAFF (1ull<<4) // Staff member #define CF_DEAD (1ull<<11) // Character is dying #define CF_MALE (1ull<<14) // Male gender #define CF_FEMALE (1ull<<15) // Female gender #define CF_WARRIOR (1ull<<16) // Warrior class #define CF_MAGE (1ull<<17) // Mage class #define CF_RESPAWN (1ull<<13) // NPC will respawn // Value indices (V_*) #define V_HP 0 // Hit points #define V_ENDURANCE 1 // Endurance #define V_MANA 2 // Mana #define V_WIS 3 // Wisdom #define V_INT 4 // Intelligence #define V_AGI 5 // Agility #define V_STR 6 // Strength #define V_ARMOR 7 // Armor value #define V_WEAPON 8 // Weapon value #define V_ATTACK 18 // Attack skill #define V_PARRY 19 // Parry skill #define V_BLESS 28 // Bless spell skill #define V_HEAL 29 // Heal spell skill #define V_FIREBALL 33 // Fireball spell skill // Accessing character values: // ch[cn].value[0][V_HP] = total value (base + equipment + buffs) // ch[cn].value[1][V_HP] = base value only int total_hp = ch[cn].value[0][V_HP]; int base_hp = ch[cn].value[1][V_HP]; // Current HP/Mana are scaled by POWERSCALE (1000) int current_hp = ch[cn].hp; // Actual value int max_hp = ch[cn].value[0][V_HP] * POWERSCALE; ``` -------------------------------- ### Handle Player Driver Tick in C Source: https://context7.com/danielbrockhaus/astonia_server/llms.txt Processes a single tick of the player's session, handling input and updating game state. ```c player_driver(cn, return_value, last_action); ``` -------------------------------- ### NPC Driver Helper Functions Source: https://context7.com/danielbrockhaus/astonia_server/llms.txt Provides common helper functions for NPC driver modules, such as moving characters, attacking targets, checking for valid enemies, calculating distances, managing fight memory, and handling standard messages. ```c // Common driver helper functions: // Move character towards target coordinates int success = move_driver(cn, target_x, target_y, min_distance); // Attack a target character int success = attack_driver(cn, target_cn); // Check if target is a valid enemy int is_enemy = is_valid_enemy(cn, target_cn, check_memory); // Get distance between characters int dist = char_dist(cn, target_cn); // Add enemy to fight memory fight_driver_add_enemy(cn, enemy_cn, hurt_me, is_visible); // Standard message handler for NPCs standard_message_driver(cn, msg, is_aggressive, is_helper); ``` -------------------------------- ### Map Direction Helpers in C Source: https://context7.com/danielbrockhaus/astonia_server/llms.txt Utility functions to convert between map directions and coordinate offsets, and to calculate direction from coordinates. ```c int dx, dy, diag; dx2offset(direction, &dx, &dy, &diag); int dir = offset2dx(from_x, from_y, to_x, to_y); ``` -------------------------------- ### Define Chat Channel Indices in C Source: https://context7.com/danielbrockhaus/astonia_server/llms.txt Lists the numerical indices and common uses for various chat channels within the communication system. ```c // Channel indices // 0 = Announce (system messages) // 1 = Info (help requests) // 2 = Gossip (general chat) // 3 = Auction (trading) // 6 = Grats (congratulations) // 7 = Clan2 (clan private) // 8 = Area (local to area) // 31 = Staff (staff only) // 32 = God (admin only) ``` -------------------------------- ### Give Item to Character in C Source: https://context7.com/danielbrockhaus/astonia_server/llms.txt Transfers an item to a character's inventory. Returns success status. ```c int success = give_char_item(cn, item_in); ``` -------------------------------- ### Create and Update Club Source: https://context7.com/danielbrockhaus/astonia_server/llms.txt Functions to create and update club data. The club system is similar to clans but with different mechanics. ```c // Club system (similar to clans but different mechanics) int success = db_create_club(club_number); db_update_club(club_number); ``` -------------------------------- ### Add Clan Log Entry Source: https://context7.com/danielbrockhaus/astonia_server/llms.txt Adds a log entry to the clan's activity log. Used for tracking events like player joins. ```c // Clan logging add_clanlog(clan_id, serial, char_id, priority, "Player %s joined the clan", ch[cn].name); ``` -------------------------------- ### Define Action Types in C Source: https://context7.com/danielbrockhaus/astonia_server/llms.txt Defines constants for various character actions within the action system. Used to represent different states or commands for characters. ```c #define AC_IDLE 0 #define AC_WALK 1 #define AC_ATTACK 2 #define AC_USE 3 #define AC_TAKE 4 #define AC_DROP 5 #define AC_GIVE 6 ``` -------------------------------- ### Send Message to Player in C Source: https://context7.com/danielbrockhaus/astonia_server/llms.txt Sends a formatted message to a specific player's client, potentially with color coding. ```c log_player(player_nr, color, "Message text"); ``` -------------------------------- ### Kick Player from Server in C Source: https://context7.com/danielbrockhaus/astonia_server/llms.txt Removes a player from the server, optionally providing a reason for the disconnection. ```c kick_player(player_nr, "Reason for kick"); ``` -------------------------------- ### Request Character Action in C Source: https://context7.com/danielbrockhaus/astonia_server/llms.txt Logs a message indicating a character is performing an attack. This is part of the action system's logging mechanism. ```c do_char_log(cn, 0, "You attack %s!\n", ch[co].name); ``` -------------------------------- ### Define Notification Types in C Source: https://context7.com/danielbrockhaus/astonia_server/llms.txt Defines constants for different types of notifications that can be sent within the game world. ```c // Notification types (NT_*) #define NT_CHAR 1 // Character update #define NT_ITEM 2 // Item update #define NT_SOUND 3 // Sound effect ``` -------------------------------- ### Add Timer for Delayed Actions Source: https://context7.com/danielbrockhaus/astonia_server/llms.txt Adds a timer that will execute a callback function after a specified delay. ```c // Timer system for delayed actions int timer_id = add_timer(callback_tick, data); ``` -------------------------------- ### Access Map Tile Data in C Source: https://context7.com/danielbrockhaus/astonia_server/llms.txt Calculates the memory index for a map tile based on its coordinates and accesses the tile's data structure. ```c int m = x + y * MAXMAP; struct map *tile = &map[m]; ``` -------------------------------- ### Lookup Clan Log Entries Source: https://context7.com/danielbrockhaus/astonia_server/llms.txt Searches for clan log entries within a specified time range and criteria. ```c // Look up clan logs lookup_clanlog(cn_id, clan_id, serial, co_id, priority, from_time, to_time); ``` -------------------------------- ### Exit Character from Game in C Source: https://context7.com/danielbrockhaus/astonia_server/llms.txt Handles the process of a character logging out or disconnecting from the game. ```c exit_char(cn); ``` -------------------------------- ### Clean Build Artifacts Source: https://context7.com/danielbrockhaus/astonia_server/llms.txt Removes compiled files and build artifacts generated by the Makefile. ```bash # Clean build artifacts make clean ``` -------------------------------- ### Check Tile Walkability in C Source: https://context7.com/danielbrockhaus/astonia_server/llms.txt Determines if a map tile is walkable by checking if it's not blocked by movement restrictions and has no character present. ```c if (!(map[m].flags & MF_MOVEBLOCK) && !map[m].ch) { // Can walk here } ``` -------------------------------- ### Define Log Types in C Source: https://context7.com/danielbrockhaus/astonia_server/llms.txt Defines constants for different types of log messages used in the communication system. ```c // Log types #define LOG_SYSTEM 0 // System messages #define LOG_INFO 1 // Informational #define LOG_CHAT 2 // Chat messages ``` -------------------------------- ### Define Item Driver Numbers and Flags Source: https://context7.com/danielbrockhaus/astonia_server/llms.txt Defines constants for various item driver types and flags that describe item properties. These are used within the item driver system to manage item behaviors and states. ```c // drvlib.h - Item driver numbers (IDR_*) #define IDR_POTION 1 // Healing/mana potion #define IDR_DOOR 2 // Closable, lockable door #define IDR_CHEST 5 // Treasure chest #define IDR_TELEPORT 10 // Teleporter item #define IDR_TORCH 12 // Torch with on/off #define IDR_RECALL 13 // Recall scroll #define IDR_SHRINE 14 // Shrine for bonuses #define IDR_BOOK 16 // Readable book #define IDR_TRANSPORT 18 // Transport system // Item flags (IF_*) #define IF_USED (1ull<<0) // Slot is in use #define IF_TAKE (1ull<<3) // Can be picked up #define IF_USE (1ull<<4) // Can be used #define IF_WNHEAD (1ull<<5) // Wearable on head #define IF_WNBODY (1ull<<7) // Wearable on body #define IF_QUEST (1ull<<26) // Quest item (can't drop) #define IF_MONEY (1ull<<29) // Is money // Item modifiers (up to MAXMOD=5 per item): // it[in].mod_index[0-4] = which stat to modify (V_* values) // it[in].mod_value[0-4] = modification amount ``` -------------------------------- ### Place Character on Map in C Source: https://context7.com/danielbrockhaus/astonia_server/llms.txt Sets a character's position on the map. The `no_step_trap` parameter can affect behavior. ```c int success = set_char(cn, x, y, no_step_trap); ``` -------------------------------- ### Send System Message to Character in C Source: https://context7.com/danielbrockhaus/astonia_server/llms.txt Logs a system message to a specific character's output. Uses predefined log types. ```c log_char(cn, LOG_SYSTEM, 0, "Welcome to Astonia!"); ``` -------------------------------- ### Define Player Action Codes in C Source: https://context7.com/danielbrockhaus/astonia_server/llms.txt Constants representing various actions a player can perform, used in player session management. ```c #define PAC_IDLE 0 #define PAC_MOVE 1 #define PAC_TAKE 2 #define PAC_DROP 3 #define PAC_KILL 4 #define PAC_USE 5 #define PAC_BLESS 6 #define PAC_HEAL 7 #define PAC_FIREBALL 9 #define PAC_GIVE 15 ``` -------------------------------- ### Save Character to Database Source: https://context7.com/danielbrockhaus/astonia_server/llms.txt Saves the current state of a character to the database. This is crucial for persistence, ensuring player progress is maintained between sessions. ```c // Save character to database int result = save_char(cn, area); ``` -------------------------------- ### Create Spell Effect Source: https://context7.com/danielbrockhaus/astonia_server/llms.txt Creates a new spell effect with specified type, caster, strength, and duration. ```c // Create a spell effect int en = create_effect(type, caster_cn, strength, duration); ``` -------------------------------- ### Check Attack Permission in C Source: https://context7.com/danielbrockhaus/astonia_server/llms.txt Checks if a character is allowed to attack another character. Requires the `can_attack` function. ```c if (can_attack(cn, co)) { // Proceed with attack } ``` -------------------------------- ### Reset Player Map Cache in C Source: https://context7.com/danielbrockhaus/astonia_server/llms.txt Forces a player's client to refresh its cached map data, ensuring an accurate visual representation. ```c player_reset_map_cache(player_nr); ``` -------------------------------- ### Check Asynchronous Storage Read Result Source: https://context7.com/danielbrockhaus/astonia_server/llms.txt Checks the status of an asynchronous storage read operation. If the data is ready, it populates the provided pointers with the version, data, and size. ```c // Check async storage read result int version; void *data; int size; if (check_read_storage(&version, &data, &size)) { // Data is ready } ``` -------------------------------- ### Define Map Flags in C Source: https://context7.com/danielbrockhaus/astonia_server/llms.txt Defines bitmask flags for map tiles, indicating properties like movement blocking, sight blocking, and special area types. ```c #define MF_MOVEBLOCK (1ULL<<0) // Blocks movement #define MF_SIGHTBLOCK (1ULL<<1) // Blocks line of sight #define MF_INDOORS (1ull<<4) // Indoor area #define MF_RESTAREA (1ull<<5) // Rest/save area #define MF_DOOR (1ull<<6) // Door tile #define MF_ARENA (1ull<<11) // PvP arena #define MF_PEACE (1ull<<12) // No fighting allowed ``` -------------------------------- ### Calculate Damage Reduction in C Source: https://context7.com/danielbrockhaus/astonia_server/llms.txt Determines the amount of damage reduction based on target's immunities or resistances to a spell. ```c int reduced = immunity_reduction(caster_cn, target_cn, spell_strength); ``` -------------------------------- ### Read Persistent Storage Source: https://context7.com/danielbrockhaus/astonia_server/llms.txt Reads data from the persistent storage system. This function retrieves stored content based on its ID and version. ```c int result = read_storage(id, version); ``` -------------------------------- ### Access Clan Rank Source: https://context7.com/danielbrockhaus/astonia_server/llms.txt Retrieves the rank of a character within their clan. Rank 4 is the leader. ```c // Clan ranks (0-4, where 4 is leader) int rank = ch[cn].clan_rank; ``` -------------------------------- ### Check Line of Sight in C Source: https://context7.com/danielbrockhaus/astonia_server/llms.txt Determines if one character can see another character on the map, considering obstacles. ```c int can_see = char_see_char(cn, co); ``` -------------------------------- ### Character Says Message in C Source: https://context7.com/danielbrockhaus/astonia_server/llms.txt Makes a character speak a message that is audible to nearby characters. Uses the `say` function. ```c say(cn, "Hello, adventurer!"); ``` -------------------------------- ### Apply Spell Bonus in C Source: https://context7.com/danielbrockhaus/astonia_server/llms.txt Adds a spell effect to a character, such as a bless spell, with specified strength and duration. ```c int success = add_bonus_spell(cn, IDR_BLESS, strength, duration); ``` -------------------------------- ### Effect Type Definitions Source: https://context7.com/danielbrockhaus/astonia_server/llms.txt Defines constants for various spell effect types used in the game. ```c // Effect types for spells #define EF_BLESS 1 #define EF_FREEZE 2 #define EF_FLASH 3 #define EF_FIREBALL 4 // etc. ``` -------------------------------- ### Update Persistent Storage Source: https://context7.com/danielbrockhaus/astonia_server/llms.txt Updates an existing entry in the persistent storage system with new content. This allows for modifying saved game data. ```c int result = update_storage(id, version, content, size); ``` -------------------------------- ### Log Game Actions Source: https://context7.com/danielbrockhaus/astonia_server/llms.txt Logs significant game events or actions for auditing purposes. This function records details about the event, including involved characters and items. ```c // Log an action for auditing dlog(cn, in, "Player %s picked up item %s", ch[cn].name, it[in].name); ``` -------------------------------- ### Notify Area of Event in C Source: https://context7.com/danielbrockhaus/astonia_server/llms.txt Sends a notification to all characters within a specific area about an event, such as a character update. ```c notify_area(ch[cn].x, ch[cn].y, NT_CHAR, cn, 0, 0); ``` -------------------------------- ### Calculate Fireball Damage in C Source: https://context7.com/danielbrockhaus/astonia_server/llms.txt Calculates the damage dealt by a fireball spell, considering caster, target, and spell strength. ```c int damage = fireball_damage(caster_cn, target_cn, spell_strength); ``` -------------------------------- ### Effect Structure Definition Source: https://context7.com/danielbrockhaus/astonia_server/llms.txt Defines the structure for managing spell effects, including type, duration, creator, and strength. ```c // Effect structure manages visual and gameplay effects struct effect { int type; // Effect type int serial; // Unique ID int start, stop; // Tick range int cn, sercn; // Creator int strength; // Effect power int light; // Light emission // ... position and field data }; ``` -------------------------------- ### Add Visual Effect Source: https://context7.com/danielbrockhaus/astonia_server/llms.txt Adds a visual effect to the game world at a specific position and direction. ```c // Add visual effect at position add_effect(type, x, y, direction, strength); ``` -------------------------------- ### Calculate Map Distance in C Source: https://context7.com/danielbrockhaus/astonia_server/llms.txt Computes the distance between two points on the map. ```c int distance = map_dist(from_x, from_y, to_x, to_y); ``` -------------------------------- ### Read In-Game Mail Source: https://context7.com/danielbrockhaus/astonia_server/llms.txt Retrieves in-game mail messages for a specific recipient from a sender. It populates a buffer with the mail content and returns the next mail sequence number. ```c // Read mail unsigned long long next = get_mail(to_id, from_id, buffer, start); ``` -------------------------------- ### Send In-Game Mail Source: https://context7.com/danielbrockhaus/astonia_server/llms.txt Sends an in-game mail message from one player to another. This function is used for communication within the game world. ```c // Send in-game mail int result = send_mail(to_id, from_id, "Hello from Astonia!"); ``` -------------------------------- ### Change Character Area Source: https://context7.com/danielbrockhaus/astonia_server/llms.txt Transfers a character to a different game area, potentially across different servers. This function updates the character's location and ensures smooth transition. ```c // Change character's area (transfer between servers) int result = change_area(cn, new_area, x, y); ``` -------------------------------- ### Check Clan Alliance Status Source: https://context7.com/danielbrockhaus/astonia_server/llms.txt Checks if two clans are allied. Returns an integer indicating alliance status. ```c // Check clan alliance int allied = clan_alliance(clan1, clan2); ``` -------------------------------- ### Check Timer Expiration Source: https://context7.com/danielbrockhaus/astonia_server/llms.txt Checks if a timer has expired based on the current ticker value. ```c // Check if timer expired if (ticker >= timer_stop) { // Timer fired } ``` -------------------------------- ### Release Character Lock Source: https://context7.com/danielbrockhaus/astonia_server/llms.txt Releases any locks held on a character's data in the database. This is typically done after operations that require exclusive access, preventing race conditions. ```c // Release character lock int result = release_char(cn); ``` -------------------------------- ### Character Quietly Says Message in C Source: https://context7.com/danielbrockhaus/astonia_server/llms.txt Allows a character to send a message with specific formatting, often used for status or private remarks. ```c quiet_say(cn, "I'm %s.", ch[cn].name); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.