Profiles should be fine now. I just need to do server code that's it
This commit is contained in:
@@ -40,38 +40,7 @@ public class MenuScript : MonoBehaviour
|
|||||||
{
|
{
|
||||||
var clone = Instantiate(profilePrefab.gameObject, profilePrefab.gameObject.transform.parent);
|
var clone = Instantiate(profilePrefab.gameObject, profilePrefab.gameObject.transform.parent);
|
||||||
clone.SetActive(true);
|
clone.SetActive(true);
|
||||||
var customIconData = BazookaManager.Instance.GetCustomBirdIconData();
|
await clone.GetComponent<ProfileMenu>().Init();
|
||||||
string customIcon = null;
|
|
||||||
if (customIconData.Selected != null)
|
|
||||||
{
|
|
||||||
foreach (var icon in customIconData.Data)
|
|
||||||
{
|
|
||||||
if (icon.UUID == customIconData.Selected)
|
|
||||||
{
|
|
||||||
customIcon = icon.Data;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
var iconColor = BazookaManager.Instance.GetColorSettingIcon();
|
|
||||||
var overlayColor = BazookaManager.Instance.GetColorSettingOverlay();
|
|
||||||
await clone.GetComponent<ProfileMenu>().Init(
|
|
||||||
BazookaManager.Instance.GetGameStoreTotalNormalBerries().ToString(),
|
|
||||||
BazookaManager.Instance.GetGameStoreTotalPoisonBerries().ToString(),
|
|
||||||
BazookaManager.Instance.GetGameStoreTotalSlowBerries().ToString(),
|
|
||||||
BazookaManager.Instance.GetGameStoreTotalUltraBerries().ToString(),
|
|
||||||
BazookaManager.Instance.GetGameStoreTotalSpeedyBerries().ToString(),
|
|
||||||
BazookaManager.Instance.GetGameStoreTotalCoinBerries().ToString(),
|
|
||||||
BazookaManager.Instance.GetGameStoreTotalRandomBerries().ToString(),
|
|
||||||
BazookaManager.Instance.GetGameStoreTotalAntiBerries().ToString(),
|
|
||||||
customIconData.Balance.ToString(),
|
|
||||||
BazookaManager.Instance.GetAccountName().ToString(),
|
|
||||||
BazookaManager.Instance.GetAccountID() ?? 0,
|
|
||||||
BazookaManager.Instance.GetBirdIcon(),
|
|
||||||
BazookaManager.Instance.GetBirdOverlay(),
|
|
||||||
customIcon,
|
|
||||||
new Color((int)iconColor[0] / 255f, (int)iconColor[1] / 255f, (int)iconColor[2] / 255f),
|
|
||||||
new Color((int)overlayColor[0] / 255f, (int)overlayColor[1] / 255f, (int)overlayColor[2] / 255f)
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
profileButton.gameObject.SetActive(true);
|
profileButton.gameObject.SetActive(true);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,4 +6,6 @@ public class Endpoints
|
|||||||
public static readonly string LEADERBOARDS_COIN_ENDPOINT = BASE_URL + "/berrydash/leaderboards/coin";
|
public static readonly string LEADERBOARDS_COIN_ENDPOINT = BASE_URL + "/berrydash/leaderboards/coin";
|
||||||
public static readonly string LEADERBOARDS_LEGACY_ENDPOINT = BASE_URL + "/berrydash/leaderboards/legacy";
|
public static readonly string LEADERBOARDS_LEGACY_ENDPOINT = BASE_URL + "/berrydash/leaderboards/legacy";
|
||||||
public static readonly string LEADERBOARDS_TOTAL_ENDPOINT = BASE_URL + "/berrydash/leaderboards/total";
|
public static readonly string LEADERBOARDS_TOTAL_ENDPOINT = BASE_URL + "/berrydash/leaderboards/total";
|
||||||
|
public static readonly string PROFILE_ENDPOINT = BASE_URL + "/berrydash/profile";
|
||||||
|
public static readonly string PROFILE_POSTS_ENDPOINT = BASE_URL + "/berrydash/profile/posts";
|
||||||
}
|
}
|
||||||
@@ -122,9 +122,8 @@ public class ProfileMenu : MonoBehaviour
|
|||||||
|
|
||||||
public async Task Init(BigInteger playerID)
|
public async Task Init(BigInteger playerID)
|
||||||
{
|
{
|
||||||
WWWForm dataForm = new();
|
if (BazookaManager.Instance.GetAccountID() == playerID) { await Init(); return; }
|
||||||
dataForm.AddField("uesrId", playerID.ToString());
|
using UnityWebRequest request = UnityWebRequest.Get(Endpoints.PROFILE_ENDPOINT + "?userId=" + playerID.ToString());
|
||||||
using UnityWebRequest request = UnityWebRequest.Post(SensitiveInfo.SERVER_DATABASE_PREFIX + "berrydash/getAccountProfile.php", dataForm);
|
|
||||||
request.SetRequestHeader("Requester", "BerryDashClient");
|
request.SetRequestHeader("Requester", "BerryDashClient");
|
||||||
request.SetRequestHeader("ClientVersion", Application.version);
|
request.SetRequestHeader("ClientVersion", Application.version);
|
||||||
request.SetRequestHeader("ClientPlatform", Application.platform.ToString());
|
request.SetRequestHeader("ClientPlatform", Application.platform.ToString());
|
||||||
@@ -134,43 +133,32 @@ public class ProfileMenu : MonoBehaviour
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
string response = request.downloadHandler.text;
|
string response = request.downloadHandler.text;
|
||||||
|
try
|
||||||
|
{
|
||||||
var jsonResponse = JObject.Parse(response);
|
var jsonResponse = JObject.Parse(response);
|
||||||
if ((bool)jsonResponse["success"])
|
if ((bool)jsonResponse["success"])
|
||||||
{
|
{
|
||||||
var totalNormalBerries = (string)jsonResponse["totalNormalBerries"];
|
var iconColorArray = JArray.Parse(jsonResponse["data"]["iconColor"].Type == JTokenType.Null ? "[255,255,255]" : jsonResponse["data"]["iconColor"].ToString());
|
||||||
var totalPoisonBerries = (string)jsonResponse["totalPoisonBerries"];
|
var overlayColorArray = JArray.Parse(jsonResponse["data"]["overlayColor"].Type == JTokenType.Null ? "[255,255,255]" : jsonResponse["data"]["overlayColor"].ToString());
|
||||||
var totalSlowBerries = (string)jsonResponse["totalSlowBerries"];
|
var iconColor = new Color((int)iconColorArray[0] / 255f, (int)iconColorArray[1] / 255f, (int)iconColorArray[2] / 255f);
|
||||||
var totalUltraBerries = (string)jsonResponse["totalUltraBerries"];
|
var overlayColor = new Color((int)overlayColorArray[0] / 255f, (int)overlayColorArray[1] / 255f, (int)overlayColorArray[2] / 255f);
|
||||||
var totalSpeedyBerries = (string)jsonResponse["totalSpeedyBerries"];
|
|
||||||
var totalCoinBerries = (string)jsonResponse["totalCoinBerries"];
|
|
||||||
var totalRandomBerries = (string)jsonResponse["totalRandomBerries"];
|
|
||||||
var totalAntiBerries = (string)jsonResponse["totalAntiBerries"];
|
|
||||||
var coins = (string)jsonResponse["coins"];
|
|
||||||
var name = (string)jsonResponse["name"];
|
|
||||||
var icon = (int)jsonResponse["icon"];
|
|
||||||
var overlay = (int)jsonResponse["overlay"];
|
|
||||||
var customIcon = (string)jsonResponse["customIcon"];
|
|
||||||
var playerIconColorArray = JArray.Parse(jsonResponse["playerIconColor"].ToString());
|
|
||||||
var playerIconColor = new Color((int)playerIconColorArray[0] / 255f, (int)playerIconColorArray[1] / 255f, (int)playerIconColorArray[2] / 255f);
|
|
||||||
var playerOverlayColorArray = JArray.Parse(jsonResponse["playerOverlayColor"].ToString());
|
|
||||||
var playerOverlayColor = new Color((int)playerOverlayColorArray[0] / 255f, (int)playerOverlayColorArray[1] / 255f, (int)playerOverlayColorArray[2] / 255f);
|
|
||||||
await Init(
|
await Init(
|
||||||
totalNormalBerries,
|
(string)jsonResponse["data"]["stats"]["totalNormalBerries"],
|
||||||
totalPoisonBerries,
|
(string)jsonResponse["data"]["stats"]["totalPoisonBerries"],
|
||||||
totalSlowBerries,
|
(string)jsonResponse["data"]["stats"]["totalSlowBerries"],
|
||||||
totalUltraBerries,
|
(string)jsonResponse["data"]["stats"]["totalUltraBerries"],
|
||||||
totalSpeedyBerries,
|
(string)jsonResponse["data"]["stats"]["totalSpeedyBerries"],
|
||||||
totalCoinBerries,
|
(string)jsonResponse["data"]["stats"]["totalCoinBerries"],
|
||||||
totalRandomBerries,
|
(string)jsonResponse["data"]["stats"]["totalRandomBerries"],
|
||||||
totalAntiBerries,
|
(string)jsonResponse["data"]["stats"]["totalAntiBerries"],
|
||||||
coins,
|
(string)jsonResponse["data"]["stats"]["coins"],
|
||||||
name,
|
(string)jsonResponse["data"]["username"],
|
||||||
playerID,
|
playerID,
|
||||||
icon,
|
int.Parse(jsonResponse["data"]["icon"].Type == JTokenType.Null ? "1" : jsonResponse["data"]["icon"].ToString()),
|
||||||
overlay,
|
int.Parse(jsonResponse["data"]["overlay"].Type == JTokenType.Null ? "0" : jsonResponse["data"]["overlay"].ToString()),
|
||||||
customIcon,
|
(string)jsonResponse["data"]["customIcon"],
|
||||||
playerIconColor,
|
iconColor,
|
||||||
playerOverlayColor
|
overlayColor
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -178,6 +166,48 @@ public class ProfileMenu : MonoBehaviour
|
|||||||
Destroy(gameObject);
|
Destroy(gameObject);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
|
||||||
|
Destroy(gameObject);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task Init()
|
||||||
|
{
|
||||||
|
var customIconData = BazookaManager.Instance.GetCustomBirdIconData();
|
||||||
|
string customIcon = null;
|
||||||
|
if (customIconData.Selected != null)
|
||||||
|
{
|
||||||
|
foreach (var icon in customIconData.Data)
|
||||||
|
{
|
||||||
|
if (icon.UUID == customIconData.Selected)
|
||||||
|
{
|
||||||
|
customIcon = icon.Data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var iconColor = BazookaManager.Instance.GetColorSettingIcon();
|
||||||
|
var overlayColor = BazookaManager.Instance.GetColorSettingOverlay();
|
||||||
|
await Init(
|
||||||
|
BazookaManager.Instance.GetGameStoreTotalNormalBerries().ToString(),
|
||||||
|
BazookaManager.Instance.GetGameStoreTotalPoisonBerries().ToString(),
|
||||||
|
BazookaManager.Instance.GetGameStoreTotalSlowBerries().ToString(),
|
||||||
|
BazookaManager.Instance.GetGameStoreTotalUltraBerries().ToString(),
|
||||||
|
BazookaManager.Instance.GetGameStoreTotalSpeedyBerries().ToString(),
|
||||||
|
BazookaManager.Instance.GetGameStoreTotalCoinBerries().ToString(),
|
||||||
|
BazookaManager.Instance.GetGameStoreTotalRandomBerries().ToString(),
|
||||||
|
BazookaManager.Instance.GetGameStoreTotalAntiBerries().ToString(),
|
||||||
|
customIconData.Balance.ToString(),
|
||||||
|
BazookaManager.Instance.GetAccountName().ToString(),
|
||||||
|
BazookaManager.Instance.GetAccountID() ?? 0,
|
||||||
|
BazookaManager.Instance.GetBirdIcon(),
|
||||||
|
BazookaManager.Instance.GetBirdOverlay(),
|
||||||
|
customIcon,
|
||||||
|
new Color((int)iconColor[0] / 255f, (int)iconColor[1] / 255f, (int)iconColor[2] / 255f),
|
||||||
|
new Color((int)overlayColor[0] / 255f, (int)overlayColor[1] / 255f, (int)overlayColor[2] / 255f)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
async Task RefreshPosts(BigInteger playerID, string playerName)
|
async Task RefreshPosts(BigInteger playerID, string playerName)
|
||||||
{
|
{
|
||||||
@@ -191,15 +221,15 @@ public class ProfileMenu : MonoBehaviour
|
|||||||
Destroy(post.gameObject);
|
Destroy(post.gameObject);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
WWWForm dataForm = new();
|
using UnityWebRequest request = UnityWebRequest.Get(Endpoints.PROFILE_POSTS_ENDPOINT + "?userId=" + playerID.ToString());
|
||||||
dataForm.AddField("targetId", playerID.ToString());
|
|
||||||
using UnityWebRequest request = UnityWebRequest.Post(SensitiveInfo.SERVER_DATABASE_PREFIX + "berrydash/getAccountProfileMessages.php", dataForm);
|
|
||||||
request.SetRequestHeader("Requester", "BerryDashClient");
|
request.SetRequestHeader("Requester", "BerryDashClient");
|
||||||
request.SetRequestHeader("ClientVersion", Application.version);
|
request.SetRequestHeader("ClientVersion", Application.version);
|
||||||
request.SetRequestHeader("ClientPlatform", Application.platform.ToString());
|
request.SetRequestHeader("ClientPlatform", Application.platform.ToString());
|
||||||
await request.SendWebRequest();
|
await request.SendWebRequest();
|
||||||
if (request.result != UnityWebRequest.Result.Success)
|
if (request.result != UnityWebRequest.Result.Success)
|
||||||
{
|
{
|
||||||
|
exitButton.interactable = true;
|
||||||
|
refreshButton.interactable = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
string response = request.downloadHandler.text;
|
string response = request.downloadHandler.text;
|
||||||
@@ -222,7 +252,7 @@ public class ProfileMenu : MonoBehaviour
|
|||||||
entryLikesCount.text = Tools.FormatWithCommas(post.Likes);
|
entryLikesCount.text = Tools.FormatWithCommas(post.Likes);
|
||||||
entryLikesButton.onClick.AddListener(() =>
|
entryLikesButton.onClick.AddListener(() =>
|
||||||
{
|
{
|
||||||
if (canVote && BazookaManager.Instance.GetAccountID() != null && BazookaManager.Instance.GetAccountID() != post.UserID)
|
if (canVote && BazookaManager.Instance.GetAccountID() != null && BazookaManager.Instance.GetAccountID() != playerID)
|
||||||
{
|
{
|
||||||
var likedPosts = BazookaManager.Instance
|
var likedPosts = BazookaManager.Instance
|
||||||
.GetLikedPosts()
|
.GetLikedPosts()
|
||||||
@@ -231,9 +261,9 @@ public class ProfileMenu : MonoBehaviour
|
|||||||
if (!likedPosts.Any(x => x.ToString() == post.ID.ToString())) VotePost(post.ID, entryLikesCount, entryLikesTexture);
|
if (!likedPosts.Any(x => x.ToString() == post.ID.ToString())) VotePost(post.ID, entryLikesCount, entryLikesTexture);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
entryMessage.text = Encoding.UTF8.GetString(Convert.FromBase64String(post.Content));
|
entryMessage.text = post.Content;
|
||||||
entryTimestamp.text = post.Timestamp.ToString();
|
entryTimestamp.text = post.Timestamp.ToString();
|
||||||
if (BazookaManager.Instance.GetAccountID() == post.UserID)
|
if (BazookaManager.Instance.GetAccountID() == playerID)
|
||||||
{
|
{
|
||||||
entryDeleteButton.gameObject.SetActive(true);
|
entryDeleteButton.gameObject.SetActive(true);
|
||||||
entryDeleteButton.onClick.AddListener(async () => await DeletePost(entry, post.ID));
|
entryDeleteButton.onClick.AddListener(async () => await DeletePost(entry, post.ID));
|
||||||
@@ -278,9 +308,8 @@ public class ProfileMenu : MonoBehaviour
|
|||||||
WWWForm dataForm = new();
|
WWWForm dataForm = new();
|
||||||
dataForm.AddField("targetId", postId.ToString());
|
dataForm.AddField("targetId", postId.ToString());
|
||||||
dataForm.AddField("liked", liked ? "1" : "0");
|
dataForm.AddField("liked", liked ? "1" : "0");
|
||||||
dataForm.AddField("username", BazookaManager.Instance.GetAccountName());
|
using UnityWebRequest request = UnityWebRequest.Put(Endpoints.PROFILE_POSTS_ENDPOINT, dataForm.data);
|
||||||
dataForm.AddField("token", BazookaManager.Instance.GetAccountSession());
|
request.SetRequestHeader("Authorization", BazookaManager.Instance.GetAccountSession());
|
||||||
using UnityWebRequest request = UnityWebRequest.Post(SensitiveInfo.SERVER_DATABASE_PREFIX + "berrydash/voteAccountProfileMessage.php", dataForm);
|
|
||||||
request.SetRequestHeader("Requester", "BerryDashClient");
|
request.SetRequestHeader("Requester", "BerryDashClient");
|
||||||
request.SetRequestHeader("ClientVersion", Application.version);
|
request.SetRequestHeader("ClientVersion", Application.version);
|
||||||
request.SetRequestHeader("ClientPlatform", Application.platform.ToString());
|
request.SetRequestHeader("ClientPlatform", Application.platform.ToString());
|
||||||
@@ -313,7 +342,7 @@ public class ProfileMenu : MonoBehaviour
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch
|
||||||
{
|
{
|
||||||
Debug.LogError("Failed to proccess vote");
|
Debug.LogError("Failed to proccess vote");
|
||||||
}
|
}
|
||||||
@@ -339,61 +368,31 @@ public class ProfileMenu : MonoBehaviour
|
|||||||
{
|
{
|
||||||
WWWForm dataForm = new();
|
WWWForm dataForm = new();
|
||||||
dataForm.AddField("content", message);
|
dataForm.AddField("content", message);
|
||||||
dataForm.AddField("username", BazookaManager.Instance.GetAccountName());
|
using UnityWebRequest request = UnityWebRequest.Post(Endpoints.PROFILE_POSTS_ENDPOINT, dataForm);
|
||||||
dataForm.AddField("token", BazookaManager.Instance.GetAccountSession());
|
request.SetRequestHeader("Authorization", BazookaManager.Instance.GetAccountSession());
|
||||||
using UnityWebRequest request = UnityWebRequest.Post(SensitiveInfo.SERVER_DATABASE_PREFIX + "berrydash/uploadAccountProfileMessage.php", dataForm);
|
|
||||||
request.SetRequestHeader("Requester", "BerryDashClient");
|
request.SetRequestHeader("Requester", "BerryDashClient");
|
||||||
request.SetRequestHeader("ClientVersion", Application.version);
|
request.SetRequestHeader("ClientVersion", Application.version);
|
||||||
request.SetRequestHeader("ClientPlatform", Application.platform.ToString());
|
request.SetRequestHeader("ClientPlatform", Application.platform.ToString());
|
||||||
await request.SendWebRequest();
|
await request.SendWebRequest();
|
||||||
if (request.result != UnityWebRequest.Result.Success)
|
if (request.result == UnityWebRequest.Result.Success && request.responseCode == 200)
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
string response = request.downloadHandler.text;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var jsonResponse = JObject.Parse(response);
|
|
||||||
if ((bool)jsonResponse["success"])
|
|
||||||
{
|
{
|
||||||
await RefreshPosts(BazookaManager.Instance.GetAccountID() ?? 0, BazookaManager.Instance.GetAccountName());
|
await RefreshPosts(BazookaManager.Instance.GetAccountID() ?? 0, BazookaManager.Instance.GetAccountName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception)
|
|
||||||
{
|
|
||||||
Debug.LogError("Failed to upload post");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async Task DeletePost(GameObject entryObject, BigInteger targetId)
|
async Task DeletePost(GameObject entryObject, BigInteger targetId)
|
||||||
{
|
{
|
||||||
WWWForm dataForm = new();
|
using UnityWebRequest request = UnityWebRequest.Delete(Endpoints.PROFILE_POSTS_ENDPOINT + "?id=" + targetId.ToString());
|
||||||
dataForm.AddField("targetId", targetId.ToString());
|
request.SetRequestHeader("Authorization", BazookaManager.Instance.GetAccountSession());
|
||||||
dataForm.AddField("username", BazookaManager.Instance.GetAccountName());
|
|
||||||
dataForm.AddField("token", BazookaManager.Instance.GetAccountSession());
|
|
||||||
using UnityWebRequest request = UnityWebRequest.Post(SensitiveInfo.SERVER_DATABASE_PREFIX + "berrydash/deleteAccountProfileMessage.php", dataForm);
|
|
||||||
request.SetRequestHeader("Requester", "BerryDashClient");
|
request.SetRequestHeader("Requester", "BerryDashClient");
|
||||||
request.SetRequestHeader("ClientVersion", Application.version);
|
request.SetRequestHeader("ClientVersion", Application.version);
|
||||||
request.SetRequestHeader("ClientPlatform", Application.platform.ToString());
|
request.SetRequestHeader("ClientPlatform", Application.platform.ToString());
|
||||||
await request.SendWebRequest();
|
await request.SendWebRequest();
|
||||||
if (request.result != UnityWebRequest.Result.Success)
|
if (request.result == UnityWebRequest.Result.Success && request.responseCode == 200)
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
string response = request.downloadHandler.text;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var jsonResponse = JObject.Parse(response);
|
|
||||||
if ((bool)jsonResponse["success"])
|
|
||||||
{
|
{
|
||||||
Destroy(entryObject);
|
Destroy(entryObject);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception)
|
|
||||||
{
|
|
||||||
Debug.LogError("Failed to upload post");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Update()
|
void Update()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -9,10 +9,6 @@ public class ProfileMessageResponse
|
|||||||
[JsonProperty("id")]
|
[JsonProperty("id")]
|
||||||
public BigInteger ID { get; set; }
|
public BigInteger ID { get; set; }
|
||||||
|
|
||||||
[Preserve]
|
|
||||||
[JsonProperty("userId")]
|
|
||||||
public BigInteger UserID { get; set; }
|
|
||||||
|
|
||||||
[Preserve]
|
[Preserve]
|
||||||
[JsonProperty("content")]
|
[JsonProperty("content")]
|
||||||
public string Content { get; set; }
|
public string Content { get; set; }
|
||||||
|
|||||||
Reference in New Issue
Block a user