Files
JJBB/Assets/Project/Script/GUI/Chat/LimitChatInfoCtr.cs
2024-08-23 15:49:34 +08:00

282 lines
9.2 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Collections;
using GCGame;
using GCGame.Table;
using Module.Log;
using UnityEngine;
using UnityEngine.Networking;
public class LimitChatInfoCtr : MonoBehaviour
{
private const string _staticKey = "\"code\"";
private const string _containertypeStr = "application/x-www-form-urlencoded";
// private const string _complaintUrl = "http://139.159.226.174/api/avoid/appeal"; //申诉(内网: gz.zyadmin.com 外网139.159.226.174)
//private const string _reportUrl = "http://139.159.226.174/api/avoid/report"; //举报
private static string _complaintUrl = null;
private static string _reportUrl = null;
public static LimitChatInfoCtr Instance;
private int _canComplainLevel;
public GameObject _forbiddenIcon;
private bool _isCountTime;
private string _randomStrAttr;
private int _remainTime;
private string _signAttr;
private string _timeAttr;
private float countTime;
public static string ComplainUrl
{
get
{
//if (_complaintUrl == null)
// _complaintUrl = TableManager.GetSystemParamByID(30, 0).StringValue;
//return _complaintUrl;
return ControllUrlManager.AvoidAppealUrl;
}
}
public static string ReportUrl
{
get
{
//if (_reportUrl == null)
// _reportUrl = TableManager.GetSystemParamByID(31, 0).StringValue;
//return _reportUrl;
return ControllUrlManager.AvoidReportUrl;
}
}
public void ShowForbiddenIcon(bool isShow)
{
if (isShow)
{
if (!_forbiddenIcon.activeInHierarchy)
_forbiddenIcon.SetActive(true);
}
else
{
if (_forbiddenIcon.activeInHierarchy)
_forbiddenIcon.SetActive(false);
}
}
public void OnForbiddenIconClick()
{
ReqComplaint();
}
private void Awake()
{
Instance = this;
}
private void OnDestroy()
{
Instance = null;
}
private void OnEnable()
{
if (gameObject.activeInHierarchy)
{
StopAllCoroutines();
StartCoroutine(CalculateRemainTime());
}
}
private IEnumerator CalculateRemainTime()
{
while (true)
{
yield return new WaitForSeconds(1f);
_remainTime = Utils.GetRemainTime(GameManager.gameManager.PlayerDataPool.ForbiddenTalkOverTime);
if (_remainTime > 0)
{
countTime += Time.deltaTime;
if (countTime >= 1.0f)
{
_remainTime--;
countTime -= 1.0f;
}
if (_remainTime > 0)
ShowForbiddenIcon(true);
else
ShowForbiddenIcon(false);
}
else
{
_remainTime = 0;
_isCountTime = false;
ShowForbiddenIcon(false);
}
}
}
//请求申诉
public void ReqComplaint()
{
var chatLimit = TableManager.GetChatLimitByID(0);
if (chatLimit != null)
_canComplainLevel = chatLimit.ComplainNeedLevel;
if (GameManager.gameManager.PlayerDataPool.MainPlayerBaseAttr.Level >= _canComplainLevel)
MessageBoxLogic.OpenOKCancelBoxWithBtnName(
StrDictionary.GetClientDictionaryString("#{79201}", GetForbiddenRemainTime()),
null, StrDictionary.GetClientDictionaryString("#{79202}"),
StrDictionary.GetClientDictionaryString("#{1074}"), delegate
{
//StartCoroutine(CreateComplaintHttpPost());
var cc_id = string.IsNullOrEmpty(GameManager.gameManager.PlayerDataPool.ChannelId)
? "-1"
: GameManager.gameManager.PlayerDataPool.ChannelId;
var _formatStr = "&serverId={0}&guid={1}&charname={2}&level={3}&vip_level={4}&cch_id={5}";
var paramData = Utils.GetHttpSingStr() + string.Format(_formatStr,
GameManager.gameManager.PlayerDataPool.WorldId,
GameManager.gameManager.PlayerDataPool.MainPlayerBaseAttr.Guid,
GameManager.gameManager.PlayerDataPool.MainPlayerBaseAttr.RoleName,
GameManager.gameManager.PlayerDataPool.MainPlayerBaseAttr.Level,
GameManager.gameManager.PlayerDataPool.VipCost,
cc_id);
StartCoroutine(CreateComplainHttpPost(ComplainUrl, paramData));
}, delegate { UIManager.CloseUI(UIInfo.MessageBox); });
else
MessageBoxLogic.OpenOKBox(StrDictionary.GetClientDictionaryString("#{79200}", _canComplainLevel), null,
delegate { UIManager.CloseUI(UIInfo.MessageBox); });
//StartCoroutine(CreateComplaintHttpPost());
}
private string GetForbiddenRemainTime()
{
var remainTime = Utils.GetRemainTime(GameManager.gameManager.PlayerDataPool.ForbiddenTalkOverTime);
if (remainTime >= 3600)
{
var remainHour = remainTime / 3600;
var remainMin = (remainTime - remainHour * 3600) / 60;
var remainSec = remainTime % 60;
return StrDictionary.GetClientDictionaryString("#{67129}", remainHour, remainMin, remainSec);
}
else
{
var remainMin = remainTime / 60;
var remainSec = remainTime % 60;
return StrDictionary.GetClientDictionaryString("#{67130}", remainMin, remainSec);
}
}
public void CloseReportPanel()
{
if (ChatReportPanelCtr.Instance && ChatReportPanelCtr.Instance.gameObject.activeInHierarchy)
UIManager.CloseUI(UIInfo.ChatReportPanel);
}
//发送请求到PHP
public IEnumerator CreateReportHttpPost(string url, string dataMsg)
{
var request = UnityWebRequest.Post(url, dataMsg);
yield return request.SendWebRequest();
//
if (request.isNetworkError)
{
LogModule.ErrorLog("PostMsg error:" + request.isNetworkError);
}
else
{
if (ParseJsonByKey(request.downloadHandler.text, _staticKey).Equals("1"))
{
MessageBoxLogic.OpenOKBox(StrDictionary.GetClientDictionaryString("#{68011}"));
CloseReportPanel();
}
}
}
public IEnumerator CreateComplainHttpPost(string url, string dataMsg)
{
var request = UnityWebRequest.Post(url, dataMsg);
yield return request.SendWebRequest();
//
if (request.isNetworkError)
{
LogModule.ErrorLog("PostMsg error:" + request.isNetworkError);
}
else
{
if (ParseJsonByKey(request.downloadHandler.text, _staticKey).Equals("1"))
{
MessageBoxLogic.OpenOKBox(StrDictionary.GetClientDictionaryString("#{68010}"), "",
() => { MessageHelpLogic.ShowHelpMessage(43); });
CloseReportPanel();
}
else if (ParseJsonByKey(request.downloadHandler.text, _staticKey).Equals("-4")) //一天只能申诉一次
{
GUIData.AddNotifyData("#{79204}");
}
}
}
//举报
public void ReqReport(int type, string content, ulong guid, ulong bGuid, int worldId, string bContent,
string bName) //需要举报的描述 举报类型
{
var cc_id = string.IsNullOrEmpty(GameManager.gameManager.PlayerDataPool.ChannelId)
? "-1"
: GameManager.gameManager.PlayerDataPool.ChannelId;
content = string.IsNullOrEmpty(content) ? "-1" : content;
bContent = string.IsNullOrEmpty(bContent) ? "-1" : bContent;
var _formatStr =
"&type={0}&content={1}&guid={2}&bguid={3}&serverId={4}&bContent={5}&cch_id={6}&charname={7}&report_name={8}&level={9}&vip_level={10}";
var paramData = Utils.GetHttpSingStr() + string.Format(_formatStr, type, content, guid, bGuid, worldId,
bContent,
cc_id,
GameManager.gameManager.PlayerDataPool.MainPlayerBaseAttr.RoleName,
bName,
GameManager.gameManager.PlayerDataPool.MainPlayerBaseAttr.Level,
GameManager.gameManager.PlayerDataPool.VipCost);
StartCoroutine(CreateReportHttpPost(ReportUrl, paramData));
}
private string ParseJsonByKey(string jsonText, string key)
{
if (jsonText == "" || jsonText == null) return null;
string val = null;
var _res = new ResultMsg("", "");
_res = JsonUtility.FromJson<ResultMsg>(jsonText);
try
{
val = _res.code;
}
catch
{
LogModule.ErrorLog(_res.msg);
}
return val;
}
private struct ResultMsg
{
public readonly string code;
public readonly string msg;
public ResultMsg(string _code, string _msg)
{
code = _code;
msg = _msg;
}
}
}