Update chatroom script for server rewrite
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
@@ -56,7 +59,7 @@ public class ChatroomMenu : MonoBehaviour
|
||||
|
||||
EncryptedWWWForm dataForm = new();
|
||||
dataForm.AddField("content", text);
|
||||
dataForm.AddField("gameSession", BazookaManager.Instance.GetAccountSession());
|
||||
dataForm.AddField("token", BazookaManager.Instance.GetAccountSession());
|
||||
using UnityWebRequest request = UnityWebRequest.Post(SensitiveInfo.SERVER_DATABASE_PREFIX + "sendChatroomMessage.php", dataForm.GetWWWForm());
|
||||
request.SetRequestHeader("Requester", "BerryDashClient");
|
||||
request.SetRequestHeader("ClientVersion", Application.version);
|
||||
@@ -67,28 +70,39 @@ public class ChatroomMenu : MonoBehaviour
|
||||
return;
|
||||
}
|
||||
string response = SensitiveInfo.Decrypt(request.downloadHandler.text, SensitiveInfo.SERVER_RECEIVE_TRANSFER_KEY);
|
||||
switch (response)
|
||||
if (response == "-999")
|
||||
{
|
||||
case "-999":
|
||||
ShowStatus("Server error while fetching data");
|
||||
break;
|
||||
case "-998":
|
||||
ShowStatus("Client version too outdated to access servers");
|
||||
break;
|
||||
case "-997":
|
||||
ShowStatus("Encryption/decryption issues");
|
||||
break;
|
||||
case "-996":
|
||||
ShowStatus("Can't send requests on self-built instance");
|
||||
break;
|
||||
case "-1":
|
||||
ShowStatus("Authentication error");
|
||||
break;
|
||||
case "1":
|
||||
ShowStatus("Server error while fetching data");
|
||||
return;
|
||||
}
|
||||
else if (response == "-998")
|
||||
{
|
||||
ShowStatus("Client version too outdated to access servers");
|
||||
return;
|
||||
}
|
||||
else if (response == "-997")
|
||||
{
|
||||
ShowStatus("Encryption/decryption issues");
|
||||
return;
|
||||
}
|
||||
else if (response == "-996")
|
||||
{
|
||||
ShowStatus("Can't send requests on self-built instance");
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
var jsonResponse = JObject.Parse(response);
|
||||
if ((bool)jsonResponse["success"])
|
||||
{
|
||||
StopCoroutine(refreshLoopRoutine);
|
||||
refreshLoopRoutine = StartCoroutine(Loop());
|
||||
content.transform.localPosition = new Vector2(0f, 0f);
|
||||
break;
|
||||
content.transform.localPosition = new UnityEngine.Vector2(0f, 0f);
|
||||
}
|
||||
else
|
||||
{
|
||||
ShowStatus((string)jsonResponse["message"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,83 +173,71 @@ public class ChatroomMenu : MonoBehaviour
|
||||
ShowStatus("Can't send requests on self-built instance");
|
||||
break;
|
||||
default:
|
||||
var split = response.Split(':');
|
||||
if (split[0] == "1")
|
||||
shouldClear = false;
|
||||
var jsonResponse = JArray.Parse(response);
|
||||
foreach (JObject entry in jsonResponse.Cast<JObject>())
|
||||
{
|
||||
shouldClear = false;
|
||||
foreach (var row in split[1].Split("|"))
|
||||
var username = (string)entry["username"];
|
||||
var chatContent = Encoding.UTF8.GetString(Convert.FromBase64String((string)entry["content"]));
|
||||
var id = BigInteger.Parse((string)entry["id"]);
|
||||
var icon = (int)entry["icon"];
|
||||
var overlay = (int)entry["overlay"];
|
||||
var uid = BigInteger.Parse((string)entry["userid"]);
|
||||
var birdColor = (JArray)entry["birdColor"];
|
||||
var overlayColor = (JArray)entry["overlayColor"];
|
||||
|
||||
if (content.transform.Find("ChatroomRow_" + id + "_" + uid) != null)
|
||||
{
|
||||
var rowSplit = row.Split(';');
|
||||
var id = rowSplit[0];
|
||||
var username = Encoding.UTF8.GetString(Convert.FromBase64String(rowSplit[1]));
|
||||
var chatContent = Encoding.UTF8.GetString(Convert.FromBase64String(rowSplit[2]));
|
||||
var icon = rowSplit[3];
|
||||
var overlay = rowSplit[4];
|
||||
var uid = rowSplit[5];
|
||||
var birdR = rowSplit[6];
|
||||
var birdG = rowSplit[7];
|
||||
var birdB = rowSplit[8];
|
||||
var overlayR = rowSplit[9];
|
||||
var overlayG = rowSplit[10];
|
||||
var overlayB = rowSplit[11];
|
||||
|
||||
if (content.transform.Find("ChatroomRow_" + id + "_" + uid) != null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (content.transform.childCount > 50)
|
||||
{
|
||||
var firstChild = content.transform.GetChild(0);
|
||||
Destroy(firstChild.gameObject);
|
||||
}
|
||||
|
||||
var rowInfo = Instantiate(sampleObject, content.transform);
|
||||
var usernameText = rowInfo.transform.GetChild(0).GetComponent<TMP_Text>();
|
||||
var playerIcon = usernameText.transform.GetChild(0).GetComponent<Image>();
|
||||
var playerOverlayIcon = playerIcon.transform.GetChild(0).GetComponent<Image>();
|
||||
var messageText = rowInfo.transform.GetChild(1).GetComponent<TMP_Text>();
|
||||
|
||||
usernameText.text = username;
|
||||
messageText.text = chatContent;
|
||||
playerIcon.sprite = Resources.Load<Sprite>("Icons/Icons/bird_" + icon);
|
||||
if (icon == "1")
|
||||
{
|
||||
playerIcon.sprite = Tools.GetIconForUser(int.Parse(uid));
|
||||
}
|
||||
playerOverlayIcon.sprite = Resources.Load<Sprite>("Icons/Overlays/overlay_" + overlay);
|
||||
if (overlay == "0")
|
||||
{
|
||||
playerOverlayIcon.gameObject.SetActive(false);
|
||||
}
|
||||
else if (overlay == "8")
|
||||
{
|
||||
playerOverlayIcon.transform.localPosition = new Vector2(-16.56f, 14.81f);
|
||||
}
|
||||
else if (overlay == "11")
|
||||
{
|
||||
playerOverlayIcon.transform.localPosition = new Vector2(-14.74451f, 20.39122f);
|
||||
}
|
||||
else if (overlay == "13")
|
||||
{
|
||||
playerOverlayIcon.transform.localPosition = new Vector2(-16.54019f, 14.70365f);
|
||||
}
|
||||
try
|
||||
{
|
||||
playerIcon.color = new Color32(byte.Parse(birdR), byte.Parse(birdG), byte.Parse(birdB), 255);
|
||||
playerOverlayIcon.color = new Color32(byte.Parse(overlayR), byte.Parse(overlayG), byte.Parse(overlayB), 255);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
playerIcon.color = Color.white;
|
||||
playerOverlayIcon.color = Color.white;
|
||||
}
|
||||
rowInfo.name = "ChatroomRow_" + id + "_" + uid;
|
||||
rowInfo.SetActive(true);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ShowStatus("Error fetching messages.");
|
||||
if (content.transform.childCount > 50)
|
||||
{
|
||||
var firstChild = content.transform.GetChild(0);
|
||||
Destroy(firstChild.gameObject);
|
||||
}
|
||||
|
||||
var rowInfo = Instantiate(sampleObject, content.transform);
|
||||
var usernameText = rowInfo.transform.GetChild(0).GetComponent<TMP_Text>();
|
||||
var playerIcon = usernameText.transform.GetChild(0).GetComponent<Image>();
|
||||
var playerOverlayIcon = playerIcon.transform.GetChild(0).GetComponent<Image>();
|
||||
var messageText = rowInfo.transform.GetChild(1).GetComponent<TMP_Text>();
|
||||
|
||||
usernameText.text = username;
|
||||
messageText.text = chatContent;
|
||||
playerIcon.sprite = Resources.Load<Sprite>("Icons/Icons/bird_" + icon);
|
||||
if (icon == 1)
|
||||
{
|
||||
playerIcon.sprite = Tools.GetIconForUser(uid);
|
||||
}
|
||||
playerOverlayIcon.sprite = Resources.Load<Sprite>("Icons/Overlays/overlay_" + overlay);
|
||||
if (overlay == 0)
|
||||
{
|
||||
playerOverlayIcon.gameObject.SetActive(false);
|
||||
}
|
||||
else if (overlay == 8)
|
||||
{
|
||||
playerOverlayIcon.transform.localPosition = new UnityEngine.Vector2(-16.56f, 14.81f);
|
||||
}
|
||||
else if (overlay == 11)
|
||||
{
|
||||
playerOverlayIcon.transform.localPosition = new UnityEngine.Vector2(-14.74451f, 20.39122f);
|
||||
}
|
||||
else if (overlay == 13)
|
||||
{
|
||||
playerOverlayIcon.transform.localPosition = new UnityEngine.Vector2(-16.54019f, 14.70365f);
|
||||
}
|
||||
try
|
||||
{
|
||||
playerIcon.color = new Color((int)birdColor[0] / 255f, (int)birdColor[1] / 255f, (int)birdColor[2] / 255f);
|
||||
playerOverlayIcon.color = new Color((int)overlayColor[0] / 255f, (int)overlayColor[1] / 255f, (int)overlayColor[2] / 255f);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
playerIcon.color = Color.white;
|
||||
playerOverlayIcon.color = Color.white;
|
||||
}
|
||||
rowInfo.name = "ChatroomRow_" + id + "_" + uid;
|
||||
rowInfo.SetActive(true);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user