Esempio n. 1
0
 /// <summary>
 /// 初始化
 /// </summary>
 /// <param name="connectionGuid">服务器链接标识</param>
 /// <param name="eventName">事件名</param>
 /// <param name="offlineFileArgs">离线文件事件参数</param>
 internal OfflineFileEventArgs(Guid connectionGuid, string eventName, ApiOfflineFileEventArgs offlineFileArgs) :
     base(connectionGuid, eventName, offlineFileArgs.SelfID, offlineFileArgs.Time)
 {
     this.Sender          = new User(connectionGuid, offlineFileArgs.UserId);
     this.OfflineFileInfo = offlineFileArgs.Info;
 }
Esempio n. 2
0
        /// <summary>
        /// 通知事件处理和分发
        /// </summary>
        /// <param name="messageJson">消息</param>
        /// <param name="connection">连接GUID</param>
        private async void NoticeAdapter(JObject messageJson, Guid connection)
        {
            switch (GetNoticeType(messageJson))
            {
            //群文件上传
            case "group_upload":
                ApiFileUploadEventArgs fileUpload = messageJson.ToObject <ApiFileUploadEventArgs>();
                if (fileUpload == null)
                {
                    break;
                }
                ConsoleLog.Debug("Sora",
                                 $"Group notice[Upload file] file[{fileUpload.Upload.Name}] from group[{fileUpload.GroupId}({fileUpload.UserId})]");
                //执行回调函数
                if (OnFileUpload == null)
                {
                    break;
                }
                await OnFileUpload(typeof(EventInterface),
                                   new FileUploadEventArgs(connection, "group_upload", fileUpload));

                break;

            //群管理员变动
            case "group_admin":
                ApiAdminChangeEventArgs adminChange = messageJson.ToObject <ApiAdminChangeEventArgs>();
                if (adminChange == null)
                {
                    break;
                }
                ConsoleLog.Debug("Sora",
                                 $"Group amdin change[{adminChange.SubType}] from group[{adminChange.GroupId}] by[{adminChange.UserId}]");
                //执行回调函数
                if (OnGroupAdminChange == null)
                {
                    break;
                }
                await OnGroupAdminChange(typeof(EventInterface),
                                         new GroupAdminChangeEventArgs(connection, "group_upload", adminChange));

                break;

            //群成员变动
            case "group_decrease":
            case "group_increase":
                ApiGroupMemberChangeEventArgs groupMemberChange = messageJson.ToObject <ApiGroupMemberChangeEventArgs>();
                if (groupMemberChange == null)
                {
                    break;
                }
                ConsoleLog.Debug("Sora",
                                 $"{groupMemberChange.NoticeType} type[{groupMemberChange.SubType}] member {groupMemberChange.GroupId}[{groupMemberChange.UserId}]");
                //执行回调函数
                if (OnGroupMemberChange == null)
                {
                    break;
                }
                await OnGroupMemberChange(typeof(EventInterface),
                                          new GroupMemberChangeEventArgs(connection, "group_member_change", groupMemberChange));

                break;

            //群禁言
            case "group_ban":
                ApiGroupMuteEventArgs groupMute = messageJson.ToObject <ApiGroupMuteEventArgs>();
                if (groupMute == null)
                {
                    break;
                }
                ConsoleLog.Debug("Sora",
                                 $"Group[{groupMute.GroupId}] {groupMute.ActionType} member[{groupMute.UserId}]{groupMute.Duration}");
                //执行回调函数
                if (OnGroupMemberMute == null)
                {
                    break;
                }
                await OnGroupMemberMute(typeof(EventInterface),
                                        new GroupMuteEventArgs(connection, "group_ban", groupMute));

                break;

            //好友添加
            case "friend_add":
                ApiFriendAddEventArgs friendAdd = messageJson.ToObject <ApiFriendAddEventArgs>();
                if (friendAdd == null)
                {
                    break;
                }
                ConsoleLog.Debug("Sora", $"Friend add user[{friendAdd.UserId}]");
                //执行回调函数
                if (OnFriendAdd == null)
                {
                    break;
                }
                await OnFriendAdd(typeof(EventInterface),
                                  new FriendAddEventArgs(connection, "friend_add", friendAdd));

                break;

            //群消息撤回
            case "group_recall":
                ApiGroupRecallEventArgs groupRecall = messageJson.ToObject <ApiGroupRecallEventArgs>();
                if (groupRecall == null)
                {
                    break;
                }
                ConsoleLog.Debug("Sora",
                                 $"Group[{groupRecall.GroupId}] recall by [{groupRecall.OperatorId}],msg id={groupRecall.MessageId} sender={groupRecall.UserId}");
                //执行回调函数
                if (OnGroupRecall == null)
                {
                    break;
                }
                await OnGroupRecall(typeof(EventInterface),
                                    new GroupRecallEventArgs(connection, "group_recall", groupRecall));

                break;

            //好友消息撤回
            case "friend_recall":
                ApiFriendRecallEventArgs friendRecall = messageJson.ToObject <ApiFriendRecallEventArgs>();
                if (friendRecall == null)
                {
                    break;
                }
                ConsoleLog.Debug("Sora", $"Friend[{friendRecall.UserId}] recall msg id={friendRecall.MessageId}");
                //执行回调函数
                if (OnFriendRecall == null)
                {
                    break;
                }
                await OnFriendRecall(typeof(EventInterface),
                                     new FriendRecallEventArgs(connection, "friend_recall", friendRecall));

                break;

            //群名片变更
            //此事件仅在Go上存在
            case "group_card":
                ApiGroupCardUpdateEventArgs groupCardUpdate = messageJson.ToObject <ApiGroupCardUpdateEventArgs>();
                if (groupCardUpdate == null)
                {
                    break;
                }
                ConsoleLog.Debug("Sora",
                                 $"Group[{groupCardUpdate.GroupId}] member[{groupCardUpdate.UserId}] card update [{groupCardUpdate.OldCard} => {groupCardUpdate.NewCard}]");
                if (OnGroupCardUpdate == null)
                {
                    break;
                }
                await OnGroupCardUpdate(typeof(EventInterface),
                                        new GroupCardUpdateEventArgs(connection, "group_card", groupCardUpdate));

                break;

            case "offline_file":
                ApiOfflineFileEventArgs offlineFile = messageJson.ToObject <ApiOfflineFileEventArgs>();
                if (offlineFile == null)
                {
                    break;
                }
                ConsoleLog.Debug("Sora",
                                 $"Get offline file from[{offlineFile.UserId}] file name = {offlineFile.Info.Name}");
                if (OnOfflineFileEvent == null)
                {
                    break;
                }
                await OnOfflineFileEvent(typeof(EventInterface),
                                         new OfflineFileEventArgs(connection, "offline_file", offlineFile));

                break;

            //通知类事件
            case "notify":
                switch (GetNotifyType(messageJson))
                {
                case "poke":        //戳一戳
                    ApiPokeOrLuckyEventArgs pokeEvent = messageJson.ToObject <ApiPokeOrLuckyEventArgs>();
                    if (pokeEvent == null)
                    {
                        break;
                    }
                    ConsoleLog.Debug("Sora",
                                     $"Group[{pokeEvent.GroupId}] poke from [{pokeEvent.UserId}] to [{pokeEvent.TargetId}]");
                    if (OnGroupPoke == null)
                    {
                        break;
                    }
                    await OnGroupPoke(typeof(EventInterface),
                                      new GroupPokeEventArgs(connection, "poke", pokeEvent));

                    break;

                case "lucky_king":        //运气王
                    ApiPokeOrLuckyEventArgs luckyEvent = messageJson.ToObject <ApiPokeOrLuckyEventArgs>();
                    if (luckyEvent == null)
                    {
                        break;
                    }
                    ConsoleLog.Debug("Sora",
                                     $"Group[{luckyEvent.GroupId}] lucky king user[{luckyEvent.TargetId}]");
                    if (OnLuckyKingEvent == null)
                    {
                        break;
                    }
                    await OnLuckyKingEvent(typeof(EventInterface),
                                           new LuckyKingEventArgs(connection, "lucky_king", luckyEvent));

                    break;

                case "honor":
                    ApiHonorEventArgs honorEvent = messageJson.ToObject <ApiHonorEventArgs>();
                    if (honorEvent == null)
                    {
                        break;
                    }
                    ConsoleLog.Debug("Sora",
                                     $"Group[{honorEvent.GroupId}] member honor change [{honorEvent.HonorType}]");
                    if (OnHonorEvent == null)
                    {
                        break;
                    }
                    await OnHonorEvent(typeof(EventInterface),
                                       new HonorEventArgs(connection, "honor", honorEvent));

                    break;

                default:
                    ConsoleLog.Warning("Sora", $"未知Notify事件类型[{GetNotifyType(messageJson)}]");
                    break;
                }
                break;

            default:
                ConsoleLog.Debug("Sora", $"unknown notice \n{messageJson}");
                ConsoleLog.Warning("Sora", $"接收到未知事件[{GetNoticeType(messageJson)}]");
                break;
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 通知事件处理和分发
        /// </summary>
        /// <param name="messageJson">消息</param>
        /// <param name="connection">连接GUID</param>
        private async void NoticeAdapter(JObject messageJson, Guid connection)
        {
            switch (GetNoticeType(messageJson))
            {
                //群文件上传
                case "group_upload":
                {
                    ApiFileUploadEventArgs fileUpload = messageJson.ToObject<ApiFileUploadEventArgs>();
                    if (fileUpload == null) break;
                    Log.Debug("Sora",
                              $"Group notice[Upload file] file[{fileUpload.Upload.Name}] from group[{fileUpload.GroupId}({fileUpload.UserId})]");
                    //执行回调
                    if (OnFileUpload == null) break;
                    await OnFileUpload("Notice",
                                       new FileUploadEventArgs(connection, "group_upload", fileUpload));
                    break;
                }
                //群管理员变动
                case "group_admin":
                {
                    ApiAdminChangeEventArgs adminChange = messageJson.ToObject<ApiAdminChangeEventArgs>();
                    if (adminChange == null) break;
                    Log.Debug("Sora",
                              $"Group amdin change[{adminChange.SubType}] from group[{adminChange.GroupId}] by[{adminChange.UserId}]");
                    //执行回调
                    if (OnGroupAdminChange == null) break;
                    await OnGroupAdminChange("Notice",
                                             new GroupAdminChangeEventArgs(connection, "group_upload", adminChange));
                    break;
                }
                //群成员变动
                case "group_decrease":
                case "group_increase":
                {
                    ApiGroupMemberChangeEventArgs groupMemberChange =
                        messageJson.ToObject<ApiGroupMemberChangeEventArgs>();
                    if (groupMemberChange == null) break;
                    Log.Debug("Sora",
                              $"{groupMemberChange.NoticeType} type[{groupMemberChange.SubType}] member {groupMemberChange.GroupId}[{groupMemberChange.UserId}]");
                    //执行回调
                    if (OnGroupMemberChange == null) break;
                    await OnGroupMemberChange("Notice",
                                              new GroupMemberChangeEventArgs(connection, "group_member_change",
                                                                             groupMemberChange));
                    break;
                }
                //群禁言
                case "group_ban":
                {
                    ApiGroupMuteEventArgs groupMute = messageJson.ToObject<ApiGroupMuteEventArgs>();
                    if (groupMute == null) break;
                    Log.Debug("Sora",
                              $"Group[{groupMute.GroupId}] {groupMute.ActionType} member[{groupMute.UserId}]{groupMute.Duration}");
                    //执行回调
                    if (OnGroupMemberMute == null) break;
                    await OnGroupMemberMute("Notice",
                                            new GroupMuteEventArgs(connection, "group_ban", groupMute));
                    break;
                }
                //好友添加
                case "friend_add":
                {
                    ApiFriendAddEventArgs friendAdd = messageJson.ToObject<ApiFriendAddEventArgs>();
                    if (friendAdd == null) break;
                    Log.Debug("Sora", $"Friend add user[{friendAdd.UserId}]");
                    //执行回调
                    if (OnFriendAdd == null) break;
                    await OnFriendAdd("Notice",
                                      new FriendAddEventArgs(connection, "friend_add", friendAdd));
                    break;
                }
                //群消息撤回
                case "group_recall":
                {
                    ApiGroupRecallEventArgs groupRecall = messageJson.ToObject<ApiGroupRecallEventArgs>();
                    if (groupRecall == null) break;
                    Log.Debug("Sora",
                              $"Group[{groupRecall.GroupId}] recall by [{groupRecall.OperatorId}],msg id={groupRecall.MessageId} sender={groupRecall.UserId}");
                    //执行回调
                    if (OnGroupRecall == null) break;
                    await OnGroupRecall("Notice",
                                        new GroupRecallEventArgs(connection, "group_recall", groupRecall));
                    break;
                }
                //好友消息撤回
                case "friend_recall":
                {
                    ApiFriendRecallEventArgs friendRecall = messageJson.ToObject<ApiFriendRecallEventArgs>();
                    if (friendRecall == null) break;
                    Log.Debug("Sora", $"Friend[{friendRecall.UserId}] recall msg id={friendRecall.MessageId}");
                    //执行回调
                    if (OnFriendRecall == null) break;
                    await OnFriendRecall("Notice",
                                         new FriendRecallEventArgs(connection, "friend_recall", friendRecall));
                    break;
                }
                //群名片变更
                //此事件仅在Go上存在
                case "group_card":
                {
                    ApiGroupCardUpdateEventArgs groupCardUpdate = messageJson.ToObject<ApiGroupCardUpdateEventArgs>();
                    if (groupCardUpdate == null) break;
                    Log.Debug("Sora",
                              $"Group[{groupCardUpdate.GroupId}] member[{groupCardUpdate.UserId}] card update [{groupCardUpdate.OldCard} => {groupCardUpdate.NewCard}]");
                    if (OnGroupCardUpdate == null) break;
                    await OnGroupCardUpdate("Notice",
                                            new GroupCardUpdateEventArgs(connection, "group_card", groupCardUpdate));
                    break;
                }
                case "offline_file":
                {
                    ApiOfflineFileEventArgs offlineFile = messageJson.ToObject<ApiOfflineFileEventArgs>();
                    if (offlineFile == null) break;
                    Log.Debug("Sora",
                              $"Get offline file from[{offlineFile.UserId}] file name = {offlineFile.Info.Name}");
                    if (OnOfflineFileEvent == null) break;
                    await OnOfflineFileEvent("Notice",
                                             new OfflineFileEventArgs(connection, "offline_file", offlineFile));
                    break;
                }
                case "client_status":
                {
                    ApiClientStatusEventArgs clientStatus = messageJson.ToObject<ApiClientStatusEventArgs>();
                    if (clientStatus == null) break;
                    Log.Debug("Sora",
                              $"Get client status change from[{clientStatus.UserId}] client id = {clientStatus.ClientInfo.AppId}");
                    if (OnClientStatusChangeEvent == null) break;
                    await OnClientStatusChangeEvent("Notice",
                                                    new ClientStatusChangeEventArgs(connection, "client_status",
                                                        clientStatus));
                    break;
                }
                case "essence":
                {
                    ApiEssenceChangeEventArgs essenceChange = messageJson.ToObject<ApiEssenceChangeEventArgs>();
                    if (essenceChange == null) break;
                    Log.Debug("Sora",
                              $"Get essence change msg_id = {essenceChange.MessageId} type = {essenceChange.EssenceChangeType}");
                    if (OnEssenceChange == null) break;
                    await OnEssenceChange("Notice",
                                          new EssenceChangeEventArgs(connection, "essence", essenceChange));
                    break;
                }
                //通知类事件
                case "notify":
                    switch (GetNotifyType(messageJson))
                    {
                        case "poke": //戳一戳
                        {
                            ApiPokeOrLuckyEventArgs pokeEvent = messageJson.ToObject<ApiPokeOrLuckyEventArgs>();
                            if (pokeEvent == null) break;
                            Log.Debug("Sora",
                                      $"Group[{pokeEvent.GroupId}] poke from [{pokeEvent.UserId}] to [{pokeEvent.TargetId}]");
                            if (OnGroupPoke == null) break;
                            await OnGroupPoke("Notify",
                                              new GroupPokeEventArgs(connection, "poke", pokeEvent));
                            break;
                        }
                        case "lucky_king": //运气王
                        {
                            ApiPokeOrLuckyEventArgs luckyEvent = messageJson.ToObject<ApiPokeOrLuckyEventArgs>();
                            if (luckyEvent == null) break;
                            Log.Debug("Sora",
                                      $"Group[{luckyEvent.GroupId}] lucky king user[{luckyEvent.TargetId}]");
                            if (OnLuckyKingEvent == null) break;
                            await OnLuckyKingEvent("Notify",
                                                   new LuckyKingEventArgs(connection, "lucky_king", luckyEvent));
                            break;
                        }
                        case "honor":
                        {
                            ApiHonorEventArgs honorEvent = messageJson.ToObject<ApiHonorEventArgs>();
                            if (honorEvent == null) break;
                            Log.Debug("Sora",
                                      $"Group[{honorEvent.GroupId}] member honor change [{honorEvent.HonorType}]");
                            if (OnHonorEvent == null) break;
                            await OnHonorEvent("Notify",
                                               new HonorEventArgs(connection, "honor", honorEvent));
                            break;
                        }
                        default:
                            Log.Warning("Sora|Notify", $"接收到未知事件[{GetNotifyType(messageJson)}]");
                            break;
                    }

                    break;
                default:
                    Log.Warning("Sora|Notice", $"接收到未知事件[{GetNoticeType(messageJson)}]");
                    break;
            }
        }