//.......................................................................................................................... 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 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 static string GetSender(this Message message) { if (message is FriendMessage) { FriendMessage friendMessage = (FriendMessage)message; if (string.IsNullOrEmpty(friendMessage.m_NickName) == false) { return(friendMessage.m_NickName); } var friend = GameCloudManager.friendList.friends.Find(obj => obj.PrimaryKey == message.m_Sender); if (friend != null) { return(friend.Nickname); } } else if (message is FriendRequest) { FriendRequest friendRequest = (FriendRequest)message; if (string.IsNullOrEmpty(friendRequest.m_NickName) == false) { return(friendRequest.m_NickName); } if (string.IsNullOrEmpty(friendRequest.m_Username) == false) { return(friendRequest.m_Username); } } else if (message is FriendRequestReject) { FriendRequestReject friendRequest = (FriendRequestReject)message; if (string.IsNullOrEmpty(friendRequest.m_NickName) == false) { return(friendRequest.m_NickName); } } return(message != null && string.IsNullOrEmpty(message.m_Sender) == false ? message.m_Sender : message.msgType); }