Пример #1
0
        public void HandleNotification(Notification notification)
        {
            if (notification.subType == (int)NotificationSubType.RequestFriend)
            {
                Hashtable data = notification.data;
                if (data != null)
                {
                    string fromGameRefID = data.GetValue <string>((int)SPC.SourceGameRefID, string.Empty);
                    string fromLogin     = data.GetValue <string>((int)SPC.SourceLogin, string.Empty);
                    string toGameRefID   = data.GetValue <string>((int)SPC.TargetGameRefID, string.Empty);
                    string toLogin       = data.GetValue <string>((int)SPC.TargetLogin, string.Empty);

                    if (CommonUtils.AllNonEmty(new string[] { fromGameRefID, fromLogin, toGameRefID, toLogin }))
                    {
                        var sourceFriend = GetFriendsObject(fromGameRefID, fromLogin);

                        if (sourceFriend == null)
                        {
                            return;
                        }

                        var targetFriend = GetFriendsObject(toGameRefID, toLogin);
                        if (targetFriend == null)
                        {
                            return;
                        }

                        var sourcePlayer = application.Players.GetExistingPlayer(fromGameRefID);
                        if (sourcePlayer == null)
                        {
                            return;
                        }

                        var targetPlayer = application.Players.GetExistingPlayer(toGameRefID);
                        if (targetPlayer == null)
                        {
                            return;
                        }



                        if (!sourceFriend.Data.IsFriend(targetFriend.Data))
                        {
                            sourceFriend.Data.AddFriend(toGameRefID, toLogin);
                            sourceFriend.Changed = true;

                            var sourceCharacter = sourcePlayer.Data.SelectedCharacter();

                            ChatMessage msg = new ChatMessage {
                                chatGroup           = (int)ChatGroup.whisper,
                                links               = new List <ChatLinkedObject>(),
                                message             = string.Format("{0} now friend with {1}", fromLogin, toLogin),
                                messageID           = Guid.NewGuid().ToString(),
                                sourceCharacterID   = sourcePlayer.Data.SelectedCharacterId,
                                sourceLogin         = "******",
                                targetCharacterID   = sourcePlayer.Data.SelectedCharacterId,
                                targetLogin         = fromLogin,
                                sourceCharacterName = (sourceCharacter != null) ? sourceCharacter.Name : string.Empty
                            };
                            application.Chat.SendMessage(msg);
                        }

                        if (!targetFriend.Data.IsFriend(sourceFriend.Data))
                        {
                            targetFriend.Data.AddFriend(fromGameRefID, fromLogin);
                            targetFriend.Changed = true;
                            var sourceCharacter = targetPlayer.Data.SelectedCharacter();

                            ChatMessage msg = new ChatMessage {
                                chatGroup           = (int)ChatGroup.whisper,
                                links               = new List <ChatLinkedObject>(),
                                message             = string.Format("{0} now friend with {1}", toLogin, fromLogin),
                                messageID           = Guid.NewGuid().ToString(),
                                sourceCharacterID   = targetPlayer.Data.SelectedCharacterId,
                                sourceLogin         = "******",
                                targetCharacterID   = targetPlayer.Data.SelectedCharacterId,
                                targetLogin         = toLogin,
                                sourceCharacterName = (sourceCharacter != null) ? sourceCharacter.Name : string.Empty
                            };
                            application.Chat.SendMessage(msg);
                        }

                        application.Clients.SendGenericEventToGameref(fromGameRefID, new Events.GenericEvent {
                            subCode = (int)SelectCharacterGenericEventSubCode.FriendsUpdate,
                            data    = GetFriendsInfo(fromGameRefID, fromLogin)
                        });
                        application.Clients.SendGenericEventToGameref(toGameRefID, new Events.GenericEvent {
                            subCode = (int)SelectCharacterGenericEventSubCode.FriendsUpdate,
                            data    = GetFriendsInfo(toGameRefID, toLogin)
                        });
                        //application.SendEventToClient
                    }
                }
            }
        }