// ========================================================================================================================= // === debug =============================================================================================================== #if UNITY_EDITOR void Debug_GenerateRandomFriends(bool inActive) { if (inActive == true) { m_Friends.Clear(); for (int i = 0; i < 10; i++) { FriendInfo friend = new FriendInfo(); friend.PrimaryKey = MFDebugUtils.GetRandomString(Random.Range(5, 12)); //friend.m_Level = Random.Range(1,20); //friend.m_Missions = Random.Range(0,200); friend.LastOnlineDate = 0; //MiscUtils.RandomValue( new string[] {"unknown", "yesterday", "tomorrow"}); m_Friends.Add(friend); } } else { m_PendingFriends.Clear(); for (int i = 0; i < 10; i++) { PendingFriendInfo friend = new PendingFriendInfo(); friend.PrimaryKey = MFDebugUtils.GetRandomString(Random.Range(5, 12)); friend.AddedDate = GuiBaseUtils.DateToEpoch(CloudDateTime.UtcNow); if (Random.Range(0, 2) == 0) { // create dummy message, for testing gui behavior... friend.CloudCommand = MFDebugUtils.GetRandomString(Random.Range(512, 512)); } m_PendingFriends.Add(friend); } } }
//.......................................................................................................................... public void ProcessMessage(CloudMailbox.BaseMessage inMessage) { // add into pending friends.. CloudMailbox.FriendRequest req = inMessage as CloudMailbox.FriendRequest; if (req != null) { FriendInfo fInfo = m_Friends.Find(f => f.PrimaryKey == inMessage.m_Sender); if (fInfo != null) { //Debug.Log("User with name " + inMessage.m_Sender + " is already your friend"); return; } List <PendingFriendInfo> pfInfo = m_PendingFriends.FindAll(f => f.PrimaryKey == inMessage.m_Sender); if (pfInfo != null && pfInfo.Count > 0) { foreach (PendingFriendInfo p in pfInfo) { if (p != null && p.IsItRequest == true) { //Debug.Log("Request from this person is already in pending list"); return; } } } PendingFriendInfo friend = new PendingFriendInfo(); friend.PrimaryKey = req.m_Sender; friend.Nickname = req.m_NickName; friend.Username_New = req.m_Username; friend.AddedDate = GuiBaseUtils.DateToEpoch(inMessage.m_SendTime); friend.Message = inMessage.m_Message; friend.CloudCommand = req.m_ConfirmCommand; m_PendingFriends.Add(friend); OnPendingFriendListChanged(); Save(); return; } CloudMailbox.FriendRequestReject reject = inMessage as CloudMailbox.FriendRequestReject; if (reject != null) { // remove this friend from pending list if it is still there. List <PendingFriendInfo> pfInfo = m_PendingFriends.FindAll(friend => friend.PrimaryKey == inMessage.m_Sender); if (pfInfo != null && pfInfo.Count > 0) { foreach (PendingFriendInfo p in pfInfo) { m_PendingFriends.Remove(p); } } OnPendingFriendListChanged(); Save(); return; } Debug.LogError("Unknown message " + inMessage + " " + inMessage.msgType); }
//.......................................................................................................................... public void RejectFriendRequest(string inFriendName) { //Debug.Log("RejectFriendRequest " + inFriendName); // check preconditions... if (CloudUser.instance.isUserAuthenticated == false) { Debug.LogError("user is not authenticated, can't Accept Friend Request"); return; } PendingFriendInfo fInfo = m_PendingFriends.Find(f => f.PrimaryKey == inFriendName); if (fInfo == null || fInfo.IsItRequest == false) { Debug.LogError("Can't reject friend which is not in pending list"); return; } // create message object... CloudMailbox.FriendRequestReject msg = new CloudMailbox.FriendRequestReject(); msg.m_TargetSystem = "Game.FriendList"; msg.m_Mailbox = CloudMailbox.E_Mailbox.Global; msg.m_Sender = CloudUser.instance.primaryKey; msg.m_NickName = CloudUser.instance.nickName; msg.m_Message = "FriendShip rejected"; // this will not be shown... GameCloudManager.mailbox.SendMessage(inFriendName, msg); m_PendingFriends.Remove(fInfo); OnPendingFriendListChanged(); Save(); }
//.......................................................................................................................... public bool AddNewFriend(string inPrimaryKey, string inUsername, string inNickName, string inMessage) { // check preconditions... if (CloudUser.instance.isUserAuthenticated == false) { Debug.LogError("user is not authenticated, can't fetch friends list"); return(false); } FriendInfo fInfo = m_Friends.Find(f => f.PrimaryKey == inPrimaryKey); if (fInfo != null) { //Debug.Log("User with name " + inFriendName + " is already your friend"); return(false); } PendingFriendInfo pfInfo = m_PendingFriends.Find(f => f.PrimaryKey == inPrimaryKey); if (pfInfo != null) { //Debug.Log("User with name " + inFriendName + " is already in pending friend list"); return(false); } if (string.IsNullOrEmpty(inMessage) == true) { inMessage = string.Format(TextDatabase.instance[02040236], CloudUser.instance.nickName); } // create message object... CloudMailbox.FriendRequest msg = new CloudMailbox.FriendRequest(); msg.m_TargetSystem = "Game.FriendList"; msg.m_Mailbox = CloudMailbox.E_Mailbox.Global; msg.m_Sender = CloudUser.instance.primaryKey; msg.m_Username = CloudUser.instance.userName_TODO; msg.m_NickName = CloudUser.instance.nickName; msg.m_Message = inMessage; // this will not be shown... //GameCloudManager.mailbox.SendMessage(m_FriendName, msg); GameCloudManager.mailbox.SendMessage(inPrimaryKey, msg); // add into pending friends... PendingFriendInfo friend = new PendingFriendInfo(); friend.PrimaryKey = inPrimaryKey; friend.Username_New = inUsername; friend.Nickname = inNickName; friend.AddedDate = GuiBaseUtils.DateToEpoch(CloudDateTime.UtcNow); m_PendingFriends.Add(friend); OnPendingFriendListChanged(); Save(); return(true); }
//.......................................................................................................................... public void RemovePendingFriendRequest(string inFriendName) { PendingFriendInfo fInfo = m_PendingFriends.Find(f => f.PrimaryKey == inFriendName); if (fInfo == null || fInfo.IsItRequest == true) { Debug.LogError("Can't remove friend which is not in pending list"); return; } m_PendingFriends.Remove(fInfo); OnPendingFriendListChanged(); Save(); }
//.......................................................................................................................... public void AcceptFriendRequest(string inFriendName) { //Debug.Log("AcceptFriendRequest " + inFriendName); // check preconditions... if (CloudUser.instance.isUserAuthenticated == false) { Debug.LogError("user is not authenticated, can't Accept Friend Request"); return; } PendingFriendInfo fInfo = m_PendingFriends.Find(f => (f.PrimaryKey == inFriendName && f.IsItRequest == true)); if (fInfo == null) { Debug.LogError("Can't accept friend which is not in pending list"); return; } GameCloudManager.AddAction(new SendAcceptFriendCommand(CloudUser.instance.authenticatedUserID, inFriendName, fInfo.CloudCommand)); m_PendingFriends.Remove(fInfo); OnPendingFriendListChanged(); Save(); FriendInfo friend = new FriendInfo() { PrimaryKey = fInfo.PrimaryKey, Username = fInfo.Username, Nickname = fInfo.Nickname, OnlineStatus = E_OnlineStatus.Offline }; m_Friends.Add(friend); // force redownload friend list... RetriveFriendListFromCloud(true); }