Atavism Online

In this fourth part of the series, we establish the messaging system between the client and server to enable efficient data transfer for the Guild System in Atavism. This involves modifications to both the client (Unity) and the server (AGIS).

Prerequisites:

  • Completion of the previous parts of this guide.

Step 1: Server-to-Client Messages

  1. Identify Necessary Messages: Determine what information needs to be sent from the server to the client, such as guild data, member updates, rank changes, MOTD updates, and guild chat messages.
  2. Implementing Server Message Functions: In the Guild.java file, create functions to handle different types of messages like sendGuildData(), sendMemberData(), sendRankData(), sendMOTD(), and sendGuildChat(). These functions will create a Map of properties for each message and send them to the client using TargetedExtensionMessage.
    • Example for sendGuildData:
      public void sendGuildData(OID targetOid) {
      // Code to set up message properties and send the message
      }

Step 2: Client Message Handlers

  1. Implementing Handlers in AtavismGuild Class: Create handler functions in the Unity AtavismGuild script to process the received messages. Each handler should take a Dictionary<string, object> as a parameter.
  2. Registering Handlers: Register these handlers in the Start() function of the AtavismGuild class, associating them with their respective ext_msg_subtype.
    • Example:
      NetworkAPI.RegisterExtensionMessageHandler("sendGuildData", HandleGuildData);

Step 3: Client-to-Server Messages

  1. Setting up MessageTypes: In the GuildPlugin.java file, define MessageType constants for client-to-server messages like guild creation, invite responses, and guild commands.
  2. Implementing Client Message Functions: In the AtavismGuild.cs file in Unity, implement functions to send messages to the server for actions like creating a guild, responding to invitations, and executing guild commands.
    • Example:
      public void CreateGuild(string guildName) {
      // Code to send message to server
      }

Step 4: Server Handling of Client Messages

  1. Creating Hooks in GuildPlugin.java: Implement Hook classes for each MessageType in the server code to process incoming messages from the client.
  2. Registering Hooks: In the registerHooks() function of the GuildPlugin, register these hooks to associate them with their MessageType.

Step 5: Linking Actions to Messages

  1. Implementing Guild Creation Flow: Start with handling the /createGuild command in the StandardCommands.cs script in Unity. Call the CreateGuild() function from the AtavismGuild script when the command is issued.
  2. Implementing Server Logic: In the GuildCreateHook class on the server side, add logic to handle guild creation, including checking if a guild with the same name exists, creating a new guild, and updating the database.

Step 6: Handling Player Login and Logout

  1. Implementing Spawn and Logout Hooks: Add SpawnedHook and LogoutHook in the GuildPlugin to handle player login and logout events, respectively. These hooks will notify the guild system of the player’s online status.
  2. Guild Member Status Updates: In the Guild.java file, implement memberLoggedIn() and memberLoggedOut() functions to update the member’s status and notify other guild members.

By following these steps, you have set up a foundational system for guild communication between the server and client in Atavism. This system handles key guild functionalities like creation, member updates, and communication. The next part of the series will focus on developing the UI and implementing more guild commands.