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
- 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.
- Implementing Server Message Functions: In the
Guild.javafile, create functions to handle different types of messages likesendGuildData(),sendMemberData(),sendRankData(),sendMOTD(), andsendGuildChat(). These functions will create aMapof properties for each message and send them to the client usingTargetedExtensionMessage.- Example for
sendGuildData:public void sendGuildData(OID targetOid) {
// Code to set up message properties and send the message
}
- Example for
Step 2: Client Message Handlers
- Implementing Handlers in
AtavismGuildClass: Create handler functions in the UnityAtavismGuildscript to process the received messages. Each handler should take aDictionary<string, object>as a parameter. - Registering Handlers: Register these handlers in the
Start()function of theAtavismGuildclass, associating them with their respectiveext_msg_subtype.- Example:
NetworkAPI.RegisterExtensionMessageHandler("sendGuildData", HandleGuildData);
- Example:
Step 3: Client-to-Server Messages
- Setting up MessageTypes: In the
GuildPlugin.javafile, defineMessageTypeconstants for client-to-server messages like guild creation, invite responses, and guild commands. - Implementing Client Message Functions: In the
AtavismGuild.csfile 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
}
- Example:
Step 4: Server Handling of Client Messages
- Creating Hooks in
GuildPlugin.java: Implement Hook classes for each MessageType in the server code to process incoming messages from the client. - Registering Hooks: In the
registerHooks()function of theGuildPlugin, register these hooks to associate them with their MessageType.
Step 5: Linking Actions to Messages
- Implementing Guild Creation Flow: Start with handling the
/createGuildcommand in theStandardCommands.csscript in Unity. Call theCreateGuild()function from theAtavismGuildscript when the command is issued. - Implementing Server Logic: In the
GuildCreateHookclass 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
- Implementing Spawn and Logout Hooks: Add
SpawnedHookandLogoutHookin theGuildPluginto handle player login and logout events, respectively. These hooks will notify the guild system of the player’s online status. - Guild Member Status Updates: In the
Guild.javafile, implementmemberLoggedIn()andmemberLoggedOut()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.
