question

Siddharth avatar image
Siddharth asked

How can I ban a user (Single User) from api, Unity plugin, C#

How can I ban a user (Single User) from api, Unity plugin, C#

I want a detail code example on it. I'm trying to resolve it from last 3 days but didn't resolve it yet.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using PlayFab;
using PlayFab.AdminModels;




void BanUserForCheating() {
	string playfabId = PlayerPrefs.GetString("SetPlayfabId");


	BanRequest parameters = new BanRequest {
		PlayFabId = playfabId,
		DurationInHours = 1,
		Reason = "For Speed Hack"
	};


	BanUsersRequest request = new BanUsersRequest {
		Bans = {
			parameters
		}
	};


	PlayFabAdminAPI.BanUsers(request, OnBanUserSuccess, OnBanUserFailure);


}


private void OnBanUserSuccess(BanUsersResult result) {
	foreach(var item in result.BanData) {
		string a = item.Reason;
	}
}


private void OnBanUserFailure(PlayFabError error) {
	print(error.Error);
}

apisunity3dandroid
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Seth Du avatar image
Seth Du answered

Please always refer to the API document and check the types for each properties in the request.

The “Bans” in the request is List type, meanwhile it is used as an object in the sample code you have shared. Here is an example:

               PlayFabServerAPI.BanUsers(
                    new PlayFab.ServerModels.BanUsersRequest {
                        Bans = new List<PlayFab.ServerModels.BanRequest> {
                            new PlayFab.ServerModels.BanRequest
                            {
                                IPAddress = "xxxxx",
                                DurationInHours = 1,
                                PlayFabId = "xxxx"
                            },
                            new PlayFab.ServerModels.BanRequest
                            {
                                IPAddress = "xxxx",
                                DurationInHours = 1,
                                PlayFabId = "xxxxx"
                            },
                        }
                    },
                    success=> { },
                    failed=> { });
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Siddharth avatar image
Siddharth answered

The code that you have given to me is not working, It is not performing ban, it is not banning the user,

Please check the code that you have provided.

I written the code which i written for instance. check it

  void BanUserForCheating()
    {
        string playfabId = PlayerPrefs.GetString("SetPlayfabId");

        PlayFabServerAPI.BanUsers(
                    new PlayFab.ServerModels.BanUsersRequest
                    {
                        Bans = new List<PlayFab.ServerModels.BanRequest> {
                            new PlayFab.ServerModels.BanRequest
                            {
                               // IPAddress = "xxxxx",
                                DurationInHours = 1,
                                PlayFabId = "4759547F7F90CF31"
                            },
                            new PlayFab.ServerModels.BanRequest
                            {
                               // IPAddress = "xxxx",
                                DurationInHours = 1,
                                PlayFabId = "4759547F7F90CF31"
                            },
                        }
                    },

                    success =>
                    {
                        foreach (var item in success.BanData
                        )
                        {
                            string a = item.Reason;
                        }

                    },

                    failed =>
                    {

                    });

    }


1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Seth Du avatar image Seth Du ♦ commented ·

May I ask what's the responed error?

0 Likes 0 ·
Siddharth avatar image
Siddharth answered

No, I am not getting any results of success or failed. I think the code itself is not working.

for instance, If the code works then i may get any the results callback link Success or Failed, but i am getting nothing.

Please check it from your side. please.

1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Seth Du avatar image Seth Du ♦ commented ·

It seems you haven't implement failed callback result.

You may add

print(failed.GenerateErrorReport());

under your failed action.

If there are any other question, you may use network capture tool like fiddler to track your API.

Otherwise, we will need a sample reproduction project from you for us to dig into it.

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.