using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Text; using System.Threading; using UnityEngine; namespace MoleMole { public class QAManager { private class MessageEntry { public int id; public string message; public string stackTrace; private static int _lastId; public MessageEntry(string msg, string st) { id = ++_lastId; message = msg; stackTrace = st; } public override int GetHashCode() { return message.GetHashCode() ^ stackTrace.GetHashCode(); } } private int _mainThreadID; private string _channelName = string.Empty; private List _sendToServerMessages = new List(); private HashSet _sentMessageHashes = new HashSet(); public QAManager() { _mainThreadID = Thread.CurrentThread.ManagedThreadId; ConfigChannel configChannel = ConfigUtil.LoadJSONConfig("DataPersistent/BuildChannel/ChannelConfig"); if (configChannel != null) { _channelName = configChannel.ChannelName; } SuperDebug.sendToServerAction = SendMessageToSever; } public void Destroy() { } [Conditional("NG_HSOD_DEBUG")] public void SetFPSContext(string context) { MonoFPSIndicator monoFPSIndicator = UnityEngine.Object.FindObjectOfType(); if ((bool)monoFPSIndicator) { MonoFPSIndicator component = monoFPSIndicator.GetComponent(); component.logContext = context; } } [Conditional("NG_HSOD_DEBUG")] public void LogFPS(string context, float fpsAvg, float fpsMin, float fpsMax) { } public bool IsSentMessage(string msg, string stackTrace) { MessageEntry messageEntry = new MessageEntry(msg, stackTrace); return _sentMessageHashes.Contains(messageEntry.GetHashCode()); } public void SendMessageToSever(string msg, string stackTrace) { MessageEntry messageEntry = new MessageEntry(msg, stackTrace); int hashCode = messageEntry.GetHashCode(); if (!_sentMessageHashes.Contains(hashCode)) { _sentMessageHashes.Add(hashCode); if (_mainThreadID == Thread.CurrentThread.ManagedThreadId && Singleton.Instance.applicationBehaviour != null) { Singleton.Instance.applicationBehaviour.StartCoroutine(SendMessageToSeverCoroutine(messageEntry)); } else { _sendToServerMessages.Add(messageEntry); } } } public IEnumerator SendMessageToSeverSync(string msg, string stackTrace) { MessageEntry entry = new MessageEntry(msg, stackTrace); int hash = entry.GetHashCode(); if (!_sentMessageHashes.Contains(hash)) { _sentMessageHashes.Add(hash); yield return SendMessageToSeverCoroutine(entry); } } public void UpdateSendMessageToSever() { if (_sendToServerMessages.Count > 0 && Singleton.Instance.applicationBehaviour != null) { List list = new List(_sendToServerMessages); _sendToServerMessages.Clear(); for (int i = 0; i < list.Count; i++) { Singleton.Instance.applicationBehaviour.StartCoroutine(SendMessageToSeverCoroutine(list[i])); } } } private IEnumerator SendMessageToSeverCoroutine(MessageEntry msg) { int uid = -1; if (Singleton.Instance != null && Singleton.Instance.playerData != null) { uid = Singleton.Instance.playerData.userId; } string vid = string.Empty; if (Singleton.Instance != null) { vid = Singleton.Instance.GetGameVersion(); } string asb = string.Empty; if (Singleton.Instance != null && Singleton.Instance.Loader != null) { asb = Singleton.Instance.Loader.assetBoundleSVNVersion; } StringBuilder url = new StringBuilder(); url.Append("http://139.196.152.26:10080/recorder?"); url.Append("&channelName=" + _channelName); url.Append("&uid=" + uid); url.Append("&vid=" + vid); url.Append("&asb=" + asb); url.Append("&time=" + WWW.EscapeURL(TimeUtil.Now.ToString())); url.Append("&operatingSystem=" + WWW.EscapeURL(SystemInfo.operatingSystem)); url.Append("&deviceModel=" + WWW.EscapeURL(SystemInfo.deviceModel)); url.Append("&graphicsDeviceName=" + WWW.EscapeURL(SystemInfo.graphicsDeviceName)); url.Append("&graphicsDeviceType=" + SystemInfo.graphicsDeviceType); url.Append("&graphicsDeviceVendor=" + WWW.EscapeURL(SystemInfo.graphicsDeviceVendor)); url.Append("&graphicsDeviceVersion=" + WWW.EscapeURL(SystemInfo.graphicsDeviceVersion)); url.Append("&graphicsMemorySize=" + SystemInfo.graphicsMemorySize); url.Append("&systemMemorySize=" + SystemInfo.systemMemorySize); url.Append("&processorCount=" + SystemInfo.processorCount); url.Append("&processorFrequency=" + SystemInfo.processorFrequency); url.Append("&processorType=" + WWW.EscapeURL(SystemInfo.processorType)); url.Append("&msgId=" + msg.id); url.Append("&msg=" + WWW.EscapeURL(msg.message)); url.Append("&st=" + WWW.EscapeURL(msg.stackTrace)); yield return new WWW(url.ToString()); } public void SendFileToServer(string url, string fileType, byte[] buf, Action successCallback, Action failCallback, float timeoutSecond = 5f, string prefix = null, bool needDispose = true) { string arg = Singleton.Instance.playerData.userId.ToString(); string gameVersion = Singleton.Instance.GetGameVersion(); string arg2 = TimeUtil.Now.ToString("yyyy-MM-dd_HH-mm-ss"); string text = string.Format("{0}-{1}-{2}.txt", arg, gameVersion, arg2); if (!string.IsNullOrEmpty(prefix)) { text = string.Format("{0}-{1}", prefix, text); } Dictionary dictionary = new Dictionary(); dictionary.Add("File-Type", fileType); dictionary.Add("File-Name", text); Dictionary headers = dictionary; Singleton.Instance.applicationBehaviour.StartCoroutine(Miscs.WWWRequestWithTimeOut(url, successCallback, failCallback, timeoutSecond, buf, headers, needDispose)); } } }