Accepting Guild Join Requests
1. Write a method for accepting guild join requests
Add content to the ApproveGuildJoinRequest method in BackndGuild.cs written in Pre-arrangements.
BackndGuild.cs
Before editing
public void ApproveGuildJoinRequest(int index) {
// Step 4. Accepting Guild Join Requests
}
After editing
public void ApproveGuildJoinRequest(int index) {
var bro = Backnd.Guild.GetGuildJoinRequestList();
if(bro.IsSuccess() == false) {
Debug.LogError("An error occurred while loading the list of users who requested to join the guild. : " + bro);
return;
}
Debug.Log("Successfully loaded the list of users who requested to join the guild. : " + bro);
if(bro.FlattenRows().Count <= 0) {
Debug.LogError("There are no users who requested to join. : " + bro);
return;
}
List<Tuple<string, string>> requestUserList = new List<Tuple<string, string>>();
foreach(BACKND.LitJson.JsonData requestJson in bro.FlattenRows()) {
requestUserList.Add(new Tuple<string, string>(requestJson["nickname"].ToString(), requestJson["inDate"].ToString()));
}
string userString = "Join request list\n";
for(int i = 0; i < requestUserList.Count; i++) {
userString += $"{index}. {requestUserList[i].Item1}({requestUserList[i].Item2})\n";
}
Debug.Log(userString);
bro = Backnd.Guild.ApproveGuildJoinRequest(requestUserList[index].Item2);
if(bro.IsSuccess() == false) {
Debug.LogError($"An error occurred while approving the join request of {requestUserList[index].Item1}({requestUserList[index].Item2}). : " + bro);
return;
}
Debug.Log($"Successfully accepted the join request of {requestUserList[index].Item1}({requestUserList[index].Item2}).: " + bro);
}
2. Add method call to BackndManager.cs
BackndManager, which is automatically called when the game is executed, must be used to call this method.
Add it so that the method may be called after BACKND initialization and BACKND login.
At this time, the user to log in must be the one that called Step 2. Creating Guilds.
BackndManager.cs
Before editing
async void Test() {
await Task.Run(() => {
BackndLogin.Instance.CustomSignUp("guildUser", "1234"); // New sign-up of user for the guild
BackndLogin.Instance.ChangeDisplayName("guildUser"); // Nickname registration of user for the guild
BackndGuild.Instance.RequestGuildJoin("Desired_guild_name"); // The guild name entered in CreateGuild during Step 2 should be entered as the parameter value.
Debug.Log("Test complete.");
});
}
After editing
async void Test() {
await Task.Run(() => {
BackndLogin.Instance.CustomSignIn("user1", "1234"); // Must be logged in as the user who created the guild in Step 2.
BackndGuild.Instance.ApproveGuildJoinRequest(0); // From users who sent join requests, accepts the one who sent the most recent request.
Debug.Log("Test complete.");
});
}
3. Test in Unity
After editing the script, execute Unity debugging and check the console log of Unity.
the method has been successfully called when the log displays 'Successfully accepted the join request from OO. : statusCode : 204'.
When errors, such as statusCode : 400, 404, and 409, occur instead of the above log, you can check which errors caused the failure in ApproveGuildJoinRequest and GetGuildJoinRequestList error case.
4. Check in the console
Go to BACKND Base, and in BACKND Base > Guild Management
, click the created guild and check that the member count has increased.